ol-webgl-vector-layer
A layer for rendering points, lines and polygons using WebGL
Please note, that you can't use ol-style and related style components here as child components. For more information please checkout the ol-source-vector docs as well.
Setup
Plugin usage
This component is part of the Layers 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 Layers plugin
import { createApp } from "vue";
import App from "./App.vue";
import {
Map,
Layers,
Sources,
} from "vue3-openlayers";
const app = createApp(App);
// ...
app.use(Layers);
// ...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 Layers.
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-webgl-vector-layer> | <Layers.OlWebglVectorLayer> |
WebGL Points, Lines, Polygons
<template>
<form>
<fieldset>
<label for="opacity">Layer Opacity</label>
<input
type="range"
id="opacity"
min="0"
max="1"
step="0.1"
v-model.number="opacity"
/>
<span class="description">{{ opacity }}</span>
</fieldset>
<fieldset>
<label for="visibility-toggle">Layer Visibility:</label>
<input type="checkbox" id="visibility-toggle" v-model="visible" />
<span> {{ visible ? "Visible" : "Hidden" }}</span>
</fieldset>
</form>
<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 crossOrigin="anonymous" />
</ol-tile-layer>
<!-- webgl points layer -->
<ol-webgl-vector-layer
:styles="webglPointStyle"
:visible="visible"
:opacity="opacity"
>
<ol-source-vector
:format="geoJson"
crossOrigin="anonymous"
url="https://openlayers.org/en/latest/examples/data/geojson/point-samples.geojson"
/>
</ol-webgl-vector-layer>
<!-- webgl lines layer -->
<ol-webgl-vector-layer
:styles="webglLineStyle"
:visible="visible"
:opacity="opacity"
>
<ol-source-vector
:format="geoJson"
crossOrigin="anonymous"
url="https://openlayers.org/en/latest/examples/data/geojson/line-samples.geojson"
/>
</ol-webgl-vector-layer>
<!-- webgl polygons layer -->
<ol-webgl-vector-layer
:styles="webglPolyStyle"
:visible="visible"
:opacity="opacity"
>
<ol-source-vector
:format="geoJson"
crossOrigin="anonymous"
url="https://openlayers.org/en/latest/examples/data/geojson/polygon-samples.geojson"
/>
</ol-webgl-vector-layer>
</ol-map>
</template>
<script setup lang="ts">
import { inject, ref } from "vue";
const opacity = ref(1);
const visible = ref(true);
const center = ref([-73.3, 48.0]);
const projection = ref("EPSG:4326");
const zoom = ref(7);
const format = inject("ol-format");
const geoJson = new format.GeoJSON();
const webglPointStyle = {
"shape-points": 3,
"shape-radius": 10,
"shape-opacity": 0.5,
"shape-fill-color": "blue",
};
const webglLineStyle = {
"stroke-width": 5,
"stroke-color": "rgba(24,86,34,0.7)",
};
const webglPolyStyle = {
"stroke-width": 5,
"stroke-color": "rgba(24,86,34,0.4)",
"fill-color": "#0000ff40",
};
</script>variables
You can also filter features according to variables (inspired in this openlayers example).
<template>
<form>
<fieldset>
<label for="timestamp">Current time shown</label>
<input type="range" id="timestamp" min="1303200000" max="1303240000" v-model.number="timestamp" />
<span class="description">{{ new Date(timestamp * 1000).toUTCString() }}</span>
</fieldset>
</form>
<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 crossOrigin="anonymous" />
</ol-tile-layer>
<!-- webgl lines layer -->
<ol-webgl-vector-layer :styles="webglLineStyle" :variables="webglVariables">
<ol-source-vector ref="sourceRef" />
</ol-webgl-vector-layer>
</ol-map>
</template>
<script setup lang="ts">
import { computed, inject, onMounted, ref } from "vue";
const sourceRef = ref();
const timestamp = ref(1303240000);
const center = ref([703365.7089403362, 5714629.865071137]);
const projection = ref("EPSG:3857");
const zoom = ref(9);
const format = inject("ol-format");
const igc = new format.IGC();
const igcUrls = [
'https://openlayers.org/en/latest/examples/data/igc/Clement-Latour.igc',
'https://openlayers.org/en/latest/examples/data/igc/Damien-de-Baenst.igc',
'https://openlayers.org/en/latest/examples/data/igc/Sylvain-Dhonneur.igc',
'https://openlayers.org/en/latest/examples/data/igc/Tom-Payne.igc',
'https://openlayers.org/en/latest/examples/data/igc/Ulrich-Prinz.igc',
];
onMounted(() => {
for (let i = 0; i < igcUrls.length; ++i) {
fetch(igcUrls[i])
.then((resp) => resp.text())
.then((data) => {
const features = igc.readFeatures(data, {
featureProjection: 'EPSG:3857',
});
sourceRef.value.source.addFeatures(features);
});
}
})
const webglLineStyle = {
filter: ['<=', ['line-metric'], ['var', 'timestamp']],
style: {
'stroke-width': 4,
'stroke-color': [
'interpolate',
['linear'],
['line-metric'],
1303200000,
'hsl(312,100%,39%)',
1303240000,
'hsl(36,100%,45%)',
],
}
};
const webglVariables = computed(() => ({
timestamp: timestamp.value,
}));
</script>Properties
disableHitDetection
- Type:
boolean - Default:
false
style
- Type:
object - Default:
() => ({ 'stroke-color' : 'green', 'stroke-width' : 2 })
variables
- Type:
object