Skip to content

Commit 3621c25

Browse files
committed
refactor(ol-source-image-static): pass-through all props and events from ol/source/ImageStatic
BREAKING CHANGE: - drop prop `imageSmoothing`, use `interpolate` - set compatible OpenLayers version to latest (7.4.0)
1 parent 2ed205f commit 3621c25

File tree

8 files changed

+95
-88
lines changed

8 files changed

+95
-88
lines changed

docs/componentsguide/sources/cluster/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ None.
114114
## Events
115115

116116
You have access to all Events from the underlying source.
117-
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_source_BingMaps-BingMaps.html) to see the available events tht will be fired.
117+
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_source_Cluster-Cluster.html) to see the available events tht will be fired.
118118

119119
```html
120120
<ol-source-cluster @error="handleEvent" />
@@ -123,7 +123,7 @@ Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc
123123
## Methods
124124

125125
You have access to all Methods from the underlying source.
126-
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_source_BingMaps-BingMaps.html) to see the available methods.
126+
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_source_Cluster-Cluster.html) to see the available methods.
127127

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

docs/componentsguide/sources/imagestatic/index.md

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ol-source-image-static
22

3-
A layer source for displaying a single, static image.
3+
> Layer source for displaying a single, static image.
44
55
<script setup>
66
import ImageLayerDemo from "@demos/ImageLayerDemo.vue"
@@ -64,47 +64,49 @@ const imgCopyright = ref('© <a href="http://xkcd.com/license.html">xkcd</a>');
6464

6565
## Properties
6666

67-
### attributions
67+
### Props from OpenLayers
6868

69-
- **Type**: `string`
69+
Properties are passed-trough from OpenLayers directly.
70+
Their types and default values can be checked-out [in the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_source_ImageStatic-Static.html).
71+
Only some properties deviate caused by reserved keywords from Vue / HTML.
72+
This deviating props are described in the section below.
7073

71-
Attributions
74+
### Deviating Properties
7275

73-
### crossOrigin
76+
None.
7477

75-
- **Type**: `string`
76-
- **Default**: `ol-layer`
78+
## Events
7779

78-
The crossOrigin attribute for loaded images. Note that you must provide a crossOrigin value if you want to access pixel data with the Canvas renderer.
80+
You have access to all Events from the underlying source.
81+
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_source_ImageStatic-Static.html) to see the available events tht will be fired.
7982

80-
### imageExtent
81-
82-
- **Type**: `Array`
83-
84-
Extent of the image in map coordinates. This is the [left, bottom, right, top] map coordinates of your image.
85-
86-
### imageSmoothing
87-
88-
- **Type**: `boolean`
89-
- **Default**: `true`
90-
91-
Enable image smoothing.
92-
93-
### projection
94-
95-
- **Type**: `string or object (options projection)`
96-
- **Default**: `Projection. Default is the view projection.`
83+
```html
84+
<ol-source-image-static :url="imgUrl" @error="handleEvent" />
85+
```
9786

98-
The crossOrigin attribute for loaded images. Note that you must provide a crossOrigin value if you want to access pixel data with the Canvas renderer.
87+
## Methods
9988

100-
### imageSize
89+
You have access to all Methods from the underlying source.
90+
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_source_ImageStatic-Static.html) to see the available methods.
10191

102-
- **Type**: `Array`
92+
To access the source, you can use a `ref()` as shown below:
10393

104-
Size of the image in pixels. Usually the image size is auto-detected, so this only needs to be set if auto-detection fails for some reason.
94+
```vue
95+
<template>
96+
<!-- ... -->
97+
<ol-source-image-static :url="url" ref="sourceRef" />
98+
<!-- ... -->
99+
</template>
105100
106-
### url
101+
<script setup lang="ts">
102+
import { ref, onMounted } from "vue";
103+
import type ImageStatic from "ol/source/ImageStatic";
107104
108-
- **Type**: `string`
105+
const sourceRef = ref<{ source: ImageStatic }>(null);
109106
110-
Image URL.
107+
onMounted(() => {
108+
const source: ImageStatic = sourceRef.value?.source;
109+
// call your method on `source`
110+
});
111+
</script>
112+
```

docs/get-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Installation
44

5-
vue3-openlayers works with Vue.js **^3.0** and OpenLayers **^6.6.1**
5+
vue3-openlayers works with Vue.js **^3.0** and OpenLayers **^7.3.0**
66

77
Install current **stable version**
88

package-lock.json

Lines changed: 26 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
"dependencies": {
6666
"file-saver": "^2.0.5",
6767
"jspdf": "^2.5.1",
68-
"ol": "^7.3.0",
68+
"ol": "^7.4.0",
6969
"ol-contextmenu": "^5.2.1",
70-
"ol-ext": "^4.0.7",
70+
"ol-ext": "^4.0.8",
7171
"proj4": "^2.9.0"
7272
},
7373
"browserslist": [

src/components/sources/OlSourceImageStatic.vue

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,37 @@
33
</template>
44
<script setup lang="ts">
55
import Static, { type Options } from "ol/source/ImageStatic";
6-
import Projection from "ol/proj/Projection";
7-
import { inject, onMounted, onUnmounted, watch } from "vue";
8-
import type { Extent } from "ol/extent";
6+
import { computed, inject, onMounted, onUnmounted, watch, type Ref } from "vue";
97
import type ImageLayer from "ol/layer/Image";
108
import type ImageSource from "ol/source/Image";
119
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties";
12-
import type { ProjectionLike } from "ol/proj";
10+
import eventGateway from "@/helpers/eventGateway";
11+
import projectionFromProperties from "@/helpers/projection";
1312
14-
const props = withDefaults(
15-
defineProps<{
16-
attributions?: string;
17-
crossOrigin?: string;
18-
imageExtent?: Extent;
19-
projection?: ProjectionLike;
20-
imageSmoothing?: boolean;
21-
imageSize?: number[];
22-
url: string;
23-
}>(),
24-
{
25-
imageSmoothing: true,
26-
}
27-
);
13+
const props = withDefaults(defineProps<Options>(), {
14+
interpolate: true,
15+
});
16+
const emit = defineEmits([]);
2817
2918
const layer = inject<ImageLayer<ImageSource> | null>("imageLayer");
3019
const { properties } = usePropsAsObjectProperties(props);
3120
3221
const createSource = () => {
33-
return new Static({
22+
const s = new Static({
3423
...properties,
35-
projection:
36-
typeof properties.projection === "string"
37-
? properties.projection
38-
: // @ts-ignore
39-
new Projection({
40-
...properties.projection,
41-
}),
42-
} as Options);
24+
projection: projectionFromProperties(properties.projection),
25+
});
26+
27+
eventGateway(emit, s, [
28+
"change",
29+
"error",
30+
"imageloadend",
31+
"imageloaderror",
32+
"imageloadstart",
33+
"propertychange",
34+
]);
35+
36+
return s;
4337
};
4438
4539
let source = createSource();

src/helpers/eventGateway.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default function eventGateway(
77
) {
88
events.forEach((event: string) => {
99
instance.on(event, (...args: unknown[]) => {
10+
console.log(event, args);
1011
emit(event, ...args);
1112
});
1213
});

src/helpers/projection.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Projection, type ProjectionLike } from "ol/proj";
2+
3+
export default function projectionFromProperties(projection: ProjectionLike) {
4+
if (!projection) return;
5+
if (typeof projection === "string") return projection;
6+
if (projection instanceof Projection) return projection;
7+
return new Projection(projection);
8+
}

0 commit comments

Comments
 (0)