react-leaflet#GeoJSON TypeScript Examples
The following examples show how to use
react-leaflet#GeoJSON.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegionLabelLayer.tsx From Teyvat.moe with GNU General Public License v3.0 | 6 votes |
_RegionLabelLayer: FunctionComponent<RegionLabelLayerProps> = ({ displayed, zoomLevel }) => {
const classes = useStyles();
const map = useMap();
const layerReference = useRef<GeoJSONLeaflet | null>(null);
useEffect(() => {
if (layerReference.current != null) {
if (displayed) {
layerReference.current.addTo(map);
} else {
layerReference.current.removeFrom(map);
}
}
}, [map, displayed]);
const pointToLayer = (featureData: Feature<Point, any>, latLng: LatLng) => {
const html = renderToString(<RegionLabel featureData={featureData} zoomLevel={zoomLevel} />);
return LeafletMarker([latLng.lng, latLng.lat], {
interactive: false, // Allow clicks to pass through.
icon: LeafletDivIcon({
html,
className: classes.regionLabelMarker,
}),
zIndexOffset: -900,
});
};
return (
<GeoJSON
ref={layerReference}
key={zoomLevel}
pointToLayer={pointToLayer}
data={RegionLabelData as GeoJsonObject}
/>
);
}
Example #2
Source File: WorldBorderLayer.tsx From Teyvat.moe with GNU General Public License v3.0 | 6 votes |
_WorldBorderLayer: FunctionComponent<WorldBorderLayerProps> = ({ displayed }) => {
// Any child elements of the react-leaflet MapContainer can access the Map instance
// through the use of a custom hook.
const mapCurrent = useMap();
const layerReference = useRef<GeoJSONLeaflet | null>(null);
useEffect(() => {
if (layerReference.current != undefined) {
if (displayed) {
layerReference.current.addTo(mapCurrent);
} else {
layerReference.current.removeFrom(mapCurrent);
}
}
}, [mapCurrent, displayed]);
return (
<GeoJSON
ref={layerReference}
// If the zoom level changes, the world border should reload.
key={mapCurrent.getZoom()}
style={{
// fillPattern: worldBorderPattern,
stroke: false,
fillOpacity: 0.3,
color: 'red',
}}
data={WorldBorderData}
/>
);
}