Skip to content

ol-geom-line-string

ol-geom-line-string can be used inside a ol-feature to draw lines on the map.

Demo

Setup

Plugin usage

This component is part of the Geometries 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 Geometries plugin
ts
import { createApp } from "vue";
import App from "./App.vue";

import {
  Map,
  Layers,
  Sources,
  Geometries,
} from "vue3-openlayers";

const app = createApp(App);
// ...
app.use(Geometries); 
// ...

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

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-geom-line-string><Geometries.OlGeomLineString>
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-osm />
    </ol-tile-layer>

    <ol-vector-layer>
      <ol-source-vector>
        <ol-feature ref="profileFeatureRef">
          <ol-geom-line-string
            :coordinates="[
              [116.544921, 40.451633],
              [116.545264, 40.451649],
              [116.545865, 40.451698],
              [116.546144, 40.451551],
              [116.546337, 40.451274],
              [116.546788, 40.451143],
              [116.547324, 40.451078],
              [116.547539, 40.450996],
              [116.547839, 40.450719],
              [116.54844, 40.450506],
              [116.548933, 40.450604],
              [116.549448, 40.450604],
              [116.550242, 40.450376],
              [116.550865, 40.450163],
              [116.551702, 40.449935],
              [116.552581, 40.449576],
            ]"
          ></ol-geom-line-string>
          <ol-style>
            <ol-style-stroke
              :color="strokeColor"
              :width="strokeWidth"
            ></ol-style-stroke>
          </ol-style>
        </ol-feature>
      </ol-source-vector>
    </ol-vector-layer>

    <ol-profile-control
      v-if="profileFeatureRef?.feature"
      :feature="profileFeatureRef.feature"
      @over="over"
      @out="out"
    ></ol-profile-control>
  </ol-map>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";

const center = ref([116.54875, 40.45064]);
const projection = ref("EPSG:4326");
const zoom = ref(17);
const strokeWidth = ref(10);
const strokeColor = ref("red");
const profileFeatureRef = ref(null);

function over(event) {
  console.log(event);
}

function out(event) {
  console.log(event);
}

onMounted(() => {
  console.log(profileFeatureRef.value);
});
</script>

Properties

coordinates

  • Type: number[][] An array of pairs of coordinates as specified by the geojson spec in units of the map's projection.