简体   繁体   中英

I want to change the icon color of one layer in leaflet, I have two point ,layers all appearing as blue default icons

I have two points layers as Geojson files that I added to my leaflet map. The issue is that they all appear as the blue default icon. I want to change one to red. How do I do this?

Code

 <body> <h1>Settlement Map</h1> <div id="map"> <script> var map = L.map('map').setView([-34.06001, 18.66321], 13); var addressLayer = L.geoJSON(address, { color: 'red' }).addTo(map); var EPLayer = L.geoJSON(EP).addTo(map); </script> </div> <body/>

It would be good if you could provide some code. It's hard to understand your problem and what you have done so far...

Use the pointToLayer function

L.geoJSON(json,{
    pointToLayer: function (feature, latlng) {
        switch (feature.properties.country) {
            case 'at': return L.marker(latlng, {icon: redIcon});
            case 'de': return L.marker(latlng, {icon: greenIcon});
            default: return L.marker(latlng);
        } 
    }
}).addTo(mymap);

https://jsfiddle.net/falkedesign/3ycm6dzv/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM