Render start / complete
by Vladimir Vershinin
HTML
<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">
<script src="https://unpkg.com/@reactivex/[email protected]/dist/global/rxjs.umd.min.js"></script>
<div id="app">
<div>Loading: {{ mapLoading }}</div>
<vl-map ref="map" data-projection="EPSG:4326">
<vl-view ref="mapView" :zoom.sync="zoom" :center.sync="center"></vl-view>
<vl-layer-tile>
<vl-source-osm></vl-source-osm>
</vl-layer-tile>
<vl-layer-vector id="countries">
<vl-source-vector url="https://openlayers.org/en/latest/examples/data/geojson/countries.geojson"></vl-source-vector>
</vl-layer-vector>
</vl-map>
</div>
CSS
html,
body,
#app {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
JavaScript
new Vue({
el: '#app',
data() {
return {
zoom: 5,
center: [0, 0],
points: [{
type: 'Feature',
id: 'one',
properties: {},
geometry: {
type: 'Point',
coordinates: [10, 10],
},
}],
mapLoading: true,
}
},
mounted () {
rxFromVueEvent(this.$refs.map, 'rendercomplete').pipe(
rxjs.operators.debounceTime(500)
).subscribe(evt => {
this.mapLoading = false
console.log('rendercomplete')
})
rxjs.merge(
rxFromVueEvent(this.$refs.mapView, 'update:zoom'),
rxFromVueEvent(this.$refs.mapView, 'update:center')
).pipe(
rxjs.operators.debounceTime(100),
).subscribe(evt => {
this.mapLoading = true
console.log('renderstart')
})
},
})
function rxFromVueEvent (vm, event) {
return rxjs.fromEventPattern(
function (handler) { vm.$on(event, handler) },
function (handler) { vm.$off(event, handler) },
)
}