Le repo des sources pour le site web des JM2L
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

1964 řádky
51 KiB

  1. !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<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. (function() {
  3. 'use strict';
  4. L.Routing = L.Routing || {};
  5. L.Routing.Autocomplete = L.Class.extend({
  6. options: {
  7. timeout: 500,
  8. blurTimeout: 100,
  9. noResultsMessage: 'No results found.'
  10. },
  11. initialize: function(elem, callback, context, options) {
  12. L.setOptions(this, options);
  13. this._elem = elem;
  14. this._resultFn = options.resultFn ? L.Util.bind(options.resultFn, options.resultContext) : null;
  15. this._autocomplete = options.autocompleteFn ? L.Util.bind(options.autocompleteFn, options.autocompleteContext) : null;
  16. this._selectFn = L.Util.bind(callback, context);
  17. this._container = L.DomUtil.create('div', 'leaflet-routing-geocoder-result');
  18. this._resultTable = L.DomUtil.create('table', '', this._container);
  19. // TODO: looks a bit like a kludge to register same for input and keypress -
  20. // browsers supporting both will get duplicate events; just registering
  21. // input will not catch enter, though.
  22. L.DomEvent.addListener(this._elem, 'input', this._keyPressed, this);
  23. L.DomEvent.addListener(this._elem, 'keypress', this._keyPressed, this);
  24. L.DomEvent.addListener(this._elem, 'keydown', this._keyDown, this);
  25. L.DomEvent.addListener(this._elem, 'blur', function() {
  26. if (this._isOpen) {
  27. this.close();
  28. }
  29. }, this);
  30. },
  31. close: function() {
  32. L.DomUtil.removeClass(this._container, 'leaflet-routing-geocoder-result-open');
  33. this._isOpen = false;
  34. },
  35. _open: function() {
  36. var rect = this._elem.getBoundingClientRect();
  37. if (!this._container.parentElement) {
  38. this._container.style.left = rect.left + 'px';
  39. this._container.style.top = rect.bottom + 'px';
  40. this._container.style.width = (rect.right - rect.left) + 'px';
  41. document.body.appendChild(this._container);
  42. }
  43. L.DomUtil.addClass(this._container, 'leaflet-routing-geocoder-result-open');
  44. this._isOpen = true;
  45. },
  46. _setResults: function(results) {
  47. var i,
  48. tr,
  49. td,
  50. text;
  51. delete this._selection;
  52. this._results = results;
  53. while (this._resultTable.firstChild) {
  54. this._resultTable.removeChild(this._resultTable.firstChild);
  55. }
  56. for (i = 0; i < results.length; i++) {
  57. tr = L.DomUtil.create('tr', '', this._resultTable);
  58. tr.setAttribute('data-result-index', i);
  59. td = L.DomUtil.create('td', '', tr);
  60. text = document.createTextNode(results[i].name);
  61. td.appendChild(text);
  62. // mousedown + click because:
  63. // http://stackoverflow.com/questions/10652852/jquery-fire-click-before-blur-event
  64. L.DomEvent.addListener(td, 'mousedown', L.DomEvent.preventDefault);
  65. L.DomEvent.addListener(td, 'click', this._createClickListener(results[i]));
  66. }
  67. if (!i) {
  68. tr = L.DomUtil.create('tr', '', this._resultTable);
  69. td = L.DomUtil.create('td', 'leaflet-routing-geocoder-no-results', tr);
  70. td.innerHTML = this.options.noResultsMessage;
  71. }
  72. this._open();
  73. if (results.length > 0) {
  74. // Select the first entry
  75. this._select(1);
  76. }
  77. },
  78. _createClickListener: function(r) {
  79. var resultSelected = this._resultSelected(r);
  80. return L.bind(function() {
  81. this._elem.blur();
  82. resultSelected();
  83. }, this);
  84. },
  85. _resultSelected: function(r) {
  86. return L.bind(function() {
  87. this.close();
  88. this._elem.value = r.name;
  89. this._lastCompletedText = r.name;
  90. this._selectFn(r);
  91. }, this);
  92. },
  93. _keyPressed: function(e) {
  94. var index;
  95. if (this._isOpen && e.keyCode === 13 && this._selection) {
  96. index = parseInt(this._selection.getAttribute('data-result-index'), 10);
  97. this._resultSelected(this._results[index])();
  98. L.DomEvent.preventDefault(e);
  99. return;
  100. }
  101. if (e.keyCode === 13) {
  102. this._complete(this._resultFn, true);
  103. return;
  104. }
  105. if (this._autocomplete && document.activeElement === this._elem) {
  106. if (this._timer) {
  107. clearTimeout(this._timer);
  108. }
  109. this._timer = setTimeout(L.Util.bind(function() { this._complete(this._autocomplete); }, this),
  110. this.options.timeout);
  111. return;
  112. }
  113. this._unselect();
  114. },
  115. _select: function(dir) {
  116. var sel = this._selection;
  117. if (sel) {
  118. L.DomUtil.removeClass(sel.firstChild, 'leaflet-routing-geocoder-selected');
  119. sel = sel[dir > 0 ? 'nextSibling' : 'previousSibling'];
  120. }
  121. if (!sel) {
  122. sel = this._resultTable[dir > 0 ? 'firstChild' : 'lastChild'];
  123. }
  124. if (sel) {
  125. L.DomUtil.addClass(sel.firstChild, 'leaflet-routing-geocoder-selected');
  126. this._selection = sel;
  127. }
  128. },
  129. _unselect: function() {
  130. if (this._selection) {
  131. L.DomUtil.removeClass(this._selection.firstChild, 'leaflet-routing-geocoder-selected');
  132. }
  133. delete this._selection;
  134. },
  135. _keyDown: function(e) {
  136. if (this._isOpen) {
  137. switch (e.keyCode) {
  138. // Escape
  139. case 27:
  140. this.close();
  141. L.DomEvent.preventDefault(e);
  142. return;
  143. // Up
  144. case 38:
  145. this._select(-1);
  146. L.DomEvent.preventDefault(e);
  147. return;
  148. // Down
  149. case 40:
  150. this._select(1);
  151. L.DomEvent.preventDefault(e);
  152. return;
  153. }
  154. }
  155. },
  156. _complete: function(completeFn, trySelect) {
  157. var v = this._elem.value;
  158. function completeResults(results) {
  159. this._lastCompletedText = v;
  160. if (trySelect && results.length === 1) {
  161. this._resultSelected(results[0])();
  162. } else {
  163. this._setResults(results);
  164. }
  165. }
  166. if (!v) {
  167. return;
  168. }
  169. if (v !== this._lastCompletedText) {
  170. completeFn(v, completeResults, this);
  171. } else if (trySelect) {
  172. completeResults.call(this, this._results);
  173. }
  174. }
  175. });
  176. })();
  177. },{}],2:[function(require,module,exports){
  178. (function (global){
  179. (function() {
  180. 'use strict';
  181. var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null);
  182. L.Routing = L.Routing || {};
  183. L.extend(L.Routing, require('./L.Routing.Itinerary'));
  184. L.extend(L.Routing, require('./L.Routing.Line'));
  185. L.extend(L.Routing, require('./L.Routing.Plan'));
  186. L.extend(L.Routing, require('./L.Routing.OSRM'));
  187. L.Routing.Control = L.Routing.Itinerary.extend({
  188. options: {
  189. fitSelectedRoutes: 'smart',
  190. routeLine: function(route, options) { return L.Routing.line(route, options); },
  191. autoRoute: true,
  192. routeWhileDragging: false,
  193. routeDragInterval: 500,
  194. waypointMode: 'connect',
  195. useZoomParameter: false
  196. },
  197. initialize: function(options) {
  198. L.Util.setOptions(this, options);
  199. this._router = this.options.router || new L.Routing.OSRM(options);
  200. this._plan = this.options.plan || L.Routing.plan(this.options.waypoints, options);
  201. this._requestCount = 0;
  202. L.Routing.Itinerary.prototype.initialize.call(this, options);
  203. this.on('routeselected', this._routeSelected, this);
  204. this._plan.on('waypointschanged', this._onWaypointsChanged, this);
  205. if (options.routeWhileDragging) {
  206. this._setupRouteDragging();
  207. }
  208. if (this.options.autoRoute) {
  209. this.route();
  210. }
  211. },
  212. onAdd: function(map) {
  213. var container = L.Routing.Itinerary.prototype.onAdd.call(this, map);
  214. this._map = map;
  215. this._map.addLayer(this._plan);
  216. if (this.options.useZoomParameter) {
  217. this._map.on('zoomend', function() {
  218. this.route({
  219. callback: L.bind(this._updateLineCallback, this)
  220. });
  221. }, this);
  222. }
  223. if (this._plan.options.geocoder) {
  224. container.insertBefore(this._plan.createGeocoders(), container.firstChild);
  225. }
  226. return container;
  227. },
  228. onRemove: function(map) {
  229. if (this._line) {
  230. map.removeLayer(this._line);
  231. }
  232. map.removeLayer(this._plan);
  233. return L.Routing.Itinerary.prototype.onRemove.call(this, map);
  234. },
  235. getWaypoints: function() {
  236. return this._plan.getWaypoints();
  237. },
  238. setWaypoints: function(waypoints) {
  239. this._plan.setWaypoints(waypoints);
  240. return this;
  241. },
  242. spliceWaypoints: function() {
  243. var removed = this._plan.spliceWaypoints.apply(this._plan, arguments);
  244. return removed;
  245. },
  246. getPlan: function() {
  247. return this._plan;
  248. },
  249. _routeSelected: function(e) {
  250. var route = e.route,
  251. fitMode = this.options.fitSelectedRoutes,
  252. fitBounds =
  253. (fitMode === 'smart' && !this._waypointsVisible()) ||
  254. (fitMode !== 'smart' && fitMode);
  255. this._updateLine(route);
  256. if (fitBounds) {
  257. this._map.fitBounds(this._line.getBounds());
  258. }
  259. if (this.options.waypointMode === 'snap') {
  260. this._plan.off('waypointschanged', this._onWaypointsChanged, this);
  261. this.setWaypoints(route.waypoints);
  262. this._plan.on('waypointschanged', this._onWaypointsChanged, this);
  263. }
  264. },
  265. _waypointsVisible: function() {
  266. var wps = this.getWaypoints(),
  267. mapSize,
  268. bounds,
  269. boundsSize,
  270. i,
  271. p;
  272. try {
  273. mapSize = this._map.getSize();
  274. for (i = 0; i < wps.length; i++) {
  275. p = this._map.latLngToLayerPoint(wps[i].latLng);
  276. if (bounds) {
  277. bounds.extend(p);
  278. } else {
  279. bounds = L.bounds([p]);
  280. }
  281. }
  282. boundsSize = bounds.getSize();
  283. return (boundsSize.x > mapSize.x / 5 ||
  284. boundsSize.y > mapSize.y / 5) && this._waypointsInViewport();
  285. } catch (e) {
  286. return false;
  287. }
  288. },
  289. _waypointsInViewport: function() {
  290. var wps = this.getWaypoints(),
  291. mapBounds,
  292. i;
  293. try {
  294. mapBounds = this._map.getBounds();
  295. } catch (e) {
  296. return false;
  297. }
  298. for (i = 0; i < wps.length; i++) {
  299. if (mapBounds.contains(wps[i].latLng)) {
  300. return true;
  301. }
  302. }
  303. return false;
  304. },
  305. _updateLine: function(route) {
  306. var addWaypoints = this.options.addWaypoints !== undefined ?
  307. this.options.addWaypoints : true;
  308. this._clearLine();
  309. this._line = this.options.routeLine(route,
  310. L.extend({
  311. addWaypoints: addWaypoints,
  312. extendToWaypoints: this.options.waypointMode === 'connect'
  313. }, this.options.lineOptions));
  314. this._line.addTo(this._map);
  315. this._hookEvents(this._line);
  316. },
  317. _hookEvents: function(l) {
  318. l.on('linetouched', function(e) {
  319. this._plan.dragNewWaypoint(e);
  320. }, this);
  321. },
  322. _onWaypointsChanged: function(e) {
  323. if (this.options.autoRoute) {
  324. this.route({});
  325. }
  326. if (!this._plan.isReady()) {
  327. this._clearLine();
  328. this._clearAlts();
  329. }
  330. this.fire('waypointschanged', {waypoints: e.waypoints});
  331. },
  332. _setupRouteDragging: function() {
  333. var timer = 0,
  334. waypoints;
  335. this._plan.on('waypointdrag', L.bind(function(e) {
  336. waypoints = e.waypoints;
  337. if (!timer) {
  338. timer = setTimeout(L.bind(function() {
  339. this.route({
  340. waypoints: waypoints,
  341. geometryOnly: true,
  342. callback: L.bind(this._updateLineCallback, this)
  343. });
  344. timer = undefined;
  345. }, this), this.options.routeDragInterval);
  346. }
  347. }, this));
  348. this._plan.on('waypointdragend', function() {
  349. if (timer) {
  350. clearTimeout(timer);
  351. timer = undefined;
  352. }
  353. this.route();
  354. }, this);
  355. },
  356. _updateLineCallback: function(err, routes) {
  357. if (!err) {
  358. this._updateLine(routes[0]);
  359. }
  360. },
  361. route: function(options) {
  362. var ts = ++this._requestCount,
  363. wps;
  364. options = options || {};
  365. if (this._plan.isReady()) {
  366. if (this.options.useZoomParameter) {
  367. options.z = this._map && this._map.getZoom();
  368. }
  369. wps = options && options.waypoints || this._plan.getWaypoints();
  370. this.fire('routingstart', {waypoints: wps});
  371. this._router.route(wps, options.callback || function(err, routes) {
  372. // Prevent race among multiple requests,
  373. // by checking the current request's timestamp
  374. // against the last request's; ignore result if
  375. // this isn't the latest request.
  376. if (ts === this._requestCount) {
  377. this._clearLine();
  378. this._clearAlts();
  379. if (err) {
  380. this.fire('routingerror', {error: err});
  381. return;
  382. }
  383. if (!options.geometryOnly) {
  384. this.fire('routesfound', {waypoints: wps, routes: routes});
  385. this.setAlternatives(routes);
  386. } else {
  387. this._routeSelected({route: routes[0]});
  388. }
  389. }
  390. }, this, options);
  391. }
  392. },
  393. _clearLine: function() {
  394. if (this._line) {
  395. this._map.removeLayer(this._line);
  396. delete this._line;
  397. }
  398. }
  399. });
  400. L.Routing.control = function(options) {
  401. return new L.Routing.Control(options);
  402. };
  403. module.exports = L.Routing;
  404. })();
  405. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  406. },{"./L.Routing.Itinerary":4,"./L.Routing.Line":6,"./L.Routing.OSRM":8,"./L.Routing.Plan":9}],3:[function(require,module,exports){
  407. (function (global){
  408. (function() {
  409. 'use strict';
  410. var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null);
  411. L.Routing = L.Routing || {};
  412. L.extend(L.Routing, require('./L.Routing.Localization'));
  413. L.Routing.Formatter = L.Class.extend({
  414. options: {
  415. units: 'metric',
  416. unitNames: {
  417. meters: 'm',
  418. kilometers: 'km',
  419. yards: 'yd',
  420. miles: 'mi',
  421. hours: 'h',
  422. minutes: 'mín',
  423. seconds: 's'
  424. },
  425. language: 'en',
  426. roundingSensitivity: 1,
  427. distanceTemplate: '{value} {unit}'
  428. },
  429. initialize: function(options) {
  430. L.setOptions(this, options);
  431. },
  432. formatDistance: function(d /* Number (meters) */) {
  433. var un = this.options.unitNames,
  434. v,
  435. data;
  436. if (this.options.units === 'imperial') {
  437. d = d / 1.609344;
  438. if (d >= 1000) {
  439. data = {
  440. value: (this._round(d) / 1000),
  441. unit: un.miles
  442. };
  443. } else {
  444. data = {
  445. value: this._round(d / 1.760),
  446. unit: un.yards
  447. };
  448. }
  449. } else {
  450. v = this._round(d);
  451. data = {
  452. value: v >= 1000 ? (v / 1000) : v,
  453. unit: v >= 1000 ? un.kilometers : un.meters
  454. };
  455. }
  456. return L.Util.template(this.options.distanceTemplate, data);
  457. },
  458. _round: function(d) {
  459. var pow10 = Math.pow(10, (Math.floor(d / this.options.roundingSensitivity) + '').length - 1),
  460. r = Math.floor(d / pow10),
  461. p = (r > 5) ? pow10 : pow10 / 2;
  462. return Math.round(d / p) * p;
  463. },
  464. formatTime: function(t /* Number (seconds) */) {
  465. if (t > 86400) {
  466. return Math.round(t / 3600) + ' h';
  467. } else if (t > 3600) {
  468. return Math.floor(t / 3600) + ' h ' +
  469. Math.round((t % 3600) / 60) + ' min';
  470. } else if (t > 300) {
  471. return Math.round(t / 60) + ' min';
  472. } else if (t > 60) {
  473. return Math.floor(t / 60) + ' min' +
  474. (t % 60 !== 0 ? ' ' + (t % 60) + ' s' : '');
  475. } else {
  476. return t + ' s';
  477. }
  478. },
  479. formatInstruction: function(instr, i) {
  480. if (instr.type !== undefined) {
  481. return L.Util.template(this._getInstructionTemplate(instr, i),
  482. L.extend({
  483. exitStr: L.Routing.Localization[this.options.language].formatOrder(instr.exit),
  484. dir: L.Routing.Localization[this.options.language].directions[instr.direction]
  485. },
  486. instr));
  487. } else {
  488. return instr.text;
  489. }
  490. },
  491. getIconName: function(instr, i) {
  492. switch (instr.type) {
  493. case 'Straight':
  494. return (i === 0 ? 'depart' : 'continue');
  495. case 'SlightRight':
  496. return 'bear-right';
  497. case 'Right':
  498. return 'turn-right';
  499. case 'SharpRight':
  500. return 'sharp-right';
  501. case 'TurnAround':
  502. return 'u-turn';
  503. case 'SharpLeft':
  504. return 'sharp-left';
  505. case 'Left':
  506. return 'turn-left';
  507. case 'SlightLeft':
  508. return 'slight-left';
  509. case 'WaypointReached':
  510. return 'arrive';
  511. case 'Roundabout':
  512. return 'enter-roundabout';
  513. case 'DestinationReached':
  514. return 'arrive';
  515. }
  516. },
  517. _getInstructionTemplate: function(instr, i) {
  518. var type = instr.type === 'Straight' ? (i === 0 ? 'Head' : 'Continue') : instr.type,
  519. strings = L.Routing.Localization[this.options.language].instructions[type];
  520. return strings[0] + (strings.length > 1 && instr.road ? strings[1] : '');
  521. },
  522. });
  523. module.exports = L.Routing;
  524. })();
  525. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  526. },{"./L.Routing.Localization":7}],4:[function(require,module,exports){
  527. (function (global){
  528. (function() {
  529. 'use strict';
  530. var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null);
  531. L.Routing = L.Routing || {};
  532. L.extend(L.Routing, require('./L.Routing.Formatter'));
  533. L.extend(L.Routing, require('./L.Routing.ItineraryBuilder'));
  534. L.Routing.Itinerary = L.Control.extend({
  535. includes: L.Mixin.Events,
  536. options: {
  537. pointMarkerStyle: {
  538. radius: 5,
  539. color: '#03f',
  540. fillColor: 'white',
  541. opacity: 1,
  542. fillOpacity: 0.7
  543. },
  544. summaryTemplate: '<h2>{name}</h2><h3>{distance}, {time}</h3>',
  545. timeTemplate: '{time}',
  546. containerClassName: '',
  547. alternativeClassName: '',
  548. minimizedClassName: '',
  549. itineraryClassName: '',
  550. show: true
  551. },
  552. initialize: function(options) {
  553. L.setOptions(this, options);
  554. this._formatter = this.options.formatter || new L.Routing.Formatter(this.options);
  555. this._itineraryBuilder = this.options.itineraryBuilder || new L.Routing.ItineraryBuilder({
  556. containerClassName: this.options.itineraryClassName
  557. });
  558. },
  559. onAdd: function() {
  560. this._container = L.DomUtil.create('div', 'leaflet-routing-container leaflet-bar ' +
  561. (!this.options.show ? 'leaflet-routing-container-hide' : '') +
  562. this.options.containerClassName);
  563. this._altContainer = this.createAlternativesContainer();
  564. this._container.appendChild(this._altContainer);
  565. L.DomEvent.disableClickPropagation(this._container);
  566. L.DomEvent.addListener(this._container, 'mousewheel', function(e) {
  567. L.DomEvent.stopPropagation(e);
  568. });
  569. return this._container;
  570. },
  571. onRemove: function() {
  572. },
  573. createAlternativesContainer: function() {
  574. return L.DomUtil.create('div', 'leaflet-routing-alternatives-container');
  575. },
  576. setAlternatives: function(routes) {
  577. var i,
  578. alt,
  579. altDiv;
  580. this._clearAlts();
  581. this._routes = routes;
  582. for (i = 0; i < this._routes.length; i++) {
  583. alt = this._routes[i];
  584. altDiv = this._createAlternative(alt, i);
  585. this._altContainer.appendChild(altDiv);
  586. this._altElements.push(altDiv);
  587. }
  588. this.fire('routeselected', {route: this._routes[0]});
  589. return this;
  590. },
  591. show: function() {
  592. L.DomUtil.removeClass(this._container, 'leaflet-routing-container-hide');
  593. },
  594. hide: function() {
  595. L.DomUtil.addClass(this._container, 'leaflet-routing-container-hide');
  596. },
  597. _createAlternative: function(alt, i) {
  598. var altDiv = L.DomUtil.create('div', 'leaflet-routing-alt ' +
  599. this.options.alternativeClassName +
  600. (i > 0 ? ' leaflet-routing-alt-minimized ' + this.options.minimizedClassName : ''));
  601. altDiv.innerHTML = L.Util.template(this.options.summaryTemplate, {
  602. name: alt.name,
  603. distance: this._formatter.formatDistance(alt.summary.totalDistance),
  604. time: this._formatter.formatTime(alt.summary.totalTime)
  605. });
  606. L.DomEvent.addListener(altDiv, 'click', this._onAltClicked, this);
  607. altDiv.appendChild(this._createItineraryContainer(alt));
  608. return altDiv;
  609. },
  610. _clearAlts: function() {
  611. var el = this._altContainer;
  612. while (el && el.firstChild) {
  613. el.removeChild(el.firstChild);
  614. }
  615. this._altElements = [];
  616. },
  617. _createItineraryContainer: function(r) {
  618. var container = this._itineraryBuilder.createContainer(),
  619. steps = this._itineraryBuilder.createStepsContainer(),
  620. i,
  621. instr,
  622. step,
  623. distance,
  624. text,
  625. icon;
  626. container.appendChild(steps);
  627. for (i = 0; i < r.instructions.length; i++) {
  628. instr = r.instructions[i];
  629. text = this._formatter.formatInstruction(instr, i);
  630. distance = this._formatter.formatDistance(instr.distance);
  631. icon = this._formatter.getIconName(instr, i);
  632. step = this._itineraryBuilder.createStep(text, distance, icon, steps);
  633. this._addRowListeners(step, r.coordinates[instr.index]);
  634. }
  635. return container;
  636. },
  637. _addRowListeners: function(row, coordinate) {
  638. var _this = this,
  639. marker;
  640. L.DomEvent.addListener(row, 'mouseover', function() {
  641. marker = L.circleMarker(coordinate,
  642. _this.options.pointMarkerStyle).addTo(_this._map);
  643. });
  644. L.DomEvent.addListener(row, 'mouseout', function() {
  645. if (marker) {
  646. _this._map.removeLayer(marker);
  647. marker = null;
  648. }
  649. });
  650. L.DomEvent.addListener(row, 'click', function(e) {
  651. _this._map.panTo(coordinate);
  652. L.DomEvent.stopPropagation(e);
  653. });
  654. },
  655. _onAltClicked: function(e) {
  656. var altElem,
  657. j,
  658. n,
  659. isCurrentSelection,
  660. classFn;
  661. altElem = e.target || window.event.srcElement;
  662. while (!L.DomUtil.hasClass(altElem, 'leaflet-routing-alt')) {
  663. altElem = altElem.parentElement;
  664. }
  665. if (L.DomUtil.hasClass(altElem, 'leaflet-routing-alt-minimized')) {
  666. for (j = 0; j < this._altElements.length; j++) {
  667. n = this._altElements[j];
  668. isCurrentSelection = altElem === n;
  669. classFn = isCurrentSelection ? 'removeClass' : 'addClass';
  670. L.DomUtil[classFn](n, 'leaflet-routing-alt-minimized');
  671. if (this.options.minimizedClassName) {
  672. L.DomUtil[classFn](n, this.options.minimizedClassName);
  673. }
  674. if (isCurrentSelection) {
  675. // TODO: don't fire if the currently active is clicked
  676. this.fire('routeselected', {route: this._routes[j]});
  677. } else {
  678. n.scrollTop = 0;
  679. }
  680. }
  681. }
  682. L.DomEvent.stop(e);
  683. },
  684. });
  685. L.Routing.itinerary = function(router) {
  686. return new L.Routing.Itinerary(router);
  687. };
  688. module.exports = L.Routing;
  689. })();
  690. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  691. },{"./L.Routing.Formatter":3,"./L.Routing.ItineraryBuilder":5}],5:[function(require,module,exports){
  692. (function (global){
  693. (function() {
  694. 'use strict';
  695. var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null);
  696. L.Routing = L.Routing || {};
  697. L.Routing.ItineraryBuilder = L.Class.extend({
  698. options: {
  699. containerClassName: ''
  700. },
  701. initialize: function(options) {
  702. L.setOptions(this, options);
  703. },
  704. createContainer: function() {
  705. return L.DomUtil.create('table', this.options.containerClassName);
  706. },
  707. createStepsContainer: function() {
  708. return L.DomUtil.create('tbody', '');
  709. },
  710. createStep: function(text, distance, icon, steps) {
  711. var row = L.DomUtil.create('tr', '', steps),
  712. span,
  713. td;
  714. td = L.DomUtil.create('td', '', row);
  715. span = L.DomUtil.create('span', 'leaflet-routing-icon leaflet-routing-icon-'+icon, td);
  716. td.appendChild(span);
  717. td = L.DomUtil.create('td', '', row);
  718. td.appendChild(document.createTextNode(text));
  719. td = L.DomUtil.create('td', '', row);
  720. td.appendChild(document.createTextNode(distance));
  721. return row;
  722. }
  723. });
  724. module.exports = L.Routing;
  725. })();
  726. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  727. },{}],6:[function(require,module,exports){
  728. (function (global){
  729. (function() {
  730. 'use strict';
  731. var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null);
  732. L.Routing = L.Routing || {};
  733. L.Routing.Line = L.LayerGroup.extend({
  734. includes: L.Mixin.Events,
  735. options: {
  736. styles: [
  737. {color: 'black', opacity: 0.15, weight: 9},
  738. {color: 'white', opacity: 0.8, weight: 6},
  739. {color: 'red', opacity: 1, weight: 2}
  740. ],
  741. missingRouteStyles: [
  742. {color: 'black', opacity: 0.15, weight: 7},
  743. {color: 'white', opacity: 0.6, weight: 4},
  744. {color: 'gray', opacity: 0.8, weight: 2, dashArray: '7,12'}
  745. ],
  746. addWaypoints: true,
  747. extendToWaypoints: true,
  748. missingRouteTolerance: 10
  749. },
  750. initialize: function(route, options) {
  751. L.setOptions(this, options);
  752. L.LayerGroup.prototype.initialize.call(this, options);
  753. this._route = route;
  754. if (this.options.extendToWaypoints) {
  755. this._extendToWaypoints();
  756. }
  757. this._addSegment(
  758. route.coordinates,
  759. this.options.styles,
  760. this.options.addWaypoints);
  761. },
  762. addTo: function(map) {
  763. map.addLayer(this);
  764. return this;
  765. },
  766. getBounds: function() {
  767. return L.latLngBounds(this._route.coordinates);
  768. },
  769. _findWaypointIndices: function() {
  770. var wps = this._route.inputWaypoints,
  771. indices = [],
  772. i;
  773. for (i = 0; i < wps.length; i++) {
  774. indices.push(this._findClosestRoutePoint(wps[i].latLng));
  775. }
  776. return indices;
  777. },
  778. _findClosestRoutePoint: function(latlng) {
  779. var minDist = Number.MAX_VALUE,
  780. minIndex,
  781. i,
  782. d;
  783. for (i = this._route.coordinates.length - 1; i >= 0 ; i--) {
  784. // TODO: maybe do this in pixel space instead?
  785. d = latlng.distanceTo(this._route.coordinates[i]);
  786. if (d < minDist) {
  787. minIndex = i;
  788. minDist = d;
  789. }
  790. }
  791. return minIndex;
  792. },
  793. _extendToWaypoints: function() {
  794. var wps = this._route.inputWaypoints,
  795. wpIndices = this._getWaypointIndices(),
  796. i,
  797. wpLatLng,
  798. routeCoord;
  799. for (i = 0; i < wps.length; i++) {
  800. wpLatLng = wps[i].latLng;
  801. routeCoord = L.latLng(this._route.coordinates[wpIndices[i]]);
  802. if (wpLatLng.distanceTo(routeCoord) >
  803. this.options.missingRouteTolerance) {
  804. this._addSegment([wpLatLng, routeCoord],
  805. this.options.missingRouteStyles);
  806. }
  807. }
  808. },
  809. _addSegment: function(coords, styles, mouselistener) {
  810. var i,
  811. pl;
  812. for (i = 0; i < styles.length; i++) {
  813. pl = L.polyline(coords, styles[i]);
  814. this.addLayer(pl);
  815. if (mouselistener) {
  816. pl.on('mousedown', this._onLineTouched, this);
  817. }
  818. }
  819. },
  820. _findNearestWpBefore: function(i) {
  821. var wpIndices = this._getWaypointIndices(),
  822. j = wpIndices.length - 1;
  823. while (j >= 0 && wpIndices[j] > i) {
  824. j--;
  825. }
  826. return j;
  827. },
  828. _onLineTouched: function(e) {
  829. var afterIndex = this._findNearestWpBefore(this._findClosestRoutePoint(e.latlng));
  830. this.fire('linetouched', {
  831. afterIndex: afterIndex,
  832. latlng: e.latlng
  833. });
  834. },
  835. _getWaypointIndices: function() {
  836. if (!this._wpIndices) {
  837. this._wpIndices = this._route.waypointIndices || this._findWaypointIndices();
  838. }
  839. return this._wpIndices;
  840. }
  841. });
  842. L.Routing.line = function(route, options) {
  843. return new L.Routing.Line(route, options);
  844. };
  845. module.exports = L.Routing;
  846. })();
  847. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  848. },{}],7:[function(require,module,exports){
  849. (function() {
  850. 'use strict';
  851. L.Routing = L.Routing || {};
  852. L.Routing.Localization = {
  853. 'en': {
  854. directions: {
  855. N: 'north',
  856. NE: 'northeast',
  857. E: 'east',
  858. SE: 'southeast',
  859. S: 'south',
  860. SW: 'southwest',
  861. W: 'west',
  862. NW: 'northwest'
  863. },
  864. instructions: {
  865. // instruction, postfix if the road is named
  866. 'Head':
  867. ['Head {dir}', ' on {road}'],
  868. 'Continue':
  869. ['Continue {dir}', ' on {road}'],
  870. 'SlightRight':
  871. ['Slight right', ' onto {road}'],
  872. 'Right':
  873. ['Right', ' onto {road}'],
  874. 'SharpRight':
  875. ['Sharp right', ' onto {road}'],
  876. 'TurnAround':
  877. ['Turn around'],
  878. 'SharpLeft':
  879. ['Sharp left', ' onto {road}'],
  880. 'Left':
  881. ['Left', ' onto {road}'],
  882. 'SlightLeft':
  883. ['Slight left', ' onto {road}'],
  884. 'WaypointReached':
  885. ['Waypoint reached'],
  886. 'Roundabout':
  887. ['Take the {exitStr} exit in the roundabout'],
  888. 'DestinationReached':
  889. ['Destination reached'],
  890. },
  891. formatOrder: function(n) {
  892. var i = n % 10 - 1,
  893. suffix = ['st', 'nd', 'rd'];
  894. return suffix[i] ? n + suffix[i] : n + 'th';
  895. }
  896. },
  897. 'de': {
  898. directions: {
  899. N: 'Norden',
  900. NE: 'Nordosten',
  901. E: 'Osten',
  902. SE: 'Südosten',
  903. S: 'Süden',
  904. SW: 'Südwesten',
  905. W: 'Westen',
  906. NW: 'Nordwesten'
  907. },
  908. instructions: {
  909. // instruction, postfix if the road is named
  910. 'Head':
  911. ['Richtung {dir}', ' auf {road}'],
  912. 'Continue':
  913. ['Geradeaus Richtung {dir}', ' auf {road}'],
  914. 'SlightRight':
  915. ['Leicht rechts abbiegen', ' auf {road}'],
  916. 'Right':
  917. ['Rechts abbiegen', ' auf {road}'],
  918. 'SharpRight':
  919. ['Scharf rechts abbiegen', ' auf {road}'],
  920. 'TurnAround':
  921. ['Wenden'],
  922. 'SharpLeft':
  923. ['Scharf links abbiegen', ' auf {road}'],
  924. 'Left':
  925. ['Links abbiegen', ' auf {road}'],
  926. 'SlightLeft':
  927. ['Leicht links abbiegen', ' auf {road}'],
  928. 'WaypointReached':
  929. ['Zwischenhalt erreicht'],
  930. 'Roundabout':
  931. ['Nehmen Sie die {exitStr} Ausfahrt im Kreisverkehr'],
  932. 'DestinationReached':
  933. ['Sie haben ihr Ziel erreicht'],
  934. },
  935. formatOrder: function(n) {
  936. return n + '.';
  937. }
  938. },
  939. 'sv': {
  940. directions: {
  941. N: 'norr',
  942. NE: 'nordost',
  943. E: 'öst',
  944. SE: 'sydost',
  945. S: 'syd',
  946. SW: 'sydväst',
  947. W: 'väst',
  948. NW: 'nordväst'
  949. },
  950. instructions: {
  951. // instruction, postfix if the road is named
  952. 'Head':
  953. ['Åk åt {dir}', ' på {road}'],
  954. 'Continue':
  955. ['Fortsätt {dir}', ' på {road}'],
  956. 'SlightRight':
  957. ['Svagt höger', ' på {road}'],
  958. 'Right':
  959. ['Sväng höger', ' på {road}'],
  960. 'SharpRight':
  961. ['Skarpt höger', ' på {road}'],
  962. 'TurnAround':
  963. ['Vänd'],
  964. 'SharpLeft':
  965. ['Skarpt vänster', ' på {road}'],
  966. 'Left':
  967. ['Sväng vänster', ' på {road}'],
  968. 'SlightLeft':
  969. ['Svagt vänster', ' på {road}'],
  970. 'WaypointReached':
  971. ['Viapunkt nådd'],
  972. 'Roundabout':
  973. ['Tag {exitStr} avfarten i rondellen'],
  974. 'DestinationReached':
  975. ['Framme vid resans mål'],
  976. },
  977. formatOrder: function(n) {
  978. return ['första', 'andra', 'tredje', 'fjärde', 'femte',
  979. 'sjätte', 'sjunde', 'åttonde', 'nionde', 'tionde'
  980. /* Can't possibly be more than ten exits, can there? */][n - 1];
  981. }
  982. },
  983. 'sp': {
  984. directions: {
  985. N: 'norte',
  986. NE: 'noreste',
  987. E: 'este',
  988. SE: 'sureste',
  989. S: 'sur',
  990. SW: 'suroeste',
  991. W: 'oeste',
  992. NW: 'noroeste'
  993. },
  994. instructions: {
  995. // instruction, postfix if the road is named
  996. 'Head':
  997. ['Derecho {dir}', ' sobre {road}'],
  998. 'Continue':
  999. ['Continuar {dir}', ' en {road}'],
  1000. 'SlightRight':
  1001. ['Leve giro a la derecha', ' sobre {road}'],
  1002. 'Right':
  1003. ['Derecha', ' sobre {road}'],
  1004. 'SharpRight':
  1005. ['Giro pronunciado a la derecha', ' sobre {road}'],
  1006. 'TurnAround':
  1007. ['Dar vuelta'],
  1008. 'SharpLeft':
  1009. ['Giro pronunciado a la izquierda', ' sobre {road}'],
  1010. 'Left':
  1011. ['Izquierda', ' en {road}'],
  1012. 'SlightLeft':
  1013. ['Leve giro a la izquierda', ' en {road}'],
  1014. 'WaypointReached':
  1015. ['Llegó a un punto del camino'],
  1016. 'Roundabout':
  1017. ['Tomar {exitStr} salida en la rotonda'],
  1018. 'DestinationReached':
  1019. ['Llegada a destino'],
  1020. },
  1021. formatOrder: function(n) {
  1022. return n + 'º';
  1023. }
  1024. }
  1025. };
  1026. module.exports = L.Routing;
  1027. })();
  1028. },{}],8:[function(require,module,exports){
  1029. (function (global){
  1030. (function() {
  1031. 'use strict';
  1032. var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null);
  1033. // Ignore camelcase naming for this file, since OSRM's API uses
  1034. // underscores.
  1035. /* jshint camelcase: false */
  1036. L.Routing = L.Routing || {};
  1037. L.extend(L.Routing, require('./L.Routing.Waypoint'));
  1038. L.Routing._jsonpCallbackId = 0;
  1039. L.Routing._jsonp = function(url, callback, context, jsonpParam) {
  1040. var callbackId = '_l_routing_machine_' + (L.Routing._jsonpCallbackId++),
  1041. script;
  1042. url += '&' + jsonpParam + '=' + callbackId;
  1043. window[callbackId] = L.Util.bind(callback, context);
  1044. script = document.createElement('script');
  1045. script.type = 'text/javascript';
  1046. script.src = url;
  1047. script.id = callbackId;
  1048. document.getElementsByTagName('head')[0].appendChild(script);
  1049. };
  1050. L.Routing.OSRM = L.Class.extend({
  1051. options: {
  1052. serviceUrl: '//router.project-osrm.org/viaroute',
  1053. timeout: 30 * 1000
  1054. },
  1055. initialize: function(options) {
  1056. L.Util.setOptions(this, options);
  1057. this._hints = {
  1058. locations: {}
  1059. };
  1060. },
  1061. route: function(waypoints, callback, context, options) {
  1062. var timedOut = false,
  1063. timer = setTimeout(function() {
  1064. timedOut = true;
  1065. callback.call(context || callback, {
  1066. status: -1,
  1067. message: 'OSRM request timed out.'
  1068. });
  1069. }, this.options.timeout),
  1070. wps = [],
  1071. wp,
  1072. url,
  1073. i;
  1074. // Create a copy of the waypoints, since they
  1075. // might otherwise be asynchronously modified while
  1076. // the request is being processed.
  1077. for (i = 0; i < waypoints.length; i++) {
  1078. wp = waypoints[i];
  1079. wps.push(new L.Routing.Waypoint(wp.latLng, wp.name, wp.options));
  1080. }
  1081. options = options || {};
  1082. url = this._buildRouteUrl(wps, options);
  1083. L.Routing._jsonp(url, function(data) {
  1084. clearTimeout(timer);
  1085. if (!timedOut) {
  1086. this._routeDone(data, wps, callback, context);
  1087. }
  1088. }, this, 'jsonp');
  1089. return this;
  1090. },
  1091. _routeDone: function(response, inputWaypoints, callback, context) {
  1092. var coordinates,
  1093. alts,
  1094. actualWaypoints,
  1095. i;
  1096. context = context || callback;
  1097. if (response.status !== 0) {
  1098. callback.call(context, {
  1099. status: response.status,
  1100. message: response.status_message
  1101. });
  1102. return;
  1103. }
  1104. coordinates = this._decode(response.route_geometry, 6);
  1105. actualWaypoints = this._toWaypoints(inputWaypoints, response.via_points);
  1106. alts = [{
  1107. name: response.route_name.join(', '),
  1108. coordinates: coordinates,
  1109. instructions: response.route_instructions ? this._convertInstructions(response.route_instructions) : [],
  1110. summary: response.route_summary ? this._convertSummary(response.route_summary) : [],
  1111. inputWaypoints: inputWaypoints,
  1112. waypoints: actualWaypoints,
  1113. waypointIndices: this._clampIndices(response.via_indices, coordinates)
  1114. }];
  1115. if (response.alternative_geometries) {
  1116. for (i = 0; i < response.alternative_geometries.length; i++) {
  1117. coordinates = this._decode(response.alternative_geometries[i], 6);
  1118. alts.push({
  1119. name: response.alternative_names[i].join(', '),
  1120. coordinates: coordinates,
  1121. instructions: response.alternative_instructions[i] ? this._convertInstructions(response.alternative_instructions[i]) : [],
  1122. summary: response.alternative_summaries[i] ? this._convertSummary(response.alternative_summaries[i]) : [],
  1123. inputWaypoints: inputWaypoints,
  1124. waypoints: actualWaypoints,
  1125. waypointIndices: this._clampIndices(response.alternative_geometries.length === 1 ?
  1126. // Unsure if this is a bug in OSRM or not, but alternative_indices
  1127. // does not appear to be an array of arrays, at least not when there is
  1128. // a single alternative route.
  1129. response.alternative_indices : response.alternative_indices[i],
  1130. coordinates)
  1131. });
  1132. }
  1133. }
  1134. this._saveHintData(response, inputWaypoints);
  1135. callback.call(context, null, alts);
  1136. },
  1137. _toWaypoints: function(inputWaypoints, vias) {
  1138. var wps = [],
  1139. i;
  1140. for (i = 0; i < vias.length; i++) {
  1141. wps.push(L.Routing.waypoint(L.latLng(vias[i]),
  1142. inputWaypoints[i].name,
  1143. inputWaypoints[i].options));
  1144. }
  1145. return wps;
  1146. },
  1147. _buildRouteUrl: function(waypoints, options) {
  1148. var locs = [],
  1149. computeInstructions,
  1150. computeAlternative,
  1151. locationKey,
  1152. hint;
  1153. for (var i = 0; i < waypoints.length; i++) {
  1154. locationKey = this._locationKey(waypoints[i].latLng);
  1155. locs.push('loc=' + locationKey);
  1156. hint = this._hints.locations[locationKey];
  1157. if (hint) {
  1158. locs.push('hint=' + hint);
  1159. }
  1160. if (waypoints[i].options.allowUTurn)
  1161. {
  1162. locs.push('u=true');
  1163. }
  1164. }
  1165. computeAlternative = computeInstructions =
  1166. !(options && options.geometryOnly);
  1167. return this.options.serviceUrl + '?' +
  1168. 'instructions=' + computeInstructions + '&' +
  1169. 'alt=' + computeAlternative + '&' +
  1170. (options.z ? 'z=' + options.z + '&' : '') +
  1171. locs.join('&') +
  1172. (this._hints.checksum !== undefined ? '&checksum=' + this._hints.checksum : '');
  1173. },
  1174. _locationKey: function(location) {
  1175. return location.lat + ',' + location.lng;
  1176. },
  1177. _saveHintData: function(route, waypoints) {
  1178. var hintData = route.hint_data,
  1179. loc;
  1180. this._hints = {
  1181. checksum: hintData.checksum,
  1182. locations: {}
  1183. };
  1184. for (var i = hintData.locations.length - 1; i >= 0; i--) {
  1185. loc = waypoints[i].latLng;
  1186. this._hints.locations[this._locationKey(loc)] = hintData.locations[i];
  1187. }
  1188. },
  1189. // Adapted from
  1190. // https://github.com/DennisSchiefer/Project-OSRM-Web/blob/develop/WebContent/routing/OSRM.RoutingGeometry.js
  1191. _decode: function(encoded, precision) {
  1192. var len = encoded.length,
  1193. index=0,
  1194. lat=0,
  1195. lng = 0,
  1196. array = [];
  1197. precision = Math.pow(10, -precision);
  1198. while (index < len) {
  1199. var b,
  1200. shift = 0,
  1201. result = 0;
  1202. do {
  1203. b = encoded.charCodeAt(index++) - 63;
  1204. result |= (b & 0x1f) << shift;
  1205. shift += 5;
  1206. } while (b >= 0x20);
  1207. var dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
  1208. lat += dlat;
  1209. shift = 0;
  1210. result = 0;
  1211. do {
  1212. b = encoded.charCodeAt(index++) - 63;
  1213. result |= (b & 0x1f) << shift;
  1214. shift += 5;
  1215. } while (b >= 0x20);
  1216. var dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
  1217. lng += dlng;
  1218. //array.push( {lat: lat * precision, lng: lng * precision} );
  1219. array.push( [lat * precision, lng * precision] );
  1220. }
  1221. return array;
  1222. },
  1223. _convertSummary: function(osrmSummary) {
  1224. return {
  1225. totalDistance: osrmSummary.total_distance,
  1226. totalTime: osrmSummary.total_time
  1227. };
  1228. },
  1229. _convertInstructions: function(osrmInstructions) {
  1230. var result = [],
  1231. i,
  1232. instr,
  1233. type,
  1234. driveDir;
  1235. for (i = 0; i < osrmInstructions.length; i++) {
  1236. instr = osrmInstructions[i];
  1237. type = this._drivingDirectionType(instr[0]);
  1238. driveDir = instr[0].split('-');
  1239. if (type) {
  1240. result.push({
  1241. type: type,
  1242. distance: instr[2],
  1243. time: instr[4],
  1244. road: instr[1],
  1245. direction: instr[6],
  1246. exit: driveDir.length > 1 ? driveDir[1] : undefined,
  1247. index: instr[3]
  1248. });
  1249. }
  1250. }
  1251. return result;
  1252. },
  1253. _drivingDirectionType: function(d) {
  1254. switch (parseInt(d, 10)) {
  1255. case 1:
  1256. return 'Straight';
  1257. case 2:
  1258. return 'SlightRight';
  1259. case 3:
  1260. return 'Right';
  1261. case 4:
  1262. return 'SharpRight';
  1263. case 5:
  1264. return 'TurnAround';
  1265. case 6:
  1266. return 'SharpLeft';
  1267. case 7:
  1268. return 'Left';
  1269. case 8:
  1270. return 'SlightRight';
  1271. case 9:
  1272. return 'WaypointReached';
  1273. case 10:
  1274. // TODO: "Head on"
  1275. // https://github.com/DennisOSRM/Project-OSRM/blob/master/DataStructures/TurnInstructions.h#L48
  1276. return 'Straight';
  1277. case 11:
  1278. case 12:
  1279. return 'Roundabout';
  1280. case 15:
  1281. return 'DestinationReached';
  1282. default:
  1283. return null;
  1284. }
  1285. },
  1286. _clampIndices: function(indices, coords) {
  1287. var maxCoordIndex = coords.length - 1,
  1288. i;
  1289. for (i = 0; i < indices.length; i++) {
  1290. indices[i] = Math.min(maxCoordIndex, Math.max(indices[i], 0));
  1291. }
  1292. }
  1293. });
  1294. L.Routing.osrm = function(options) {
  1295. return new L.Routing.OSRM(options);
  1296. };
  1297. module.exports = L.Routing;
  1298. })();
  1299. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1300. },{"./L.Routing.Waypoint":10}],9:[function(require,module,exports){
  1301. (function (global){
  1302. (function() {
  1303. 'use strict';
  1304. var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null);
  1305. L.Routing = L.Routing || {};
  1306. L.extend(L.Routing, require('./L.Routing.Autocomplete'));
  1307. L.extend(L.Routing, require('./L.Routing.Waypoint'));
  1308. function selectInputText(input) {
  1309. if (input.setSelectionRange) {
  1310. // On iOS, select() doesn't work
  1311. input.setSelectionRange(0, 9999);
  1312. } else {
  1313. // On at least IE8, setSeleectionRange doesn't exist
  1314. input.select();
  1315. }
  1316. }
  1317. L.Routing.Plan = L.Class.extend({
  1318. includes: L.Mixin.Events,
  1319. options: {
  1320. dragStyles: [
  1321. {color: 'black', opacity: 0.15, weight: 9},
  1322. {color: 'white', opacity: 0.8, weight: 6},
  1323. {color: 'red', opacity: 1, weight: 2, dashArray: '7,12'}
  1324. ],
  1325. draggableWaypoints: true,
  1326. addWaypoints: true,
  1327. maxGeocoderTolerance: 200,
  1328. autocompleteOptions: {},
  1329. geocodersClassName: '',
  1330. geocoderClassName: '',
  1331. geocoderPlaceholder: function(i, numberWaypoints) {
  1332. return i === 0 ?
  1333. 'Start' :
  1334. (i < numberWaypoints - 1 ?
  1335. 'Via ' + i :
  1336. 'End');
  1337. },
  1338. geocoderClass: function() {
  1339. return '';
  1340. },
  1341. createGeocoder: function() {
  1342. var container = L.DomUtil.create('div', ''),
  1343. input = L.DomUtil.create('input', '', container),
  1344. remove = L.DomUtil.create('span', 'leaflet-routing-remove-waypoint', container);
  1345. return {
  1346. container: container,
  1347. input: input,
  1348. closeButton: remove
  1349. };
  1350. },
  1351. waypointNameFallback: function(latLng) {
  1352. var ns = latLng.lat < 0 ? 'S' : 'N',
  1353. ew = latLng.lng < 0 ? 'W' : 'E',
  1354. lat = (Math.round(Math.abs(latLng.lat) * 10000) / 10000).toString(),
  1355. lng = (Math.round(Math.abs(latLng.lng) * 10000) / 10000).toString();
  1356. return ns + lat + ', ' + ew + lng;
  1357. }
  1358. },
  1359. initialize: function(waypoints, options) {
  1360. L.Util.setOptions(this, options);
  1361. this._waypoints = [];
  1362. this.setWaypoints(waypoints);
  1363. },
  1364. isReady: function() {
  1365. var i;
  1366. for (i = 0; i < this._waypoints.length; i++) {
  1367. if (!this._waypoints[i].latLng) {
  1368. return false;
  1369. }
  1370. }
  1371. return true;
  1372. },
  1373. getWaypoints: function() {
  1374. var i,
  1375. wps = [];
  1376. for (i = 0; i < this._waypoints.length; i++) {
  1377. wps.push(this._waypoints[i]);
  1378. }
  1379. return wps;
  1380. },
  1381. setWaypoints: function(waypoints) {
  1382. var args = [0, this._waypoints.length].concat(waypoints);
  1383. this.spliceWaypoints.apply(this, args);
  1384. return this;
  1385. },
  1386. spliceWaypoints: function() {
  1387. var args = [arguments[0], arguments[1]],
  1388. i,
  1389. wp;
  1390. for (i = 2; i < arguments.length; i++) {
  1391. args.push(arguments[i] && arguments[i].hasOwnProperty('latLng') ? arguments[i] : L.Routing.waypoint(arguments[i]));
  1392. }
  1393. [].splice.apply(this._waypoints, args);
  1394. while (this._waypoints.length < 2) {
  1395. wp = L.Routing.waypoint();
  1396. this._waypoints.push(wp);
  1397. args.push(wp);
  1398. }
  1399. this._updateMarkers();
  1400. this._fireChanged.apply(this, args);
  1401. },
  1402. onAdd: function(map) {
  1403. this._map = map;
  1404. this._updateMarkers();
  1405. },
  1406. onRemove: function() {
  1407. var i;
  1408. this._removeMarkers();
  1409. if (this._newWp) {
  1410. for (i = 0; i < this._newWp.lines.length; i++) {
  1411. this._map.removeLayer(this._newWp.lines[i]);
  1412. }
  1413. }
  1414. delete this._map;
  1415. },
  1416. createGeocoders: function() {
  1417. var container = L.DomUtil.create('div', 'leaflet-routing-geocoders ' + this.options.geocodersClassName),
  1418. waypoints = this._waypoints,
  1419. i,
  1420. geocoderElem,
  1421. addWpBtn;
  1422. this._geocoderContainer = container;
  1423. this._geocoderElems = [];
  1424. for (i = 0; i < waypoints.length; i++) {
  1425. geocoderElem = this._createGeocoder(i);
  1426. container.appendChild(geocoderElem.container);
  1427. this._geocoderElems.push(geocoderElem);
  1428. }
  1429. addWpBtn = L.DomUtil.create('button', '', container);
  1430. addWpBtn.setAttribute('type', 'button');
  1431. addWpBtn.innerHTML = '+';
  1432. if (this.options.addWaypoints) {
  1433. L.DomEvent.addListener(addWpBtn, 'click', function() {
  1434. this.spliceWaypoints(waypoints.length, 0, null);
  1435. }, this);
  1436. } else {
  1437. addWpBtn.style.display = 'none';
  1438. }
  1439. this.on('waypointsspliced', this._updateGeocoders);
  1440. return container;
  1441. },
  1442. _createGeocoder: function(i) {
  1443. var nWps = this._waypoints.length,
  1444. g = this.options.createGeocoder(i, nWps),
  1445. closeButton = g.closeButton,
  1446. geocoderInput = g.input,
  1447. wp = this._waypoints[i];
  1448. geocoderInput.setAttribute('placeholder', this.options.geocoderPlaceholder(i, nWps));
  1449. geocoderInput.className = this.options.geocoderClass(i, nWps);
  1450. this._updateWaypointName(i, geocoderInput);
  1451. // This has to be here, or geocoder's value will not be properly
  1452. // initialized.
  1453. // TODO: look into why and make _updateWaypointName fix this.
  1454. geocoderInput.value = wp.name;
  1455. L.DomEvent.addListener(geocoderInput, 'click', function() {
  1456. selectInputText(this);
  1457. }, geocoderInput);
  1458. if (closeButton) {
  1459. L.DomEvent.addListener(closeButton, 'click', function() {
  1460. this.spliceWaypoints(i, 1);
  1461. }, this);
  1462. }
  1463. new L.Routing.Autocomplete(geocoderInput, function(r) {
  1464. geocoderInput.value = r.name;
  1465. wp.name = r.name;
  1466. wp.latLng = r.center;
  1467. this._updateMarkers();
  1468. this._fireChanged();
  1469. this._focusGeocoder(i + 1);
  1470. }, this, L.extend({
  1471. resultFn: this.options.geocoder.geocode,
  1472. resultContext: this.options.geocoder,
  1473. autocompleteFn: this.options.geocoder.suggest,
  1474. autocompleteContext: this.options.geocoder
  1475. }, this.options.autocompleteOptions));
  1476. return g;
  1477. },
  1478. _updateGeocoders: function(e) {
  1479. var newElems = [],
  1480. i,
  1481. geocoderElem,
  1482. beforeElem;
  1483. // Determine where to insert geocoders for new waypoints
  1484. if (e.index >= this._geocoderElems.length) {
  1485. // lastChild is the "add new wp" button
  1486. beforeElem = this._geocoderContainer.lastChild;
  1487. } else {
  1488. beforeElem = this._geocoderElems[e.index].container;
  1489. }
  1490. // Insert new geocoders for new waypoints
  1491. for (i = 0; i < e.added.length; i++) {
  1492. geocoderElem = this._createGeocoder(e.index + i);
  1493. this._geocoderContainer.insertBefore(geocoderElem.container, beforeElem);
  1494. newElems.push(geocoderElem);
  1495. }
  1496. //newElems.reverse();
  1497. for (i = e.index; i < e.index + e.nRemoved; i++) {
  1498. this._geocoderContainer.removeChild(this._geocoderElems[i].container);
  1499. }
  1500. newElems.splice(0, 0, e.index, e.nRemoved);
  1501. [].splice.apply(this._geocoderElems, newElems);
  1502. for (i = 0; i < this._geocoderElems.length; i++) {
  1503. this._geocoderElems[i].input.placeholder = this.options.geocoderPlaceholder(i, this._waypoints.length);
  1504. this._geocoderElems[i].input.className = this.options.geocoderClass(i, this._waypoints.length);
  1505. }
  1506. },
  1507. _updateGeocoder: function(i, geocoderElem) {
  1508. var wp = this._waypoints[i],
  1509. value = wp && wp.name ? wp.name : '';
  1510. if (geocoderElem) {
  1511. geocoderElem.value = value;
  1512. }
  1513. },
  1514. _updateWaypointName: function(i, geocoderElem, force) {
  1515. var wp = this._waypoints[i],
  1516. wpCoords;
  1517. wp.name = wp.name || '';
  1518. if (wp.latLng && (force || !wp.name)) {
  1519. wpCoords = this.options.waypointNameFallback(wp.latLng);
  1520. if (this.options.geocoder && this.options.geocoder.reverse) {
  1521. this.options.geocoder.reverse(wp.latLng, 67108864 /* zoom 18 */, function(rs) {
  1522. if (rs.length > 0 && rs[0].center.distanceTo(wp.latLng) < this.options.maxGeocoderTolerance) {
  1523. wp.name = rs[0].name;
  1524. } else {
  1525. wp.name = wpCoords;
  1526. }
  1527. this._updateGeocoder(i, geocoderElem);
  1528. }, this);
  1529. } else {
  1530. wp.name = wpCoords;
  1531. }
  1532. this._updateGeocoder(i, geocoderElem);
  1533. }
  1534. },
  1535. _removeMarkers: function() {
  1536. var i;
  1537. if (this._markers) {
  1538. for (i = 0; i < this._markers.length; i++) {
  1539. if (this._markers[i]) {
  1540. this._map.removeLayer(this._markers[i]);
  1541. }
  1542. }
  1543. }
  1544. this._markers = [];
  1545. },
  1546. _updateMarkers: function() {
  1547. var i,
  1548. icon,
  1549. m;
  1550. if (!this._map) {
  1551. return;
  1552. }
  1553. this._removeMarkers();
  1554. for (i = 0; i < this._waypoints.length; i++) {
  1555. if (this._waypoints[i].latLng) {
  1556. icon = (typeof(this.options.waypointIcon) === 'function') ?
  1557. this.options.waypointIcon(i, this._waypoints[i].name, this._waypoints.length) :
  1558. this.options.waypointIcon;
  1559. m = this._createMarker(icon, i);
  1560. if (this.options.draggableWaypoints) {
  1561. this._hookWaypointEvents(m, i);
  1562. }
  1563. } else {
  1564. m = null;
  1565. }
  1566. this._markers.push(m);
  1567. }
  1568. },
  1569. _createMarker: function(icon, i) {
  1570. var options = {
  1571. draggable: this.options.draggableWaypoints
  1572. };
  1573. if (icon) {
  1574. options.icon = icon;
  1575. }
  1576. return L.marker(this._waypoints[i].latLng, options).addTo(this._map);
  1577. },
  1578. _fireChanged: function() {
  1579. this.fire('waypointschanged', {waypoints: this.getWaypoints()});
  1580. if (arguments.length >= 2) {
  1581. this.fire('waypointsspliced', {
  1582. index: Array.prototype.shift.call(arguments),
  1583. nRemoved: Array.prototype.shift.call(arguments),
  1584. added: arguments
  1585. });
  1586. }
  1587. },
  1588. _hookWaypointEvents: function(m, i) {
  1589. m.on('dragstart', function(e) {
  1590. this.fire('waypointdragstart', this._createWaypointEvent(i, e));
  1591. }, this);
  1592. m.on('drag', function(e) {
  1593. this._waypoints[i].latLng = e.target.getLatLng();
  1594. this.fire('waypointdrag', this._createWaypointEvent(i, e));
  1595. }, this);
  1596. m.on('dragend', function(e) {
  1597. this._waypoints[i].latLng = e.target.getLatLng();
  1598. this._waypoints[i].name = '';
  1599. this._updateWaypointName(i, this._geocoderElems && this._geocoderElems[i].input, true);
  1600. this.fire('waypointdragend', this._createWaypointEvent(i, e));
  1601. this._fireChanged();
  1602. }, this);
  1603. },
  1604. _createWaypointEvent: function(i, e) {
  1605. return {index: i, latlng: e.target.getLatLng()};
  1606. },
  1607. dragNewWaypoint: function(e) {
  1608. var i;
  1609. this._newWp = {
  1610. afterIndex: e.afterIndex,
  1611. marker: L.marker(e.latlng).addTo(this._map),
  1612. lines: []
  1613. };
  1614. for (i = 0; i < this.options.dragStyles.length; i++) {
  1615. this._newWp.lines.push(L.polyline([
  1616. this._waypoints[e.afterIndex].latLng,
  1617. e.latlng,
  1618. this._waypoints[e.afterIndex + 1].latLng
  1619. ], this.options.dragStyles[i]).addTo(this._map));
  1620. }
  1621. this._markers.splice(e.afterIndex + 1, 0, this._newWp.marker);
  1622. this._map.on('mousemove', this._onDragNewWp, this);
  1623. this._map.on('mouseup', this._onWpRelease, this);
  1624. },
  1625. _onDragNewWp: function(e) {
  1626. var i;
  1627. this._newWp.marker.setLatLng(e.latlng);
  1628. for (i = 0; i < this._newWp.lines.length; i++) {
  1629. this._newWp.lines[i].spliceLatLngs(1, 1, e.latlng);
  1630. }
  1631. },
  1632. _onWpRelease: function(e) {
  1633. var i;
  1634. this._map.off('mouseup', this._onWpRelease, this);
  1635. this._map.off('mousemove', this._onDragNewWp, this);
  1636. for (i = 0; i < this._newWp.lines.length; i++) {
  1637. this._map.removeLayer(this._newWp.lines[i]);
  1638. }
  1639. this.spliceWaypoints(this._newWp.afterIndex + 1, 0, e.latlng);
  1640. delete this._newWp;
  1641. },
  1642. _focusGeocoder: function(i) {
  1643. var input;
  1644. if (this._geocoderElems[i]) {
  1645. input = this._geocoderElems[i].input;
  1646. input.focus();
  1647. selectInputText(input);
  1648. } else {
  1649. document.activeElement.blur();
  1650. }
  1651. }
  1652. });
  1653. L.Routing.plan = function(waypoints, options) {
  1654. return new L.Routing.Plan(waypoints, options);
  1655. };
  1656. module.exports = L.Routing;
  1657. })();
  1658. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1659. },{"./L.Routing.Autocomplete":1,"./L.Routing.Waypoint":10}],10:[function(require,module,exports){
  1660. (function (global){
  1661. (function() {
  1662. 'use strict';
  1663. var L = (typeof window !== "undefined" ? window.L : typeof global !== "undefined" ? global.L : null);
  1664. L.Routing = L.Routing || {};
  1665. L.Routing.Waypoint = L.Class.extend({
  1666. options: {
  1667. allowUTurn: false,
  1668. },
  1669. initialize: function(latLng, name, options) {
  1670. L.Util.setOptions(this, options);
  1671. this.latLng = latLng;
  1672. this.name = name;
  1673. }
  1674. });
  1675. L.Routing.waypoint = function(latLng, name, options) {
  1676. return new L.Routing.Waypoint(latLng, name, options);
  1677. };
  1678. module.exports = L.Routing;
  1679. })();
  1680. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1681. },{}]},{},[2])(2)
  1682. });