!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),(f.L||(f.L={})).Routing=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { // Select the first entry this._select(1); } }, _createClickListener: function(r) { var resultSelected = this._resultSelected(r); return L.bind(function() { this._elem.blur(); resultSelected(); }, this); }, _resultSelected: function(r) { return L.bind(function() { this.close(); this._elem.value = r.name; this._lastCompletedText = r.name; this._selectFn(r); }, this); }, _keyPressed: function(e) { var index; if (this._isOpen && e.keyCode === 13 && this._selection) { index = parseInt(this._selection.getAttribute('data-result-index'), 10); this._resultSelected(this._results[index])(); L.DomEvent.preventDefault(e); return; } if (e.keyCode === 13) { this._complete(this._resultFn, true); return; } if (this._autocomplete && document.activeElement === this._elem) { if (this._timer) { clearTimeout(this._timer); } this._timer = setTimeout(L.Util.bind(function() { this._complete(this._autocomplete); }, this), this.options.timeout); return; } this._unselect(); }, _select: function(dir) { var sel = this._selection; if (sel) { L.DomUtil.removeClass(sel.firstChild, 'leaflet-routing-geocoder-selected'); sel = sel[dir > 0 ? 'nextSibling' : 'previousSibling']; } if (!sel) { sel = this._resultTable[dir > 0 ? 'firstChild' : 'lastChild']; } if (sel) { L.DomUtil.addClass(sel.firstChild, 'leaflet-routing-geocoder-selected'); this._selection = sel; } }, _unselect: function() { if (this._selection) { L.DomUtil.removeClass(this._selection.firstChild, 'leaflet-routing-geocoder-selected'); } delete this._selection; }, _keyDown: function(e) { if (this._isOpen) { switch (e.keyCode) { // Escape case 27: this.close(); L.DomEvent.preventDefault(e); return; // Up case 38: this._select(-1); L.DomEvent.preventDefault(e); return; // Down case 40: this._select(1); L.DomEvent.preventDefault(e); return; } } }, _complete: function(completeFn, trySelect) { var v = this._elem.value; function completeResults(results) { this._lastCompletedText = v; if (trySelect && results.length === 1) { this._resultSelected(results[0])(); } else { this._setResults(results); } } if (!v) { return; } if (v !== this._lastCompletedText) { completeFn(v, completeResults, this); } else if (trySelect) { completeResults.call(this, this._results); } } }); })(); },{}],2:[function(require,module,exports){ (function (global){ (function() { 'use strict'; var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null); L.Routing = L.Routing || {}; L.extend(L.Routing, require('./L.Routing.Itinerary')); L.extend(L.Routing, require('./L.Routing.Line')); L.extend(L.Routing, require('./L.Routing.Plan')); L.extend(L.Routing, require('./L.Routing.OSRM')); L.Routing.Control = L.Routing.Itinerary.extend({ options: { fitSelectedRoutes: 'smart', routeLine: function(route, options) { return L.Routing.line(route, options); }, autoRoute: true, routeWhileDragging: false, routeDragInterval: 500, waypointMode: 'connect', useZoomParameter: false }, initialize: function(options) { L.Util.setOptions(this, options); this._router = this.options.router || new L.Routing.OSRM(options); this._plan = this.options.plan || L.Routing.plan(this.options.waypoints, options); this._requestCount = 0; L.Routing.Itinerary.prototype.initialize.call(this, options); this.on('routeselected', this._routeSelected, this); this._plan.on('waypointschanged', this._onWaypointsChanged, this); if (options.routeWhileDragging) { this._setupRouteDragging(); } if (this.options.autoRoute) { this.route(); } }, onAdd: function(map) { var container = L.Routing.Itinerary.prototype.onAdd.call(this, map); this._map = map; this._map.addLayer(this._plan); if (this.options.useZoomParameter) { this._map.on('zoomend', function() { this.route({ callback: L.bind(this._updateLineCallback, this) }); }, this); } if (this._plan.options.geocoder) { container.insertBefore(this._plan.createGeocoders(), container.firstChild); } return container; }, onRemove: function(map) { if (this._line) { map.removeLayer(this._line); } map.removeLayer(this._plan); return L.Routing.Itinerary.prototype.onRemove.call(this, map); }, getWaypoints: function() { return this._plan.getWaypoints(); }, setWaypoints: function(waypoints) { this._plan.setWaypoints(waypoints); return this; }, spliceWaypoints: function() { var removed = this._plan.spliceWaypoints.apply(this._plan, arguments); return removed; }, getPlan: function() { return this._plan; }, _routeSelected: function(e) { var route = e.route, fitMode = this.options.fitSelectedRoutes, fitBounds = (fitMode === 'smart' && !this._waypointsVisible()) || (fitMode !== 'smart' && fitMode); this._updateLine(route); if (fitBounds) { this._map.fitBounds(this._line.getBounds()); } if (this.options.waypointMode === 'snap') { this._plan.off('waypointschanged', this._onWaypointsChanged, this); this.setWaypoints(route.waypoints); this._plan.on('waypointschanged', this._onWaypointsChanged, this); } }, _waypointsVisible: function() { var wps = this.getWaypoints(), mapSize, bounds, boundsSize, i, p; try { mapSize = this._map.getSize(); for (i = 0; i < wps.length; i++) { p = this._map.latLngToLayerPoint(wps[i].latLng); if (bounds) { bounds.extend(p); } else { bounds = L.bounds([p]); } } boundsSize = bounds.getSize(); return (boundsSize.x > mapSize.x / 5 || boundsSize.y > mapSize.y / 5) && this._waypointsInViewport(); } catch (e) { return false; } }, _waypointsInViewport: function() { var wps = this.getWaypoints(), mapBounds, i; try { mapBounds = this._map.getBounds(); } catch (e) { return false; } for (i = 0; i < wps.length; i++) { if (mapBounds.contains(wps[i].latLng)) { return true; } } return false; }, _updateLine: function(route) { var addWaypoints = this.options.addWaypoints !== undefined ? this.options.addWaypoints : true; this._clearLine(); this._line = this.options.routeLine(route, L.extend({ addWaypoints: addWaypoints, extendToWaypoints: this.options.waypointMode === 'connect' }, this.options.lineOptions)); this._line.addTo(this._map); this._hookEvents(this._line); }, _hookEvents: function(l) { l.on('linetouched', function(e) { this._plan.dragNewWaypoint(e); }, this); }, _onWaypointsChanged: function(e) { if (this.options.autoRoute) { this.route({}); } if (!this._plan.isReady()) { this._clearLine(); this._clearAlts(); } this.fire('waypointschanged', {waypoints: e.waypoints}); }, _setupRouteDragging: function() { var timer = 0, waypoints; this._plan.on('waypointdrag', L.bind(function(e) { waypoints = e.waypoints; if (!timer) { timer = setTimeout(L.bind(function() { this.route({ waypoints: waypoints, geometryOnly: true, callback: L.bind(this._updateLineCallback, this) }); timer = undefined; }, this), this.options.routeDragInterval); } }, this)); this._plan.on('waypointdragend', function() { if (timer) { clearTimeout(timer); timer = undefined; } this.route(); }, this); }, _updateLineCallback: function(err, routes) { if (!err) { this._updateLine(routes[0]); } }, route: function(options) { var ts = ++this._requestCount, wps; options = options || {}; if (this._plan.isReady()) { if (this.options.useZoomParameter) { options.z = this._map && this._map.getZoom(); } wps = options && options.waypoints || this._plan.getWaypoints(); this.fire('routingstart', {waypoints: wps}); this._router.route(wps, options.callback || function(err, routes) { // Prevent race among multiple requests, // by checking the current request's timestamp // against the last request's; ignore result if // this isn't the latest request. if (ts === this._requestCount) { this._clearLine(); this._clearAlts(); if (err) { this.fire('routingerror', {error: err}); return; } if (!options.geometryOnly) { this.fire('routesfound', {waypoints: wps, routes: routes}); this.setAlternatives(routes); } else { this._routeSelected({route: routes[0]}); } } }, this, options); } }, _clearLine: function() { if (this._line) { this._map.removeLayer(this._line); delete this._line; } } }); L.Routing.control = function(options) { return new L.Routing.Control(options); }; module.exports = L.Routing; })(); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./L.Routing.Itinerary":4,"./L.Routing.Line":6,"./L.Routing.OSRM":8,"./L.Routing.Plan":9}],3:[function(require,module,exports){ (function (global){ (function() { 'use strict'; var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null); L.Routing = L.Routing || {}; L.extend(L.Routing, require('./L.Routing.Localization')); L.Routing.Formatter = L.Class.extend({ options: { units: 'metric', unitNames: { meters: 'm', kilometers: 'km', yards: 'yd', miles: 'mi', hours: 'h', minutes: 'mín', seconds: 's' }, language: 'en', roundingSensitivity: 1, distanceTemplate: '{value} {unit}' }, initialize: function(options) { L.setOptions(this, options); }, formatDistance: function(d /* Number (meters) */) { var un = this.options.unitNames, v, data; if (this.options.units === 'imperial') { d = d / 1.609344; if (d >= 1000) { data = { value: (this._round(d) / 1000), unit: un.miles }; } else { data = { value: this._round(d / 1.760), unit: un.yards }; } } else { v = this._round(d); data = { value: v >= 1000 ? (v / 1000) : v, unit: v >= 1000 ? un.kilometers : un.meters }; } return L.Util.template(this.options.distanceTemplate, data); }, _round: function(d) { var pow10 = Math.pow(10, (Math.floor(d / this.options.roundingSensitivity) + '').length - 1), r = Math.floor(d / pow10), p = (r > 5) ? pow10 : pow10 / 2; return Math.round(d / p) * p; }, formatTime: function(t /* Number (seconds) */) { if (t > 86400) { return Math.round(t / 3600) + ' h'; } else if (t > 3600) { return Math.floor(t / 3600) + ' h ' + Math.round((t % 3600) / 60) + ' min'; } else if (t > 300) { return Math.round(t / 60) + ' min'; } else if (t > 60) { return Math.floor(t / 60) + ' min' + (t % 60 !== 0 ? ' ' + (t % 60) + ' s' : ''); } else { return t + ' s'; } }, formatInstruction: function(instr, i) { if (instr.type !== undefined) { return L.Util.template(this._getInstructionTemplate(instr, i), L.extend({ exitStr: L.Routing.Localization[this.options.language].formatOrder(instr.exit), dir: L.Routing.Localization[this.options.language].directions[instr.direction] }, instr)); } else { return instr.text; } }, getIconName: function(instr, i) { switch (instr.type) { case 'Straight': return (i === 0 ? 'depart' : 'continue'); case 'SlightRight': return 'bear-right'; case 'Right': return 'turn-right'; case 'SharpRight': return 'sharp-right'; case 'TurnAround': return 'u-turn'; case 'SharpLeft': return 'sharp-left'; case 'Left': return 'turn-left'; case 'SlightLeft': return 'slight-left'; case 'WaypointReached': return 'arrive'; case 'Roundabout': return 'enter-roundabout'; case 'DestinationReached': return 'arrive'; } }, _getInstructionTemplate: function(instr, i) { var type = instr.type === 'Straight' ? (i === 0 ? 'Head' : 'Continue') : instr.type, strings = L.Routing.Localization[this.options.language].instructions[type]; return strings[0] + (strings.length > 1 && instr.road ? strings[1] : ''); }, }); module.exports = L.Routing; })(); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./L.Routing.Localization":7}],4:[function(require,module,exports){ (function (global){ (function() { 'use strict'; var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null); L.Routing = L.Routing || {}; L.extend(L.Routing, require('./L.Routing.Formatter')); L.extend(L.Routing, require('./L.Routing.ItineraryBuilder')); L.Routing.Itinerary = L.Control.extend({ includes: L.Mixin.Events, options: { pointMarkerStyle: { radius: 5, color: '#03f', fillColor: 'white', opacity: 1, fillOpacity: 0.7 }, summaryTemplate: '

{name}

{distance}, {time}

', timeTemplate: '{time}', containerClassName: '', alternativeClassName: '', minimizedClassName: '', itineraryClassName: '', show: true }, initialize: function(options) { L.setOptions(this, options); this._formatter = this.options.formatter || new L.Routing.Formatter(this.options); this._itineraryBuilder = this.options.itineraryBuilder || new L.Routing.ItineraryBuilder({ containerClassName: this.options.itineraryClassName }); }, onAdd: function() { this._container = L.DomUtil.create('div', 'leaflet-routing-container leaflet-bar ' + (!this.options.show ? 'leaflet-routing-container-hide' : '') + this.options.containerClassName); this._altContainer = this.createAlternativesContainer(); this._container.appendChild(this._altContainer); L.DomEvent.disableClickPropagation(this._container); L.DomEvent.addListener(this._container, 'mousewheel', function(e) { L.DomEvent.stopPropagation(e); }); return this._container; }, onRemove: function() { }, createAlternativesContainer: function() { return L.DomUtil.create('div', 'leaflet-routing-alternatives-container'); }, setAlternatives: function(routes) { var i, alt, altDiv; this._clearAlts(); this._routes = routes; for (i = 0; i < this._routes.length; i++) { alt = this._routes[i]; altDiv = this._createAlternative(alt, i); this._altContainer.appendChild(altDiv); this._altElements.push(altDiv); } this.fire('routeselected', {route: this._routes[0]}); return this; }, show: function() { L.DomUtil.removeClass(this._container, 'leaflet-routing-container-hide'); }, hide: function() { L.DomUtil.addClass(this._container, 'leaflet-routing-container-hide'); }, _createAlternative: function(alt, i) { var altDiv = L.DomUtil.create('div', 'leaflet-routing-alt ' + this.options.alternativeClassName + (i > 0 ? ' leaflet-routing-alt-minimized ' + this.options.minimizedClassName : '')); altDiv.innerHTML = L.Util.template(this.options.summaryTemplate, { name: alt.name, distance: this._formatter.formatDistance(alt.summary.totalDistance), time: this._formatter.formatTime(alt.summary.totalTime) }); L.DomEvent.addListener(altDiv, 'click', this._onAltClicked, this); altDiv.appendChild(this._createItineraryContainer(alt)); return altDiv; }, _clearAlts: function() { var el = this._altContainer; while (el && el.firstChild) { el.removeChild(el.firstChild); } this._altElements = []; }, _createItineraryContainer: function(r) { var container = this._itineraryBuilder.createContainer(), steps = this._itineraryBuilder.createStepsContainer(), i, instr, step, distance, text, icon; container.appendChild(steps); for (i = 0; i < r.instructions.length; i++) { instr = r.instructions[i]; text = this._formatter.formatInstruction(instr, i); distance = this._formatter.formatDistance(instr.distance); icon = this._formatter.getIconName(instr, i); step = this._itineraryBuilder.createStep(text, distance, icon, steps); this._addRowListeners(step, r.coordinates[instr.index]); } return container; }, _addRowListeners: function(row, coordinate) { var _this = this, marker; L.DomEvent.addListener(row, 'mouseover', function() { marker = L.circleMarker(coordinate, _this.options.pointMarkerStyle).addTo(_this._map); }); L.DomEvent.addListener(row, 'mouseout', function() { if (marker) { _this._map.removeLayer(marker); marker = null; } }); L.DomEvent.addListener(row, 'click', function(e) { _this._map.panTo(coordinate); L.DomEvent.stopPropagation(e); }); }, _onAltClicked: function(e) { var altElem, j, n, isCurrentSelection, classFn; altElem = e.target || window.event.srcElement; while (!L.DomUtil.hasClass(altElem, 'leaflet-routing-alt')) { altElem = altElem.parentElement; } if (L.DomUtil.hasClass(altElem, 'leaflet-routing-alt-minimized')) { for (j = 0; j < this._altElements.length; j++) { n = this._altElements[j]; isCurrentSelection = altElem === n; classFn = isCurrentSelection ? 'removeClass' : 'addClass'; L.DomUtil[classFn](n, 'leaflet-routing-alt-minimized'); if (this.options.minimizedClassName) { L.DomUtil[classFn](n, this.options.minimizedClassName); } if (isCurrentSelection) { // TODO: don't fire if the currently active is clicked this.fire('routeselected', {route: this._routes[j]}); } else { n.scrollTop = 0; } } } L.DomEvent.stop(e); }, }); L.Routing.itinerary = function(router) { return new L.Routing.Itinerary(router); }; module.exports = L.Routing; })(); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./L.Routing.Formatter":3,"./L.Routing.ItineraryBuilder":5}],5:[function(require,module,exports){ (function (global){ (function() { 'use strict'; var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null); L.Routing = L.Routing || {}; L.Routing.ItineraryBuilder = L.Class.extend({ options: { containerClassName: '' }, initialize: function(options) { L.setOptions(this, options); }, createContainer: function() { return L.DomUtil.create('table', this.options.containerClassName); }, createStepsContainer: function() { return L.DomUtil.create('tbody', ''); }, createStep: function(text, distance, icon, steps) { var row = L.DomUtil.create('tr', '', steps), span, td; td = L.DomUtil.create('td', '', row); span = L.DomUtil.create('span', 'leaflet-routing-icon leaflet-routing-icon-'+icon, td); td.appendChild(span); td = L.DomUtil.create('td', '', row); td.appendChild(document.createTextNode(text)); td = L.DomUtil.create('td', '', row); td.appendChild(document.createTextNode(distance)); return row; } }); module.exports = L.Routing; })(); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{}],6:[function(require,module,exports){ (function (global){ (function() { 'use strict'; var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null); L.Routing = L.Routing || {}; L.Routing.Line = L.LayerGroup.extend({ includes: L.Mixin.Events, options: { styles: [ {color: 'black', opacity: 0.15, weight: 9}, {color: 'white', opacity: 0.8, weight: 6}, {color: 'red', opacity: 1, weight: 2} ], missingRouteStyles: [ {color: 'black', opacity: 0.15, weight: 7}, {color: 'white', opacity: 0.6, weight: 4}, {color: 'gray', opacity: 0.8, weight: 2, dashArray: '7,12'} ], addWaypoints: true, extendToWaypoints: true, missingRouteTolerance: 10 }, initialize: function(route, options) { L.setOptions(this, options); L.LayerGroup.prototype.initialize.call(this, options); this._route = route; if (this.options.extendToWaypoints) { this._extendToWaypoints(); } this._addSegment( route.coordinates, this.options.styles, this.options.addWaypoints); }, addTo: function(map) { map.addLayer(this); return this; }, getBounds: function() { return L.latLngBounds(this._route.coordinates); }, _findWaypointIndices: function() { var wps = this._route.inputWaypoints, indices = [], i; for (i = 0; i < wps.length; i++) { indices.push(this._findClosestRoutePoint(wps[i].latLng)); } return indices; }, _findClosestRoutePoint: function(latlng) { var minDist = Number.MAX_VALUE, minIndex, i, d; for (i = this._route.coordinates.length - 1; i >= 0 ; i--) { // TODO: maybe do this in pixel space instead? d = latlng.distanceTo(this._route.coordinates[i]); if (d < minDist) { minIndex = i; minDist = d; } } return minIndex; }, _extendToWaypoints: function() { var wps = this._route.inputWaypoints, wpIndices = this._getWaypointIndices(), i, wpLatLng, routeCoord; for (i = 0; i < wps.length; i++) { wpLatLng = wps[i].latLng; routeCoord = L.latLng(this._route.coordinates[wpIndices[i]]); if (wpLatLng.distanceTo(routeCoord) > this.options.missingRouteTolerance) { this._addSegment([wpLatLng, routeCoord], this.options.missingRouteStyles); } } }, _addSegment: function(coords, styles, mouselistener) { var i, pl; for (i = 0; i < styles.length; i++) { pl = L.polyline(coords, styles[i]); this.addLayer(pl); if (mouselistener) { pl.on('mousedown', this._onLineTouched, this); } } }, _findNearestWpBefore: function(i) { var wpIndices = this._getWaypointIndices(), j = wpIndices.length - 1; while (j >= 0 && wpIndices[j] > i) { j--; } return j; }, _onLineTouched: function(e) { var afterIndex = this._findNearestWpBefore(this._findClosestRoutePoint(e.latlng)); this.fire('linetouched', { afterIndex: afterIndex, latlng: e.latlng }); }, _getWaypointIndices: function() { if (!this._wpIndices) { this._wpIndices = this._route.waypointIndices || this._findWaypointIndices(); } return this._wpIndices; } }); L.Routing.line = function(route, options) { return new L.Routing.Line(route, options); }; module.exports = L.Routing; })(); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{}],7:[function(require,module,exports){ (function() { 'use strict'; L.Routing = L.Routing || {}; L.Routing.Localization = { 'en': { directions: { N: 'north', NE: 'northeast', E: 'east', SE: 'southeast', S: 'south', SW: 'southwest', W: 'west', NW: 'northwest' }, instructions: { // instruction, postfix if the road is named 'Head': ['Head {dir}', ' on {road}'], 'Continue': ['Continue {dir}', ' on {road}'], 'SlightRight': ['Slight right', ' onto {road}'], 'Right': ['Right', ' onto {road}'], 'SharpRight': ['Sharp right', ' onto {road}'], 'TurnAround': ['Turn around'], 'SharpLeft': ['Sharp left', ' onto {road}'], 'Left': ['Left', ' onto {road}'], 'SlightLeft': ['Slight left', ' onto {road}'], 'WaypointReached': ['Waypoint reached'], 'Roundabout': ['Take the {exitStr} exit in the roundabout'], 'DestinationReached': ['Destination reached'], }, formatOrder: function(n) { var i = n % 10 - 1, suffix = ['st', 'nd', 'rd']; return suffix[i] ? n + suffix[i] : n + 'th'; } }, 'de': { directions: { N: 'Norden', NE: 'Nordosten', E: 'Osten', SE: 'Südosten', S: 'Süden', SW: 'Südwesten', W: 'Westen', NW: 'Nordwesten' }, instructions: { // instruction, postfix if the road is named 'Head': ['Richtung {dir}', ' auf {road}'], 'Continue': ['Geradeaus Richtung {dir}', ' auf {road}'], 'SlightRight': ['Leicht rechts abbiegen', ' auf {road}'], 'Right': ['Rechts abbiegen', ' auf {road}'], 'SharpRight': ['Scharf rechts abbiegen', ' auf {road}'], 'TurnAround': ['Wenden'], 'SharpLeft': ['Scharf links abbiegen', ' auf {road}'], 'Left': ['Links abbiegen', ' auf {road}'], 'SlightLeft': ['Leicht links abbiegen', ' auf {road}'], 'WaypointReached': ['Zwischenhalt erreicht'], 'Roundabout': ['Nehmen Sie die {exitStr} Ausfahrt im Kreisverkehr'], 'DestinationReached': ['Sie haben ihr Ziel erreicht'], }, formatOrder: function(n) { return n + '.'; } }, 'sv': { directions: { N: 'norr', NE: 'nordost', E: 'öst', SE: 'sydost', S: 'syd', SW: 'sydväst', W: 'väst', NW: 'nordväst' }, instructions: { // instruction, postfix if the road is named 'Head': ['Åk åt {dir}', ' på {road}'], 'Continue': ['Fortsätt {dir}', ' på {road}'], 'SlightRight': ['Svagt höger', ' på {road}'], 'Right': ['Sväng höger', ' på {road}'], 'SharpRight': ['Skarpt höger', ' på {road}'], 'TurnAround': ['Vänd'], 'SharpLeft': ['Skarpt vänster', ' på {road}'], 'Left': ['Sväng vänster', ' på {road}'], 'SlightLeft': ['Svagt vänster', ' på {road}'], 'WaypointReached': ['Viapunkt nådd'], 'Roundabout': ['Tag {exitStr} avfarten i rondellen'], 'DestinationReached': ['Framme vid resans mål'], }, formatOrder: function(n) { return ['första', 'andra', 'tredje', 'fjärde', 'femte', 'sjätte', 'sjunde', 'åttonde', 'nionde', 'tionde' /* Can't possibly be more than ten exits, can there? */][n - 1]; } }, 'sp': { directions: { N: 'norte', NE: 'noreste', E: 'este', SE: 'sureste', S: 'sur', SW: 'suroeste', W: 'oeste', NW: 'noroeste' }, instructions: { // instruction, postfix if the road is named 'Head': ['Derecho {dir}', ' sobre {road}'], 'Continue': ['Continuar {dir}', ' en {road}'], 'SlightRight': ['Leve giro a la derecha', ' sobre {road}'], 'Right': ['Derecha', ' sobre {road}'], 'SharpRight': ['Giro pronunciado a la derecha', ' sobre {road}'], 'TurnAround': ['Dar vuelta'], 'SharpLeft': ['Giro pronunciado a la izquierda', ' sobre {road}'], 'Left': ['Izquierda', ' en {road}'], 'SlightLeft': ['Leve giro a la izquierda', ' en {road}'], 'WaypointReached': ['Llegó a un punto del camino'], 'Roundabout': ['Tomar {exitStr} salida en la rotonda'], 'DestinationReached': ['Llegada a destino'], }, formatOrder: function(n) { return n + 'º'; } } }; module.exports = L.Routing; })(); },{}],8:[function(require,module,exports){ (function (global){ (function() { 'use strict'; var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null); // Ignore camelcase naming for this file, since OSRM's API uses // underscores. /* jshint camelcase: false */ L.Routing = L.Routing || {}; L.extend(L.Routing, require('./L.Routing.Waypoint')); L.Routing._jsonpCallbackId = 0; L.Routing._jsonp = function(url, callback, context, jsonpParam) { var callbackId = '_l_routing_machine_' + (L.Routing._jsonpCallbackId++), script; url += '&' + jsonpParam + '=' + callbackId; window[callbackId] = L.Util.bind(callback, context); script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; script.id = callbackId; document.getElementsByTagName('head')[0].appendChild(script); }; L.Routing.OSRM = L.Class.extend({ options: { serviceUrl: '//router.project-osrm.org/viaroute', timeout: 30 * 1000 }, initialize: function(options) { L.Util.setOptions(this, options); this._hints = { locations: {} }; }, route: function(waypoints, callback, context, options) { var timedOut = false, timer = setTimeout(function() { timedOut = true; callback.call(context || callback, { status: -1, message: 'OSRM request timed out.' }); }, this.options.timeout), wps = [], wp, url, i; // Create a copy of the waypoints, since they // might otherwise be asynchronously modified while // the request is being processed. for (i = 0; i < waypoints.length; i++) { wp = waypoints[i]; wps.push(new L.Routing.Waypoint(wp.latLng, wp.name, wp.options)); } options = options || {}; url = this._buildRouteUrl(wps, options); L.Routing._jsonp(url, function(data) { clearTimeout(timer); if (!timedOut) { this._routeDone(data, wps, callback, context); } }, this, 'jsonp'); return this; }, _routeDone: function(response, inputWaypoints, callback, context) { var coordinates, alts, actualWaypoints, i; context = context || callback; if (response.status !== 0) { callback.call(context, { status: response.status, message: response.status_message }); return; } coordinates = this._decode(response.route_geometry, 6); actualWaypoints = this._toWaypoints(inputWaypoints, response.via_points); alts = [{ name: response.route_name.join(', '), coordinates: coordinates, instructions: response.route_instructions ? this._convertInstructions(response.route_instructions) : [], summary: response.route_summary ? this._convertSummary(response.route_summary) : [], inputWaypoints: inputWaypoints, waypoints: actualWaypoints, waypointIndices: this._clampIndices(response.via_indices, coordinates) }]; if (response.alternative_geometries) { for (i = 0; i < response.alternative_geometries.length; i++) { coordinates = this._decode(response.alternative_geometries[i], 6); alts.push({ name: response.alternative_names[i].join(', '), coordinates: coordinates, instructions: response.alternative_instructions[i] ? this._convertInstructions(response.alternative_instructions[i]) : [], summary: response.alternative_summaries[i] ? this._convertSummary(response.alternative_summaries[i]) : [], inputWaypoints: inputWaypoints, waypoints: actualWaypoints, waypointIndices: this._clampIndices(response.alternative_geometries.length === 1 ? // Unsure if this is a bug in OSRM or not, but alternative_indices // does not appear to be an array of arrays, at least not when there is // a single alternative route. response.alternative_indices : response.alternative_indices[i], coordinates) }); } } this._saveHintData(response, inputWaypoints); callback.call(context, null, alts); }, _toWaypoints: function(inputWaypoints, vias) { var wps = [], i; for (i = 0; i < vias.length; i++) { wps.push(L.Routing.waypoint(L.latLng(vias[i]), inputWaypoints[i].name, inputWaypoints[i].options)); } return wps; }, _buildRouteUrl: function(waypoints, options) { var locs = [], computeInstructions, computeAlternative, locationKey, hint; for (var i = 0; i < waypoints.length; i++) { locationKey = this._locationKey(waypoints[i].latLng); locs.push('loc=' + locationKey); hint = this._hints.locations[locationKey]; if (hint) { locs.push('hint=' + hint); } if (waypoints[i].options.allowUTurn) { locs.push('u=true'); } } computeAlternative = computeInstructions = !(options && options.geometryOnly); return this.options.serviceUrl + '?' + 'instructions=' + computeInstructions + '&' + 'alt=' + computeAlternative + '&' + (options.z ? 'z=' + options.z + '&' : '') + locs.join('&') + (this._hints.checksum !== undefined ? '&checksum=' + this._hints.checksum : ''); }, _locationKey: function(location) { return location.lat + ',' + location.lng; }, _saveHintData: function(route, waypoints) { var hintData = route.hint_data, loc; this._hints = { checksum: hintData.checksum, locations: {} }; for (var i = hintData.locations.length - 1; i >= 0; i--) { loc = waypoints[i].latLng; this._hints.locations[this._locationKey(loc)] = hintData.locations[i]; } }, // Adapted from // https://github.com/DennisSchiefer/Project-OSRM-Web/blob/develop/WebContent/routing/OSRM.RoutingGeometry.js _decode: function(encoded, precision) { var len = encoded.length, index=0, lat=0, lng = 0, array = []; precision = Math.pow(10, -precision); while (index < len) { var b, shift = 0, result = 0; do { b = encoded.charCodeAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); var dlat = ((result & 1) ? ~(result >> 1) : (result >> 1)); lat += dlat; shift = 0; result = 0; do { b = encoded.charCodeAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); var dlng = ((result & 1) ? ~(result >> 1) : (result >> 1)); lng += dlng; //array.push( {lat: lat * precision, lng: lng * precision} ); array.push( [lat * precision, lng * precision] ); } return array; }, _convertSummary: function(osrmSummary) { return { totalDistance: osrmSummary.total_distance, totalTime: osrmSummary.total_time }; }, _convertInstructions: function(osrmInstructions) { var result = [], i, instr, type, driveDir; for (i = 0; i < osrmInstructions.length; i++) { instr = osrmInstructions[i]; type = this._drivingDirectionType(instr[0]); driveDir = instr[0].split('-'); if (type) { result.push({ type: type, distance: instr[2], time: instr[4], road: instr[1], direction: instr[6], exit: driveDir.length > 1 ? driveDir[1] : undefined, index: instr[3] }); } } return result; }, _drivingDirectionType: function(d) { switch (parseInt(d, 10)) { case 1: return 'Straight'; case 2: return 'SlightRight'; case 3: return 'Right'; case 4: return 'SharpRight'; case 5: return 'TurnAround'; case 6: return 'SharpLeft'; case 7: return 'Left'; case 8: return 'SlightRight'; case 9: return 'WaypointReached'; case 10: // TODO: "Head on" // https://github.com/DennisOSRM/Project-OSRM/blob/master/DataStructures/TurnInstructions.h#L48 return 'Straight'; case 11: case 12: return 'Roundabout'; case 15: return 'DestinationReached'; default: return null; } }, _clampIndices: function(indices, coords) { var maxCoordIndex = coords.length - 1, i; for (i = 0; i < indices.length; i++) { indices[i] = Math.min(maxCoordIndex, Math.max(indices[i], 0)); } } }); L.Routing.osrm = function(options) { return new L.Routing.OSRM(options); }; module.exports = L.Routing; })(); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./L.Routing.Waypoint":10}],9:[function(require,module,exports){ (function (global){ (function() { 'use strict'; var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null); L.Routing = L.Routing || {}; L.extend(L.Routing, require('./L.Routing.Autocomplete')); L.extend(L.Routing, require('./L.Routing.Waypoint')); function selectInputText(input) { if (input.setSelectionRange) { // On iOS, select() doesn't work input.setSelectionRange(0, 9999); } else { // On at least IE8, setSeleectionRange doesn't exist input.select(); } } L.Routing.Plan = L.Class.extend({ includes: L.Mixin.Events, options: { dragStyles: [ {color: 'black', opacity: 0.15, weight: 9}, {color: 'white', opacity: 0.8, weight: 6}, {color: 'red', opacity: 1, weight: 2, dashArray: '7,12'} ], draggableWaypoints: true, addWaypoints: true, maxGeocoderTolerance: 200, autocompleteOptions: {}, geocodersClassName: '', geocoderClassName: '', geocoderPlaceholder: function(i, numberWaypoints) { return i === 0 ? 'Start' : (i < numberWaypoints - 1 ? 'Via ' + i : 'End'); }, geocoderClass: function() { return ''; }, createGeocoder: function() { var container = L.DomUtil.create('div', ''), input = L.DomUtil.create('input', '', container), remove = L.DomUtil.create('span', 'leaflet-routing-remove-waypoint', container); return { container: container, input: input, closeButton: remove }; }, waypointNameFallback: function(latLng) { var ns = latLng.lat < 0 ? 'S' : 'N', ew = latLng.lng < 0 ? 'W' : 'E', lat = (Math.round(Math.abs(latLng.lat) * 10000) / 10000).toString(), lng = (Math.round(Math.abs(latLng.lng) * 10000) / 10000).toString(); return ns + lat + ', ' + ew + lng; } }, initialize: function(waypoints, options) { L.Util.setOptions(this, options); this._waypoints = []; this.setWaypoints(waypoints); }, isReady: function() { var i; for (i = 0; i < this._waypoints.length; i++) { if (!this._waypoints[i].latLng) { return false; } } return true; }, getWaypoints: function() { var i, wps = []; for (i = 0; i < this._waypoints.length; i++) { wps.push(this._waypoints[i]); } return wps; }, setWaypoints: function(waypoints) { var args = [0, this._waypoints.length].concat(waypoints); this.spliceWaypoints.apply(this, args); return this; }, spliceWaypoints: function() { var args = [arguments[0], arguments[1]], i, wp; for (i = 2; i < arguments.length; i++) { args.push(arguments[i] && arguments[i].hasOwnProperty('latLng') ? arguments[i] : L.Routing.waypoint(arguments[i])); } [].splice.apply(this._waypoints, args); while (this._waypoints.length < 2) { wp = L.Routing.waypoint(); this._waypoints.push(wp); args.push(wp); } this._updateMarkers(); this._fireChanged.apply(this, args); }, onAdd: function(map) { this._map = map; this._updateMarkers(); }, onRemove: function() { var i; this._removeMarkers(); if (this._newWp) { for (i = 0; i < this._newWp.lines.length; i++) { this._map.removeLayer(this._newWp.lines[i]); } } delete this._map; }, createGeocoders: function() { var container = L.DomUtil.create('div', 'leaflet-routing-geocoders ' + this.options.geocodersClassName), waypoints = this._waypoints, i, geocoderElem, addWpBtn; this._geocoderContainer = container; this._geocoderElems = []; for (i = 0; i < waypoints.length; i++) { geocoderElem = this._createGeocoder(i); container.appendChild(geocoderElem.container); this._geocoderElems.push(geocoderElem); } addWpBtn = L.DomUtil.create('button', '', container); addWpBtn.setAttribute('type', 'button'); addWpBtn.innerHTML = '+'; if (this.options.addWaypoints) { L.DomEvent.addListener(addWpBtn, 'click', function() { this.spliceWaypoints(waypoints.length, 0, null); }, this); } else { addWpBtn.style.display = 'none'; } this.on('waypointsspliced', this._updateGeocoders); return container; }, _createGeocoder: function(i) { var nWps = this._waypoints.length, g = this.options.createGeocoder(i, nWps), closeButton = g.closeButton, geocoderInput = g.input, wp = this._waypoints[i]; geocoderInput.setAttribute('placeholder', this.options.geocoderPlaceholder(i, nWps)); geocoderInput.className = this.options.geocoderClass(i, nWps); this._updateWaypointName(i, geocoderInput); // This has to be here, or geocoder's value will not be properly // initialized. // TODO: look into why and make _updateWaypointName fix this. geocoderInput.value = wp.name; L.DomEvent.addListener(geocoderInput, 'click', function() { selectInputText(this); }, geocoderInput); if (closeButton) { L.DomEvent.addListener(closeButton, 'click', function() { this.spliceWaypoints(i, 1); }, this); } new L.Routing.Autocomplete(geocoderInput, function(r) { geocoderInput.value = r.name; wp.name = r.name; wp.latLng = r.center; this._updateMarkers(); this._fireChanged(); this._focusGeocoder(i + 1); }, this, L.extend({ resultFn: this.options.geocoder.geocode, resultContext: this.options.geocoder, autocompleteFn: this.options.geocoder.suggest, autocompleteContext: this.options.geocoder }, this.options.autocompleteOptions)); return g; }, _updateGeocoders: function(e) { var newElems = [], i, geocoderElem, beforeElem; // Determine where to insert geocoders for new waypoints if (e.index >= this._geocoderElems.length) { // lastChild is the "add new wp" button beforeElem = this._geocoderContainer.lastChild; } else { beforeElem = this._geocoderElems[e.index].container; } // Insert new geocoders for new waypoints for (i = 0; i < e.added.length; i++) { geocoderElem = this._createGeocoder(e.index + i); this._geocoderContainer.insertBefore(geocoderElem.container, beforeElem); newElems.push(geocoderElem); } //newElems.reverse(); for (i = e.index; i < e.index + e.nRemoved; i++) { this._geocoderContainer.removeChild(this._geocoderElems[i].container); } newElems.splice(0, 0, e.index, e.nRemoved); [].splice.apply(this._geocoderElems, newElems); for (i = 0; i < this._geocoderElems.length; i++) { this._geocoderElems[i].input.placeholder = this.options.geocoderPlaceholder(i, this._waypoints.length); this._geocoderElems[i].input.className = this.options.geocoderClass(i, this._waypoints.length); } }, _updateGeocoder: function(i, geocoderElem) { var wp = this._waypoints[i], value = wp && wp.name ? wp.name : ''; if (geocoderElem) { geocoderElem.value = value; } }, _updateWaypointName: function(i, geocoderElem, force) { var wp = this._waypoints[i], wpCoords; wp.name = wp.name || ''; if (wp.latLng && (force || !wp.name)) { wpCoords = this.options.waypointNameFallback(wp.latLng); if (this.options.geocoder && this.options.geocoder.reverse) { this.options.geocoder.reverse(wp.latLng, 67108864 /* zoom 18 */, function(rs) { if (rs.length > 0 && rs[0].center.distanceTo(wp.latLng) < this.options.maxGeocoderTolerance) { wp.name = rs[0].name; } else { wp.name = wpCoords; } this._updateGeocoder(i, geocoderElem); }, this); } else { wp.name = wpCoords; } this._updateGeocoder(i, geocoderElem); } }, _removeMarkers: function() { var i; if (this._markers) { for (i = 0; i < this._markers.length; i++) { if (this._markers[i]) { this._map.removeLayer(this._markers[i]); } } } this._markers = []; }, _updateMarkers: function() { var i, icon, m; if (!this._map) { return; } this._removeMarkers(); for (i = 0; i < this._waypoints.length; i++) { if (this._waypoints[i].latLng) { icon = (typeof(this.options.waypointIcon) === 'function') ? this.options.waypointIcon(i, this._waypoints[i].name, this._waypoints.length) : this.options.waypointIcon; m = this._createMarker(icon, i); if (this.options.draggableWaypoints) { this._hookWaypointEvents(m, i); } } else { m = null; } this._markers.push(m); } }, _createMarker: function(icon, i) { var options = { draggable: this.options.draggableWaypoints }; if (icon) { options.icon = icon; } return L.marker(this._waypoints[i].latLng, options).addTo(this._map); }, _fireChanged: function() { this.fire('waypointschanged', {waypoints: this.getWaypoints()}); if (arguments.length >= 2) { this.fire('waypointsspliced', { index: Array.prototype.shift.call(arguments), nRemoved: Array.prototype.shift.call(arguments), added: arguments }); } }, _hookWaypointEvents: function(m, i) { m.on('dragstart', function(e) { this.fire('waypointdragstart', this._createWaypointEvent(i, e)); }, this); m.on('drag', function(e) { this._waypoints[i].latLng = e.target.getLatLng(); this.fire('waypointdrag', this._createWaypointEvent(i, e)); }, this); m.on('dragend', function(e) { this._waypoints[i].latLng = e.target.getLatLng(); this._waypoints[i].name = ''; this._updateWaypointName(i, this._geocoderElems && this._geocoderElems[i].input, true); this.fire('waypointdragend', this._createWaypointEvent(i, e)); this._fireChanged(); }, this); }, _createWaypointEvent: function(i, e) { return {index: i, latlng: e.target.getLatLng()}; }, dragNewWaypoint: function(e) { var i; this._newWp = { afterIndex: e.afterIndex, marker: L.marker(e.latlng).addTo(this._map), lines: [] }; for (i = 0; i < this.options.dragStyles.length; i++) { this._newWp.lines.push(L.polyline([ this._waypoints[e.afterIndex].latLng, e.latlng, this._waypoints[e.afterIndex + 1].latLng ], this.options.dragStyles[i]).addTo(this._map)); } this._markers.splice(e.afterIndex + 1, 0, this._newWp.marker); this._map.on('mousemove', this._onDragNewWp, this); this._map.on('mouseup', this._onWpRelease, this); }, _onDragNewWp: function(e) { var i; this._newWp.marker.setLatLng(e.latlng); for (i = 0; i < this._newWp.lines.length; i++) { this._newWp.lines[i].spliceLatLngs(1, 1, e.latlng); } }, _onWpRelease: function(e) { var i; this._map.off('mouseup', this._onWpRelease, this); this._map.off('mousemove', this._onDragNewWp, this); for (i = 0; i < this._newWp.lines.length; i++) { this._map.removeLayer(this._newWp.lines[i]); } this.spliceWaypoints(this._newWp.afterIndex + 1, 0, e.latlng); delete this._newWp; }, _focusGeocoder: function(i) { var input; if (this._geocoderElems[i]) { input = this._geocoderElems[i].input; input.focus(); selectInputText(input); } else { document.activeElement.blur(); } } }); L.Routing.plan = function(waypoints, options) { return new L.Routing.Plan(waypoints, options); }; module.exports = L.Routing; })(); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./L.Routing.Autocomplete":1,"./L.Routing.Waypoint":10}],10:[function(require,module,exports){ (function (global){ (function() { 'use strict'; var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null); L.Routing = L.Routing || {}; L.Routing.Waypoint = L.Class.extend({ options: { allowUTurn: false, }, initialize: function(latLng, name, options) { L.Util.setOptions(this, options); this.latLng = latLng; this.name = name; } }); L.Routing.waypoint = function(latLng, name, options) { return new L.Routing.Waypoint(latLng, name, options); }; module.exports = L.Routing; })(); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{}]},{},[2])(2) });