Reputation: 349
In my Google map, all I want to show is
Except 3, I have them all figured out:
{featureType:'all', elementType: 'geometry', stylers: [{color: '#242f3e'}]}
{featureType: 'administrative.country', elementType: 'geometry.stroke', stylers: [{color: '#242f3e'}]}
??????? HOW DO i ACHIEVE THIS ?????
{feature.type: 'administrative.country', elementType: 'labels.text.fill', stylers: [{color: '#746855'}]}
{feature.type: 'administrative.province', elementType: 'labels.text.fill', stylers: [{color: '#746855'}]}
{feature.type: 'administrative.locality', elementType: 'labels.text.fill', stylers: [{color: '#746855'}]}
But I am having problem achieving no. 3. And that is the question.
Please it will be great if you can test the solution you give in the JSFiddle given, because sometimes people give suggestions that don't even work.
Upvotes: 0
Views: 4041
Reputation: 14600
You need to load a GeoJSON with all countries and attach a style.
You can visit this site here select all world regions and select for instance medium resolution and build a custom GeoJson containing all world countries.
You can rename it as you desire. I renamed it as countries.geo.json.
Following load a GoogleMaps, import the GeoJson and attach a style to it: Just make sure you have this html in the same place as countries.geo.json.
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 34.397, lng: 150.644},
zoom: 2
});
// here import the GeoJson holding all the countries
map.data.loadGeoJson('countries.geo.json');
// here attach a style - I gave red fill and white stroke
map.data.setStyle(function(feature) {
return /** @type {google.maps.Data.StyleOptions} */({
fillColor: 'red',
strokeColor: 'white',
strokeWeight: 2
});
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD-9tSrke72PouQMnMX-a7eZSW0jkFMBWY&callback=initMap"
async defer></script>
</body>
</html>
Last but not least I want to mention that the API key is not mine. I borrowed it from developers.google.com here
Upvotes: 3