X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/13289d404188bd397ee72852f66c415a2bb87066..a9824dbc2e8763e6fff6f71db7a31cc4761cd245:/app/views/export/start.js.erb diff --git a/app/views/export/start.js.erb b/app/views/export/start.js.erb index 80e9de1d8..e433a498f 100644 --- a/app/views/export/start.js.erb +++ b/app/views/export/start.js.erb @@ -1,5 +1,6 @@ var vectors; var box; +var transform; var markerLayer; var markerControl; @@ -20,6 +21,13 @@ function startExport() { box.handler.callbacks.done = endDrag; map.addControl(box); + transform = new OpenLayers.Control.TransformFeature(vectors, { + rotate: false, + irregular: true + }); + transform.events.register("transformcomplete", transform, transformComplete); + map.addControl(transform); + map.events.register("moveend", map, mapMoved); map.events.register("changebaselayer", map, htmlUrlChanged); @@ -37,7 +45,6 @@ function startExport() { $("#format_osm").click(formatChanged); $("#format_mapnik").click(formatChanged); - $("#format_osmarender").click(formatChanged); $("#format_html").click(formatChanged); $("#mapnik_scale").change(mapnikSizeChanged); @@ -46,8 +53,6 @@ function startExport() { if (map.baseLayer.name == "Mapnik") { $("#format_mapnik").prop("checked", true); - } else if (map.baseLayer.name == "Osmarender") { - $("#format_osmarender").prop("checked", true); } formatChanged(); @@ -104,6 +109,11 @@ function endDrag(bbox) { $("#drag_box").html("<%=j t 'export.start_rjs.manually_select' %>"); } +function transformComplete(event) { + setBounds(event.feature.geometry.bounds); + validateControls(); +} + function startMarker() { $("#add_marker").html("<%=j t 'export.start_rjs.click_add_marker' %>"); @@ -111,7 +121,7 @@ function startMarker() { markerLayer = new OpenLayers.Layer.Vector("",{ displayInLayerSwitcher: false, style: { - externalGraphic: OpenLayers.Util.getImagesLocation() + "marker.png", + externalGraphic: OpenLayers.Util.getImageLocation("marker.png"), graphicXOffset: -10.5, graphicYOffset: -25, graphicWidth: 21, @@ -183,6 +193,7 @@ function setBounds(bounds) { } function clearBox() { + transform.deactivate(); vectors.destroyFeatures(); } @@ -190,6 +201,7 @@ function drawBox(bounds) { var feature = new OpenLayers.Feature.Vector(bounds.toGeometry()); vectors.addFeatures(feature); + transform.setFeature(feature); } function validateControls() { @@ -202,30 +214,16 @@ function validateControls() { } var max_scale = maxMapnikScale(); + var disabled = true; - if ($("#format_osm").prop("checked") && bounds.getWidth() * bounds.getHeight() > <%= MAX_REQUEST_AREA %>) { - $("#export_commit").prop("disabled", true); - } else if ($("#format_mapnik").prop("checked") && $("#mapnik_scale").val() < max_scale) { - $("#export_commit").prop("disabled", true); - } else { - $("#export_commit").prop("disabled", false); + if ($("#format_osm").prop("checked")) { + disabled = bounds.getWidth() * bounds.getHeight() > <%= MAX_REQUEST_AREA %>; + } else if ($("#format_mapnik").prop("checked")) { + disabled = $("#mapnik_scale").val() < max_scale; } + $("#export_commit").prop("disabled", disabled); $("#mapnik_max_scale").html(roundScale(max_scale)); - - var max_zoom = maxOsmarenderZoom(); - - $("#osmarender_zoom option").each(function () { - if ($(this).val() > max_zoom) { - $(this).prop("disabled", true); - } else { - $(this).prop("disabled", false); - } - }); - - if ($("#osmarender_zoom option").is(":disabled:selected")) { - $("#osmarender_zoom option").filter(":enabled").last().prop("selected", true); - } } function htmlUrlChanged() { @@ -276,15 +274,6 @@ function formatChanged() { $("#export_mapnik").hide(); } - if ($("#format_osmarender").prop("checked")) { - var zoom = Math.min(map.getZoom(), maxOsmarenderZoom()); - - $("#osmarender_zoom option[value=" + zoom + "]").prop("selected", true); - $("#export_osmarender").show(); - } else { - $("#export_osmarender").hide(); - } - if ($("#format_html").prop("checked")) { $("#export_html").show(); $("#export_commit").hide(); @@ -319,16 +308,6 @@ function mapnikImageSize(scale) { Math.round(bounds.getHeight() / scale / 0.00028)); } -function maxOsmarenderZoom() { - var bounds = new OpenLayers.Bounds($("#minlon").val(), $("#minlat").val(), $("#maxlon").val(), $("#maxlat").val()); - var xzoom = Math.LOG2E * Math.log(2000 * 1.40625 / bounds.getWidth()); - var ymin = bounds.bottom * Math.PI / 180; - var ymax = bounds.top * Math.PI / 180; - var yzoom = Math.LOG2E * (Math.log(2000 * 2 * Math.PI) - Math.log(Math.log((Math.tan(ymax) + 1 / Math.cos(ymax)) / (Math.tan(ymin) + 1 / Math.cos(ymin))))) - - return Math.min(Math.floor(Math.min(xzoom, yzoom)), 17); -} - function roundScale(scale) { var precision = 5 * Math.pow(10, Math.floor(Math.LOG10E * Math.log(scale)) - 2);