Skip to content

Commit

Permalink
Fix pointer events observable
Browse files Browse the repository at this point in the history
Do not miss pointer events due to throttle filtering

#423
  • Loading branch information
ghettovoice committed Apr 8, 2021
1 parent f2f2d54 commit f66bc0d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
22 changes: 8 additions & 14 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/component/map/map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import VectorSource from 'ol/source/Vector'
import View from 'ol/View'
import { merge as mergeObs } from 'rxjs/observable'
import { distinctUntilChanged, map as mapObs, throttleTime } from 'rxjs/operators'
import { distinctUntilChanged, map as mapObs } from 'rxjs/operators'
import Vue from 'vue'
import {
featuresContainer,
Expand Down Expand Up @@ -462,7 +462,6 @@
hasMap(this)
hasView(this)
const ft = 1000 / 60
// pointer
const pointerEvents = mergeObs(
observableFromOlEvent(this.$map, [
Expand All @@ -474,8 +473,13 @@
'pointerdrag',
'pointermove',
]).pipe(
throttleTime(ft),
distinctUntilChanged((a, b) => isEqual(a.coordinate, b.coordinate)),
distinctUntilChanged((a, b) => isEqual({
t: a.type,
c: a.coordinate,
}, {
t: b.type,
c: b.coordinate,
})),
),
).pipe(
mapObs(evt => ({
Expand Down
5 changes: 4 additions & 1 deletion test/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div id="app">
<button @click="features = savedFeatures.slice()">set</button>
<button @click="features = []">unset</button>
<vl-map ref="map" data-projection="EPSG:4326" :default-controls="false">
<vl-map ref="map" data-projection="EPSG:4326" :default-controls="false" @pointerdrag="onDrag">
<vl-view :center.sync="center" :rotation.sync="rotation" :zoom.sync="zoom"
ident="view" ref="view" />

Expand Down Expand Up @@ -59,6 +59,9 @@
featureClass: Feature,
})
},
onDrag (evt) {
console.log(evt)
},
},
}
</script>
Expand Down

0 comments on commit f66bc0d

Please sign in to comment.