ol-source-tianditu
Layer source for Tianditu
ol-source-tianditu
adds ability to display tile data from Tianditu Maps. To use this source you should get API key at https://console.tianditu.gov.cn/.
Usage
Example of ol-source-tianditu
usage
<template>
<ol-map
:loadTilesWhileAnimating="true"
:loadTilesWhileInteracting="true"
style="height: 400px"
>
<ol-view
ref="view"
:center="center"
:rotation="rotation"
:zoom="zoom"
:projection="projection"
/>
<ol-tile-layer>
<ol-source-tianditu
layerType="vec"
projection="EPSG:4326"
tk="dbed7e0f96194affd82763e159de4c50"
:hidpi="true"
></ol-source-tianditu>
</ol-tile-layer>
<ol-tile-layer>
<ol-source-tianditu
:isLabel="true"
layerType="vec"
projection="EPSG:4326"
tk="dbed7e0f96194affd82763e159de4c50"
:hidpi="true"
></ol-source-tianditu>
</ol-tile-layer>
</ol-map>
</template>
<script setup>
import { ref } from "vue";
const center = ref([116.41124529391394, 39.953530444730816]);
const projection = ref("EPSG:4326");
const zoom = ref(8);
const rotation = ref(0);
</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
layerType
- Type:
string
- Default:
img
options: img, vec, ter, eia, cta
tk
- Type:
string
api key
isLabel
- Type:
Boolean
- Default:
false
culture
- Type:
String
- Default:
en-us
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-tianditu :url="url" @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-tianditu :url="url" ref="sourceRef" />
<!-- ... -->
</template>
<script setup>
import { ref, onMounted } from "vue";
const sourceRef = ref(null);
onMounted(() => {
const source = sourceRef.value?.source;
// call your method on `source`
});
</script>