11

I need to change style on a point GeoJSON layer in a Leaflet map.

I'm using the following code:

function onEachFeature(feature, layer) {
                      if (feature.properties && feature.properties.popupContent) {
                         layer.bindPopup(feature.properties.popupContent);
                      }
                     }

var myStyle = {
 "color": "#ff7800",
 "weight": 5,
 "opacity": 0.65
};

myGeoJSONLayer = L.geoJson(myGeoJSON, {
                      style: myStyle,
                      onEachFeature: onEachFeature,
             });

myGeoJSONLayer.addTo(map);                         

All is working but there is always the standard default blue marker on my map.

1 Answer 1

22

To change point markers, you should use the pointToLayer function. See the example page.

var geojsonMarkerOptions = {
    radius: 8,
    fillColor: "#ff7800",
    color: "#000",
    weight: 1,
    opacity: 1,
    fillOpacity: 0.8
};

L.geoJson(someGeojsonFeature, {
    pointToLayer: function (feature, latlng) {
        return L.circleMarker(latlng, geojsonMarkerOptions);
    }
}).addTo(map);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.