ol-interaction-select
Interaction for selecting vector features
Demo
Setup
Plugin usage
This component is part of the Interactions
plugin. If not installed globally, you need to import and use
the plugin in your main.ts
or use the explicit component import (see section below).
Import and use the Interactions
plugin
ts
import { createApp } from "vue";
import App from "./App.vue";
import {
Map,
Layers,
Sources,
Interactions,
} from "vue3-openlayers";
const app = createApp(App);
// ...
app.use(Interactions);
// ...
Explicit import
If you don't want to install a plugin, you can import the component explicitly. It's available as a child of the named export Interactions
.
NOTE
The following documentation refers to the plugin usage. Please make sure to adopt the component names, when you decided to use explicit component imports (e. g. <ol-map>
becomes <Map.OlMap>
etc.).
Usage
Plugin Usage | Explicit Import |
---|---|
<ol-interaction-select> | <Interactions.OlInteractionSelect> |
vue
<template>
<ol-map
:loadTilesWhileAnimating="true"
:loadTilesWhileInteracting="true"
style="height: 400px"
>
<ol-view
ref="view"
:center="center"
:zoom="zoom"
:projection="projection"
/>
<ol-tile-layer>
<ol-source-osm />
</ol-tile-layer>
<ol-interaction-select
@select="featureSelected"
:condition="selectCondition"
:filter="selectInteactionFilter"
>
<ol-style>
<ol-style-stroke color="green" :width="10"></ol-style-stroke>
<ol-style-fill color="rgba(255,255,255,0.5)"></ol-style-fill>
<ol-style-icon :src="markerIcon" :scale="0.05"></ol-style-icon>
</ol-style>
</ol-interaction-select>
<ol-vector-layer>
<ol-source-vector
ref="cities"
url="https://raw.githubusercontent.com/alpers/Turkey-Maps-GeoJSON/master/tr-cities-airports.json"
:format="geoJson"
:projection="projection"
>
</ol-source-vector>
<ol-style>
<ol-style-stroke color="red" :width="2"></ol-style-stroke>
<ol-style-fill color="rgba(255,255,255,0.1)"></ol-style-fill>
<ol-style-circle :radius="7">
<ol-style-fill color="blue"></ol-style-fill>
</ol-style-circle>
</ol-style>
</ol-vector-layer>
</ol-map>
</template>
<script setup>
import markerIcon from "@/assets/marker.png";
import { ref, inject } from "vue";
const center = ref([40, 40]);
const projection = ref("EPSG:4326");
const zoom = ref(8);
const format = inject("ol-format");
const geoJson = new format.GeoJSON();
const selectConditions = inject("ol-selectconditions");
const selectCondition = selectConditions.pointerMove;
const featureSelected = (event) => {
console.log(event);
};
const selectInteactionFilter = (feature) => {
return feature.values_.name != undefined;
};
</script>
Properties
multi
- Type:
Boolean
- Default:
false
features
- Type:
Collection
filter
- Type:
Function
condition
- Type:
Function