Permalink
Browse files

Merge branch 'trial/dragging' into develop

Conflicts:
	WebContent/OSRM.JSONP.js
	WebContent/OSRM.debug.js
	WebContent/main.html
  • Loading branch information...
2 parents 0ab287e + 4638e7c commit bab2887f8f7b17d6346e5f18d0464a66d8ae4e98 @DennisSchiefer DennisSchiefer committed Apr 3, 2012
View
@@ -11,7 +11,7 @@ Setup
-----
The frontend should work directly as provided.
Several settings - including the URL for the routing server and the geocoder server - can be specified in `OSRM.config.js`.
-Different tile servers can be specified in `OSRM.main.js`.
+Different tile servers can be specified in `OSRM.Map.js`.
Note that the URL shortener used for generating route links only works with URLs pointing to the official Project-OSRM website.
View
@@ -0,0 +1,80 @@
+/*
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU AFFERO General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+or see http://www.gnu.org/licenses/agpl.txt.
+*/
+
+// Leaflet bugfixes
+// [assorted bugfixes to Leaflet functions we use]
+
+
+// return closest point on segment or distance to that point
+L.LineUtil._sqClosestPointOnSegment = function (p, p1, p2, sqDist) {
+ var x = p1.x,
+ y = p1.y,
+ dx = p2.x - x,
+ dy = p2.y - y,
+ dot = dx * dx + dy * dy,
+ t;
+
+ if (dot > 0) {
+ t = ((p.x - x) * dx + (p.y - y) * dy) / dot;
+
+ if (t > 1) {
+ x = p2.x;
+ y = p2.y;
+ } else if (t > 0) {
+ x += dx * t;
+ y += dy * t;
+ }
+ }
+
+ dx = p.x - x;
+ dy = p.y - y;
+
+ // DS_CHANGE: modified return values
+ if(sqDist)
+ return dx*dx + dy*dy;
+ else {
+ var p = new L.Point(x,y);
+ p._sqDist = dx*dx + dy*dy;
+ return p;
+ }
+};
+
+
+// makes requestAnimFrame respect the immediate paramter -> prevents drag events after dragend events
+// (alternatively: add if(!this.dragging ) return to L.Draggable._updatePosition, but must be done in leaflet.js!)
+// [TODO: In Leaflet 0.4 use L.Util.cancelAnimFrame(this._animRequest) in L.Draggable._onUp() instead, also has to be done in leaflet.js!]
+L.Util.requestAnimFrame = (function () {
+ function timeoutDefer(callback) {
+ window.setTimeout(callback, 1000 / 60);
+ }
+
+ var requestFn = window.requestAnimationFrame ||
+ window.webkitRequestAnimationFrame ||
+ window.mozRequestAnimationFrame ||
+ window.oRequestAnimationFrame ||
+ window.msRequestAnimationFrame ||
+ timeoutDefer;
+
+ return function (callback, context, immediate, contextEl) {
+ callback = context ? L.Util.bind(callback, context) : callback;
+ if (immediate ) { // DS_CHANGE: removed additional condition requestFn === timeoutDefer
+ callback();
+ } else {
+ requestFn(callback, contextEl);
+ }
+ };
+}());
@@ -16,30 +16,41 @@ or see http://www.gnu.org/licenses/agpl.txt.
*/
// Leaflet extension: MouseMarker
-// [marker class that propagates modifier and button presses]
-// [currently deactivated: propagation mousemove events]
+// [marker class that propagates modifier and button presses in mouse click events and allows for changing icons]
// extended marker class
L.MouseMarker = L.Marker.extend({
initialize: function (latlng, options) {
L.Marker.prototype.initialize.apply(this, arguments);
},
+
+ switchIcon: function( icon ) {
+ this.options.icon = icon;
-// _initInteraction: function (){
-// L.Marker.prototype._initInteraction.apply(this, arguments);
-// if (this.options.clickable)
-// L.DomEvent.addListener(this._icon, 'mousemove', this._fireMouseEvent, this);
-// },
-
-// _fireMouseEvent: function (e) {
-// this.fire(e.type, {
-// latlng: this._map.mouseEventToLatLng(e),
-// layerPoint: this._map.mouseEventToLayerPoint(e)
-// });
-// L.DomEvent.stopPropagation(e);
-// },
+ if (this._map) {
+ this._changeIcon();
+ this._reset();
+ }
+ },
+ _changeIcon: function () {
+ var options = this.options;
+
+ if (this._icon) {
+ this._icon = options.icon.switchIcon( this._icon );
+ this._icon.title = options.title;
+ }
+
+ var panes = this._map._panes;
+
+ if (this._shadow)
+ panes.shadowPane.removeChild(this._shadow);
+ this._shadow = options.icon.createShadow();
+ if (this._shadow)
+ panes.shadowPane.appendChild(this._shadow);
+ },
+
_onMouseClick: function (e) {
L.DomEvent.stopPropagation(e);
if (this.dragging && this.dragging.moved()) { return; }
@@ -0,0 +1,115 @@
+/*
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU AFFERO General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+or see http://www.gnu.org/licenses/agpl.txt.
+*/
+
+// Leaflet extension: SwitchableIcon
+// [will be an extension of L.Icon in Leaflet 0.4, for now it is a copy with added functionality]
+
+
+// icon class with functions to simply switch the icon images
+L.SwitchableIcon = L.Class.extend({
+ options: {
+ /*
+ iconUrl: (String) (required)
+ iconSize: (Point) (can be set through CSS)
+ iconAnchor: (Point) (centered by default if size is specified, can be set in CSS with negative margins)
+ popupAnchor: (Point) (if not specified, popup opens in the anchor point)
+ shadowUrl: (Point) (no shadow by default)
+ shadowSize: (Point)
+ */
+ className: ''
+ },
+
+ initialize: function (options) {
+ L.Util.setOptions(this, options);
+ },
+
+ createIcon: function () {
+ return this._createIcon('icon');
+ },
+
+ createShadow: function () {
+ return this.options.shadowUrl ? this._createIcon('shadow') : null;
+ },
+
+ _createIcon: function (name) {
+ var img = this._createImg(this.options[name + 'Url']);
+ this._setIconStyles(img, name);
+ return img;
+ },
+
+ _setIconStyles: function (img, name) {
+ var options = this.options,
+ size = options[name + 'Size'],
+ anchor = options.iconAnchor;
+
+ if (!anchor && size) {
+ anchor = size.divideBy(2, true);
+ }
+
+ if (name === 'shadow' && anchor && options.shadowOffset) {
+ anchor._add(options.shadowOffset);
+ }
+
+ img.className = 'leaflet-marker-' + name + ' ' + options.className;
+
+ if (anchor) {
+ img.style.marginLeft = (-anchor.x) + 'px';
+ img.style.marginTop = (-anchor.y) + 'px';
+ }
+
+ if (size) {
+ img.style.width = size.x + 'px';
+ img.style.height = size.y + 'px';
+ }
+ },
+
+ _createImg: function (src) {
+ var el;
+ if (!L.Browser.ie6) {
+ el = document.createElement('img');
+ el.src = src;
+ } else {
+ el = document.createElement('div');
+ el.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '")';
+ }
+ return el;
+ },
+
+ // new functions start here
+ switchIcon: function (el) {
+ return this._switchIcon('icon', el);
+ },
+
+ switchShadow: function (el) {
+ return this.options.shadowUrl ? this._switchIcon('shadow', el) : null;
+ },
+
+ _switchIcon: function (name, el) {
+ var img = this._switchImg(this.options[name + 'Url'], el);
+ this._setIconStyles(img, name);
+ return img;
+ },
+
+ _switchImg: function (src, el) {
+ if (!L.Browser.ie6) {
+ el.src = src;
+ } else {
+ el.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '")';
+ }
+ return el;
+ }
+});
View
@@ -20,10 +20,34 @@ or see http://www.gnu.org/licenses/agpl.txt.
OSRM.GUI = {
+
+// defaults
+visible: null,
+width: null,
-// default state
-visible: true,
-width: 410,
+// init GUI
+init: function() {
+ OSRM.GUI.visible = true;
+ OSRM.GUI.width = document.getElementById("main-wrapper").clientWidth;
+
+ // translate
+ document.getElementById("open-josm").innerHTML = OSRM.loc("OPEN_JOSM");
+ document.getElementById("open-osmbugs").innerHTML = OSRM.loc("OPEN_OSMBUGS");
+ document.getElementById("gui-reset").innerHTML = OSRM.loc("GUI_RESET");
+ document.getElementById("gui-reverse").innerHTML = OSRM.loc("GUI_REVERSE");
+ document.getElementById("gui-option-highlight-nonames-label").innerHTML = OSRM.loc("GUI_HIGHLIGHT_UNNAMED_ROADS");
+ document.getElementById("options-toggle").innerHTML = OSRM.loc("GUI_OPTIONS");
+ document.getElementById("gui-search-source").innerHTML = OSRM.loc("GUI_SEARCH");
+ document.getElementById("gui-search-target").innerHTML = OSRM.loc("GUI_SEARCH");
+ document.getElementById("gui-search-source-label").innerHTML = OSRM.loc("GUI_START")+":";
+ document.getElementById("gui-search-target-label").innerHTML = OSRM.loc("GUI_END")+":";
+ document.getElementById("input-source-name").title = OSRM.loc("GUI_START_TOOLTIP");
+ document.getElementById("input-target-name").title = OSRM.loc("GUI_END_TOOLTIP");
+ document.getElementById("legal-notice").innerHTML = OSRM.loc("GUI_LEGAL_NOTICE");
+
+ document.getElementById('input-source-name').value = OSRM.DEFAULTS.ONLOAD_SOURCE;
+ document.getElementById('input-target-name').value = OSRM.DEFAULTS.ONLOAD_TARGET;
+},
// show/hide main-gui
toggleMain: function() {
@@ -60,7 +60,7 @@ _onclickResult: function(marker_id, lat, lon) {
OSRM.G.markers.route[index].show();
OSRM.G.markers.route[index].centerView();
- getRoute(OSRM.C.FULL_DESCRIPTION);
+ OSRM.Routing.getRoute();
},
View
@@ -66,8 +66,8 @@ OSRM.JSONP = {
OSRM.JSONP.fences[id] = undefined; // clean fence
}
- OSRM.JSONP.sum[id] += new Number( new Date() - OSRM.JSONP.durations[id] );
- OSRM.debug.log("[jsonp] response handling: "+id+" "+ (OSRM.JSONP.sum[id]/OSRM.JSONP.counter[id]).toFixed(2) );
+// OSRM.JSONP.sum[id] += new Number( new Date() - OSRM.JSONP.durations[id] );
+// OSRM.debug.log("[jsonp] response handling: "+id+" "+ (OSRM.JSONP.sum[id]/OSRM.JSONP.counter[id]).toFixed(2) );
};
// clean DOM (unfortunately, script elements cannot be reused by all browsers)
@@ -85,12 +85,11 @@ OSRM.JSONP = {
// start timeout timer
OSRM.JSONP.timers[id] = setTimeout(OSRM.JSONP.timeouts[id], timeout);
- // statistics
- if(!OSRM.JSONP.durations) { OSRM.JSONP.durations = {}; OSRM.JSONP.counter = {}; OSRM.JSONP.sum = {}; }
- if(OSRM.JSONP.counter[id]) OSRM.JSONP.counter[id]++; else {OSRM.JSONP.counter[id] = 1;OSRM.JSONP.sum[id] = 0;}
- OSRM.JSONP.durations[id] = new Date();
-
-// OSRM.debug.log("[jsonp] init: "+id);
+// if(!OSRM.JSONP.durations) { OSRM.JSONP.durations = {}; OSRM.JSONP.counter = {}; OSRM.JSONP.sum = {}; }
+// if(OSRM.JSONP.counter[id]) OSRM.JSONP.counter[id]++; else {OSRM.JSONP.counter[id] = 1;OSRM.JSONP.sum[id] = 0;}
+// OSRM.JSONP.durations[id] = new Date();
+// OSRM.debug.log("[jsonp] init: "+id);
+
return true;
},
@@ -101,4 +100,4 @@ OSRM.JSONP = {
OSRM.JSONP.timeouts = {};
OSRM.JSONP.timers = {};
}
-};
+};
@@ -39,12 +39,14 @@ OSRM.loc = OSRM.Localization.translate;
// German language support
OSRM.Localization["de"] = {
//gui
+"OPEN_JOSM": "JOSM",
+"OPEN_OSMBUGS": "OSM Bugs",
"GUI_START": "Start",
"GUI_END": "Ziel",
"GUI_RESET": "Reset",
"GUI_SEARCH": "Zeigen",
"GUI_REVERSE": "Umdrehen",
-"GUI_OPTIONS": "Optionen",
+"GUI_OPTIONS": "Kartenwerkzeuge",
"GUI_HIGHLIGHT_UNNAMED_ROADS": "Unbenannte Straßen hervorheben",
"GUI_START_TOOLTIP": "Startposition eingeben",
"GUI_END_TOOLTIP": "Zielposition eingeben",
@@ -80,12 +82,14 @@ OSRM.Localization["de"] = {
// English language support
OSRM.Localization["en"] = {
//gui
+"OPEN_JOSM": "JOSM",
+"OPEN_OSMBUGS": "OSM Bugs",
"GUI_START": "Start",
"GUI_END": "End",
"GUI_RESET": "  Reset  ",
"GUI_SEARCH": "  Show  ",
"GUI_REVERSE": "Reverse",
-"GUI_OPTIONS": "Options",
+"GUI_OPTIONS": "Mapping Tools",
"GUI_HIGHLIGHT_UNNAMED_ROADS": "Highlight unnamed streets",
"GUI_START_TOOLTIP": "Enter start",
"GUI_END_TOOLTIP": "Enter destination",
Oops, something went wrong.

0 comments on commit bab2887

Please sign in to comment.