-
Notifications
You must be signed in to change notification settings - Fork 0
/
ol-map-polygon-draw.js
43 lines (38 loc) · 1003 Bytes
/
ol-map-polygon-draw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// global
var draw;
// Add draw to map
function addInteractions(value = 'Polygon', geometryFunction)
{
if (value !== 'None')
{
// @type {ol.geom.GeometryType}
// var geometryFunction = function(coordinates, geometry) {};
var maxPoints = 100000;
draw = new ol.interaction.Draw({
source: Source,
type: (value),
geometryFunction: geometryFunction,
maxPoints: maxPoints
});
map.addInteraction(draw);
}else{
console.log("Error draw value: Point, Polygon, LineString, Circle, Square, Box");
}
}
// Remove draw from map
function removeInteractions()
{
map.removeInteraction(draw);
}
// Callback does not works (delete)
function Geometry(coordinates, geometry)
{
if (geometry == undefined)
{
geometry = new ol.geom.Polygon(null);
}
console.log("Polygon points: ", coordinates);
return geometry;
};
// Allow draw polygon on map
addInteractions('Polygon');