don't let users select areas bigger than allowed
This commit is contained in:
parent
adc823ce1b
commit
19a57c97b1
1 changed files with 32 additions and 13 deletions
|
@ -7,19 +7,21 @@ page << <<EOJ
|
||||||
OpenLayers.Feature.Vector.style['default'].cursor = "pointer";
|
OpenLayers.Feature.Vector.style['default'].cursor = "pointer";
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
openSidebar({ onclose: stopBrowse });
|
openSidebar({ onclose: stopBrowse });
|
||||||
var vectors = new OpenLayers.Layer.Vector();
|
var vectors = new OpenLayers.Layer.Vector();
|
||||||
|
|
||||||
box = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, {
|
box = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, {
|
||||||
handlerOptions: {
|
handlerOptions: {
|
||||||
sides: 4,
|
sides: 4,
|
||||||
snapAngle: 90,
|
snapAngle: 90,
|
||||||
irregular: true,
|
irregular: true,
|
||||||
persist: true,
|
persist: true,
|
||||||
callbacks: { done: endDrag }
|
callbacks: { done: endDrag }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
map.addControl(box);
|
map.addControl(box);
|
||||||
|
map.events.register("moveend", map, validateLinks);
|
||||||
|
map.events.triggerEvent("moveend");
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopBrowse() {
|
function stopBrowse() {
|
||||||
|
@ -35,6 +37,7 @@ page << <<EOJ
|
||||||
currentFeature.destroy();
|
currentFeature.destroy();
|
||||||
currentFeature = null;
|
currentFeature = null;
|
||||||
}
|
}
|
||||||
|
map.events.unregister("moveend", map, validateLinks);
|
||||||
}
|
}
|
||||||
|
|
||||||
function startDrag() {
|
function startDrag() {
|
||||||
|
@ -59,6 +62,7 @@ page << <<EOJ
|
||||||
getData(bounds);
|
getData(bounds);
|
||||||
$("drag_box").innerHTML = "Manually select a different area";
|
$("drag_box").innerHTML = "Manually select a different area";
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayFeatureWarning() {
|
function displayFeatureWarning() {
|
||||||
var div = document.createElement("div");
|
var div = document.createElement("div");
|
||||||
var p = document.createElement("p");
|
var p = document.createElement("p");
|
||||||
|
@ -106,11 +110,17 @@ page << <<EOJ
|
||||||
}
|
}
|
||||||
|
|
||||||
function getData(bounds) {
|
function getData(bounds) {
|
||||||
$("status").innerHTML = "Loading...";
|
|
||||||
|
|
||||||
bounds.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
|
bounds.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
|
||||||
|
var size = bounds.getWidth() * bounds.getHeight();
|
||||||
|
if (size > 0.25) {
|
||||||
|
$("status").innerHTML = "Unable to load: Bounding box size of " + size + " is too large. (Must be smaller than 0.25)";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var url = "/api/0.5/map?bbox="+bounds.toBBOX();
|
var url = "/api/0.5/map?bbox="+bounds.toBBOX();
|
||||||
|
|
||||||
|
$("status").innerHTML = "Loading...";
|
||||||
if (!gml) {
|
if (!gml) {
|
||||||
var def = OpenLayers.Feature.Vector.style['default'];
|
var def = OpenLayers.Feature.Vector.style['default'];
|
||||||
var style = new OpenLayers.Style();
|
var style = new OpenLayers.Style();
|
||||||
|
@ -257,6 +267,15 @@ page << <<EOJ
|
||||||
$("maxlon").innerHTML = Math.round(bounds.right * decimals) / decimals;
|
$("maxlon").innerHTML = Math.round(bounds.right * decimals) / decimals;
|
||||||
$("maxlat").innerHTML = Math.round(bounds.top * decimals) / decimals;
|
$("maxlat").innerHTML = Math.round(bounds.top * decimals) / decimals;
|
||||||
}
|
}
|
||||||
|
function validateLinks() {
|
||||||
|
var bounds = this.getExtent();
|
||||||
|
bounds = bounds.clone().transform(map.getProjectionObject(), epsg4326);
|
||||||
|
|
||||||
|
if (bounds.getWidth() * bounds.getHeight() > 0.25) {
|
||||||
|
$("use_map").style.display = "none";
|
||||||
|
} else {
|
||||||
|
$("use_map").style.display = "inline";
|
||||||
|
}
|
||||||
|
}
|
||||||
start();
|
start();
|
||||||
EOJ
|
EOJ
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue