Skip to content

ol-interaction-transform

Interaction for transform feature geometries.

Demo

Setup

Plugin usage

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

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

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

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

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-interaction-transform><Interactions.OlInteractionTransform>
vue
<template>
  <button class="btn-default" @click="drawEnabled = !drawEnabled">
    Draw: {{ drawEnabled }}
  </button>

  <ol-map
    ref="map"
    :load-tiles-while-animating="true"
    :load-tiles-while-interacting="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 :features="zones">
        <ol-interaction-draw
          v-if="drawEnabled"
          :stopClick="true"
          type="Polygon"
          @drawend="drawend"
        />
        <ol-style>
          <ol-style-stroke color="blue" :width="2" />
          <ol-style-fill color="rgba(255, 0, 0, 0.4)" />
        </ol-style>
      </ol-source-vector>
    </ol-vector-layer>

    <ol-interaction-transform
      @select="log('select', $event)"
      @rotatestart="log('rotatestart', $event)"
      @rotating="log('rotate', $event)"
      @rotateend="log('rotateend', $event)"
      @translatestart="log('translatestart', $event)"
      @translate="log('translate', $event)"
      @translateend="log('translateend', $event)"
      @scalestart="log('scalestart', $event)"
      @scaling="log('scaling', $event)"
      @scaleend="log('scaleend', $event)"
    />
  </ol-map>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { GeoJSON } from "ol/format";
import type { DrawEvent } from "ol/interaction/Draw";
import type { Feature } from "ol";
import type { Geometry } from "ol/geom";

const map = ref("");
const center = ref([-102.13121, 40.2436]);
const projection = ref("EPSG:4326");
const zoom = ref(5);
const drawEnabled = ref(false);

const geojsonObject = {
  type: "FeatureCollection",
  crs: {
    type: "name",
    properties: {
      name: "EPSG:4326",
    },
  },
  features: [
    {
      type: "Feature",
      geometry: {
        type: "Polygon",
        coordinates: [
          [
            [-103.86923852630616, 43.45599322423934],
            [-103.90891107984544, 39.34240191087722],
            [-98.76630637117387, 39.558687199211114],
            [-98.89435771175386, 43.945405844902986],
            [-103.86923852630616, 43.45599322423934],
          ],
        ],
      },
    },
    {
      type: "Feature",
      geometry: {
        type: "Polygon",
        coordinates: [
          [
            [-103.85636392303468, 38.10970692739486],
            [-103.86770698495866, 33.218572724914544],
            [-98.20654544301988, 33.6532810221672],
            [-98.4408283538437, 38.31894739375114],
            [-103.85636392303468, 38.10970692739486],
          ],
        ],
      },
    },
  ],
};

const zones = ref<Feature<Geometry>[]>([]);

const drawend = (event: DrawEvent) => {
  zones.value.push(event.feature);
  drawEnabled.value = false;
};

const log = (eventType: string, event: unknown) => {
  console.log(eventType, event);
};

zones.value = new GeoJSON().readFeatures(geojsonObject);
</script>

Properties

enableRotatedTransform

  • Type: Function

condition

  • Type: Function

addCondition

  • Type: Function

filter

  • Type: Function

layers

  • Type: Array

hitTolerance

  • Type: Number
  • Default: 2

translateFeature

  • Type: Boolean
  • Default: true

scale

  • Type: Boolean
  • Default: true

rotate

  • Type: Boolean
  • Default: true

keepAspectRatio

  • Type: Boolean
  • Default: false

translate

  • Type: Boolean
  • Default: true

stretch

  • Type: Boolean
  • Default: true

Events

  • select
  • rotatestart
  • rotating
  • rotateend
  • translatestart
  • translating
  • translateend
  • scalestart
  • scaling
  • scaleend