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.
Best Answer
This interaction does not support custom projections. In the code, the private
ol.interaction.DragAndDrop.prototype.handleResult_
calls the code below:This code itself return
format.readFeatures(text)
(where format isol.format.GeoJSON
). If custom projections were supported, it would beformat.readFeatures(text, options)
whereoptions
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.