Skip to content

Commit b4e1b31

Browse files
committed
docs(ol-style-flowline): add missing documentation page
1 parent c69f4e8 commit b4e1b31

File tree

5 files changed

+140
-39
lines changed

5 files changed

+140
-39
lines changed

docs/.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ export default defineConfig({
225225
text: "ol-style-fill",
226226
link: "/componentsguide/styles/fill/",
227227
},
228+
{
229+
text: "ol-style-flowline",
230+
link: "/componentsguide/styles/flowline/",
231+
},
228232
{
229233
text: "ol-style-icon",
230234
link: "/componentsguide/styles/icon/",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# ol-style-flowline
2+
3+
> Style of a flowline in a vector layer
4+
5+
<script setup>
6+
import FlowLineDemo from "@demos/FlowLineDemo.vue"
7+
</script>
8+
<ClientOnly>
9+
<FlowLineDemo />
10+
</ClientOnly>
11+
12+
## Usage
13+
14+
::: code-group
15+
16+
<<< ../../../../src/demos/FlowLineDemo.vue
17+
18+
:::
19+
20+
## Properties
21+
22+
### Props from OpenLayers
23+
24+
Properties are passed-trough from OpenLayers directly.
25+
Their types and default values can be checked-out [in the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_source_OSM-OSM.html).
26+
Only some properties deviate caused by reserved keywords from Vue / HTML.
27+
This deviating props are described in the section below.
28+
29+
### Deviating Properties
30+
31+
### `overrideStyleFunction`
32+
33+
- **Type**: `OverrideStyleFunction`
34+
35+
Change / override the applied style.
36+
The function has three arguments:
37+
38+
1. `feature: FeatureLike`: The feature the style is related to.
39+
2. `currentStyle: Style`: The current style that's applied (you can override it here)
40+
3. `resolution?: number`: A number representing the view's resolution

docs/public/sitemap.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@
197197
<lastmod>2021-08-15T21:05:05+00:00</lastmod>
198198
<priority>0.80</priority>
199199
</url>
200+
<url>
201+
<loc>https://vue3openlayers.netlify.app/componentsguide/styles/flowline/</loc>
202+
<lastmod>2023-07-06T23:00:00+00:00</lastmod>
203+
<priority>0.80</priority>
204+
</url>
200205
<url>
201206
<loc>https://vue3openlayers.netlify.app/componentsguide/styles/icon/</loc>
202207
<lastmod>2021-08-15T21:05:05+00:00</lastmod>

src/components/styles/OlStyleFlowline.vue

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,32 @@
88
import type { Ref } from "vue";
99
import { inject, watch, onUnmounted, onMounted, computed } from "vue";
1010
11-
import FlowLine from "ol-ext/style/FlowLine";
11+
import FlowLine, { type Options } from "ol-ext/style/FlowLine";
1212
import Draw from "ol/interaction/Draw";
1313
import Modify from "ol/interaction/Modify";
14-
import type { ColorLike } from "ol/colorlike";
1514
import type Feature from "ol/Feature";
16-
import type Style from "ol/style/Style";
15+
import Style from "ol/style/Style";
1716
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties";
18-
import type { StyleFunction, StyleLike } from "ol/style/Style";
17+
import type { StyleLike } from "ol/style/Style";
18+
import type { OverrideStyleFunction } from ".";
19+
import type { Layer } from "ol/layer";
20+
import type { Select } from "ol/interaction";
1921
2022
const props = withDefaults(
21-
defineProps<{
22-
color?: ColorLike | ((feature: Feature, step: number) => ColorLike);
23-
color2?: ColorLike;
24-
width?: number | ((feature: Feature, step: number) => number);
25-
width2?: number;
26-
arrow?: number;
27-
arrowColor?: string;
28-
lineCap: CanvasRenderingContext2D["lineCap"];
29-
overrideStyleFunction?: (...args: unknown[]) => unknown;
30-
}>(),
23+
defineProps<
24+
Options & {
25+
lineCap?: CanvasLineCap;
26+
overrideStyleFunction?: OverrideStyleFunction;
27+
}
28+
>(),
3129
{
3230
visible: true,
3331
lineCap: "butt",
3432
arrowSize: 16,
3533
}
3634
);
3735
38-
const styledObj = inject<Ref<Draw | Modify | Style | null> | null>(
36+
const styledObj = inject<Ref<Draw | Modify | Select | Feature | Layer> | null>(
3937
"stylable",
4038
null
4139
);
@@ -44,60 +42,51 @@ const { properties } = usePropsAsObjectProperties(props);
4442
4543
const style = computed(() => new FlowLine(properties));
4644
47-
const setStyle = (val: StyleLike | null) => {
48-
if (styledObj?.value instanceof Draw || styledObj?.value instanceof Modify) {
49-
styledObj?.value?.getOverlay().setStyle(val);
50-
styledObj?.value?.dispatchEvent("styleChanged");
45+
const setStyle = (val: StyleLike) => {
46+
if (!styledObj?.value) {
47+
return;
48+
}
49+
if (styledObj.value instanceof Draw || styledObj?.value instanceof Modify) {
50+
styledObj.value.getOverlay().setStyle(val);
51+
styledObj.value.dispatchEvent("styleChanged");
5152
return;
5253
}
5354
try {
5455
// @ts-ignore
55-
styledObj?.value?.setStyle(val);
56-
// @ts-ignore
57-
styledObj?.value?.changed();
58-
// @ts-ignore
56+
styledObj.value.setStyle(val);
57+
styledObj.value.changed();
5958
styledObj?.value?.dispatchEvent("styleChanged");
6059
} catch (error) {
6160
if (styledObj?.value) {
6261
// @ts-ignore
6362
styledObj.value.style_ = val;
6463
// @ts-ignore
6564
styledObj.value.values_.style = val;
66-
// @ts-ignore
6765
styledObj.value?.changed();
68-
// @ts-ignore
6966
styledObj.value?.dispatchEvent("styleChanged");
7067
}
7168
}
7269
};
7370
7471
const styleFunc = computed<StyleLike>(() => {
75-
return (feature) => {
76-
if (properties.overrideStyleFunction != null) {
77-
properties.overrideStyleFunction(feature, style.value);
72+
return (feature, resolution) => {
73+
if (properties.overrideStyleFunction) {
74+
properties.overrideStyleFunction(feature, style.value, resolution);
7875
}
7976
return style.value;
8077
};
8178
});
8279
8380
watch(properties, () => {
84-
if (properties.overrideStyleFunction == null) {
85-
setStyle(style.value);
86-
} else {
87-
setStyle(styleFunc.value);
88-
}
81+
setStyle(properties.overrideStyleFunction ? styleFunc.value : style.value);
8982
});
9083
9184
onMounted(() => {
92-
if (properties.overrideStyleFunction == null) {
93-
setStyle(style.value);
94-
} else {
95-
setStyle(styleFunc.value);
96-
}
85+
setStyle(properties.overrideStyleFunction ? styleFunc.value : style.value);
9786
});
9887
9988
onUnmounted(() => {
100-
setStyle(null);
89+
setStyle(new Style());
10190
});
10291
10392
defineExpose({

src/demos/FlowLineDemo.vue

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<template>
2+
<ol-map ref="map" style="height: 400px">
3+
<ol-view
4+
ref="view"
5+
:center="center"
6+
:zoom="zoom"
7+
:projection="projection"
8+
/>
9+
10+
<ol-tile-layer title="OSM">
11+
<ol-source-osm />
12+
</ol-tile-layer>
13+
14+
<ol-vector-layer>
15+
<ol-source-vector>
16+
<ol-feature ref="animationPath">
17+
<ol-geom-line-string :coordinates="path"></ol-geom-line-string>
18+
<ol-style-flowline
19+
color="red"
20+
color2="yellow"
21+
:width="10"
22+
:width2="10"
23+
:arrow="1"
24+
/>
25+
</ol-feature>
26+
<ol-animation-path
27+
v-if="animationPath"
28+
:path="animationPath?.feature"
29+
:duration="4000"
30+
:repeat="10"
31+
>
32+
<ol-feature>
33+
<ol-geom-point :coordinates="path[0]"></ol-geom-point>
34+
<ol-style>
35+
<ol-style-circle :radius="10">
36+
<ol-style-fill color="blue"></ol-style-fill>
37+
<ol-style-stroke color="blue" :width="2"></ol-style-stroke>
38+
</ol-style-circle>
39+
</ol-style>
40+
</ol-feature>
41+
</ol-animation-path>
42+
</ol-source-vector>
43+
</ol-vector-layer>
44+
</ol-map>
45+
</template>
46+
47+
<script setup lang="ts">
48+
import { ref } from "vue";
49+
import type AnimationPath from "ol-ext/featureanimation/Path";
50+
51+
const center = ref([29, 44.5]);
52+
const projection = ref("EPSG:4326");
53+
const zoom = ref(6);
54+
const animationPath = ref<{ feature: AnimationPath } | null>(null);
55+
56+
const path = ref([
57+
[25.6064453125, 44.73302734375001],
58+
[27.759765625, 44.75500000000001],
59+
[28.287109375, 43.32677734375001],
60+
[30.55029296875, 46.40294921875001],
61+
[31.69287109375, 43.04113281250001],
62+
]);
63+
</script>

0 commit comments

Comments
 (0)