ol-style-icon
Style the icon of a points
Use it inside ol-style to style points
Setup
Plugin usage
This component is part of the Styles
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 Styles
plugin
import { createApp } from "vue";
import App from "./App.vue";
import {
Map,
Layers,
Sources,
Styles,
} from "vue3-openlayers";
const app = createApp(App);
// ...
app.use(Styles);
// ...
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 Styles
.
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-style-icon> | <Styles.OlStyleIcon> |
src
URL
You can pass an icon image by setting the src
attribute as shown below.
<template>
<ol-map
ref="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-vector-layer>
<ol-source-vector
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-icon :src="markerIcon" :scale="0.1"></ol-style-icon>
</ol-style>
</ol-vector-layer>
</ol-map>
</template>
<script setup>
import { ref, inject } from "vue";
import markerIcon from "@/assets/marker.png";
const center = ref([34, 39.13]);
const projection = ref("EPSG:4326");
const zoom = ref(6.8);
const format = inject("ol-format");
const geoJson = new format.GeoJSON();
</script>
Slot
If no src
Attribute is set, the component will render the HTML content within the slot into an image data URL and use the generated image as icon.
<template>
<ol-map
ref="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-vector-layer>
<ol-source-vector
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-icon :scale="1">
<span class="marker">📍</span>
</ol-style-icon>
</ol-style>
</ol-vector-layer>
</ol-map>
</template>
<script setup>
import { ref, inject } from "vue";
const center = ref([34, 39.13]);
const projection = ref("EPSG:4326");
const zoom = ref(6.8);
const format = inject("ol-format");
const geoJson = new format.GeoJSON();
</script>
<style scoped>
.marker {
background-color: #ffddaa;
padding: 10px;
border-radius: 25px;
margin: 5px;
font-size: 25px;
}
</style>
Properties
Props from OpenLayers
Properties are passed-trough from OpenLayers directly. Their types and default values can be checked-out in the official OpenLayers docs. Only some properties deviate caused by reserved keywords from Vue / HTML. This deviating props are described in the section below.
Deviating Properties
None.