ol-source-wmts
Layer source for tile data from WMTS servers.
Demo
Setup
Plugin usage
This component is part of the Sources
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 Sources
plugin
import { createApp } from "vue";
import App from "./App.vue";
import {
Map,
Layers,
Sources,
} from "vue3-openlayers";
const app = createApp(App);
// ...
app.use(Sources);
// ...
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 Sources
.
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-source-wmts> | <Sources.OlSourceWmts> |
Example below shows how to use ol-layer-tile component together with ol-source-wmts and with ol-source-osm.
<template>
<ol-map
:loadTilesWhileAnimating="true"
:loadTilesWhileInteracting="true"
style="height: 400px"
>
<ol-view ref="view" :center="center" :zoom="zoom" />
<ol-tile-layer>
<ol-source-osm />
</ol-tile-layer>
<ol-tile-layer>
<ol-source-wmts
:attributions="attribution"
:url="url"
:matrixSet="matrixSet"
:format="format"
:layer="layerName"
:styles="styleName"
></ol-source-wmts>
</ol-tile-layer>
</ol-map>
</template>
<script setup>
import { ref } from "vue";
const center = ref([-11158582, 4813697]);
const zoom = ref(4);
const url = ref("https://mrdata.usgs.gov/mapcache/wmts");
const layerName = ref("sgmc2");
const matrixSet = ref("GoogleMapsCompatible");
const format = ref("image/png");
const styleName = ref("default");
const attribution = ref(
'Tiles © <a href="https://services.arcgisonline.com/arcgis/rest/services/Demographics/USA_Population_Density/MapServer/">ArcGIS</a>',
);
</script>
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
styles
Sets the WMTS source style
property.
- Type:
string
tileZoomLevel
Sets the zoom level to calculate the used WMTSTileGrid
. It's only used, when the tileGrid
property isn't set.
- Type:
number
- Default:
30
tileMatrixPrefix
Sets the matrix prefix string to create the used WMTSTileGrid
. It's only used, when the tileGrid
property isn't set.
- Type:
string
- Default:
""
Events
You have access to all Events from the underlying source. Check out the official OpenLayers docs to see the available events tht will be fired.
<ol-source-wmts :url="imgUrl" @error="handleEvent" />
Methods
You have access to all Methods from the underlying source. Check out the official OpenLayers docs to see the available methods.
To access the source, you can use a ref()
as shown below:
<template>
<!-- ... -->
<ol-source-wmts :url="url" ref="sourceRef" />
<!-- ... -->
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue";
import type WMTS from "ol/source/WMTS";
const sourceRef = ref<{ source: WMTS }>(null);
onMounted(() => {
const source: WMTS = sourceRef.value?.source;
// call your method on `source`
});
</script>