X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/e316f0e425cc934295c8e64cdcf03f00899f287c..6616d5e1bab2c5e8db39a1aefe978c57fc7b3a0f:/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 e75ae9dd2..9d3f9a470 100644 --- a/app/assets/javascripts/index/browse.js +++ b/app/assets/javascripts/index/browse.js @@ -1,462 +1,123 @@ -//= require templates/browse/feature -//= require templates/browse/feature_list -//= require templates/browse/feature_history - -$(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").toggle(hideAreas, showAreas); - - 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 = unproj(bounds); - - 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')); - - 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')); - - 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 = unproj(bounds); - - 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( + $("