2

I would like to export the features drawn on my OpenLayers map in GeoJSON format.

So far everything is working apart from the properties section, which keeps coming with nothing, as you see below.

enter image description here

I would like to define something for every individual drawing I make on the map.

I found some nice approaches here:

Openlayers 3 draw set name

but it doesn't work in my code:

 var lineInteraction = new ol.interaction.Draw({ type: 'LineString', source: vectorLayer.getSource() }); lineInteraction.setActive(false); lineInteraction.on('drawend', onDrawend) { feature.setProperties({ 'id':1234, 'name': 'yourCustomName' }); console.log(feature, feature.getProperties()); }); 

Is it the OpenLayers library reason behind it? The aforementioned example refers to version 3.0.

My full JS fiddle is here: https://jsfiddle.net/fb9mtyz3/

1 Answer 1

2

You are not setting the properties inside the drawend handler

Either add a second listener

 lineInteraction.on('drawend', onDrawend); lineInteraction.on('drawend', function(e) { e.feature.setProperties({ 'id':1234, 'name': 'yourCustomName' }); }); 

Or call the default onDrawend function and set the properties inside a single handler

 lineInteraction.on('drawend', function(e) { onDrawend(); e.feature.setProperties({ 'id':1234, 'name': 'yourCustomName' }); }); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.