Skip to content

Commit 9451194

Browse files
committed
feat(OlScalelineControl): support all props with defaults from OpenLayers
1 parent d92a7fd commit 9451194

File tree

8 files changed

+29
-107
lines changed

8 files changed

+29
-107
lines changed

docs/componentsguide/mapcontrols/scaleline/index.md

+8-39
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<script setup>
1010
import ScalelineControlDemo from "@demos/ScalelineControlDemo.vue"
1111
</script>
12+
1213
<ClientOnly>
1314
<ScalelineControlDemo />
1415
</ClientOnly>
@@ -31,45 +32,13 @@ import ScalelineControlDemo from "@demos/ScalelineControlDemo.vue"
3132

3233
## Properties
3334

34-
### className
35-
36-
- **Type**: `String`
37-
- **Default**: `ol-scale-line`
38-
39-
### minWidth
40-
41-
- **Type**: `Number`
42-
- **Default**: `64`
43-
44-
### render
45-
46-
- **Type**: `Function`
47-
48-
### target
49-
50-
- **Type**: `HTMLElement`
51-
52-
### units
53-
54-
- **Type**: `String`
55-
- **Default**: `metric`
56-
57-
### bar
58-
59-
- **Type**: `Boolean`
60-
- **Default**: `false`
61-
62-
### steps
63-
64-
- **Type**: `Number`
65-
- **Default**: `4`
66-
67-
### text
35+
### Props from OpenLayers
6836

69-
- **Type**: `Boolean`
70-
- **Default**: `false`
37+
Properties are passed-trough from OpenLayers directly.
38+
Their types and default values can be checked-out [in the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_control_ScaleLine-ScaleLine.html).
39+
Only some properties deviate caused by reserved keywords from Vue / HTML.
40+
This deviating props are described in the section below.
7141

72-
### dpi
42+
### Deviating Properties
7343

74-
- **Type**: `Number`
75-
- **Default**: `undefined`
44+
None.

src/components/mapControls/OlScaleLineControl.vue

-41
This file was deleted.

src/components/mapControls/OlScalelineControl.vue

+2-24
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,12 @@
22
<div v-if="false"></div>
33
</template>
44
<script setup lang="ts">
5-
import { ScaleLine } from "ol/control";
5+
import ScaleLine, { type Options } from "ol/control/ScaleLine";
66
import { useAttrs } from "vue";
77
import useControl from "@/composables/useControl";
88
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties";
99
10-
const props = withDefaults(
11-
defineProps<{
12-
className?: string;
13-
minWidth?: number;
14-
maxWidth?:number;
15-
render?: (...args: unknown[]) => unknown;
16-
target?: HTMLElement;
17-
units?: string;
18-
bar?: boolean;
19-
steps?: number;
20-
text?: string;
21-
dpi?: number;
22-
}>(),
23-
{
24-
className: "ol-scale-line",
25-
minWidth: 64,
26-
units: "metric",
27-
bar: false,
28-
steps: 4,
29-
text: "",
30-
dpi: undefined,
31-
},
32-
);
10+
const props = defineProps<Options>();
3311
3412
const attrs = useAttrs();
3513
const properties = usePropsAsObjectProperties(props);

src/demos/ScalelineControlDemo.vue

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
<template>
2+
<form>
3+
<fieldset>
4+
<label for="checkbox">Show as bar</label>
5+
<input type="checkbox" id="checkbox" v-model="showAsBar" />
6+
</fieldset>
7+
</form>
28
<ol-map style="height: 400px" :controls="[]">
39
<ol-view :center="center" :zoom="zoom" :projection="projection" />
4-
510
<ol-tile-layer>
611
<ol-source-osm />
712
</ol-tile-layer>
8-
<ol-scaleline-control />
13+
<ol-scaleline-control :bar="showAsBar" />
914
</ol-map>
1015
</template>
1116

1217
<script setup>
1318
import { ref } from "vue";
19+
1420
const center = ref([40, 40]);
1521
const projection = ref("EPSG:4326");
1622
const zoom = ref(8);
23+
const showAsBar = ref(false);
1724
</script>
Binary file not shown.
Loading

tests/controls.test.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,19 @@ test.describe("ol-search-control", () => {
144144
});
145145

146146
test.describe("ol-scaleline-control", () => {
147-
test("should render", async ({ page }) => {
147+
test("should render as ScaleLine", async ({ page }) => {
148+
const map = new MapPage(page);
149+
await map.goto("/componentsguide/mapcontrols/scaleline/");
150+
await map.waitUntilReady();
151+
await map.waitUntilCanvasLoaded();
152+
await map.checkCanvasScreenshot();
153+
});
154+
155+
test("should render as ScaleBar", async ({ page }) => {
148156
const map = new MapPage(page);
149157
await map.goto("/componentsguide/mapcontrols/scaleline/");
150158
await map.waitUntilReady();
159+
await map.page.getByLabel("Show as bar").check();
151160
await map.waitUntilCanvasLoaded();
152161
await map.checkCanvasScreenshot();
153162
});

0 commit comments

Comments
 (0)