Removed SelectInteraction

This commit is contained in:
Simon Seyock
2019-09-23 14:54:46 +02:00
parent c65e802c71
commit 3838b68427
16 changed files with 289 additions and 1127 deletions

View File

@@ -1,9 +1,11 @@
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {Draw, Modify, Select, Snap} from '../src/ol/interaction.js';
import {Draw, Modify, Snap} from '../src/ol/interaction.js';
import {Tile as TileLayer, Vector as VectorLayer} from '../src/ol/layer.js';
import {OSM, Vector as VectorSource} from '../src/ol/source.js';
import {Circle as CircleStyle, Fill, Stroke, Style} from '../src/ol/style.js';
import Collection from '../src/ol/Collection.js';
import {shiftKeyOnly} from '../src/ol/events/condition.js';
const raster = new TileLayer({
source: new OSM()
@@ -37,29 +39,53 @@ const map = new Map({
})
});
const highlightStyle = new Style({
fill: new Fill({
color: 'rgba(255,255,255,0.7)'
}),
stroke: new Stroke({
color: 'rgb(51,153,204)',
width: 3
})
});
const ExampleModify = {
init: function() {
this.select = new Select();
map.addInteraction(this.select);
this.features = new Collection();
this.features.on('add', function(e) {
e.element.setStyle(highlightStyle);
});
this.features.on('remove', function(e) {
e.element.setStyle(undefined);
});
this.select = function(e) {
if (!shiftKeyOnly(e)) {
this.features.clear();
}
map.forEachFeatureAtPixel(e.pixel, function(f) {
this.features.push(f);
}.bind(this));
}.bind(this);
this.modify = new Modify({
features: this.select.getFeatures()
features: this.features
});
map.addInteraction(this.modify);
this.setEvents();
},
setEvents: function() {
const selectedFeatures = this.select.getFeatures();
this.select.on('change:active', function() {
selectedFeatures.forEach(function(each) {
selectedFeatures.remove(each);
});
});
},
setActive: function(active) {
this.select.setActive(active);
if (active) {
this.features.clear();
map.on('singleclick', this.select);
} else {
map.un('singleclick', this.select);
}
this.modify.setActive(active);
}
};