Rework export to not rely on ctrl+drag to select an area.
This commit is contained in:
parent
ab62a4b453
commit
7a9e92386e
2 changed files with 107 additions and 81 deletions
|
@ -12,23 +12,20 @@ page << <<EOJ
|
|||
|
||||
box = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, {
|
||||
handlerOptions: {
|
||||
keyMask: OpenLayers.Handler.MOD_CTRL,
|
||||
sides: 4,
|
||||
snapAngle: 90,
|
||||
irregular: true,
|
||||
persist: true,
|
||||
callbacks: { done: boxComplete }
|
||||
callbacks: { done: endDrag }
|
||||
}
|
||||
});
|
||||
map.addControl(box);
|
||||
|
||||
box.activate();
|
||||
|
||||
map.events.register("moveend", map, mapMoved);
|
||||
|
||||
openSidebar({ onclose: stopExport });
|
||||
|
||||
updateRegion(map.getExtent());
|
||||
setBounds(map.getExtent());
|
||||
|
||||
if (map.baseLayer.name == "Mapnik") {
|
||||
$("format_mapnik").checked = true;
|
||||
|
@ -51,6 +48,110 @@ page << <<EOJ
|
|||
map.removeLayer(vectors);
|
||||
}
|
||||
|
||||
function boundsChanged() {
|
||||
var epsg4326 = new OpenLayers.Projection("EPSG:4326");
|
||||
var bounds = new OpenLayers.Bounds($("minlon").value,
|
||||
$("minlat").value,
|
||||
$("maxlon").value,
|
||||
$("maxlat").value);
|
||||
|
||||
bounds.transform(epsg4326, map.getProjectionObject());
|
||||
|
||||
map.events.unregister("moveend", map, mapMoved);
|
||||
map.zoomToExtent(bounds);
|
||||
|
||||
clearBox();
|
||||
drawBox(bounds);
|
||||
|
||||
validateControls();
|
||||
}
|
||||
|
||||
$("maxlat").onchange = boundsChanged;
|
||||
$("minlon").onchange = boundsChanged;
|
||||
$("maxlon").onchange = boundsChanged;
|
||||
$("minlat").onchange = boundsChanged;
|
||||
|
||||
function startDrag() {
|
||||
$("drag_box").innerHTML='Drag a box on the map to select an area';
|
||||
|
||||
clearBox();
|
||||
box.activate();
|
||||
};
|
||||
|
||||
$("drag_box").onclick = startDrag;
|
||||
|
||||
function endDrag(bbox) {
|
||||
var bounds = bbox.getBounds();
|
||||
|
||||
map.events.unregister("moveend", map, mapMoved);
|
||||
setBounds(bounds);
|
||||
drawBox(bounds);
|
||||
box.deactivate();
|
||||
validateControls();
|
||||
|
||||
$("drag_box").innerHTML = "Manually select a different area";
|
||||
}
|
||||
|
||||
function mapMoved() {
|
||||
setBounds(map.getExtent());
|
||||
validateControls();
|
||||
}
|
||||
|
||||
function setBounds(bounds) {
|
||||
var epsg4326 = new OpenLayers.Projection("EPSG:4326");
|
||||
var decimals = Math.pow(10, Math.floor(map.getZoom() / 3));
|
||||
|
||||
bounds = bounds.clone().transform(map.getProjectionObject(), epsg4326);
|
||||
|
||||
$("minlon").value = Math.round(bounds.left * decimals) / decimals;
|
||||
$("minlat").value = Math.round(bounds.bottom * decimals) / decimals;
|
||||
$("maxlon").value = Math.round(bounds.right * decimals) / decimals;
|
||||
$("maxlat").value = Math.round(bounds.top * decimals) / decimals;
|
||||
}
|
||||
|
||||
function clearBox() {
|
||||
vectors.destroyFeatures();
|
||||
}
|
||||
|
||||
function drawBox(bounds) {
|
||||
var feature = new OpenLayers.Feature.Vector(bounds.toGeometry());
|
||||
|
||||
vectors.addFeatures(feature);
|
||||
}
|
||||
|
||||
function validateControls() {
|
||||
var bounds = new OpenLayers.Bounds($("minlon").value, $("minlat").value, $("maxlon").value, $("maxlat").value);
|
||||
|
||||
if (bounds.getWidth() * bounds.getHeight() > 0.25) {
|
||||
$("format_osm").disabled = true;
|
||||
$("format_osm").checked = false;
|
||||
$("export_osm").style.display = "none";
|
||||
} else {
|
||||
$("format_osm").disabled = false;
|
||||
}
|
||||
|
||||
var max_zoom = maxOsmarenderZoom();
|
||||
var max_scale = maxMapnikScale();
|
||||
|
||||
$("mapnik_max_scale").innerHTML = roundScale(max_scale);
|
||||
|
||||
mapnikScaleChanged();
|
||||
|
||||
for (var o = 0; o < $("osmarender_zoom").options.length; o++) {
|
||||
var option = $("osmarender_zoom").options[o];
|
||||
|
||||
if (option.value > max_zoom) {
|
||||
option.disabled = true;
|
||||
} else {
|
||||
option.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($("osmarender_zoom").options.selectedIndex + 4 > max_zoom) {
|
||||
$("osmarender_zoom").options.selectedIndex = max_zoom - 4;
|
||||
}
|
||||
}
|
||||
|
||||
function formatChanged() {
|
||||
if ($("format_osm").checked) {
|
||||
$("export_osm").style.display = "inline";
|
||||
|
@ -81,81 +182,6 @@ page << <<EOJ
|
|||
$("format_mapnik").onclick = formatChanged;
|
||||
$("format_osmarender").onclick = formatChanged;
|
||||
|
||||
function boundsChanged() {
|
||||
var epsg4326 = new OpenLayers.Projection("EPSG:4326");
|
||||
var bounds = new OpenLayers.Bounds($("minlon").value,
|
||||
$("minlat").value,
|
||||
$("maxlon").value,
|
||||
$("maxlat").value);
|
||||
|
||||
bounds.transform(epsg4326, map.getProjectionObject());
|
||||
|
||||
map.events.unregister("moveend", map, mapMoved);
|
||||
map.zoomToExtent(bounds);
|
||||
|
||||
box.handler.clear();
|
||||
box.handler.feature = new OpenLayers.Feature.Vector(bounds.toGeometry());
|
||||
box.handler.layer.addFeatures([box.handler.feature], [box.handler.style]);
|
||||
box.handler.layer.drawFeature(box.handler.feature, box.handler.style);
|
||||
|
||||
mapnikSizeChanged();
|
||||
}
|
||||
|
||||
$("maxlat").onchange = boundsChanged;
|
||||
$("minlon").onchange = boundsChanged;
|
||||
$("maxlon").onchange = boundsChanged;
|
||||
$("minlat").onchange = boundsChanged;
|
||||
|
||||
function mapMoved() {
|
||||
updateRegion(map.getExtent());
|
||||
}
|
||||
|
||||
function boxComplete(box) {
|
||||
map.events.unregister("moveend", map, mapMoved);
|
||||
updateRegion(box.getBounds());
|
||||
}
|
||||
|
||||
function updateRegion(bounds) {
|
||||
var epsg4326 = new OpenLayers.Projection("EPSG:4326");
|
||||
var decimals = Math.pow(10, Math.floor(map.getZoom() / 3));
|
||||
|
||||
bounds.transform(map.getProjectionObject(), epsg4326);
|
||||
|
||||
$("minlon").value = Math.round(bounds.left * decimals) / decimals;
|
||||
$("minlat").value = Math.round(bounds.bottom * decimals) / decimals;
|
||||
$("maxlon").value = Math.round(bounds.right * decimals) / decimals;
|
||||
$("maxlat").value = Math.round(bounds.top * decimals) / decimals;
|
||||
|
||||
if (bounds.getWidth() * bounds.getHeight() > 0.25) {
|
||||
$("format_osm").disabled = true;
|
||||
$("format_osm").checked = false;
|
||||
$("export_osm").style.display = "none";
|
||||
} else {
|
||||
$("format_osm").disabled = false;
|
||||
}
|
||||
|
||||
var max_zoom = maxOsmarenderZoom();
|
||||
var max_scale = maxMapnikScale();
|
||||
|
||||
$("mapnik_max_scale").innerHTML = roundScale(max_scale);
|
||||
|
||||
mapnikScaleChanged();
|
||||
|
||||
for (var o = 0; o < $("osmarender_zoom").options.length; o++) {
|
||||
var option = $("osmarender_zoom").options[o];
|
||||
|
||||
if (option.value > max_zoom) {
|
||||
option.disabled = true;
|
||||
} else {
|
||||
option.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($("osmarender_zoom").options.selectedIndex + 4 > max_zoom) {
|
||||
$("osmarender_zoom").options.selectedIndex = max_zoom - 4;
|
||||
}
|
||||
}
|
||||
|
||||
function maxMapnikScale() {
|
||||
var bounds = new OpenLayers.Bounds($("minlon").value, $("minlat").value, $("maxlon").value, $("maxlat").value);
|
||||
var epsg4326 = new OpenLayers.Projection("EPSG:4326");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue