Reputation: 1216
after drawing features to OpenLayers map (map overlay) I want to parse features to be able to send it.
Problem is that when I call getArray() it works and without getArray it doesn't. Shouldn't parse.writeFeatures get as paramater featureOverlay.getFeatures() and not featureOverlay.getFeatures().getArray()?
$.FooBarNS.featureOverlay = new ol.FeatureOverlay({
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: '#ffcc33',
width: 2
}),
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
});
$.FooBarNS.featureOverlay.setMap(map);
$('#save_polygon').click( function(){
var parser = new ol.format.GeoJSON();
//features = $.FooBarNS.features;
var features = $.FooBarNS.featureOverlay.getFeatures().getArray();
console.log(features);
var featuresGeoJSON = parser.writeFeatures(features, {'dataProjection':'EPSG:4326','featureProjection':'EPSG:3857'});
console.log(featuresGeoJSON);
$.ajax({
type: 'POST',
url: 'http://gis.FooBar.com/testpolygon/',
dataType: 'json',
//contentType: 'application/json;charset=utf-8',
data: featuresGeoJSON
}).then(function(response) {
//console.log(response);
});
});
Upvotes: 0
Views: 298
Reputation: 2126
Check the API docs: http://openlayers.org/en/v3.5.0/apidoc/ol.format.GeoJSON.html#writeFeatures
writeFeatures takes an Array of ol.Feature so that's what you need to pass in.
Upvotes: 1