Slavomir
Slavomir

Reputation: 31

GeoJson styling Asymmetrik/ngx-leaflet

Hi I have a problem with Asymmetrik/ngx-leaflet geojson interpretation.

My geojson is automatically generated with color and opacity corresponding to the map information. Each geojson is a FeatureCollection with multiple Polygons differently styled.

I've tried different options, I've found to set style of the Polygons, but non of them seems to work.

Example geoJson:

{  
   "type":"FeatureCollection",
   "features":[  
      {  
         "geometry":{  
            "type":"Polygon",
            "coordinates":[  
               [...]
            ]
         },
         "type":"Feature",
         "properties":{  
            "style":{  
               "color":"#ff0000",
               "weight":0,
               "opacity":0.2
            }
         }
      }, ... ]}

I've been trying multiple options that seems to work for people. Also there is nothing on styling inside geojson in the ngx-leaflet docs.

How should I set the styling above to make ngx-leaflet display proper color, stroke and opacity?

Upvotes: 1

Views: 1117

Answers (1)

reblace
reblace

Reputation: 4185

ngx-leaflet doesn't do anything to manipulate the layers you add to the map. So, it's up to you to provide the style options when you create the features.

E.g.,

let geoJson = {...};
let options = { "color": "#ff7800", "weight": 5, "opacity": 0.65 };
L.geoJSON(geoJson, options).addTo(map);

This example was taken from here: http://leafletjs.com/examples/geojson/

Upvotes: 4

Related Questions