Skip to content

Commit a95f8a5

Browse files
committed
feat(ol-map) support all Map events from OpenLayers on component
Newly supported events are: - `change:size` - `change:target` - `change:view` - `rendercomplete` Please refer to the [OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html)
1 parent 8685ea7 commit a95f8a5

File tree

2 files changed

+20
-66
lines changed

2 files changed

+20
-66
lines changed

docs/componentsguide/map/index.md

Lines changed: 11 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,29 @@ None.
3838

3939
## Events
4040

41-
Pointer events that emits [`ol.MapBrowserEvent`](http://openlayers.org/en/latest/apidoc/module-ol_MapBrowserEvent-MapBrowserEvent.html)
41+
You have access to all Events from the underlying source.
42+
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html) to see the available events tht will be fired.
4243

43-
- `click`
44-
- `dblclick`
45-
- `singleclick`
46-
- `pointerdrag`
47-
- `pointermove`
48-
49-
Other events that emit [`ol.MapEvent`](http://openlayers.org/en/latest/apidoc/module-ol_MapEvent-MapEvent.html)
50-
51-
- `movestart`
52-
- `moveend`
53-
- `postrender`
54-
- `precompose`
55-
- `postcompose`
44+
```html
45+
<ol-map @error="handleEvent">
46+
<!-- ... -->
47+
</ol-map>
48+
```
5649

5750
## Methods
5851

5952
You have access to all Methods from the underlying source.
60-
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_Map.html) to see the available methods.
53+
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html) to see the available methods.
6154

6255
To access the source, you can use a `ref()` as shown below:
6356

6457
```vue
6558
<template>
66-
<ol-map ref="mapRef">
59+
<!-- ... -->
60+
<ol-map ref="mapRef" @error="handleEvent">
6761
<!-- ... -->
6862
</ol-map>
63+
<!-- ... -->
6964
</template>
7065
7166
<script setup lang="ts">
@@ -77,55 +72,6 @@ const mapRef = ref<{ map: Map }>(null);
7772
onMounted(() => {
7873
const map: Map = mapRef.value?.map;
7974
// call your method on `map`
80-
const size = map.getSize();
8175
});
8276
</script>
8377
```
84-
85-
Furthermore the following methods are directly exposed and can be use as describe above, using a `ref=""`.
86-
87-
### focus()
88-
89-
Triggers focus on map container.
90-
91-
### forEachFeatureAtPixel(pixel, callback, options = {})
92-
93-
- **Arguments**:
94-
- `pixel {number[]}`
95-
- `callback {function(ol.Feature, ?ol.layer.Layer): *}`
96-
Feature callback. The callback will be called with two arguments: OpenLayers `feature`
97-
at the pixel and `layer` of the feature (will be null for unmanaged layers).
98-
To stop detection, callback functions can return a truthy value.
99-
- `[options] {Object | undefined}`
100-
- `layerFilter {function(ol.layer.Layer): boolean}` Layer filter function.
101-
- `hitTolerance {number | undefined}` Hit-detection tolerance in pixels.
102-
Default is `0`.
103-
- **Returns**: `*` Truthy value returned from the callback.
104-
105-
Detect features that intersect a pixel on the viewport, and execute a callback
106-
with each intersecting feature. Layers included in the detection can be configured
107-
through the `layerFilter` option in `options`.
108-
109-
### getCoordinateFromPixel(pixel)
110-
111-
- **Arguments**:
112-
- `pixel {number[]}`
113-
- **Returns**: `number[]` Coordinates of the pixel in map view projection.
114-
115-
Get the coordinate for a given pixel.
116-
117-
### refresh()
118-
119-
- **Returns**: `{Promise<void>}`
120-
121-
Updates map size and re-renders map.
122-
123-
### render()
124-
125-
- **Returns**: `{Promise<void>}`
126-
127-
Request a map rendering (at the next animation frame).
128-
129-
### updateSize()
130-
131-
Updates map size.

src/components/map/OlMap.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties
2020
const props = defineProps<MapOptions>();
2121
2222
const emit = defineEmits([
23+
"change:layerGroup",
24+
"change:size",
25+
"change:target",
26+
"change:view",
2327
"click",
2428
"dblclick",
2529
"singleclick",
@@ -30,6 +34,7 @@ const emit = defineEmits([
3034
"postrender",
3135
"precompose",
3236
"postcompose",
37+
"rendercomplete",
3338
]);
3439
3540
const { properties } = usePropsAsObjectProperties(props);
@@ -67,16 +72,19 @@ const render = () => map?.render();
6772
const updateSize = () => map?.updateSize();
6873
6974
map.on("click", (event) => emit("click", event));
75+
map.on("change:size", (event) => emit("change:size", event));
76+
map.on("change:target", (event) => emit("change:target", event));
77+
map.on("change:view", (event) => emit("change:view", event));
7078
map.on("dblclick", (event) => emit("dblclick", event));
7179
map.on("singleclick", (event) => emit("singleclick", event));
7280
map.on("pointerdrag", (event) => emit("pointerdrag", event));
7381
map.on("pointermove", (event) => emit("pointermove", event));
74-
7582
map.on("movestart", (event) => emit("movestart", event));
7683
map.on("moveend", (event) => emit("moveend", event));
7784
map.on("postrender", (event) => emit("postrender", event));
7885
map.on("precompose", (event) => emit("precompose", event));
7986
map.on("postcompose", (event) => emit("postcompose", event));
87+
map.on("rendercomplete", (event) => emit("rendercomplete", event));
8088
8189
defineExpose({
8290
map,

0 commit comments

Comments
 (0)