Google maps 3.54 adding style to the map
Trying to make custom google map with custom style
Using my own map styles in Google Maps with mapId and Style created in in the Google Maps Platform console - Stack Overflow
Working on a โGoogle Mapsโ style map. Thought I would share progress!
Videos
It is currently not possible to upload or import JSON from Google Map Console/Platform for custom styling of Google Maps.
But it is possible to add custom styles from the code end. I have also tried this in an Angular project.
Working Code -
import { Loader } from '@googlemaps/js-api-loader';
ngOnInit(): void {
const loader = new Loader({
apiKey: API_KEY,
version: 'weekly'
});
loader.importLibrary('maps').then(() => {
void this.initMap();
}).catch((error: Error) => {
console.error(`Error loading Google Maps API: ${error.message}`);
});
}
async initMap(): Promise <void> {
const { Map } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
const mapOptions = {
zoom: 7,
center: {
lat: 22.5744,
lng: 88.3629
},
};
const map = new Map(document.getElementById('map'), mapOptions);
const styledMapType = new google.maps.StyledMapType(
[
{
featureType: 'water',
elementType: 'all',
stylers: [
{
color: '#f40000',
},
{
visibility: 'on',
},
],
}
]
);
this.map.mapTypes.set('styled_map', styledMapType);
this.map.setMapTypeId('styled_map');
}
Output -
Google map package version -
"@angular/core": "^17.2.0",
"@angular/google-maps": "^17.2.0",
"@googlemaps/js-api-loader": "^1.16.6",
"@googlemaps/markerclusterer": "^2.5.3",
Not sure about how it is with Vue but your code looks correct โ with or without &v=3.54.
The thing is, if you instantiate your map with a mapId, the styles attribute in the constructor will not override the map's appearance.
So, if you don't have cloud styling associated with your mapId, remove it from the constructor. Your styles should apply right away. And I suspect this.map.setMapTypeId(...) will take effect too.
UPDATE
You cannot use mapIds and styles at the same time. When you do, you'll get the warning:
A Map's styles property cannot be set when a
mapIdis present. When amapIdis present, Map styles are controlled via the cloud console. Please see documentation at https://developers.google.com/maps/documentation/javascript/styling#cloud_tooling
Given that your style definitions are stored in a DB, you'll likely need to create individual mapIds and their associated cloud styleโฆ
Alternatively, you can reconsider your usage of Advanced Markers. Here's a guide to explore alternatives. Dislaimer: I wrote the guide.
Finally, you might want to keep an eye on the gcloud cli which might, at some future point, let you programmatically create mapIds and styles -- just like Google did for API Keys.
(if this is the wrong subreddit im sorry)
So, i made a map using snazzymaps, specifically trying to make a RDR2 styled map. I figured out how to get the JSON code, along with a static map URL, but i cant seem to find out how to import that into Google Maps, or use it in any way. If anyone can help me, id be very thankful.