react-leaflet#useMap JavaScript Examples

The following examples show how to use react-leaflet#useMap. 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: ZipCodeGeoJson.js    From landlord with MIT License 6 votes vote down vote up
function ZipCodeGeoJson({feature}) {
    const map = useMap()
    const pathOptions = {
        weight: 2,
        opacity: 1,
        color: 'green',
        fillOpacity: 0.1,
        fillColor: 'transparent',
    }
    const resetHighlight = (e) => {
        const layer = e.target;
        layer.setStyle(pathOptions);
        layer.unbindTooltip()
        layer.bindTooltip(feature.properties.ZIP, {permanent: true, opacity: 0.5});
        // layer.bindTooltip(feature.properties.ZIP, {className: 'normalTooltip', permanent: true, opacity: 0.5});
    }
    const highlight = (e) => {
        const layer = e.target;
        layer.setStyle({
            fillOpacity: .5,
            fillColor: 'yellow',
        });
        layer.unbindTooltip()
        layer.bindTooltip(feature.properties.ZIP, {permanent: true, opacity: 1});
        // layer.bindTooltip(feature.properties.ZIP, {className: 'highlightedTooltip', permanent: true, opacity: 1});
    }
    const zoomToFeature = (e) => {
        map.fitBounds(e.target.getBounds());
    }
    return <GeoJSON key={feature.properties.ZIP}
                    data={feature} style={pathOptions}
                    eventHandlers={{
                        click: zoomToFeature,
                        mouseout: resetHighlight,
                        mouseover: (e) => highlight(e, feature.properties.ZIP)
                    }}>
        <Tooltip permanent={true} opacity={.5}>{feature.properties.ZIP}</Tooltip>
    </GeoJSON>
}
Example #2
Source File: Map.jsx    From doc2pen with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
function ReCenterButton() {
	const map = useMap();

	return (
		<label title="Re Center">
			<button
				className="reCenter"
				onClick={() => map.flyTo(position, map.getZoom())}
			>
				<FiCrosshair size={30} color="#cccccc" />
			</button>
		</label>
	);
}
Example #3
Source File: RouteMap.js    From hk-independent-bus-eta with GNU General Public License v3.0 5 votes vote down vote up
ChangeMapCenter = ( {center, zoom} ) => {
  const map = useMap()
  map.flyTo(checkPosition(center))
  return <></>
}