1var leafletControlGeocoder = (function (exports, L) { 2 3 function _interopNamespace(e) { 4 if (e && e.__esModule) return e; 5 var n = Object.create(null); 6 if (e) { 7 Object.keys(e).forEach(function (k) { 8 if (k !== 'default') { 9 var d = Object.getOwnPropertyDescriptor(e, k); 10 Object.defineProperty(n, k, d.get ? d : { 11 enumerable: true, 12 get: function () { 13 return e[k]; 14 } 15 }); 16 } 17 }); 18 } 19 n['default'] = e; 20 return n; 21 } 22 23 var L__namespace = /*#__PURE__*/_interopNamespace(L); 24 25 function _inheritsLoose(subClass, superClass) { 26 subClass.prototype = Object.create(superClass.prototype); 27 subClass.prototype.constructor = subClass; 28 subClass.__proto__ = superClass; 29 } 30 31 function _assertThisInitialized(self) { 32 if (self === void 0) { 33 throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); 34 } 35 36 return self; 37 } 38 39 /** 40 * @internal 41 */ 42 43 function geocodingParams(options, params) { 44 return L__namespace.Util.extend(params, options.geocodingQueryParams); 45 } 46 /** 47 * @internal 48 */ 49 50 function reverseParams(options, params) { 51 return L__namespace.Util.extend(params, options.reverseQueryParams); 52 } 53 54 /** 55 * @internal 56 */ 57 58 var lastCallbackId = 0; // Adapted from handlebars.js 59 // https://github.com/wycats/handlebars.js/ 60 61 /** 62 * @internal 63 */ 64 65 var badChars = /[&<>"'`]/g; 66 /** 67 * @internal 68 */ 69 70 var possible = /[&<>"'`]/; 71 /** 72 * @internal 73 */ 74 75 var escape = { 76 '&': '&', 77 '<': '<', 78 '>': '>', 79 '"': '"', 80 "'": ''', 81 '`': '`' 82 }; 83 /** 84 * @internal 85 */ 86 87 function escapeChar(chr) { 88 return escape[chr]; 89 } 90 /** 91 * @internal 92 */ 93 94 95 function htmlEscape(string) { 96 if (string == null) { 97 return ''; 98 } else if (!string) { 99 return string + ''; 100 } // Force a string conversion as this will be done by the append regardless and 101 // the regex test will do this transparently behind the scenes, causing issues if 102 // an object's to string has escaped characters in it. 103 104 105 string = '' + string; 106 107 if (!possible.test(string)) { 108 return string; 109 } 110 111 return string.replace(badChars, escapeChar); 112 } 113 /** 114 * @internal 115 */ 116 117 function jsonp(url, params, callback, context, jsonpParam) { 118 var callbackId = '_l_geocoder_' + lastCallbackId++; 119 params[jsonpParam || 'callback'] = callbackId; 120 window[callbackId] = L__namespace.Util.bind(callback, context); 121 var script = document.createElement('script'); 122 script.type = 'text/javascript'; 123 script.src = url + getParamString(params); 124 script.id = callbackId; 125 document.getElementsByTagName('head')[0].appendChild(script); 126 } 127 /** 128 * @internal 129 */ 130 131 function getJSON(url, params, callback) { 132 var xmlHttp = new XMLHttpRequest(); 133 134 xmlHttp.onreadystatechange = function () { 135 if (xmlHttp.readyState !== 4) { 136 return; 137 } 138 139 var message; 140 141 if (xmlHttp.status !== 200 && xmlHttp.status !== 304) { 142 message = ''; 143 } else if (typeof xmlHttp.response === 'string') { 144 // IE doesn't parse JSON responses even with responseType: 'json'. 145 try { 146 message = JSON.parse(xmlHttp.response); 147 } catch (e) { 148 // Not a JSON response 149 message = xmlHttp.response; 150 } 151 } else { 152 message = xmlHttp.response; 153 } 154 155 callback(message); 156 }; 157 158 xmlHttp.open('GET', url + getParamString(params), true); 159 xmlHttp.responseType = 'json'; 160 xmlHttp.setRequestHeader('Accept', 'application/json'); 161 xmlHttp.send(null); 162 } 163 /** 164 * @internal 165 */ 166 167 function template(str, data) { 168 return str.replace(/\{ *([\w_]+) *\}/g, function (str, key) { 169 var value = data[key]; 170 171 if (value === undefined) { 172 value = ''; 173 } else if (typeof value === 'function') { 174 value = value(data); 175 } 176 177 return htmlEscape(value); 178 }); 179 } 180 /** 181 * @internal 182 */ 183 184 function getParamString(obj, existingUrl, uppercase) { 185 var params = []; 186 187 for (var i in obj) { 188 var key = encodeURIComponent(uppercase ? i.toUpperCase() : i); 189 var value = obj[i]; 190 191 if (!Array.isArray(value)) { 192 params.push(key + '=' + encodeURIComponent(String(value))); 193 } else { 194 for (var j = 0; j < value.length; j++) { 195 params.push(key + '=' + encodeURIComponent(value[j])); 196 } 197 } 198 } 199 200 return (!existingUrl || existingUrl.indexOf('?') === -1 ? '?' : '&') + params.join('&'); 201 } 202 203 /** 204 * Implementation of the [ArcGIS geocoder](https://developers.arcgis.com/features/geocoding/) 205 */ 206 207 var ArcGis = /*#__PURE__*/function () { 208 function ArcGis(options) { 209 this.options = { 210 serviceUrl: 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer', 211 apiKey: '' 212 }; 213 L__namespace.Util.setOptions(this, options); 214 } 215 216 var _proto = ArcGis.prototype; 217 218 _proto.geocode = function geocode(query, cb, context) { 219 var params = geocodingParams(this.options, { 220 token: this.options.apiKey, 221 SingleLine: query, 222 outFields: 'Addr_Type', 223 forStorage: false, 224 maxLocations: 10, 225 f: 'json' 226 }); 227 getJSON(this.options.serviceUrl + '/findAddressCandidates', params, function (data) { 228 var results = []; 229 230 if (data.candidates && data.candidates.length) { 231 for (var i = 0; i <= data.candidates.length - 1; i++) { 232 var loc = data.candidates[i]; 233 var latLng = L__namespace.latLng(loc.location.y, loc.location.x); 234 var latLngBounds = L__namespace.latLngBounds(L__namespace.latLng(loc.extent.ymax, loc.extent.xmax), L__namespace.latLng(loc.extent.ymin, loc.extent.xmin)); 235 results[i] = { 236 name: loc.address, 237 bbox: latLngBounds, 238 center: latLng 239 }; 240 } 241 } 242 243 cb.call(context, results); 244 }); 245 }; 246 247 _proto.suggest = function suggest(query, cb, context) { 248 return this.geocode(query, cb, context); 249 }; 250 251 _proto.reverse = function reverse(location, scale, cb, context) { 252 var params = reverseParams(this.options, { 253 location: location.lng + ',' + location.lat, 254 distance: 100, 255 f: 'json' 256 }); 257 getJSON(this.options.serviceUrl + '/reverseGeocode', params, function (data) { 258 var result = []; 259 260 if (data && !data.error) { 261 var center = L__namespace.latLng(data.location.y, data.location.x); 262 var bbox = L__namespace.latLngBounds(center, center); 263 result.push({ 264 name: data.address.Match_addr, 265 center: center, 266 bbox: bbox 267 }); 268 } 269 270 cb.call(context, result); 271 }); 272 }; 273 274 return ArcGis; 275 }(); 276 /** 277 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link ArcGis} 278 * @param options the options 279 */ 280 281 function arcgis(options) { 282 return new ArcGis(options); 283 } 284 285 /** 286 * Implementation of the [Bing Locations API](https://docs.microsoft.com/en-us
286/bingmaps/rest-services/locations/) 287 */ 288 289 var Bing = /*#__PURE__*/function () { 290 function Bing(options) { 291 this.options = { 292 serviceUrl: 'https://dev.virtualearth.net/REST/v1/Locations' 293 }; 294 L__namespace.Util.setOptions(this, options); 295 } 296 297 var _proto = Bing.prototype; 298 299 _proto.geocode = function geocode(query, cb, context) { 300 var params = geocodingParams(this.options, { 301 query: query, 302 key: this.options.apiKey 303 }); 304 jsonp(this.options.apiKey, params, function (data) { 305 var results = []; 306 307 if (data.resourceSets.length > 0) { 308 for (var i = data.resourceSets[0].resources.length - 1; i >= 0; i--) { 309 var resource = data.resourceSets[0].resources[i], 310 bbox = resource.bbox; 311 results[i] = { 312 name: resource.name, 313 bbox: L__namespace.latLngBounds([bbox[0], bbox[1]], [bbox[2], bbox[3]]), 314 center: L__namespace.latLng(resource.point.coordinates) 315 }; 316 } 317 } 318 319 cb.call(context, results); 320 }, this, 'jsonp'); 321 }; 322 323 _proto.reverse = function reverse(location, scale, cb, context) { 324 var params = reverseParams(this.options, { 325 key: this.options.apiKey 326 }); 327 jsonp(this.options.serviceUrl + location.lat + ',' + location.lng, params, function (data) { 328 var results = []; 329 330 for (var i = data.resourceSets[0].resources.length - 1; i >= 0; i--) { 331 var resource = data.resourceSets[0].resources[i], 332 bbox = resource.bbox; 333 results[i] = { 334 name: resource.name, 335 bbox: L__namespace.latLngBounds([bbox[0], bbox[1]], [bbox[2], bbox[3]]), 336 center: L__namespace.latLng(resource.point.coordinates) 337 }; 338 } 339 340 cb.call(context, results); 341 }, this, 'jsonp'); 342 }; 343 344 return Bing; 345 }(); 346 /** 347 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Bing} 348 * @param options the options 349 */ 350 351 function bing(options) { 352 return new Bing(options); 353 } 354 355 var Google = /*#__PURE__*/function () { 356 function Google(options) { 357 this.options = { 358 serviceUrl: 'https://maps.googleapis.com/maps/api/geocode/json' 359 }; 360 L__namespace.Util.setOptions(this, options); 361 } 362 363 var _proto = Google.prototype; 364 365 _proto.geocode = function geocode(query, cb, context) { 366 var params = geocodingParams(this.options, { 367 key: this.options.apiKey, 368 address: query 369 }); 370 getJSON(this.options.serviceUrl, params, function (data) { 371 var results = []; 372 373 if (data.results && data.results.length) { 374 for (var i = 0; i <= data.results.length - 1; i++) { 375 var loc = data.results[i]; 376 var latLng = L__namespace.latLng(loc.geometry.location); 377 var latLngBounds = L__namespace.latLngBounds(L__namespace.latLng(loc.geometry.viewport.northeast), L__namespace.latLng(loc.geometry.viewport.southwest)); 378 results[i] = { 379 name: loc.formatted_address, 380 bbox: latLngBounds, 381 center: latLng, 382 properties: loc.address_components 383 }; 384 } 385 } 386 387 cb.call(context, results); 388 }); 389 }; 390 391 _proto.reverse = function reverse(location, scale, cb, context) { 392 var params = reverseParams(this.options, { 393 key: this.options.apiKey, 394 latlng: location.lat + ',' + location.lng 395 }); 396 getJSON(this.options.serviceUrl, params, function (data) { 397 var results = []; 398 399 if (data.results && data.results.length) { 400 for (var i = 0; i <= data.results.length - 1; i++) { 401 var loc = data.results[i]; 402 var center = L__namespace.latLng(loc.geometry.location); 403 var bbox = L__namespace.latLngBounds(L__namespace.latLng(loc.geometry.viewport.northeast), L__namespace.latLng(loc.geometry.viewport.southwest)); 404 results[i] = { 405 name: loc.formatted_address, 406 bbox: bbox, 407 center: center, 408 properties: loc.address_components 409 }; 410 } 411 } 412 413 cb.call(context, results); 414 }); 415 }; 416 417 return Google; 418 }(); 419 /** 420 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Google} 421 * @param options the options 422 */ 423 424 function google(options) { 425 return new Google(options); 426 } 427 428 /**
429 * Implementation of the [HERE Geocoder API](https://developer.here.com/documentation/geocoder/topics/introduction.html) 430 */ 431 432 var HERE = /*#__PURE__*/function () { 433 function HERE(options) { 434 this.options = { 435 serviceUrl: 'https://geocoder.api.here.com/6.2/', 436 app_id: '', 437 app_code: '', 438 apiKey: '', 439 maxResults: 5 440 }; 441 L__namespace.Util.setOptions(this, options); 442 if (options.apiKey) throw Error('apiKey is not supported, use app_id/app_code instead!'); 443 } 444 445 var _proto = HERE.prototype; 446 447 _proto.geocode = function geocode(query, cb, context) { 448 var params = geocodingParams(this.options, { 449 searchtext: query, 450 gen: 9, 451 app_id: this.options.app_id, 452 app_code: this.options.app_code, 453 jsonattributes: 1, 454 maxresults: this.options.maxResults 455 }); 456 this.getJSON(this.options.serviceUrl + 'geocode.json', params, cb, context); 457 }; 458 459 _proto.reverse = function reverse(location, scale, cb, context) { 460 var prox = location.lat + ',' + location.lng; 461 462 if (this.options.reverseGeocodeProxRadius) { 463 prox += ',' + this.options.reverseGeocodeProxRadius; 464 } 465 466 var params = reverseParams(this.options, { 467 prox: prox, 468 mode: 'retrieveAddresses', 469 app_id: this.options.app_id, 470 app_code: this.options.app_code, 471 gen: 9, 472 jsonattributes: 1, 473 maxresults: this.options.maxResults 474 }); 475 this.getJSON(this.options.serviceUrl + 'reversegeocode.json', params, cb, context); 476 }; 477 478 _proto.getJSON = function getJSON$1(url, params, cb, context) { 479 getJSON(url, params, function (data) { 480 var results = []; 481 482 if (data.response.view && data.response.view.length) { 483 for (var i = 0; i <= data.response.view[0].result.length - 1; i++) { 484 var loc = data.response.view[0].result[i].location; 485 var center = L__namespace.latLng(loc.displayPosition.latitude, loc.displayPosition.longitude); 486 var bbox = L__namespace.latLngBounds(L__namespace.latLng(loc.mapView.topLeft.latitude, loc.mapView.topLeft.longitude), L__namespace.latLng(loc.mapView.bottomRight.latitude, loc.mapView.bottomRight.longitude)); 487 results[i] = { 488 name: loc.address.label, 489 properties: loc.address, 490 bbox: bbox, 491 center: center 492 }; 493 } 494 } 495 496 cb.call(context, results); 497 }); 498 }; 499 500 return HERE; 501 }(); 502 /** 503 * Implementation of the new [HERE Geocoder API](https://developer.here.com/documentation/geocoding-search-api/api-reference-swagger.html) 504 */ 505 506 var HEREv2 = /*#__PURE__*/function () { 507 function HEREv2(options) { 508 this.options = { 509 serviceUrl: 'https://geocode.search.hereapi.com/v1', 510 apiKey: '', 511 app_id: '', 512 app_code: '', 513 maxResults: 10 514 }; 515 L__namespace.Util.setOptions(this, options); 516 } 517 518 var _proto2 = HEREv2.prototype; 519 520 _proto2.geocode = function geocode(query, cb, context) { 521 var params = geocodingParams(this.options, { 522 q: query, 523 apiKey: this.options.apiKey, 524 limit: this.options.maxResults 525 }); 526 527 if (!params.at && !params["in"]) { 528 throw Error('at / in parameters not found. Please define coordinates (at=latitude,longitude) or other (in) in your geocodingQueryParams.'); 529 } 530 531 this.getJSON(this.options.serviceUrl + '/discover', params, cb, context); 532 }; 533 534 _proto2.reverse = function reverse(location, scale, cb, context) { 535 var params = reverseParams(this.options, { 536 at: location.lat + ',' + location.lng, 537 limit: this.options.reverseGeocodeProxRadius, 538 apiKey: this.options.apiKey 539 }); 540 this.getJSON(this.options.serviceUrl + '/revgeocode', params, cb, context); 541 }; 542 543 _proto2.getJSON = function getJSON$1(url, params, cb, context) { 544 getJSON(url, params, function (data) { 545 var results = []; 546 547 if (data.items && data.items.length) { 548 for (var i = 0; i <= data.items.length - 1; i++) { 549 var item = data.items[i]; 550 var latLng = L__namespace.latLng(item.position.lat, item.position.lng); 551 var bbox = void 0; 552 553 if (item.mapView) { 554 bbox = L__namespace.latLngBounds(L__namespace.latLng(item.mapView.south, item.mapView.west), L__namespace.latLng(item.mapView.north, item.mapView.east)); 555 } else { 556 // Using only position when not provided 557 bbox = L__namespace.latLngBounds(L__namespace.latLng(item.position.lat, item.position.lng), L__namespace.latLng(item.position.lat, item.position.lng)); 558 } 559 560 results[i] = { 561 name: item.address.label, 562 properties: item.address, 563 bbox: bbox, 564 center: latLng 565 }; 566 } 567 } 568 569 cb.call(context, results); 570 }); 571 }; 572 573 return HEREv2; 574 }(); 575 /** 576 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link HERE} 577 * @param options the options 578 */ 579 580 function here(options) { 581 if (options.apiKey) { 582 return new HEREv2(options); 583 } else { 584 return new HERE(options); 585 } 586 } 587 588 /** 589 * Parses basic latitude/longitude strings such as `'50.06773 14.37742'`, `'N50.06773 W14.37742'`, `'S 50° 04.064 E 014° 22.645'`, or `'S 50° 4′ 03.828″, W 14° 22′ 38.712″'` 590 * @param query the latitude/longitude string to parse 591 * @returns the parsed latitude/longitude 592 */ 593 594 function parseLatLng(query) { 595 var match; // regex from https://github.com/openstreetmap/openstreetmap-website/blob/master/app/controllers/geocoder_controller.rb 596 597 if (match = query.match(/^([NS])\s*(\d{1,3}(?:\.\d*)?)\W*([EW])\s*(\d{1,3}(?:\.\d*)?)$/)) { 598 // [NSEW] decimal degrees 599 return L__namespace.latLng((/N/i.test(match[1]) ? 1 : -1) * +match[2], (/E/i.test(match[3]) ? 1 : -1) * +match[4]); 600 } else if (match = query.match(/^(\d{1,3}(?:\.\d*)?)\s*([NS])\W*(\d{1,3}(?:\.\d*)?)\s*([EW])$/)) { 601 // decimal degrees [NSEW] 602 return L__namespace.latLng((/N/i.test(match[2]) ? 1 : -1) * +match[1], (/E/i.test(match[4]) ? 1 : -1) * +match[3]); 603 } else if (match = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?$/)) { 604 // [NSEW] degrees, decimal minutes 605 return L__namespace.latLng((/N/i.test(match[1]) ? 1 : -1) * (+match[2] + +match[3] / 60), (/E/i.test(match[4]) ? 1 : -1) * (+match[5] + +match[6] / 60)); 606 } else if (match = query.match(/^(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}(?:\.\d*)?)?['′]?\s*([EW])$/)) { 607 // degrees, decimal minutes [NSEW] 608 return L__namespace.latLng((/N/i.test(match[3]) ? 1 : -1) * (+match[1] + +match[2] / 60), (/E/i.test(match[6]) ? 1 : -1) * (+match[4] + +match[5] / 60)); 609 } else if (match = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?$/)) { 610 // [NSEW] degrees, minutes, decimal seconds 611 return L__namespace.latLng((/N/i.test(match[1]) ? 1 : -1) * (+match[2] + +match[3] / 60 + +match[4] / 3600), (/E/i.test(match[5]) ? 1 : -1) * (+match[6] + +match[7] / 60 + +match[8] / 3600)); 612 } else if (match = query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(?:\.\d*)?)?["″]?\s*([EW])$/)) { 613 // degrees, minutes, decimal seconds [NSEW] 614 return L__namespace.latLng((/N/i.test(match[4]) ? 1 : -1) * (+match[1] + +match[2] / 60 + +match[3] / 3600), (/E/i.test(match[8]) ? 1 : -1) * (+match[5] + +match[6] / 60 + +match[7] / 3600)); 615 } else if (match = query.match(/^\s*([+-]?\d+(?:\.\d*)?)\s*[\s,]\s*([+-]?\d+(?:\.\d*)?)\s*$/)) { 616 return L__namespace.latLng(+match[1], +match[2]); 617 } 618 } 619 /** 620 * Parses basic latitude/longitude strings such as `'50.06773 14.37742'`, `'N50.06773 W14.37742'`, `'S 50° 04.064 E 014° 22.645'`, or `'S 50° 4′ 03.828″, W 14° 22′ 38.712″'` 621 */ 622 623 var LatLng = /*#__PURE__*/function () { 624 function LatLng(options) { 625 this.options = { 626 next: undefined, 627 sizeInMeters: 10000 628 }; 629 L__namespace.Util.setOptions(this, options); 630 } 631 632 var _proto = LatLng.prototype; 633 634 _proto.geocode = function geocode(query, cb, context) { 635 var center = parseLatLng(query); 636 637 if (center) { 638 var results = [{ 639 name: query, 640 center: center, 641 bbox: center.toBounds(this.options.sizeInMeters) 642 }]; 643 cb.call(context, results); 644 } else if (this.options.next) { 645 this.options.next.geocode(query, cb, context); 646 } 647 }; 648 649 return LatLng; 650 }(); 651 /** 652 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link LatLng} 653 * @param options the options 654 */ 655 656 function latLng(options) {
657 return new LatLng(options); 658 } 659 660 /** 661 * Implementation of the [Mapbox Geocoding](https://www.mapbox.com/api-documentation/#geocoding) 662 */ 663 664 var Mapbox = /*#__PURE__*/function () { 665 function Mapbox(options) { 666 this.options = { 667 serviceUrl: 'https://api.mapbox.com/geocoding/v5/mapbox.places/' 668 }; 669 L__namespace.Util.setOptions(this, options); 670 } 671 672 var _proto = Mapbox.prototype; 673 674 _proto._getProperties = function _getProperties(loc) { 675 var properties = { 676 text: loc.text, 677 address: loc.address 678 }; 679 680 for (var j = 0; j < (loc.context || []).length; j++) { 681 var id = loc.context[j].id.split('.')[0]; 682 properties[id] = loc.context[j].text; // Get country code when available 683 684 if (loc.context[j].short_code) { 685 properties['countryShortCode'] = loc.context[j].short_code; 686 } 687 } 688 689 return properties; 690 }; 691 692 _proto.geocode = function geocode(query, cb, context) { 693 var _this = this; 694 695 var params = geocodingParams(this.options, { 696 access_token: this.options.apiKey 697 }); 698 699 if (params.proximity !== undefined && params.proximity.lat !== undefined && params.proximity.lng !== undefined) { 700 params.proximity = params.proximity.lng + ',' + params.proximity.lat; 701 } 702 703 getJSON(this.options.serviceUrl + encodeURIComponent(query) + '.json', params, function (data) { 704 var results = []; 705 706 if (data.features && data.features.length) { 707 for (var i = 0; i <= data.features.length - 1; i++) { 708 var loc = data.features[i]; 709 var center = L__namespace.latLng(loc.center.reverse()); 710 var bbox = void 0; 711 712 if (loc.bbox) { 713 bbox = L__namespace.latLngBounds(L__namespace.latLng(loc.bbox.slice(0, 2).reverse()), L__namespace.latLng(loc.bbox.slice(2, 4).reverse())); 714 } else { 715 bbox = L__namespace.latLngBounds(center, center); 716 } 717 718 results[i] = { 719 name: loc.place_name, 720 bbox: bbox, 721 center: center, 722 properties: _this._getProperties(loc) 723 }; 724 } 725 } 726 727 cb.call(context, results); 728 }); 729 }; 730 731 _proto.suggest = function suggest(query, cb, context) { 732 return this.geocode(query, cb, context); 733 }; 734 735 _proto.reverse = function reverse(location, scale, cb, context) { 736 var _this2 = this; 737 738 var url = this.options.serviceUrl + location.lng + ',' + location.lat + '.json'; 739 var param = reverseParams(this.options, { 740 access_token: this.options.apiKey 741 }); 742 getJSON(url, param, function (data) { 743 var results = []; 744 745 if (data.features && data.features.length) { 746 for (var i = 0; i <= data.features.length - 1; i++) { 747 var loc = data.features[i]; 748 var center = L__namespace.latLng(loc.center.reverse()); 749 var bbox = void 0; 750 751 if (loc.bbox) { 752 bbox = L__namespace.latLngBounds(L__namespace.latLng(loc.bbox.slice(0, 2).reverse()), L__namespace.latLng(loc.bbox.slice(2, 4).reverse())); 753 } else { 754 bbox = L__namespace.latLngBounds(center, center); 755 } 756 757 results[i] = { 758 name: loc.place_name, 759 bbox: bbox, 760 center: center, 761 properties: _this2._getProperties(loc) 762 }; 763 } 764 } 765 766 cb.call(context, results); 767 }); 768 }; 769 770 return Mapbox; 771 }(); 772 /** 773 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Mapbox} 774 * @param options the options 775 */ 776 777 function mapbox(options) { 778 return new Mapbox(options); 779 } 780 781 /** 782 * Implementation of the [MapQuest Geocoding API](http://developer.mapquest.com/web/products/dev-services/geocoding-ws) 783 */ 784 785 var MapQuest = /*#__PURE__*/function () { 786 function MapQuest(options) { 787 this.options = { 788 serviceUrl: 'https://www.mapquestapi.com/geocoding/v1' 789 }; 790 L__namespace.Util.setOptions(this, options); // MapQuest seems to provide URI encoded API keys, 791 // so to avoid encoding them twice, we decode them here 792 793 this.options.apiKey = decodeURIComponent(this.options.apiKey); 794 } 795 796 var _proto = MapQuest.prototype; 797 798 _proto._formatName = function _formatName() { 799 return [].slice.call(arguments).filter(function (s) { 800 return !!s; 801 }).join(', '); 802 }; 803 804 _proto.geocode = function geocode(query, cb, context) { 805 var params = geocodingParams(this.options, { 806 key: this.options.apiKey, 807 location: query, 808 limit: 5, 809 outFormat: 'json' 810 }); 811 getJSON(this.options.serviceUrl + '/address', params, L__namespace.Util.bind(function (data) { 812 var results = []; 813 814 if (data.results && data.results[0].locations) { 815 for (var i = data.results[0].locations.length - 1; i >= 0; i--) { 816 var loc = data.results[0].locations[i]; 817 var center = L__namespace.latLng(loc.latLng); 818 results[i] = { 819 name: this._formatName(loc.street, loc.adminArea4, loc.adminArea3, loc.adminArea1), 820 bbox: L__namespace.latLngBounds(center, center), 821 center: center 822 }; 823 } 824 } 825 826 cb.call(context, results); 827 }, this)); 828 }; 829 830 _proto.reverse = function reverse(location, scale, cb, context) { 831 var params = reverseParams(this.options, { 832 key: this.options.apiKey, 833 location: location.lat + ',' + location.lng, 834 outputFormat: 'json' 835 }); 836 getJSON(this.options.serviceUrl + '/reverse', params, L__namespace.Util.bind(function (data) { 837 var results = []; 838 839 if (data.results && data.results[0].locations) { 840 for (var i = data.results[0].locations.length - 1; i >= 0; i--) { 841 var loc = data.results[0].locations[i]; 842 var center = L__namespace.latLng(loc.latLng); 843 results[i] = { 844 name: this._formatName(loc.street, loc.adminArea4, loc.adminArea3, loc.adminArea1), 845 bbox: L__namespace.latLngBounds(center, center), 846 center: center 847 }; 848 } 849 } 850 851 cb.call(context, results); 852 }, this)); 853 }; 854 855 return MapQuest; 856 }(); 857 /** 858 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link MapQuest} 859 * @param options the options 860 */ 861 862 function mapQuest(options) { 863 return new MapQuest(options); 864 } 865 866 /** 867 * Implementation of the [Neutrino API](https://www.neutrinoapi.com/api/geocode
867-address/) 868 */ 869 870 var Neutrino = /*#__PURE__*/function () { 871 function Neutrino(options) { 872 this.options = { 873 userId: undefined, 874 apiKey: undefined, 875 serviceUrl: 'https://neutrinoapi.com/' 876 }; 877 L__namespace.Util.setOptions(this, options); 878 } // https://www.neutrinoapi.com/api/geocode-address/ 879 880 881 var _proto = Neutrino.prototype; 882 883 _proto.geocode = function geocode(query, cb, context) { 884 var params = geocodingParams(this.options, { 885 apiKey: this.options.apiKey, 886 userId: this.options.userId, 887 //get three words and make a dot based string 888 address: query.split(/\s+/).join('.') 889 }); 890 getJSON(this.options.serviceUrl + 'geocode-address', params, function (data) { 891 var results = []; 892 893 if (data.locations) { 894 data.geometry = data.locations[0]; 895 var center = L__namespace.latLng(data.geometry['latitude'], data.geometry['longitude']); 896 var bbox = L__namespace.latLngBounds(center, center); 897 results[0] = { 898 name: data.geometry.address, 899 bbox: bbox, 900 center: center 901 }; 902 } 903 904 cb.call(context, results); 905 }); 906 }; 907 908 _proto.suggest = function suggest(query, cb, context) { 909 return this.geocode(query, cb, context); 910 } // https://www.neutrinoapi.com/api/geocode-reverse/ 911 ; 912 913 _proto.reverse = function reverse(location, scale, cb, context) { 914 var params = reverseParams(this.options, { 915 apiKey: this.options.apiKey, 916 userId: this.options.userId, 917 latitude: location.lat, 918 longitude: location.lng 919 }); 920 getJSON(this.options.serviceUrl + 'geocode-reverse', params, function (data) { 921 var results = []; 922 923 if (data.status.status == 200 && data.found) { 924 var center = L__namespace.latLng(location.lat, location.lng); 925 var bbox = L__namespace.latLngBounds(center, center); 926 results[0] = { 927 name: data.address, 928 bbox: bbox, 929 center: center 930 }; 931 } 932 933 cb.call(context, results); 934 }); 935 }; 936 937 return Neutrino; 938 }(); 939 /** 940 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Neutrino} 941 * @param options the options 942 */ 943 944 function neutrino(options) { 945 return new Neutrino(options); 946 } 947 948 /** 949 * Implementation of the [Nominatim](https://wiki.openstreetmap.org/wiki/Nominatim) geocoder. 950 * 951 * This is the default geocoding service used by the control, unless otherwise specified in the options. 952 * 953 * Unless using your own Nominatim installation, please refer to the [Nominatim usage policy](https://operations.osmfoundation.org/policies/nominatim/). 954 */ 955 956 var Nominatim = /*#__PURE__*/function () { 957 function Nominatim(options) { 958 this.options = { 959 serviceUrl: 'https://nominatim.openstreetmap.org/', 960 htmlTemplate: function htmlTemplate(r) { 961 var address = r.address; 962 var className; 963 var parts = []; 964 965 if (address.road || address.building) { 966 parts.push('{building} {road} {house_number}'); 967 } 968 969 if (address.city || address.town || address.village || address.hamlet) { 970 className = parts.length > 0 ? 'leaflet-control-geocoder-address-detail' : ''; 971 parts.push('<span class="' + className + '">{postcode} {city} {town} {village} {hamlet}</span>'); 972 } 973 974 if (address.state || address.country) { 975 className = parts.length > 0 ? 'leaflet-control-geocoder-address-context' : ''; 976 parts.push('<span class="' + className + '">{state} {country}</span>'); 977 } 978 979 return template(parts.join('<br/>'), address); 980 } 981 }; 982 L__namespace.Util.setOptions(this, options || {}); 983 } 984 985 var _proto = Nominatim.prototype; 986 987 _proto.geocode = function geocode(query, cb, context) { 988 var _this = this; 989 990 var params = geocodingParams(this.options, { 991 q: query, 992 limit: 5, 993 format: 'json', 994 addressdetails: 1 995 }); 996 getJSON(this.options.serviceUrl + 'search', params, function (data) { 997 var results = []; 998 999 for (var i = data.length - 1; i >= 0; i--) { 1000 var bbox = data[i].boundingbox; 1001 1002 for (var j = 0; j < 4; j++) { 1003 bbox[j] = +bbox[j]; 1004 } 1005 1006 results[i] = { 1007 icon: data[i].icon, 1008 name: data[i].display_name, 1009 html: _this.options.htmlTemplate ? _this.options.htmlTemplate(data[i]) : undefined, 1010 bbox: L__namespace.latLngBounds([bbox[0], bbox[2]], [bbox[1], bbox[3]]), 1011 center: L__namespace.latLng(data[i].lat, data[i].lon), 1012 properties: data[i] 1013 }; 1014 } 1015 1016 cb.call(context, results); 1017 }); 1018 }; 1019 1020 _proto.reverse = function reverse(location, scale, cb, context) { 1021 var _this2 = this; 1022 1023 var params = reverseParams(this.options, { 1024 lat: location.lat, 1025 lon: location.lng, 1026 zoom: Math.round(Math.log(scale / 256) / Math.log(2)), 1027 addressdetails: 1, 1028 format: 'json' 1029 }); 1030 getJSON(this.options.serviceUrl + 'reverse', params, function (data) { 1031 var result = []; 1032 1033 if (data && data.lat && data.lon) { 1034 var center = L__namespace.latLng(data.lat, data.lon); 1035 var bbox = L__namespace.latLngBounds(center, center); 1036 result.push({ 1037 name: data.display_name, 1038 html: _this2.options.htmlTemplate ? _this2.options.htmlTemplate(data) : undefined, 1039 center: center, 1040 bbox: bbox, 1041 properties: data 1042 }); 1043 } 1044 1045 cb.call(context, result); 1046 }); 1047 }; 1048 1049 return Nominatim;
1050 }(); 1051 /** 1052 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Nominatim} 1053 * @param options the options 1054 */ 1055 1056 function nominatim(options) { 1057 return new Nominatim(options); 1058 } 1059 1060 /** 1061 * Implementation of the [Plus codes](https://plus.codes/) (formerly OpenLocationCode) (requires [open-location-code](https://www.npmjs.com/package/open-location-code)) 1062 */ 1063 1064 var OpenLocationCode = /*#__PURE__*/function () { 1065 function OpenLocationCode(options) { 1066 L__namespace.Util.setOptions(this, options); 1067 } 1068 1069 var _proto = OpenLocationCode.prototype; 1070 1071 _proto.geocode = function geocode(query, cb, context) { 1072 try { 1073 var decoded = this.options.OpenLocationCode.decode(query); 1074 var result = { 1075 name: query, 1076 center: L__namespace.latLng(decoded.latitudeCenter, decoded.longitudeCenter), 1077 bbox: L__namespace.latLngBounds(L__namespace.latLng(decoded.latitudeLo, decoded.longitudeLo), L__namespace.latLng(decoded.latitudeHi, decoded.longitudeHi)) 1078 }; 1079 cb.call(context, [result]); 1080 } catch (e) { 1081 console.warn(e); // eslint-disable-line no-console 1082 1083 cb.call(context, []); 1084 } 1085 }; 1086 1087 _proto.reverse = function reverse(location, scale, cb, context) { 1088 try { 1089 var code = this.options.OpenLocationCode.encode(location.lat, location.lng, this.options.codeLength); 1090 var result = { 1091 name: code, 1092 center: L__namespace.latLng(location.lat, location.lng), 1093 bbox: L__namespace.latLngBounds(L__namespace.latLng(location.lat, location.lng), L__namespace.latLng(location.lat, location.lng)) 1094 }; 1095 cb.call(context, [result]); 1096 } catch (e) { 1097 console.warn(e); // eslint-disable-line no-console 1098 1099 cb.call(context, []); 1100 } 1101 }; 1102 1103 return OpenLocationCode; 1104 }(); 1105 /** 1106 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link OpenLocationCode} 1107 * @param options the options 1108 */ 1109 1110 function openLocationCode(options) { 1111 return new OpenLocationCode(options); 1112 } 1113 1114 /** 1115 * Implementation of the [OpenCage Data API](https://opencagedata.com/) 1116 */ 1117 1118 var OpenCage = /*#__PURE__*/function () { 1119 function OpenCage(options) { 1120 this.options = { 1121 serviceUrl: 'https://api.opencagedata.com/geocode/v1/json' 1122 }; 1123 L__namespace.Util.setOptions(this, options); 1124 } 1125 1126 var _proto = OpenCage.prototype; 1127 1128 _proto.geocode = function geocode(query, cb, context) { 1129 var params = geocodingParams(this.options, { 1130 key: this.options.apiKey, 1131 q: query 1132 }); 1133 getJSON(this.options.serviceUrl, params, function (data) { 1134 var results = []; 1135 1136 if (data.results && data.results.length) { 1137 for (var i = 0; i < data.results.length; i++) { 1138 var loc = data.results[i]; 1139 var center = L__namespace.latLng(loc.geometry); 1140 var bbox = void 0; 1141 1142 if (loc.annotations && loc.annotations.bounds) { 1143 bbox = L__namespace.latLngBounds(L__namespace.latLng(loc.annotations.bounds.northeast), L__namespace.latLng(loc.annotations.bounds.southwest)); 1144 } else { 1145 bbox = L__namespace.latLngBounds(center, center); 1146 } 1147 1148 results.push({ 1149 name: loc.formatted, 1150 bbox: bbox, 1151 center: center 1152 }); 1153 } 1154 } 1155 1156 cb.call(context, results); 1157 }); 1158 }; 1159 1160 _proto.suggest = function suggest(query, cb, context) { 1161 return this.geocode(query, cb, context); 1162 }; 1163 1164 _proto.reverse = function reverse(location, scale, cb, context) { 1165 var params = reverseParams(this.options, { 1166 key: this.options.apiKey, 1167 q: [location.lat, location.lng].join(',') 1168 }); 1169 getJSON(this.options.serviceUrl, params, function (data) { 1170 var results = []; 1171 1172 if (data.results && data.results.length) { 1173 for (var i = 0; i < data.results.length; i++) { 1174 var loc = data.results[i]; 1175 var center = L__namespace.latLng(loc.geometry); 1176 var bbox = void 0; 1177 1178 if (loc.annotations && loc.annotations.bounds) { 1179 bbox = L__namespace.latLngBounds(L__namespace.latLng(loc.annotations.bounds.northeast), L__namespace.latLng(loc.annotations.bounds.southwest)); 1180 } else { 1181 bbox = L__namespace.latLngBounds(center, center); 1182 } 1183 1184 results.push({ 1185 name: loc.formatted, 1186 bbox: bbox, 1187 center: center 1188 }); 1189 } 1190 } 1191 1192 cb.call(context, results); 1193 }); 1194 }; 1195 1196 return OpenCage; 1197 }(); 1198 function opencage(options) { 1199 return new OpenCage(options); 1200 } 1201 1202 /** 1203 * Implementation of the [Pelias](https://pelias.io/), [geocode.earth](https://geocode.earth/) geocoder (formerly Mapzen Search) 1204 */ 1205 1206 var Pelias = /*#__PURE__*/function () { 1207 function Pelias(options) { 1208 this.options = { 1209 serviceUrl: 'https://api.geocode.earth/v1' 1210 }; 1211 this._lastSuggest = 0; 1212 L__namespace.Util.setOptions(this, options); 1213 } 1214 1215 var _proto = Pelias.prototype; 1216 1217 _proto.geocode = function geocode(query, cb, context) { 1218 var _this = this; 1219 1220 var params = geocodingParams(this.options, { 1221 api_key: this.options.apiKey, 1222 text: query 1223 }); 1224 getJSON(this.options.serviceUrl + '/search', params, function (data) { 1225 cb.call(context, _this._parseResults(data, 'bbox')); 1226 }); 1227 }; 1228 1229 _proto.suggest = function suggest(query, cb, context) { 1230 var _this2 = this; 1231 1232 var params = geocodingParams(this.options, { 1233 api_key: this.options.apiKey, 1234 text: query 1235 }); 1236 getJSON(this.options.serviceUrl + '/autocomplete', params, function (data) { 1237 if (data.geocoding.timestamp > _this2._lastSuggest) { 1238 _this2._lastSuggest = data.geocoding.timestamp; 1239 cb.call(context, _this2._parseResults(data, 'bbox')); 1240 } 1241 }); 1242 }; 1243 1244 _proto.reverse = function reverse(location, scale, cb, context) { 1245 var _this3 = this; 1246 1247 var params = reverseParams(this.options, { 1248 api_key: this.options.apiKey, 1249 'point.lat': location.lat, 1250 'point.lon': location.lng 1251 }); 1252 getJSON(this.options.serviceUrl + '/reverse', params, function (data) { 1253 cb.call(context, _this3._parseResults(data, 'bounds')); 1254 }); 1255 }; 1256 1257 _proto._parseResults = function _parseResults(data, bboxname) { 1258 var results = []; 1259 L__namespace.geoJSON(data, { 1260 pointToLayer: function pointToLayer(feature, latlng) { 1261 return L__namespace.circleMarker(latlng); 1262 }, 1263 onEachFeature: function onEachFeature(feature, layer) { 1264 var result = {}; 1265 var bbox; 1266 var center; 1267 1268 if (layer.getBounds) { 1269 bbox = layer.getBounds(); 1270 center = bbox.getCenter(); 1271 } else if (layer.feature.bbox) { 1272 center = layer.getLatLng(); 1273 bbox = L__namespace.latLngBounds(L__namespace.GeoJSON.coordsToLatLng(layer.feature.bbox.slice(0, 2)), L__namespace.GeoJSON.coordsToLatLng(layer.feature.bbox.slice(2, 4))); 1274 } else { 1275 center = layer.getLatLng(); 1276 bbox = L__namespace.latLngBounds(center, center); 1277 } 1278 1279 result.name = layer.feature.properties.label; 1280 result.center = center; 1281 result[bboxname] = bbox; 1282 result.properties = layer.feature.properties; 1283 results.push(result); 1284 } 1285 }); 1286 return results; 1287 }; 1288 1289 return Pelias; 1290 }(); 1291 /** 1292 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Pelias} 1293 * @param options the options 1294 */ 1295 1296 function pelias(options) { 1297 return new Pelias(options); 1298 } 1299 var GeocodeEarth = Pelias; 1300 var geocodeEarth = pelias; 1301 /** 1302 * r.i.p. 1303 * @deprecated 1304 */ 1305 1306 var Mapzen = Pelias; 1307 /** 1308 * r.i.p. 1309 * @deprecated 1310 */ 1311 1312 var mapzen = pelias; 1313 /**
1314 * Implementation of the [Openrouteservice](https://openrouteservice.org/dev/#/api-docs/geocode) geocoder 1315 */ 1316 1317 var Openrouteservice = /*#__PURE__*/function (_Pelias) { 1318 _inheritsLoose(Openrouteservice, _Pelias); 1319 1320 function Openrouteservice(options) { 1321 return _Pelias.call(this, L__namespace.Util.extend({ 1322 serviceUrl: 'https://api.openrouteservice.org/geocode' 1323 }, options)) || this; 1324 } 1325 1326 return Openrouteservice; 1327 }(Pelias); 1328 /** 1329 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Openrouteservice} 1330 * @param options the options 1331 */ 1332 1333 function openrouteservice(options) { 1334 return new Openrouteservice(options); 1335 } 1336 1337 /** 1338 * Implementation of the [Photon](http://photon.komoot.de/) geocoder 1339 */ 1340 1341 var Photon = /*#__PURE__*/function () { 1342 function Photon(options) { 1343 this.options = { 1344 serviceUrl: 'https://photon.komoot.io/api/', 1345 reverseUrl: 'https://photon.komoot.io/reverse/', 1346 nameProperties: ['name', 'street', 'suburb', 'hamlet', 'town', 'city', 'state', 'country'] 1347 }; 1348 L__namespace.Util.setOptions(this, options); 1349 } 1350 1351 var _proto = Photon.prototype; 1352 1353 _proto.geocode = function geocode(query, cb, context) { 1354 var params = geocodingParams(this.options, { 1355 q: query 1356 }); 1357 getJSON(this.options.serviceUrl, params, L__namespace.Util.bind(function (data) { 1358 cb.call(context, this._decodeFeatures(data)); 1359 }, this)); 1360 }; 1361 1362 _proto.suggest = function suggest(query, cb, context) { 1363 return this.geocode(query, cb, context); 1364 }; 1365 1366 _proto.reverse = function reverse(latLng, scale, cb, context) { 1367 var params = reverseParams(this.options, { 1368 lat: latLng.lat, 1369 lon: latLng.lng 1370 }); 1371 getJSON(this.options.reverseUrl, params, L__namespace.Util.bind(function (data) { 1372 cb.call(context, this._decodeFeatures(data)); 1373 }, this)); 1374 }; 1375 1376 _proto._decodeFeatures = function _decodeFeatures(data) { 1377 var results = []; 1378 1379 if (data && data.features) { 1380 for (var i = 0; i < data.features.length; i++) { 1381 var f = data.features[i]; 1382 var c = f.geometry.coordinates; 1383 var center = L__namespace.latLng(c[1], c[0]); 1384 var extent = f.properties.extent; 1385 var bbox = extent ? L__namespace.latLngBounds([extent[1], extent[0]], [extent[3], extent[2]]) : L__namespace.latLngBounds(center, center); 1386 results.push({ 1387 name: this._decodeFeatureName(f), 1388 html: this.options.htmlTemplate ? this.options.htmlTemplate(f) : undefined, 1389 center: center, 1390 bbox: bbox, 1391 properties: f.properties 1392 }); 1393 } 1394 } 1395 1396 return results; 1397 }; 1398 1399 _proto._decodeFeatureName = function _decodeFeatureName(f) { 1400 return (this.options.nameProperties || []).map(function (p) { 1401 return f.properties[p]; 1402 }).filter(function (v) { 1403 return !!v; 1404 }).join(', '); 1405 }; 1406 1407 return Photon; 1408 }(); 1409 /** 1410 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link Photon} 1411 * @param options the options 1412 */ 1413 1414 function photon(options) { 1415 return new Photon(options); 1416 } 1417 1418 /** 1419 * Implementation of the What3Words service 1420 */ 1421 1422 var What3Words = /*#__PURE__*/function () { 1423 function What3Words(options) { 1424 this.options = { 1425 serviceUrl: 'https://api.what3words.com/v2/' 1426 }; 1427 L__namespace.Util.setOptions(this, options); 1428 } 1429 1430 var _proto = What3Words.prototype; 1431 1432 _proto.geocode = function geocode(query, cb, context) { 1433 //get three words and make a dot based string 1434 getJSON(this.options.serviceUrl + 'forward', geocodingParams(this.options, { 1435 key: this.options.apiKey, 1436 addr: query.split(/\s+/).join('.') 1437 }), function (data) { 1438 var results = []; 1439 1440 if (data.geometry) { 1441 var latLng = L__namespace.latLng(data.geometry['lat'], data.geometry['lng']); 1442 var latLngBounds = L__namespace.latLngBounds(latLng, latLng); 1443 results[0] = { 1444 name: data.words, 1445 bbox: latLngBounds, 1446 center: latLng 1447 }; 1448 } 1449 1450 cb.call(context, results); 1451 }); 1452 }; 1453 1454 _proto.suggest = function suggest(query, cb, context) { 1455 return this.geocode(query, cb, context); 1456 }; 1457 1458 _proto.reverse = function reverse(location, scale, cb, context) { 1459 getJSON(this.options.serviceUrl + 'reverse', reverseParams(this.options, { 1460 key: this.options.apiKey, 1461 coords: [location.lat, location.lng].join(',') 1462 }), function (data) { 1463 var results = []; 1464 1465 if (data.status.status == 200) { 1466 var center = L__namespace.latLng(data.geometry['lat'], data.geometry['lng']); 1467 var bbox = L__namespace.latLngBounds(center, center); 1468 results[0] = { 1469 name: data.words, 1470 bbox: bbox, 1471 center: center 1472 }; 1473 } 1474 1475 cb.call(context, results); 1476 }); 1477 }; 1478 1479 return What3Words; 1480 }(); 1481 /** 1482 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link What3Words} 1483 * @param options the options 1484 */ 1485 1486 function what3words(options) { 1487 return new What3Words(options); 1488 } 1489 1490 var geocoders = { 1491 __proto__: null, 1492 geocodingParams: geocodingParams, 1493 reverseParams: reverseParams, 1494 ArcGis: ArcGis, 1495 arcgis: arcgis, 1496 Bing: Bing, 1497 bing: bing, 1498 Google: Google, 1499 google: google, 1500 HERE: HERE, 1501 HEREv2: HEREv2, 1502 here: here, 1503 parseLatLng: parseLatLng, 1504 LatLng: LatLng, 1505 latLng: latLng, 1506 Mapbox: Mapbox, 1507 mapbox: mapbox, 1508 MapQuest: MapQuest, 1509 mapQuest: mapQuest, 1510 Neutrino: Neutrino, 1511 neutrino: neutrino, 1512 Nominatim: Nominatim, 1513 nominatim: nominatim, 1514 OpenLocationCode: OpenLocationCode, 1515 openLocationCode: openLocationCode, 1516 OpenCage: OpenCage, 1517 opencage: opencage, 1518 Pelias: Pelias, 1519 pelias: pelias, 1520 GeocodeEarth: GeocodeEarth, 1521 geocodeEarth: geocodeEarth, 1522 Mapzen: Mapzen, 1523 mapzen: mapzen, 1524 Openrouteservice: Openrouteservice, 1525 openrouteservice: openrouteservice, 1526 Photon: Photon, 1527 photon: photon, 1528 What3Words: What3Words, 1529 what3words: what3words 1530 }; 1531 1532 /** 1533 * Leaflet mixins https://leafletjs.com/reference-1.7.1.html#class-includes
1534 * for TypeScript https://www.typescriptlang.org/docs/handbook/mixins.html 1535 * @internal 1536 */ 1537 1538 var EventedControl = // eslint-disable-next-line @typescript-eslint/no-unused-vars 1539 function EventedControl() {// empty 1540 }; 1541 1542 L__namespace.Util.extend(EventedControl.prototype, L__namespace.Control.prototype); 1543 L__namespace.Util.extend(EventedControl.prototype, L__namespace.Evented.prototype); 1544 /** 1545 * This is the geocoder control. It works like any other [Leaflet control](https://leafletjs.com/reference.html#control), and is added to the map. 1546 */ 1547 1548 var GeocoderControl = /*#__PURE__*/function (_EventedControl) { 1549 _inheritsLoose(GeocoderControl, _EventedControl); 1550 1551 /** 1552 * Instantiates a geocoder control (to be invoked using `new`) 1553 * @param options the options 1554 */ 1555 function GeocoderControl(options) { 1556 var _this; 1557 1558 _this = _EventedControl.call(this, options) || this; 1559 _this.options = { 1560 showUniqueResult: true, 1561 showResultIcons: false, 1562 collapsed: true, 1563 expand: 'touch', 1564 position: 'topright', 1565 placeholder: 'Search...', 1566 errorMessage: 'Nothing found.', 1567 iconLabel: 'Initiate a new search', 1568 query: '', 1569 queryMinLength: 1, 1570 suggestMinLength: 3, 1571 suggestTimeout: 250, 1572 defaultMarkGeocode: true 1573 }; 1574 _this._requestCount = 0; 1575 L__namespace.Util.setOptions(_assertThisInitialized(_this), options); 1576 1577 if (!_this.options.geocoder) { 1578 _this.options.geocoder = new Nominatim(); 1579 } 1580 1581 return _this; 1582 } 1583 1584 var _proto = GeocoderControl.prototype; 1585 1586 _proto.addThrobberClass = function addThrobberClass() { 1587 L__namespace.DomUtil.addClass(this._container, 'leaflet-control-geocoder-throbber'); 1588 }; 1589 1590 _proto.removeThrobberClass = function removeThrobberClass() { 1591 L__namespace.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-throbber'); 1592 } 1593 /** 1594 * Returns the container DOM element for the control and add listeners on relevant map events. 1595 * @param map the map instance 1596 * @see https://leafletjs.com/reference.html#control-onadd 1597 */ 1598 ; 1599 1600 _proto.onAdd = function onAdd(map) { 1601 var _this2 = this; 1602 1603 var className = 'leaflet-control-geocoder'; 1604 var container = L__namespace.DomUtil.create('div', className + ' leaflet-bar'); 1605 var icon = L__namespace.DomUtil.create('button', className + '-icon', container); 1606 var form = this._form = L__namespace.DomUtil.create('div', className + '-form', container); 1607 this._map = map; 1608 this._container = container; 1609 icon.innerHTML = ' '; 1610 icon.type = 'button'; 1611 icon.setAttribute('aria-label', this.options.iconLabel); 1612 var input = this._input = L__namespace.DomUtil.create('input', '', form); 1613 input.type = 'text'; 1614 input.value = this.options.query; 1615 input.placeholder = this.options.placeholder; 1616 L__namespace.DomEvent.disableClickPropagation(input); 1617 this._errorElement = L__namespace.DomUtil.create('div', className + '-form-no-error', container); 1618 this._errorElement.innerHTML = this.options.errorMessage; 1619 this._alts = L__namespace.DomUtil.create('ul', className + '-alternatives leaflet-control-geocoder-alternatives-minimized', container); 1620 L__namespace.DomEvent.disableClickPropagation(this._alts); 1621 L__namespace.DomEvent.addListener(input, 'keydown', this._keydown, this); 1622 1623 if (this.options.geocoder.suggest) { 1624 L__namespace.DomEvent.addListener(input, 'input', this._change, this); 1625 } 1626 1627 L__namespace.DomEvent.addListener(input, 'blur', function () { 1628 if (_this2.options.collapsed && !_this2._preventBlurCollapse) { 1629 _this2._collapse(); 1630 } 1631 1632 _this2._preventBlurCollapse = false; 1633 }); 1634 1635 if (this.options.collapsed) { 1636 if (this.options.expand === 'click') { 1637 L__namespace.DomEvent.addListener(container, 'click', function (e) { 1638 if (e.button === 0 && e.detail !== 2) { 1639 _this2._toggle(); 1640 } 1641 }); 1642 } else if (this.options.expand === 'touch') { 1643 L__namespace.DomEvent.addListener(container, L__namespace.Browser.touch ? 'touchstart mousedown' : 'mousedown', function (e) { 1644 _this2._toggle(); 1645 1646 e.preventDefault(); // mobile: clicking focuses the icon, so UI expands and immediately collapses 1647 1648 e.stopPropagation(); 1649 }, this); 1650 } else { 1651 L__namespace.DomEvent.addListener(container, 'mouseover', this._expand, this); 1652 L__namespace.DomEvent.addListener(container, 'mouseout', this._collapse, this); 1653 1654 this._map.on('movestart', this._collapse, this); 1655 } 1656 } else { 1657 this._expand(); 1658 1659 if (L__namespace.Browser.touch) { 1660 L__namespace.DomEvent.addListener(container, 'touchstart', function () { 1661 return _this2._geocode(); 1662 }); 1663 } else { 1664 L__namespace.DomEvent.addListener(container, 'click', function () { 1665 return _this2._geocode(); 1666 }); 1667 } 1668 } 1669 1670 if (this.options.defaultMarkGeocode) { 1671 this.on('markgeocode', this.markGeocode, this); 1672 } 1673 1674 this.on('startgeocode', this.addThrobberClass, this); 1675 this.on('finishgeocode', this.removeThrobberClass, this); 1676 this.on('startsuggest', this.addThrobberClass, this); 1677 this.on('finishsuggest', this.removeThrobberClass, this); 1678 L__namespace.DomEvent.disableClickPropagation(container); 1679 return container; 1680 } 1681 /** 1682 * Sets the query string on the text input 1683 * @param string the query string 1684 */ 1685 ; 1686 1687 _proto.setQuery = function setQuery(string) { 1688 this._input.value = string; 1689 return this; 1690 }; 1691 1692 _proto._geocodeResult = function _geocodeResult(results, suggest) { 1693 if (!suggest && this.options.showUniqueResult && results.length === 1) { 1694 this._geocodeResultSelected(results[0]); 1695 } else if (results.length > 0) { 1696 this._alts.innerHTML = ''; 1697 this._results = results; 1698 L__namespace.DomUtil.removeClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); 1699 L__namespace.DomUtil.addClass(this._container, 'leaflet-control-geocoder-options-open'); 1700 1701 for (var i = 0; i < results.length; i++) { 1702 this._alts.appendChild(this._createAlt(results[i], i)); 1703 } 1704 } else { 1705 L__namespace.DomUtil.addClass(this._container, 'leaflet-control-geocoder-options-error'); 1706 L__namespace.DomUtil.addClass(this._errorElement, 'leaflet-control-geocoder-error'); 1707 } 1708 } 1709 /** 1710 * Marks a geocoding result on the map 1711 * @param result the geocoding result 1712 */ 1713 ; 1714 1715 _proto.markGeocode = function markGeocode(event) { 1716 var result = event.geocode; 1717 1718 this._map.fitBounds(result.bbox); 1719 1720 if (this._geocodeMarker) { 1721 this._map.removeLayer(this._geocodeMarker); 1722 } 1723 1724 this._geocodeMarker = new L__namespace.Marker(result.center).bindPopup(result.html || result.name).addTo(this._map).openPopup(); 1725 return this; 1726 }; 1727 1728 _proto._geocode = function _geocode(suggest) { 1729 var _this3 = this; 1730 1731 var value = this._input.value; 1732 1733 if (!suggest && value.length < this.options.queryMinLength) { 1734 return; 1735 } 1736 1737 var requestCount = ++this._requestCount; 1738 1739 var cb = function cb(results) { 1740 if (requestCount === _this3._requestCount) { 1741 var _event = { 1742 input: value, 1743 results: results 1744 }; 1745 1746 _this3.fire(suggest ? 'finishsuggest' : 'finishgeocode', _event); 1747 1748 _this3._geocodeResult(results, suggest); 1749 } 1750 }; 1751 1752 this._lastGeocode = value; 1753 1754 if (!suggest) { 1755 this._clearResults(); 1756 } 1757 1758 var event = { 1759 input: value 1760 }; 1761 this.fire(suggest ? 'startsuggest' : 'startgeocode', event); 1762 1763 if (suggest) { 1764 this.options.geocoder.suggest(value, cb); 1765 } else { 1766 this.options.geocoder.geocode(value, cb); 1767 } 1768 }; 1769 1770 _proto._geocodeResultSelected = function _geocodeResultSelected(geocode) { 1771 var event = { 1772 geocode: geocode 1773 }; 1774 this.fire('markgeocode', event); 1775 }; 1776 1777 _proto._toggle = function _toggle() { 1778 if (L__namespace.DomUtil.hasClass(this._container, 'leaflet-control-geocoder-expanded')) { 1779 this._collapse(); 1780 } else { 1781 this._expand(); 1782 } 1783 }; 1784 1785 _proto._expand = function _expand() { 1786 L__namespace.DomUtil.addClass(this._container, 'leaflet-control-geocoder-expanded'); 1787 1788 this._input.select(); 1789 1790 this.fire('expand'); 1791 }; 1792 1793 _proto._collapse = function _collapse() { 1794 L__namespace.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-expanded'); 1795 L__namespace.DomUtil.addClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); 1796 L__namespace.DomUtil.removeClass(this._errorElement, 'leaflet-control-geocoder-error'); 1797 L__namespace.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-options-open'); 1798 L__namespace.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-options-error'); 1799 1800 this._input.blur(); // mobile: keyboard shouldn't stay expanded 1801 1802 1803 this.fire('collapse'); 1804 }; 1805 1806 _proto._clearResults = function _clearResults() { 1807 L__namespace.DomUtil.addClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); 1808 this._selection = null; 1809 L__namespace.DomUtil.removeClass(this._errorElement, 'leaflet-control-geocoder-error'); 1810 L__namespace.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-options-open'); 1811 L__namespace.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-options-error'); 1812 }; 1813 1814 _proto._createAlt = function _createAlt(result, index) { 1815 var _this4 = this; 1816 1817 var li = L__namespace.DomUtil.create('li', ''), 1818 a = L__namespace.DomUtil.create('a', '', li), 1819 icon = this.options.showResultIcons && result.icon ? L__namespace.DomUtil.create('img', '', a) : null, 1820 text = result.html ? undefined : document.createTextNode(result.name), 1821 mouseDownHandler = function mouseDownHandler(e) { 1822 // In some browsers, a click will fire on the map if the control is
1823 // collapsed directly after mousedown. To work around this, we 1824 // wait until the click is completed, and _then_ collapse the 1825 // control. Messy, but this is the workaround I could come up with 1826 // for #142. 1827 _this4._preventBlurCollapse = true; 1828 L__namespace.DomEvent.stop(e); 1829 1830 _this4._geocodeResultSelected(result); 1831 1832 L__namespace.DomEvent.on(li, 'click touchend', function () { 1833 if (_this4.options.collapsed) { 1834 _this4._collapse(); 1835 } else { 1836 _this4._clearResults(); 1837 } 1838 }); 1839 }; 1840 1841 if (icon) { 1842 icon.src = result.icon; 1843 } 1844 1845 li.setAttribute('data-result-index', String(index)); 1846 1847 if (result.html) { 1848 a.innerHTML = a.innerHTML + result.html; 1849 } else if (text) { 1850 a.appendChild(text); 1851 } // Use mousedown and not click, since click will fire _after_ blur, 1852 // causing the control to have collapsed and removed the items 1853 // before the click can fire. 1854 1855 1856 L__namespace.DomEvent.addListener(li, 'mousedown touchstart', mouseDownHandler, this); 1857 return li; 1858 }; 1859 1860 _proto._keydown = function _keydown(e) { 1861 var _this5 = this; 1862 1863 var select = function select(dir) { 1864 if (_this5._selection) { 1865 L__namespace.DomUtil.removeClass(_this5._selection, 'leaflet-control-geocoder-selected'); 1866 _this5._selection = _this5._selection[dir > 0 ? 'nextSibling' : 'previousSibling']; 1867 } 1868 1869 if (!_this5._selection) { 1870 _this5._selection = _this5._alts[dir > 0 ? 'firstChild' : 'lastChild']; 1871 } 1872 1873 if (_this5._selection) { 1874 L__namespace.DomUtil.addClass(_this5._selection, 'leaflet-control-geocoder-selected'); 1875 } 1876 }; 1877 1878 switch (e.keyCode) { 1879 // Escape 1880 case 27: 1881 if (this.options.collapsed) { 1882 this._collapse(); 1883 } else { 1884 this._clearResults(); 1885 } 1886 1887 break; 1888 // Up 1889 1890 case 38: 1891 select(-1); 1892 break; 1893 // Up 1894 1895 case 40: 1896 select(1); 1897 break; 1898 // Enter 1899 1900 case 13: 1901 if (this._selection) { 1902 var index = parseInt(this._selection.getAttribute('data-result-index'), 10); 1903 1904 this._geocodeResultSelected(this._results[index]); 1905 1906 this._clearResults(); 1907 } else { 1908 this._geocode(); 1909 } 1910 1911 break; 1912 1913 default: 1914 return; 1915 } 1916 1917 L__namespace.DomEvent.preventDefault(e); 1918 }; 1919 1920 _proto._change = function _change() { 1921 var _this6 = this; 1922 1923 var v = this._input.value; 1924 1925 if (v !== this._lastGeocode) { 1926 clearTimeout(this._suggestTimeout); 1927 1928 if (v.length >= this.options.suggestMinLength) { 1929 this._suggestTimeout = setTimeout(function () { 1930 return _this6._geocode(true); 1931 }, this.options.suggestTimeout); 1932 } else { 1933 this._clearResults(); 1934 } 1935 } 1936 }; 1937 1938 return GeocoderControl; 1939 }(EventedControl); 1940 /** 1941 * [Class factory method](https://leafletjs.com/reference.html#class-class-factories) for {@link GeocoderControl} 1942 * @param options the options 1943 */ 1944 1945 function geocoder(options) { 1946 return new GeocoderControl(options); 1947 } 1948 1949 /* @preserve 1950 * Leaflet Control Geocoder 1951 * https://github.com/perliedman/leaflet-control-geocoder 1952 * 1953 * Copyright (c) 2012 sa3m (https://github.com/sa3m) 1954 * Copyright (c) 2018 Per Liedman 1955 * All rights reserved. 1956 */ 1957 L__namespace.Util.extend(GeocoderControl, geocoders); 1958 L__namespace.Util.extend(L__namespace.Control, { 1959 Geocoder: GeocoderControl, 1960 geocoder: geocoder 1961 }); 1962 1963 exports.Geocoder = GeocoderControl; 1964 exports.default = GeocoderControl; 1965 exports.geocoder = geocoder; 1966 exports.geocoders = geocoders; 1967 1968 return exports; 1969 1970}({}, L)); 1971//# sourceMappingURL=Control.Geocoder.js.map
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.