1(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.leafletControlGeocoder = f()}})(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(_dereq_,module,exports){ 2(function (global){ 3var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), 4 Nominatim = _dereq_('./geocoders/nominatim')["class"]; 5 6module.exports = { 7 "class": L.Control.extend({ 8 options: { 9 showResultIcons: false, 10 collapsed: true, 11 expand: 'touch', // options: touch, click, anythingelse 12 position: 'topright', 13 placeholder: 'Search...', 14 errorMessage: 'Nothing found.', 15 suggestMinLength: 3, 16 suggestTimeout: 250, 17 defaultMarkGeocode: true 18 }, 19 20 includes: L.Evented.prototype || L.Mixin.Events, 21 22 initialize: function (options) { 23 L.Util.setOptions(this, options); 24 if (!this.options.geocoder) { 25 this.options.geocoder = new Nominatim(); 26 } 27 28 this._requestCount = 0; 29 }, 30 31 onAdd: function (map) { 32 var className = 'leaflet-control-geocoder', 33 container = L.DomUtil.create('div', className + ' leaflet-bar'), 34 icon = L.DomUtil.create('button', className + '-icon', container), 35 form = this._form = L.DomUtil.create('div', className + '-form', container), 36 input; 37 38 this._map = map; 39 this._container = container; 40 41 icon.innerHTML = ' '; 42 icon.type = 'button'; 43 44 input = this._input = L.DomUtil.create('input', '', form); 45 input.type = 'text'; 46 input.placeholder = this.options.placeholder; 47 48 this._errorElement = L.DomUtil.create('div', className + '-form-no-error', container); 49 this._errorElement.innerHTML = this.options.errorMessage; 50 51 this._alts = L.DomUtil.create('ul', 52 className + '-alternatives leaflet-control-geocoder-alternatives-minimized', 53 container); 54 L.DomEvent.disableClickPropagation(this._alts); 55 56 L.DomEvent.addListener(input, 'keydown', this._keydown, this); 57 if (this.options.geocoder.suggest) { 58 L.DomEvent.addListener(input, 'input', this._change, this); 59 } 60 L.DomEvent.addListener(input, 'blur', function() { 61 if (this.options.collapsed && !this._preventBlurCollapse) { 62 this._collapse(); 63 } 64 this._preventBlurCollapse = false; 65 }, this); 66 67 68 if (this.options.collapsed) { 69 if (this.options.expand === 'click') { 70 L.DomEvent.addListener(container, 'click', function(e) { 71 if (e.button === 0 && e.detail !== 2) { 72 this._toggle(); 73 } 74 }, this); 75 } 76 else if (L.Browser.touch && this.options.expand === 'touch') { 77 L.DomEvent.addListener(container, 'touchstart mousedown', function(e) { 78 this._toggle(); 79 e.preventDefault(); // mobile: clicking focuses the icon, so UI expands and immediately collapses 80 e.stopPropagation(); 81 }, this); 82 } 83 else { 84 L.DomEvent.addListener(container, 'mouseover', this._expand, this); 85 L.DomEvent.addListener(container, 'mouseout', this._collapse, this); 86 this._map.on('movestart', this._collapse, this); 87 } 88 } else { 89 this._expand(); 90 if (L.Browser.touch) { 91 L.DomEvent.addListener(container, 'touchstart', function(e) { 92 this._geocode(e); 93 }, this); 94 } 95 else { 96 L.DomEvent.addListener(container, 'click', function(e) { 97 this._geocode(e); 98 }, this); 99 } 100 } 101 102 if (this.options.defaultMarkGeocode) { 103 this.on('markgeocode', this.markGeocode, this); 104 } 105 106 this.on('startgeocode', function() { 107 L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-throbber'); 108 }, this); 109 this.on('finishgeocode', function() { 110 L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-throbber'); 111 }, this); 112 113 L.DomEvent.disableClickPropagation(container); 114 115 return container; 116 }, 117 118 _geocodeResult: function (results, suggest) { 119 if (!suggest && results.length === 1) { 120 this._geocodeResultSelected(results[0]); 121 } else if (results.length > 0) { 122 this._alts.innerHTML = ''; 123 this._results = results; 124 L.DomUtil.removeClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); 125 for (var i = 0; i < results.length; i++) { 126 this._alts.appendChild(this._createAlt(results[i], i)); 127 } 128 } else { 129 L.DomUtil.addClass(this._errorElement, 'leaflet-control-geocoder-error'); 130 } 131 }, 132 133 markGeocode: function(result) { 134 result = result.geocode || result; 135 136 this._map.fitBounds(result.bbox); 137 138 if (this._geocodeMarker) { 139 this._map.removeLayer(this._geocodeMarker); 140 } 141 142 this._geocodeMarker = new L.Marker(result.center) 143 .bindPopup(result.html || result.name) 144 .addTo(this._map) 145 .openPopup(); 146 147 return this; 148 }, 149 150 _geocode: function(suggest) { 151 var requestCount = ++this._requestCount, 152 mode = suggest ? 'suggest' : 'geocode',
153 eventData = {input: this._input.value}; 154 155 this._lastGeocode = this._input.value; 156 if (!suggest) { 157 this._clearResults(); 158 } 159 160 this.fire('start' + mode, eventData); 161 this.options.geocoder[mode](this._input.value, function(results) { 162 if (requestCount === this._requestCount) { 163 eventData.results = results; 164 this.fire('finish' + mode, eventData); 165 this._geocodeResult(results, suggest); 166 } 167 }, this); 168 }, 169 170 _geocodeResultSelected: function(result) { 171 this.fire('markgeocode', {geocode: result}); 172 }, 173 174 _toggle: function() { 175 if (L.DomUtil.hasClass(this._container, 'leaflet-control-geocoder-expanded')) { 176 this._collapse(); 177 } else { 178 this._expand(); 179 } 180 }, 181 182 _expand: function () { 183 L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-expanded'); 184 this._input.select(); 185 this.fire('expand'); 186 }, 187 188 _collapse: function () { 189 L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-expanded'); 190 L.DomUtil.addClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); 191 L.DomUtil.removeClass(this._errorElement, 'leaflet-control-geocoder-error'); 192 this._input.blur(); // mobile: keyboard shouldn't stay expanded 193 this.fire('collapse'); 194 }, 195 196 _clearResults: function () { 197 L.DomUtil.addClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); 198 this._selection = null; 199 L.DomUtil.removeClass(this._errorElement, 'leaflet-control-geocoder-error'); 200 }, 201 202 _createAlt: function(result, index) { 203 var li = L.DomUtil.create('li', ''), 204 a = L.DomUtil.create('a', '', li), 205 icon = this.options.showResultIcons && result.icon ? L.DomUtil.create('img', '', a) : null, 206 text = result.html ? undefined : document.createTextNode(result.name), 207 mouseDownHandler = function mouseDownHandler(e) { 208 // In some browsers, a click will fire on the map if the control is 209 // collapsed directly after mousedown. To work around this, we 210 // wait until the click is completed, and _then_ collapse the 211 // control. Messy, but this is the workaround I could come up with 212 // for #142. 213 this._preventBlurCollapse = true; 214 L.DomEvent.stop(e); 215 this._geocodeResultSelected(result); 216 L.DomEvent.on(li, 'click', function() { 217 if (this.options.collapsed) { 218 this._collapse(); 219 } else { 220 this._clearResults(); 221 } 222 }, this); 223 }; 224 225 if (icon) { 226 icon.src = result.icon; 227 } 228 229 li.setAttribute('data-result-index', index); 230 231 if (result.html) { 232 a.innerHTML = a.innerHTML + result.html; 233 } else { 234 a.appendChild(text); 235 } 236 237 // Use mousedown and not click, since click will fire _after_ blur, 238 // causing the control to have collapsed and removed the items 239 // before the click can fire. 240 L.DomEvent.addListener(li, 'mousedown touchstart', mouseDownHandler, this); 241 242 return li; 243 }, 244 245 _keydown: function(e) { 246 var _this = this, 247 select = function select(dir) { 248 if (_this._selection) { 249 L.DomUtil.removeClass(_this._selection, 'leaflet-control-geocoder-selected'); 250 _this._selection = _this._selection[dir > 0 ? 'nextSibling' : 'previousSibling']; 251 } 252 if (!_this._selection) { 253 _this._selection = _this._alts[dir > 0 ? 'firstChild' : 'lastChild']; 254 } 255 256 if (_this._selection) { 257 L.DomUtil.addClass(_this._selection, 'leaflet-control-geocoder-selected'); 258 } 259 }; 260 261 switch (e.keyCode) { 262 // Escape 263 case 27: 264 if (this.options.collapsed) { 265 this._collapse(); 266 } 267 break; 268 // Up 269 case 38: 270 select(-1); 271 break; 272 // Up 273 case 40: 274 select(1); 275 break; 276 // Enter 277 case 13: 278 if (this._selection) { 279 var index = parseInt(this._selection.getAttribute('data-result-index'), 10); 280 this._geocodeResultSelected(this._results[index]); 281 this._clearResults(); 282 } else { 283 this._geocode(); 284 } 285 break; 286 } 287 }, 288 _change: function(e) { 289 var v = this._input.value; 290 if (v !== this._lastGeocode) { 291 clearTimeout(this._suggestTimeout); 292 if (v.length >= this.options.suggestMinLength) { 293 this._suggestTimeout = setTimeout(L.bind(function() { 294 this._geocode(true); 295 }, this), this.options.suggestTimeout); 296 } else { 297 this._clearResults(); 298 } 299 } 300 } 301 }), 302 factory: function(options) { 303 return new L.Control.Geocoder(options); 304 } 305}; 306 307}
307).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 308},{"./geocoders/nominatim":9}],2:[function(_dereq_,module,exports){ 309(function (global){ 310var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), 311 Util = _dereq_('../util'); 312 313module.exports = { 314 "class": L.Class.extend({ 315 options: { 316 service_url: 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer' 317 }, 318 319 initialize: function(accessToken, options) { 320 L.setOptions(this, options); 321 this._accessToken = accessToken; 322 }, 323 324 geocode: function(query, cb, context) { 325 var params = { 326 SingleLine: query, 327 outFields: 'Addr_Type', 328 forStorage: false, 329 maxLocations: 10, 330 f: 'json' 331 }; 332 333 if (this._key && this._key.length) { 334 params.token = this._key; 335 } 336 337 Util.getJSON(this.options.service_url + '/findAddressCandidates', params, function(data) { 338 var results = [], 339 loc, 340 latLng, 341 latLngBounds; 342 343 if (data.candidates && data.candidates.length) { 344 for (var i = 0; i <= data.candidates.length - 1; i++) { 345 loc = data.candidates[i]; 346 latLng = L.latLng(loc.location.y, loc.location.x); 347 latLngBounds = L.latLngBounds(L.latLng(loc.extent.ymax, loc.extent.xmax), L.latLng(loc.extent.ymin, loc.extent.xmin)); 348 results[i] = { 349 name: loc.address, 350 bbox: latLngBounds, 351 center: latLng 352 }; 353 } 354 } 355 356 cb.call(context, results); 357 }); 358 }, 359 360 suggest: function(query, cb, context) { 361 return this.geocode(query, cb, context); 362 }, 363 364 reverse: function(location, scale, cb, context) { 365 var params = { 366 location: encodeURIComponent(location.lng) + ',' + encodeURIComponent(location.lat), 367 distance: 100, 368 f: 'json' 369 }; 370 371 Util.getJSON(this.options.service_url + '/reverseGeocode', params, function(data) { 372 var result = [], 373 loc; 374 375 if (data && !data.error) { 376 loc = L.latLng(data.location.y, data.location.x); 377 result.push({ 378 name: data.address.Match_addr, 379 center: loc, 380 bounds: L.latLngBounds(loc, loc) 381 }); 382 } 383 384 cb.call(context, result); 385 }); 386 } 387 }), 388 389 factory: function(accessToken, options) { 390 return new L.Control.Geocoder.ArcGis(accessToken, options); 391 } 392}; 393 394}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 395},{"../util":13}],3:[function(_dereq_,module,exports){ 396(function (global){ 397var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null),
398 Util = _dereq_('../util'); 399 400module.exports = { 401 "class": L.Class.extend({ 402 initialize: function(key) { 403 this.key = key; 404 }, 405 406 geocode : function (query, cb, context) { 407 Util.jsonp('https://dev.virtualearth.net/REST/v1/Locations', { 408 query: query, 409 key : this.key 410 }, function(data) { 411 var results = []; 412 if( data.resourceSets.length > 0 ){ 413 for (var i = data.resourceSets[0].resources.length - 1; i >= 0; i--) { 414 var resource = data.resourceSets[0].resources[i], 415 bbox = resource.bbox; 416 results[i] = { 417 name: resource.name, 418 bbox: L.latLngBounds([bbox[0], bbox[1]], [bbox[2], bbox[3]]), 419 center: L.latLng(resource.point.coordinates) 420 }; 421 } 422 } 423 cb.call(context, results); 424 }, this, 'jsonp'); 425 }, 426 427 reverse: function(location, scale, cb, context) { 428 Util.jsonp('//dev.virtualearth.net/REST/v1/Locations/' + location.lat + ',' + location.lng, { 429 key : this.key 430 }, function(data) { 431 var results = []; 432 for (var i = data.resourceSets[0].resources.length - 1; i >= 0; i--) { 433 var resource = data.resourceSets[0].resources[i], 434 bbox = resource.bbox; 435 results[i] = { 436 name: resource.name, 437 bbox: L.latLngBounds([bbox[0], bbox[1]], [bbox[2], bbox[3]]), 438 center: L.latLng(resource.point.coordinates) 439 }; 440 } 441 cb.call(context, results); 442 }, this, 'jsonp'); 443 } 444 }), 445 446 factory: function(key) { 447 return new L.Control.Geocoder.Bing(key); 448 } 449}; 450 451}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 452},{"../util":13}],4:[function(_dereq_,module,exports){ 453(function (global){ 454var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null),
455 Util = _dereq_('../util'); 456 457module.exports = { 458 "class": L.Class.extend({ 459 options: { 460 serviceUrl: 'https://maps.googleapis.com/maps/api/geocode/json', 461 geocodingQueryParams: {}, 462 reverseQueryParams: {} 463 }, 464 465 initialize: function(key, options) { 466 this._key = key; 467 L.setOptions(this, options); 468 // Backwards compatibility 469 this.options.serviceUrl = this.options.service_url || this.options.serviceUrl; 470 }, 471 472 geocode: function(query, cb, context) { 473 var params = { 474 address: query 475 }; 476 477 if (this._key && this._key.length) { 478 params.key = this._key; 479 } 480 481 params = L.Util.extend(params, this.options.geocodingQueryParams); 482 483 Util.getJSON(this.options.serviceUrl, params, function(data) { 484 var results = [], 485 loc, 486 latLng, 487 latLngBounds; 488 if (data.results && data.results.length) { 489 for (var i = 0; i <= data.results.length - 1; i++) { 490 loc = data.results[i]; 491 latLng = L.latLng(loc.geometry.location); 492 latLngBounds = L.latLngBounds(L.latLng(loc.geometry.viewport.northeast), L.latLng(loc.geometry.viewport.southwest)); 493 results[i] = { 494 name: loc.formatted_address, 495 bbox: latLngBounds, 496 center: latLng, 497 properties: loc.address_components 498 }; 499 } 500 } 501 502 cb.call(context, results); 503 }); 504 }, 505 506 reverse: function(location, scale, cb, context) { 507 var params = { 508 latlng: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng) 509 }; 510 params = L.Util.extend(params, this.options.reverseQueryParams); 511 if (this._key && this._key.length) { 512 params.key = this._key; 513 } 514 515 Util.getJSON(this.options.serviceUrl, params, function(data) { 516 var results = [], 517 loc, 518 latLng, 519 latLngBounds; 520 if (data.results && data.results.length) { 521 for (var i = 0; i <= data.results.length - 1; i++) { 522 loc = data.results[i]; 523 latLng = L.latLng(loc.geometry.location); 524 latLngBounds = L.latLngBounds(L.latLng(loc.geometry.viewport.northeast), L.latLng(loc.geometry.viewport.southwest)); 525 results[i] = { 526 name: loc.formatted_address, 527 bbox: latLngBounds, 528 center: latLng, 529 properties: loc.address_components 530 }; 531 } 532 } 533 534 cb.call(context, results); 535 }); 536 } 537 }), 538 539 factory: function(key, options) { 540 return new L.Control.Geocoder.Google(key, options); 541 } 542}; 543 544}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 545},{"../util":13}],5:[function(_dereq_,module,exports){ 546(function (global){ 547var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), 548 Util = _dereq_('../util'); 549 550module.exports = { 551 "class": L.Class.extend({ 552 options: { 553 geocodeUrl: 'http://geocoder.api.here.com/6.2/geocode.json', 554 reverseGeocodeUrl: 'http://reverse.geocoder.api.here.com/6.2/reversegeocode.json', 555 app_id: '<insert your app_id here>', 556 app_code: '<insert your app_code here>', 557 geocodingQueryParams: {}, 558 reverseQueryParams: {} 559 }, 560 561 initialize: function(options) { 562 L.setOptions(this, options); 563 }, 564 565 geocode: function(query, cb, context) { 566 var params = { 567 searchtext: query, 568 gen: 9, 569 app_id: this.options.app_id, 570 app_code: this.options.app_code, 571 jsonattributes: 1 572 }; 573 params = L.Util.extend(params, this.options.geocodingQueryParams); 574 this.getJSON(this.options.geocodeUrl, params, cb, context); 575 }, 576 577 reverse: function(location, scale, cb, context) { 578 var params = { 579 prox: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng), 580 mode: 'retrieveAddresses', 581 app_id: this.options.app_id, 582 app_code: this.options.app_code, 583 gen: 9, 584 jsonattributes: 1 585 }; 586 params = L.Util.extend(params, this.options.reverseQueryParams); 587 this.getJSON(this.options.reverseGeocodeUrl, params, cb, context); 588 }, 589 590 getJSON: function(url, params, cb, context) { 591 Util.getJSON(url, params, function(data) { 592 var results = [], 593 loc, 594 latLng, 595 latLngBounds; 596 if (data.response.view && data.response.view.length) { 597 for (var i = 0; i <= data.response.view[0].result.length - 1; i++) { 598 loc = data.response.view[0].result[i].location; 599 latLng = L.latLng(loc.displayPosition.latitude, loc.displayPosition.longitude); 600 latLngBounds = L.latLngBounds(L.latLng(loc.mapView.topLeft.latitude, loc.mapView.topLeft.longitude), L.latLng(loc.mapView.bottomRight.latitude, loc.mapView.bottomRight.longitude)); 601 results[i] = { 602 name: loc.address.label, 603 bbox: latLngBounds, 604 center: latLng 605 }; 606 } 607 } 608 cb.call(context, results); 609 }) 610 } 611 }), 612 613 factory: function(options) { 614 return new L.Control.Geocoder.HERE(options); 615 } 616}; 617 618}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 619},{"../util":13}],6:[function(_dereq_,module,exports){ 620(function (global){ 621var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null),
622 Util = _dereq_('../util'); 623 624module.exports = { 625 "class": L.Class.extend({ 626 options: { 627 serviceUrl: 'https://api.tiles.mapbox.com/v4/geocode/mapbox.places-v1/', 628 geocodingQueryParams: {}, 629 reverseQueryParams: {} 630 }, 631 632 initialize: function(accessToken, options) { 633 L.setOptions(this, options); 634 this.options.geocodingQueryParams.access_token = accessToken; 635 this.options.reverseQueryParams.access_token = accessToken; 636 }, 637 638 geocode: function(query, cb, context) { 639 var params = this.options.geocodingQueryParams; 640 if (typeof params.proximity !== 'undefined' 641 && params.proximity.hasOwnProperty('lat') 642 && params.proximity.hasOwnProperty('lng')) 643 { 644 params.proximity = params.proximity.lng + ',' + params.proximity.lat; 645 } 646 Util.getJSON(this.options.serviceUrl + encodeURIComponent(query) + '.json', params, function(data) { 647 var results = [], 648 loc, 649 latLng, 650 latLngBounds; 651 if (data.features && data.features.length) { 652 for (var i = 0; i <= data.features.length - 1; i++) { 653 loc = data.features[i]; 654 latLng = L.latLng(loc.center.reverse()); 655 if (loc.hasOwnProperty('bbox')) 656 { 657 latLngBounds = L.latLngBounds(L.latLng(loc.bbox.slice(0, 2).reverse()), L.latLng(loc.bbox.slice(2, 4).reverse())); 658 } 659 else 660 { 661 latLngBounds = L.latLngBounds(latLng, latLng); 662 } 663 results[i] = { 664 name: loc.place_name, 665 bbox: latLngBounds, 666 center: latLng 667 }; 668 } 669 } 670 671 cb.call(context, results); 672 }); 673 }, 674 675 suggest: function(query, cb, context) { 676 return this.geocode(query, cb, context); 677 }, 678 679 reverse: function(location, scale, cb, context) { 680 Util.getJSON(this.options.serviceUrl + encodeURIComponent(location.lng) + ',' + encodeURIComponent(location.lat) + '.json', this.options.reverseQueryParams, function(data) { 681 var results = [], 682 loc, 683 latLng, 684 latLngBounds; 685 if (data.features && data.features.length) { 686 for (var i = 0; i <= data.features.length - 1; i++) { 687 loc = data.features[i]; 688 latLng = L.latLng(loc.center.reverse()); 689 if (loc.hasOwnProperty('bbox')) 690 { 691 latLngBounds = L.latLngBounds(L.latLng(loc.bbox.slice(0, 2).reverse()), L.latLng(loc.bbox.slice(2, 4).reverse())); 692 } 693 else 694 { 695 latLngBounds = L.latLngBounds(latLng, latLng); 696 } 697 results[i] = { 698 name: loc.place_name, 699 bbox: latLngBounds, 700 center: latLng 701 }; 702 } 703 } 704 705 cb.call(context, results); 706 }); 707 } 708 }), 709 710 factory: function(accessToken, options) { 711 return new L.Control.Geocoder.Mapbox(accessToken, options); 712 } 713}; 714 715 716}
716).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 717},{"../util":13}],7:[function(_dereq_,module,exports){ 718(function (global){ 719var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), 720 Util = _dereq_('../util'); 721 722module.exports = { 723 "class": L.Class.extend({ 724 options: { 725 serviceUrl: 'https://www.mapquestapi.com/geocoding/v1' 726 }, 727 728 initialize: function(key, options) { 729 // MapQuest seems to provide URI encoded API keys, 730 // so to avoid encoding them twice, we decode them here 731 this._key = decodeURIComponent(key); 732 733 L.Util.setOptions(this, options); 734 }, 735 736 _formatName: function() { 737 var r = [], 738 i; 739 for (i = 0; i < arguments.length; i++) { 740 if (arguments[i]) { 741 r.push(arguments[i]); 742 } 743 } 744 745 return r.join(', '); 746 }, 747 748 geocode: function(query, cb, context) { 749 Util.jsonp(this.options.serviceUrl + '/address', { 750 key: this._key, 751 location: query, 752 limit: 5, 753 outFormat: 'json' 754 }, function(data) { 755 var results = [], 756 loc, 757 latLng; 758 if (data.results && data.results[0].locations) { 759 for (var i = data.results[0].locations.length - 1; i >= 0; i--) { 760 loc = data.results[0].locations[i]; 761 latLng = L.latLng(loc.latLng); 762 results[i] = { 763 name: this._formatName(loc.street, loc.adminArea4, loc.adminArea3, loc.adminArea1), 764 bbox: L.latLngBounds(latLng, latLng), 765 center: latLng 766 }; 767 } 768 } 769 770 cb.call(context, results); 771 }, this); 772 }, 773 774 reverse: function(location, scale, cb, context) { 775 Util.jsonp(this.options.serviceUrl + '/reverse', { 776 key: this._key, 777 location: location.lat + ',' + location.lng, 778 outputFormat: 'json' 779 }, function(data) { 780 var results = [], 781 loc, 782 latLng; 783 if (data.results && data.results[0].locations) { 784 for (var i = data.results[0].locations.length - 1; i >= 0; i--) { 785 loc = data.results[0].locations[i]; 786 latLng = L.latLng(loc.latLng); 787 results[i] = { 788 name: this._formatName(loc.street, loc.adminArea4, loc.adminArea3, loc.adminArea1), 789 bbox: L.latLngBounds(latLng, latLng), 790 center: latLng 791 }; 792 } 793 } 794 795 cb.call(context, results); 796 }, this); 797 } 798 }), 799 800 factory: function(key, options) { 801 return new L.Control.Geocoder.MapQuest(key, options); 802 } 803}; 804 805}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 806},{"../util":13}],8:[function(_dereq_,module,exports){ 807(function (global){ 808var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null),
809 Util = _dereq_('../util'); 810 811module.exports = { 812 "class": L.Class.extend({ 813 options: { 814 serviceUrl: 'https://search.mapzen.com/v1', 815 geocodingQueryParams: {}, 816 reverseQueryParams: {} 817 }, 818 819 initialize: function(apiKey, options) { 820 L.Util.setOptions(this, options); 821 this._apiKey = apiKey; 822 this._lastSuggest = 0; 823 }, 824 825 geocode: function(query, cb, context) { 826 var _this = this; 827 Util.getJSON(this.options.serviceUrl + "/search", L.extend({ 828 'api_key': this._apiKey, 829 'text': query 830 }, this.options.geocodingQueryParams), function(data) { 831 cb.call(context, _this._parseResults(data, "bbox")); 832 }); 833 }, 834 835 suggest: function(query, cb, context) { 836 var _this = this; 837 Util.getJSON(this.options.serviceUrl + "/autocomplete", L.extend({ 838 'api_key': this._apiKey, 839 'text': query 840 }, this.options.geocodingQueryParams), L.bind(function(data) { 841 if (data.geocoding.timestamp > this._lastSuggest) { 842 this._lastSuggest = data.geocoding.timestamp; 843 cb.call(context, _this._parseResults(data, "bbox")); 844 } 845 }, this)); 846 }, 847 848 reverse: function(location, scale, cb, context) { 849 var _this = this; 850 Util.getJSON(this.options.serviceUrl + "/reverse", L.extend({ 851 'api_key': this._apiKey, 852 'point.lat': location.lat, 853 'point.lon': location.lng 854 }, this.options.reverseQueryParams), function(data) { 855 cb.call(context, _this._parseResults(data, "bounds")); 856 }); 857 }, 858 859 _parseResults: function(data, bboxname) { 860 var results = []; 861 L.geoJson(data, { 862 pointToLayer: function (feature, latlng) { 863 return L.circleMarker(latlng); 864 }, 865 onEachFeature: function(feature, layer) { 866 var result = {}, 867 bbox, 868 center; 869 870 if (layer.getBounds) { 871 bbox = layer.getBounds(); 872 center = bbox.getCenter(); 873 } else { 874 center = layer.getLatLng(); 875 bbox = L.latLngBounds(center, center); 876 } 877 878 result.name = layer.feature.properties.label; 879 result.center = center; 880 result[bboxname] = bbox; 881 result.properties = layer.feature.properties; 882 results.push(result); 883 } 884 }); 885 return results; 886 } 887 }), 888 889 factory: function(apiKey, options) { 890 return new L.Control.Geocoder.Mapzen(apiKey, options); 891 } 892}; 893 894}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 895},{"../util":13}],9:[function(_dereq_,module,exports){ 896(function (global){ 897var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null),
898 Util = _dereq_('../util'); 899 900module.exports = { 901 "class": L.Class.extend({ 902 options: { 903 serviceUrl: 'https://nominatim.openstreetmap.org/', 904 geocodingQueryParams: {}, 905 reverseQueryParams: {}, 906 htmlTemplate: function(r) { 907 var a = r.address, 908 parts = []; 909 if (a.road || a.building) { 910 parts.push('{building} {road} {house_number}'); 911 } 912 913 if (a.city || a.town || a.village || a.hamlet) { 914 parts.push('<span class="' + (parts.length > 0 ? 'leaflet-control-geocoder-address-detail' : '') + 915 '">{postcode} {city} {town} {village} {hamlet}</span>'); 916 } 917 918 if (a.state || a.country) { 919 parts.push('<span class="' + (parts.length > 0 ? 'leaflet-control-geocoder-address-context' : '') + 920 '">{state} {country}</span>'); 921 } 922 923 return Util.template(parts.join('<br/>'), a, true); 924 } 925 }, 926 927 initialize: function(options) { 928 L.Util.setOptions(this, options); 929 }, 930 931 geocode: function(query, cb, context) { 932 Util.jsonp(this.options.serviceUrl + 'search', L.extend({ 933 q: query, 934 limit: 5, 935 format: 'json', 936 addressdetails: 1 937 }, this.options.geocodingQueryParams), 938 function(data) { 939 var results = []; 940 for (var i = data.length - 1; i >= 0; i--) { 941 var bbox = data[i].boundingbox; 942 for (var j = 0; j < 4; j++) bbox[j] = parseFloat(bbox[j]); 943 results[i] = { 944 icon: data[i].icon, 945 name: data[i].display_name, 946 html: this.options.htmlTemplate ? 947 this.options.htmlTemplate(data[i]) 948 : undefined, 949 bbox: L.latLngBounds([bbox[0], bbox[2]], [bbox[1], bbox[3]]), 950 center: L.latLng(data[i].lat, data[i].lon), 951 properties: data[i] 952 }; 953 } 954 cb.call(context, results); 955 }, this, 'json_callback'); 956 }, 957 958 reverse: function(location, scale, cb, context) { 959 Util.jsonp(this.options.serviceUrl + 'reverse', L.extend({ 960 lat: location.lat, 961 lon: location.lng, 962 zoom: Math.round(Math.log(scale / 256) / Math.log(2)), 963 addressdetails: 1, 964 format: 'json' 965 }, this.options.reverseQueryParams), function(data) { 966 var result = [], 967 loc; 968 969 if (data && data.lat && data.lon) { 970 loc = L.latLng(data.lat, data.lon); 971 result.push({ 972 name: data.display_name, 973 html: this.options.htmlTemplate ? 974 this.options.htmlTemplate(data) 975 : undefined, 976 center: loc, 977 bounds: L.latLngBounds(loc, loc), 978 properties: data 979 }); 980 } 981 982 cb.call(context, result); 983 }, this, 'json_callback'); 984 } 985 }), 986 987 factory: function(options) { 988 return new L.Control.Geocoder.Nominatim(options); 989 } 990}; 991 992}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 993},{"../util":13}],10:[function(_dereq_,module,exports){ 994(function (global){ 995var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null),
996 Util = _dereq_('../util'); 997 998module.exports = { 999 "class": L.Class.extend({ 1000 options: { 1001 serviceUrl: 'https://photon.komoot.de/api/', 1002 reverseUrl: 'https://photon.komoot.de/reverse/', 1003 nameProperties: [ 1004 'name', 1005 'street', 1006 'suburb', 1007 'hamlet', 1008 'town', 1009 'city', 1010 'state', 1011 'country' 1012 ] 1013 }, 1014 1015 initialize: function(options) { 1016 L.setOptions(this, options); 1017 }, 1018 1019 geocode: function(query, cb, context) { 1020 var params = L.extend({ 1021 q: query 1022 }, this.options.geocodingQueryParams); 1023 1024 Util.getJSON(this.options.serviceUrl, params, L.bind(function(data) { 1025 cb.call(context, this._decodeFeatures(data)); 1026 }, this)); 1027 }, 1028 1029 suggest: function(query, cb, context) { 1030 return this.geocode(query, cb, context); 1031 }, 1032 1033 reverse: function(latLng, scale, cb, context) { 1034 var params = L.extend({ 1035 lat: latLng.lat, 1036 lon: latLng.lng 1037 }, this.options.geocodingQueryParams); 1038 1039 Util.getJSON(this.options.reverseUrl, params, L.bind(function(data) { 1040 cb.call(context, this._decodeFeatures(data)); 1041 }, this)); 1042 }, 1043 1044 _decodeFeatures: function(data) { 1045 var results = [], 1046 i, 1047 f, 1048 c, 1049 latLng, 1050 extent, 1051 bbox; 1052 1053 if (data && data.features) { 1054 for (i = 0; i < data.features.length; i++) { 1055 f = data.features[i]; 1056 c = f.geometry.coordinates; 1057 latLng = L.latLng(c[1], c[0]); 1058 extent = f.properties.extent; 1059 1060 if (extent) { 1061 bbox = L.latLngBounds([extent[1], extent[0]], [extent[3], extent[2]]); 1062 } else { 1063 bbox = L.latLngBounds(latLng, latLng); 1064 } 1065 1066 results.push({ 1067 name: this._deocodeFeatureName(f), 1068 html: this.options.htmlTemplate ? 1069 this.options.htmlTemplate(f) 1070 : undefined, 1071 center: latLng, 1072 bbox: bbox, 1073 properties: f.properties 1074 }); 1075 } 1076 } 1077 1078 return results; 1079 }, 1080 1081 _deocodeFeatureName: function(f) { 1082 var j, 1083 name; 1084 for (j = 0; !name && j < this.options.nameProperties.length; j++) { 1085 name = f.properties[this.options.nameProperties[j]]; 1086 } 1087 1088 return name; 1089 } 1090 }), 1091 1092 factory: function(options) { 1093 return new L.Control.Geocoder.Photon(options); 1094 } 1095}; 1096 1097 1098}
1098).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 1099},{"../util":13}],11:[function(_dereq_,module,exports){ 1100(function (global){ 1101var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), 1102 Util = _dereq_('../util'); 1103 1104module.exports = { 1105 "class": L.Class.extend({ 1106 options: { 1107 serviceUrl: 'https://api.what3words.com/v2/' 1108 }, 1109 1110 initialize: function(accessToken) { 1111 this._accessToken = accessToken; 1112 }, 1113 1114 geocode: function(query, cb, context) { 1115 //get three words and make a dot based string 1116 Util.getJSON(this.options.serviceUrl +'forward', { 1117 key: this._accessToken, 1118 addr: query.split(/\s+/).join('.') 1119 }, function(data) { 1120 var results = [], loc, latLng, latLngBounds; 1121 if (data.hasOwnProperty('geometry')) { 1122 latLng = L.latLng(data.geometry['lat'],data.geometry['lng']); 1123 latLngBounds = L.latLngBounds(latLng, latLng); 1124 results[0] = { 1125 name: data.words, 1126 bbox: latLngBounds, 1127 center: latLng 1128 }; 1129 } 1130 1131 cb.call(context, results); 1132 }); 1133 }, 1134 1135 suggest: function(query, cb, context) { 1136 return this.geocode(query, cb, context); 1137 }, 1138 1139 reverse: function(location, scale, cb, context) { 1140 Util.getJSON(this.options.serviceUrl +'reverse', { 1141 key: this._accessToken, 1142 coords: [location.lat,location.lng].join(',') 1143 }, function(data) { 1144 var results = [],loc,latLng,latLngBounds; 1145 if (data.status.status == 200) { 1146 latLng = L.latLng(data.geometry['lat'],data.geometry['lng']); 1147 latLngBounds = L.latLngBounds(latLng, latLng); 1148 results[0] = { 1149 name: data.words, 1150 bbox: latLngBounds, 1151 center: latLng 1152 }; 1153 } 1154 cb.call(context, results); 1155 }); 1156 } 1157 }), 1158 1159 factory: function(accessToken) { 1160 return new L.Control.Geocoder.What3Words(accessToken); 1161 } 1162}; 1163 1164}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 1165},{"../util":13}],12:[function(_dereq_,module,exports){ 1166(function (global){ 1167var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null),
1168 Control = _dereq_('./control'), 1169 Nominatim = _dereq_('./geocoders/nominatim'), 1170 Bing = _dereq_('./geocoders/bing'), 1171 MapQuest = _dereq_('./geocoders/mapquest'), 1172 Mapbox = _dereq_('./geocoders/mapbox'), 1173 What3Words = _dereq_('./geocoders/what3words'), 1174 Google = _dereq_('./geocoders/google'), 1175 Photon = _dereq_('./geocoders/photon'), 1176 Mapzen = _dereq_('./geocoders/mapzen'), 1177 ArcGis = _dereq_('./geocoders/arcgis'), 1178 HERE = _dereq_('./geocoders/here'); 1179 1180module.exports = L.Util.extend(Control["class"], { 1181 Nominatim: Nominatim["class"], 1182 nominatim: Nominatim.factory, 1183 Bing: Bing["class"], 1184 bing: Bing.factory, 1185 MapQuest: MapQuest["class"], 1186 mapQuest: MapQuest.factory, 1187 Mapbox: Mapbox["class"], 1188 mapbox: Mapbox.factory, 1189 What3Words: What3Words["class"], 1190 what3words: What3Words.factory, 1191 Google: Google["class"], 1192 google: Google.factory, 1193 Photon: Photon["class"], 1194 photon: Photon.factory, 1195 Mapzen: Mapzen["class"], 1196 mapzen: Mapzen.factory, 1197 ArcGis: ArcGis["class"], 1198 arcgis: ArcGis.factory, 1199 HERE: HERE["class"], 1200 here: HERE.factory 1201}); 1202 1203L.Util.extend(L.Control, { 1204 Geocoder: module.exports, 1205 geocoder: Control.factory 1206}); 1207 1208}
1208).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 1209},{"./control":1,"./geocoders/arcgis":2,"./geocoders/bing":3,"./geocoders/google":4,"./geocoders/here":5,"./geocoders/mapbox":6,"./geocoders/mapquest":7,"./geocoders/mapzen":8,"./geocoders/nominatim":9,"./geocoders/photon":10,"./geocoders/what3words":11}],13:[function(_dereq_,module,exports){ 1210(function (global){ 1211var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null), 1212 lastCallbackId = 0, 1213 htmlEscape = (function() { 1214 // Adapted from handlebars.js 1215 // https://github.com/wycats/handlebars.js/ 1216 var badChars = /[&<>"'`]/g; 1217 var possible = /[&<>"'`]/; 1218 var escape = { 1219 '&': '&', 1220 '<': '<', 1221 '>': '>', 1222 '"': '"', 1223 '\'': ''', 1224 '`': '`' 1225 }; 1226 1227 function escapeChar(chr) { 1228 return escape[chr]; 1229 } 1230 1231 return function(string) { 1232 if (string == null) { 1233 return ''; 1234 } else if (!string) { 1235 return string + ''; 1236 } 1237 1238 // Force a string conversion as this will be done by the append regardless and 1239 // the regex test will do this transparently behind the scenes, causing issues if 1240 // an object's to string has escaped characters in it. 1241 string = '' + string; 1242 1243 if (!possible.test(string)) { 1244 return string; 1245 } 1246 return string.replace(badChars, escapeChar); 1247 }; 1248 })(); 1249 1250module.exports = { 1251 jsonp: function(url, params, callback, context, jsonpParam) { 1252 var callbackId = '_l_geocoder_' + (lastCallbackId++); 1253 params[jsonpParam || 'callback'] = callbackId; 1254 window[callbackId] = L.Util.bind(callback, context); 1255 var script = document.createElement('script'); 1256 script.type = 'text/javascript'; 1257 script.src = url + L.Util.getParamString(params); 1258 script.id = callbackId; 1259 document.getElementsByTagName('head')[0].appendChild(script); 1260 }, 1261 1262 getJSON: function(url, params, callback) { 1263 var xmlHttp = new XMLHttpRequest(); 1264 xmlHttp.onreadystatechange = function () { 1265 if (xmlHttp.readyState !== 4){ 1266 return; 1267 } 1268 if (xmlHttp.status !== 200 && xmlHttp.status !== 304){ 1269 callback(''); 1270 return; 1271 } 1272 callback(JSON.parse(xmlHttp.response)); 1273 }; 1274 xmlHttp.open('GET', url + L.Util.getParamString(params), true); 1275 xmlHttp.setRequestHeader('Accept', 'application/json'); 1276 xmlHttp.send(null); 1277 }, 1278 1279 template: function (str, data) { 1280 return str.replace(/\{ *([\w_]+) *\}/g, function (str, key) { 1281 var value = data[key]; 1282 if (value === undefined) { 1283 value = ''; 1284 } else if (typeof value === 'function') { 1285 value = value(data); 1286 } 1287 return htmlEscape(value); 1288 }); 1289 }, 1290 1291 htmlEscape: htmlEscape 1292}; 1293 1294}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 1295},{}]},{},[12])(12) 1296});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.