ol-source-wmts
Layer source for tile data from WMTS servers.
Usage
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" :rotation="rotation" :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 rotation = ref(0);
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>
<template>
<ol-map
:loadTilesWhileAnimating="true"
:loadTilesWhileInteracting="true"
style="height: 400px"
>
<ol-view ref="view" :center="center" :rotation="rotation" :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 rotation = ref(0);
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" />
<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>
<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>