0

I am trying to add layers by using drag and drop interaction. Here is jsfiddle.http://jsfiddle.net/anuket/umdwzn10/ It almost works, I mean new layer is added, but for Geometry it gives "NaN". Geojson I used for testing is this one:

{"type":"FeatureCollection","totalFeatures":36458,"features":[{"type":"Feature","id":"testdata_geopnt.65","geometry":{"type":"Point","coordinates":[388095.34465382877,6464704.213578554]},"geometry_name":"geometry","properties":{"latitude":58.30865,"longitude":22.09077,"coord_id":948,"loc_count":4,"obs_count":0,"seq_count":2,"spe_count":2,"occ_count":0,"overall_count":4}}]}

Does this interaction support custom projections? and second question is, does this support polygons, because seems like it does not, at least in my tests.

1

This interaction does not support custom projections. In the code, the private ol.interaction.DragAndDrop.prototype.handleResult_ calls the code below:

var readFeatures = this.tryReadFeatures_(format, result);

This code itself return format.readFeatures(text) (where format is ol.format.GeoJSON). If custom projections were supported, it would be format.readFeatures(text, options) where options would take {dataProjection: 'EPSG:3301'}.

Anyways, you can always overload the ol.format.GeoJSON using OpenLayers 3. You can also make your custom component for Drag and Drop without OpenLayers and call OpenLayers functions only to parse dragged GeoJSON with the "right" projection. For example, you can use http://www.dropzonejs.com or http://filedropjs.org

For polygons, using a polygon created with http://geojson.io and then add it to http://openlayers.org/en/master/examples/drag-and-drop.html works on my side.

  • Sorry, could you specify what do you mean by "...you can always overload the ol.format.GeoJSON using OpenLayers 3..." – Anuket Oct 20 '14 at 8:47

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.