Methods for programmatically manipulating sketches while digitizing features. r=bartvde (closes #3343)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@12103 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
83
examples/editing-methods.js
Normal file
83
examples/editing-methods.js
Normal file
@@ -0,0 +1,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
|
||||
$("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]);
|
||||
}
|
||||
}
|
||||
$("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]);
|
||||
}
|
||||
}
|
||||
$("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]);
|
||||
}
|
||||
}
|
||||
$("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]);
|
||||
}
|
||||
}
|
||||
$("cancel").onclick = function() {
|
||||
draw.cancel();
|
||||
}
|
||||
$("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;
|
||||
}
|
||||
Reference in New Issue
Block a user