Select delayed features
by Vladimir Vershinin
HTML
<script src="https://unpkg.com/[email protected]/lodash.js"></script>
<script src="https://unpkg.com/vue@latest/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io/en/v5.3.0/build/ol.js"></script>
<script src="https://unpkg.com/[email protected]/lib/index.umd.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/lib/style.css">
<div id="app">
<div>
{{ featuresState }}
</div>
<vl-map ref="map" data-projection="EPSG:4326">
<vl-view ref="view"
:zoom.sync="zoom"
:center.sync="center"></vl-view>
<vl-layer-tile>
<vl-source-osm></vl-source-osm>
</vl-layer-tile>
<vl-layer-vector>
<vl-source-vector :features="features"></vl-source-vector>
<vl-style-box>
<vl-style-icon src="https://img.icons8.com/office/50/000000/place-marker.png" :anchor="[0.5, 1]"></vl-style-icon>
</vl-style-box>
</vl-layer-vector>
<vl-interaction-select :condition="selectCondition">
<vl-style-box>
<vl-style-icon src="https://img.icons8.com/ultraviolet/50/000000/place-marker.png" :anchor="[0.5, 1]"></vl-style-icon>
</vl-style-box>
</vl-interaction-select>
</vl-map>
</div>
CSS
html, body, #app {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#app {
display: flex;
flex-direction: column;
}
.vl-map {
overflow: hidden;
}
JavaScript
new Vue({
el: '#app',
data () {
return {
zoom: 2,
center: [0, 0],
features: [],
}
},
computed: {
layerFeatureIds () {
return this.features.map(f => f.id)
},
featuresState () {
if (this.features.length) {
return 'Loaded: ' + this.layerFeatureIds.length
}
return 'Loading....'
},
},
mounted () {
this.loadFeatures().then(features => console.log('loaded', features))
},
methods: {
selectCondition: ol.events.condition.click,
loadFeatures () {
return new Promise(resolve => {
setTimeout(() => {
this.features = _.range(0, 100).map(i => ({
type: 'Feature',
id: 'point-' + (i + 1),
properties: {},
geometry: {
type: 'Point',
coordinates: [
_.random(-50, 50),
_.random(-50, 50),
],
},
}))
resolve(this.features)
}, 3000)
})
},
}
})