Skip to content

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/.

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
ts
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 UsageExplicit Import
<ol-source-tianditu><Sources.OlSourceTianditu>

Example of ol-source-tianditu usage

vue
<template>
  <ol-map
    :loadTilesWhileAnimating="true"
    :loadTilesWhileInteracting="true"
    style="height: 400px"
  >
    <ol-view
      ref="view"
      :center="center"
      :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);
</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.

html
<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:

vue
<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>