How to draw COUNTY limits line #741
-
Hey! I have a list of county placeIds and I want to draw their boundaries and fill the areas with a specific color. How can I achieve this using this library? |
Beta Was this translation helpful? Give feedback.
Answered by
usefulthink
Apr 11, 2025
Replies: 1 comment 3 replies
-
That would be using the Data Driven Styling for boundaries. There are some examples in the documentation that should get you started into the right direction, most of them can be translated into this library using import { Map, useMap } from "@vis.gl/react-google-maps";
import { useEffect } from "react";
// Define a style with purple fill and border.
const featureStyleOptions: google.maps.FeatureStyleOptions = {
strokeColor: "#810FCB",
strokeOpacity: 1.0,
strokeWeight: 3.0,
fillColor: "#810FCB",
fillOpacity: 0.5,
};
const CustomMap = (mapProps) => {
const map = useMap();
useEffect(() => {
if (!map) return;
// once the map is available, we can configure the feature-layer:
const featureLayer = map.getFeatureLayer("LOCALITY");
// Apply the style to a single boundary.
featureLayer.style = (options: { feature: { placeId: string } }) => {
if (options.feature.placeId == "ChIJ0zQtYiWsVHkRk8lRoB1RNPo") {
return featureStyleOptions;
}
};
return () => (featureLayer.style = null);
}, [map]);
return <Map {...mapProps}></Map>;
}; |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
lukzfern
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That would be using the Data Driven Styling for boundaries.
There are some examples in the documentation that should get you started into the right direction, most of them can be translated into this library using
useMap
/useEffect
like this (based on https://developers.google.com/maps/documentation/javascript/dds-boundaries/style-polygon#complete_example_code):