react-leaflet#LayerGroup TypeScript Examples
The following examples show how to use
react-leaflet#LayerGroup.
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: EditorLayer.tsx From Teyvat.moe with GNU General Public License v3.0 | 6 votes |
_EditorLayer: FunctionComponent<EditorLayerProps> = ({ displayed, editorData }) => {
const map = useMap();
const layerReference = useRef<LeafletLayerGroup | null>(null);
useEffect(() => {
if (layerReference.current !== null) {
if (displayed) {
layerReference.current.addTo(map);
} else {
layerReference.current.removeFrom(map);
}
}
}, [map, displayed]);
return (
<LayerGroup ref={layerReference}>
{_.map(editorData, (element) => {
return distinguishRoute(element) ? (
<RouteLine key={element.id} route={element} editable />
) : (
<FeatureMarker
key={element.id}
marker={element}
featureKey={'editor' as MSFFeatureKey}
editable
icons={null}
allowExternalMedia
/>
);
})}
</LayerGroup>
);
}
Example #2
Source File: RouteLayer.tsx From Teyvat.moe with GNU General Public License v3.0 | 6 votes |
_RouteLayer: FunctionComponent<RouteLayerProps> = ({ routeGroup, displayed }) => {
if (!displayed) return null;
switch (routeGroup.format) {
case 2:
return (
<LayerGroup>
{_.map(routeGroup.data, (route) => {
return <RouteLine key={route.id} route={route} />;
})}
</LayerGroup>
);
default:
return null;
}
}
Example #3
Source File: index.tsx From aqualink-app with MIT License | 6 votes |
SiteMarkers = ({ collection }: SiteMarkersProps) => {
const storedSites = useSelector(sitesToDisplayListSelector);
const sitesList = collection?.sites || storedSites || [];
const siteOnMap = useSelector(siteOnMapSelector);
const { map } = useLeaflet();
const setCenter = useCallback(
(inputMap: L.Map, latLng: [number, number], zoom: number) => {
const maxZoom = Math.max(inputMap.getZoom() || 6, zoom);
const pointBounds = L.latLngBounds(latLng, latLng);
inputMap.flyToBounds(pointBounds, {
duration: 2,
maxZoom,
paddingTopLeft: L.point(0, 200),
});
},
[]
);
// zoom in and center on site marker when it's clicked
useEffect(() => {
if (map && siteOnMap?.polygon.type === "Point") {
const [lng, lat] = siteOnMap.polygon.coordinates;
setCenter(map, [lat, lng], 6);
}
}, [map, siteOnMap, setCenter]);
return (
<LayerGroup>
<MarkerClusterGroup
iconCreateFunction={clusterIcon}
disableClusteringAtZoom={1}
>
{sitesList.map((site: Site) => (
<SiteMarker key={site.id} site={site} />
))}
</MarkerClusterGroup>
</LayerGroup>
);
}