X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/1f4e41f6725ea373aa13bbb067595e2c4fc326d8..f12c6b77ccd940784597cb306d1cb26e08072a15:/app/assets/javascripts/index.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 9a975c11c..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)); @@ -166,37 +168,11 @@ $(document).ready(function () { 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); @@ -233,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();