想要在地图上绘制自由图形,只需要在new Draw的时候多加一个配置项就行。
function addInteraction() {
const value = typeSelect.value;
if (value !== "None") {
draw = new Draw({
source: source,
type: typeSelect.value,
freehand: true, //是否自由绘制
});
map.addInteraction(draw);
}
}
完整代码:
<template>
<div class="box">
<h1>Freehand Drawing</h1>
<div id="map"></div>
<form>
<label for="type">Geometry type </label>
<select id="type">
<option value="LineString">LineString</option>
<option value="Polygon">Polygon</option>
<option value="Circle">Circle</option>
<option value="None">No