Is there a way to apply JSON based styles while using AdvancedMarkers? #138
-
When adding a This works:
When adding a <Map
zoom={zoom}
center={position}
disableDefaultUI
styles={twoToneWithLabels} // https://snazzymaps.com/style/1861/two-tone-with-labels
+ mapId="123"
>
<Marker
position={position}
icon={{
url: "/images/map-marker.png",
scaledSize: { width: 18.14, height: 23.21 },
}}
/>
</Map>; I'm assuming this is expected behavior, by using a mapId we are supposed to use cloud based styling so the styles prop is ignored. Is my assumption correct? If so, is there a way to use JSON based styles while still using a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I'm not sure if this can solve your current issue, but you can convert the existing JSON styling to Cloud-based styling by following the steps described in this docs: https://developers.google.com/maps/documentation/maps-static/cloud-customization/map-styles#import-json-styling Then, you can use mapId to set the desired map style instead of using the JSON one. Sample screenshotHere's the preview converted from the JSON at https://snazzymaps.com/style/1861/two-tone-with-labels |
Beta Was this translation helpful? Give feedback.
-
This works: "use client";
import { APIProvider, Map, useMap } from "@vis.gl/react-google-maps";
import { useEffect } from "react";
const apiKey = process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY ?? "";
const mapId = process.env.NEXT_PUBLIC_GOOGLE_MAPS_MAP_ID ?? "";
export default function Page() {
return (
<div className="h-screen w-full">
<APIProvider apiKey={apiKey}>
<StyledMap />
</APIProvider>
</div>
);
}
function StyledMap() {
const map = useMap();
useEffect(() => {
if (!map) return;
const styledMapType = new google.maps.StyledMapType(twoToneWithLabels); // https://snazzymaps.com/style/1861/two-tone-with-labels
map.mapTypes.set("styled_map", styledMapType);
map.setMapTypeId("styled_map");
}, [map]);
return (
<Map
zoom={14}
center={{ lat: 47.608013, lng: -122.335167 }}
mapId={mapId}
/>
);
} Taken from here. |
Beta Was this translation helpful? Give feedback.
This works: