Modify feature
by Vladimir Vershinin
HTML
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io/en/v5.3.0/build/ol.js"></script>
<script src="https://unpkg.com/vue@latest"></script>
<script src="https://unpkg.com/vuelayers@latest"></script>
<link rel="stylesheet" href="https://unpkg.com/vuelayers@latest/lib/style.css">
<script src="https://rawgit.com/Marak/faker.js/master/examples/browser/js/faker.js"></script>
<div id="app">
<button @click="addFeature">
Add feature
</button>
<vl-map ref="map" data-projection="EPSG:4326">
<vl-view :zoom.sync="zoom" :center.sync="center"></vl-view>
<vl-layer-tile>
<vl-source-osm></vl-source-osm>
</vl-layer-tile>
<vl-layer-vector id="featuresLayer">
<vl-source-vector ident="featuresSource" :features.sync="features"></vl-source-vector>
</vl-layer-vector>
<vl-interaction-modify source="featuresSource"></vl-interaction-modify>
</vl-map>
</div>
CSS
html, body, #app {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
JavaScript
new Vue({
el: '#app',
data () {
return {
zoom: 1,
center: [0, 0],
features: [],
}
},
methods: {
async addFeature () {
this.features = this.features.concat({
id: faker.random.uuid(),
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [
parseFloat(faker.address.longitude()),
parseFloat(faker.address.latitude()),
],
},
})
},
},
})