forked from openlayers/ol2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editing-methods.js
83 lines (80 loc) · 2.33 KB
/
editing-methods.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var map = new OpenLayers.Map({
div: "map",
layers: [
new OpenLayers.Layer.WMS(
"Global Imagery",
"http://maps.opengeo.org/geowebcache/service/wms",
{layers: "bluemarble"},
{tileOrigin: new OpenLayers.LonLat(-180, -90)}
),
new OpenLayers.Layer.Vector()
],
center: new OpenLayers.LonLat(0, 0),
zoom: 1
});
var draw = new OpenLayers.Control.DrawFeature(
map.layers[1], OpenLayers.Handler.Path
);
map.addControl(draw);
draw.activate();
// handle clicks on method links
document.getElementById("insertXY").onclick = function() {
var values = parseInput(
window.prompt(
"Enter map coordinates for new point (e.g. '-111, 46')", "x, y"
)
);
if (values != null) {
draw.insertXY(values[0], values[1]);
}
};
document.getElementById("insertDeltaXY").onclick = function() {
var values = parseInput(
window.prompt(
"Enter offset values for new point (e.g. '15, -10')", "dx, dy"
)
);
if (values != null) {
draw.insertDeltaXY(values[0], values[1]);
}
};
document.getElementById("insertDirectionLength").onclick = function() {
var values = parseInput(
window.prompt(
"Enter direction and length offset values for new point (e.g. '-45, 10')", "direction, length"
)
);
if (values != null) {
draw.insertDirectionLength(values[0], values[1]);
}
};
document.getElementById("insertDeflectionLength").onclick = function() {
var values = parseInput(
window.prompt(
"Enter deflection and length offset values for new point (e.g. '15, 20')", "deflection, length"
)
);
if (values != null) {
draw.insertDeflectionLength(values[0], values[1]);
}
};
document.getElementById("cancel").onclick = function() {
draw.cancel();
};
document.getElementById("finishSketch").onclick = function() {
draw.finishSketch();
};
function parseInput(text) {
var values = text.split(",");
if (values.length !== 2) {
values = null;
} else {
values[0] = parseFloat(values[0]);
values[1] = parseFloat(values[1]);
if (isNaN(values[0]) || isNaN(values[1])) {
window.alert("The two values must be numeric.");
values = null;
}
}
return values;
}