X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/b95f9115d7edf13ccdf8aac5e91251bf05d3084f..b79e4f04b9197e1c1954638db46c9d97597612d4:/app/assets/javascripts/index/browse.js?ds=sidebyside diff --git a/app/assets/javascripts/index/browse.js b/app/assets/javascripts/index/browse.js index 891e1c9bc..69d625eca 100644 --- a/app/assets/javascripts/index/browse.js +++ b/app/assets/javascripts/index/browse.js @@ -1,558 +1,124 @@ -$(document).ready(function () { - $("#show_data").click(function (e) { - $.ajax({ url: $(this).attr('href'), success: function (sidebarHtml) { - startBrowse(sidebarHtml); - }}); - e.preventDefault(); - }); - - function startBrowse(sidebarHtml) { - var browseBoxControl; - var browseMode = "auto"; - var browseBounds; - var browseFeatureList; - var browseActiveFeature; - var browseDataLayer; - var browseSelectControl; - var browseObjectList; - var areasHidden = false; - - OpenLayers.Feature.Vector.style['default'].strokeWidth = 3; - OpenLayers.Feature.Vector.style['default'].cursor = "pointer"; - - map.dataLayer.active = true; - - $("#sidebar_title").html(I18n.t('browse.start_rjs.data_frame_title')); - $("#sidebar_content").html(sidebarHtml); - - openSidebar(); - - var vectors = new OpenLayers.Layer.Vector(); - - browseBoxControl = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, { - handlerOptions: { - sides: 4, - snapAngle: 90, - irregular: true, - persist: true - } - }); - browseBoxControl.handler.callbacks.done = endDrag; - map.addControl(browseBoxControl); - - map.events.register("moveend", map, updateData); - map.events.triggerEvent("moveend"); - - $("#browse_select_view").click(useMap); - - $("#browse_select_box").click(startDrag); - - $("#browse_hide_areas_box").html(I18n.t('browse.start_rjs.hide_areas')); - $("#browse_hide_areas_box").show(); - $("#browse_hide_areas_box").click(hideAreas); - - function updateData() { - if (browseMode == "auto") { - if (map.getZoom() >= 15) { - useMap(false); - } else { - setStatus(I18n.t('browse.start_rjs.zoom_or_select')); - } - } +OSM.initializeBrowse = function (map) { + var browseBounds; + var dataLayer = map.dataLayer; + + dataLayer.setStyle({ + way: { + weight: 3, + color: "#000000", + opacity: 0.4 + }, + area: { + weight: 3, + color: "#ff0000" + }, + node: { + color: "#00ff00" } + }); - $("#sidebar").one("closed", function () { - if (map.dataLayer.active) { - map.dataLayer.active = false; - - if (browseSelectControl) { - browseSelectControl.destroy(); - browseSelectControl = null; - } - - if (browseBoxControl) { - browseBoxControl.destroy(); - browseBoxControl = null; - } - - if (browseActiveFeature) { - browseActiveFeature.destroy(); - browseActiveFeature = null; - } - - if (browseDataLayer) { - browseDataLayer.destroy(); - browseDataLayer = null; - } - - map.dataLayer.setVisibility(false); - map.events.unregister("moveend", map, updateData); - } - }); - - function startDrag() { - $("#browse_select_box").html(I18n.t('browse.start_rjs.drag_a_box')); - - browseBoxControl.activate(); - - return false; - } - - function useMap(reload) { - var bounds = map.getExtent(); - var projected = bounds.clone().transform(map.getProjectionObject(), epsg4326); - - if (!browseBounds || !browseBounds.containsBounds(projected)) { - var center = bounds.getCenterLonLat(); - var tileWidth = bounds.getWidth() * 1.2; - var tileHeight = bounds.getHeight() * 1.2; - var tileBounds = new OpenLayers.Bounds(center.lon - (tileWidth / 2), - center.lat - (tileHeight / 2), - center.lon + (tileWidth / 2), - center.lat + (tileHeight / 2)); - - browseBounds = tileBounds; - getData(tileBounds, reload); - - browseMode = "auto"; + dataLayer.isWayArea = function () { + return false; + }; - $("#browse_select_view").hide(); - } + dataLayer.on("click", function (e) { + onSelect(e.layer); + }); - return false; + map.on("layeradd", function (e) { + if (e.layer === dataLayer) { + map.on("moveend", updateData); + updateData(); } + }); - function hideAreas() { - $("#browse_hide_areas_box").html(I18n.t('browse.start_rjs.show_areas')); - $("#browse_hide_areas_box").show(); - $("#browse_hide_areas_box").click(showAreas); - - areasHidden = true; - - useMap(true); + map.on("layerremove", function (e) { + if (e.layer === dataLayer) { + map.off("moveend", updateData); + $("#browse_status").empty(); } + }); - function showAreas() { - $("#browse_hide_areas_box").html(I18n.t('browse.start_rjs.hide_areas')); - $("#browse_hide_areas_box").show(); - $("#browse_hide_areas_box").click(hideAreas); - - areasHidden = false; - - useMap(true); + function updateData() { + var bounds = map.getBounds(); + if (!browseBounds || !browseBounds.contains(bounds)) { + getData(); } + } - function endDrag(bbox) { - var bounds = bbox.getBounds(); - var projected = bounds.clone().transform(map.getProjectionObject(), epsg4326); - - browseBoxControl.deactivate(); - browseBounds = projected; - getData(bounds); - - browseMode = "manual"; + function displayFeatureWarning(count, limit, add, cancel) { + $("#browse_status").html( + $("
").append( + $("
").append( + $("

") + .text(I18n.t("browse.start_rjs.load_data")), + $("
").append( + $("