X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/c8f8dbca19f9f1ed3539f93e1785d4de70f2b093..7094370208712e77d92ea2ad0d76e160742d6c0a:/app/assets/javascripts/index.js?ds=sidebyside diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index c96d18afd..029c0bfd1 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -1,5 +1,5 @@ //= require_self -//= require leaflet.customzoom +//= require leaflet.sidebar //= require leaflet.locate //= require leaflet.layers //= require leaflet.key @@ -51,37 +51,43 @@ $(document).ready(function () { map.noteLayer = new L.LayerGroup({code: 'N'}); map.dataLayer = new L.OSM.DataLayer(null); - $("#map").on("resized", function () { + $("#sidebar").on("opened closed", function () { map.invalidateSize(); }); - L.control.customZoom({position: 'topright'}) + var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright'; + + L.OSM.zoom({position: position}) .addTo(map); - L.control.locate({position: 'topright'}) + L.control.locate({position: position}) .addTo(map); - var uiPane = $('#map-ui')[0]; + var sidebar = L.OSM.sidebar('#map-ui') + .addTo(map); L.OSM.layers({ - position: 'topright', + position: position, layers: layers, - uiPane: uiPane + sidebar: sidebar }).addTo(map); L.OSM.key({ - position: 'topright', - uiPane: uiPane + position: position, + sidebar: sidebar }).addTo(map); - L.OSM.note({ - position: 'topright', - uiPane: uiPane + L.OSM.share({ + position: position, + getShortUrl: getShortUrl, + getUrl: getUrl, + sidebar: sidebar, + short: true }).addTo(map); - L.OSM.share({ - getUrl: getShortUrl, - uiPane: uiPane + L.OSM.note({ + position: position, + sidebar: sidebar }).addTo(map); L.control.scale() @@ -133,8 +139,6 @@ $(document).ready(function () { addObjectToMap(params.object, map, { zoom: params.object_zoom }); } - handleResize(); - $("body").on("click", "a.set_position", setPositionLink(map)); $("a[data-editor=remote]").click(function(e) { @@ -146,8 +150,6 @@ $(document).ready(function () { remoteEditHandler(map.getBounds()); } - $(window).resize(handleResize); - $("#search_form").submit(submitSearch(map)); @@ -161,41 +163,16 @@ $(document).ready(function () { $("#query").focus(); } + initializeExport(map); initializeBrowse(map); initializeNotes(map); }); -function getMapBaseLayerId(map) { - for (var i in map._layers) { // TODO: map.eachLayer - var layer = map._layers[i]; - if (layer.options && layer.options.keyid) { - return layer.options.keyid; - } - } -} - -function getMapLayers(map) { - var layerConfig = ''; - for (var i in map._layers) { // TODO: map.eachLayer - var layer = map._layers[i]; - if (layer.options && layer.options.code) { - layerConfig += layer.options.code; - } - } - return layerConfig; -} - -// generate a cookie-safe string of map state -function cookieContent(map) { - var center = map.getCenter().wrap(); - return [center.lng, center.lat, map.getZoom(), getMapLayers(map)].join('|'); -} - function updateLocation() { updatelinks(this.getCenter().wrap(), this.getZoom(), - getMapLayers(this), - this.getBounds().wrap(), {}); + this.getLayersCode(), + this.getBounds().wrap()); var expiry = new Date(); expiry.setYear(expiry.getFullYear() + 10); @@ -232,10 +209,10 @@ function submitSearch(map) { $("#sidebar_title").html(I18n.t('site.sidebar.search_results')); $("#sidebar_content").load($(this).attr("action"), { query: $("#query").val(), - minlon: bounds.getWestLng(), - minlat: bounds.getSouthLat(), - maxlon: bounds.getEastLng(), - maxlat: bounds.getNorthLat() + minlon: bounds.getWest(), + minlat: bounds.getSouth(), + maxlon: bounds.getEast(), + maxlat: bounds.getNorth() }, openSidebar); return e.preventDefault();