diff --git a/WebContent/base/osrm/OSRM.MapView.js b/WebContent/base/osrm/OSRM.MapView.js index 89a114a97..e6f2404a8 100644 --- a/WebContent/base/osrm/OSRM.MapView.js +++ b/WebContent/base/osrm/OSRM.MapView.js @@ -43,6 +43,14 @@ OSRM.MapView = L.Map.extend({ bounds.extend( this.unproject(ne_point,zoom) ); this.fitBounds( bounds ); }, + getBoundsUI: function(unbounded) { + var bounds = this.getPixelBounds(); + if( OSRM.GUI.visible == true ) + bounds.min.x+=OSRM.GUI.width; + var sw = this.unproject(new L.Point(bounds.min.x, bounds.max.y), this._zoom, true), + ne = this.unproject(new L.Point(bounds.max.x, bounds.min.y), this._zoom, true); + return new L.LatLngBounds(sw, ne); + }, getCenterUI: function(unbounded) { var viewHalf = this.getSize(); if( OSRM.GUI.visible == true ) diff --git a/WebContent/gui/OSRM.RoutingGUI.js b/WebContent/gui/OSRM.RoutingGUI.js index cf49c3455..22268d5e4 100644 --- a/WebContent/gui/OSRM.RoutingGUI.js +++ b/WebContent/gui/OSRM.RoutingGUI.js @@ -78,16 +78,22 @@ inputChanged: function(marker_id) { // click: button "open JOSM" openJOSM: function() { - var x = OSRM.G.map.getCenterUI(); - var ydelta = 0.01; - var xdelta = ydelta * 2; - var p = [ 'left=' + (x.lng - xdelta), 'bottom=' + (x.lat - ydelta), 'right=' + (x.lng + xdelta), 'top=' + (x.lat + ydelta)]; - var url = 'http://localhost:8111/load_and_zoom?' + p.join('&'); + var center = OSRM.G.map.getCenterUI(); + var bounds = OSRM.G.map.getBoundsUI(); - var frame = L.DomUtil.create('iframe', null, document.body); - frame.style.width = frame.style.height = "0px"; + var xdelta = Math.min(0.02, Math.abs(bounds.getSouthWest().lng - center.lng) ); + var ydelta = Math.min(0.01, Math.abs(bounds.getSouthWest().lat - center.lat) ); + + var p = [ 'left=' + (center.lng - xdelta), 'bottom=' + (center.lat - ydelta), 'right=' + (center.lng + xdelta), 'top=' + (center.lat + ydelta)]; + var url = 'http://127.0.0.1:8111/load_and_zoom?' + p.join('&'); + + var frame = document.getElementById('josm-frame'); + if(!frame) { + frame = L.DomUtil.create('iframe', null, document.body); + frame.style.display = "none"; + frame.id = 'josm-frame'; + } frame.src = url; - frame.onload = function(e) { document.body.removeChild(frame); }; }, //click: button "open OSM Bugs" @@ -111,4 +117,4 @@ deleteMarker: function(marker_id) { OSRM.G.markers.highlight.hide(); } -}; \ No newline at end of file +};