ol-interaction-draw
Interaction for drawing feature geometries.
ol-interaction-draw handles click events on the map and makes easier to draw geometries.
Usage
vue
<template>
<form>
<fieldset>
<label for="checkbox">Draw Mode Enabled</label>
<input type="checkbox" id="checkbox" v-model="drawEnable" />
</fieldset>
<fieldset>
<label for="type">Geometry Type</label>
<select id="type" class="select-default" v-model="drawType">
<option value="Point">Point</option>
<option value="LineString">LineString</option>
<option value="Polygon">Polygon</option>
<option value="Circle">Circle</option>
</select>
</fieldset>
</form>
<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-osm />
</ol-tile-layer>
<ol-vector-layer>
<ol-source-vector :projection="projection">
<ol-interaction-draw
v-if="drawEnable"
:type="drawType"
@drawend="drawend"
@drawstart="drawstart"
>
<ol-style>
<ol-style-stroke color="blue" :width="2"></ol-style-stroke>
<ol-style-fill color="rgba(255, 255, 0, 0.4)"></ol-style-fill>
</ol-style>
</ol-interaction-draw>
</ol-source-vector>
<ol-style>
<ol-style-stroke color="red" :width="2"></ol-style-stroke>
<ol-style-fill color="rgba(255,255,255,0.1)"></ol-style-fill>
<ol-style-circle :radius="7">
<ol-style-fill color="red"></ol-style-fill>
</ol-style-circle>
</ol-style>
</ol-vector-layer>
</ol-map>
</template>
<script setup>
import { ref } from "vue";
const center = ref([40, 40]);
const projection = ref("EPSG:4326");
const zoom = ref(8);
const rotation = ref(0);
const drawEnable = ref(true);
const drawType = ref("Polygon");
const drawstart = (event) => {
console.log(event);
};
const drawend = (event) => {
console.log(event);
};
</script>
<template>
<form>
<fieldset>
<label for="checkbox">Draw Mode Enabled</label>
<input type="checkbox" id="checkbox" v-model="drawEnable" />
</fieldset>
<fieldset>
<label for="type">Geometry Type</label>
<select id="type" class="select-default" v-model="drawType">
<option value="Point">Point</option>
<option value="LineString">LineString</option>
<option value="Polygon">Polygon</option>
<option value="Circle">Circle</option>
</select>
</fieldset>
</form>
<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-osm />
</ol-tile-layer>
<ol-vector-layer>
<ol-source-vector :projection="projection">
<ol-interaction-draw
v-if="drawEnable"
:type="drawType"
@drawend="drawend"
@drawstart="drawstart"
>
<ol-style>
<ol-style-stroke color="blue" :width="2"></ol-style-stroke>
<ol-style-fill color="rgba(255, 255, 0, 0.4)"></ol-style-fill>
</ol-style>
</ol-interaction-draw>
</ol-source-vector>
<ol-style>
<ol-style-stroke color="red" :width="2"></ol-style-stroke>
<ol-style-fill color="rgba(255,255,255,0.1)"></ol-style-fill>
<ol-style-circle :radius="7">
<ol-style-fill color="red"></ol-style-fill>
</ol-style-circle>
</ol-style>
</ol-vector-layer>
</ol-map>
</template>
<script setup>
import { ref } from "vue";
const center = ref([40, 40]);
const projection = ref("EPSG:4326");
const zoom = ref(8);
const rotation = ref(0);
const drawEnable = ref(true);
const drawType = ref("Polygon");
const drawstart = (event) => {
console.log(event);
};
const drawend = (event) => {
console.log(event);
};
</script>
Properties
type
- Type:
String
clickTolerance
- Type:
Number
- Default:
6
dragVertexDelay
- Type:
Number
- Default:
500
snapTolerance
- Type:
Number
- Default:
12
stopClick
- Type:
Boolean
- Default:
false
maxPoints
- Type:
Number
minPoints
- Type:
Number
finishCondition
- Type:
Function
geometryFunction
- Type:
Function
geometryName
- Type:
String
condition
- Type:
Function
freehand
- Type:
Boolean
- Default:
false
freehandCondition
- Type:
Function
wrapX
- Type:
Boolean
- Default:
false