-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathzoom.mjs
66 lines (43 loc) · 1.33 KB
/
zoom.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
## Mapview.interactions.zoom()
@module /mapview/interactions/zoom
@param {Object} params
The params object argument.
*/
export default function(params){
const mapview = this
// Finish the current interaction.
mapview.interaction?.finish()
mapview.interaction = {
finish: finish,
Layer: new ol.layer.Vector({
source: new ol.source.Vector()
}),
// Spread params argument.
...params
}
mapview.interaction.Layer.getSource().clear()
mapview.Map.addLayer(mapview.interaction.Layer);
mapview.Map.getTargetElement().style.cursor = 'zoom-in';
mapview.interaction.interaction = new ol.interaction.Draw({
source: mapview.interaction.Layer.getSource(),
type: 'Circle',
geometryFunction: ol.interaction.Draw.createBox(),
style: {
'stroke-color': '#ddd',
'fill-color': '#fff9'
}
})
mapview.interaction.interaction.on('drawend', e => {
mapview.fitView(e.feature.getGeometry().getExtent())
finish()
})
mapview.Map.addInteraction(mapview.interaction.interaction)
function finish() {
mapview.Map.getTargetElement().style.cursor = 'auto';
mapview.Map.removeInteraction(mapview.interaction.interaction)
mapview.Map.removeLayer(mapview.interaction.Layer)
mapview.interaction.Layer.getSource().clear()
mapview.interaction.callback?.()
}
}