0

I want to represent the weight of each point of my geojson collection by a circle with a scalable radius.

Here an sample of my GeoJSON file:

"features": [
{ "type": "Feature", "properties": { "id": 20401, "radius": 0.032878 }, "geometry": { "type": "Point", "coordinates": [ 6.569957243078316, 46.744609055776721 ] } },
{ "type": "Feature", "properties": { "id": 20402, "radius": 0.024677 }, "geometry": { "type": "Point", "coordinates": [ 6.56996417375066, 46.744609055776721 ] } },

Is there a way to extract the radius property?

actually I represent my points like this

var points = new ol.layer.Vector({
         source: new ol.source.Vector({
         projection : 'EPSG:4326',
         url: 'weeds.geojson',
         format: new ol.format.GeoJSON(),
      })
  });

It's the default representation who appear on the map.

  • You can simply do feature.get('radius') in the style function? – bartvde Sep 15 '16 at 6:57
1

Like @bartvde pointed out you can use an ol.StyleFunction() (see API):

var points = new ol.layer.Vector({
    source: new ol.source.Vector({
        // ...
        style: function(feature, viewResolution){
            // access your radius property
            var r = feature.get('radius');
            // create your style...
            var style = new ol.style.Style({
                // ...
                image: new ol.style.Circle({
                    // ...
                    radius: r
                })
            });
            return style;
        }
    })
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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