I have a World Countries geojson, that has country codes as "ID" (feature.id) and names as feature.properties.name
I would like to color specific countries for making a "countries visited" map.
What would be the easiest way to provide a list of ids or names to assign a color to them?
Currently my code for one country is this:
var map = L.map('map').setView([30.45,24.61], 3);
function style(feature) {
if ("Latvia" == feature.properties.name) {
return {
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7,
fillColor: '#FFA000'
};
} else {
return {
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7,
fillColor: '#000'
};
}
}
var geojsonLayer = new L.GeoJSON.AJAX("countries.geo.json", {
style: style
});
geojsonLayer.addTo(map);
I would like to replace the "IF" thing with some sort of comma separated list of ids or names.
Here is a sample of that geojson file:
{"type":"FeatureCollection","features":[
{"type":"Feature","id":"AFG","properties":{"name":"Afghanistan"},"geometry":{"type":"Polygon","coordinates":