0

I'm currently working on ReactJS GIS and referring to this sample Demo. But when I update the latest version of React and dependencies is not work, no error message displayed on the console. What wrong. I've also test in my local computer, the result is same (not work) what happen?

The demo: enter image description here

After update the dependencies: enter image description here

Plipus Tel
  • 666
  • 3
  • 13
  • 23

1 Answers1

2

There are many things that have been changed:

  1. React has changed to 18.x. You should replace in index.js all the code

    import React from "react";
    import ReactDOM from "react-dom/client";
    
    import App from "./App";
    
    const root = ReactDOM.createRoot(document.getElementById("root"));
    
    root.render(
      <App />
    );
    
  2. react-leaflet has moved to version 4.x which has breaking changes:

map ref is received via a ref and a useState hook and no need for map.current or map.current.leafletElement. Also Map comp has been renamed to MapContainer

 const [map, setMap] = useState(null);

  useEffect(() => {
    if (!map) return;

    map.setView([34.74161249883172, 18.6328125], 2);
  }, [map]);

<MapContainer
      center={position}
      zoom={13}
      style={{ height: "100vh" }}
      ref={setMap}
    >
  1. mapRef in MapContainer's child components is received via

    const map = useMap();
    

Demo

kboul
  • 13,836
  • 5
  • 42
  • 53
  • Thank you @kboul, but I have to tell you ....the css code import "leaflet/dist/leaflet.css"; is still generate an erro WARNING in ./node_modules/leaflet/dist/leaflet.css (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[2]!./node_modules/source-map-loader/dist/cjs.js!./node_modules/leaflet/dist/leaflet.css) Module Warning (from ./node_modules/postcss-loader/dist/cjs.js): Warning – Plipus Tel Aug 22 '22 at 12:30
  • You 're welcome. This error has to do with your custom app configuration which I am not aware of. – kboul Aug 22 '22 at 12:39
  • Hello @kboul, one more thing....in your sandbox...everything is work, why in my local...is not show the border? just show the map. Anything I missed ? thanks, just curious – Plipus Tel Aug 23 '22 at 13:37
  • 1
    Hi kboul, I just found the problem due to the coordinates system using in my shapefile, my coordinates system is UTM. – Plipus Tel Aug 27 '22 at 12:59