From 4f529f7b66810f296f86ac8197bafbefb2f01d73 Mon Sep 17 00:00:00 2001 From: Danny Koppenhagen Date: Thu, 7 Mar 2024 19:29:36 +0100 Subject: [PATCH] feat(ol-search-control): add search control (#309) closes #306 --- docs/.vitepress/config.ts | 4 + .../mapcontrols/search/index.md | 61 ++++++++++ .../mapControls/OlSearchControl.vue | 24 ++++ src/components/mapControls/index.ts | 3 + src/composables/useControl.ts | 4 + src/demos/SearchControlDemo.vue | 106 ++++++++++++++++++ vite.config.ts | 1 + 7 files changed, 203 insertions(+) create mode 100644 docs/componentsguide/mapcontrols/search/index.md create mode 100644 src/components/mapControls/OlSearchControl.vue create mode 100644 src/demos/SearchControlDemo.vue diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 7d88997a..54fef4b3 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -377,6 +377,10 @@ export default defineConfig({ text: "ol-rotate-control", link: "/componentsguide/mapcontrols/rotate/", }, + { + text: "ol-search-control", + link: "/componentsguide/mapcontrols/search/", + }, { text: "ol-scaleline-control", link: "/componentsguide/mapcontrols/scaleline/", diff --git a/docs/componentsguide/mapcontrols/search/index.md b/docs/componentsguide/mapcontrols/search/index.md new file mode 100644 index 00000000..c3227579 --- /dev/null +++ b/docs/componentsguide/mapcontrols/search/index.md @@ -0,0 +1,61 @@ +# ol-search-control + +> A Search control for OpenLayers. + + + + + + +## Usage + +::: code-group + +<<< ../../../../src/demos/SearchControlDemo.vue + +::: + +## Properties + +### Props from OpenLayers + +Properties are passed-trough from `ol-ext` directly. +Their types and default values can be checked-out [in the official OpenLayers docs](https://viglino.github.io/ol-ext/examples/search/map.control.search.html). +Only some properties deviate caused by reserved keywords from Vue / HTML. +This deviating props are described in the section below. + +### Deviating Properties + +None. + +## Events + +### select + +Emits when selecting an item from the list of search results. + +- **Type**: `SearchEvent` + +```vue + + + +``` diff --git a/src/components/mapControls/OlSearchControl.vue b/src/components/mapControls/OlSearchControl.vue new file mode 100644 index 00000000..0dbcf7a3 --- /dev/null +++ b/src/components/mapControls/OlSearchControl.vue @@ -0,0 +1,24 @@ + + diff --git a/src/components/mapControls/index.ts b/src/components/mapControls/index.ts index eccc3b8c..6b2ddc6c 100644 --- a/src/components/mapControls/index.ts +++ b/src/components/mapControls/index.ts @@ -11,6 +11,7 @@ import OlOverviewMapControl from "./OlOverviewMapControl.vue"; import OlPrintDialogControl from "./OlPrintDialogControl.vue"; import OlRotateControl from "./OlRotateControl.vue"; import OlScaleLineControl from "./OlScaleLineControl.vue"; +import OlSearchControl from "./OlSearchControl.vue"; import OlSwipeControl from "./OlSwipeControl.vue"; import OlToggleControl from "./OlToggleControl.vue"; import OlVideoRecorderControl from "./OlVideoRecorderControl.vue"; @@ -30,6 +31,7 @@ function install(app: App) { app.component("ol-zoomtoextent-control", OlZoomToExtentControl); app.component("ol-rotate-control", OlRotateControl); app.component("ol-context-menu-control", OlContextMenuControl); + app.component("ol-search-control", OlSearchControl); app.component("ol-swipe-control", OlSwipeControl); app.component("ol-control-bar", OlControlBar); app.component("ol-toggle-control", OlToggleControl); @@ -57,6 +59,7 @@ export { OlPrintDialogControl, OlRotateControl, OlScaleLineControl, + OlSearchControl, OlSwipeControl, OlToggleControl, OlVideoRecorderControl, diff --git a/src/composables/useControl.ts b/src/composables/useControl.ts index 82e480a7..c9abe4e8 100644 --- a/src/composables/useControl.ts +++ b/src/composables/useControl.ts @@ -27,6 +27,8 @@ import type { Options as LayerSwitcherOptions } from "ol-ext/control/LayerSwitch import type LayerSwitcherImage from "ol-ext/control/LayerSwitcherImage"; import type Rotate from "ol/control/Rotate"; import type { Options as RotateOptions } from "ol/control/Rotate"; +import type Search from "ol-ext/control/Search"; +import type { Options as SearchOptions } from "ol-ext/control/Search"; import type Swipe from "ol-ext/control/Swipe"; import type { Options as SwipeOptions } from "ol-ext/control/Swipe"; import type Zone from "ol-ext/control/MapZone"; @@ -55,6 +57,7 @@ type InnerControlType = ( | MousePosition | OverviewMap | Rotate + | Search | ScaleLine | Swipe | Zone @@ -73,6 +76,7 @@ type InnerControlProperties = | ToggleOptions | VideoRecorderOptions | LayerSwitcherOptions + | SearchOptions | RotateOptions | SwipeOptions | MapZoneOptions diff --git a/src/demos/SearchControlDemo.vue b/src/demos/SearchControlDemo.vue new file mode 100644 index 00000000..4458444c --- /dev/null +++ b/src/demos/SearchControlDemo.vue @@ -0,0 +1,106 @@ + + + diff --git a/vite.config.ts b/vite.config.ts index b321e1cb..5548789d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -107,6 +107,7 @@ export default defineConfig({ "ol-ext/control/PrintDialog": "PrintDialog", "ol/control/Rotate": "Rotate$1", "ol-ext/control/Swipe": "Swipe", + "ol-ext/control/Search": "Search", "ol-ext/control/Toggle": "Toggle", "ol-ext/control/VideoRecorder": "VideoRecorder", "ol-ext/control/MapZone": "MapZone",