2

I want to show my road network in red color. How can I change this default color of the road network. Where should I attach style property?

var roadNetwork = new L.LayerGroup();
$.getJSON("{% url 'road_dataset' %}", function (data) {
    var geojson = L.geoJson(data, {
        onEachFeature: function (feature, layer) {
            layer.bindPopup(feature.properties.road_name);
        }
    });
    geojson.addTo(roadNetwork);
});
2
  • please you should have a look to the official doc of leaflet then if you still have problem precise your problem leafletjs.com/examples/geojson and I don't understand why it's link to jquery Mar 31, 2019 at 6:59
  • Yes i already check this documentation. But i have no idea where i can insert the style function in jquery. For showing the data from database in geodjango i used jquery. Mar 31, 2019 at 10:44

1 Answer 1

6

You don't use jquery for this, jquery is a library for interacting with the DOM. You just have to define a style object and attach it to your layer, as seen in the documentation:

var roadNetwork = new L.LayerGroup();

var myStyle = { // Define your style object
    "color": "#ff0000"
};

$.getJSON("{% url 'road_dataset' %}", function (data) {
    var geojson = L.geoJson(data, {

        style: myStyle, // Assign the style object to the "style" property of the layer

        onEachFeature: function (feature, layer) {
            layer.bindPopup(feature.properties.road_name);
        }
    });
    geojson.addTo(roadNetwork);
});
0

Your Answer

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

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