Created
October 5, 2020 18:07
-
-
Save vgrem/b817a5e08fbb6c549c58c15c6aa4b930 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from "react"; | |
import { Map, GeoJSON, TileLayer } from "react-leaflet"; | |
import leafletStream from "leaflet-geojson-stream"; | |
function StreamGeoJsonLayer(props) { | |
const layerRef = React.useRef(); | |
const { url } = props; | |
useEffect(() => { | |
const gj = layerRef.current.leafletElement; | |
leafletStream.ajax(url, gj).on("end", function () { | |
console.log("all done!"); | |
}); | |
}, []); | |
return <GeoJSON ref={layerRef} />; | |
} | |
function MapExample(props) { | |
return ( | |
<Map center={props.center} zoom={props.zoom}> | |
<TileLayer | |
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" | |
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' | |
/> | |
<StreamGeoJsonLayer url={"http://localhost:8000/data"} /> | |
</Map> | |
); | |
} | |
export default MapExample; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment