Я бы хотел перетащить какой-нибудь файл jp2 на мою карту с помощью OpenLayer.
Как вы можете видеть, мы можем сделать это в каком-то формате, например: GPX, Geo JSON, IG C, KML или Topo JSON файлы (источник: https://openlayers.org/en/latest/examples/drag-and-drop-image-vector.html)
import Map from 'ol/Map';
import View from 'ol/View';
import {GPX, GeoJSON, IGC, KML, TopoJSON, WFS} from 'ol/format';
import {defaults as defaultInteractions, DragAndDrop} from 'ol/interaction';
import {VectorImage as VectorImageLayer, Tile as TileLayer} from 'ol/layer';
import {XYZ, Vector as VectorSource} from 'ol/source';
var dragAndDropInteraction = new DragAndDrop({
formatConstructors: [
GPX,
GeoJSON,
IGC,
KML,
TopoJSON
]
});
dragAndDropInteraction.on('addfeatures', function(event) {
var vectorSource = new VectorSource({
features: event.features
});
map.addLayer(new VectorImageLayer({
source: vectorSource
}));
map.getView().fit(vectorSource.getExtent());
});
var displayFeatureInfo = function(pixel) {
var features = [];
map.forEachFeatureAtPixel(pixel, function(feature) {
features.push(feature);
});
if (features.length > 0) {
var info = [];
var i, ii;
for (i = 0, ii = features.length; i < ii; ++i) {
info.push(features[i].get('name'));
}
document.getElementById('info').innerHTML = info.join(', ') || ' ';
} else {
document.getElementById('info').innerHTML = ' ';
}
};