You can easily do that by loading an appropriate GeoJSON onto your map (you can find more information here).
For example, at the below, I created a medium resolution GeoJSON of the world via here and uploaded it to my server, and then by the following script, I was able to config the Google Map API to show countries in different colors.
// Load GeoJSON.
map.data.loadGeoJson('http://domain/geojson.json');
map.data.setStyle(function(feature) {
var color = 'green';
if (feature.getProperty('wb_a2') === "AU") {
color = 'red';
}
if (feature.getProperty('wb_a2') === "IR") {
color = 'yellow';
}
return /** @type {google.maps.Data.StyleOptions} */({
fillColor: color,
strokeColor: color,
strokeWeight: 2
});
});
As you can see the default color is Green and both of Iran and Australia have got different colors.
Notice: from here you can create different GeoJSON files according to your requirements such as the file size, covering the area and the resolution.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…