1(function (global, factory) { 2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (factory((global.L = {}))) 3}(this, (function (exports) { 4 'use strict'; 5 var version = "1.3.3+HEAD.b22aef4"; 6 var freeze = Object.freeze; 7 Object.freeze = function (obj) { 8 return obj 9 } 10 ; 11 function extend(dest) { 12 var i, j, len, src; 13 for (j = 1, 14 len = arguments.length; j < len; j++) { 15 src = arguments[j]; 16 for (i in src) { 17 dest[i] = src[i] 18 } 19 } 20 return dest 21 } 22 var create = Object.create || (function () { 23 function F() { } 24 return function (proto) { 25 F.prototype = proto; 26 return new F() 27 } 28 } 29 )(); 30 function bind(fn, obj) { 31 var slice = Array.prototype.slice; 32 if (fn.bind) { 33 return fn.bind.apply(fn, slice.call(arguments, 1)) 34 } 35 var args = slice.call(arguments, 2); 36 return function () { 37 return fn.apply(obj, args.length ? args.concat(slice.call(arguments)) : arguments) 38 } 39 } 40 var lastId = 0; 41 function stamp(obj) { 42 obj._leaflet_id = obj._leaflet_id || ++lastId; 43 return obj._leaflet_id 44 } 45 function throttle(fn, time, context) { 46 var lock, args, wrapperFn, later; 47 later = function () { 48 lock = !1; 49 if (args) { 50 wrapperFn.apply(context, args); 51 args = !1 52 } 53 } 54 ; 55 wrapperFn = function () { 56 if (lock) { 57 args = arguments 58 } else { 59 fn.apply(context, arguments); 60 setTimeout(later, time); 61 lock = !0 62 } 63 } 64 ; 65 return wrapperFn 66 } 67 function wrapNum(x, range, includeMax) { 68 var max = range[1] 69 , min = range[0] 70 , d = max - min; 71 return x === max && includeMax ? x : ((x - min) % d + d) % d + min 72 } 73 function falseFn() { 74 return !1 75 } 76 function formatNum(num, digits) { 77 var pow = Math.pow(10, (digits === undefined ? 6 : digits)); 78 return Math.round(num * pow) / pow 79 } 80 function trim(str) { 81 return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '') 82 } 83 function splitWords(str) { 84 return trim(str).split(/\s+/) 85 } 86 function setOptions(obj, options) { 87 if (!obj.hasOwnProperty('options')) { 88 obj.options = obj.options ? create(obj.options) : {} 89 } 90 for (var i in options) { 91 obj.options[i] = options[i] 92 } 93 return obj.options 94 } 95 function getParamString(obj, existingUrl, uppercase) { 96 var params = []; 97 for (var i in obj) { 98 params.push(encodeURIComponent(uppercase ? i.toUpperCase() : i) + '=' + encodeURIComponent(obj[i])) 99 } 100 return ((!existingUrl || existingUrl.indexOf('?') === -1) ? '?' : '&') + params.join('&') 101 } 102 var templateRe = /\{ *([\w_-]+) *\}/g; 103 function template(str, data) { 104 return str.replace(templateRe, function (str, key) { 105 var value = data[key]; 106 if (value === undefined) { 107 throw new Error('No value provided for variable ' + str) 108 } else if (typeof value === 'function') { 109 value = value(data) 110 } 111 return value 112 }) 113 } 114 var isArray = Array.isArray || function (obj) { 115 return (Object.prototype.toString.call(obj) === '[object Array]') 116 } 117 ; 118 function indexOf(array, el) { 119 for (var i = 0; i < array.length; i++) { 120 if (array[i] === el) { 121 return i 122 } 123 } 124 return -1 125 } 126 var emptyImageUrl = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='; 127 function getPrefixed(name) { 128 return window['webkit' + name] || window['moz' + name] || window['ms' + name] 129 } 130 var lastTime = 0; 131 function timeoutDefer(fn) { 132 var time = +new Date() 133 , timeToCall = Math.max(0, 16 - (time - lastTime)); 134 lastTime = time + timeToCall; 135 return window.setTimeout(fn, timeToCall) 136 } 137 var requestFn = window.requestAnimationFrame || getPrefixed('RequestAnimationFrame') || timeoutDefer; 138 var cancelFn = window.cancelAnimationFrame || getPrefixed('CancelAnimationFrame') || getPrefixed('CancelRequestAnimationFrame') || function (id) { 139 window.clearTimeout(id) 140 } 141 ;
142 function requestAnimFrame(fn, context, immediate) { 143 if (immediate && requestFn === timeoutDefer) { 144 fn.call(context) 145 } else { 146 return requestFn.call(window, bind(fn, context)) 147 } 148 } 149 function cancelAnimFrame(id) { 150 if (id) { 151 cancelFn.call(window, id) 152 } 153 } 154 var Util = (Object.freeze || Object)({ 155 freeze: freeze, 156 extend: extend, 157 create: create, 158 bind: bind, 159 lastId: lastId, 160 stamp: stamp, 161 throttle: throttle, 162 wrapNum: wrapNum, 163 falseFn: falseFn, 164 formatNum: formatNum, 165 trim: trim, 166 splitWords: splitWords, 167 setOptions: setOptions, 168 getParamString: getParamString, 169 template: template, 170 isArray: isArray, 171 indexOf: indexOf, 172 emptyImageUrl: emptyImageUrl, 173 requestFn: requestFn, 174 cancelFn: cancelFn, 175 requestAnimFrame: requestAnimFrame, 176 cancelAnimFrame: cancelAnimFrame 177 }); 178 function Class() { } 179 Class.extend = function (props) { 180 var NewClass = function () { 181 if (this.initialize) { 182 this.initialize.apply(this, arguments) 183 } 184 this.callInitHooks() 185 }; 186 var parentProto = NewClass.__super__ = this.prototype; 187 var proto = create(parentProto); 188 proto.constructor = NewClass; 189 NewClass.prototype = proto; 190 for (var i in this) { 191 if (this.hasOwnProperty(i) && i !== 'prototype' && i !== '__super__') { 192 NewClass[i] = this[i] 193 } 194 } 195 if (props.statics) { 196 extend(NewClass, props.statics); 197 delete props.statics 198 } 199 if (props.includes) { 200 checkDeprecatedMixinEvents(props.includes); 201 extend.apply(null, [proto].concat(props.includes)); 202 delete props.includes 203 } 204 if (proto.options) { 205 props.options = extend(create(proto.options), props.options) 206 } 207 extend(proto, props); 208 proto._initHooks = []; 209 proto.callInitHooks = function () { 210 if (this._initHooksCalled) { 211 return 212 } 213 if (parentProto.callInitHooks) { 214 parentProto.callInitHooks.call(this) 215 } 216 this._initHooksCalled = !0; 217 for (var i = 0, len = proto._initHooks.length; i < len; i++) { 218 proto._initHooks[i].call(this) 219 } 220 } 221 ; 222 return NewClass 223 } 224 ; 225 Class.include = function (props) { 226 extend(this.prototype, props); 227 return this 228 } 229 ; 230 Class.mergeOptions = function (options) { 231 extend(this.prototype.options, options); 232 return this 233 } 234 ; 235 Class.addInitHook = function (fn) { 236 var args = Array.prototype.slice.call(arguments, 1); 237 var init = typeof fn === 'function' ? fn : function () { 238 this[fn].apply(this, args) 239 } 240 ; 241 this.prototype._initHooks = this.prototype._initHooks || []; 242 this.prototype._initHooks.push(init); 243 return this 244 } 245 ; 246 function checkDeprecatedMixinEvents(includes) { 247 if (typeof L === 'undefined' || !L || !L.Mixin) { 248 return 249 } 250 includes = isArray(includes) ? includes : [includes]; 251 for (var i = 0; i < includes.length; i++) { 252 if (includes[i] === L.Mixin.Events) {
253 console.warn('Deprecated include of L.Mixin.Events: ' + 'this property will be removed in future releases, ' + 'please inherit from L.Evented instead.', new Error().stack) 254 } 255 } 256 } 257 var Events = { 258 on: function (types, fn, context) { 259 if (typeof types === 'object') { 260 for (var type in types) { 261 this._on(type, types[type], fn) 262 } 263 } else { 264 types = splitWords(types); 265 for (var i = 0, len = types.length; i < len; i++) { 266 this._on(types[i], fn, context) 267 } 268 } 269 return this 270 }, 271 off: function (types, fn, context) { 272 if (!types) { 273 delete this._events 274 } else if (typeof types === 'object') { 275 for (var type in types) { 276 this._off(type, types[type], fn) 277 } 278 } else { 279 types = splitWords(types); 280 for (var i = 0, len = types.length; i < len; i++) { 281 this._off(types[i], fn, context) 282 } 283 } 284 return this 285 }, 286 _on: function (type, fn, context) { 287 this._events = this._events || {}; 288 var typeListeners = this._events[type]; 289 if (!typeListeners) { 290 typeListeners = []; 291 this._events[type] = typeListeners 292 } 293 if (context === this) { 294 context = undefined 295 } 296 var newListener = { 297 fn: fn, 298 ctx: context 299 } 300 , listeners = typeListeners; 301 for (var i = 0, len = listeners.length; i < len; i++) { 302 if (listeners[i].fn === fn && listeners[i].ctx === context) { 303 return 304 } 305 } 306 listeners.push(newListener) 307 }, 308 _off: function (type, fn, context) { 309 var listeners, i, len; 310 if (!this._events) { 311 return 312 } 313 listeners = this._events[type]; 314 if (!listeners) { 315 return 316 } 317 if (!fn) { 318 for (i = 0, 319 len = listeners.length; i < len; i++) { 320 listeners[i].fn = falseFn 321 } 322 delete this._events[type]; 323 return 324 } 325 if (context === this) { 326 context = undefined 327 } 328 if (listeners) { 329 for (i = 0, 330 len = listeners.length; i < len; i++) { 331 var l = listeners[i]; 332 if (l.ctx !== context) { 333 continue 334 } 335 if (l.fn === fn) { 336 l.fn = falseFn; 337 if (this._firingCount) { 338 this._events[type] = listeners = listeners.slice() 339 } 340 listeners.splice(i, 1); 341 return 342 } 343 } 344 } 345 }, 346 fire: function (type, data, propagate) { 347 if (!this.listens(type, propagate)) { 348 return this 349 } 350 var event = extend({}, data, { 351 type: type, 352 target: this, 353 sourceTarget: data && data.sourceTarget || this 354 }); 355 if (this._events) { 356 var listeners = this._events[type]; 357 if (listeners) { 358 this._firingCount = (this._firingCount + 1) || 1; 359 for (var i = 0, len = listeners.length; i < len; i++) { 360 var l = listeners[i]; 361 l.fn.call(l.ctx || this, event) 362 } 363 this._firingCount-- 364 } 365 } 366 if (propagate) { 367 this._propagateEvent(event) 368 } 369 return this 370 }, 371 listens: function (type, propagate) { 372 var listeners = this._events && this._events[type]; 373 if (listeners && listeners.length) { 374 return !0 375 } 376 if (propagate) { 377 for (var id in this._eventParents) { 378 if (this._eventParents[id].listens(type, propagate)) { 379 return !0 380 } 381 } 382 } 383 return !1 384 }, 385 once: function (types, fn, context) { 386 if (typeof types === 'object') { 387 for (var type in types) { 388 this.once(type, types[type], fn) 389 } 390 return this 391 } 392 var handler = bind(function () { 393 this.off(types, fn, context).off(types, handler, context) 394 }, this); 395 return this.on(types, fn, context).on(types, handler, context) 396 }, 397 addEventParent: function (obj) { 398 this._eventParents = this._eventParents || {}; 399 this._eventParents[stamp(obj)] = obj;
400 return this 401 }, 402 removeEventParent: function (obj) { 403 if (this._eventParents) { 404 delete this._eventParents[stamp(obj)] 405 } 406 return this 407 }, 408 _propagateEvent: function (e) { 409 for (var id in this._eventParents) { 410 this._eventParents[id].fire(e.type, extend({ 411 layer: e.target, 412 propagatedFrom: e.target 413 }, e), !0) 414 } 415 } 416 }; 417 Events.addEventListener = Events.on; 418 Events.removeEventListener = Events.clearAllEventListeners = Events.off; 419 Events.addOneTimeEventListener = Events.once; 420 Events.fireEvent = Events.fire; 421 Events.hasEventListeners = Events.listens; 422 var Evented = Class.extend(Events); 423 function Point(x, y, round) { 424 this.x = (round ? Math.round(x) : x); 425 this.y = (round ? Math.round(y) : y) 426 } 427 var trunc = Math.trunc || function (v) { 428 return v > 0 ? Math.floor(v) : Math.ceil(v) 429 } 430 ; 431 Point.prototype = { 432 clone: function () { 433 return new Point(this.x, this.y) 434 }, 435 add: function (point) { 436 return this.clone()._add(toPoint(point)) 437 }, 438 _add: function (point) { 439 this.x += point.x; 440 this.y += point.y; 441 return this 442 }, 443 subtract: function (point) { 444 return this.clone()._subtract(toPoint(point)) 445 }, 446 _subtract: function (point) { 447 this.x -= point.x; 448 this.y -= point.y; 449 return this 450 }, 451 divideBy: function (num) { 452 return this.clone()._divideBy(num) 453 }, 454 _divideBy: function (num) { 455 this.x /= num; 456 this.y /= num; 457 return this 458 }, 459 multiplyBy: function (num) { 460 return this.clone()._multiplyBy(num) 461 }, 462 _multiplyBy: function (num) { 463 this.x *= num; 464 this.y *= num; 465 return this 466 }, 467 scaleBy: function (point) { 468 return new Point(this.x * point.x, this.y * point.y) 469 }, 470 unscaleBy: function (point) { 471 return new Point(this.x / point.x, this.y / point.y) 472 }, 473 round: function () { 474 return this.clone()._round() 475 }, 476 _round: function () { 477 this.x = Math.round(this.x); 478 this.y = Math.round(this.y); 479 return this 480 }, 481 floor: function () { 482 return this.clone()._floor() 483 }, 484 _floor: function () { 485 this.x = Math.floor(this.x); 486 this.y = Math.floor(this.y); 487 return this 488 }, 489 ceil: function () { 490 return this.clone()._ceil() 491 }, 492 _ceil: function () { 493 this.x = Math.ceil(this.x); 494 this.y = Math.ceil(this.y); 495 return this 496 }, 497 trunc: function () { 498 return this.clone()._trunc() 499 }, 500 _trunc: function () { 501 this.x = trunc(this.x); 502 this.y = trunc(this.y); 503 return this 504 }, 505 distanceTo: function (point) { 506 point = toPoint(point); 507 var x = point.x - this.x 508 , y = point.y - this.y; 509 return Math.sqrt(x * x + y * y) 510 }, 511 equals: function (point) { 512 point = toPoint(point); 513 return point.x === this.x && point.y === this.y 514 }, 515 contains: function (point) { 516 point = toPoint(point); 517 return Math.abs(point.x) <= Math.abs(this.x) && Math.abs(point.y) <= Math.abs(this.y) 518 }, 519 toString: function () { 520 return 'Point(' + formatNum(this.x) + ', ' + formatNum(this.y) + ')' 521 } 522 }; 523 function toPoint(x, y, round) { 524 if (x instanceof Point) { 525 return x 526 } 527 if (isArray(x)) { 528 return new Point(x[0], x[1]) 529 } 530 if (x === undefined || x === null) { 531 return x 532 } 533 if (typeof x === 'object' && 'x' in x && 'y' in x) { 534 return new Point(x.x, x.y) 535 } 536 return new Point(x, y, round) 537 } 538 function Bounds(a, b) { 539 if (!a) { 540 return 541 } 542 var points = b ? [a, b] : a; 543 for (var i = 0, len = points.length; i < len; i++) { 544 this.extend(points[i]) 545 } 546 } 547 Bounds.prototype = { 548 extend: function (point) { 549 point = toPoint(point); 550 if (!this.min && !this.max) { 551 this.min = point.clone(); 552 this.max = point.clone() 553 } else { 554 this.min.x = Math.min(point.x, this.min.x); 555 this.max.x = Math.max(point.x, this.max.x); 556 this.min.y = Math.min(point.y, this.min.y); 557 this.max.y = Math.max(point.y, this.max.y) 558 } 559 return this 560 }, 561 getCenter: function (round) { 562 return new Point((this.min.x + this.max.x) / 2, (this.min.y + this.max.y) / 2, round) 563 }, 564 getBottomLeft: function () { 565 return new Point(this.min.x, this.max.y) 566 }, 567 getTopRight: function () { 568 return new Point(this.max.x, this.min.y) 569 }, 570 getTopLeft: function () { 571 return this.min 572 }, 573 getBottomRight: function () { 574 return this.max 575 }, 576 getSize: function () { 577 return this.max.subtract(this.min) 578 }, 579 contains: function (obj) { 580 var min, max; 581 if (typeof obj[0] === 'number' || obj instanceof Point) { 582 obj = toPoint(obj) 583 } else { 584 obj = toBounds(obj) 585 } 586 if (obj instanceof Bounds) { 587 min = obj.min; 588 max = obj.max 589 } else { 590 min = max = obj 591 } 592 return (min.x >= this.min.x) && (max.x <= this.max.x) && (min.y >= this.min.y) && (max.y <= this.max.y) 593 }, 594 intersects: function (bounds) { 595 bounds = toBounds(bounds); 596 var min = this.min 597 , max = this.max 598 , min2 = bounds.min 599 , max2 = bounds.max 600 , xIntersects = (max2.x >= min.x) && (min2.x <= max.x) 601 , yIntersects = (max2.y >= min.y) && (min2.y <= max.y); 602 return xIntersects && yIntersects 603 }, 604 overlaps: function (bounds) { 605 bounds = toBounds(bounds); 606 var min = this.min 607 , max = this.max 608 , min2 = bounds.min 609 , max2 = bounds.max 610 , xOverlaps = (max2.x > min.x) && (min2.x < max.x) 611 , yOverlaps = (max2.y > min.y) && (min2.y < max.y); 612 return xOverlaps && yOverlaps 613 }, 614 isValid: function () { 615 return !!(this.min && this.max) 616 } 617 }; 618 function toBounds(a, b) { 619 if (!a || a instanceof Bounds) { 620 return a 621 } 622 return new Bounds(a, b) 623 } 624 function LatLngBounds(corner1, corner2) { 625 if (!corner1) { 626 return 627 } 628 var latlngs = corner2 ? [corner1, corner2] : corner1; 629 for (var i = 0, len = latlngs.length; i < len; i++) { 630 this.extend(latlngs[i]) 631 } 632 } 633 LatLngBounds.prototype = { 634 extend: function (obj) { 635 var sw = this._southWest, ne = this._northEast, sw2, ne2; 636 if (obj instanceof LatLng) { 637 sw2 = obj; 638 ne2 = obj 639 } else if (obj instanceof LatLngBounds) { 640 sw2 = obj._southWest; 641 ne2 = obj._northEast; 642 if (!sw2 || !ne2) { 643 return this 644 } 645 } else { 646 return obj ? this.extend(toLatLng(obj) || toLatLngBounds(obj)) : this 647 } 648 if (!sw && !ne) { 649 this._southWest = new LatLng(sw2.lat, sw2.lng); 650 this._northEast = new LatLng(ne2.lat, ne2.lng) 651 } else { 652 sw.lat = Math.min(sw2.lat, sw.lat); 653 sw.lng = Math.min(sw2.lng, sw.lng); 654 ne.lat = Math.max(ne2.lat, ne.lat); 655 ne.lng = Math.max(ne2.lng, ne.lng) 656 } 657 return this 658 }, 659 pad: function (bufferRatio) { 660 var sw = this._southWest 661 , ne = this._northEast 662 , heightBuffer = Math.abs(sw.lat - ne.lat) * bufferRatio 663 , widthBuffer = Math.abs(sw.lng - ne.lng) * bufferRatio;
664 return new LatLngBounds(new LatLng(sw.lat - heightBuffer, sw.lng - widthBuffer), new LatLng(ne.lat + heightBuffer, ne.lng + widthBuffer)) 665 }, 666 getCenter: function () { 667 return new LatLng((this._southWest.lat + this._northEast.lat) / 2, (this._southWest.lng + this._northEast.lng) / 2) 668 }, 669 getSouthWest: function () { 670 return this._southWest 671 }, 672 getNorthEast: function () { 673 return this._northEast 674 }, 675 getNorthWest: function () { 676 return new LatLng(this.getNorth(), this.getWest()) 677 }, 678 getSouthEast: function () { 679 return new LatLng(this.getSouth(), this.getEast()) 680 }, 681 getWest: function () { 682 return this._southWest.lng 683 }, 684 getSouth: function () { 685 return this._southWest.lat 686 }, 687 getEast: function () { 688 return this._northEast.lng 689 }, 690 getNorth: function () { 691 return this._northEast.lat 692 }, 693 contains: function (obj) { 694 if (typeof obj[0] === 'number' || obj instanceof LatLng || 'lat' in obj) { 695 obj = toLatLng(obj) 696 } else { 697 obj = toLatLngBounds(obj) 698 } 699 var sw = this._southWest, ne = this._northEast, sw2, ne2; 700 if (obj instanceof LatLngBounds) {
701 sw2 = obj.getSouthWest(); 702 ne2 = obj.getNorthEast() 703 } else { 704 sw2 = ne2 = obj 705 } 706 return (sw2.lat >= sw.lat) && (ne2.lat <= ne.lat) && (sw2.lng >= sw.lng) && (ne2.lng <= ne.lng) 707 }, 708 intersects: function (bounds) { 709 bounds = toLatLngBounds(bounds); 710 var sw = this._southWest 711 , ne = this._northEast 712 , sw2 = bounds.getSouthWest() 713 , ne2 = bounds.getNorthEast() 714 , latIntersects = (ne2.lat >= sw.lat) && (sw2.lat <= ne.lat) 715 , lngIntersects = (ne2.lng >= sw.lng) && (sw2.lng <= ne.lng); 716 return latIntersects && lngIntersects 717 }, 718 overlaps: function (bounds) { 719 bounds = toLatLngBounds(bounds); 720 var sw = this._southWest 721 , ne = this._northEast 722 , sw2 = bounds.getSouthWest() 723 , ne2 = bounds.getNorthEast() 724 , latOverlaps = (ne2.lat > sw.lat) && (sw2.lat < ne.lat) 725 , lngOverlaps = (ne2.lng > sw.lng) && (sw2.lng < ne.lng); 726 return latOverlaps && lngOverlaps 727 }, 728 toBBoxString: function () { 729 return [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()].join(',') 730 }, 731 equals: function (bounds, maxMargin) { 732 if (!bounds) { 733 return !1 734 } 735 bounds = toLatLngBounds(bounds);
736 return this._southWest.equals(bounds.getSouthWest(), maxMargin) && this._northEast.equals(bounds.getNorthEast(), maxMargin) 737 }, 738 isValid: function () { 739 return !!(this._southWest && this._northEast) 740 } 741 }; 742 function toLatLngBounds(a, b) { 743 if (a instanceof LatLngBounds) { 744 return a 745 } 746 return new LatLngBounds(a, b) 747 } 748 function LatLng(lat, lng, alt) { 749 if (isNaN(lat) || isNaN(lng)) { 750 throw new Error('Invalid LatLng object: (' + lat + ', ' + lng + ')') 751 } 752 this.lat = +lat; 753 this.lng = +lng; 754 if (alt !== undefined) { 755 this.alt = +alt 756 } 757 } 758 LatLng.prototype = { 759 equals: function (obj, maxMargin) { 760 if (!obj) { 761 return !1 762 } 763 obj = toLatLng(obj); 764 var margin = Math.max(Math.abs(this.lat - obj.lat), Math.abs(this.lng - obj.lng)); 765 return margin <= (maxMargin === undefined ? 1.0E-9 : maxMargin) 766 }, 767 toString: function (precision) { 768 return 'LatLng(' + formatNum(this.lat, precision) + ', ' + formatNum(this.lng, precision) + ')' 769 }, 770 distanceTo: function (other) { 771 return Earth.distance(this, toLatLng(other)) 772 }, 773 wrap: function () { 774 return Earth.wrapLatLng(this) 775 }, 776 toBounds: function (sizeInMeters) { 777 var latAccuracy = 180 * sizeInMeters / 40075017 778 , lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat); 779 return toLatLngBounds([this.lat - latAccuracy, this.lng - lngAccuracy], [this.lat + latAccuracy, this.lng + lngAccuracy]) 780 }, 781 clone: function () { 782 return new LatLng(this.lat, this.lng, this.alt) 783 } 784 }; 785 function toLatLng(a, b, c) { 786 if (a instanceof LatLng) { 787 return a 788 } 789 if (isArray(a) && typeof a[0] !== 'object') { 790 if (a.length === 3) { 791 return new LatLng(a[0], a[1], a[2]) 792 } 793 if (a.length === 2) { 794 return new LatLng(a[0], a[1]) 795 } 796 return null 797 } 798 if (a === undefined || a === null) { 799 return a 800 } 801 if (typeof a === 'object' && 'lat' in a) { 802 return new LatLng(a.lat, 'lng' in a ? a.lng : a.lon, a.alt) 803 } 804 if (b === undefined) { 805 return null 806 } 807 return new LatLng(a, b, c) 808 } 809 var CRS = { 810 latLngToPoint: function (latlng, zoom) { 811 var projectedPoint = this.projection.project(latlng) 812 , scale = this.scale(zoom); 813 return this.transformation._transform(projectedPoint, scale) 814 }, 815 pointToLatLng: function (point, zoom) { 816 var scale = this.scale(zoom) 817 , untransformedPoint = this.transformation.untransform(point, scale); 818 return this.projection.unproject(untransformedPoint) 819 }, 820 project: function (latlng) { 821 return this.projection.project(latlng) 822 }, 823 unproject: function (point) { 824 return this.projection.unproject(point) 825 }, 826 scale: function (zoom) { 827 return 256 * Math.pow(2, zoom) 828 }, 829 zoom: function (scale) { 830 return Math.log(scale / 256) / Math.LN2 831 }, 832 getProjectedBounds: function (zoom) { 833 if (this.infinite) { 834 return null 835 } 836 var b = this.projection.bounds 837 , s = this.scale(zoom) 838 , min = this.transformation.transform(b.min, s) 839 , max = this.transformation.transform(b.max, s); 840 return new Bounds(min, max) 841 }, 842 infinite: !1, 843 wrapLatLng: function (latlng) { 844 var lng = this.wrapLng ? wrapNum(latlng.lng, this.wrapLng, !0) : latlng.lng 845 , lat = this.wrapLat ? wrapNum(latlng.lat, this.wrapLat, !0) : latlng.lat 846 , alt = latlng.alt; 847 return new LatLng(lat, lng, alt) 848 }, 849 wrapLatLngBounds: function (bounds) { 850 var center = bounds.getCenter() 851 , newCenter = this.wrapLatLng(center) 852 , latShift = center.lat - newCenter.lat 853 , lngShift = center.lng - newCenter.lng; 854 if (latShift === 0 && lngShift === 0) { 855 return bounds 856 }
857 var sw = bounds.getSouthWest() 858 , ne = bounds.getNorthEast() 859 , newSw = new LatLng(sw.lat - latShift, sw.lng - lngShift) 860 , newNe = new LatLng(ne.lat - latShift, ne.lng - lngShift); 861 return new LatLngBounds(newSw, newNe) 862 } 863 }; 864 var Earth = extend({}, CRS, { 865 wrapLng: [-180, 180], 866 R: 6371000, 867 distance: function (latlng1, latlng2) { 868 var rad = Math.PI / 180 869 , lat1 = latlng1.lat * rad 870 , lat2 = latlng2.lat * rad 871 , sinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2) 872 , sinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2) 873 , a = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon 874 , c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); 875 return this.R * c 876 } 877 }); 878 var SphericalMercator = { 879 R: 6378137, 880 MAX_LATITUDE: 85.0511287798, 881 project: function (latlng) { 882 var d = Math.PI / 180 883 , max = this.MAX_LATITUDE 884 , lat = Math.max(Math.min(max, latlng.lat), -max) 885 , sin = Math.sin(lat * d); 886 return new Point(this.R * latlng.lng * d, this.R * Math.log((1 + sin) / (1 - sin)) / 2) 887 }, 888 unproject: function (point) { 889 var d = 180 / Math.PI; 890 return new LatLng((2 * Math.atan(Math.exp(point.y / this.R)) - (Math.PI / 2)) * d, point.x * d / this.R) 891 }, 892 bounds: (function () { 893 var d = 6378137 * Math.PI; 894 return new Bounds([-d, -d], [d, d]) 895 } 896 )() 897 }; 898 function Transformation(a, b, c, d) { 899 if (isArray(a)) { 900 this._a = a[0]; 901 this._b = a[1]; 902 this._c = a[2]; 903 this._d = a[3]; 904 return 905 } 906 this._a = a; 907 this._b = b; 908 this._c = c; 909 this._d = d 910 } 911 Transformation.prototype = { 912 transform: function (point, scale) { 913 return this._transform(point.clone(), scale) 914 }, 915 _transform: function (point, scale) { 916 scale = scale || 1; 917 point.x = scale * (this._a * point.x + this._b); 918 point.y = scale * (this._c * point.y + this._d); 919 return point 920 }, 921 untransform: function (point, scale) { 922 scale = scale || 1; 923 return new Point((point.x / scale - this._b) / this._a, (point.y / scale - this._d) / this._c) 924 } 925 }; 926 function toTransformation(a, b, c, d) { 927 return new Transformation(a, b, c, d) 928 } 929 var EPSG3857 = extend({}, Earth, { 930 code: 'EPSG:3857', 931 projection: SphericalMercator, 932 transformation: (function () { 933 var scale = 0.5 / (Math.PI * SphericalMercator.R); 934 return toTransformation(scale, 0.5, -scale, 0.5) 935 }()) 936 }); 937 var EPSG900913 = extend({}, EPSG3857, { 938 code: 'EPSG:900913' 939 }); 940 function svgCreate(name) { 941 return document.createElementNS('http://www.w3.org/2000/svg', name) 942 } 943 function pointsToPath(rings, closed) { 944 var str = '', i, j, len, len2, points, p; 945 for (i = 0, 946 len = rings.length; i < len; i++) { 947 points = rings[i]; 948 for (j = 0, 949 len2 = points.length; j < len2; j++) { 950 p = points[j]; 951 str += (j ? 'L' : 'M') + p.x + ' ' + p.y 952 } 953 str += closed ? (svg ? 'z' : 'x') : '' 954 } 955 return str || 'M0 0' 956 } 957 var style$1 = document.documentElement.style; 958 var ie = 'ActiveXObject' in window; 959 var ielt9 = ie && !document.addEventListener; 960 var edge = 'msLaunchUri' in navigator && !('documentMode' in document); 961 var webkit = userAgentContains('webkit'); 962 var android = userAgentContains('android'); 963 var android23 = userAgentContains('android 2') || userAgentContains('android 3'); 964 var webkitVer = parseInt(/WebKit\/([0-9]+)|$/.exec(navigator.userAgent)[1], 10); 965 var androidStock = android && userAgentContains('Google') && webkitVer < 537 && !('AudioNode' in window); 966 var opera = !!window.opera; 967 var chrome = userAgentContains('chrome'); 968 var gecko = userAgentContains('gecko') && !webkit && !opera && !ie; 969 var safari = !chrome && userAgentContains('safari'); 970 var phantom = userAgentContains('phantom'); 971 var opera12 = 'OTransition' in style$1; 972 var win = navigator.platform.indexOf('Win') === 0; 973 var ie3d = ie && ('transition' in style$1); 974 var webkit3d = ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()) && !android23; 975 var gecko3d = 'MozPerspective' in style$1; 976 var any3d = !window.L_DISABLE_3D && (ie3d || webkit3d || gecko3d) && !opera12 && !phantom; 977 var mobile = typeof orientation !== 'undefined' || userAgentContains('mobile'); 978 var mobileWebkit = mobile && webkit; 979 var mobileWebkit3d = mobile && webkit3d; 980 var msPointer = !window.PointerEvent && window.MSPointerEvent; 981 var pointer = !!(window.PointerEvent || msPointer); 982 var touch = !window.L_NO_TOUCH && (pointer || 'ontouchstart' in window || (window.DocumentTouch && document instanceof window.DocumentTouch)); 983 var mobileOpera = mobile && opera; 984 var mobileGecko = mobile && gecko;
985 var retina = (window.devicePixelRatio || (window.screen.deviceXDPI / window.screen.logicalXDPI)) > 1; 986 var canvas = (function () { 987 return !!document.createElement('canvas').getContext 988 }()); 989 var svg = !!(document.createElementNS && svgCreate('svg').createSVGRect); 990 var vml = !svg && (function () { 991 try { 992 var div = document.createElement('div'); 993 div.innerHTML = '<v:shape adj="1"/>'; 994 var shape = div.firstChild; 995 shape.style.behavior = 'url(#default#VML)'; 996 return shape && (typeof shape.adj === 'object') 997 } catch (e) { 998 return !1 999 } 1000 }()); 1001 function userAgentContains(str) { 1002 return navigator.userAgent.toLowerCase().indexOf(str) >= 0 1003 } 1004 var Browser = (Object.freeze || Object)({ 1005 ie: ie, 1006 ielt9: ielt9, 1007 edge: edge, 1008 webkit: webkit, 1009 android: android, 1010 android23: android23, 1011 androidStock: androidStock, 1012 opera: opera, 1013 chrome: chrome, 1014 gecko: gecko, 1015 safari: safari, 1016 phantom: phantom, 1017 opera12: opera12, 1018 win: win, 1019 ie3d: ie3d, 1020 webkit3d: webkit3d, 1021 gecko3d: gecko3d, 1022 any3d: any3d, 1023 mobile: mobile, 1024 mobileWebkit: mobileWebkit, 1025 mobileWebkit3d: mobileWebkit3d, 1026 msPointer: msPointer, 1027 pointer: pointer, 1028 touch: touch, 1029 mobileOpera: mobileOpera, 1030 mobileGecko: mobileGecko, 1031 retina: retina, 1032 canvas: canvas, 1033 svg: svg, 1034 vml: vml 1035 }); 1036 var POINTER_DOWN = msPointer ? 'MSPointerDown' : 'pointerdown'; 1037 var POINTER_MOVE = msPointer ? 'MSPointerMove' : 'pointermove'; 1038 var POINTER_UP = msPointer ? 'MSPointerUp' : 'pointerup'; 1039 var POINTER_CANCEL = msPointer ? 'MSPointerCancel' : 'pointercancel'; 1040 var TAG_WHITE_LIST = ['INPUT', 'SELECT', 'OPTIONS']; 1041 var _pointers = {}; 1042 var _pointerDocListener = !1; 1043 var _pointersCount = 0; 1044 function addPointerListener(obj, type, handler, id) { 1045 if (type === 'touchstart') { 1046 _addPointerStart(obj, handler, id) 1047 } else if (type === 'touchmove') { 1048 _addPointerMove(obj, handler, id) 1049 } else if (type === 'touchend') { 1050 _addPointerEnd(obj, handler, id) 1051 } 1052 return this 1053 } 1054 function removePointerListener(obj, type, id) { 1055 var handler = obj['_leaflet_' + type + id]; 1056 if (type === 'touchstart') { 1057 obj.removeEventListener(POINTER_DOWN, handler, !1) 1058 } else if (type === 'touchmove') { 1059 obj.removeEventListener(POINTER_MOVE, handler, !1) 1060 } else if (type === 'touchend') { 1061 obj.removeEventListener(POINTER_UP, handler, !1); 1062 obj.removeEventListener(POINTER_CANCEL, handler, !1) 1063 } 1064 return this 1065 } 1066 function _addPointerStart(obj, handler, id) { 1067 var onDown = bind(function (e) { 1068 if (e.pointerType !== 'mouse' && e.MSPOINTER_TYPE_MOUSE && e.pointerType !== e.MSPOINTER_TYPE_MOUSE) { 1069 if (TAG_WHITE_LIST.indexOf(e.target.tagName) < 0) { 1070 preventDefault(e) 1071 } else { 1072 return 1073 } 1074 } 1075 _handlePointer(e, handler) 1076 }); 1077 obj['_leaflet_touchstart' + id] = onDown; 1078 obj.addEventListener(POINTER_DOWN, onDown, !1); 1079 if (!_pointerDocListener) { 1080 document.documentElement.addEventListener(POINTER_DOWN, _globalPointerDown, !0); 1081 document.documentElement.addEventListener(POINTER_MOVE, _globalPointerMove, !0); 1082 document.documentElement.addEventListener(POINTER_UP, _globalPointerUp, !0); 1083 document.documentElement.addEventListener(POINTER_CANCEL, _globalPointerUp, !0); 1084 _pointerDocListener = !0 1085 } 1086 } 1087 function _globalPointerDown(e) { 1088 _pointers[e.pointerId] = e; 1089 _pointersCount++ 1090 } 1091 function _globalPointerMove(e) { 1092 if (_pointers[e.pointerId]) { 1093 _pointers[e.pointerId] = e 1094 } 1095 } 1096 function _globalPointerUp(e) { 1097 delete _pointers[e.pointerId]; 1098 _pointersCount-- 1099 } 1100 function _handlePointer(e, handler) { 1101 e.touches = []; 1102 for (var i in _pointers) { 1103 e.touches.push(_pointers[i]) 1104 } 1105 e.changedTouches = [e]; 1106 handler(e) 1107 } 1108 function _addPointerMove(obj, handler, id) { 1109 var onMove = function (e) { 1110 if ((e.pointerType === e.MSPOINTER_TYPE_MOUSE || e.pointerType === 'mouse') && e.buttons === 0) { 1111 return 1112 } 1113 _handlePointer(e, handler) 1114 }; 1115 obj['_leaflet_touchmove' + id] = onMove;
1116 obj.addEventListener(POINTER_MOVE, onMove, !1) 1117 } 1118 function _addPointerEnd(obj, handler, id) { 1119 var onUp = function (e) { 1120 _handlePointer(e, handler) 1121 }; 1122 obj['_leaflet_touchend' + id] = onUp; 1123 obj.addEventListener(POINTER_UP, onUp, !1); 1124 obj.addEventListener(POINTER_CANCEL, onUp, !1) 1125 } 1126 var _touchstart = msPointer ? 'MSPointerDown' : pointer ? 'pointerdown' : 'touchstart'; 1127 var _touchend = msPointer ? 'MSPointerUp' : pointer ? 'pointerup' : 'touchend'; 1128 var _pre = '_leaflet_'; 1129 function addDoubleTapListener(obj, handler, id) { 1130 var last, touch$$1, doubleTap = !1, delay = 250; 1131 function onTouchStart(e) { 1132 var count; 1133 if (pointer) { 1134 if ((!edge) || e.pointerType === 'mouse') { 1135 return 1136 } 1137 count = _pointersCount 1138 } else { 1139 count = e.touches.length 1140 } 1141 if (count > 1) { 1142 return 1143 } 1144 var now = Date.now() 1145 , delta = now - (last || now); 1146 touch$$1 = e.touches ? e.touches[0] : e; 1147 doubleTap = (delta > 0 && delta <= delay); 1148 last = now 1149 } 1150 function onTouchEnd(e) { 1151 if (doubleTap && !touch$$1.cancelBubble) { 1152 if (pointer) { 1153 if ((!edge) || e.pointerType === 'mouse') { 1154 return 1155 } 1156 var newTouch = {}, prop, i; 1157 for (i in touch$$1) { 1158 prop = touch$$1[i]; 1159 newTouch[i] = prop && prop.bind ? prop.bind(touch$$1) : prop 1160 } 1161 touch$$1 = newTouch 1162 } 1163 touch$$1.type = 'dblclick'; 1164 handler(touch$$1); 1165 last = null 1166 } 1167 } 1168 obj[_pre + _touchstart + id] = onTouchStart; 1169 obj[_pre + _touchend + id] = onTouchEnd; 1170 obj[_pre + 'dblclick' + id] = handler; 1171 obj.addEventListener(_touchstart, onTouchStart, !1); 1172 obj.addEventListener(_touchend, onTouchEnd, !1); 1173 obj.addEventListener('dblclick', handler, !1); 1174 return this 1175 } 1176 function removeDoubleTapListener(obj, id) { 1177 var touchstart = obj[_pre + _touchstart + id] 1178 , touchend = obj[_pre + _touchend + id] 1179 , dblclick = obj[_pre + 'dblclick' + id]; 1180 obj.removeEventListener(_touchstart, touchstart, !1); 1181 obj.removeEventListener(_touchend, touchend, !1); 1182 if (!edge) { 1183 obj.removeEventListener('dblclick', dblclick, !1) 1184 } 1185 return this 1186 } 1187 var TRANSFORM = testProp(['transform', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform']); 1188 var TRANSITION = testProp(['webkitTransition', 'transition', 'OTransition', 'MozTransition', 'msTransition']); 1189 var TRANSITION_END = TRANSITION === 'webkitTransition' || TRANSITION === 'OTransition' ? TRANSITION + 'End' : 'transitionend'; 1190 function get(id) { 1191 return typeof id === 'string' ? document.getElementById(id) : id 1192 } 1193 function getStyle(el, style) { 1194 var value = el.style[style] || (el.currentStyle && el.currentStyle[style]); 1195 if ((!value || value === 'auto') && document.defaultView) { 1196 var css = document.defaultView.getComputedStyle(el, null); 1197 value = css ? css[style] : null 1198 } 1199 return value === 'auto' ? null : value 1200 } 1201 function create$1(tagName, className, container) { 1202 var el = document.createElement(tagName); 1203 el.className = className || ''; 1204 if (container) { 1205 container.appendChild(el) 1206 } 1207 return el 1208 } 1209 function remove(el) { 1210 var parent = el.parentNode; 1211 if (parent) { 1212 parent.removeChild(el) 1213 } 1214 } 1215 function empty(el) { 1216 while (el.firstChild) { 1217 el.removeChild(el.firstChild) 1218 } 1219 } 1220 function toFront(el) { 1221 var parent = el.parentNode; 1222 if (parent.lastChild !== el) { 1223 parent.appendChild(el) 1224 } 1225 } 1226 function toBack(el) { 1227 var parent = el.parentNode; 1228 if (parent.firstChild !== el) { 1229 parent.insertBefore(el, parent.firstChild) 1230 } 1231 } 1232 function hasClass(el, name) { 1233 if (el.classList !== undefined) { 1234 return el.classList.contains(name) 1235 } 1236 var className = getClass(el); 1237 return className.length > 0 && new RegExp('(^|\\s)' + name + '(\\s|$)').test(className) 1238 } 1239 function addClass(el, name) { 1240 if (el.classList !== undefined) { 1241 var classes = splitWords(name); 1242 for (var i = 0, len = classes.length; i < len; i++) { 1243 el.classList.add(classes[i]) 1244 } 1245 } else if (!hasClass(el, name)) { 1246 var className = getClass(el); 1247 setClass(el, (className ? className + ' ' : '') + name) 1248 } 1249 } 1250 function removeClass(el, name) { 1251 if (el.classList !== undefined) { 1252 el.classList.remove(name) 1253 } else { 1254 setClass(el, trim((' ' + getClass(el) + ' ').replace(' ' + name + ' ', ' '))) 1255 } 1256 } 1257 function setClass(el, name) { 1258 if (el.className.baseVal === undefined) { 1259 el.className = name 1260 } else { 1261 el.className.baseVal = name 1262 } 1263 } 1264 function getClass(el) { 1265 return el.className.baseVal === undefined ? el.className : el.className.baseVal 1266 } 1267 function setOpacity(el, value) { 1268 if ('opacity' in el.style) { 1269 el.style.opacity = value 1270 } else if ('filter' in el.style) { 1271 _setOpacityIE(el, value) 1272 } 1273 } 1274 function _setOpacityIE(el, value) { 1275 var filter = !1 1276 , filterName = 'DXImageTransform.Microsoft.Alpha'; 1277 try { 1278 filter = el.filters.item(filterName) 1279 } catch (e) { 1280 if (value === 1) { 1281 return 1282 } 1283 } 1284 value = Math.round(value * 100); 1285 if (filter) { 1286 filter.Enabled = (value !== 100); 1287 filter.Opacity = value 1288 } else { 1289 el.style.filter += ' progid:' + filterName + '(opacity=' + value + ')' 1290 } 1291 } 1292 function testProp(props) { 1293 var style = document.documentElement.style; 1294 for (var i = 0; i < props.length; i++) { 1295 if (props[i] in style) { 1296 return props[i] 1297 } 1298 } 1299 return !1 1300 } 1301 function setTransform(el, offset, scale) { 1302 var pos = offset || new Point(0, 0); 1303 el.style[TRANSFORM] = (ie3d ? 'translate(' + pos.x + 'px,' + pos.y + 'px)' : 'translate3d(' + pos.x + 'px,' + pos.y + 'px,0)') + (scale ? ' scale(' + scale + ')' : '') 1304 } 1305 function setPosition(el, point) { 1306 el._leaflet_pos = point; 1307 if (any3d) { 1308 setTransform(el, point) 1309 } else { 1310 el.style.left = point.x + 'px'; 1311 el.style.top = point.y + 'px' 1312 } 1313 } 1314 function getPosition(el) { 1315 return el._leaflet_pos || new Point(0, 0) 1316 } 1317 var disableTextSelection; 1318 var enableTextSelection; 1319 var _userSelect; 1320 if ('onselectstart' in document) { 1321 disableTextSelection = function () { 1322 on(window, 'selectstart', preventDefault) 1323 } 1324 ; 1325 enableTextSelection = function () { 1326 off(window, 'selectstart', preventDefault) 1327 } 1328 } else { 1329 var userSelectProperty = testProp(['userSelect', 'WebkitUserSelect', 'OUserSelect', 'MozUserSelect', 'msUserSelect']); 1330 disableTextSelection = function () { 1331 if (userSelectProperty) { 1332 var style = document.documentElement.style; 1333 _userSelect = style[userSelectProperty]; 1334 style[userSelectProperty] = 'none' 1335 } 1336 } 1337 ; 1338 enableTextSelection = function () { 1339 if (userSelectProperty) { 1340 document.documentElement.style[userSelectProperty] = _userSelect; 1341 _userSelect = undefined 1342 } 1343 } 1344 } 1345 function disableImageDrag() { 1346 on(window, 'dragstart', preventDefault) 1347 } 1348 function enableImageDrag() { 1349 off(window, 'dragstart', preventDefault) 1350 } 1351 var _outlineElement; 1352 var _outlineStyle; 1353 function preventOutline(element) { 1354 while (element.tabIndex === -1) { 1355 element = element.parentNode 1356 } 1357 if (!element.style) { 1358 return 1359 } 1360 restoreOutline(); 1361 _outlineElement = element; 1362 _outlineStyle = element.style.outline; 1363 element.style.outline = 'none'; 1364 on(window, 'keydown', restoreOutline) 1365 } 1366 function restoreOutline() { 1367 if (!_outlineElement) { 1368 return 1369 } 1370 _outlineElement.style.outline = _outlineStyle; 1371 _outlineElement = undefined; 1372 _outlineStyle = undefined; 1373 off(window, 'keydown', restoreOutline) 1374 } 1375 function getSizedParentNode(element) { 1376 do { 1377 element = element.parentNode 1378 } while ((!element.offsetWidth || !element.offsetHeight) && element !== document.body); return element 1379 } 1380 function getScale(element) { 1381 var rect = element.getBoundingClientRect(); 1382 return { 1383 x: rect.width / element.offsetWidth || 1, 1384 y: rect.height / element.offsetHeight || 1, 1385 boundingClientRect: rect 1386 } 1387 } 1388 var DomUtil = (Object.freeze || Object)({ 1389 TRANSFORM: TRANSFORM, 1390 TRANSITION: TRANSITION, 1391 TRANSITION_END: TRANSITION_END, 1392 get: get, 1393 getStyle: getStyle, 1394 create: create$1, 1395 remove: remove, 1396 empty: empty, 1397 toFront: toFront, 1398 toBack: toBack, 1399 hasClass: hasClass, 1400 addClass: addClass, 1401 removeClass: removeClass, 1402 setClass: setClass, 1403 getClass: getClass, 1404 setOpacity: setOpacity, 1405 testProp: testProp, 1406 setTransform: setTransform, 1407 setPosition: setPosition, 1408 getPosition: getPosition, 1409 disableTextSelection: disableTextSelection, 1410 enableTextSelection: enableTextSelection, 1411 disableImageDrag: disableImageDrag, 1412 enableImageDrag: enableImageDrag, 1413 preventOutline: preventOutline, 1414 restoreOutline: restoreOutline, 1415 getSizedParentNode: getSizedParentNode, 1416 getScale: getScale 1417 }); 1418 function on(obj, types, fn, context) { 1419 if (typeof types === 'object') { 1420 for (var type in types) { 1421 addOne(obj, type, types[type], fn) 1422 } 1423 } else { 1424 types = splitWords(types); 1425 for (var i = 0, len = types.length; i < len; i++) { 1426 addOne(obj, types[i], fn, context) 1427 } 1428 } 1429 return this 1430 } 1431 var eventsKey = '_leaflet_events'; 1432 function off(obj, types, fn, context) { 1433 if (typeof types === 'object') { 1434 for (var type in types) { 1435 removeOne(obj, type, types[type], fn) 1436 } 1437 } else if (types) { 1438 types = splitWords(types); 1439 for (var i = 0, len = types.length; i < len; i++) { 1440 removeOne(obj, types[i], fn, context) 1441 } 1442 } else { 1443 for (var j in obj[eventsKey]) { 1444 removeOne(obj, j, obj[eventsKey][j]) 1445 } 1446 delete obj[eventsKey] 1447 } 1448 return this 1449 } 1450 function addOne(obj, type, fn, context) { 1451 var id = type + stamp(fn) + (context ? '_' + stamp(context) : ''); 1452 if (obj[eventsKey] && obj[eventsKey][id]) { 1453 return this 1454 } 1455 var handler = function (e) {
1456 return fn.call(context || obj, e || window.event) 1457 }; 1458 var originalHandler = handler; 1459 if (pointer && type.indexOf('touch') === 0) { 1460 addPointerListener(obj, type, handler, id) 1461 } else if (touch && (type === 'dblclick') && addDoubleTapListener && !(pointer && chrome)) { 1462 addDoubleTapListener(obj, handler, id) 1463 } else if ('addEventListener' in obj) { 1464 if (type === 'mousewheel') { 1465 obj.addEventListener('onwheel' in obj ? 'wheel' : 'mousewheel', handler, !1) 1466 } else if ((type === 'mouseenter') || (type === 'mouseleave')) { 1467 handler = function (e) { 1468 e = e || window.event; 1469 if (isExternalTarget(obj, e)) { 1470 originalHandler(e) 1471 } 1472 } 1473 ; 1474 obj.addEventListener(type === 'mouseenter' ? 'mouseover' : 'mouseout', handler, !1) 1475 } else { 1476 if (type === 'click' && android) { 1477 handler = function (e) { 1478 filterClick(e, originalHandler) 1479 } 1480 } 1481 obj.addEventListener(type, handler, !1) 1482 } 1483 } else if ('attachEvent' in obj) { 1484 obj.attachEvent('on' + type, handler) 1485 } 1486 obj[eventsKey] = obj[eventsKey] || {}; 1487 obj[eventsKey][id] = handler 1488 } 1489 function removeOne(obj, type, fn, context) { 1490 var id = type + stamp(fn) + (context ? '_' + stamp(context) : '') 1491 , handler = obj[eventsKey] && obj[eventsKey][id]; 1492 if (!handler) { 1493 return this 1494 } 1495 if (pointer && type.indexOf('touch') === 0) { 1496 removePointerListener(obj, type, id) 1497 } else if (touch && (type === 'dblclick') && removeDoubleTapListener && !(pointer && chrome)) { 1498 removeDoubleTapListener(obj, id) 1499 } else if ('removeEventListener' in obj) { 1500 if (type === 'mousewheel') { 1501 obj.removeEventListener('onwheel' in obj ? 'wheel' : 'mousewheel', handler, !1) 1502 } else { 1503 obj.removeEventListener(type === 'mouseenter' ? 'mouseover' : type === 'mouseleave' ? 'mouseout' : type, handler, !1) 1504 } 1505 } else if ('detachEvent' in obj) { 1506 obj.detachEvent('on' + type, handler) 1507 } 1508 obj[eventsKey][id] = null 1509 } 1510 function stopPropagation(e) { 1511 if (e.stopPropagation) { 1512 e.stopPropagation() 1513 } else if (e.originalEvent) { 1514 e.originalEvent._stopped = !0 1515 } else { 1516 e.cancelBubble = !0 1517 } 1518 skipped(e); 1519 return this 1520 } 1521 function disableScrollPropagation(el) { 1522 addOne(el, 'mousewheel', stopPropagation); 1523 return this 1524 } 1525 function disableClickPropagation(el) { 1526 on(el, 'mousedown touchstart dblclick', stopPropagation); 1527 addOne(el, 'click', fakeStop); 1528 return this 1529 } 1530 function preventDefault(e) { 1531 if (e.preventDefault) { 1532 e.preventDefault() 1533 } else { 1534 e.returnValue = !1 1535 } 1536 return this 1537 } 1538 function stop(e) { 1539 preventDefault(e); 1540 stopPropagation(e); 1541 return this 1542 } 1543 function getMousePosition(e, container) { 1544 if (!container) { 1545 return new Point(e.clientX, e.clientY) 1546 } 1547 var scale = getScale(container) 1548 , offset = scale.boundingClientRect; 1549 return new Point((e.clientX - offset.left) / scale.x - container.clientLeft, (e.clientY - offset.top) / scale.y - container.clientTop) 1550 } 1551 var wheelPxFactor = (win && chrome) ? 2 * window.devicePixelRatio : gecko ? window.devicePixelRatio : 1; 1552 function getWheelDelta(e) { 1553 return (edge) ? e.wheelDeltaY / 2 : (e.deltaY && e.deltaMode === 0) ? -e.deltaY / wheelPxFactor : (e.deltaY && e.deltaMode === 1) ? -e.deltaY * 20 : (e.deltaY && e.deltaMode === 2) ? -e.deltaY * 60 : (e.deltaX || e.deltaZ) ? 0 : e.wheelDelta ? (e.wheelDeltaY || e.wheelDelta) / 2 : (e.detail && Math.abs(e.detail) < 32765) ? -e.detail * 20 : e.detail ? e.detail / -32765 * 60 : 0 1554 } 1555 var skipEvents = {}; 1556 function fakeStop(e) { 1557 skipEvents[e.type] = !0 1558 } 1559 function skipped(e) { 1560 var events = skipEvents[e.type]; 1561 skipEvents[e.type] = !1; 1562 return events 1563 } 1564 function isExternalTarget(el, e) { 1565 var related = e.relatedTarget; 1566 if (!related) { 1567 return !0 1568 } 1569 try { 1570 while (related && (related !== el)) { 1571 related = related.parentNode 1572 } 1573 } catch (err) { 1574 return !1 1575 } 1576 return (related !== el) 1577 } 1578 var lastClick; 1579 function filterClick(e, handler) { 1580 var timeStamp = (e.timeStamp || (e.originalEvent && e.originalEvent.timeStamp))
1581 , elapsed = lastClick && (timeStamp - lastClick); 1582 if ((elapsed && elapsed > 100 && elapsed < 500) || (e.target._simulatedClick && !e._simulated)) { 1583 stop(e); 1584 return 1585 } 1586 lastClick = timeStamp; 1587 handler(e) 1588 } 1589 var DomEvent = (Object.freeze || Object)({ 1590 on: on, 1591 off: off, 1592 stopPropagation: stopPropagation, 1593 disableScrollPropagation: disableScrollPropagation, 1594 disableClickPropagation: disableClickPropagation, 1595 preventDefault: preventDefault, 1596 stop: stop, 1597 getMousePosition: getMousePosition, 1598 getWheelDelta: getWheelDelta, 1599 fakeStop: fakeStop, 1600 skipped: skipped, 1601 isExternalTarget: isExternalTarget, 1602 addListener: on, 1603 removeListener: off 1604 }); 1605 var PosAnimation = Evented.extend({ 1606 run: function (el, newPos, duration, easeLinearity) { 1607 this.stop(); 1608 this._el = el; 1609 this._inProgress = !0; 1610 this._duration = duration || 0.25; 1611 this._easeOutPower = 1 / Math.max(easeLinearity || 0.5, 0.2); 1612 this._startPos = getPosition(el); 1613 this._offset = newPos.subtract(this._startPos); 1614 this._startTime = +new Date(); 1615 this.fire('start'); 1616 this._animate() 1617 }, 1618 stop: function () { 1619 if (!this._inProgress) { 1620 return 1621 } 1622 this._step(!0); 1623 this._complete() 1624 }, 1625 _animate: function () { 1626 this._animId = requestAnimFrame(this._animate, this); 1627 this._step() 1628 }, 1629 _step: function (round) { 1630 var elapsed = (+new Date()) - this._startTime 1631 , duration = this._duration * 1000; 1632 if (elapsed < duration) { 1633 this._runFrame(this._easeOut(elapsed / duration), round) 1634 } else { 1635 this._runFrame(1); 1636 this._complete() 1637 } 1638 }, 1639 _runFrame: function (progress, round) { 1640 var pos = this._startPos.add(this._offset.multiplyBy(progress)); 1641 if (round) { 1642 pos._round() 1643 } 1644 setPosition(this._el, pos); 1645 this.fire('step') 1646 }, 1647 _complete: function () { 1648 cancelAnimFrame(this._animId); 1649 this._inProgress = !1; 1650 this.fire('end') 1651 }, 1652 _easeOut: function (t) { 1653 return 1 - Math.pow(1 - t, this._easeOutPower) 1654 } 1655 }); 1656 var Map = Evented.extend({ 1657 options: { 1658 crs: EPSG3857, 1659 center: undefined, 1660 zoom: undefined, 1661 minZoom: undefined, 1662 maxZoom: undefined, 1663 layers: [], 1664 maxBounds: undefined, 1665 renderer: undefined, 1666 zoomAnimation: !0, 1667 zoomAnimationThreshold: 4, 1668 fadeAnimation: !0, 1669 markerZoomAnimation: !0, 1670 transform3DLimit: 8388608, 1671 zoomSnap: 1, 1672 zoomDelta: 1, 1673 trackResize: !0 1674 }, 1675 initialize: function (id, options) { 1676 options = setOptions(this, options); 1677 this._initContainer(id); 1678 this._initLayout(); 1679 this._onResize = bind(this._onResize, this); 1680 this._initEvents(); 1681 if (options.maxBounds) { 1682 this.setMaxBounds(options.maxBounds) 1683 } 1684 if (options.zoom !== undefined) { 1685 this._zoom = this._limitZoom(options.zoom) 1686 } 1687 if (options.center && options.zoom !== undefined) { 1688 this.setView(toLatLng(options.center), options.zoom, { 1689 reset: !0 1690 }) 1691 } 1692 this._handlers = []; 1693 this._layers = {}; 1694 this._zoomBoundLayers = {}; 1695 this._sizeChanged = !0; 1696 this.callInitHooks(); 1697 this._zoomAnimated = TRANSITION && any3d && !mobileOpera && this.options.zoomAnimation; 1698 if (this._zoomAnimated) { 1699 this._createAnimProxy(); 1700 on(this._proxy, TRANSITION_END, this._catchTransitionEnd, this) 1701 } 1702 this._addLayers(this.options.layers) 1703 },
1704 setView: function (center, zoom, options) { 1705 zoom = zoom === undefined ? this._zoom : this._limitZoom(zoom); 1706 center = this._limitCenter(toLatLng(center), zoom, this.options.maxBounds); 1707 options = options || {}; 1708 this._stop(); 1709 if (this._loaded && !options.reset && options !== !0) { 1710 if (options.animate !== undefined) { 1711 options.zoom = extend({ 1712 animate: options.animate 1713 }, options.zoom); 1714 options.pan = extend({ 1715 animate: options.animate, 1716 duration: options.duration 1717 }, options.pan) 1718 } 1719 var moved = (this._zoom !== zoom) ? this._tryAnimatedZoom && this._tryAnimatedZoom(center, zoom, options.zoom) : this._tryAnimatedPan(center, options.pan); 1720 if (moved) { 1721 clearTimeout(this._sizeTimer); 1722 return this 1723 } 1724 } 1725 this._resetView(center, zoom); 1726 return this 1727 }, 1728 setZoom: function (zoom, options) { 1729 if (!this._loaded) { 1730 this._zoom = zoom; 1731 return this 1732 } 1733 return this.setView(this.getCenter(), zoom, { 1734 zoom: options 1735 }) 1736 }, 1737 zoomIn: function (delta, options) { 1738 delta = delta || (any3d ? this.options.zoomDelta : 1); 1739 return this.setZoom(this._zoom + delta, options) 1740 }, 1741 zoomOut: function (delta, options) { 1742 delta = delta || (any3d ? this.options.zoomDelta : 1); 1743 return this.setZoom(this._zoom - delta, options) 1744 }, 1745 setZoomAround: function (latlng, zoom, options) { 1746 var scale = this.getZoomScale(zoom) 1747 , viewHalf = this.getSize().divideBy(2) 1748 , containerPoint = latlng instanceof Point ? latlng : this.latLngToContainerPoint(latlng) 1749 , centerOffset = containerPoint.subtract(viewHalf).multiplyBy(1 - 1 / scale) 1750 , newCenter = this.containerPointToLatLng(viewHalf.add(centerOffset)); 1751 return this.setView(newCenter, zoom, { 1752 zoom: options 1753 }) 1754 }, 1755 _getBoundsCenterZoom: function (bounds, options) { 1756 options = options || {}; 1757 bounds = bounds.getBounds ? bounds.getBounds() : toLatLngBounds(bounds); 1758 var paddingTL = toPoint(options.paddingTopLeft || options.padding || [0, 0]) 1759 , paddingBR = toPoint(options.paddingBottomRight || options.padding || [0, 0]) 1760 , zoom = this.getBoundsZoom(bounds, !1, paddingTL.add(paddingBR)); 1761 zoom = (typeof options.maxZoom === 'number') ? Math.min(options.maxZoom, zoom) : zoom; 1762 if (zoom === Infinity) { 1763 return { 1764 center: bounds.getCenter(), 1765 zoom: zoom 1766 } 1767 } 1768 var paddingOffset = paddingBR.subtract(paddingTL).divideBy(2)
1769 , swPoint = this.project(bounds.getSouthWest(), zoom) 1770 , nePoint = this.project(bounds.getNorthEast(), zoom) 1771 , center = this.unproject(swPoint.add(nePoint).divideBy(2).add(paddingOffset), zoom); 1772 return { 1773 center: center, 1774 zoom: zoom 1775 } 1776 }, 1777 fitBounds: function (bounds, options) { 1778 bounds = toLatLngBounds(bounds); 1779 if (!bounds.isValid()) { 1780 throw new Error('Bounds are not valid.') 1781 } 1782 var target = this._getBoundsCenterZoom(bounds, options); 1783 return this.setView(target.center, target.zoom, options) 1784 }, 1785 fitWorld: function (options) { 1786 return this.fitBounds([[-90, -180], [90, 180]], options) 1787 }, 1788 panTo: function (center, options) { 1789 return this.setView(center, this._zoom, { 1790 pan: options 1791 }) 1792 }, 1793 panBy: function (offset, options) { 1794 offset = toPoint(offset).round(); 1795 options = options || {}; 1796 if (!offset.x && !offset.y) { 1797 return this.fire('moveend') 1798 } 1799 if (options.animate !== !0 && !this.getSize().contains(offset)) { 1800 this._resetView(this.unproject(this.project(this.getCenter()).add(offset)), this.getZoom()); 1801 return this 1802 } 1803 if (!this._panAnim) { 1804 this._panAnim = new PosAnimation(); 1805 this._panAnim.on({ 1806 'step': this._onPanTransitionStep, 1807 'end': this._onPanTransitionEnd 1808 }, this) 1809 } 1810 if (!options.noMoveStart) { 1811 this.fire('movestart') 1812 } 1813 if (options.animate !== !1) { 1814 addClass(this._mapPane, 'leaflet-pan-anim'); 1815 var newPos = this._getMapPanePos().subtract(offset).round(); 1816 this._panAnim.run(this._mapPane, newPos, options.duration || 0.25, options.easeLinearity) 1817 } else { 1818 this._rawPanBy(offset); 1819 this.fire('move').fire('moveend') 1820 } 1821 return this 1822 }, 1823 flyTo: function (targetCenter, targetZoom, options) { 1824 options = options || {}; 1825 if (options.animate === !1 || !any3d) { 1826 return this.setView(targetCenter, targetZoom, options) 1827 } 1828 this._stop(); 1829 var from = this.project(this.getCenter()) 1830 , to = this.project(targetCenter) 1831 , size = this.getSize() 1832 , startZoom = this._zoom; 1833 targetCenter = toLatLng(targetCenter); 1834 targetZoom = targetZoom === undefined ? startZoom : targetZoom; 1835 var w0 = Math.max(size.x, size.y) 1836 , w1 = w0 * this.getZoomScale(startZoom, targetZoom) 1837 , u1 = (to.distanceTo(from)) || 1 1838 , rho = 1.42 1839 , rho2 = rho * rho; 1840 function r(i) { 1841 var s1 = i ? -1 : 1 1842 , s2 = i ? w1 : w0 1843 , t1 = w1 * w1 - w0 * w0 + s1 * rho2 * rho2 * u1 * u1 1844 , b1 = 2 * s2 * rho2 * u1 1845 , b = t1 / b1 1846 , sq = Math.sqrt(b * b + 1) - b; 1847 var log = sq < 0.000000001 ? -18 : Math.log(sq); 1848 return log 1849 } 1850 function sinh(n) { 1851 return (Math.exp(n) - Math.exp(-n)) / 2 1852 } 1853 function cosh(n) { 1854 return (Math.exp(n) + Math.exp(-n)) / 2 1855 } 1856 function tanh(n) { 1857 return sinh(n) / cosh(n) 1858 } 1859 var r0 = r(0); 1860 function w(s) { 1861 return w0 * (cosh(r0) / cosh(r0 + rho * s)) 1862 } 1863 function u(s) { 1864 return w0 * (cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2 1865 } 1866 function easeOut(t) { 1867 return 1 - Math.pow(1 - t, 1.5) 1868 } 1869 var start = Date.now() 1870 , S = (r(1) - r0) / rho 1871 , duration = options.duration ? 1000 * options.duration : 1000 * S * 0.8; 1872 function frame() { 1873 var t = (Date.now() - start) / duration 1874 , s = easeOut(t) * S; 1875 if (t <= 1) { 1876 this._flyToFrame = requestAnimFrame(frame, this); 1877 this._move(this.unproject(from.add(to.subtract(from).multiplyBy(u(s) / u1)), startZoom), this.getScaleZoom(w0 / w(s), startZoom), { 1878 flyTo: !0 1879 }) 1880 } else { 1881 this._move(targetCenter, targetZoom)._moveEnd(!0) 1882 } 1883 } 1884 this._moveStart(!0, options.noMoveStart); 1885 frame.call(this); 1886 return this 1887 }, 1888 flyToBounds: function (bounds, options) { 1889 var target = this._getBoundsCenterZoom(bounds, options); 1890 return this.flyTo(target.center, target.zoom, options) 1891 },
1892 setMaxBounds: function (bounds) { 1893 bounds = toLatLngBounds(bounds); 1894 if (!bounds.isValid()) { 1895 this.options.maxBounds = null; 1896 return this.off('moveend', this._panInsideMaxBounds) 1897 } else if (this.options.maxBounds) { 1898 this.off('moveend', this._panInsideMaxBounds) 1899 } 1900 this.options.maxBounds = bounds; 1901 if (this._loaded) { 1902 this._panInsideMaxBounds() 1903 } 1904 return this.on('moveend', this._panInsideMaxBounds) 1905 }, 1906 setMinZoom: function (zoom) { 1907 var oldZoom = this.options.minZoom; 1908 this.options.minZoom = zoom; 1909 if (this._loaded && oldZoom !== zoom) { 1910 this.fire('zoomlevelschange'); 1911 if (this.getZoom() < this.options.minZoom) { 1912 return this.setZoom(zoom) 1913 } 1914 } 1915 return this 1916 }, 1917 setMaxZoom: function (zoom) { 1918 var oldZoom = this.options.maxZoom; 1919 this.options.maxZoom = zoom; 1920 if (this._loaded && oldZoom !== zoom) { 1921 this.fire('zoomlevelschange'); 1922 if (this.getZoom() > this.options.maxZoom) { 1923 return this.setZoom(zoom) 1924 } 1925 } 1926 return this 1927 }, 1928 panInsideBounds: function (bounds, options) { 1929 this._enforcingBounds = !0; 1930 var center = this.getCenter() 1931 , newCenter = this._limitCenter(center, this._zoom, toLatLngBounds(bounds)); 1932 if (!center.equals(newCenter)) { 1933 this.panTo(newCenter, options) 1934 } 1935 this._enforcingBounds = !1; 1936 return this 1937 }, 1938 invalidateSize: function (options) { 1939 if (!this._loaded) { 1940 return this 1941 } 1942 options = extend({ 1943 animate: !1, 1944 pan: !0 1945 }, options === !0 ? { 1946 animate: !0 1947 } : options); 1948 var oldSize = this.getSize(); 1949 this._sizeChanged = !0; 1950 this._lastCenter = null; 1951 var newSize = this.getSize() 1952 , oldCenter = oldSize.divideBy(2).round() 1953 , newCenter = newSize.divideBy(2).round() 1954 , offset = oldCenter.subtract(newCenter); 1955 if (!offset.x && !offset.y) { 1956 return this 1957 } 1958 if (options.animate && options.pan) { 1959 this.panBy(offset) 1960 } else { 1961 if (options.pan) { 1962 this._rawPanBy(offset) 1963 } 1964 this.fire('move'); 1965 if (options.debounceMoveend) { 1966 clearTimeout(this._sizeTimer); 1967 this._sizeTimer = setTimeout(bind(this.fire, this, 'moveend'), 200) 1968 } else { 1969 this.fire('moveend') 1970 } 1971 } 1972 return this.fire('resize', { 1973 oldSize: oldSize, 1974 newSize: newSize 1975 }) 1976 }, 1977 stop: function () { 1978 this.setZoom(this._limitZoom(this._zoom)); 1979 if (!this.options.zoomSnap) { 1980 this.fire('viewreset') 1981 } 1982 return this._stop() 1983 }, 1984 locate: function (options) { 1985 options = this._locateOptions = extend({ 1986 timeout: 10000, 1987 watch: !1 1988 }, options); 1989 if (!('geolocation' in navigator)) { 1990 this._handleGeolocationError({ 1991 code: 0, 1992 message: 'Geolocation not supported.' 1993 }); 1994 return this 1995 } 1996 var onResponse = bind(this._handleGeolocationResponse, this) 1997 , onError = bind(this._handleGeolocationError, this); 1998 if (options.watch) { 1999 this._locationWatchId = navigator.geolocation.watchPosition(onResponse, onError, options) 2000 } else { 2001 navigator.geolocation.getCurrentPosition(onResponse, onError, options) 2002 } 2003 return this 2004 }, 2005 stopLocate: function () { 2006 if (navigator.geolocation && navigator.geolocation.clearWatch) { 2007 navigator.geolocation.clearWatch(this._locationWatchId) 2008 } 2009 if (this._locateOptions) { 2010 this._locateOptions.setView = !1 2011 } 2012 return this 2013 }, 2014 _handleGeolocationError: function (error) { 2015 var c = error.code 2016 , message = error.message || (c === 1 ? 'permission denied' : (c === 2 ? 'position unavailable' : 'timeout')); 2017 if (this._locateOptions.setView && !this._loaded) { 2018 this.fitWorld() 2019 } 2020 this.fire('locationerror', { 2021 code: c, 2022 message: 'Geolocation error: ' + message + '.' 2023 }) 2024 }, 2025 _handleGeolocationResponse: function (pos) { 2026 var lat = pos.coords.latitude 2027 , lng = pos.coords.longitude 2028 , latlng = new LatLng(lat, lng) 2029 , bounds = latlng.toBounds(pos.coords.accuracy * 2) 2030 , options = this._locateOptions; 2031 if (options.setView) { 2032 var zoom = this.getBoundsZoom(bounds); 2033 this.setView(latlng, options.maxZoom ? Math.min(zoom, options.maxZoom) : zoom) 2034 } 2035 var data = { 2036 latlng: latlng,
2037 bounds: bounds, 2038 timestamp: pos.timestamp 2039 }; 2040 for (var i in pos.coords) { 2041 if (typeof pos.coords[i] === 'number') { 2042 data[i] = pos.coords[i] 2043 } 2044 } 2045 this.fire('locationfound', data) 2046 }, 2047 addHandler: function (name, HandlerClass) { 2048 if (!HandlerClass) { 2049 return this 2050 } 2051 var handler = this[name] = new HandlerClass(this); 2052 this._handlers.push(handler); 2053 if (this.options[name]) { 2054 handler.enable() 2055 } 2056 return this 2057 }, 2058 remove: function () { 2059 this._initEvents(!0); 2060 if (this._containerId !== this._container._leaflet_id) { 2061 throw new Error('Map container is being reused by another instance') 2062 } 2063 try { 2064 delete this._container._leaflet_id; 2065 delete this._containerId 2066 } catch (e) { 2067 this._container._leaflet_id = undefined; 2068 this._containerId = undefined 2069 } 2070 if (this._locationWatchId !== undefined) { 2071 this.stopLocate() 2072 } 2073 this._stop(); 2074 remove(this._mapPane); 2075 if (this._clearControlPos) { 2076 this._clearControlPos() 2077 } 2078 if (this._resizeRequest) { 2079 cancelAnimFrame(this._resizeRequest); 2080 this._resizeRequest = null 2081 } 2082 this._clearHandlers(); 2083 if (this._loaded) { 2084 this.fire('unload') 2085 } 2086 var i; 2087 for (i in this._layers) { 2088 this._layers[i].remove() 2089 } 2090 for (i in this._panes) { 2091 remove(this._panes[i]) 2092 } 2093 this._layers = []; 2094 this._panes = []; 2095 delete this._mapPane; 2096 delete this._renderer; 2097 return this 2098 }, 2099 createPane: function (name, container) { 2100 var className = 'leaflet-pane' + (name ? ' leaflet-' + name.replace('Pane', '') + '-pane' : '') 2101 , pane = create$1('div', className, container || this._mapPane); 2102 if (name) { 2103 this._panes[name] = pane 2104 } 2105 return pane 2106 }, 2107 getCenter: function () { 2108 this._checkIfLoaded(); 2109 if (this._lastCenter && !this._moved()) { 2110 return this._lastCenter 2111 } 2112 return this.layerPointToLatLng(this._getCenterLayerPoint()) 2113 }, 2114 getZoom: function () { 2115 return this._zoom 2116 }, 2117 getBounds: function () { 2118 var bounds = this.getPixelBounds() 2119 , sw = this.unproject(bounds.getBottomLeft()) 2120 , ne = this.unproject(bounds.getTopRight()); 2121 return new LatLngBounds(sw, ne) 2122 }, 2123 getMinZoom: function () { 2124 return this.options.minZoom === undefined ? this._layersMinZoom || 0 : this.options.minZoom 2125 }, 2126 getMaxZoom: function () { 2127 return this.options.maxZoom === undefined ? (this._layersMaxZoom === undefined ? Infinity : this._layersMaxZoom) : this.options.maxZoom 2128 }, 2129 getBoundsZoom: function (bounds, inside, padding) { 2130 bounds = toLatLngBounds(bounds); 2131 padding = toPoint(padding || [0, 0]); 2132 var zoom = this.getZoom() || 0 2133 , min = this.getMinZoom() 2134 , max = this.getMaxZoom() 2135 , nw = bounds.getNorthWest() 2136 , se = bounds.getSouthEast() 2137 , size = this.getSize().subtract(padding) 2138 , boundsSize = toBounds(this.project(se, zoom), this.project(nw, zoom)).getSize() 2139 , snap = any3d ? this.options.zoomSnap : 1 2140 , scalex = size.x / boundsSize.x 2141 , scaley = size.y / boundsSize.y 2142 , scale = inside ? Math.max(scalex, scaley) : Math.min(scalex, scaley); 2143 zoom = this.getScaleZoom(scale, zoom); 2144 if (snap) { 2145 zoom = Math.round(zoom / (snap / 100)) * (snap / 100); 2146 zoom = inside ? Math.ceil(zoom / snap) * snap : Math.floor(zoom / snap) * snap 2147 } 2148 return Math.max(min, Math.min(max, zoom)) 2149 }, 2150 getSize: function () { 2151 if (!this._size || this._sizeChanged) { 2152 this._size = new Point(this._container.clientWidth || 0, this._container.clientHeight || 0); 2153 this._sizeChanged = !1 2154 } 2155 return this._size.clone() 2156 }, 2157 getPixelBounds: function (center, zoom) { 2158 var topLeftPoint = this._getTopLeftPoint(center, zoom); 2159 return new Bounds(topLeftPoint, topLeftPoint.add(this.getSize())) 2160 }, 2161 getPixelOrigin: function () { 2162 this._checkIfLoaded(); 2163 return this._pixelOrigin 2164 }, 2165 getPixelWorldBounds: function (zoom) { 2166 return this.options.crs.getProjectedBounds(zoom === undefined ? this.getZoom() : zoom) 2167 }, 2168 getPane: function (pane) { 2169 return typeof pane === 'string' ? this._panes[pane] : pane 2170 }, 2171 getPanes: function () { 2172 return this._panes 2173 }, 2174 getContainer: function () { 2175 return this._container 2176 }, 2177 getZoomScale: function (toZoom, fromZoom) { 2178 var crs = this.options.crs; 2179 fromZoom = fromZoom === undefined ? this._zoom : fromZoom; 2180 return crs.scale(toZoom) / crs.scale(fromZoom) 2181 }, 2182 getScaleZoom: function (scale, fromZoom) { 2183 var crs = this.options.crs; 2184 fromZoom = fromZoom === undefined ? this._zoom : fromZoom; 2185 var zoom = crs.zoom(scale * crs.scale(fromZoom)); 2186 return isNaN(zoom) ? Infinity : zoom 2187 }, 2188 project: function (latlng, zoom) { 2189 zoom = zoom === undefined ? this._zoom : zoom; 2190 return this.options.crs.latLngToPoint(toLatLng(latlng), zoom) 2191 }, 2192 unproject: function (point, zoom) { 2193 zoom = zoom === undefined ? this._zoom : zoom; 2194 return this.options.crs.pointToLatLng(toPoint(point), zoom) 2195 }, 2196 layerPointToLatLng: function (point) { 2197 var projectedPoint = toPoint(point).add(this.getPixelOrigin()); 2198 return this.unproject(projectedPoint) 2199 }, 2200 latLngToLayerPoint: function (latlng) { 2201 var projectedPoint = this.project(toLatLng(latlng))._round(); 2202 return projectedPoint._subtract(this.getPixelOrigin()) 2203 }, 2204 wrapLatLng: function (latlng) { 2205 return this.options.crs.wrapLatLng(toLatLng(latlng)) 2206 }, 2207 wrapLatLngBounds: function (latlng) { 2208 return this.options.crs.wrapLatLngBounds(toLatLngBounds(latlng)) 2209 }, 2210 distance: function (latlng1, latlng2) { 2211 return this.options.crs.distance(toLatLng(latlng1), toLatLng(latlng2)) 2212 }, 2213 containerPointToLayerPoint: function (point) { 2214 return toPoint(point).subtract(this._getMapPanePos()) 2215 }, 2216 layerPointToContainerPoint: function (point) { 2217 return toPoint(point).add(this._getMapPanePos()) 2218 }, 2219 containerPointToLatLng: function (point) { 2220 var layerPoint = this.containerPointToLayerPoint(toPoint(point)); 2221 return this.layerPointToLatLng(layerPoint) 2222 }, 2223 latLngToContainerPoint: function (latlng) { 2224 return this.layerPointToContainerPoint(this.latLngToLayerPoint(toLatLng(latlng))) 2225 }, 2226 mouseEventToContainerPoint: function (e) { 2227 return getMousePosition(e, this._container) 2228 }, 2229 mouseEventToLayerPoint: function (e) { 2230 return this.containerPointToLayerPoint(this.mouseEventToContainerPoint(e)) 2231 }, 2232 mouseEventToLatLng: function (e) { 2233 return this.layerPointToLatLng(this.mouseEventToLayerPoint(e)) 2234 }, 2235 _initContainer: function (id) { 2236 var container = this._container = get(id); 2237 if (!container) { 2238 throw new Error('Map container not found.') 2239 } else if (container._leaflet_id) { 2240 throw new Error('Map container is already initialized.') 2241 } 2242 on(container, 'scroll', this._onScroll, this); 2243 this._containerId = stamp(container) 2244 }, 2245 _initLayout: function () { 2246 var container = this._container; 2247 this._fadeAnimated = this.options.fadeAnimation && any3d; 2248 addClass(container, 'leaflet-container' + (touch ? ' leaflet-touch' : '') + (retina ? ' leaflet-retina' : '') + (ielt9 ? ' leaflet-oldie' : '') + (safari ? ' leaflet-safari' : '') + (this._fadeAnimated ? ' leaflet-fade-anim' : '')); 2249 var position = getStyle(container, 'position'); 2250 if (position !== 'absolute' && position !== 'relative' && position !== 'fixed') { 2251 container.style.position = 'relative' 2252 } 2253 this._initPanes(); 2254 if (this._initControlPos) { 2255 this._initControlPos() 2256 } 2257 }, 2258 _initPanes: function () { 2259 var panes = this._panes = {}; 2260 this._paneRenderers = {}; 2261 this._mapPane = this.createPane('mapPane', this._container); 2262 setPosition(this._mapPane, new Point(0, 0)); 2263 this.createPane('tilePane'); 2264 this.createPane('shadowPane'); 2265 this.createPane('overlayPane'); 2266 this.createPane('markerPane'); 2267 this.createPane('tooltipPane'); 2268 this.createPane('popupPane'); 2269 if (!this.options.markerZoomAnimation) { 2270 addClass(panes.markerPane, 'leaflet-zoom-hide'); 2271 addClass(panes.shadowPane, 'leaflet-zoom-hide') 2272 } 2273 }, 2274 _resetView: function (center, zoom) { 2275 setPosition(this._mapPane, new Point(0, 0)); 2276 var loading = !this._loaded; 2277 this._loaded = !0; 2278 zoom = this._limitZoom(zoom); 2279 this.fire('viewprereset'); 2280 var zoomChanged = this._zoom !== zoom;
2281 this._moveStart(zoomChanged, !1)._move(center, zoom)._moveEnd(zoomChanged); 2282 this.fire('viewreset'); 2283 if (loading) { 2284 this.fire('load') 2285 } 2286 }, 2287 _moveStart: function (zoomChanged, noMoveStart) { 2288 if (zoomChanged) { 2289 this.fire('zoomstart') 2290 } 2291 if (!noMoveStart) { 2292 this.fire('movestart') 2293 } 2294 return this 2295 }, 2296 _move: function (center, zoom, data) { 2297 if (zoom === undefined) { 2298 zoom = this._zoom 2299 } 2300 var zoomChanged = this._zoom !== zoom; 2301 this._zoom = zoom; 2302 this._lastCenter = center; 2303 this._pixelOrigin = this._getNewPixelOrigin(center); 2304 if (zoomChanged || (data && data.pinch)) { 2305 this.fire('zoom', data) 2306 } 2307 return this.fire('move', data) 2308 }, 2309 _moveEnd: function (zoomChanged) { 2310 if (zoomChanged) { 2311 this.fire('zoomend') 2312 } 2313 return this.fire('moveend') 2314 }, 2315 _stop: function () { 2316 cancelAnimFrame(this._flyToFrame); 2317 if (this._panAnim) { 2318 this._panAnim.stop() 2319 } 2320 return this 2321 }, 2322 _rawPanBy: function (offset) { 2323 setPosition(this._mapPane, this._getMapPanePos().subtract(offset)) 2324 }, 2325 _getZoomSpan: function () { 2326 return this.getMaxZoom() - this.getMinZoom() 2327 }, 2328 _panInsideMaxBounds: function () { 2329 if (!this._enforcingBounds) { 2330 this.panInsideBounds(this.options.maxBounds) 2331 } 2332 }, 2333 _checkIfLoaded: function () { 2334 if (!this._loaded) { 2335 throw new Error('Set leaflet center and zoom first.') 2336 } 2337 }, 2338 _initEvents: function (remove$$1) { 2339 this._targets = {}; 2340 this._targets[stamp(this._container)] = this; 2341 var onOff = remove$$1 ? off : on; 2342 onOff(this._container, 'click dblclick mousedown mouseup ' + 'mouseover mouseout mousemove contextmenu keypress', this._handleDOMEvent, this); 2343 if (this.options.trackResize) { 2344 onOff(window, 'resize', this._onResize, this) 2345 } 2346 if (any3d && this.options.transform3DLimit) { 2347 (remove$$1 ? this.off : this.on).call(this, 'moveend', this._onMoveEnd) 2348 } 2349 }, 2350 _onResize: function () { 2351 cancelAnimFrame(this._resizeRequest); 2352 this._resizeRequest = requestAnimFrame(function () { 2353 this.invalidateSize({ 2354 debounceMoveend: !0 2355 }) 2356 }, this) 2357 }, 2358 _onScroll: function () { 2359 this._container.scrollTop = 0; 2360 this._container.scrollLeft = 0 2361 }, 2362 _onMoveEnd: function () { 2363 var pos = this._getMapPanePos(); 2364 if (Math.max(Math.abs(pos.x), Math.abs(pos.y)) >= this.options.transform3DLimit) { 2365 this._resetView(this.getCenter(), this.getZoom()) 2366 } 2367 }, 2368 _findEventTargets: function (e, type) { 2369 var targets = [], target, isHover = type === 'mouseout' || type === 'mouseover', src = e.target || e.srcElement, dragging = !1; 2370 while (src) { 2371 target = this._targets[stamp(src)]; 2372 if (target && (type === 'click' || type === 'preclick') && !e._simulated && this._draggableMoved(target)) { 2373 dragging = !0; 2374 break 2375 } 2376 if (target && target.listens(type, !0)) { 2377 if (isHover && !isExternalTarget(src, e)) { 2378 break 2379 } 2380 targets.push(target); 2381 if (isHover) { 2382 break 2383 } 2384 } 2385 if (src === this._container) { 2386 break 2387 } 2388 src = src.parentNode 2389 } 2390 if (!targets.length && !dragging && !isHover && isExternalTarget(src, e)) { 2391 targets = [this] 2392 } 2393 return targets 2394 }, 2395 _handleDOMEvent: function (e) { 2396 if (!this._loaded || skipped(e)) { 2397 return 2398 } 2399 var type = e.type; 2400 if (type === 'mousedown' || type === 'keypress') { 2401 preventOutline(e.target || e.srcElement) 2402 } 2403 this._fireDOMEvent(e, type) 2404 }, 2405 _mouseEvents: ['click', 'dblclick', 'mouseover', 'mouseout', 'contextmenu'], 2406 _fireDOMEvent: function (e, type, targets) { 2407 if (e.type === 'click') { 2408 var synth = extend({}, e); 2409 synth.type = 'preclick'; 2410 this._fireDOMEvent(synth, synth.type, targets) 2411 } 2412 if (e._stopped) { 2413 return 2414 } 2415 targets = (targets || []).concat(this._findEventTargets(e, type)); 2416 if (!targets.length) { 2417 return 2418 } 2419 var target = targets[0]; 2420 if (type === 'contextmenu' && target.listens(type, !0)) { 2421 preventDefault(e) 2422 } 2423 var data = { 2424 originalEvent: e 2425 }; 2426 if (e.type !== 'keypress') { 2427 var isMarker = target.getLatLng && (!target._radius || target._radius <= 10); 2428 data.containerPoint = isMarker ? this.latLngToContainerPoint(target.getLatLng()) : this.mouseEventToContainerPoint(e); 2429 data.layerPoint = this.containerPointToLayerPoint(data.containerPoint); 2430 data.latlng = isMarker ? target.getLatLng() : this.layerPointToLatLng(data.layerPoint) 2431 } 2432 for (var i = 0; i < targets.length; i++) { 2433 targets[i].fire(type, data, !0); 2434 if (data.originalEvent._stopped || (targets[i].options.bubblingMouseEvents === !1 && indexOf(this._mouseEvents, type) !== -1)) { 2435 return 2436 } 2437 } 2438 }, 2439 _draggableMoved: function (obj) { 2440 obj = obj.dragging && obj.dragging.enabled() ? obj : this; 2441 return (obj.dragging && obj.dragging.moved()) || (this.boxZoom && this.boxZoom.moved()) 2442 }, 2443 _clearHandlers: function () { 2444 for (var i = 0, len = this._handlers.length; i < len; i++) { 2445 this._handlers[i].disable() 2446 } 2447 }, 2448 whenReady: function (callback, context) { 2449 if (this._loaded) { 2450 callback.call(context || this, { 2451 target: this 2452 }) 2453 } else { 2454 this.on('load', callback, context) 2455 } 2456 return this 2457 }, 2458 _getMapPanePos: function () { 2459 return getPosition(this._mapPane) || new Point(0, 0) 2460 }, 2461 _moved: function () { 2462 var pos = this._getMapPanePos(); 2463 return pos && !pos.equals([0, 0]) 2464 }, 2465 _getTopLeftPoint: function (center, zoom) { 2466 var pixelOrigin = center && zoom !== undefined ? this._getNewPixelOrigin(center, zoom) : this.getPixelOrigin(); 2467 return pixelOrigin.subtract(this._getMapPanePos()) 2468 }, 2469 _getNewPixelOrigin: function (center, zoom) {
2470 var viewHalf = this.getSize()._divideBy(2); 2471 return this.project(center, zoom)._subtract(viewHalf)._add(this._getMapPanePos())._round() 2472 }, 2473 _latLngToNewLayerPoint: function (latlng, zoom, center) { 2474 var topLeft = this._getNewPixelOrigin(center, zoom); 2475 return this.project(latlng, zoom)._subtract(topLeft) 2476 }, 2477 _latLngBoundsToNewLayerBounds: function (latLngBounds, zoom, center) { 2478 var topLeft = this._getNewPixelOrigin(center, zoom); 2479 return toBounds([this.project(latLngBounds.getSouthWest(), zoom)._subtract(topLeft), this.project(latLngBounds.getNorthWest(), zoom)._subtract(topLeft), this.project(latLngBounds.getSouthEast(), zoom)._subtract(topLeft), this.project(latLngBounds.getNorthEast(), zoom)._subtract(topLeft)]) 2480 }, 2481 _getCenterLayerPoint: function () { 2482 return this.containerPointToLayerPoint(this.getSize()._divideBy(2)) 2483 }, 2484 _getCenterOffset: function (latlng) { 2485 return this.latLngToLayerPoint(latlng).subtract(this._getCenterLayerPoint()) 2486 }, 2487 _limitCenter: function (center, zoom, bounds) { 2488 if (!bounds) { 2489 return center 2490 } 2491 var centerPoint = this.project(center, zoom) 2492 , viewHalf = this.getSize().divideBy(2) 2493 , viewBounds = new Bounds(centerPoint.subtract(viewHalf), centerPoint.add(viewHalf)) 2494 , offset = this._getBoundsOffset(viewBounds, bounds, zoom); 2495 if (offset.round().equals([0, 0])) { 2496 return center 2497 } 2498 return this.unproject(centerPoint.add(offset), zoom) 2499 }, 2500 _limitOffset: function (offset, bounds) { 2501 if (!bounds) { 2502 return offset 2503 } 2504 var viewBounds = this.getPixelBounds() 2505 , newBounds = new Bounds(viewBounds.min.add(offset), viewBounds.max.add(offset)); 2506 return offset.add(this._getBoundsOffset(newBounds, bounds)) 2507 }, 2508 _getBoundsOffset: function (pxBounds, maxBounds, zoom) { 2509 var projectedMaxBounds = toBounds(this.project(maxBounds.getNorthEast(), zoom), this.project(maxBounds.getSouthWest
2509(), zoom)) 2510 , minOffset = projectedMaxBounds.min.subtract(pxBounds.min) 2511 , maxOffset = projectedMaxBounds.max.subtract(pxBounds.max) 2512 , dx = this._rebound(minOffset.x, -maxOffset.x) 2513 , dy = this._rebound(minOffset.y, -maxOffset.y); 2514 return new Point(dx, dy) 2515 }, 2516 _rebound: function (left, right) { 2517 return left + right > 0 ? Math.round(left - right) / 2 : Math.max(0, Math.ceil(left)) - Math.max(0, Math.floor(right)) 2518 }, 2519 _limitZoom: function (zoom) { 2520 var min = this.getMinZoom() 2521 , max = this.getMaxZoom() 2522 , snap = any3d ? this.options.zoomSnap : 1; 2523 if (snap) { 2524 zoom = Math.round(zoom / snap) * snap 2525 } 2526 return Math.max(min, Math.min(max, zoom)) 2527 }, 2528 _onPanTransitionStep: function () { 2529 this.fire('move') 2530 }, 2531 _onPanTransitionEnd: function () { 2532 removeClass(this._mapPane, 'leaflet-pan-anim'); 2533 this.fire('moveend') 2534 }, 2535 _tryAnimatedPan: function (center, options) { 2536 var offset = this._getCenterOffset(center)._trunc(); 2537 if ((options && options.animate) !== !0 && !this.getSize().contains(offset)) { 2538 return !1 2539 } 2540 this.panBy(offset, options); 2541 return !0 2542 }, 2543 _createAnimProxy: function () { 2544 var proxy = this._proxy = create$1('div', 'leaflet-proxy leaflet-zoom-animated'); 2545 this._panes.mapPane.appendChild(proxy); 2546 this.on('zoomanim', function (e) { 2547 var prop = TRANSFORM 2548 , transform = this._proxy.style[prop]; 2549 setTransform(this._proxy, this.project(e.center, e.zoom), this.getZoomScale(e.zoom, 1)); 2550 if (transform === this._proxy.style[prop] && this._animatingZoom) { 2551 this._onZoomTransitionEnd() 2552 } 2553 }, this); 2554 this.on('load moveend', function () { 2555 var c = this.getCenter() 2556 , z = this.getZoom(); 2557 setTransform(this._proxy, this.project(c, z), this.getZoomScale(z, 1)) 2558 }, this); 2559 this._on('unload', this._destroyAnimProxy, this) 2560 }, 2561 _destroyAnimProxy: function () { 2562 remove(this._proxy); 2563 delete this._proxy 2564 }, 2565 _catchTransitionEnd: function (e) { 2566 if (this._animatingZoom && e.propertyName.indexOf('transform') >= 0) { 2567 this._onZoomTransitionEnd() 2568 } 2569 }, 2570 _nothingToAnimate: function () { 2571 return !this._container.getElementsByClassName('leaflet-zoom-animated').length 2572 }, 2573 _tryAnimatedZoom: function (center, zoom, options) { 2574 if (this._animatingZoom) { 2575 return !0 2576 } 2577 options = options || {}; 2578 if (!this._zoomAnimated || options.animate === !1 || this._nothingToAnimate() || Math.abs(zoom - this._zoom) > this.options.zoomAnimationThreshold) { 2579 return !1 2580 } 2581 var scale = this.getZoomScale(zoom) 2582 , offset = this._getCenterOffset(center)._divideBy(1 - 1 / scale); 2583 if (options.animate !== !0 && !this.getSize().contains(offset)) { 2584 return !1 2585 } 2586 requestAnimFrame(function () { 2587 this._moveStart(!0, !1)._animateZoom(center, zoom, !0) 2588 }, this); 2589 return !0 2590 }, 2591 _animateZoom: function (center, zoom, startAnim, noUpdate) { 2592 if (!this._mapPane) { 2593 return 2594 } 2595 if (startAnim) { 2596 this._animatingZoom = !0; 2597 this._animateToCenter = center; 2598 this._animateToZoom = zoom; 2599 addClass(this._mapPane, 'leaflet-zoom-anim') 2600 } 2601 this.fire('zoomanim', { 2602 center: center, 2603 zoom: zoom, 2604 noUpdate: noUpdate 2605 }); 2606 setTimeout(bind(this._onZoomTransitionEnd, this), 250) 2607 }, 2608 _onZoomTransitionEnd: function () { 2609 if (!this._animatingZoom) { 2610 return 2611 } 2612 if (this._mapPane) { 2613 removeClass(this._mapPane, 'leaflet-zoom-anim') 2614 } 2615 this._animatingZoom = !1; 2616 this._move(this._animateToCenter, this._animateToZoom); 2617 requestAnimFrame(function () { 2618 this._moveEnd(!0) 2619 }, this) 2620 } 2621 }); 2622 function createMap(id, options) { 2623 return new Map(id, options) 2624 } 2625 var Control = Class.extend({ 2626 options: { 2627 position: 'topright' 2628 }, 2629 initialize: function (options) { 2630 setOptions(this, options) 2631 }, 2632 getPosition: function () { 2633 return this.options.position 2634 }, 2635 setPosition: function (position) { 2636 var leaflet = this._map; 2637 if (leaflet) { 2638 leaflet.removeControl(this) 2639 } 2640 this.options.position = position; 2641 if (leaflet) { 2642 leaflet.addControl(this) 2643 } 2644 return this 2645 }, 2646 getContainer: function () { 2647 return this._container 2648 }, 2649 addTo: function (leaflet) { 2650 this.remove(); 2651 this._map = leaflet; 2652 var container = this._container = this.onAdd(leaflet) 2653 , pos = this.getPosition() 2654 , corner = leaflet._controlCorners[pos]; 2655 addClass(container, 'leaflet-control'); 2656 if (pos.indexOf('bottom') !== -1) { 2657 corner.insertBefore(container, corner.firstChild) 2658 } else { 2659 corner.appendChild(container) 2660 } 2661 return this 2662 }, 2663 remove: function () { 2664 if (!this._map) { 2665 return this 2666 } 2667 remove(this._container); 2668 if (this.onRemove) { 2669 this.onRemove(this._map) 2670 } 2671 this._map = null; 2672 return this 2673 }, 2674 _refocusOnMap: function (e) { 2675 if (this._map && e && e.screenX > 0 && e.screenY > 0) { 2676 this._map.getContainer().focus() 2677 } 2678 } 2679 }); 2680 var control = function (options) { 2681 return new Control(options) 2682 }; 2683 Map.include({ 2684 addControl: function (control) { 2685 control.addTo(this); 2686 return this 2687 }, 2688 removeControl: function (control) { 2689 control.remove(); 2690 return this 2691 }, 2692 _initControlPos: function () { 2693 var corners = this._controlCorners = {} 2694 , l = 'leaflet-' 2695 , container = this._controlContainer = create$1('div', l + 'control-container', this._container); 2696 function createCorner(vSide, hSide) { 2697 var className = l + vSide + ' ' + l + hSide; 2698 corners[vSide + hSide] = create$1('div', className, container) 2699 } 2700 createCorner('top', 'left'); 2701 createCorner('top', 'right'); 2702 createCorner('bottom', 'left'); 2703 createCorner('bottom', 'right') 2704 }, 2705 _clearControlPos: function () { 2706 for (var i in this._controlCorners) { 2707 remove(this._controlCorners[i]) 2708 } 2709 remove(this._controlContainer); 2710 delete this._controlCorners; 2711 delete this._controlContainer 2712 } 2713 }); 2714 var Layers = Control.extend({ 2715 options: { 2716 collapsed: !0, 2717 position: 'topright', 2718 autoZIndex: !0, 2719 hideSingleBase: !1,
2720 sortLayers: !1, 2721 sortFunction: function (layerA, layerB, nameA, nameB) { 2722 return nameA < nameB ? -1 : (nameB < nameA ? 1 : 0) 2723 } 2724 }, 2725 initialize: function (baseLayers, overlays, options) { 2726 setOptions(this, options); 2727 this._layerControlInputs = []; 2728 this._layers = []; 2729 this._lastZIndex = 0; 2730 this._handlingClick = !1; 2731 for (var i in baseLayers) { 2732 this._addLayer(baseLayers[i], i) 2733 } 2734 for (i in overlays) { 2735 this._addLayer(overlays[i], i, !0) 2736 } 2737 }, 2738 onAdd: function (leaflet) { 2739 this._initLayout(); 2740 this._update(); 2741 this._map = leaflet; 2742 leaflet.on('zoomend', this._checkDisabledLayers, this); 2743 for (var i = 0; i < this._layers.length; i++) { 2744 this._layers[i].layer.on('add remove', this._onLayerChange, this) 2745 } 2746 return this._container 2747 }, 2748 addTo: function (leaflet) { 2749 Control.prototype.addTo.call(this, leaflet); 2750 return this._expandIfNotCollapsed() 2751 }, 2752 onRemove: function () { 2753 this._map.off('zoomend', this._checkDisabledLayers, this); 2754 for (var i = 0; i < this._layers.length; i++) { 2755 this._layers[i].layer.off('add remove', this._onLayerChange, this) 2756 } 2757 }, 2758 addBaseLayer: function (layer, name) { 2759 this._addLayer(layer, name); 2760 return (this._map) ? this._update() : this 2761 }, 2762 addOverlay: function (layer, name) { 2763 this._addLayer(layer, name, !0); 2764 return (this._map) ? this._update() : this 2765 }, 2766 removeLayer: function (layer) { 2767 layer.off('add remove', this._onLayerChange, this); 2768 var obj = this._getLayer(stamp(layer)); 2769 if (obj) { 2770 this._layers.splice(this._layers.indexOf(obj), 1) 2771 } 2772 return (this._map) ? this._update() : this 2773 }, 2774 expand: function () { 2775 addClass(this._container, 'leaflet-control-layers-expanded'); 2776 this._form.style.height = null; 2777 var acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50); 2778 if (acceptableHeight < this._form.clientHeight) { 2779 addClass(this._form, 'leaflet-control-layers-scrollbar'); 2780 this._form.style.height = acceptableHeight + 'px' 2781 } else { 2782 removeClass(this._form, 'leaflet-control-layers-scrollbar') 2783 } 2784 this._checkDisabledLayers(); 2785 return this 2786 }, 2787 collapse: function () { 2788 removeClass(this._container, 'leaflet-control-layers-expanded'); 2789 return this 2790 }, 2791 _initLayout: function () { 2792 var className = 'leaflet-control-layers' 2793 , container = this._container = create$1('div', className) 2794 , collapsed = this.options.collapsed; 2795 container.setAttribute('aria-haspopup', !0); 2796 disableClickPropagation(container); 2797 disableScrollPropagation(container); 2798 var form = this._form = create$1('form', className + '-list'); 2799 if (collapsed) { 2800 this._map.on('click', this.collapse, this); 2801 if (!android) { 2802 on(container, { 2803 mouseenter: this.expand, 2804 mouseleave: this.collapse 2805 }, this) 2806 } 2807 } 2808 var link = this._layersLink = create$1('a', className + '-toggle', container); 2809 link.href = '#'; 2810 link.title = 'Layers'; 2811 if (touch) { 2812 on(link, 'click', stop); 2813 on(link, 'click', this.expand, this) 2814 } else { 2815 on(link, 'focus', this.expand, this) 2816 } 2817 if (!collapsed) { 2818 this.expand() 2819 } 2820 this._baseLayersList = create$1('div', className + '-base', form); 2821 this._separator = create$1('div', className + '-separator', form); 2822 this._overlaysList = create$1('div', className + '-overlays', form); 2823 container.appendChild(form) 2824 }, 2825 _getLayer: function (id) { 2826 for (var i = 0; i < this._layers.length; i++) { 2827 if (this._layers[i] && stamp(this._layers[i].layer) === id) { 2828 return this._layers[i] 2829 } 2830 } 2831 }, 2832 _addLayer: function (layer, name, overlay) { 2833 if (this._map) { 2834 layer.on('add remove', this._onLayerChange, this) 2835 } 2836 this._layers.push({ 2837 layer: layer, 2838 name: name, 2839 overlay: overlay 2840 }); 2841 if (this.options.sortLayers) { 2842 this._layers.sort(bind(function (a, b) { 2843 return this.options.sortFunction(a.layer, b.layer, a.name, b.name) 2844 }, this)) 2845 }
2846 if (this.options.autoZIndex && layer.setZIndex) { 2847 this._lastZIndex++; 2848 layer.setZIndex(this._lastZIndex) 2849 } 2850 this._expandIfNotCollapsed() 2851 }, 2852 _update: function () { 2853 if (!this._container) { 2854 return this 2855 } 2856 empty(this._baseLayersList); 2857 empty(this._overlaysList); 2858 this._layerControlInputs = []; 2859 var baseLayersPresent, overlaysPresent, i, obj, baseLayersCount = 0; 2860 for (i = 0; i < this._layers.length; i++) { 2861 obj = this._layers[i]; 2862 this._addItem(obj); 2863 overlaysPresent = overlaysPresent || obj.overlay; 2864 baseLayersPresent = baseLayersPresent || !obj.overlay; 2865 baseLayersCount += !obj.overlay ? 1 : 0 2866 } 2867 if (this.options.hideSingleBase) { 2868 baseLayersPresent = baseLayersPresent && baseLayersCount > 1; 2869 this._baseLayersList.style.display = baseLayersPresent ? '' : 'none' 2870 } 2871 this._separator.style.display = overlaysPresent && baseLayersPresent ? '' : 'none'; 2872 return this 2873 }, 2874 _onLayerChange: function (e) { 2875 if (!this._handlingClick) { 2876 this._update() 2877 } 2878 var obj = this._getLayer(stamp(e.target)); 2879 var type = obj.overlay ? (e.type === 'add' ? 'overlayadd' : 'overlayremove') : (e.type === 'add' ? 'baselayerchange' : null); 2880 if (type) { 2881 this._map.fire(type, obj) 2882 } 2883 }, 2884 _createRadioElement: function (name, checked) { 2885 var radioHtml = '<input type="radio" class="leaflet-control-layers-selector" name="' + name + '"' + (checked ? ' checked="checked"' : '') + '/>'; 2886 var radioFragment = document.createElement('div'); 2887 radioFragment.innerHTML = radioHtml; 2888 return radioFragment.firstChild 2889 }, 2890 _addItem: function (obj) { 2891 var label = document.createElement('label'), checked = this._map.hasLayer(obj.layer), input; 2892 if (obj.overlay) { 2893 input = document.createElement('input'); 2894 input.type = 'checkbox'; 2895 input.className = 'leaflet-control-layers-selector'; 2896 input.defaultChecked = checked 2897 } else { 2898 input = this._createRadioElement('leaflet-base-layers', checked) 2899 } 2900 this._layerControlInputs.push(input); 2901 input.layerId = stamp(obj.layer); 2902 on(input, 'click', this._onInputClick, this); 2903 var name = document.createElement('span'); 2904 name.innerHTML = ' ' + obj.name; 2905 var holder = document.createElement('div'); 2906 label.appendChild(holder); 2907 holder.appendChild(input); 2908 holder.appendChild(name); 2909 var container = obj.overlay ? this._overlaysList : this._baseLayersList; 2910 container.appendChild(label); 2911 this._checkDisabledLayers(); 2912 return label 2913 }, 2914 _onInputClick: function () { 2915 var inputs = this._layerControlInputs, input, layer; 2916 var addedLayers = [] 2917 , removedLayers = []; 2918 this._handlingClick = !0; 2919 for (var i = inputs.length - 1; i >= 0; i--) { 2920 input = inputs[i]; 2921 layer = this._getLayer(input.layerId).layer; 2922 if (input.checked) { 2923 addedLayers.push(layer) 2924 } else if (!input.checked) { 2925 removedLayers.push(layer) 2926 } 2927 } 2928 for (i = 0; i < removedLayers.length; i++) { 2929 if (this._map.hasLayer(removedLayers[i])) { 2930 this._map.removeLayer(removedLayers[i]) 2931 } 2932 } 2933 for (i = 0; i < addedLayers.length; i++) { 2934 if (!this._map.hasLayer(addedLayers[i])) { 2935 this._map.addLayer(addedLayers[i]) 2936 } 2937 } 2938 this._handlingClick = !1; 2939 this._refocusOnMap() 2940 }, 2941 _checkDisabledLayers: function () { 2942 var inputs = this._layerControlInputs, input, layer, zoom = this._map.getZoom(); 2943 for (var i = inputs.length - 1; i >= 0; i--) { 2944 input = inputs[i]; 2945 layer = this._getLayer(input.layerId).layer; 2946 input.disabled = (layer.options.minZoom !== undefined && zoom < layer.options.minZoom) || (layer.options.maxZoom !== undefined && zoom > layer.options.maxZoom) 2947 } 2948 }, 2949 _expandIfNotCollapsed: function () { 2950 if (this._map && !this.options.collapsed) { 2951 this.expand() 2952 } 2953 return this 2954 }, 2955 _expand: function () { 2956 return this.expand() 2957 }, 2958 _collapse: function () { 2959 return this.collapse() 2960 } 2961 }); 2962 var layers = function (baseLayers, overlays, options) {
2963 return new Layers(baseLayers, overlays, options) 2964 }; 2965 var Zoom = Control.extend({ 2966 options: { 2967 position: 'topleft', 2968 zoomInText: '+', 2969 zoomInTitle: 'Zoom in', 2970 zoomOutText: '−', 2971 zoomOutTitle: 'Zoom out' 2972 }, 2973 onAdd: function (leaflet) { 2974 var zoomName = 'leaflet-control-zoom' 2975 , container = create$1('div', zoomName + ' leaflet-bar') 2976 , options = this.options; 2977 this._zoomInButton = this._createButton(options.zoomInText, options.zoomInTitle, zoomName + '-in', container, this._zoomIn); 2978 this._zoomOutButton = this._createButton(options.zoomOutText, options.zoomOutTitle, zoomName + '-out', container, this._zoomOut); 2979 this._updateDisabled(); 2980 leaflet.on('zoomend zoomlevelschange', this._updateDisabled, this); 2981 return container 2982 }, 2983 onRemove: function (leaflet) { 2984 leaflet.off('zoomend zoomlevelschange', this._updateDisabled, this) 2985 }, 2986 disable: function () { 2987 this._disabled = !0; 2988 this._updateDisabled(); 2989 return this 2990 }, 2991 enable: function () { 2992 this._disabled = !1; 2993 this._updateDisabled(); 2994 return this 2995 }, 2996 _zoomIn: function (e) { 2997 if (!this._disabled && this._map._zoom < this._map.getMaxZoom()) { 2998 this._map.zoomIn(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1)) 2999 } 3000 }, 3001 _zoomOut: function (e) { 3002 if (!this._disabled && this._map._zoom > this._map.getMinZoom()) { 3003 this._map.zoomOut(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1)) 3004 } 3005 }, 3006 _createButton: function (html, title, className, container, fn) { 3007 var link = create$1('a', className, container); 3008 link.innerHTML = html; 3009 link.href = '#'; 3010 link.title = title; 3011 link.setAttribute('role', 'button'); 3012 link.setAttribute('aria-label', title); 3013 disableClickPropagation(link); 3014 on(link, 'click', stop); 3015 on(link, 'click', fn, this); 3016 on(link, 'click', this._refocusOnMap, this); 3017 return link 3018 }, 3019 _updateDisabled: function () { 3020 var leaflet = this._map 3021 , className = 'leaflet-disabled'; 3022 removeClass(this._zoomInButton, className); 3023 removeClass(this._zoomOutButton, className); 3024 if (this._disabled || leaflet._zoom === leaflet.getMinZoom()) { 3025 addClass(this._zoomOutButton, className) 3026 } 3027 if (this._disabled || leaflet._zoom === leaflet.getMaxZoom()) { 3028 addClass(this._zoomInButton, className) 3029 } 3030 } 3031 }); 3032 Map.mergeOptions({ 3033 zoomControl: !0 3034 }); 3035 Map.addInitHook(function () { 3036 if (this.options.zoomControl) { 3037 this.zoomControl = new Zoom(); 3038 this.addControl(this.zoomControl) 3039 } 3040 }); 3041 var zoom = function (options) { 3042 return new Zoom(options) 3043 }; 3044 var Scale = Control.extend({ 3045 options: { 3046 position: 'bottomleft', 3047 maxWidth: 100, 3048 metric: !0, 3049 imperial: !0 3050 }, 3051 onAdd: function (leaflet) { 3052 var className = 'leaflet-control-scale' 3053 , container = create$1('div', className) 3054 , options = this.options; 3055 this._addScales(options, className + '-line', container); 3056 leaflet.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this); 3057 leaflet.whenReady(this._update, this); 3058 return container 3059 }, 3060 onRemove: function (leaflet) { 3061 leaflet.off(this.options.updateWhenIdle ? 'moveend' : 'move', this._update, this) 3062 }, 3063 _addScales: function (options, className, container) { 3064 if (options.metric) { 3065 this._mScale = create$1('div', className, container) 3066 } 3067 if (options.imperial) { 3068 this._iScale = create$1('div', className, container) 3069 } 3070 }, 3071 _update: function () { 3072 var leaflet = this._map 3073 , y = leaflet.getSize().y / 2; 3074 var maxMeters = leaflet.distance(leaflet.containerPointToLatLng([0, y]), leaflet.containerPointToLatLng([this.options.maxWidth, y])); 3075 this._updateScales(maxMeters) 3076 }, 3077 _updateScales: function (maxMeters) { 3078 if (this.options.metric && maxMeters) { 3079 this._updateMetric(maxMeters) 3080 } 3081 if (this.options.imperial && maxMeters) { 3082 this._updateImperial(maxMeters) 3083 } 3084 }, 3085 _updateMetric: function (maxMeters) { 3086 var meters = this._getRoundNum(maxMeters) 3087 , label = meters < 1000 ? meters + ' m' : (meters / 1000) + ' km'; 3088 this._updateScale(this._mScale, label, meters / maxMeters) 3089 }, 3090 _updateImperial: function (maxMeters) { 3091 var maxFeet = maxMeters * 3.2808399, maxMiles, miles, feet; 3092 if (maxFeet > 5280) { 3093 maxMiles = maxFeet / 5280; 3094 miles = this._getRoundNum(maxMiles); 3095 this._updateScale(this._iScale, miles + ' mi', miles / max
3095Miles) 3096 } else { 3097 feet = this._getRoundNum(maxFeet); 3098 this._updateScale(this._iScale, feet + ' ft', feet / maxFeet) 3099 } 3100 }, 3101 _updateScale: function (scale, text, ratio) { 3102 scale.style.width = Math.round(this.options.maxWidth * ratio) + 'px'; 3103 scale.innerHTML = text 3104 }, 3105 _getRoundNum: function (num) { 3106 var pow10 = Math.pow(10, (Math.floor(num) + '').length - 1) 3107 , d = num / pow10; 3108 d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1; 3109 return pow10 * d 3110 } 3111 }); 3112 var scale = function (options) { 3113 return new Scale(options) 3114 }; 3115 var Attribution = Control.extend({ 3116 options: { 3117 position: 'bottomright', 3118 prefix: '<a href="http://leafletjs.com" title="A JS library for interactive maps">leaflet</a>' 3119 }, 3120 initialize: function (options) { 3121 setOptions(this, options); 3122 this._attributions = {} 3123 }, 3124 onAdd: function (leaflet) { 3125 leaflet.attributionControl = this; 3126 this._container = create$1('div', 'leaflet-control-attribution'); 3127 disableClickPropagation(this._container); 3128 for (var i in leaflet._layers) { 3129 if (leaflet._layers[i].getAttribution) { 3130 this.addAttribution(leaflet._layers[i].getAttribution()) 3131 } 3132 } 3133 this._update(); 3134 return this._container 3135 }, 3136 setPrefix: function (prefix) { 3137 this.options.prefix = prefix; 3138 this._update(); 3139 return this 3140 }, 3141 addAttribution: function (text) { 3142 if (!text) { 3143 return this 3144 } 3145 if (!this._attributions[text]) { 3146 this._attributions[text] = 0 3147 } 3148 this._attributions[text]++; 3149 this._update(); 3150 return this 3151 }, 3152 removeAttribution: function (text) { 3153 if (!text) { 3154 return this 3155 } 3156 if (this._attributions[text]) { 3157 this._attributions[text]--; 3158 this._update() 3159 } 3160 return this 3161 }, 3162 _update: function () { 3163 if (!this._map) { 3164 return 3165 } 3166 var attribs = []; 3167 for (var i in this._attributions) { 3168 if (this._attributions[i]) { 3169 attribs.push(i) 3170 } 3171 } 3172 var prefixAndAttribs = []; 3173 if (this.options.prefix) { 3174 prefixAndAttribs.push(this.options.prefix) 3175 } 3176 if (attribs.length) { 3177 prefixAndAttribs.push(attribs.join(', ')) 3178 } 3179 this._container.innerHTML = prefixAndAttribs.join(' | ') 3180 } 3181 }); 3182 Map.mergeOptions({ 3183 attributionControl: !0 3184 }); 3185 Map.addInitHook(function () { 3186 if (this.options.attributionControl) { 3187 new Attribution().addTo(this) 3188 } 3189 }); 3190 var attribution = function (options) { 3191 return new Attribution(options) 3192 }; 3193 Control.Layers = Layers; 3194 Control.Zoom = Zoom; 3195 Control.Scale = Scale; 3196 Control.Attribution = Attribution;
3197 control.layers = layers; 3198 control.zoom = zoom; 3199 control.scale = scale; 3200 control.attribution = attribution; 3201 var Handler = Class.extend({ 3202 initialize: function (leaflet) { 3203 this._map = leaflet 3204 }, 3205 enable: function () { 3206 if (this._enabled) { 3207 return this 3208 } 3209 this._enabled = !0; 3210 this.addHooks(); 3211 return this 3212 }, 3213 disable: function () { 3214 if (!this._enabled) { 3215 return this 3216 } 3217 this._enabled = !1; 3218 this.removeHooks(); 3219 return this 3220 }, 3221 enabled: function () { 3222 return !!this._enabled 3223 } 3224 }); 3225 Handler.addTo = function (leaflet, name) { 3226 leaflet.addHandler(name, this); 3227 return this 3228 } 3229 ; 3230 var Mixin = { 3231 Events: Events 3232 }; 3233 var START = touch ? 'touchstart mousedown' : 'mousedown'; 3234 var END = { 3235 mousedown: 'mouseup', 3236 touchstart: 'touchend', 3237 pointerdown: 'touchend', 3238 MSPointerDown: 'touchend' 3239 }; 3240 var MOVE = { 3241 mousedown: 'mousemove', 3242 touchstart: 'touchmove', 3243 pointerdown: 'touchmove', 3244 MSPointerDown: 'touchmove' 3245 }; 3246 var Draggable = Evented.extend({ 3247 options: { 3248 clickTolerance: 3 3249 }, 3250 initialize: function (element, dragStartTarget, preventOutline$$1, options) { 3251 setOptions(this, options); 3252 this._element = element; 3253 this._dragStartTarget = dragStartTarget || element; 3254 this._preventOutline = preventOutline$$1 3255 }, 3256 enable: function () { 3257 if (this._enabled) { 3258 return 3259 } 3260 on(this._dragStartTarget, START, this._onDown, this); 3261 this._enabled = !0 3262 }, 3263 disable: function () { 3264 if (!this._enabled) { 3265 return 3266 } 3267 if (Draggable._dragging === this) { 3268 this.finishDrag() 3269 } 3270 off(this._dragStartTarget, START, this._onDown, this); 3271 this._enabled = !1; 3272 this._moved = !1 3273 }, 3274 _onDown: function (e) { 3275 if (e._simulated || !this._enabled) { 3276 return 3277 } 3278 this._moved = !1; 3279 if (hasClass(this._element, 'leaflet-zoom-anim')) { 3280 return 3281 } 3282 if (Draggable._dragging || e.shiftKey || ((e.which !== 1) && (e.button !== 1) && !e.touches)) { 3283 return 3284 } 3285 Draggable._dragging = this; 3286 if (this._preventOutline) { 3287 preventOutline(this._element) 3288 } 3289 disableImageDrag(); 3290 disableTextSelection(); 3291 if (this._moving) { 3292 return 3293 } 3294 this.fire('down'); 3295 var first = e.touches ? e.touches[0] : e 3296 , sizedParent = getSizedParentNode(this._element); 3297 this._startPoint = new Point(first.clientX, first.clientY); 3298 this._parentScale = getScale(sizedParent); 3299 on(document, MOVE[e.type], this._onMove, this); 3300 on(document, END[e.type], this._onUp, this) 3301 }, 3302 _onMove: function (e) { 3303 if (e._simulated || !this._enabled) { 3304 return 3305 } 3306 if (e.touches && e.touches.length > 1) { 3307 this._moved = !0; 3308 return 3309 } 3310 var first = (e.touches && e.touches.length === 1 ? e.touches[0] : e) 3311 , offset = new Point(first.clientX, first.clientY)._subtract(this._startPoint); 3312 if (!offset.x && !offset.y) { 3313 return 3314 } 3315 if (Math.abs(offset.x) + Math.abs(offset.y) < this.options.clickTolerance) { 3316 return 3317 } 3318 offset.x /= this._parentScale.x; 3319 offset.y /= this._parentScale.y; 3320 preventDefault(e); 3321 if (!this._moved) { 3322 this.fire('dragstart'); 3323 this._moved = !0; 3324 this._startPos = getPosition(this._element).subtract(offset); 3325 addClass(document.body, 'leaflet-dragging'); 3326 this._lastTarget = e.target || e.srcElement; 3327 if ((window.SVGElementInstance) && (this._lastTarget instanceof SVGElementInstance)) { 3328 this._lastTarget = this._lastTarget.correspondingUseElement 3329 } 3330 addClass(this._lastTarget, 'leaflet-drag-target') 3331 } 3332 this._newPos = this._startPos.add(offset); 3333 this._moving = !0;
3334 cancelAnimFrame(this._animRequest); 3335 this._lastEvent = e; 3336 this._animRequest = requestAnimFrame(this._updatePosition, this, !0) 3337 }, 3338 _updatePosition: function () { 3339 var e = { 3340 originalEvent: this._lastEvent 3341 }; 3342 this.fire('predrag', e); 3343 setPosition(this._element, this._newPos); 3344 this.fire('drag', e) 3345 }, 3346 _onUp: function (e) { 3347 if (e._simulated || !this._enabled) { 3348 return 3349 } 3350 this.finishDrag() 3351 }, 3352 finishDrag: function () { 3353 removeClass(document.body, 'leaflet-dragging'); 3354 if (this._lastTarget) { 3355 removeClass(this._lastTarget, 'leaflet-drag-target'); 3356 this._lastTarget = null 3357 } 3358 for (var i in MOVE) { 3359 off(document, MOVE[i], this._onMove, this); 3360 off(document, END[i], this._onUp, this) 3361 } 3362 enableImageDrag(); 3363 enableTextSelection(); 3364 if (this._moved && this._moving) { 3365 cancelAnimFrame(this._animRequest); 3366 this.fire('dragend', { 3367 distance: this._newPos.distanceTo(this._startPos) 3368 }) 3369 } 3370 this._moving = !1; 3371 Draggable._dragging = !1 3372 } 3373 }); 3374 function simplify(points, tolerance) { 3375 if (!tolerance || !points.length) { 3376 return points.slice() 3377 } 3378 var sqTolerance = tolerance * tolerance; 3379 points = _reducePoints(points, sqTolerance); 3380 points = _simplifyDP(points, sqTolerance); 3381 return points 3382 } 3383 function pointToSegmentDistance(p, p1, p2) { 3384 return Math.sqrt(_sqClosestPointOnSegment(p, p1, p2, !0)) 3385 } 3386 function closestPointOnSegment(p, p1, p2) { 3387 return _sqClosestPointOnSegment(p, p1, p2) 3388 } 3389 function _simplifyDP(points, sqTolerance) { 3390 var len = points.length 3391 , ArrayConstructor = typeof Uint8Array !== undefined + '' ? Uint8Array : Array 3392 , markers = new ArrayConstructor(len); 3393 markers[0] = markers[len - 1] = 1; 3394 _simplifyDPStep(points, markers, sqTolerance, 0, len - 1); 3395 var i, newPoints = []; 3396 for (i = 0; i < len; i++) { 3397 if (markers[i]) { 3398 newPoints.push(points[i]) 3399 } 3400 } 3401 return newPoints 3402 } 3403 function _simplifyDPStep(points, markers, sqTolerance, first, last) { 3404 var maxSqDist = 0, index, i, sqDist; 3405 for (i = first + 1; i <= last - 1; i++) { 3406 sqDist = _sqClosestPointOnSegment(points[i], points[first], points[last], !0); 3407 if (sqDist > maxSqDist) { 3408 index = i; 3409 maxSqDist = sqDist 3410 } 3411 } 3412 if (maxSqDist > sqTolerance) { 3413 markers[index] = 1; 3414 _simplifyDPStep(points, markers, sqTolerance, first, index); 3415 _simplifyDPStep(points, markers, sqTolerance, index, last) 3416 } 3417 } 3418 function _reducePoints(points, sqTolerance) { 3419 var reducedPoints = [points[0]]; 3420 for (var i = 1, prev = 0, len = points.length; i < len; i++) { 3421 if (_sqDist(points[i], points[prev]) > sqTolerance) { 3422 reducedPoints.push(points[i]); 3423 prev = i 3424 } 3425 } 3426 if (prev < len - 1) { 3427 reducedPoints.push(points[len - 1]) 3428 } 3429 return reducedPoints 3430 } 3431 var _lastCode; 3432 function clipSegment(a, b, bounds, useLastCode, round) { 3433 var codeA = useLastCode ? _lastCode : _getBitCode(a, bounds), codeB = _getBitCode(b, bounds), codeOut, p, newCode; 3434 _lastCode = codeB; 3435 while (!0) { 3436 if (!(codeA | codeB)) { 3437 return [a, b] 3438 } 3439 if (codeA & codeB) { 3440 return !1 3441 } 3442 codeOut = codeA || codeB; 3443 p = _getEdgeIntersection(a, b, codeOut, bounds, round); 3444 newCode = _getBitCode(p, bounds); 3445 if (codeOut === codeA) { 3446 a = p; 3447 codeA = newCode 3448 } else { 3449 b = p; 3450 codeB = newCode 3451 } 3452 } 3453 } 3454 function _getEdgeIntersection(a, b, code, bounds, round) { 3455 var dx = b.x - a.x, dy = b.y - a.y, min = bounds.min, max = bounds.max, x, y; 3456 if (code & 8) { 3457 x = a.x + dx * (max.y - a.y) / dy; 3458 y = max.y 3459 } else if (code & 4) { 3460 x = a.x + dx * (min.y - a.y) / dy; 3461 y = min.y 3462 } else if (code & 2) { 3463 x = max.x; 3464 y = a.y + dy * (max.x - a.x) / dx 3465 } else if (code & 1) { 3466 x = min.x; 3467 y = a.y + dy * (min.x - a.x) / dx 3468 } 3469 return new Point(x, y, round) 3470 } 3471 function _getBitCode(p, bounds) { 3472 var code = 0; 3473 if (p.x < bounds.min.x) { 3474 code |= 1 3475 } else if (p.x > bounds.max.x) { 3476 code |= 2 3477 } 3478 if (p.y < bounds.min.y) { 3479 code |= 4 3480 } else if (p.y > bounds.max.y) { 3481 code |= 8 3482 } 3483 return code 3484 } 3485 function _sqDist(p1, p2) { 3486 var dx = p2.x - p1.x 3487 , dy = p2.y - p1.y; 3488 return dx * dx + dy * dy 3489 } 3490 function _sqClosestPointOnSegment(p, p1, p2, sqDist) { 3491 var x = p1.x, y = p1.y, dx = p2.x - x, dy = p2.y - y, dot = dx * dx + dy * dy, t; 3492 if (dot > 0) { 3493 t = ((p.x - x) * dx + (p.y - y) * dy) / dot; 3494 if (t > 1) { 3495 x = p2.x; 3496 y = p2.y 3497 } else if (t > 0) { 3498 x += dx * t; 3499 y += dy * t 3500 } 3501 } 3502 dx = p.x - x; 3503 dy = p.y - y; 3504 return sqDist ? dx * dx + dy * dy : new Point(x, y) 3505 } 3506 function isFlat(latlngs) { 3507 return !isArray(latlngs[0]) || (typeof latlngs[0][0] !== 'object' && typeof latlngs[0][0] !== 'undefined') 3508 } 3509 function _flat(latlngs) { 3510 console.warn('Deprecated use of _flat, please use L.LineUtil.isFlat instead.'); 3511 return isFlat(latlngs) 3512 } 3513 var LineUtil = (Object.freeze || Object)({ 3514 simplify: simplify, 3515 pointToSegmentDistance: pointToSegmentDistance, 3516 closestPointOnSegment: closestPointOnSegment, 3517 clipSegment: clipSegment, 3518 _getEdgeIntersection: _getEdgeIntersection, 3519 _getBitCode: _getBitCode, 3520 _sqClosestPointOnSegment: _sqClosestPointOnSegment, 3521 isFlat: isFlat, 3522 _flat: _flat 3523 }); 3524 function clipPolygon(points, bounds, round) { 3525 var clippedPoints, edges = [1, 4, 2, 8], i, j, k, a, b, len, edge, p; 3526 for (i = 0, 3527 len = points.length; i < len; i++) { 3528 points[i]._code = _getBitCode(points[i], bounds) 3529 } 3530 for (k = 0; k < 4; k++) { 3531 edge = edges[k]; 3532 clippedPoints = []; 3533 for (i = 0, 3534 len = points.length, 3535 j = len - 1; i < len; j = i++) { 3536 a = points[i]; 3537 b = points[j];
3538 if (!(a._code & edge)) { 3539 if (b._code & edge) { 3540 p = _getEdgeIntersection(b, a, edge, bounds, round); 3541 p._code = _getBitCode(p, bounds); 3542 clippedPoints.push(p) 3543 } 3544 clippedPoints.push(a) 3545 } else if (!(b._code & edge)) { 3546 p = _getEdgeIntersection(b, a, edge, bounds, round); 3547 p._code = _getBitCode(p, bounds); 3548 clippedPoints.push(p) 3549 } 3550 } 3551 points = clippedPoints 3552 } 3553 return points 3554 } 3555 var PolyUtil = (Object.freeze || Object)({ 3556 clipPolygon: clipPolygon 3557 }); 3558 var LonLat = { 3559 project: function (latlng) { 3560 return new Point(latlng.lng, latlng.lat) 3561 }, 3562 unproject: function (point) { 3563 return new LatLng(point.y, point.x) 3564 }, 3565 bounds: new Bounds([-180, -90], [180, 90]) 3566 }; 3567 var Mercator = { 3568 R: 6378137, 3569 R_MINOR: 6356752.314245179, 3570 bounds: new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]), 3571 project: function (latlng) { 3572 var d = Math.PI / 180 3573 , r = this.R 3574 , y = latlng.lat * d 3575 , tmp = this.R_MINOR / r 3576 , e = Math.sqrt(1 - tmp * tmp) 3577 , con = e * Math.sin(y); 3578 var ts = Math.tan(Math.PI / 4 - y / 2) / Math.pow((1 - con) / (1 + con), e / 2); 3579 y = -r * Math.log(Math.max(ts, 1E-10)); 3580 return new Point(latlng.lng * d * r, y) 3581 }, 3582 unproject: function (point) { 3583 var d = 180 / Math.PI 3584 , r = this.R 3585 , tmp = this.R_MINOR / r 3586 , e = Math.sqrt(1 - tmp * tmp) 3587 , ts = Math.exp(-point.y / r) 3588 , phi = Math.PI / 2 - 2 * Math.atan(ts); 3589 for (var i = 0, dphi = 0.1, con; i < 15 && Math.abs(dphi) > 1e-7; i++) { 3590 con = e * Math.sin(phi); 3591 con = Math.pow((1 - con) / (1 + con), e / 2); 3592 dphi = Math.PI / 2 - 2 * Math.atan(ts * con) - phi; 3593 phi += dphi 3594 } 3595 return new LatLng(phi * d, point.x * d / r) 3596 } 3597 }; 3598 var index = (Object.freeze || Object)({ 3599 LonLat: LonLat, 3600 Mercator: Mercator, 3601 SphericalMercator: SphericalMercator 3602 }); 3603 var EPSG3395 = extend({}, Earth, { 3604 code: 'EPSG:3395', 3605 projection: Mercator, 3606 transformation: (function () { 3607 var scale = 0.5 / (Math.PI * Mercator.R); 3608 return toTransformation(scale, 0.5, -scale, 0.5) 3609 }()) 3610 }); 3611 var EPSG4326 = extend({}, Earth, { 3612 code: 'EPSG:4326', 3613 projection: LonLat, 3614 transformation: toTransformation(1 / 180, 1, -1 / 180, 0.5) 3615 }); 3616 var Simple = extend({}, CRS, { 3617 projection: LonLat, 3618 transformation: toTransformation(1, 0, -1, 0), 3619 scale: function (zoom) { 3620 return Math.pow(2, zoom) 3621 }, 3622 zoom: function (scale) { 3623 return Math.log(scale) / Math.LN2 3624 }, 3625 distance: function (latlng1, latlng2) { 3626 var dx = latlng2.lng - latlng1.lng 3627 , dy = latlng2.lat - latlng1.lat; 3628 return Math.sqrt(dx * dx + dy * dy) 3629 }, 3630 infinite: !0 3631 }); 3632 CRS.Earth = Earth; 3633 CRS.EPSG3395 = EPSG3395; 3634 CRS.EPSG3857 = EPSG3857; 3635 CRS.EPSG900913 = EPSG900913; 3636 CRS.EPSG4326 = EPSG4326; 3637 CRS.Simple = Simple; 3638 var Layer = Evented.extend({ 3639 options: { 3640 pane: 'overlayPane', 3641 attribution: null, 3642 bubblingMouseEvents: !0 3643 }, 3644 addTo: function (leaflet) { 3645 leaflet.addLayer(this); 3646 return this 3647 }, 3648 remove: function () { 3649 return this.removeFrom(this._map || this._mapToAdd) 3650 }, 3651 removeFrom: function (obj) { 3652 if (obj) { 3653 obj.removeLayer(this) 3654 } 3655 return this 3656 }, 3657 getPane: function (name) { 3658 return this._map.getPane(name ? (this.options[name] || name) : this.options.pane) 3659 }, 3660 addInteractiveTarget: function (targetEl) { 3661 this._map._targets[stamp(targetEl)] = this; 3662 return this 3663 }, 3664 removeInteractiveTarget: function (targetEl) { 3665 delete this._map._targets[stamp(targetEl)]; 3666 return this 3667 }, 3668 getAttribution: function () { 3669 return this.options.attribution 3670 }, 3671 _layerAdd: function (e) { 3672 var leaflet = e.target; 3673 if (!leaflet.hasLayer(this)) { 3674 return 3675 } 3676 this._map = leaflet; 3677 this._zoomAnimated = leaflet._zoomAnimated; 3678 if (this.getEvents) { 3679 var events = this.getEvents(); 3680 leaflet.on(events, this); 3681 this.once('remove', function () { 3682 leaflet.off(events, this) 3683 }, this) 3684 } 3685 this.onAdd(leaflet); 3686 if (this.getAttribution && leaflet.attributionControl) { 3687 leaflet.attributionControl.addAttribution(this.getAttribution()) 3688 } 3689 this.fire('add'); 3690 leaflet.fire('layeradd', { 3691 layer: this 3692 }) 3693 } 3694 }); 3695 Map.include({ 3696 addLayer: function (layer) { 3697 if (!layer._layerAdd) { 3698 throw new Error('The provided object is not a Layer.') 3699 } 3700 var id = stamp(layer); 3701 if (this._layers[id]) { 3702 return this 3703 } 3704 this._layers[id] = layer; 3705 layer._mapToAdd = this; 3706 if (layer.beforeAdd) { 3707 layer.beforeAdd(this) 3708 } 3709 this.whenReady(layer._layerAdd, layer); 3710 return this 3711 }, 3712 removeLayer: function (layer) { 3713 var id = stamp(layer); 3714 if (!this._layers[id]) { 3715 return this 3716 } 3717 if (this._loaded) { 3718 layer.onRemove(this) 3719 } 3720 if (layer.getAttribution && this.attributionControl) { 3721 this.attributionControl.removeAttribution(layer.getAttribution()) 3722 } 3723 delete this._layers[id]; 3724 if (this._loaded) { 3725 this.fire('layerremove', { 3726 layer: layer 3727 }); 3728 layer.fire('remove') 3729 } 3730 layer._map = layer._mapToAdd = null; 3731 return this 3732 }, 3733 hasLayer: function (layer) { 3734 return !!layer && (stamp(layer) in this._layers) 3735 }, 3736 eachLayer: function (method, context) { 3737 for (var i in this._layers) { 3738 method.call(context, this._layers[i]) 3739 } 3740 return this 3741 }, 3742 _addLayers: function (layers) { 3743 layers = layers ? (isArray(layers) ? layers : [layers]) : []; 3744 for (var i = 0, len = layers.length; i < len; i++) { 3745 this.addLayer(layers[i]) 3746 } 3747 },
3748 _addZoomLimit: function (layer) { 3749 if (isNaN(layer.options.maxZoom) || !isNaN(layer.options.minZoom)) { 3750 this._zoomBoundLayers[stamp(layer)] = layer; 3751 this._updateZoomLevels() 3752 } 3753 }, 3754 _removeZoomLimit: function (layer) { 3755 var id = stamp(layer); 3756 if (this._zoomBoundLayers[id]) { 3757 delete this._zoomBoundLayers[id]; 3758 this._updateZoomLevels() 3759 } 3760 }, 3761 _updateZoomLevels: function () { 3762 var minZoom = Infinity 3763 , maxZoom = -Infinity 3764 , oldZoomSpan = this._getZoomSpan(); 3765 for (var i in this._zoomBoundLayers) { 3766 var options = this._zoomBoundLayers[i].options; 3767 minZoom = options.minZoom === undefined ? minZoom : Math.min(minZoom, options.minZoom); 3768 maxZoom = options.maxZoom === undefined ? maxZoom : Math.max(maxZoom, options.maxZoom) 3769 } 3770 this._layersMaxZoom = maxZoom === -Infinity ? undefined : maxZoom; 3771 this._layersMinZoom = minZoom === Infinity ? undefined : minZoom; 3772 if (oldZoomSpan !== this._getZoomSpan()) { 3773 this.fire('zoomlevelschange') 3774 } 3775 if (this.options.maxZoom === undefined && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) { 3776 this.setZoom(this._layersMaxZoom) 3777 } 3778 if (this.options.minZoom === undefined && this._layersMinZoom && this.getZoom() < this._layersMinZoom) { 3779 this.setZoom(this._layersMinZoom) 3780 } 3781 } 3782 }); 3783 var LayerGroup = Layer.extend({ 3784 initialize: function (layers, options) { 3785 setOptions(this, options); 3786 this._layers = {}; 3787 var i, len; 3788 if (layers) { 3789 for (i = 0, 3790 len = layers.length; i < len; i++) { 3791 this.addLayer(layers[i]) 3792 } 3793 } 3794 }, 3795 addLayer: function (layer) { 3796 var id = this.getLayerId(layer); 3797 this._layers[id] = layer; 3798 if (this._map) { 3799 this._map.addLayer(layer) 3800 } 3801 return this 3802 }, 3803 removeLayer: function (layer) { 3804 var id = layer in this._layers ? layer : this.getLayerId(layer); 3805 if (this._map && this._layers[id]) { 3806 this._map.removeLayer(this._layers[id]) 3807 } 3808 delete this._layers[id]; 3809 return this 3810 }, 3811 hasLayer: function (layer) { 3812 return !!layer && (layer in this._layers || this.getLayerId(layer) in this._layers) 3813 }, 3814 clearLayers: function () { 3815 return this.eachLayer(this.removeLayer, this) 3816 }, 3817 invoke: function (methodName) { 3818 var args = Array.prototype.slice.call(arguments, 1), i, layer; 3819 for (i in this._layers) { 3820 layer = this._layers[i]; 3821 if (layer[methodName]) { 3822 layer[methodName].apply(layer, args) 3823 } 3824 } 3825 return this 3826 }, 3827 onAdd: function (leaflet) { 3828 this.eachLayer(leaflet.addLayer, leaflet) 3829 }, 3830 onRemove: function (leaflet) { 3831 this.eachLayer(leaflet.removeLayer, leaflet) 3832 }, 3833 eachLayer: function (method, context) { 3834 for (var i in this._layers) { 3835 method.call(context, this._layers[i]) 3836 } 3837 return this 3838 }, 3839 getLayer: function (id) { 3840 return this._layers[id] 3841 }, 3842 getLayers: function () { 3843 var layers = []; 3844 this.eachLayer(layers.push, layers); 3845 return layers 3846 }, 3847 setZIndex: function (zIndex) { 3848 return this.invoke('setZIndex', zIndex) 3849 }, 3850 getLayerId: function (layer) { 3851 return stamp(layer) 3852 } 3853 }); 3854 var layerGroup = function (layers, options) { 3855 return new LayerGroup(layers, options) 3856 }; 3857 var FeatureGroup = LayerGroup.extend({ 3858 addLayer: function (layer) { 3859 if (this.hasLayer(layer)) { 3860 return this 3861 } 3862 layer.addEventParent(this); 3863 LayerGroup.prototype.addLayer.call(this, layer); 3864 return this.fire('layeradd', { 3865 layer: layer 3866 }) 3867 }, 3868 removeLayer: function (layer) { 3869 if (!this.hasLayer(layer)) { 3870 return this 3871 } 3872 if (layer in this._layers) { 3873 layer = this._layers[layer] 3874 } 3875 layer.removeEventParent(this); 3876 LayerGroup.prototype.removeLayer.call(this, layer); 3877 return this.fire('layerremove', { 3878 layer: layer 3879 }) 3880 }, 3881 setStyle: function (style) { 3882 return this.invoke('setStyle', style) 3883 }, 3884 bringToFront: function () { 3885 return this.invoke('bringToFront') 3886 }, 3887 bringToBack: function () { 3888 return this.invoke('bringToBack') 3889 }, 3890 getBounds: function () {
3891 var bounds = new LatLngBounds(); 3892 for (var id in this._layers) { 3893 var layer = this._layers[id]; 3894 bounds.extend(layer.getBounds ? layer.getBounds() : layer.getLatLng()) 3895 } 3896 return bounds 3897 } 3898 }); 3899 var featureGroup = function (layers) { 3900 return new FeatureGroup(layers) 3901 }; 3902 var Icon = Class.extend({ 3903 options: { 3904 popupAnchor: [0, 0], 3905 tooltipAnchor: [0, 0], 3906 }, 3907 initialize: function (options) { 3908 setOptions(this, options) 3909 }, 3910 createIcon: function (oldIcon) { 3911 return this._createIcon('icon', oldIcon) 3912 }, 3913 createShadow: function (oldIcon) { 3914 return this._createIcon('shadow', oldIcon) 3915 }, 3916 _createIcon: function (name, oldIcon) { 3917 3918 var src = this._getIconUrl(name); 3919 if (!src) { 3920 if (name === 'icon') { 3921 throw new Error('iconUrl not set in Icon options (see the docs).') 3922 } 3923 return null 3924 } 3925 var img = this._createImg(src, oldIcon && oldIcon.tagName === 'IMG' ? oldIcon : null); 3926 this._setIconStyles(img, name); 3927 return img 3928 }, 3929 _setIconStyles: function (img, name) { 3930 var options = this.options; 3931 var sizeOption = options[name + 'Size']; 3932 if (typeof sizeOption === 'number') { 3933 sizeOption = [sizeOption, sizeOption] 3934 } 3935 var size = toPoint(sizeOption) 3936 , anchor = toPoint(name === 'shadow' && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, !0)); 3937 img.className = 'leaflet-marker-' + name + ' ' + (options.className || ''); 3938 if (anchor) { 3939 img.style.marginLeft = (-anchor.x) + 'px'; 3940 img.style.marginTop = (-anchor.y) + 'px' 3941 } 3942 if (size) { 3943 img.style.width = size.x + 'px'; 3944 img.style.height = size.y + 'px' 3945 } 3946 }, 3947 _createImg: function (src, el) { 3948 el = el || document.createElement('img'); 3949 el.src = src; 3950 return el 3951 }, 3952 _getIconUrl: function (name) { 3953 return retina && this.options[name + 'RetinaUrl'] || this.options[name + 'Url'] 3954 } 3955 }); 3956 function icon(options) { 3957 return new Icon(options) 3958 } 3959 var IconDefault = Icon.extend({ 3960 options: { 3961 iconUrl: 'marker-icon.png', 3962 iconRetinaUrl: 'marker-icon-2x.png', 3963 shadowUrl: 'marker-shadow.png', 3964 iconSize: [25, 41], 3965 iconAnchor: [12, 41], 3966 popupAnchor: [1, -34], 3967 tooltipAnchor: [16, -28], 3968 shadowSize: [41, 41] 3969 }, 3970 _getIconUrl: function (name) { 3971 3972 if (!IconDefault.imagePath) { 3973 IconDefault.imagePath = this._detectIconPath() 3974 } 3975 return (this.options.imagePath || IconDefault.imagePath) + Icon.prototype._getIconUrl.call(this, name) 3976 }, 3977 _detectIconPath: function () { 3978 var el = create$1('div', 'leaflet-default-icon-path', document.body); 3979 var path = getStyle(el, 'background-image') || getStyle(el, 'backgroundImage'); 3980 document.body.removeChild(el); 3981 if (path === null || path.indexOf('url') !== 0) { 3982 path = '' 3983 } else { 3984 path = path.replace(/^url\(["']?/, '').replace(/marker-icon\.png["']?\)$/, '') 3985 } 3986 return path 3987 } 3988 }); 3989 var MarkerDrag = Handler.extend({ 3990 initialize: function (marker) { 3991 this._marker = marker 3992 }, 3993 addHooks: function () { 3994 var icon = this._marker._icon; 3995 if (!this._draggable) { 3996 this._draggable = new Draggable(icon, icon, !0) 3997 } 3998 this._draggable.on({ 3999 dragstart: this._onDragStart, 4000 predrag: this._onPreDrag, 4001 drag: this._onDrag, 4002 dragend: this._onDragEnd 4003 }, this).enable(); 4004 addClass(icon, 'leaflet-marker-draggable') 4005 }, 4006 removeHooks: function () { 4007 this._draggable.off({ 4008 dragstart: this._onDragStart, 4009 predrag: this._onPreDrag, 4010 drag: this._onDrag, 4011 dragend: this._onDragEnd 4012 }, this).disable(); 4013 if (this._marker._icon) { 4014 removeClass(this._marker._icon, 'leaflet-marker-draggable') 4015 } 4016 }, 4017 moved: function () { 4018 return this._draggable && this._draggable._moved 4019 }, 4020 _adjustPan: function (e) { 4021 var marker = this._marker 4022 , leaflet = marker._map 4023 , speed = this._marker.options.autoPanSpeed 4024 , padding = this._marker.options.autoPanPadding 4025 , iconPos = getPosition(marker._icon) 4026 , bounds = leaflet.getPixelBounds() 4027 , origin = leaflet.getPixelOrigin(); 4028 var panBounds = toBounds(bounds.min._subtract(origin).add(padding), bounds.max._subtract(origin).subtract(padding)); 4029 if (!panBounds.contains(iconPos)) { 4030 var movement = toPoint((Math.max(panBounds.max.x, iconPos.x) - panBounds.max.x) / (bounds.max.x - panBounds.max.x) - (Math.min(panBounds.min.x, iconPos.x) - panBounds.min.x) / (bounds.min.x - panBounds.min.x), (Math.max(panBounds.max.y, iconPos.y) - panBounds.max.y) / (bounds.max.y - panBounds.max.y) - (Math.min(panBounds.min.y, iconPos.y) - panBounds.min.y) / (bounds.min.y - panBounds.min.y)).multiplyBy(speed); 4031 leaflet.panBy(movement, { 4032 animate: !1 4033 }); 4034 this._draggable._newPos._add(movement); 4035 this._draggable._startPos._add(movement); 4036 setPosition(marker._icon, this._draggable._newPos); 4037 this._onDrag(e);
4038 this._panRequest = requestAnimFrame(this._adjustPan.bind(this, e)) 4039 } 4040 }, 4041 _onDragStart: function () { 4042 this._oldLatLng = this._marker.getLatLng(); 4043 this._marker.closePopup().fire('movestart').fire('dragstart') 4044 }, 4045 _onPreDrag: function (e) { 4046 if (this._marker.options.autoPan) { 4047 cancelAnimFrame(this._panRequest); 4048 this._panRequest = requestAnimFrame(this._adjustPan.bind(this, e)) 4049 } 4050 }, 4051 _onDrag: function (e) { 4052 var marker = this._marker 4053 , shadow = marker._shadow 4054 , iconPos = getPosition(marker._icon) 4055 , latlng = marker._map.layerPointToLatLng(iconPos); 4056 if (shadow) { 4057 setPosition(shadow, iconPos) 4058 } 4059 marker._latlng = latlng; 4060 e.latlng = latlng; 4061 e.oldLatLng = this._oldLatLng; 4062 marker.fire('move', e).fire('drag', e) 4063 }, 4064 _onDragEnd: function (e) { 4065 cancelAnimFrame(this._panRequest); 4066 delete this._oldLatLng; 4067 this._marker.fire('moveend').fire('dragend', e) 4068 } 4069 }); 4070 var Marker = Layer.extend({ 4071 options: { 4072 icon: new IconDefault(), 4073 interactive: !0, 4074 draggable: !1, 4075 autoPan: !1, 4076 autoPanPadding: [50, 50], 4077 autoPanSpeed: 10, 4078 keyboard: !0, 4079 title: '', 4080 alt: '', 4081 zIndexOffset: 0, 4082 opacity: 1, 4083 riseOnHover: !1, 4084 riseOffset: 250, 4085 pane: 'markerPane', 4086 bubblingMouseEvents: !1 4087 }, 4088 initialize: function (latlng, options) { 4089 setOptions(this, options); 4090 this._latlng = toLatLng(latlng) 4091 }, 4092 onAdd: function (leaflet) { 4093 this._zoomAnimated = this._zoomAnimated && leaflet.options.markerZoomAnimation; 4094 if (this._zoomAnimated) { 4095 leaflet.on('zoomanim', this._animateZoom, this) 4096 } 4097 this._initIcon(); 4098 this.update() 4099 }, 4100 onRemove: function (leaflet) { 4101 if (this.dragging && this.dragging.enabled()) { 4102 this.options.draggable = !0; 4103 this.dragging.removeHooks() 4104 } 4105 delete this.dragging; 4106 if (this._zoomAnimated) { 4107 leaflet.off('zoomanim', this._animateZoom, this) 4108 } 4109 this._removeIcon(); 4110 this._removeShadow() 4111 }, 4112 getEvents: function () { 4113 return { 4114 zoom: this.update, 4115 viewreset: this.update 4116 } 4117 }, 4118 getLatLng: function () { 4119 return this._latlng 4120 }, 4121 setLatLng: function (latlng) { 4122 var oldLatLng = this._latlng; 4123 this._latlng = toLatLng(latlng); 4124 this.update(); 4125 return this.fire('move', { 4126 oldLatLng: oldLatLng, 4127 latlng: this._latlng 4128 }) 4129 }, 4130 setZIndexOffset: function (offset) { 4131 this.options.zIndexOffset = offset; 4132 return this.update() 4133 }, 4134 setIcon: function (icon) { 4135 this.options.icon = icon; 4136 if (this._map) { 4137 this._initIcon(); 4138 this.update() 4139 } 4140 if (this._popup) { 4141 this.bindPopup(this._popup, this._popup.options) 4142 } 4143 return this 4144 }, 4145 getElement: function () { 4146 return this._icon 4147 }, 4148 update: function () { 4149 if (this._icon && this._map) { 4150 var pos = this._map.latLngToLayerPoint(this._latlng).round(); 4151 this._setPos(pos) 4152 } 4153 return this 4154 }, 4155 _initIcon: function () { 4156 var options = this.options 4157 , classToAdd = 'leaflet-zoom-' + (this._zoomAnimated ? 'animated' : 'hide'); 4158 var icon = options.icon.createIcon(this._icon) 4159 , addIcon = !1; 4160 if (icon !== this._icon) { 4161 if (this._icon) { 4162 this._removeIcon() 4163 } 4164 addIcon = !0; 4165 if (options.title) { 4166 icon.title = options.title 4167 } 4168 if (icon.tagName === 'IMG') { 4169 icon.alt = options.alt || '' 4170 } 4171 } 4172 addClass(icon, classToAdd); 4173 if (options.keyboard) { 4174 icon.tabIndex = '0' 4175 } 4176 this._icon = icon; 4177 if (options.riseOnHover) { 4178 this.on({ 4179 mouseover: this._bringToFront, 4180 mouseout: this._resetZIndex 4181 }) 4182 } 4183 var newShadow = options.icon.createShadow(this._shadow) 4184 , addShadow = !1; 4185 if (newShadow !== this._shadow) { 4186 this._removeShadow(); 4187 addShadow = !0 4188 } 4189 if (newShadow) { 4190 addClass(newShadow, classToAdd); 4191 newShadow.alt = '' 4192 } 4193 this._shadow = newShadow; 4194 if (options.opacity < 1) { 4195 this._updateOpacity() 4196 } 4197 if (addIcon) { 4198 this.getPane().appendChild(this._icon) 4199 } 4200 this._initInteraction(); 4201 if (newShadow && addShadow) { 4202 this.getPane('shadowPane').appendChild(this._shadow) 4203 } 4204 }, 4205 _removeIcon: function () { 4206 if (this.options.riseOnHover) { 4207 this.off({ 4208 mouseover: this._bringToFront, 4209 mouseout: this._resetZIndex 4210 }) 4211 } 4212 remove(this._icon); 4213 this.removeInteractiveTarget(this._icon); 4214 this._icon = null 4215 }, 4216 _removeShadow: function () { 4217 if (this._shadow) { 4218 remove(this._shadow) 4219 } 4220 this._shadow = null 4221 }, 4222 _setPos: function (pos) { 4223 setPosition(this._icon, pos); 4224 if (this._shadow) { 4225 setPosition(this._shadow, pos) 4226 } 4227 this._zIndex = pos.y + this.options.zIndexOffset; 4228 this._resetZIndex() 4229 }, 4230 _updateZIndex: function (offset) { 4231 this._icon.style.zIndex = this._zIndex + offset 4232 }, 4233 _animateZoom: function (opt) { 4234 var pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center).round(); 4235 this._setPos(pos) 4236 }, 4237 _initInteraction: function () { 4238 if (!this.options.interactive) { 4239 return 4240 } 4241 addClass(this._icon, 'leaflet-interactive'); 4242 this.addInteractiveTarget(this._icon); 4243 if (MarkerDrag) { 4244 var draggable = this.options.draggable; 4245 if (this.dragging) { 4246 draggable = this.dragging.enabled(); 4247 this.dragging.disable() 4248 } 4249 this.dragging = new MarkerDrag(this); 4250 if (draggable) { 4251 this.dragging.enable() 4252 } 4253 } 4254 }, 4255 setOpacity: function (opacity) { 4256 this.options.opacity = opacity; 4257 if (this._map) { 4258 this._updateOpacity() 4259 } 4260 return this 4261 }, 4262 _updateOpacity: function () { 4263 var opacity = this.options.opacity; 4264 setOpacity(this._icon, opacity); 4265 if (this._shadow) { 4266 setOpacity(this._shadow, opacity) 4267 } 4268 }, 4269 _bringToFront: function () { 4270 this._updateZIndex(this.options.riseOffset) 4271 }, 4272 _resetZIndex: function () { 4273 this._updateZIndex(0) 4274 }, 4275 _getPopupAnchor: function () { 4276 return this.options.icon.options.popupAnchor 4277 }, 4278 _getTooltipAnchor: function () { 4279 return this.options.icon.options.tooltipAnchor 4280 } 4281 }); 4282 function marker(latlng, options) { 4283 4284 return new Marker(latlng, options) 4285 }
4286 var Path = Layer.extend({ 4287 options: { 4288 stroke: !0, 4289 color: '#3388ff', 4290 weight: 3, 4291 opacity: 1, 4292 lineCap: 'round', 4293 lineJoin: 'round', 4294 dashArray: null, 4295 dashOffset: null, 4296 fill: !1, 4297 fillColor: null, 4298 fillOpacity: 0.2, 4299 fillRule: 'evenodd', 4300 interactive: !0, 4301 bubblingMouseEvents: !0 4302 }, 4303 beforeAdd: function (leaflet) { 4304 this._renderer = leaflet.getRenderer(this) 4305 }, 4306 onAdd: function () { 4307 this._renderer._initPath(this); 4308 this._reset(); 4309 this._renderer._addPath(this) 4310 }, 4311 onRemove: function () { 4312 this._renderer._removePath(this) 4313 }, 4314 redraw: function () { 4315 if (this._map) { 4316 this._renderer._updatePath(this) 4317 } 4318 return this 4319 }, 4320 setStyle: function (style) { 4321 setOptions(this, style); 4322 if (this._renderer) { 4323 this._renderer._updateStyle(this) 4324 } 4325 return this 4326 }, 4327 bringToFront: function () { 4328 if (this._renderer) { 4329 this._renderer._bringToFront(this) 4330 } 4331 return this 4332 }, 4333 bringToBack: function () { 4334 if (this._renderer) { 4335 this._renderer._bringToBack(this) 4336 } 4337 return this 4338 }, 4339 getElement: function () { 4340 return this._path 4341 }, 4342 _reset: function () { 4343 this._project(); 4344 this._update() 4345 }, 4346 _clickTolerance: function () { 4347 return (this.options.stroke ? this.options.weight / 2 : 0) + this._renderer.options.tolerance 4348 } 4349 }); 4350 var CircleMarker = Path.extend({ 4351 options: { 4352 fill: !0, 4353 radius: 10 4354 }, 4355 initialize: function (latlng, options) { 4356 setOptions(this, options); 4357 this._latlng = toLatLng(latlng); 4358 this._radius = this.options.radius 4359 }, 4360 setLatLng: function (latlng) { 4361 this._latlng = toLatLng(latlng); 4362 this.redraw(); 4363 return this.fire('move', { 4364 latlng: this._latlng 4365 }) 4366 }, 4367 getLatLng: function () { 4368 return this._latlng 4369 }, 4370 setRadius: function (radius) { 4371 this.options.radius = this._radius = radius; 4372 return this.redraw() 4373 }, 4374 getRadius: function () { 4375 return this._radius 4376 }, 4377 setStyle: function (options) { 4378 var radius = options && options.radius || this._radius; 4379 Path.prototype.setStyle.call(this, options); 4380 this.setRadius(radius); 4381 return this 4382 }, 4383 _project: function () { 4384 this._point = this._map.latLngToLayerPoint(this._latlng); 4385 this._updateBounds() 4386 }, 4387 _updateBounds: function () { 4388 var r = this._radius 4389 , r2 = this._radiusY || r 4390 , w = this._clickTolerance() 4391 , p = [r + w, r2 + w]; 4392 this._pxBounds = new Bounds(this._point.subtract(p), this._point.add(p)) 4393 }, 4394 _update: function () { 4395 if (this._map) { 4396 this._updatePath() 4397 } 4398 }, 4399 _updatePath: function () { 4400 this._renderer._updateCircle(this) 4401 }, 4402 _empty: function () { 4403 return this._radius && !this._renderer._bounds.intersects(this._pxBounds) 4404 }, 4405 _containsPoint: function (p) { 4406 return p.distanceTo(this._point) <= this._radius + this._clickTolerance() 4407 } 4408 }); 4409 function circleMarker(latlng, options) { 4410 return new CircleMarker(latlng, options) 4411 } 4412 var Circle = CircleMarker.extend({ 4413 initialize: function (latlng, options, legacyOptions) { 4414 if (typeof options === 'number') { 4415 options = extend({}, legacyOptions, { 4416 radius: options 4417 }) 4418 } 4419 setOptions(this, options); 4420 this._latlng = toLatLng(latlng); 4421 if (isNaN(this.options.radius)) { 4422 throw new Error('Circle radius cannot be NaN') 4423 } 4424 this._mRadius = this.options.radius 4425 }, 4426 setRadius: function (radius) { 4427 this._mRadius = radius; 4428 return this.redraw() 4429 }, 4430 getRadius: function () { 4431 return this._mRadius 4432 }, 4433 getBounds: function () { 4434 var half = [this._radius, this._radiusY || this._radius];
4435 return new LatLngBounds(this._map.layerPointToLatLng(this._point.subtract(half)), this._map.layerPointToLatLng(this._point.add(half))) 4436 }, 4437 setStyle: Path.prototype.setStyle, 4438 _project: function () { 4439 var lng = this._latlng.lng 4440 , lat = this._latlng.lat 4441 , leaflet = this._map 4442 , crs = leaflet.options.crs; 4443 if (crs.distance === Earth.distance) { 4444 var d = Math.PI / 180 4445 , latR = (this._mRadius / Earth.R) / d 4446 , top = leaflet.project([lat + latR, lng]) 4447 , bottom = leaflet.project([lat - latR, lng]) 4448 , p = top.add(bottom).divideBy(2) 4449 , lat2 = leaflet.unproject(p).lat 4450 , lngR = Math.acos((Math.cos(latR * d) - Math.sin(lat * d) * Math.sin(lat2 * d)) / (Math.cos(lat * d) * Math.cos(lat2 * d))) / d; 4451 if (isNaN(lngR) || lngR === 0) { 4452 lngR = latR / Math.cos(Math.PI / 180 * lat) 4453 } 4454 this._point = p.subtract(leaflet.getPixelOrigin()); 4455 this._radius = isNaN(lngR) ? 0 : p.x - leaflet.project([lat2, lng - lngR]).x; 4456 this._radiusY = p.y - top.y 4457 } else { 4458 var latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._mRadius, 0])); 4459 this._point = leaflet.latLngToLayerPoint(this._latlng); 4460 this._radius = this._point.x - leaflet.latLngToLayerPoint(latlng2).x 4461 } 4462 this._updateBounds() 4463 } 4464 }); 4465 function circle(latlng, options, legacyOptions) { 4466 return new Circle(latlng, options, legacyOptions) 4467 } 4468 var Polyline = Path.extend({ 4469 options: { 4470 smoothFactor: 1.0, 4471 noClip: !1 4472 }, 4473 initialize: function (latlngs, options) { 4474 setOptions(this, options); 4475 this._setLatLngs(latlngs) 4476 }, 4477 getLatLngs: function () { 4478 return this._latlngs 4479 }, 4480 setLatLngs: function (latlngs) { 4481 this._setLatLngs(latlngs); 4482 return this.redraw() 4483 }, 4484 isEmpty: function () { 4485 return !this._latlngs.length 4486 }, 4487 closestLayerPoint: function (p) { 4488 var minDistance = Infinity, minPoint = null, closest = _sqClosestPointOnSegment, p1, p2; 4489 for (var j = 0, jLen = this._parts.length; j < jLen; j++) { 4490 var points = this._parts[j]; 4491 for (var i = 1, len = points.length; i < len; i++) { 4492 p1 = points[i - 1]; 4493 p2 = points[i]; 4494 var sqDist = closest(p, p1, p2, !0); 4495 if (sqDist < minDistance) { 4496 minDistance = sqDist; 4497 minPoint = closest(p, p1, p2) 4498 } 4499 } 4500 } 4501 if (minPoint) { 4502 minPoint.distance = Math.sqrt(minDistance) 4503 } 4504 return minPoint 4505 }, 4506 getCenter: function () { 4507 if (!this._map) { 4508 throw new Error('Must add layer to leaflet before using getCenter()') 4509 } 4510 var i, halfDist, segDist, dist, p1, p2, ratio, points = this._rings[0], len = points.length; 4511 if (!len) { 4512 return null 4513 } 4514 for (i = 0, 4515 halfDist = 0; i < len - 1; i++) { 4516 halfDist += points[i].distanceTo(points[i + 1]) / 2 4517 } 4518 if (halfDist === 0) { 4519 return this._map.layerPointToLatLng(points[0]) 4520 } 4521 for (i = 0, 4522 dist = 0; i < len - 1; i++) { 4523 p1 = points[i]; 4524 p2 = points[i + 1]; 4525 segDist = p1.distanceTo(p2); 4526 dist += segDist; 4527 if (dist > halfDist) { 4528 ratio = (dist - halfDist) / segDist; 4529 return this._map.layerPointToLatLng([p2.x - ratio * (p2.x - p1.x), p2.y - ratio * (p2.y - p1.y)]) 4530 } 4531 } 4532 }, 4533 getBounds: function () { 4534 return this._bounds 4535 }, 4536 addLatLng: function (latlng, latlngs) { 4537 latlngs = latlngs || this._defaultShape(); 4538 latlng = toLatLng(latlng); 4539 latlngs.push(latlng); 4540 this._bounds.extend(latlng); 4541 return this.redraw() 4542 }, 4543 _setLatLngs: function (latlngs) { 4544 this._bounds = new LatLngBounds(); 4545 this._latlngs = this._convertLatLngs(latlngs) 4546 }, 4547 _defaultShape: function () { 4548 return isFlat(this._latlngs) ? this._latlngs : this._latlngs[0] 4549 }, 4550 _convertLatLngs: function (latlngs) { 4551 var result = [] 4552 , flat = isFlat(latlngs); 4553 for (var i = 0, len = latlngs.length; i < len; i++) { 4554 if (flat) { 4555 result[i] = toLatLng(latlngs[i]); 4556 this._bounds.extend(result[i]) 4557 } else { 4558 result[i] = this._convertLatLngs(latlngs[i]) 4559 } 4560 } 4561 return result 4562 }, 4563 _project: function () { 4564 var pxBounds = new Bounds(); 4565 this._rings = []; 4566 this._projectLatlngs(this._latlngs, this._rings, pxBounds); 4567 var w = this._clickTolerance() 4568 , p = new Point(w, w); 4569 if (this._bounds.isValid() && pxBounds.isValid()) { 4570 pxBounds.min._subtract(p); 4571 pxBounds.max._add(p); 4572 this._pxBounds = pxBounds 4573 } 4574 }, 4575 _projectLatlngs: function (latlngs, result, projectedBounds) { 4576 var flat = latlngs[0] instanceof LatLng, len = latlngs.length, i, ring; 4577 if (flat) { 4578 ring = []; 4579 for (i = 0; i < len; i++) { 4580 ring[i] = this._map.latLngToLayerPoint(latlngs[i]); 4581 projectedBounds.extend(ring[i]) 4582 } 4583 result.push(ring) 4584 } else { 4585 for (i = 0; i < len; i++) { 4586 this._projectLatlngs(latlngs[i], result, projectedBounds) 4587 } 4588 } 4589 }, 4590 _clipPoints: function () { 4591 var bounds = this._renderer._bounds; 4592 this._parts = []; 4593 if (!this._pxBounds || !this._pxBounds.intersects(bounds)) { 4594 return 4595 } 4596 if (this.options.noClip) { 4597 this._parts = this._rings; 4598 return 4599 } 4600 var parts = this._parts, i, j, k, len, len2, segment, points; 4601 for (i = 0, 4602 k = 0, 4603 len = this._rings.length; i < len; i++) { 4604 points = this._rings[i]; 4605 for (j = 0, 4606 len2 = points.length; j < len2 - 1; j++) { 4607 segment = clipSegment(points[j], points[j + 1], bounds, j, !0); 4608 if (!segment) { 4609 continue 4610 } 4611 parts[k] = parts[k] || []; 4612 parts[k].push(segment[0]); 4613 if ((segment[1] !== points[j + 1]) || (j === len2 - 2)) { 4614 parts[k].push(segment[1]); 4615 k++ 4616 } 4617 } 4618 } 4619 }, 4620 _simplifyPoints: function () { 4621 var parts = this._parts 4622 , tolerance = this.options.smoothFactor; 4623 for (var i = 0, len = parts.length; i < len; i++) { 4624 parts[i] = simplify(parts[i], tolerance) 4625 } 4626 }, 4627 _update: function () { 4628 if (!this._map) { 4629 return 4630 } 4631 this._clipPoints();
4632 this._simplifyPoints(); 4633 this._updatePath() 4634 }, 4635 _updatePath: function () { 4636 this._renderer._updatePoly(this) 4637 }, 4638 _containsPoint: function (p, closed) { 4639 var i, j, k, len, len2, part, w = this._clickTolerance(); 4640 if (!this._pxBounds || !this._pxBounds.contains(p)) { 4641 return !1 4642 } 4643 for (i = 0, 4644 len = this._parts.length; i < len; i++) { 4645 part = this._parts[i]; 4646 for (j = 0, 4647 len2 = part.length, 4648 k = len2 - 1; j < len2; k = j++) { 4649 if (!closed && (j === 0)) { 4650 continue 4651 } 4652 if (pointToSegmentDistance(p, part[k], part[j]) <= w) { 4653 return !0 4654 } 4655 } 4656 } 4657 return !1 4658 } 4659 }); 4660 function polyline(latlngs, options) { 4661 return new Polyline(latlngs, options) 4662 } 4663 Polyline._flat = _flat; 4664 var Polygon = Polyline.extend({ 4665 options: { 4666 fill: !0 4667 }, 4668 isEmpty: function () { 4669 return !this._latlngs.length || !this._latlngs[0].length 4670 }, 4671 getCenter: function () { 4672 if (!this._map) { 4673 throw new Error('Must add layer to leaflet before using getCenter()') 4674 } 4675 var i, j, p1, p2, f, area, x, y, center, points = this._rings[0], len = points.length; 4676 if (!len) { 4677 return null 4678 } 4679 area = x = y = 0; 4680 for (i = 0, 4681 j = len - 1; i < len; j = i++) { 4682 p1 = points[i]; 4683 p2 = points[j]; 4684 f = p1.y * p2.x - p2.y * p1.x; 4685 x += (p1.x + p2.x) * f; 4686 y += (p1.y + p2.y) * f; 4687 area += f * 3 4688 } 4689 if (area === 0) { 4690 center = points[0] 4691 } else { 4692 center = [x / area, y / area] 4693 } 4694 return this._map.layerPointToLatLng(center) 4695 }, 4696 _convertLatLngs: function (latlngs) { 4697 var result = Polyline.prototype._convertLatLngs.call(this, latlngs) 4698 , len = result.length; 4699 if (len >= 2 && result[0] instanceof LatLng && result[0].equals(result[len - 1])) { 4700 result.pop() 4701 } 4702 return result 4703 }, 4704 _setLatLngs: function (latlngs) { 4705 Polyline.prototype._setLatLngs.call(this, latlngs); 4706 if (isFlat(this._latlngs)) { 4707 this._latlngs = [this._latlngs] 4708 } 4709 }, 4710 _defaultShape: function () { 4711 return isFlat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0] 4712 }, 4713 _clipPoints: function () { 4714 var bounds = this._renderer._bounds 4715 , w = this.options.weight 4716 , p = new Point(w, w); 4717 bounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p)); 4718 this._parts = []; 4719 if (!this._pxBounds || !this._pxBounds.intersects(bounds)) { 4720 return 4721 } 4722 if (this.options.noClip) { 4723 this._parts = this._rings; 4724 return 4725 } 4726 for (var i = 0, len = this._rings.length, clipped; i < len; i++) { 4727 clipped = clipPolygon(this._rings[i], bounds, !0); 4728 if (clipped.length) { 4729 this._parts.push(clipped) 4730 } 4731 } 4732 }, 4733 _updatePath: function () { 4734 this._renderer._updatePoly(this, !0) 4735 }, 4736 _containsPoint: function (p) { 4737 var inside = !1, part, p1, p2, i, j, k, len, len2; 4738 if (!this._pxBounds || !this._pxBounds.contains(p)) { 4739 return !1 4740 } 4741 for (i = 0, 4742 len = this._parts.length; i < len; i++) { 4743 part = this._parts[i]; 4744 for (j = 0, 4745 len2 = part.length, 4746 k = len2 - 1; j < len2; k = j++) { 4747 p1 = part[j]; 4748 p2 = part[k]; 4749 if (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) { 4750 inside = !inside 4751 } 4752 } 4753 } 4754 return inside || Polyline.prototype._containsPoint.call(this, p, !0) 4755 } 4756 }); 4757 function polygon(latlngs, options) { 4758 return new Polygon(latlngs, options) 4759 } 4760 var GeoJSON = FeatureGroup.extend({ 4761 initialize: function (geojson, options) { 4762 setOptions(this, options); 4763 this._layers = {}; 4764 if (geojson) { 4765 this.addData(geojson) 4766 } 4767 }, 4768 addData: function (geojson) { 4769 var features = isArray(geojson) ? geojson : geojson.features, i, len, feature; 4770 if (features) { 4771 for (i = 0, 4772 len = features.length; i < len; i++) { 4773 feature = features[i]; 4774 if (feature.geometries || feature.geometry || feature.features || feature.coordinates) { 4775 this.addData(feature) 4776 } 4777 } 4778 return this 4779 } 4780 var options = this.options; 4781 if (options.filter && !options.filter(geojson)) { 4782 return this 4783 } 4784 var layer = geometryToLayer(geojson, options); 4785 if (!layer) { 4786 return this 4787 } 4788 layer.feature = asFeature(geojson); 4789 layer.defaultOptions = layer.options; 4790 this.resetStyle(layer); 4791 if (options.onEachFeature) { 4792 options.onEachFeature(geojson, layer) 4793 } 4794 return this.addLayer(layer) 4795 }, 4796 resetStyle: function (layer) { 4797 layer.options = extend({}, layer.defaultOptions); 4798 this._setLayerStyle(layer, this.options.style); 4799 return this 4800 }, 4801 setStyle: function (style) { 4802 return this.eachLayer(function (layer) { 4803 this._setLayerStyle(layer, style) 4804 }, this) 4805 }, 4806 _setLayerStyle: function (layer, style) { 4807 if (typeof style === 'function') { 4808 style = style(layer.feature) 4809 } 4810 if (layer.setStyle) { 4811 layer.setStyle(style) 4812 } 4813 } 4814 }); 4815 function geometryToLayer(geojson, options) { 4816 var geometry = geojson.type === 'Feature' ? geojson.geometry : geojson, coords = geometry ? geometry.coordinates : null, layers = [], pointToLayer = options && options.pointToLayer, _coordsToLatLng = options && options.coordsToLatLng || coordsToLatLng, latlng, latlngs, i, len; 4817 if (!coords && !geometry) { 4818 return null 4819 } 4820 switch (geometry.type) { 4821 case 'Point': 4822 latlng = _coordsToLatLng(coords);
4823 return pointToLayer ? pointToLayer(geojson, latlng) : new Marker(latlng); 4824 case 'MultiPoint': 4825 for (i = 0, 4826 len = coords.length; i < len; i++) { 4827 latlng = _coordsToLatLng(coords[i]); 4828 layers.push(pointToLayer ? pointToLayer(geojson, latlng) : new Marker(latlng)) 4829 } 4830 return new FeatureGroup(layers); 4831 case 'LineString': 4832 case 'MultiLineString': 4833 latlngs = coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, _coordsToLatLng); 4834 return new Polyline(latlngs, options); 4835 case 'Polygon': 4836 case 'MultiPolygon': 4837 latlngs = coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, _coordsToLatLng); 4838 return new Polygon(latlngs, options); 4839 case 'GeometryCollection': 4840 for (i = 0, 4841 len = geometry.geometries.length; i < len; i++) { 4842 var layer = geometryToLayer({ 4843 geometry: geometry.geometries[i], 4844 type: 'Feature', 4845 properties: geojson.properties 4846 }, options); 4847 if (layer) { 4848 layers.push(layer) 4849 } 4850 } 4851 return new FeatureGroup(layers); 4852 default: 4853 throw new Error('Invalid GeoJSON object.') 4854 } 4855 } 4856 function coordsToLatLng(coords) { 4857 return new LatLng(coords[1], coords[0], coords[2]) 4858 } 4859 function coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) { 4860 var latlngs = []; 4861 for (var i = 0, len = coords.length, latlng; i < len; i++) { 4862 latlng = levelsDeep ? coordsToLatLngs(coords[i], levelsDeep - 1, _coordsToLatLng) : (_coordsToLatLng || coordsToLatLng)(coords[i]); 4863 latlngs.push(latlng) 4864 } 4865 return latlngs 4866 } 4867 function latLngToCoords(latlng, precision) { 4868 precision = typeof precision === 'number' ? precision : 6; 4869 return latlng.alt !== undefined ? [formatNum(latlng.lng, precision), formatNum(latlng.lat, precision), formatNum(latlng.alt, precision)] : [formatNum(latlng.lng, precision), formatNum(latlng.lat, precision)] 4870 } 4871 function latLngsToCoords(latlngs, levelsDeep, closed, precision) { 4872 var coords = []; 4873 for (var i = 0, len = latlngs.length; i < len; i++) { 4874 coords.push(levelsDeep ? latLngsToCoords(latlngs[i], levelsDeep - 1, closed, precision) : latLngToCoords(latlngs[i], precision)) 4875 } 4876 if (!levelsDeep && closed) { 4877 coords.push(coords[0]) 4878 } 4879 return coords 4880 } 4881 function getFeature(layer, newGeometry) { 4882 return layer.feature ? extend({}, layer.feature, { 4883 geometry: newGeometry 4884 }) : asFeature(newGeometry) 4885 } 4886 function asFeature(geojson) { 4887 if (geojson.type === 'Feature' || geojson.type === 'FeatureCollection') { 4888 return geojson 4889 } 4890 return { 4891 type: 'Feature', 4892 properties: {}, 4893 geometry: geojson 4894 } 4895 } 4896 var PointToGeoJSON = { 4897 toGeoJSON: function (precision) { 4898 return getFeature(this, { 4899 type: 'Point', 4900 coordinates: latLngToCoords(this.getLatLng(), precision) 4901 }) 4902 } 4903 }; 4904 Marker.include(PointToGeoJSON); 4905 Circle.include(PointToGeoJSON); 4906 CircleMarker.include(PointToGeoJSON); 4907 Polyline.include({ 4908 toGeoJSON: function (precision) { 4909 var multi = !isFlat(this._latlngs); 4910 var coords = latLngsToCoords(this._latlngs, multi ? 1 : 0, !1, precision); 4911 return getFeature(this, { 4912 type: (multi ? 'Multi' : '') + 'LineString', 4913 coordinates: coords 4914 }) 4915 } 4916 }); 4917 Polygon.include({ 4918 toGeoJSON: function (precision) { 4919 var holes = !isFlat(this._latlngs) 4920 , multi = holes && !isFlat(this._latlngs[0]); 4921 var coords = latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, !0, precision); 4922 if (!holes) { 4923 coords = [coords] 4924 } 4925 return getFeature(this, { 4926 type: (multi ? 'Multi' : '') + 'Polygon', 4927 coordinates: coords 4928 }) 4929 } 4930 }); 4931 LayerGroup.include({ 4932 toMultiPoint: function (precision) { 4933 var coords = []; 4934 this.eachLayer(function (layer) { 4935 coords.push(layer.toGeoJSON(precision).geometry.coordinates) 4936 }); 4937 return getFeature(this, { 4938 type: 'MultiPoint', 4939 coordinates: coords 4940 }) 4941 }, 4942 toGeoJSON: function (precision) { 4943 var type = this.feature && this.feature.geometry && this.feature.geometry.type; 4944 if (type === 'MultiPoint') { 4945 return this.toMultiPoint(precision) 4946 } 4947 var isGeometryCollection = type === 'GeometryCollection' 4948 , jsons = []; 4949 this.eachLayer(function (layer) { 4950 if (layer.toGeoJSON) { 4951 var json = layer.toGeoJSON(precision); 4952 if (isGeometryCollection) { 4953 jsons.push(json.geometry) 4954 } else { 4955 var feature = asFeature(json); 4956 if (feature.type === 'FeatureCollection') { 4957 jsons.push.apply(jsons, feature.features) 4958 } else { 4959 jsons.push(feature) 4960 } 4961 } 4962 } 4963 }); 4964 if (isGeometryCollection) { 4965 return getFeature(this, { 4966 geometries: jsons, 4967 type: 'GeometryCollection' 4968 }) 4969 } 4970 return { 4971 type: 'FeatureCollection', 4972 features: jsons 4973 } 4974 } 4975 }); 4976 function geoJSON(geojson, options) { 4977 return new GeoJSON(geojson, options) 4978 } 4979 var geoJson = geoJSON; 4980 var ImageOverlay = Layer.extend({ 4981 options: { 4982 opacity: 1, 4983 alt: '', 4984 interactive: !1, 4985 crossOrigin: !1, 4986 errorOverlayUrl: '', 4987 zIndex: 1, 4988 className: '', 4989 }, 4990 initialize: function (url, bounds, options) { 4991 this._url = url; 4992 this._bounds = toLatLngBounds(bounds); 4993 setOptions(this, options) 4994 }, 4995 onAdd: function () { 4996 if (!this._image) { 4997 this._initImage(); 4998 if (this.options.opacity < 1) { 4999 this._updateOpacity() 5000 } 5001 } 5002 if (this.options.interactive) { 5003 addClass(this._image, 'leaflet-interactive'); 5004 this.addInteractiveTarget(this._image) 5005 } 5006 this.getPane().appendChild(this._image); 5007 this._reset() 5008 }, 5009 onRemove: function () { 5010 remove(this._image); 5011 if (this.options.interactive) { 5012 this.removeInteractiveTarget(this._image) 5013 } 5014 }, 5015 setOpacity: function (opacity) { 5016 this.options.opacity = opacity; 5017 if (this._image) { 5018 this._updateOpacity() 5019 } 5020 return this 5021 }, 5022 setStyle: function (styleOpts) { 5023 if (styleOpts.opacity) { 5024 this.setOpacity(styleOpts.opacity) 5025 } 5026 return this 5027 }, 5028 bringToFront: function () { 5029 if (this._map) { 5030 toFront(this._image) 5031 } 5032 return this 5033 }, 5034 bringToBack: function () { 5035 if (this._map) { 5036 toBack(this._image) 5037 } 5038 return this 5039 }, 5040 setUrl: function (url) { 5041 this._url = url; 5042 if (this._image) { 5043 this._image.src = url 5044 } 5045 return this 5046 }, 5047 setBounds: function (bounds) { 5048 this._bounds = toLatLngBounds(bounds); 5049 if (this._map) { 5050 this._reset() 5051 } 5052 return this 5053 }, 5054 getEvents: function () { 5055 var events = { 5056 zoom: this._reset, 5057 viewreset: this._reset 5058 }; 5059 if (this._zoomAnimated) { 5060 events.zoomanim = this._animateZoom 5061 } 5062 return events 5063 }, 5064 setZIndex: function (value) { 5065 this.options.zIndex = value; 5066 this._updateZIndex(); 5067 return this 5068 }, 5069 getBounds: function () { 5070 return this._bounds 5071 }, 5072 getElement: function () { 5073 return this._image 5074 }, 5075 _initImage: function () { 5076 var wasElementSupplied = this._url.tagName === 'IMG'; 5077 var img = this._image = wasElementSupplied ? this._url : create$1('img'); 5078 addClass(img, 'leaflet-image-layer'); 5079 if (this._zoomAnimated) { 5080 addClass(img, 'leaflet-zoom-animated') 5081 } 5082 if (this.options.className) { 5083 addClass(img, this.options.className) 5084 } 5085 img.onselectstart = falseFn; 5086 img.onmousemove = falseFn; 5087 img.onload = bind(this.fire, this, 'load'); 5088 img.onerror = bind(this._overlayOnError, this, 'error'); 5089 if (this.options.crossOrigin || this.options.crossOrigin === '') { 5090 img.crossOrigin = this.options.crossOrigin === !0 ? '' : this.options.crossOrigin 5091 } 5092 if (this.options.zIndex) { 5093 this._updateZIndex() 5094 } 5095 if (wasElementSupplied) { 5096 this._url = img.src; 5097 return 5098 } 5099 img.src = this._url; 5100 img.alt = this.options.alt 5101 }, 5102 _animateZoom: function (e) { 5103 var scale = this._map.getZoomScale(e.zoom) 5104 , offset = this._map._latLngBoundsToNewLayerBounds(this._bounds, e.zoom, e.center).min; 5105 setTransform(this._image, offset, scale) 5106 }, 5107 _reset: function () { 5108 var image = this._image 5109 , bounds = new Bounds(this._map.latLngToLayerPoint(this._bounds.getNorthWest()), this._map.latLngToLayerPoint(this._bounds.getSouthEast())) 5110 , size = bounds.getSize(); 5111 setPosition(image, bounds.min); 5112 image.style.width = size.x + 'px'; 5113 image.style.height = size.y + 'px' 5114 }, 5115 _updateOpacity: function () { 5116 setOpacity(this._image, this.options.opacity) 5117 }, 5118 _updateZIndex: function () { 5119 if (this._image && this.options.zIndex !== undefined && this.options.zIndex !== null) { 5120 this._image.style.zIndex = this.options.zIndex 5121 } 5122 }, 5123 _overlayOnError: function () { 5124 this.fire('error'); 5125 var errorUrl = this.options.errorOverlayUrl; 5126 if (errorUrl && this._url !== errorUrl) { 5127 this._url = errorUrl; 5128 this._image.src = errorUrl 5129 } 5130 } 5131 }); 5132 var imageOverlay = function (url, bounds, options) { 5133 return new ImageOverlay(url, bounds, options) 5134 }; 5135 var VideoOverlay = ImageOverlay.extend({ 5136 options: { 5137 autoplay: !0, 5138 loop: !0 5139 }, 5140 _initImage: function () { 5141 var wasElementSupplied = this._url.tagName === 'VIDEO'; 5142 var vid = this._image = wasElementSupplied ? this._url : create$1('video'); 5143 addClass(vid, 'leaflet-image-layer'); 5144 if (this._zoomAnimated) { 5145 addClass(vid, 'leaflet-zoom-animated') 5146 } 5147 vid.onselectstart = falseFn; 5148 vid.onmousemove = falseFn; 5149 vid.onloadeddata = bind(this.fire, this, 'load'); 5150 if (wasElementSupplied) { 5151 var sourceElements = vid.getElementsByTagName('source'); 5152 var sources = []; 5153 for (var j = 0; j < sourceElements.length; j++) { 5154 sources.push(sourceElements[j].src) 5155 } 5156 this._url = (sourceElements.length > 0) ? sources : [vid.src]; 5157 return 5158 } 5159 if (!isArray(this._url)) { 5160 this._url = [this._url] 5161 } 5162 vid.autoplay = !!this.options.autoplay; 5163 vid.loop = !!this.options.loop; 5164 for (var i = 0; i < this._url.length; i++) { 5165 var source = create$1('source'); 5166 source.src = this._url[i]; 5167 vid.appendChild(source) 5168 } 5169 } 5170 }); 5171 function videoOverlay(video, bounds, options) { 5172 return new VideoOverlay(video, bounds, options) 5173 } 5174 var DivOverlay = Layer.extend({ 5175 options: { 5176 offset: [0, 7], 5177 className: '', 5178 pane: 'popupPane' 5179 }, 5180 initialize: function (options, source) { 5181 setOptions(this, options); 5182 this._source = source 5183 }, 5184 onAdd: function (leaflet) { 5185 this._zoomAnimated = leaflet._zoomAnimated; 5186 if (!this._container) { 5187 this._initLayout() 5188 } 5189 if (leaflet._fadeAnimated) { 5190 setOpacity(this._container, 0) 5191 } 5192 clearTimeout(this._removeTimeout); 5193 this.getPane().appendChild(this._container); 5194 this.update(); 5195 if (leaflet._fadeAnimated) { 5196 setOpacity(this._container, 1) 5197 } 5198 this.bringToFront() 5199 }, 5200 onRemove: function (leaflet) { 5201 if (leaflet._fadeAnimated) { 5202 setOpacity(this._container, 0); 5203 this._removeTimeout = setTimeout(bind(remove, undefined, this._container), 200) 5204 } else { 5205 remove(this._container) 5206 } 5207 }, 5208 getLatLng: function () { 5209 return this._latlng 5210 },
5211 setLatLng: function (latlng) { 5212 this._latlng = toLatLng(latlng); 5213 if (this._map) { 5214 this._updatePosition(); 5215 this._adjustPan() 5216 } 5217 return this 5218 }, 5219 getContent: function () { 5220 return this._content 5221 }, 5222 setContent: function (content) { 5223 this._content = content; 5224 this.update(); 5225 return this 5226 }, 5227 getElement: function () { 5228 return this._container 5229 }, 5230 update: function () { 5231 if (!this._map) { 5232 return 5233 } 5234 this._container.style.visibility = 'hidden'; 5235 this._updateContent(); 5236 this._updateLayout(); 5237 this._updatePosition(); 5238 this._container.style.visibility = ''; 5239 this._adjustPan() 5240 }, 5241 getEvents: function () { 5242 var events = { 5243 zoom: this._updatePosition, 5244 viewreset: this._updatePosition 5245 }; 5246 if (this._zoomAnimated) { 5247 events.zoomanim = this._animateZoom 5248 } 5249 return events 5250 }, 5251 isOpen: function () { 5252 return !!this._map && this._map.hasLayer(this) 5253 }, 5254 bringToFront: function () { 5255 if (this._map) { 5256 toFront(this._container) 5257 } 5258 return this 5259 }, 5260 bringToBack: function () { 5261 if (this._map) { 5262 toBack(this._container) 5263 } 5264 return this 5265 }, 5266 _updateContent: function () { 5267 if (!this._content) { 5268 return 5269 } 5270 var node = this._contentNode; 5271 var content = (typeof this._content === 'function') ? this._content(this._source || this) : this._content; 5272 if (typeof content === 'string') { 5273 node.innerHTML = content 5274 } else { 5275 while (node.hasChildNodes()) { 5276 node.removeChild(node.firstChild) 5277 } 5278 node.appendChild(content) 5279 } 5280 this.fire('contentupdate') 5281 }, 5282 _updatePosition: function () { 5283 if (!this._map) { 5284 return 5285 } 5286 var pos = this._map.latLngToLayerPoint(this._latlng) 5287 , offset = toPoint(this.options.offset) 5288 , anchor = this._getAnchor(); 5289 if (this._zoomAnimated) { 5290 setPosition(this._container, pos.add(anchor)) 5291 } else { 5292 offset = offset.add(pos).add(anchor) 5293 } 5294 var bottom = this._containerBottom = -offset.y 5295 , left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x; 5296 this._container.style.bottom = bottom + 'px'; 5297 this._container.style.left = left + 'px' 5298 }, 5299 _getAnchor: function () { 5300 return [0, 0] 5301 } 5302 }); 5303 var Popup = DivOverlay.extend({ 5304 options: { 5305 maxWidth: 300, 5306 minWidth: 50, 5307 maxHeight: null, 5308 autoPan: !0, 5309 autoPanPaddingTopLeft: null, 5310 autoPanPaddingBottomRight: null, 5311 autoPanPadding: [5, 5], 5312 keepInView: !1, 5313 closeButton: !0, 5314 autoClose: !0, 5315 closeOnEscapeKey: !0, 5316 className: '' 5317 }, 5318 openOn: function (leaflet) { 5319 leaflet.openPopup(this); 5320 return this 5321 }, 5322 onAdd: function (leaflet) { 5323 DivOverlay.prototype.onAdd.call(this, leaflet); 5324 leaflet.fire('popupopen', { 5325 popup: this 5326 }); 5327 if (this._source) { 5328 this._source.fire('popupopen', { 5329 popup: this 5330 }, !0); 5331 if (!(this._source instanceof Path)) { 5332 this._source.on('preclick', stopPropagation) 5333 } 5334 } 5335 }, 5336 onRemove: function (leaflet) { 5337 DivOverlay.prototype.onRemove.call(this, leaflet); 5338 leaflet.fire('popupclose', { 5339 popup: this 5340 }); 5341 if (this._source) { 5342 this._source.fire('popupclose', { 5343 popup: this 5344 }, !0); 5345 if (!(this._source instanceof Path)) { 5346 this._source.off('preclick', stopPropagation) 5347 } 5348 } 5349 }, 5350 getEvents: function () { 5351 var events = DivOverlay.prototype.getEvents.call(this); 5352 if (this.options.closeOnClick !== undefined ? this.options.closeOnClick : this._map.options.closePopupOnClick) { 5353 events.preclick = this._close 5354 } 5355 if (this.options.keepInView) { 5356 events.moveend = this._adjustPan 5357 } 5358 return events 5359 }, 5360 _close: function () { 5361 if (this._map) { 5362 this._map.closePopup(this) 5363 } 5364 }, 5365 _initLayout: function () { 5366 var prefix = 'leaflet-popup' 5367 , container = this._container = create$1('div', prefix + ' ' + (this.options.className || '') + ' leaflet-zoom-animated'); 5368 var wrapper = this._wrapper = create$1('div', prefix + '-content-wrapper', container); 5369 this._contentNode = create$1('div', prefix + '-content', wrapper); 5370 disableClickPropagation(wrapper); 5371 disableScrollPropagation(this._contentNode); 5372 on(wrapper, 'contextmenu', stopPropagation); 5373 this._tipContainer = create$1('div', prefix + '-tip-container', container); 5374 this._tip = create$1('div', prefix + '-tip', this._tipContainer); 5375 if (this.options.closeButton) { 5376 var closeButton = this._closeButton = create$1('a', prefix + '-close-button', container); 5377 closeButton.href = '#close'; 5378 closeButton.innerHTML = '×'; 5379 on(closeButton, 'click', this._onCloseButtonClick, this) 5380 } 5381 }, 5382 _updateLayout: function () { 5383 var container = this._contentNode 5384 , style = container.style; 5385 style.width = ''; 5386 style.whiteSpace = 'nowrap'; 5387 var width = container.offsetWidth; 5388 width = Math.min(width, this.options.maxWidth); 5389 width = Math.max(width, this.options.minWidth); 5390 style.width = (width + 1) + 'px'; 5391 style.whiteSpace = ''; 5392 style.height = ''; 5393 var height = container.offsetHeight 5394 , maxHeight = this.options.maxHeight 5395 , scrolledClass = 'leaflet-popup-scrolled'; 5396 if (maxHeight && height > maxHeight) { 5397 style.height = maxHeight + 'px'; 5398 addClass(container, scrolledClass) 5399 } else { 5400 removeClass(container, scrolledClass) 5401 } 5402 this._containerWidth = this._container.offsetWidth 5403 }, 5404 _animateZoom: function (e) { 5405 var pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center) 5406 , anchor = this._getAnchor(); 5407 setPosition(this._container, pos.add(anchor)) 5408 }, 5409 _adjustPan: function () { 5410 if (!this.options.autoPan || (this._map._panAnim && this._map._panAnim._inProgress)) { 5411 return 5412 } 5413 var leaflet = this._map 5414 , marginBottom = parseInt(getStyle(this._container, 'marginBottom'), 10) || 0 5415 , containerHeight = this._container.offsetHeight + marginBottom 5416 , containerWidth = this._containerWidth 5417 , layerPos = new Point(this._containerLeft, -containerHeight - this._containerBottom); 5418 layerPos._add(getPosition(this._container));
5419 var containerPos = leaflet.layerPointToContainerPoint(layerPos) 5420 , padding = toPoint(this.options.autoPanPadding) 5421 , paddingTL = toPoint(this.options.autoPanPaddingTopLeft || padding) 5422 , paddingBR = toPoint(this.options.autoPanPaddingBottomRight || padding) 5423 , size = leaflet.getSize() 5424 , dx = 0 5425 , dy = 0; 5426 if (containerPos.x + containerWidth + paddingBR.x > size.x) { 5427 dx = containerPos.x + containerWidth - size.x + paddingBR.x 5428 } 5429 if (containerPos.x - dx - paddingTL.x < 0) { 5430 dx = containerPos.x - paddingTL.x 5431 } 5432 if (containerPos.y + containerHeight + paddingBR.y > size.y) { 5433 dy = containerPos.y + containerHeight - size.y + paddingBR.y 5434 } 5435 if (containerPos.y - dy - paddingTL.y < 0) { 5436 dy = containerPos.y - paddingTL.y 5437 } 5438 if (dx || dy) { 5439 leaflet.fire('autopanstart').panBy([dx, dy]) 5440 } 5441 }, 5442 _onCloseButtonClick: function (e) { 5443 this._close(); 5444 stop(e) 5445 }, 5446 _getAnchor: function () { 5447 return toPoint(this._source && this._source._getPopupAnchor ? this._source._getPopupAnchor() : [0, 0]) 5448 } 5449 }); 5450 var popup = function (options, source) { 5451 return new Popup(options, source) 5452 }; 5453 Map.mergeOptions({ 5454 closePopupOnClick: !0 5455 }); 5456 Map.include({ 5457 openPopup: function (popup, latlng, options) { 5458 if (!(popup instanceof Popup)) { 5459 popup = new Popup(options).setContent(popup) 5460 } 5461 if (latlng) { 5462 popup.setLatLng(latlng) 5463 } 5464 if (this.hasLayer(popup)) { 5465 return this 5466 } 5467 if (this._popup && this._popup.options.autoClose) { 5468 this.closePopup() 5469 } 5470 this._popup = popup; 5471 return this.addLayer(popup) 5472 }, 5473 closePopup: function (popup) { 5474 if (!popup || popup === this._popup) { 5475 popup = this._popup; 5476 this._popup = null 5477 } 5478 if (popup) { 5479 this.removeLayer(popup) 5480 } 5481 return this 5482 } 5483 }); 5484 Layer.include({ 5485 bindPopup: function (content, options) { 5486 if (content instanceof Popup) { 5487 setOptions(content, options); 5488 this._popup = content; 5489 content._source = this 5490 } else { 5491 if (!this._popup || options) { 5492 this._popup = new Popup(options, this) 5493 } 5494 this._popup.setContent(content) 5495 } 5496 if (!this._popupHandlersAdded) { 5497 this.on({ 5498 click: this._openPopup, 5499 keypress: this._onKeyPress, 5500 remove: this.closePopup, 5501 move: this._movePopup 5502 }); 5503 this._popupHandlersAdded = !0 5504 } 5505 return this 5506 }, 5507 unbindPopup: function () { 5508 if (this._popup) { 5509 this.off({ 5510 click: this._openPopup, 5511 keypress: this._onKeyPress, 5512 remove: this.closePopup, 5513 move: this._movePopup 5514 }); 5515 this._popupHandlersAdded = !1; 5516 this._popup = null 5517 } 5518 return this 5519 }, 5520 openPopup: function (layer, latlng) { 5521 if (!(layer instanceof Layer)) { 5522 latlng = layer; 5523 layer = this 5524 } 5525 if (layer instanceof FeatureGroup) { 5526 for (var id in this._layers) { 5527 layer = this._layers[id]; 5528 break 5529 } 5530 } 5531 if (!latlng) { 5532 latlng = layer.getCenter ? layer.getCenter() : layer.getLatLng() 5533 } 5534 if (this._popup && this._map) { 5535 this._popup._source = layer; 5536 this._popup.update(); 5537 this._map.openPopup(this._popup, latlng) 5538 } 5539 return this 5540 }, 5541 closePopup: function () { 5542 if (this._popup) { 5543 this._popup._close() 5544 } 5545 return this 5546 }, 5547 togglePopup: function (target) { 5548 if (this._popup) { 5549 if (this._popup._map) { 5550 this.closePopup() 5551 } else { 5552 this.openPopup(target) 5553 } 5554 } 5555 return this 5556 }, 5557 isPopupOpen: function () { 5558 return (this._popup ? this._popup.isOpen() : !1) 5559 }, 5560 setPopupContent: function (content) { 5561 if (this._popup) { 5562 this._popup.setContent(content) 5563 } 5564 return this 5565 }, 5566 getPopup: function () { 5567 return this._popup 5568 }, 5569 _openPopup: function (e) { 5570 var layer = e.layer || e.target; 5571 if (!this._popup) { 5572 return 5573 } 5574 if (!this._map) { 5575 return 5576 } 5577 stop(e); 5578 if (layer instanceof Path) { 5579 this.openPopup(e.layer || e.target, e.latlng); 5580 return 5581 } 5582 if (this._map.hasLayer(this._popup) && this._popup._source === layer) { 5583 this.closePopup() 5584 } else { 5585 this.openPopup(layer, e.latlng) 5586 } 5587 }, 5588 _movePopup: function (e) { 5589 this._popup.setLatLng(e.latlng) 5590 }, 5591 _onKeyPress: function (e) { 5592 if (e.originalEvent.keyCode === 13) { 5593 this._openPopup(e) 5594 } 5595 } 5596 }); 5597 var Tooltip = DivOverlay.extend({ 5598 options: { 5599 pane: 'tooltipPane', 5600 offset: [0, 0], 5601 direction: 'auto', 5602 permanent: !1, 5603 sticky: !1, 5604 interactive: !1, 5605 opacity: 0.9 5606 }, 5607 onAdd: function (leaflet) { 5608 DivOverlay.prototype.onAdd.call(this, leaflet); 5609 this.setOpacity(this.options.opacity); 5610 leaflet.fire('tooltipopen', { 5611 tooltip: this 5612 }); 5613 if (this._source) { 5614 this._source.fire('tooltipopen', { 5615 tooltip: this 5616 }, !0) 5617 } 5618 }, 5619 onRemove: function (leaflet) { 5620 DivOverlay.prototype.onRemove.call(this, leaflet); 5621 leaflet.fire('tooltipclose', { 5622 tooltip: this 5623 }); 5624 if (this._source) { 5625 this._source.fire('tooltipclose', { 5626 tooltip: this 5627 }, !0) 5628 } 5629 }, 5630 getEvents: function () { 5631 var events = DivOverlay.prototype.getEvents.call(this); 5632 if (touch && !this.options.permanent) { 5633 events.preclick = this._close 5634 } 5635 return events 5636 }, 5637 _close: function () { 5638 if (this._map) { 5639 this._map.closeTooltip(this) 5640 } 5641 }, 5642 _initLayout: function () { 5643 var prefix = 'leaflet-tooltip' 5644 , className = prefix + ' ' + (this.options.className || '') + ' leaflet-zoom-' + (this._zoomAnimated ? 'animated' : 'hide'); 5645 this._contentNode = this._container = create$1('div', className) 5646 }, 5647 _updateLayout: function () { }, 5648 _adjustPan: function () { }, 5649 _setPosition: function (pos) { 5650 var leaflet = this._map 5651 , container = this._container 5652 , centerPoint = leaflet.latLngToContainerPoint(leaflet.getCenter()) 5653 , tooltipPoint = leaflet.layerPointToContainerPoint(pos) 5654 , direction = this.options.direction 5655 , tooltipWidth = container.offsetWidth 5656 , tooltipHeight = container.offsetHeight 5657 , offset = toPoint(this.options.offset) 5658 , anchor = this._getAnchor(); 5659 if (direction === 'top') { 5660 pos = pos.add(toPoint(-tooltipWidth / 2 + offset.x, -tooltipHeight + offset.y + anchor.y, !0)) 5661 } else if (direction === 'bottom') { 5662 pos = pos.subtract(toPoint(tooltipWidth / 2 - offset.x, -offset.y, !0)) 5663 } else if (direction === 'center') { 5664 pos = pos.subtract(toPoint(tooltipWidth / 2 + offset.x, tooltipHeight / 2 - anchor.y + offset.y, !0)) 5665 } else if (direction === 'right' || direction === 'auto' && tooltipPoint.x < centerPoint.x) { 5666 direction = 'right'; 5667 pos = pos.add(toPoint(offset.x + anchor.x, anchor.y - tooltipHeight / 2 + offset.y, !0)) 5668 } else { 5669 direction = 'left'; 5670 pos = pos.subtract(toPoint(tooltipWidth + anchor.x - offset.x, tooltipHeight / 2 - anchor.y - offset.y, !0)) 5671 } 5672 removeClass(container, 'leaflet-tooltip-right'); 5673 removeClass(container, 'leaflet-tooltip-left'); 5674 removeClass(container, 'leaflet-tooltip-top'); 5675 removeClass(container, 'leaflet-tooltip-bottom');
5676 addClass(container, 'leaflet-tooltip-' + direction); 5677 setPosition(container, pos) 5678 }, 5679 _updatePosition: function () { 5680 var pos = this._map.latLngToLayerPoint(this._latlng); 5681 this._setPosition(pos) 5682 }, 5683 setOpacity: function (opacity) { 5684 this.options.opacity = opacity; 5685 if (this._container) { 5686 setOpacity(this._container, opacity) 5687 } 5688 }, 5689 _animateZoom: function (e) { 5690 var pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center); 5691 this._setPosition(pos) 5692 }, 5693 _getAnchor: function () { 5694 return toPoint(this._source && this._source._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]) 5695 } 5696 }); 5697 var tooltip = function (options, source) { 5698 return new Tooltip(options, source) 5699 }; 5700 Map.include({ 5701 openTooltip: function (tooltip, latlng, options) { 5702 if (!(tooltip instanceof Tooltip)) { 5703 tooltip = new Tooltip(options).setContent(tooltip) 5704 } 5705 if (latlng) { 5706 tooltip.setLatLng(latlng) 5707 } 5708 if (this.hasLayer(tooltip)) { 5709 return this 5710 } 5711 return this.addLayer(tooltip) 5712 }, 5713 closeTooltip: function (tooltip) { 5714 if (tooltip) { 5715 this.removeLayer(tooltip) 5716 } 5717 return this 5718 } 5719 }); 5720 Layer.include({ 5721 bindTooltip: function (content, options) { 5722 if (content instanceof Tooltip) { 5723 setOptions(content, options); 5724 this._tooltip = content; 5725 content._source = this 5726 } else { 5727 if (!this._tooltip || options) { 5728 this._tooltip = new Tooltip(options, this) 5729 } 5730 this._tooltip.setContent(content) 5731 } 5732 this._initTooltipInteractions(); 5733 if (this._tooltip.options.permanent && this._map && this._map.hasLayer(this)) { 5734 this.openTooltip() 5735 } 5736 return this 5737 }, 5738 unbindTooltip: function () { 5739 if (this._tooltip) { 5740 this._initTooltipInteractions(!0); 5741 this.closeTooltip(); 5742 this._tooltip = null 5743 } 5744 return this 5745 }, 5746 _initTooltipInteractions: function (remove$$1) { 5747 if (!remove$$1 && this._tooltipHandlersAdded) { 5748 return 5749 } 5750 var onOff = remove$$1 ? 'off' : 'on' 5751 , events = { 5752 remove: this.closeTooltip, 5753 move: this._moveTooltip 5754 }; 5755 if (!this._tooltip.options.permanent) { 5756 events.mouseover = this._openTooltip; 5757 events.mouseout = this.closeTooltip; 5758 if (this._tooltip.options.sticky) { 5759 events.mousemove = this._moveTooltip 5760 } 5761 if (touch) { 5762 events.click = this._openTooltip 5763 } 5764 } else { 5765 events.add = this._openTooltip 5766 } 5767 this[onOff](events); 5768 this._tooltipHandlersAdded = !remove$$1 5769 }, 5770 openTooltip: function (layer, latlng) { 5771 if (!(layer instanceof Layer)) { 5772 latlng = layer; 5773 layer = this 5774 } 5775 if (layer instanceof FeatureGroup) { 5776 for (var id in this._layers) { 5777 layer = this._layers[id]; 5778 break 5779 } 5780 } 5781 if (!latlng) { 5782 latlng = layer.getCenter ? layer.getCenter() : layer.getLatLng() 5783 } 5784 if (this._tooltip && this._map) { 5785 this._tooltip._source = layer; 5786 this._tooltip.update(); 5787 this._map.openTooltip(this._tooltip, latlng); 5788 if (this._tooltip.options.interactive && this._tooltip._container) { 5789 addClass(this._tooltip._container, 'leaflet-clickable'); 5790 this.addInteractiveTarget(this._tooltip._container) 5791 } 5792 } 5793 return this 5794 }, 5795 closeTooltip: function () { 5796 if (this._tooltip) { 5797 this._tooltip._close(); 5798 if (this._tooltip.options.interactive && this._tooltip._container) { 5799 removeClass(this._tooltip._container, 'leaflet-clickable'); 5800 this.removeInteractiveTarget(this._tooltip._container) 5801 } 5802 } 5803 return this 5804 }, 5805 toggleTooltip: function (target) { 5806 if (this._tooltip) { 5807 if (this._tooltip._map) { 5808 this.closeTooltip() 5809 } else { 5810 this.openTooltip(target) 5811 } 5812 } 5813 return this 5814 }, 5815 isTooltipOpen: function () { 5816 return this._tooltip.isOpen() 5817 }, 5818 setTooltipContent: function (content) { 5819 if (this._tooltip) { 5820 this._tooltip.setContent(content) 5821 } 5822 return this 5823 }, 5824 getTooltip: function () { 5825 return this._tooltip 5826 }, 5827 _openTooltip: function (e) { 5828 var layer = e.layer || e.target; 5829 if (!this._tooltip || !this._map) { 5830 return 5831 } 5832 this.openTooltip(layer, this._tooltip.options.sticky ? e.latlng : undefined) 5833 }, 5834 _moveTooltip: function (e) { 5835 var latlng = e.latlng, containerPoint, layerPoint; 5836 if (this._tooltip.options.sticky && e.originalEvent) { 5837 containerPoint = this._map.mouseEventToContainerPoint(e.originalEvent); 5838 layerPoint = this._map.containerPointToLayerPoint(containerPoint); 5839 latlng = this._map.layerPointToLatLng(layerPoint) 5840 } 5841 this._tooltip.setLatLng(latlng) 5842 } 5843 }); 5844 var DivIcon = Icon.extend({ 5845 options: { 5846 iconSize: [12, 12], 5847 html: !1, 5848 bgPos: null, 5849 className: 'leaflet-div-icon' 5850 }, 5851 createIcon: function (oldIcon) { 5852 var div = (oldIcon && oldIcon.tagName === 'DIV') ? oldIcon : document.createElement('div') 5853 , options = this.options; 5854 div.innerHTML = options.html !== !1 ? options.html : ''; 5855 if (options.bgPos) { 5856 var bgPos = toPoint(options.bgPos); 5857 div.style.backgroundPosition = (-bgPos.x) + 'px ' + (-bgPos.y) + 'px' 5858 } 5859 this._setIconStyles(div, 'icon'); 5860 return div 5861 }, 5862 createShadow: function () { 5863 return null 5864 } 5865 }); 5866 function divIcon(options) { 5867 return new DivIcon(options) 5868 } 5869 Icon.Default = IconDefault; 5870 var GridLayer = Layer.extend({ 5871 options: { 5872 tileSize: 256, 5873 opacity: 1, 5874 updateWhenIdle: mobile, 5875 updateWhenZooming: !0, 5876 updateInterval: 200, 5877 zIndex: 1, 5878 bounds: null, 5879 minZoom: 0, 5880 maxZoom: undefined, 5881 maxNativeZoom: undefined, 5882 minNativeZoom: undefined, 5883 noWrap: !1, 5884 pane: 'tilePane', 5885 className: '', 5886 keepBuffer: 2 5887 }, 5888 initialize: function (options) { 5889 setOptions(this, options) 5890 }, 5891 onAdd: function () { 5892 this._initContainer(); 5893 this._levels = {}; 5894 this._tiles = {}; 5895 this._resetView(); 5896 this._update() 5897 }, 5898 beforeAdd: function (leaflet) { 5899 leaflet._addZoomLimit(this) 5900 }, 5901 onRemove: function (leaflet) { 5902 this._removeAllTiles(); 5903 remove(this._container); 5904 leaflet._removeZoomLimit(this); 5905 this._container = null; 5906 this._tileZoom = undefined 5907 }, 5908 bringToFront: function () { 5909 if (this._map) { 5910 toFront(this._container); 5911 this._setAutoZIndex(Math.max) 5912 } 5913 return this 5914 }, 5915 bringToBack: function () { 5916 if (this._map) { 5917 toBack(this._container); 5918 this._setAutoZIndex(Math.min) 5919 } 5920 return this 5921 }, 5922 getContainer: function () { 5923 return this._container 5924 }, 5925 setOpacity: function (opacity) { 5926 this.options.opacity = opacity; 5927 this._updateOpacity(); 5928 return this 5929 }, 5930 setZIndex: function (zIndex) { 5931 this.options.zIndex = zIndex; 5932 this._updateZIndex(); 5933 return this 5934 }, 5935 isLoading: function () { 5936 return this._loading 5937 }, 5938 redraw: function () { 5939 if (this._map) { 5940 this._removeAllTiles(); 5941 this._update() 5942 } 5943 return this 5944 }, 5945 getEvents: function () { 5946 var events = { 5947 viewprereset: this._invalidateAll, 5948 viewreset: this._resetView, 5949 zoom: this._resetView, 5950 moveend: this._onMoveEnd 5951 }; 5952 if (!this.options.updateWhenIdle) { 5953 if (!this._onMove) { 5954 this._onMove = throttle(this._onMoveEnd, this.options.updateInterval, this) 5955 } 5956 events.move = this._onMove 5957 } 5958 if (this._zoomAnimated) { 5959 events.zoomanim = this._animateZoom 5960 } 5961 return events 5962 }, 5963 createTile: function () { 5964 return document.createElement('div') 5965 }, 5966 getTileSize: function () { 5967 var s = this.options.tileSize; 5968 return s instanceof Point ? s : new Point(s, s) 5969 }, 5970 _updateZIndex: function () { 5971 if (this._container && this.options.zIndex !== undefined && this.options.zIndex !== null) { 5972 this._container.style.zIndex = this.options.zIndex 5973 } 5974 }, 5975 _setAutoZIndex: function (compare) { 5976 var layers = this.getPane().children 5977 , edgeZIndex = -compare(-Infinity, Infinity); 5978 for (var i = 0, len = layers.length, zIndex; i < len; i++) { 5979 zIndex = layers[i].style.zIndex; 5980 if (layers[i] !== this._container && zIndex) { 5981 edgeZIndex = compare(edgeZIndex, +zIndex) 5982 } 5983 } 5984 if (isFinite(edgeZIndex)) { 5985 this.options.zIndex = edgeZIndex + compare(-1, 1); 5986 this._updateZIndex() 5987 } 5988 }, 5989 _updateOpacity: function () { 5990 if (!this._map) { 5991 return 5992 } 5993 if (ielt9) { 5994 return 5995 } 5996 setOpacity(this._container, this.options.opacity); 5997 var now = +new Date() 5998 , nextFrame = !1 5999 , willPrune = !1; 6000 for (var key in this._tiles) { 6001 var tile = this._tiles[key]; 6002 if (!tile.current || !tile.loaded) { 6003 continue 6004 } 6005 var fade = Math.min(1, (now - tile.loaded) / 200); 6006 setOpacity(tile.el, fade); 6007 if (fade < 1) { 6008 nextFrame = !0 6009 } else { 6010 if (tile.active) { 6011 willPrune = !0 6012 } else { 6013 this._onOpaqueTile(tile) 6014 } 6015 tile.active = !0 6016 } 6017 } 6018 if (willPrune && !this._noPrune) { 6019 this._pruneTiles() 6020 } 6021 if (nextFrame) {
6022 cancelAnimFrame(this._fadeFrame); 6023 this._fadeFrame = requestAnimFrame(this._updateOpacity, this) 6024 } 6025 }, 6026 _onOpaqueTile: falseFn, 6027 _initContainer: function () { 6028 if (this._container) { 6029 return 6030 } 6031 this._container = create$1('div', 'leaflet-layer ' + (this.options.className || '')); 6032 this._updateZIndex(); 6033 if (this.options.opacity < 1) { 6034 this._updateOpacity() 6035 } 6036 this.getPane().appendChild(this._container) 6037 }, 6038 _updateLevels: function () { 6039 var zoom = this._tileZoom 6040 , maxZoom = this.options.maxZoom; 6041 if (zoom === undefined) { 6042 return undefined 6043 } 6044 for (var z in this._levels) { 6045 if (this._levels[z].el.children.length || z === zoom) { 6046 this._levels[z].el.style.zIndex = maxZoom - Math.abs(zoom - z); 6047 this._onUpdateLevel(z) 6048 } else { 6049 remove(this._levels[z].el); 6050 this._removeTilesAtZoom(z); 6051 this._onRemoveLevel(z); 6052 delete this._levels[z] 6053 } 6054 } 6055 var level = this._levels[zoom] 6056 , leaflet = this._map; 6057 if (!level) { 6058 level = this._levels[zoom] = {}; 6059 level.el = create$1('div', 'leaflet-tile-container leaflet-zoom-animated', this._container); 6060 level.el.style.zIndex = maxZoom; 6061 level.origin = leaflet.project(leaflet.unproject(leaflet.getPixelOrigin()), zoom).round(); 6062 level.zoom = zoom; 6063 this._setZoomTransform(level, leaflet.getCenter(), leaflet.getZoom()); 6064 falseFn(level.el.offsetWidth); 6065 this._onCreateLevel(level) 6066 } 6067 this._level = level; 6068 return level 6069 }, 6070 _onUpdateLevel: falseFn, 6071 _onRemoveLevel: falseFn, 6072 _onCreateLevel: falseFn, 6073 _pruneTiles: function () { 6074 if (!this._map) { 6075 return 6076 } 6077 var key, tile; 6078 var zoom = this._map.getZoom(); 6079 if (zoom > this.options.maxZoom || zoom < this.options.minZoom) { 6080 this._removeAllTiles(); 6081 return 6082 } 6083 for (key in this._tiles) { 6084 tile = this._tiles[key]; 6085 tile.retain = tile.current 6086 } 6087 for (key in this._tiles) { 6088 tile = this._tiles[key]; 6089 if (tile.current && !tile.active) { 6090 var coords = tile.coords; 6091 if (!this._retainParent(coords.x, coords.y, coords.z, coords.z - 5)) { 6092 this._retainChildren(coords.x, coords.y, coords.z, coords.z + 2) 6093 } 6094 } 6095 } 6096 for (key in this._tiles) { 6097 if (!this._tiles[key].retain) { 6098 this._removeTile(key) 6099 } 6100 } 6101 }, 6102 _removeTilesAtZoom: function (zoom) { 6103 for (var key in this._tiles) { 6104 if (this._tiles[key].coords.z !== zoom) { 6105 continue 6106 } 6107 this._removeTile(key) 6108 } 6109 }, 6110 _removeAllTiles: function () { 6111 for (var key in this._tiles) { 6112 this._removeTile(key) 6113 } 6114 }, 6115 _invalidateAll: function () { 6116 for (var z in this._levels) { 6117 remove(this._levels[z].el); 6118 this._onRemoveLevel(z); 6119 delete this._levels[z] 6120 } 6121 this._removeAllTiles(); 6122 this._tileZoom = undefined 6123 }, 6124 _retainParent: function (x, y, z, minZoom) { 6125 var x2 = Math.floor(x / 2) 6126 , y2 = Math.floor(y / 2) 6127 , z2 = z - 1 6128 , coords2 = new Point(+x2, +y2); 6129 coords2.z = +z2; 6130 var key = this._tileCoordsToKey(coords2) 6131 , tile = this._tiles[key]; 6132 if (tile && tile.active) { 6133 tile.retain = !0; 6134 return !0 6135 } else if (tile && tile.loaded) { 6136 tile.retain = !0 6137 } 6138 if (z2 > minZoom) { 6139 return this._retainParent(x2, y2, z2, minZoom) 6140 } 6141 return !1 6142 }, 6143 _retainChildren: function (x, y, z, maxZoom) { 6144 for (var i = 2 * x; i < 2 * x + 2; i++) { 6145 for (var j = 2 * y; j < 2 * y + 2; j++) { 6146 var coords = new Point(i, j); 6147 coords.z = z + 1; 6148 var key = this._tileCoordsToKey(coords) 6149 , tile = this._tiles[key]; 6150 if (tile && tile.active) { 6151 tile.retain = !0; 6152 continue 6153 } else if (tile && tile.loaded) { 6154 tile.retain = !0 6155 } 6156 if (z + 1 < maxZoom) { 6157 this._retainChildren(i, j, z + 1, maxZoom) 6158 } 6159 } 6160 } 6161 }, 6162 _resetView: function (e) { 6163 var animating = e && (e.pinch || e.flyTo);
6164 this._setView(this._map.getCenter(), this._map.getZoom(), animating, animating) 6165 }, 6166 _animateZoom: function (e) { 6167 this._setView(e.center, e.zoom, !0, e.noUpdate) 6168 }, 6169 _clampZoom: function (zoom) { 6170 var options = this.options; 6171 if (undefined !== options.minNativeZoom && zoom < options.minNativeZoom) { 6172 return options.minNativeZoom 6173 } 6174 if (undefined !== options.maxNativeZoom && options.maxNativeZoom < zoom) { 6175 return options.maxNativeZoom 6176 } 6177 return zoom 6178 }, 6179 _setView: function (center, zoom, noPrune, noUpdate) { 6180 var tileZoom = this._clampZoom(Math.round(zoom)); 6181 if ((this.options.maxZoom !== undefined && tileZoom > this.options.maxZoom) || (this.options.minZoom !== undefined && tileZoom < this.options.minZoom)) { 6182 tileZoom = undefined 6183 } 6184 var tileZoomChanged = this.options.updateWhenZooming && (tileZoom !== this._tileZoom); 6185 if (!noUpdate || tileZoomChanged) { 6186 this._tileZoom = tileZoom; 6187 if (this._abortLoading) { 6188 this._abortLoading() 6189 } 6190 this._updateLevels(); 6191 this._resetGrid(); 6192 if (tileZoom !== undefined) { 6193 this._update(center) 6194 } 6195 if (!noPrune) { 6196 this._pruneTiles() 6197 } 6198 this._noPrune = !!noPrune 6199 } 6200 this._setZoomTransforms(center, zoom) 6201 }, 6202 _setZoomTransforms: function (center, zoom) { 6203 for (var i in this._levels) { 6204 this._setZoomTransform(this._levels[i], center, zoom) 6205 } 6206 }, 6207 _setZoomTransform: function (level, center, zoom) { 6208 var scale = this._map.getZoomScale(zoom, level.zoom) 6209 , translate = level.origin.multiplyBy(scale).subtract(this._map._getNewPixelOrigin(center, zoom)).round(); 6210 if (any3d) { 6211 setTransform(level.el, translate, scale) 6212 } else { 6213 setPosition(level.el, translate) 6214 } 6215 }, 6216 _resetGrid: function () { 6217 var leaflet = this._map 6218 , crs = leaflet.options.crs 6219 , tileSize = this._tileSize = this.getTileSize() 6220 , tileZoom = this._tileZoom; 6221 var bounds = this._map.getPixelWorldBounds(this._tileZoom); 6222 if (bounds) { 6223 this._globalTileRange = this._pxBoundsToTileRange(bounds) 6224 } 6225 this._wrapX = crs.wrapLng && !this.options.noWrap && [Math.floor(leaflet.project([0, crs.wrapLng[0]], tileZoom).x / tileSize.x), Math.ceil(leaflet.project([0, crs.wrapLng[1]], tileZoom).x / tileSize.y)]; 6226 this._wrapY = crs.wrapLat && !this.options.noWrap && [Math.floor(leaflet.project([crs.wrapLat[0], 0], tileZoom).y / tileSize.x), Math.ceil(leaflet.project([crs.wrapLat[1], 0], tileZoom).y / tileSize.y)] 6227 }, 6228 _onMoveEnd: function () { 6229 if (!this._map || this._map._animatingZoom) { 6230 return 6231 } 6232 this._update() 6233 }, 6234 _getTiledPixelBounds: function (center) { 6235 var leaflet = this._map 6236 , mapZoom = leaflet._animatingZoom ? Math.max(leaflet._animateToZoom, leaflet.getZoom()) : leaflet.getZoom() 6237 , scale = leaflet.getZoomScale(mapZoom, this._tileZoom) 6238 , pixelCenter = leaflet.project(center, this._tileZoom).floor() 6239 , halfSize = leaflet.getSize().divideBy(scale * 2); 6240 return new Bounds(pixelCenter.subtract(halfSize), pixelCenter.add(halfSize)) 6241 }, 6242 _update: function (center) { 6243 var leaflet = this._map; 6244 if (!leaflet) { 6245 return 6246 } 6247 var zoom = this._clampZoom(leaflet.getZoom()); 6248 if (center === undefined) { 6249 center = leaflet.getCenter() 6250 } 6251 if (this._tileZoom === undefined) { 6252 return 6253 } 6254 var pixelBounds = this._getTiledPixelBounds(center) 6255 , tileRange = this._pxBoundsToTileRange(pixelBounds) 6256 , tileCenter = tileRange.getCenter() 6257 , queue = [] 6258 , margin = this.options.keepBuffer 6259 , noPruneRange = new Bounds(tileRange.getBottomLeft().subtract([margin, -margin]), tileRange.getTopRight().add([margin, -margin])); 6260 if (!(isFinite(tileRange.min.x) && isFinite(tileRange.min.y) && isFinite(tileRange.max.x) && isFinite(tileRange.max.y))) { 6261 throw new Error('Attempted to load an infinite number of tiles') 6262 } 6263 for (var key in this._tiles) { 6264 var c = this._tiles[key].coords; 6265 if (c.z !== this._tileZoom || !noPruneRange.contains(new Point(c.x, c.y))) { 6266 this._tiles[key].current = !1 6267 } 6268 } 6269 if (Math.abs(zoom - this._tileZoom) > 1) {
6270 this._setView(center, zoom); 6271 return 6272 } 6273 for (var j = tileRange.min.y; j <= tileRange.max.y; j++) { 6274 for (var i = tileRange.min.x; i <= tileRange.max.x; i++) { 6275 var coords = new Point(i, j); 6276 coords.z = this._tileZoom; 6277 if (!this._isValidTile(coords)) { 6278 continue 6279 } 6280 var tile = this._tiles[this._tileCoordsToKey(coords)]; 6281 if (tile) { 6282 tile.current = !0 6283 } else { 6284 queue.push(coords) 6285 } 6286 } 6287 } 6288 queue.sort(function (a, b) { 6289 return a.distanceTo(tileCenter) - b.distanceTo(tileCenter) 6290 }); 6291 if (queue.length !== 0) { 6292 if (!this._loading) { 6293 this._loading = !0; 6294 this.fire('loading') 6295 } 6296 var fragment = document.createDocumentFragment(); 6297 for (i = 0; i < queue.length; i++) { 6298 this._addTile(queue[i], fragment) 6299 } 6300 this._level.el.appendChild(fragment) 6301 } 6302 }, 6303 _isValidTile: function (coords) { 6304 var crs = this._map.options.crs; 6305 if (!crs.infinite) { 6306 var bounds = this._globalTileRange; 6307 if ((!crs.wrapLng && (coords.x < bounds.min.x || coords.x > bounds.max.x)) || (!crs.wrapLat && (coords.y < bounds.min.y || coords.y > bounds.max.y))) { 6308 return !1 6309 } 6310 } 6311 if (!this.options.bounds) { 6312 return !0 6313 } 6314 var tileBounds = this._tileCoordsToBounds(coords); 6315 return toLatLngBounds(this.options.bounds).overlaps(tileBounds) 6316 }, 6317 _keyToBounds: function (key) { 6318 return this._tileCoordsToBounds(this._keyToTileCoords(key)) 6319 }, 6320 _tileCoordsToNwSe: function (coords) { 6321 var leaflet = this._map 6322 , tileSize = this.getTileSize() 6323 , nwPoint = coords.scaleBy(tileSize) 6324 , sePoint = nwPoint.add(tileSize) 6325 , nw = leaflet.unproject(nwPoint, coords.z) 6326 , se = leaflet.unproject(sePoint, coords.z); 6327 return [nw, se] 6328 }, 6329 _tileCoordsToBounds: function (coords) { 6330 var bp = this._tileCoordsToNwSe(coords) 6331 , bounds = new LatLngBounds(bp[0], bp[1]); 6332 if (!this.options.noWrap) { 6333 bounds = this._map.wrapLatLngBounds(bounds) 6334 } 6335 return bounds 6336 }, 6337 _tileCoordsToKey: function (coords) { 6338 return coords.x + ':' + coords.y + ':' + coords.z 6339 }, 6340 _keyToTileCoords: function (key) { 6341 var k = key.split(':') 6342 , coords = new Point(+k[0], +k[1]); 6343 coords.z = +k[2]; 6344 return coords 6345 }, 6346 _removeTile: function (key) { 6347 var tile = this._tiles[key]; 6348 if (!tile) { 6349 return 6350 } 6351 if (!androidStock) { 6352 tile.el.setAttribute('src', emptyImageUrl) 6353 } 6354 remove(tile.el); 6355 delete this._tiles[key]; 6356 this.fire('tileunload', { 6357 tile: tile.el, 6358 coords: this._keyToTileCoords(key) 6359 }) 6360 }, 6361 _initTile: function (tile) { 6362 addClass(tile, 'leaflet-tile'); 6363 var tileSize = this.getTileSize(); 6364 tile.style.width = tileSize.x + 'px'; 6365 tile.style.height = tileSize.y + 'px'; 6366 tile.onselectstart = falseFn; 6367 tile.onmousemove = falseFn; 6368 if (ielt9 && this.options.opacity < 1) { 6369 setOpacity(tile, this.options.opacity) 6370 } 6371 if (android && !android23) { 6372 tile.style.WebkitBackfaceVisibility = 'hidden' 6373 } 6374 }, 6375 _addTile: function (coords, container) { 6376 var tilePos = this._getTilePos(coords) 6377 , key = this._tileCoordsToKey(coords); 6378 var tile = this.createTile(this._wrapCoords(coords), bind(this._tileReady, this, coords)); 6379 this._initTile(tile); 6380 if (this.createTile.length < 2) { 6381 requestAnimFrame(bind(this._tileReady, this, coords, null, tile)) 6382 } 6383 setPosition(tile, tilePos); 6384 this._tiles[key] = { 6385 el: tile, 6386 coords: coords, 6387 current: !0 6388 }; 6389 container.appendChild(tile); 6390 this.fire('tileloadstart', { 6391 tile: tile, 6392 coords: coords 6393 }) 6394 }, 6395 _tileReady: function (coords, err, tile) { 6396 if (!this._map || tile.getAttribute('src') === emptyImageUrl) { 6397 return 6398 } 6399 if (err) { 6400 this.fire('tileerror', { 6401 error: err, 6402 tile: tile, 6403 coords: coords 6404 }) 6405 } 6406 var key = this._tileCoordsToKey(coords);
6407 tile = this._tiles[key]; 6408 if (!tile) { 6409 return 6410 } 6411 tile.loaded = +new Date(); 6412 if (this._map._fadeAnimated) { 6413 setOpacity(tile.el, 0); 6414 cancelAnimFrame(this._fadeFrame); 6415 this._fadeFrame = requestAnimFrame(this._updateOpacity, this) 6416 } else { 6417 tile.active = !0; 6418 this._pruneTiles() 6419 } 6420 if (!err) { 6421 addClass(tile.el, 'leaflet-tile-loaded'); 6422 this.fire('tileload', { 6423 tile: tile.el, 6424 coords: coords 6425 }) 6426 } 6427 if (this._noTilesToLoad()) { 6428 this._loading = !1; 6429 this.fire('load'); 6430 if (ielt9 || !this._map._fadeAnimated) { 6431 requestAnimFrame(this._pruneTiles, this) 6432 } else { 6433 setTimeout(bind(this._pruneTiles, this), 250) 6434 } 6435 } 6436 }, 6437 _getTilePos: function (coords) { 6438 return coords.scaleBy(this.getTileSize()).subtract(this._level.origin) 6439 }, 6440 _wrapCoords: function (coords) { 6441 var newCoords = new Point(this._wrapX ? wrapNum(coords.x, this._wrapX) : coords.x, this._wrapY ? wrapNum(coords.y, this._wrapY) : coords.y); 6442 newCoords.z = coords.z; 6443 return newCoords 6444 }, 6445 _pxBoundsToTileRange: function (bounds) { 6446 var tileSize = this.getTileSize(); 6447 return new Bounds(bounds.min.unscaleBy(tileSize).floor(), bounds.max.unscaleBy(tileSize).ceil().subtract([1, 1])) 6448 }, 6449 _noTilesToLoad: function () { 6450 for (var key in this._tiles) { 6451 if (!this._tiles[key].loaded) { 6452 return !1 6453 } 6454 } 6455 return !0 6456 } 6457 }); 6458 function gridLayer(options) { 6459 return new GridLayer(options) 6460 } 6461 var TileLayer = GridLayer.extend({ 6462 options: { 6463 minZoom: 0, 6464 maxZoom: 18, 6465 subdomains: 'abc', 6466 errorTileUrl: '', 6467 zoomOffset: 0, 6468 tms: !1, 6469 zoomReverse: !1, 6470 detectRetina: !1, 6471 crossOrigin: !1 6472 }, 6473 initialize: function (url, options) { 6474 this._url = url; 6475 options = setOptions(this, options); 6476 if (options.detectRetina && retina && options.maxZoom > 0) { 6477 options.tileSize = Math.floor(options.tileSize / 2); 6478 if (!options.zoomReverse) { 6479 options.zoomOffset++; 6480 options.maxZoom-- 6481 } else { 6482 options.zoomOffset--; 6483 options.minZoom++ 6484 } 6485 options.minZoom = Math.max(0, options.minZoom) 6486 } 6487 if (typeof options.subdomains === 'string') { 6488 options.subdomains = options.subdomains.split('') 6489 } 6490 if (!android) { 6491 this.on('tileunload', this._onTileRemove) 6492 } 6493 }, 6494 setUrl: function (url, noRedraw) { 6495 this._url = url; 6496 if (!noRedraw) { 6497 this.redraw() 6498 } 6499 return this 6500 }, 6501 createTile: function (coords, done) { 6502 var tile = document.createElement('img'); 6503 on(tile, 'load', bind(this._tileOnLoad, this, done, tile)); 6504 on(tile, 'error', bind(this._tileOnError, this, done, tile)); 6505 if (this.options.crossOrigin || this.options.crossOrigin === '') { 6506 tile.crossOrigin = this.options.crossOrigin === !0 ? '' : this.options.crossOrigin 6507 } 6508 tile.alt = ''; 6509 tile.setAttribute('role', 'presentation'); 6510 tile.src = this.getTileUrl(coords); 6511 return tile 6512 }, 6513 getTileUrl: function (coords) { 6514 var data = { 6515 r: retina ? '@2x' : '', 6516 s: this._getSubdomain(coords), 6517 x: coords.x, 6518 y: coords.y, 6519 z: this._getZoomForUrl() 6520 }; 6521 if (this._map && !this._map.options.crs.infinite) { 6522 var invertedY = this._globalTileRange.max.y - coords.y; 6523 if (this.options.tms) { 6524 data.y = invertedY 6525 } 6526 data['-y'] = invertedY 6527 } 6528 return template(this._url, extend(data, this.options)) 6529 }, 6530 _tileOnLoad: function (done, tile) { 6531 if (ielt9) { 6532 setTimeout(bind(done, this, null, tile), 0) 6533 } else { 6534 done(null, tile) 6535 } 6536 }, 6537 _tileOnError: function (done, tile, e) { 6538 var errorUrl = this.options.errorTileUrl; 6539 if (errorUrl && tile.getAttribute('src') !== errorUrl) { 6540 tile.src = errorUrl 6541 } 6542 done(e, tile) 6543 }, 6544 _onTileRemove: function (e) { 6545 e.tile.onload = null 6546 }, 6547 _getZoomForUrl: function () { 6548 var zoom = this._tileZoom 6549 , maxZoom = this.options.maxZoom
6550 , zoomReverse = this.options.zoomReverse 6551 , zoomOffset = this.options.zoomOffset; 6552 if (zoomReverse) { 6553 zoom = maxZoom - zoom 6554 } 6555 return zoom + zoomOffset 6556 }, 6557 _getSubdomain: function (tilePoint) { 6558 var index = Math.abs(tilePoint.x + tilePoint.y) % this.options.subdomains.length; 6559 return this.options.subdomains[index] 6560 }, 6561 _abortLoading: function () { 6562 var i, tile; 6563 for (i in this._tiles) { 6564 if (this._tiles[i].coords.z !== this._tileZoom) { 6565 tile = this._tiles[i].el; 6566 tile.onload = falseFn; 6567 tile.onerror = falseFn; 6568 if (!tile.complete) { 6569 tile.src = emptyImageUrl; 6570 remove(tile); 6571 delete this._tiles[i] 6572 } 6573 } 6574 } 6575 } 6576 }); 6577 function addOGCServices(url, options) { 6578 return new TileLayer(url, options) 6579 } 6580 var TileLayerWMS = TileLayer.extend({ 6581 defaultWmsParams: { 6582 service: 'WMS', 6583 request: 'GetMap', 6584 layers: '', 6585 styles: '', 6586 format: 'image/jpeg', 6587 transparent: !1, 6588 version: '1.1.1' 6589 }, 6590 options: { 6591 crs: null, 6592 uppercase: !1 6593 }, 6594 initialize: function (url, options) { 6595 this._url = url; 6596 var wmsParams = extend({}, this.defaultWmsParams); 6597 for (var i in options) { 6598 if (!(i in this.options)) { 6599 wmsParams[i] = options[i] 6600 } 6601 } 6602 options = setOptions(this, options); 6603 var realRetina = options.detectRetina && retina ? 2 : 1; 6604 var tileSize = this.getTileSize(); 6605 wmsParams.width = tileSize.x * realRetina; 6606 wmsParams.height = tileSize.y * realRetina; 6607 this.wmsParams = wmsParams 6608 }, 6609 onAdd: function (leaflet) { 6610 this._crs = this.options.crs || leaflet.options.crs; 6611 this._wmsVersion = parseFloat(this.wmsParams.version); 6612 var projectionKey = this._wmsVersion >= 1.3 ? 'crs' : 'srs'; 6613 this.wmsParams[projectionKey] = this._crs.code; 6614 TileLayer.prototype.onAdd.call(this, leaflet) 6615 }, 6616 getTileUrl: function (coords) { 6617 var tileBounds = this._tileCoordsToNwSe(coords) 6618 , crs = this._crs 6619 , bounds = toBounds(crs.project(tileBounds[0]), crs.project(tileBounds[1])) 6620 , min = bounds.min 6621 , max = bounds.max 6622 , bbox = (this._wmsVersion >= 1.3 && this._crs === EPSG4326 ? [min.y, min.x, max.y, max.x] : [min.x, min.y, max.x, max.y]).join(',') 6623 , url = TileLayer.prototype.getTileUrl.call(this, coords); 6624 return url + getParamString(this.wmsParams, url, this.options.uppercase) + (this.options.uppercase ? '&BBOX=' : '&bbox=') + bbox 6625 }, 6626 setParams: function (params, noRedraw) { 6627 extend(this.wmsParams, params); 6628 if (!noRedraw) { 6629 this.redraw() 6630 } 6631 return this 6632 } 6633 }); 6634 function tileLayerWMS(url, options) { 6635 return new TileLayerWMS(url, options) 6636 } 6637 TileLayer.WMS = TileLayerWMS; 6638 addOGCServices.wms = tileLayerWMS; 6639 var Renderer = Layer.extend({ 6640 options: { 6641 padding: 0.1, 6642 tolerance: 0 6643 }, 6644 initialize: function (options) { 6645 setOptions(this, options); 6646 stamp(this); 6647 this._layers = this._layers || {} 6648 }, 6649 onAdd: function () { 6650 if (!this._container) { 6651 this._initContainer(); 6652 if (this._zoomAnimated) { 6653 addClass(this._container, 'leaflet-zoom-animated') 6654 } 6655 } 6656 this.getPane().appendChild(this._container); 6657 this._update(); 6658 this.on('update', this._updatePaths, this) 6659 }, 6660 onRemove: function () { 6661 this.off('update', this._updatePaths, this); 6662 this._destroyContainer() 6663 }, 6664 getEvents: function () { 6665 var events = { 6666 viewreset: this._reset, 6667 zoom: this._onZoom, 6668 moveend: this._update, 6669 zoomend: this._onZoomEnd 6670 }; 6671 if (this._zoomAnimated) { 6672 events.zoomanim = this._onAnimZoom 6673 } 6674 return events 6675 }, 6676 _onAnimZoom: function (ev) { 6677 this._updateTransform(ev.center, ev.zoom) 6678 }, 6679 _onZoom: function () { 6680 this._updateTransform(this._map.getCenter(), this._map.getZoom()) 6681 }, 6682 _updateTransform: function (center, zoom) { 6683 var scale = this._map.getZoomScale(zoom, this._zoom) 6684 , position = getPosition(this._container) 6685 , viewHalf = this._map.getSize().multiplyBy(0.5 + this.options.padding) 6686 , currentCenterPoint = this._map.project(this._center, zoom) 6687 , destCenterPoint = this._map.project(center, zoom) 6688 , centerOffset = destCenterPoint.subtract(currentCenterPoint) 6689 , topLeftOffset = viewHalf.multiplyBy(-scale).add(position).add(viewHalf).subtract(centerOffset); 6690 if (any3d) { 6691 setTransform(this._container, topLeftOffset, scale) 6692 } else { 6693 setPosition(this._container, topLeftOffset) 6694 } 6695 }, 6696 _reset: function () { 6697 this._update(); 6698 this._updateTransform(this._center, this._zoom); 6699 for (var id in this._layers) { 6700 this._layers[id]._reset() 6701 } 6702 }, 6703 _onZoomEnd: function () { 6704 for (var id in this._layers) { 6705 this._layers[id]._project() 6706 } 6707 }, 6708 _updatePaths: function () { 6709 for (var id in this._layers) { 6710 this._layers[id]._update() 6711 } 6712 }, 6713 _update: function () { 6714 var p = this.options.padding 6715 , size = this._map.getSize() 6716 , min = this._map.containerPointToLayerPoint(size.multiplyBy(-p)).round(); 6717 this._bounds = new Bounds(min, min.add(size.multiplyBy(1 + p * 2)).round()); 6718 this._center = this._map.getCenter(); 6719 this._zoom = this._map.getZoom() 6720 } 6721 }); 6722 var Canvas = Renderer.extend({ 6723 getEvents: function () { 6724 var events = Renderer.prototype.getEvents.call(this); 6725 events.viewprereset = this._onViewPreReset; 6726 return events 6727 }, 6728 _onViewPreReset: function () { 6729 this._postponeUpdatePaths = !0 6730 }, 6731 onAdd: function () { 6732 Renderer.prototype.onAdd.call(this); 6733 this._draw() 6734 }, 6735 _initContainer: function () { 6736 var container = this._container = document.createElement('canvas'); 6737 on(container, 'mousemove', throttle(this._onMouseMove, 32, this), this); 6738 on(container, 'click dblclick mousedown mouseup contextmenu', this._onClick, this); 6739 on(container, 'mouseout', this._handleMouseOut, this); 6740 this._ctx = container.getContext('2d') 6741 }, 6742 _destroyContainer: function () {
6743 cancelAnimFrame(this._redrawRequest); 6744 delete this._ctx; 6745 remove(this._container); 6746 off(this._container); 6747 delete this._container 6748 }, 6749 _updatePaths: function () { 6750 if (this._postponeUpdatePaths) { 6751 return 6752 } 6753 var layer; 6754 this._redrawBounds = null; 6755 for (var id in this._layers) { 6756 layer = this._layers[id]; 6757 layer._update() 6758 } 6759 this._redraw() 6760 }, 6761 _update: function () { 6762 if (this._map._animatingZoom && this._bounds) { 6763 return 6764 } 6765 this._drawnLayers = {}; 6766 Renderer.prototype._update.call(this); 6767 var b = this._bounds 6768 , container = this._container 6769 , size = b.getSize() 6770 , m = retina ? 2 : 1; 6771 setPosition(container, b.min); 6772 container.width = m * size.x; 6773 container.height = m * size.y; 6774 container.style.width = size.x + 'px'; 6775 container.style.height = size.y + 'px'; 6776 if (retina) { 6777 this._ctx.scale(2, 2) 6778 } 6779 this._ctx.translate(-b.min.x, -b.min.y); 6780 this.fire('update') 6781 }, 6782 _reset: function () { 6783 Renderer.prototype._reset.call(this); 6784 if (this._postponeUpdatePaths) { 6785 this._postponeUpdatePaths = !1; 6786 this._updatePaths() 6787 } 6788 }, 6789 _initPath: function (layer) { 6790 this._updateDashArray(layer); 6791 this._layers[stamp(layer)] = layer; 6792 var order = layer._order = { 6793 layer: layer, 6794 prev: this._drawLast, 6795 next: null 6796 }; 6797 if (this._drawLast) { 6798 this._drawLast.next = order 6799 } 6800 this._drawLast = order; 6801 this._drawFirst = this._drawFirst || this._drawLast 6802 }, 6803 _addPath: function (layer) { 6804 this._requestRedraw(layer) 6805 }, 6806 _removePath: function (layer) { 6807 var order = layer._order; 6808 var next = order.next; 6809 var prev = order.prev; 6810 if (next) { 6811 next.prev = prev 6812 } else { 6813 this._drawLast = prev 6814 } 6815 if (prev) { 6816 prev.next = next 6817 } else { 6818 this._drawFirst = next 6819 } 6820 delete this._drawnLayers[layer._leaflet_id]; 6821 delete layer._order; 6822 delete this._layers[stamp(layer)]; 6823 this._requestRedraw(layer) 6824 }, 6825 _updatePath: function (layer) { 6826 this._extendRedrawBounds(layer); 6827 layer._project(); 6828 layer._update(); 6829 this._requestRedraw(layer) 6830 }, 6831 _updateStyle: function (layer) { 6832 this._updateDashArray(layer); 6833 this._requestRedraw(layer) 6834 }, 6835 _updateDashArray: function (layer) { 6836 if (typeof layer.options.dashArray === 'string') { 6837 var parts = layer.options.dashArray.split(','), dashArray = [], i; 6838 for (i = 0; i < parts.length; i++) { 6839 dashArray.push(Number(parts[i])) 6840 } 6841 layer.options._dashArray = dashArray 6842 } else { 6843 layer.options._dashArray = layer.options.dashArray 6844 } 6845 }, 6846 _requestRedraw: function (layer) { 6847 if (!this._map) { 6848 return 6849 } 6850 this._extendRedrawBounds(layer); 6851 this._redrawRequest = this._redrawRequest || requestAnimFrame(this._redraw, this) 6852 }, 6853 _extendRedrawBounds: function (layer) { 6854 if (layer._pxBounds) { 6855 var padding = (layer.options.weight || 0) + 1; 6856 this._redrawBounds = this._redrawBounds || new Bounds(); 6857 this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding])); 6858 this._redrawBounds.extend(layer._pxBounds.max.add([padding, padding])) 6859 } 6860 }, 6861 _redraw: function () { 6862 this._redrawRequest = null; 6863 if (this._redrawBounds) { 6864 this._redrawBounds.min._floor(); 6865 this._redrawBounds.max._ceil() 6866 } 6867 this._clear(); 6868 this._draw(); 6869 this._redrawBounds = null 6870 }, 6871 _clear: function () { 6872 var bounds = this._redrawBounds; 6873 if (bounds) { 6874 var size = bounds.getSize(); 6875 this._ctx.clearRect(bounds.min.x, bounds.min.y, size.x, size.y) 6876 } else { 6877 this._ctx.clearRect(0, 0, this._container.width, this._container.height) 6878 } 6879 }, 6880 _draw: function () { 6881 var layer, bounds = this._redrawBounds; 6882 this._ctx.save(); 6883 if (bounds) { 6884 var size = bounds.getSize(); 6885 this._ctx.beginPath(); 6886 this._ctx.rect(bounds.min.x, bounds.min.y, size.x, size.y); 6887 this._ctx.clip() 6888 } 6889 this._drawing = !0; 6890 for (var order = this._drawFirst; order; order = order.next) { 6891 layer = order.layer; 6892 if (!bounds || (layer._pxBounds && layer._pxBounds.intersects(bounds))) { 6893 layer._updatePath() 6894 } 6895 } 6896 this._drawing = !1;
6897 this._ctx.restore() 6898 }, 6899 _updatePoly: function (layer, closed) { 6900 if (!this._drawing) { 6901 return 6902 } 6903 var i, j, len2, p, parts = layer._parts, len = parts.length, ctx = this._ctx; 6904 if (!len) { 6905 return 6906 } 6907 this._drawnLayers[layer._leaflet_id] = layer; 6908 ctx.beginPath(); 6909 for (i = 0; i < len; i++) { 6910 for (j = 0, 6911 len2 = parts[i].length; j < len2; j++) { 6912 p = parts[i][j]; 6913 ctx[j ? 'lineTo' : 'moveTo'](p.x, p.y) 6914 } 6915 if (closed) { 6916 ctx.closePath() 6917 } 6918 } 6919 this._fillStroke(ctx, layer) 6920 }, 6921 _updateCircle: function (layer) { 6922 if (!this._drawing || layer._empty()) { 6923 return 6924 } 6925 var p = layer._point 6926 , ctx = this._ctx 6927 , r = Math.max(Math.round(layer._radius), 1) 6928 , s = (Math.max(Math.round(layer._radiusY), 1) || r) / r; 6929 this._drawnLayers[layer._leaflet_id] = layer; 6930 if (s !== 1) { 6931 ctx.save(); 6932 ctx.scale(1, s) 6933 } 6934 ctx.beginPath(); 6935 ctx.arc(p.x, p.y / s, r, 0, Math.PI * 2, !1); 6936 if (s !== 1) { 6937 ctx.restore() 6938 } 6939 this._fillStroke(ctx, layer) 6940 }, 6941 _fillStroke: function (ctx, layer) { 6942 var options = layer.options; 6943 if (options.fill) { 6944 ctx.globalAlpha = options.fillOpacity; 6945 ctx.fillStyle = options.fillColor || options.color; 6946 ctx.fill(options.fillRule || 'evenodd') 6947 } 6948 if (options.stroke && options.weight !== 0) { 6949 if (ctx.setLineDash) { 6950 ctx.setLineDash(layer.options && layer.options._dashArray || []) 6951 } 6952 ctx.globalAlpha = options.opacity; 6953 ctx.lineWidth = options.weight; 6954 ctx.strokeStyle = options.color; 6955 ctx.lineCap = options.lineCap; 6956 ctx.lineJoin = options.lineJoin; 6957 ctx.stroke() 6958 } 6959 }, 6960 _onClick: function (e) { 6961 var point = this._map.mouseEventToLayerPoint(e), layer, clickedLayer; 6962 for (var order = this._drawFirst; order; order = order.next) { 6963 layer = order.layer; 6964 if (layer.options.interactive && layer._containsPoint(point) && !this._map._draggableMoved(layer)) { 6965 clickedLayer = layer 6966 } 6967 } 6968 if (clickedLayer) { 6969 fakeStop(e); 6970 this._fireEvent([clickedLayer], e) 6971 } 6972 }, 6973 _onMouseMove: function (e) { 6974 if (!this._map || this._map.dragging.moving() || this._map._animatingZoom) { 6975 return 6976 } 6977 var point = this._map.mouseEventToLayerPoint(e); 6978 this._handleMouseHover(e, point) 6979 }, 6980 _handleMouseOut: function (e) { 6981 var layer = this._hoveredLayer; 6982 if (layer) { 6983 removeClass(this._container, 'leaflet-interactive'); 6984 this._fireEvent([layer], e, 'mouseout'); 6985 this._hoveredLayer = null 6986 } 6987 }, 6988 _handleMouseHover: function (e, point) { 6989 var layer, candidateHoveredLayer; 6990 for (var order = this._drawFirst; order; order = order.next) { 6991 layer = order.layer; 6992 if (layer.options.interactive && layer._containsPoint(point)) { 6993 candidateHoveredLayer = layer 6994 } 6995 } 6996 if (candidateHoveredLayer !== this._hoveredLayer) { 6997 this._handleMouseOut(e); 6998 if (candidateHoveredLayer) { 6999 addClass(this._container, 'leaflet-interactive'); 7000 this._fireEvent([candidateHoveredLayer], e, 'mouseover'); 7001 this._hoveredLayer = candidateHoveredLayer 7002 } 7003 } 7004 if (this._hoveredLayer) { 7005 this._fireEvent([this._hoveredLayer], e) 7006 } 7007 }, 7008 _fireEvent: function (layers, e, type) { 7009 this._map._fireDOMEvent(e, type || e.type, layers) 7010 }, 7011 _bringToFront: function (layer) { 7012 var order = layer._order; 7013 var next = order.next; 7014 var prev = order.prev; 7015 if (next) { 7016 next.prev = prev 7017 } else { 7018 return 7019 } 7020 if (prev) { 7021 prev.next = next 7022 } else if (next) { 7023 this._drawFirst = next 7024 } 7025 order.prev = this._drawLast; 7026 this._drawLast.next = order; 7027 order.next = null; 7028 this._drawLast = order; 7029 this._requestRedraw(layer) 7030 }, 7031 _bringToBack: function (layer) { 7032 var order = layer._order; 7033 var next = order.next; 7034 var prev = order.prev; 7035 if (prev) { 7036 prev.next = next 7037 } else { 7038 return 7039 } 7040 if (next) { 7041 next.prev = prev 7042 } else if (prev) { 7043 this._drawLast = prev 7044 } 7045 order.prev = null; 7046 order.next = this._drawFirst; 7047 this._drawFirst.prev = order; 7048 this._drawFirst = order; 7049 this._requestRedraw(layer) 7050 } 7051 }); 7052 function canvas$1(options) { 7053 return canvas ? new Canvas(options) : null 7054 } 7055 var vmlCreate = (function () { 7056 try { 7057 document.namespaces.add('lvml', 'urn:schemas-microsoft-com:vml'); 7058 return function (name) { 7059 return document.createElement('<lvml:' + name + ' class="lvml">') 7060 } 7061 } catch (e) { 7062 return function (name) { 7063 return document.createElement('<' + name + ' xmlns="urn:schemas-microsoft.com:vml" class="lvml">') 7064 } 7065 } 7066 } 7067 )(); 7068 var vmlMixin = { 7069 _initContainer: function () { 7070 this._container = create$1('div', 'leaflet-vml-container') 7071 }, 7072 _update: function () { 7073 if (this._map._animatingZoom) { 7074 return 7075 } 7076 Renderer.prototype._update.call(this); 7077 this.fire('update') 7078 }, 7079 _initPath: function (layer) { 7080 var container = layer._container = vmlCreate('shape'); 7081 addClass(container, 'leaflet-vml-shape ' + (this.options.className || '')); 7082 container.coordsize = '1 1'; 7083 layer._path = vmlCreate('path'); 7084 container.appendChild(layer._path); 7085 this._updateStyle(layer); 7086 this._layers[stamp(layer)] = layer 7087 }, 7088 _addPath: function (layer) { 7089 var container = layer._container; 7090 this._container.appendChild(container); 7091 if (layer.options.interactive) { 7092 layer.addInteractiveTarget(container) 7093 } 7094 }, 7095 _removePath: function (layer) { 7096 var container = layer._container; 7097 remove(container); 7098 layer.removeInteractiveTarget(container); 7099 delete this._layers[stamp(layer)] 7100 }, 7101 _updateStyle: function (layer) { 7102 var stroke = layer._stroke 7103 , fill = layer._fill 7104 , options = layer.options 7105 , container = layer._container; 7106 container.stroked = !!options.stroke; 7107 container.filled = !!options.fill; 7108 if (options.stroke) { 7109 if (!stroke) { 7110 stroke = layer._stroke = vmlCreate('stroke') 7111 } 7112 container.appendChild(stroke); 7113 stroke.weight = options.weight + 'px'; 7114 stroke.color = options.color; 7115 stroke.opacity = options.opacity; 7116 if (options.dashArray) { 7117 stroke.dashStyle = isArray(options.dashArray) ? options.dashArray.join(' ') : options.dashArray.replace(/( *, *)/g, ' ') 7118 } else { 7119 stroke.dashStyle = '' 7120 } 7121 stroke.endcap = options.lineCap.replace('butt', 'flat'); 7122 stroke.joinstyle = options.lineJoin 7123 } else if (stroke) { 7124 container.removeChild(stroke); 7125 layer._stroke = null 7126 } 7127 if (options.fill) { 7128 if (!fill) { 7129 fill = layer._fill = vmlCreate('fill') 7130 } 7131 container.appendChild(fill); 7132 fill.color = options.fillColor || options.color; 7133 fill.opacity = options.fillOpacity 7134 } else if (fill) { 7135 container.removeChild(fill); 7136 layer._fill = null 7137 } 7138 }, 7139 _updateCircle: function (layer) { 7140 var p = layer._point.round() 7141 , r = Math.round(layer._radius) 7142 , r2 = Math.round(layer._radiusY || r); 7143 this._setPath(layer, layer._empty() ? 'M0 0' : 'AL ' + p.x + ',' + p.y + ' ' + r + ',' + r2 + ' 0,' + (65535 * 360)) 7144 }, 7145 _setPath: function (layer, path) { 7146 layer._path.v = path 7147 }, 7148 _bringToFront: function (layer) { 7149 toFront(layer._container) 7150 }, 7151 _bringToBack: function (layer) { 7152 toBack(layer._container) 7153 } 7154 }; 7155 var create$2 = vml ? vmlCreate : svgCreate; 7156 var SVG = Renderer.extend({ 7157 getEvents: function () { 7158 var events = Renderer.prototype.getEvents.call(this); 7159 events.zoomstart = this._onZoomStart; 7160 return events 7161 }, 7162 _initContainer: function () { 7163 this._container = create$2('svg');
7164 this._container.setAttribute('pointer-events', 'none'); 7165 this._rootGroup = create$2('g'); 7166 this._container.appendChild(this._rootGroup) 7167 }, 7168 _destroyContainer: function () { 7169 remove(this._container); 7170 off(this._container); 7171 delete this._container; 7172 delete this._rootGroup; 7173 delete this._svgSize 7174 }, 7175 _onZoomStart: function () { 7176 this._update() 7177 }, 7178 _update: function () { 7179 if (this._map._animatingZoom && this._bounds) { 7180 return 7181 } 7182 Renderer.prototype._update.call(this); 7183 var b = this._bounds 7184 , size = b.getSize() 7185 , container = this._container; 7186 if (!this._svgSize || !this._svgSize.equals(size)) { 7187 this._svgSize = size; 7188 container.setAttribute('width', size.x); 7189 container.setAttribute('height', size.y) 7190 } 7191 setPosition(container, b.min); 7192 container.setAttribute('viewBox', [b.min.x, b.min.y, size.x, size.y].join(' ')); 7193 this.fire('update') 7194 }, 7195 _initPath: function (layer) { 7196 var path = layer._path = create$2('path'); 7197 if (layer.options.className) { 7198 addClass(path, layer.options.className) 7199 } 7200 if (layer.options.interactive) { 7201 addClass(path, 'leaflet-interactive') 7202 } 7203 this._updateStyle(layer); 7204 this._layers[stamp(layer)] = layer 7205 }, 7206 _addPath: function (layer) { 7207 if (!this._rootGroup) { 7208 this._initContainer() 7209 } 7210 this._rootGroup.appendChild(layer._path); 7211 layer.addInteractiveTarget(layer._path) 7212 }, 7213 _removePath: function (layer) { 7214 remove(layer._path); 7215 layer.removeInteractiveTarget(layer._path); 7216 delete this._layers[stamp(layer)] 7217 }, 7218 _updatePath: function (layer) { 7219 layer._project(); 7220 layer._update() 7221 }, 7222 _updateStyle: function (layer) { 7223 var path = layer._path 7224 , options = layer.options; 7225 if (!path) { 7226 return 7227 } 7228 if (options.stroke) { 7229 path.setAttribute('stroke', options.color); 7230 path.setAttribute('stroke-opacity', options.opacity); 7231 path.setAttribute('stroke-width', options.weight); 7232 path.setAttribute('stroke-linecap', options.lineCap); 7233 path.setAttribute('stroke-linejoin', options.lineJoin); 7234 if (options.dashArray) { 7235 path.setAttribute('stroke-dasharray', options.dashArray) 7236 } else { 7237 path.removeAttribute('stroke-dasharray') 7238 } 7239 if (options.dashOffset) { 7240 path.setAttribute('stroke-dashoffset', options.dashOffset) 7241 } else { 7242 path.removeAttribute('stroke-dashoffset') 7243 } 7244 } else { 7245 path.setAttribute('stroke', 'none') 7246 } 7247 if (options.fill) { 7248 path.setAttribute('fill', options.fillColor || options.color); 7249 path.setAttribute('fill-opacity', options.fillOpacity); 7250 path.setAttribute('fill-rule', options.fillRule || 'evenodd') 7251 } else { 7252 path.setAttribute('fill', 'none') 7253 } 7254 }, 7255 _updatePoly: function (layer, closed) { 7256 this._setPath(layer, pointsToPath(layer._parts, closed)) 7257 }, 7258 _updateCircle: function (layer) { 7259 var p = layer._point 7260 , r = Math.max(Math.round(layer._radius), 1) 7261 , r2 = Math.max(Math.round(layer._radiusY), 1) || r 7262 , arc = 'a' + r + ',' + r2 + ' 0 1,0 '; 7263 var d = layer._empty() ? 'M0 0' : 'M' + (p.x - r) + ',' + p.y + arc + (r * 2) + ',0 ' + arc + (-r * 2) + ',0 '; 7264 this._setPath(layer, d) 7265 }, 7266 _setPath: function (layer, path) { 7267 layer._path.setAttribute('d', path) 7268 }, 7269 _bringToFront: function (layer) { 7270 toFront(layer._path) 7271 }, 7272 _bringToBack: function (layer) { 7273 toBack(layer._path) 7274 } 7275 }); 7276 if (vml) { 7277 SVG.include(vmlMixin) 7278 } 7279 function svg$1(options) { 7280 return svg || vml ? new SVG(options) : null 7281 } 7282 Map.include({ 7283 getRenderer: function (layer) { 7284 var renderer = layer.options.renderer || this._getPaneRenderer(layer.options.pane) || this.options.renderer || this._renderer; 7285 if (!renderer) { 7286 renderer = this._renderer = this._createRenderer() 7287 } 7288 if (!this.hasLayer(renderer)) { 7289 this.addLayer(renderer) 7290 } 7291 return renderer 7292 }, 7293 _getPaneRenderer: function (name) { 7294 if (name === 'overlayPane' || name === undefined) { 7295 return !1 7296 } 7297 var renderer = this._paneRenderers[name]; 7298 if (renderer === undefined) { 7299 renderer = this._createRenderer({ 7300 pane: name 7301 }); 7302 this._paneRenderers[name] = renderer 7303 } 7304 return renderer 7305 }, 7306 _createRenderer: function (options) { 7307 return (this.options.preferCanvas && canvas$1(options)) || svg$1(options) 7308 } 7309 }); 7310 var Rectangle = Polygon.extend({ 7311 initialize: function (latLngBounds, options) { 7312 Polygon.prototype.initialize.call(this, this._boundsToLatLngs(latLngBounds), options) 7313 }, 7314 setBounds: function (latLngBounds) { 7315 return this.setLatLngs(this._boundsToLatLngs(latLngBounds)) 7316 }, 7317 _boundsToLatLngs: function (latLngBounds) { 7318 latLngBounds = toLatLngBounds(latLngBounds);
7319 return [latLngBounds.getSouthWest(), latLngBounds.getNorthWest(), latLngBounds.getNorthEast(), latLngBounds.getSouthEast()] 7320 } 7321 }); 7322 function rectangle(latLngBounds, options) { 7323 return new Rectangle(latLngBounds, options) 7324 } 7325 SVG.create = create$2; 7326 SVG.pointsToPath = pointsToPath; 7327 GeoJSON.geometryToLayer = geometryToLayer; 7328 GeoJSON.coordsToLatLng = coordsToLatLng; 7329 GeoJSON.coordsToLatLngs = coordsToLatLngs; 7330 GeoJSON.latLngToCoords = latLngToCoords; 7331 GeoJSON.latLngsToCoords = latLngsToCoords; 7332 GeoJSON.getFeature = getFeature; 7333 GeoJSON.asFeature = asFeature; 7334 Map.mergeOptions({ 7335 boxZoom: !0 7336 }); 7337 var BoxZoom = Handler.extend({ 7338 initialize: function (leaflet) { 7339 this._map = leaflet; 7340 this._container = leaflet._container; 7341 this._pane = leaflet._panes.overlayPane; 7342 this._resetStateTimeout = 0; 7343 leaflet.on('unload', this._destroy, this) 7344 }, 7345 addHooks: function () { 7346 on(this._container, 'mousedown', this._onMouseDown, this) 7347 }, 7348 removeHooks: function () { 7349 off(this._container, 'mousedown', this._onMouseDown, this) 7350 }, 7351 moved: function () { 7352 return this._moved 7353 }, 7354 _destroy: function () { 7355 remove(this._pane); 7356 delete this._pane 7357 }, 7358 _resetState: function () { 7359 this._resetStateTimeout = 0; 7360 this._moved = !1 7361 }, 7362 _clearDeferredResetState: function () { 7363 if (this._resetStateTimeout !== 0) { 7364 clearTimeout(this._resetStateTimeout); 7365 this._resetStateTimeout = 0 7366 } 7367 }, 7368 _onMouseDown: function (e) { 7369 if (!e.shiftKey || ((e.which !== 1) && (e.button !== 1))) { 7370 return !1 7371 } 7372 this._clearDeferredResetState(); 7373 this._resetState(); 7374 disableTextSelection(); 7375 disableImageDrag(); 7376 this._startPoint = this._map.mouseEventToContainerPoint(e); 7377 on(document, { 7378 contextmenu: stop, 7379 mousemove: this._onMouseMove, 7380 mouseup: this._onMouseUp, 7381 keydown: this._onKeyDown 7382 }, this) 7383 }, 7384 _onMouseMove: function (e) { 7385 if (!this._moved) { 7386 this._moved = !0; 7387 this._box = create$1('div', 'leaflet-zoom-box', this._container); 7388 addClass(this._container, 'leaflet-crosshair'); 7389 this._map.fire('boxzoomstart') 7390 } 7391 this._point = this._map.mouseEventToContainerPoint(e); 7392 var bounds = new Bounds(this._point, this._startPoint) 7393 , size = bounds.getSize(); 7394 setPosition(this._box, bounds.min); 7395 this._box.style.width = size.x + 'px'; 7396 this._box.style.height = size.y + 'px' 7397 }, 7398 _finish: function () { 7399 if (this._moved) { 7400 remove(this._box); 7401 removeClass(this._container, 'leaflet-crosshair') 7402 } 7403 enableTextSelection(); 7404 enableImageDrag(); 7405 off(document, { 7406 contextmenu: stop, 7407 mousemove: this._onMouseMove, 7408 mouseup: this._onMouseUp, 7409 keydown: this._onKeyDown 7410 }, this) 7411 }, 7412 _onMouseUp: function (e) { 7413 if ((e.which !== 1) && (e.button !== 1)) { 7414 return 7415 } 7416 this._finish(); 7417 if (!this._moved) { 7418 return 7419 } 7420 this._clearDeferredResetState(); 7421 this._resetStateTimeout = setTimeout(bind(this._resetState, this), 0); 7422 var bounds = new LatLngBounds(this._map.containerPointToLatLng(this._startPoint), this._map.containerPointToLatLng(this._point)); 7423 this._map.fitBounds(bounds).fire('boxzoomend', { 7424 boxZoomBounds: bounds 7425 }) 7426 }, 7427 _onKeyDown: function (e) { 7428 if (e.keyCode === 27) { 7429 this._finish() 7430 } 7431 } 7432 }); 7433 Map.addInitHook('addHandler', 'boxZoom', BoxZoom); 7434 Map.mergeOptions({ 7435 doubleClickZoom: !0 7436 }); 7437 var DoubleClickZoom = Handler.extend({ 7438 addHooks: function () { 7439 this._map.on('dblclick', this._onDoubleClick, this) 7440 }, 7441 removeHooks: function () { 7442 this._map.off('dblclick', this._onDoubleClick, this) 7443 }, 7444 _onDoubleClick: function (e) { 7445 var leaflet = this._map 7446 , oldZoom = leaflet.getZoom() 7447 , delta = leaflet.options.zoomDelta 7448 , zoom = e.originalEvent.shiftKey ? oldZoom - delta : oldZoom + delta; 7449 if (leaflet.options.doubleClickZoom === 'center') { 7450 leaflet.setZoom(zoom) 7451 } else { 7452 leaflet.setZoomAround(e.containerPoint, zoom) 7453 } 7454 } 7455 }); 7456 Map.addInitHook('addHandler', 'doubleClickZoom', DoubleClickZoom); 7457 Map.mergeOptions({ 7458 dragging: !0, 7459 inertia: !android23, 7460 inertiaDeceleration: 3400, 7461 inertiaMaxSpeed: Infinity, 7462 easeLinearity: 0.2, 7463 worldCopyJump: !1, 7464 maxBoundsViscosity: 0.0 7465 }); 7466 var Drag = Handler.extend({ 7467 addHooks: function () { 7468 if (!this._draggable) { 7469 var leaflet = this._map; 7470 this._draggable = new Draggable(leaflet._mapPane, leaflet._container); 7471 this._draggable.on({ 7472 dragstart: this._onDragStart, 7473 drag: this._onDrag, 7474 dragend: this._onDragEnd 7475 }, this); 7476 this._draggable.on('predrag', this._onPreDragLimit, this); 7477 if (leaflet.options.worldCopyJump) { 7478 this._draggable.on('predrag', this._onPreDragWrap, this); 7479 leaflet.on('zoomend', this._onZoomEnd, this); 7480 leaflet.whenReady(this._onZoomEnd, this) 7481 } 7482 } 7483 addClass(this._map._container, 'leaflet-grab leaflet-touch-drag'); 7484 this._draggable.enable(); 7485 this._positions = []; 7486 this._times = [] 7487 }, 7488 removeHooks: function () { 7489 removeClass(this._map._container, 'leaflet-grab'); 7490 removeClass(this._map._container, 'leaflet-touch-drag'); 7491 this._draggable.disable() 7492 }, 7493 moved: function () { 7494 return this._draggable && this._draggable._moved 7495 }, 7496 moving: function () {
7497 return this._draggable && this._draggable._moving 7498 }, 7499 _onDragStart: function () { 7500 var leaflet = this._map; 7501 leaflet._stop(); 7502 if (this._map.options.maxBounds && this._map.options.maxBoundsViscosity) { 7503 var bounds = toLatLngBounds(this._map.options.maxBounds); 7504 this._offsetLimit = toBounds(this._map.latLngToContainerPoint(bounds.getNorthWest()).multiplyBy(-1), this._map.latLngToContainerPoint(bounds.getSouthEast()).multiplyBy(-1).add(this._map.getSize())); 7505 this._viscosity = Math.min(1.0, Math.max(0.0, this._map.options.maxBoundsViscosity)) 7506 } else { 7507 this._offsetLimit = null 7508 } 7509 leaflet.fire('movestart').fire('dragstart'); 7510 if (leaflet.options.inertia) { 7511 this._positions = []; 7512 this._times = [] 7513 } 7514 }, 7515 _onDrag: function (e) { 7516 if (this._map.options.inertia) { 7517 var time = this._lastTime = +new Date() 7518 , pos = this._lastPos = this._draggable._absPos || this._draggable._newPos; 7519 this._positions.push(pos); 7520 this._times.push(time); 7521 this._prunePositions(time) 7522 } 7523 this._map.fire('move', e).fire('drag', e) 7524 }, 7525 _prunePositions: function (time) { 7526 while (this._positions.length > 1 && time - this._times[0] > 50) { 7527 this._positions.shift(); 7528 this._times.shift() 7529 } 7530 }, 7531 _onZoomEnd: function () { 7532 var pxCenter = this._map.getSize().divideBy(2) 7533 , pxWorldCenter = this._map.latLngToLayerPoint([0, 0]); 7534 this._initialWorldOffset = pxWorldCenter.subtract(pxCenter).x; 7535 this._worldWidth = this._map.getPixelWorldBounds().getSize().x 7536 }, 7537 _viscousLimit: function (value, threshold) { 7538 return value - (value - threshold) * this._viscosity 7539 }, 7540 _onPreDragLimit: function () { 7541 if (!this._viscosity || !this._offsetLimit) { 7542 return 7543 } 7544 var offset = this._draggable._newPos.subtract(this._draggable._startPos); 7545 var limit = this._offsetLimit; 7546 if (offset.x < limit.min.x) { 7547 offset.x = this._viscousLimit(offset.x, limit.min.x) 7548 } 7549 if (offset.y < limit.min.y) { 7550 offset.y = this._viscousLimit(offset.y, limit.min.y) 7551 } 7552 if (offset.x > limit.max.x) { 7553 offset.x = this._viscousLimit(offset.x, limit.max.x) 7554 } 7555 if (offset.y > limit.max.y) { 7556 offset.y = this._viscousLimit(offset.y, limit.max.y) 7557 } 7558 this._draggable._newPos = this._draggable._startPos.add(offset) 7559 }, 7560 _onPreDragWrap: function () { 7561 var worldWidth = this._worldWidth 7562 , halfWidth = Math.round(worldWidth / 2) 7563 , dx = this._initialWorldOffset 7564 , x = this._draggable._newPos.x 7565 , newX1 = (x - halfWidth + dx) % worldWidth + halfWidth - dx 7566 , newX2 = (x + halfWidth + dx) % worldWidth - halfWidth - dx 7567 , newX = Math.abs(newX1 + dx) < Math.abs(newX2 + dx) ? newX1 : newX2; 7568 this._draggable._absPos = this._draggable._newPos.clone(); 7569 this._draggable._newPos.x = newX 7570 }, 7571 _onDragEnd: function (e) { 7572 var leaflet = this._map 7573 , options = leaflet.options 7574 , noInertia = !options.inertia || this._times.length < 2; 7575 leaflet.fire('dragend', e); 7576 if (noInertia) { 7577 leaflet.fire('moveend') 7578 } else { 7579 this._prunePositions(+new Date()); 7580 var direction = this._lastPos.subtract(this._positions[0]) 7581 , duration = (this._lastTime - this._times[0]) / 1000 7582 , ease = options.easeLinearity 7583 , speedVector = direction.multiplyBy(ease / duration) 7584 , speed = speedVector.distanceTo([0, 0]) 7585 , limitedSpeed = Math.min(options.inertiaMaxSpeed, speed) 7586 , limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed) 7587 , decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease) 7588 , offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round(); 7589 if (!offset.x && !offset.y) { 7590 leaflet.fire('moveend') 7591 } else { 7592 offset = leaflet._limitOffset(offset, leaflet.options.maxBounds);
7593 requestAnimFrame(function () { 7594 leaflet.panBy(offset, { 7595 duration: decelerationDuration, 7596 easeLinearity: ease, 7597 noMoveStart: !0, 7598 animate: !0 7599 }) 7600 }) 7601 } 7602 } 7603 } 7604 }); 7605 Map.addInitHook('addHandler', 'dragging', Drag); 7606 Map.mergeOptions({ 7607 keyboard: !0, 7608 keyboardPanDelta: 80 7609 }); 7610 var Keyboard = Handler.extend({ 7611 keyCodes: { 7612 left: [37], 7613 right: [39], 7614 down: [40], 7615 up: [38], 7616 zoomIn: [187, 107, 61, 171], 7617 zoomOut: [189, 109, 54, 173] 7618 }, 7619 initialize: function (leaflet) { 7620 this._map = leaflet; 7621 this._setPanDelta(leaflet.options.keyboardPanDelta); 7622 this._setZoomDelta(leaflet.options.zoomDelta) 7623 }, 7624 addHooks: function () { 7625 var container = this._map._container; 7626 if (container.tabIndex <= 0) { 7627 container.tabIndex = '0' 7628 } 7629 on(container, { 7630 focus: this._onFocus, 7631 blur: this._onBlur, 7632 mousedown: this._onMouseDown 7633 }, this); 7634 this._map.on({ 7635 focus: this._addHooks, 7636 blur: this._removeHooks 7637 }, this) 7638 }, 7639 removeHooks: function () { 7640 this._removeHooks(); 7641 off(this._map._container, { 7642 focus: this._onFocus, 7643 blur: this._onBlur, 7644 mousedown: this._onMouseDown 7645 }, this); 7646 this._map.off({ 7647 focus: this._addHooks, 7648 blur: this._removeHooks 7649 }, this) 7650 }, 7651 _onMouseDown: function () { 7652 if (this._focused) { 7653 return 7654 } 7655 var body = document.body 7656 , docEl = document.documentElement 7657 , top = body.scrollTop || docEl.scrollTop 7658 , left = body.scrollLeft || docEl.scrollLeft; 7659 this._map._container.focus(); 7660 window.scrollTo(left, top) 7661 }, 7662 _onFocus: function () { 7663 this._focused = !0; 7664 this._map.fire('focus') 7665 }, 7666 _onBlur: function () { 7667 this._focused = !1; 7668 this._map.fire('blur') 7669 }, 7670 _setPanDelta: function (panDelta) { 7671 var keys = this._panKeys = {}, codes = this.keyCodes, i, len; 7672 for (i = 0, 7673 len = codes.left.length; i < len; i++) { 7674 keys[codes.left[i]] = [-1 * panDelta, 0] 7675 } 7676 for (i = 0, 7677 len = codes.right.length; i < len; i++) { 7678 keys[codes.right[i]] = [panDelta, 0] 7679 } 7680 for (i = 0, 7681 len = codes.down.length; i < len; i++) { 7682 keys[codes.down[i]] = [0, panDelta] 7683 } 7684 for (i = 0, 7685 len = codes.up.length; i < len; i++) { 7686 keys[codes.up[i]] = [0, -1 * panDelta] 7687 } 7688 }, 7689 _setZoomDelta: function (zoomDelta) { 7690 var keys = this._zoomKeys = {}, codes = this.keyCodes, i, len; 7691 for (i = 0, 7692 len = codes.zoomIn.length; i < len; i++) { 7693 keys[codes.zoomIn[i]] = zoomDelta 7694 } 7695 for (i = 0, 7696 len = codes.zoomOut.length; i < len; i++) { 7697 keys[codes.zoomOut[i]] = -zoomDelta 7698 } 7699 }, 7700 _addHooks: function () { 7701 on(document, 'keydown', this._onKeyDown, this) 7702 }, 7703 _removeHooks: function () { 7704 off(document, 'keydown', this._onKeyDown, this) 7705 }, 7706 _onKeyDown: function (e) { 7707 if (e.altKey || e.ctrlKey || e.metaKey) { 7708 return 7709 } 7710 var key = e.keyCode, leaflet = this._map, offset; 7711 if (key in this._panKeys) { 7712 if (!leaflet._panAnim || !leaflet._panAnim._inProgress) { 7713 offset = this._panKeys[key]; 7714 if (e.shiftKey) { 7715 offset = toPoint(offset).multiplyBy(3) 7716 } 7717 leaflet.panBy(offset); 7718 if (leaflet.options.maxBounds) { 7719 leaflet.panInsideBounds(leaflet.options.maxBounds) 7720 } 7721 } 7722 } else if (key in this._zoomKeys) { 7723 leaflet.setZoom(leaflet.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]) 7724 } else if (key === 27 && leaflet._popup && leaflet._popup.options.closeOnEscapeKey) { 7725 leaflet.closePopup() 7726 } else { 7727 return 7728 } 7729 stop(e) 7730 } 7731 });
7732 Map.addInitHook('addHandler', 'keyboard', Keyboard); 7733 Map.mergeOptions({ 7734 scrollWheelZoom: !0, 7735 wheelDebounceTime: 40, 7736 wheelPxPerZoomLevel: 60 7737 }); 7738 var ScrollWheelZoom = Handler.extend({ 7739 addHooks: function () { 7740 on(this._map._container, 'mousewheel', this._onWheelScroll, this); 7741 this._delta = 0 7742 }, 7743 removeHooks: function () { 7744 off(this._map._container, 'mousewheel', this._onWheelScroll, this) 7745 }, 7746 _onWheelScroll: function (e) { 7747 var delta = getWheelDelta(e); 7748 var debounce = this._map.options.wheelDebounceTime; 7749 this._delta += delta; 7750 this._lastMousePos = this._map.mouseEventToContainerPoint(e); 7751 if (!this._startTime) { 7752 this._startTime = +new Date() 7753 } 7754 var left = Math.max(debounce - (+new Date() - this._startTime), 0); 7755 clearTimeout(this._timer); 7756 this._timer = setTimeout(bind(this._performZoom, this), left); 7757 stop(e) 7758 }, 7759 _performZoom: function () { 7760 var leaflet = this._map 7761 , zoom = leaflet.getZoom() 7762 , snap = this._map.options.zoomSnap || 0; 7763 leaflet._stop(); 7764 var d2 = this._delta / (this._map.options.wheelPxPerZoomLevel * 4) 7765 , d3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2 7766 , d4 = snap ? Math.ceil(d3 / snap) * snap : d3 7767 , delta = leaflet._limitZoom(zoom + (this._delta > 0 ? d4 : -d4)) - zoom; 7768 this._delta = 0; 7769 this._startTime = null; 7770 if (!delta) { 7771 return 7772 } 7773 if (leaflet.options.scrollWheelZoom === 'center') { 7774 leaflet.setZoom(zoom + delta) 7775 } else { 7776 leaflet.setZoomAround(this._lastMousePos, zoom + delta) 7777 } 7778 } 7779 }); 7780 Map.addInitHook('addHandler', 'scrollWheelZoom', ScrollWheelZoom); 7781 Map.mergeOptions({ 7782 tap: !0, 7783 tapTolerance: 15 7784 }); 7785 var Tap = Handler.extend({ 7786 addHooks: function () { 7787 on(this._map._container, 'touchstart', this._onDown, this) 7788 }, 7789 removeHooks: function () { 7790 off(this._map._container, 'touchstart', this._onDown, this) 7791 }, 7792 _onDown: function (e) { 7793 if (!e.touches) { 7794 return 7795 } 7796 preventDefault(e); 7797 this._fireClick = !0; 7798 if (e.touches.length > 1) { 7799 this._fireClick = !1; 7800 clearTimeout(this._holdTimeout); 7801 return 7802 } 7803 var first = e.touches[0] 7804 , el = first.target; 7805 this._startPos = this._newPos = new Point(first.clientX, first.clientY); 7806 if (el.tagName && el.tagName.toLowerCase() === 'a') { 7807 addClass(el, 'leaflet-active') 7808 } 7809 this._holdTimeout = setTimeout(bind(function () { 7810 if (this._isTapValid()) { 7811 this._fireClick = !1; 7812 this._onUp(); 7813 this._simulateEvent('contextmenu', first) 7814 } 7815 }, this), 1000); 7816 this._simulateEvent('mousedown', first); 7817 on(document, { 7818 touchmove: this._onMove, 7819 touchend: this._onUp 7820 }, this) 7821 }, 7822 _onUp: function (e) { 7823 clearTimeout(this._holdTimeout); 7824 off(document, { 7825 touchmove: this._onMove, 7826 touchend: this._onUp 7827 }, this); 7828 if (this._fireClick && e && e.changedTouches) { 7829 var first = e.changedTouches[0] 7830 , el = first.target; 7831 if (el && el.tagName && el.tagName.toLowerCase() === 'a') { 7832 removeClass(el, 'leaflet-active') 7833 } 7834 this._simulateEvent('mouseup', first); 7835 if (this._isTapValid()) { 7836 this._simulateEvent('click', first) 7837 } 7838 } 7839 }, 7840 _isTapValid: function () { 7841 return this._newPos.distanceTo(this._startPos) <= this._map.options.tapTolerance 7842 }, 7843 _onMove: function (e) { 7844 var first = e.touches[0]; 7845 this._newPos = new Point(first.clientX, first.clientY); 7846 this._simulateEvent('mousemove', first) 7847 }, 7848 _simulateEvent: function (type, e) { 7849 var simulatedEvent = document.createEvent('MouseEvents'); 7850 simulatedEvent._simulated = !0; 7851 e.target._simulatedClick = !0; 7852 simulatedEvent.initMouseEvent(type, !0, !0, window, 1, e.screenX, e.screenY, e.clientX, e.clientY, !1, !1, !1, !1, 0, null); 7853 e.target.dispatchEvent(simulatedEvent) 7854 } 7855 }); 7856 if (touch && !pointer) { 7857 Map.addInitHook('addHandler', 'tap', Tap) 7858 } 7859 Map.mergeOptions({ 7860 touchZoom: touch && !android23, 7861 bounceAtZoomLimits: !0 7862 }); 7863 var TouchZoom = Handler.extend({ 7864 addHooks: function () { 7865 addClass(this._map._container, 'leaflet-touch-zoom'); 7866 on(this._map._container, 'touchstart', this._onTouchStart, this) 7867 }, 7868 removeHooks: function () { 7869 removeClass(this._map._container, 'leaflet-touch-zoom'); 7870 off(this._map._container, 'touchstart', this._onTouchStart, this) 7871 }, 7872 _onTouchStart: function (e) { 7873 var leaflet = this._map; 7874 if (!e.touches || e.touches.length !== 2 || leaflet._animatingZoom || this._zooming) { 7875 return 7876 } 7877 var p1 = leaflet.mouseEventToContainerPoint(e.touches[0]) 7878 , p2 = leaflet.mouseEventToContainerPoint(e.touches[1]); 7879 this._centerPoint = leaflet.getSize()._divideBy(2); 7880 this._startLatLng = leaflet.containerPointToLatLng(this._centerPoint); 7881 if (leaflet.options.touchZoom !== 'center') { 7882 this._pinchStartLatLng = leaflet.containerPointToLatLng(p1.add(p2)._divideBy(2)) 7883 } 7884 this._startDist = p1.distanceTo(p2); 7885 this._startZoom = leaflet.getZoom(); 7886 this._moved = !1; 7887 this._zooming = !0; 7888 leaflet._stop(); 7889 on(document, 'touchmove', this._onTouchMove, this); 7890 on(document, 'touchend', this._onTouchEnd, this); 7891 preventDefault(e) 7892 }, 7893 _onTouchMove: function (e) { 7894 if (!e.touches || e.touches.length !== 2 || !this._zooming) { 7895 return 7896 } 7897 var leaflet = this._map 7898 , p1 = leaflet.mouseEventToContainerPoint(e.touches[0]) 7899 , p2 = leaflet.mouseEventToContainerPoint(e.touches[1]) 7900 , scale = p1.distanceTo(p2) / this._startDist; 7901 this._zoom = leaflet.getScaleZoom(scale, this._startZoom); 7902 if (!leaflet.options.bounceAtZoomLimits && ((this._zoom < leaflet.getMin
7902Zoom() && scale < 1) || (this._zoom > leaflet.getMaxZoom() && scale > 1))) { 7903 this._zoom = leaflet._limitZoom(this._zoom) 7904 } 7905 if (leaflet.options.touchZoom === 'center') { 7906 this._center = this._startLatLng; 7907 if (scale === 1) { 7908 return 7909 } 7910 } else { 7911 var delta = p1._add(p2)._divideBy(2)._subtract(this._centerPoint); 7912 if (scale === 1 && delta.x === 0 && delta.y === 0) { 7913 return 7914 } 7915 this._center = leaflet.unproject(leaflet.project(this._pinchStartLatLng, this._zoom).subtract(delta), this._zoom) 7916 } 7917 if (!this._moved) { 7918 leaflet._moveStart(!0, !1); 7919 this._moved = !0 7920 } 7921 cancelAnimFrame(this._animRequest); 7922 var moveFn = bind(leaflet._move, leaflet, this._center, this._zoom, { 7923 pinch: !0, 7924 round: !1 7925 }); 7926 this._animRequest = requestAnimFrame(moveFn, this, !0); 7927 preventDefault(e) 7928 }, 7929 _onTouchEnd: function () { 7930 if (!this._moved || !this._zooming) { 7931 this._zooming = !1; 7932 return 7933 } 7934 this._zooming = !1; 7935 cancelAnimFrame(this._animRequest); 7936 off(document, 'touchmove', this._onTouchMove); 7937 off(document, 'touchend', this._onTouchEnd); 7938 if (this._map.options.zoomAnimation) { 7939 this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), !0, this._map.options.zoomSnap) 7940 } else { 7941 this._map._resetView(this._center, this._map._limitZoom(this._zoom)) 7942 } 7943 } 7944 }); 7945 Map.addInitHook('addHandler', 'touchZoom', TouchZoom); 7946 Map.BoxZoom = BoxZoom; 7947 Map.DoubleClickZoom = DoubleClickZoom; 7948 Map.Drag = Drag; 7949 Map.Keyboard = Keyboard; 7950 Map.ScrollWheelZoom = ScrollWheelZoom; 7951 Map.Tap = Tap; 7952 Map.TouchZoom = TouchZoom; 7953 Object.freeze = freeze; 7954 exports.version = version; 7955 exports.Control = Control; 7956 exports.control = control; 7957 exports.Browser = Browser; 7958 exports.Evented = Evented; 7959 exports.Mixin = Mixin; 7960 exports.Util = Util; 7961 exports.Class = Class; 7962 exports.Handler = Handler; 7963 exports.extend = extend; 7964 exports.bind = bind; 7965 exports.stamp = stamp; 7966 exports.setOptions = setOptions; 7967 exports.DomEvent = DomEvent; 7968 exports.DomUtil = DomUtil; 7969 exports.PosAnimation = PosAnimation; 7970 exports.Draggable = Draggable; 7971 exports.LineUtil = LineUtil; 7972 exports.PolyUtil = PolyUtil; 7973 exports.Point = Point; 7974 exports.point = toPoint; 7975 exports.Bounds = Bounds; 7976 exports.bounds = toBounds; 7977 exports.Transformation = Transformation; 7978 exports.transformation = toTransformation; 7979 exports.Projection = index; 7980 exports.LatLng = LatLng; 7981 exports.latLng = toLatLng; 7982 exports.LatLngBounds = LatLngBounds; 7983 exports.latLngBounds = toLatLngBounds; 7984 exports.CRS = CRS; 7985 exports.GeoJSON = GeoJSON; 7986 exports.geoJSON = geoJSON; 7987 exports.geoJson = geoJson; 7988 exports.Layer = Layer; 7989 exports.LayerGroup = LayerGroup; 7990 exports.layerGroup = layerGroup; 7991 exports.FeatureGroup = FeatureGroup; 7992 exports.featureGroup = featureGroup; 7993 exports.ImageOverlay = ImageOverlay; 7994 exports.imageOverlay = imageOverlay; 7995 exports.VideoOverlay = VideoOverlay; 7996 exports.videoOverlay = videoOverlay; 7997 exports.DivOverlay = DivOverlay; 7998 exports.Popup = Popup; 7999 exports.popup = popup; 8000 exports.Tooltip = Tooltip; 8001 exports.tooltip = tooltip; 8002 exports.Icon = Icon; 8003 exports.icon = icon; 8004 exports.DivIcon = DivIcon; 8005 exports.divIcon = divIcon; 8006 exports.Marker = Marker; 8007 exports.marker = marker; 8008 exports.TileLayer = TileLayer; 8009 exports.addOGCServices = addOGCServices; 8010 exports.GridLayer = GridLayer; 8011 exports.gridLayer = gridLayer; 8012 exports.SVG = SVG; 8013 exports.svg = svg$1; 8014 exports.Renderer = Renderer; 8015 exports.Canvas = Canvas; 8016 exports.canvas = canvas$1; 8017 exports.Path = Path; 8018 exports.CircleMarker = CircleMarker; 8019 exports.circleMarker = circleMarker; 8020 exports.Circle = Circle; 8021 exports.circle = circle; 8022 exports.Polyline = Polyline; 8023 exports.polyline = polyline; 8024 exports.Polygon = Polygon; 8025 exports.polygon = polygon; 8026 exports.Rectangle = Rectangle; 8027 exports.rectangle = rectangle; 8028 exports.Map = Map; 8029 exports.leaflet = createMap; 8030 var oldL = window.L; 8031 exports.noConflict = function () { 8032 window.L = oldL; 8033 return this 8034 }
8035 window.L = exports 8036} 8037))); 8038(function (global, factory) { 8039 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('leaflet')) : typeof define === 'function' && define.amd ? define(['exports', 'leaflet'], factory) : (factory((global.L = global.L || {}, 8040 global.L.esri = {}), global.L)) 8041}(this, (function (exports, leaflet) { 8042 'use strict'; 8043 var version = "2.2.1"; 8044 var cors = ((window.XMLHttpRequest && 'withCredentials' in new window.XMLHttpRequest())); 8045 var pointerEvents = document.documentElement.style.pointerEvents === ''; 8046 var Support = { 8047 cors: cors, 8048 pointerEvents: pointerEvents 8049 }; 8050 var options = { 8051 attributionWidthOffset: 55 8052 }; 8053 var callbacks = 0; 8054 function serialize(params) { 8055 var data = ''; 8056 params.f = params.f || 'json'; 8057 for (var key in params) { 8058 if (params.hasOwnProperty(key)) { 8059 var param = params[key]; 8060 var type = Object.prototype.toString.call(param); 8061 var value; 8062 if (data.length) { 8063 data += '&' 8064 } 8065 if (type === '[object Array]') { 8066 value = (Object.prototype.toString.call(param[0]) === '[object Object]') ? JSON.stringify(param) : param.join(',') 8067 } else if (type === '[object Object]') { 8068 value = JSON.stringify(param) 8069 } else if (type === '[object Date]') { 8070 value = param.valueOf() 8071 } else { 8072 value = param 8073 } 8074 data += encodeURIComponent(key) + '=' + encodeURIComponent(value) 8075 } 8076 } 8077 return data 8078 } 8079 function createRequest(callback, context) { 8080 var httpRequest = new window.XMLHttpRequest(); 8081 httpRequest.onerror = function (e) { 8082 httpRequest.onreadystatechange = leaflet.Util.falseFn; 8083 callback.call(context, { 8084 error: { 8085 code: 500, 8086 message: 'XMLHttpRequest error' 8087 } 8088 }, null) 8089 } 8090 ; 8091 httpRequest.onreadystatechange = function () { 8092 var response; 8093 var error; 8094 if (httpRequest.readyState === 4) { 8095 try { 8096 response = JSON.parse(httpRequest.responseText) 8097 } catch (e) { 8098 response = null; 8099 error = { 8100 code: 500, 8101 message: 'Could not parse response as JSON. This could also be caused by a CORS or XMLHttpRequest error.' 8102 } 8103 } 8104 if (!error && response.error) { 8105 error = response.error; 8106 response = null 8107 } 8108 httpRequest.onerror = leaflet.Util.falseFn; 8109 callback.call(context, error, response) 8110 } 8111 } 8112 ; 8113 httpRequest.ontimeout = function () { 8114 this.onerror() 8115 } 8116 ; 8117 return httpRequest 8118 } 8119 function xmlHttpPost(url, params, callback, context) { 8120 var httpRequest = createRequest(callback, context); 8121 httpRequest.open('POST', url); 8122 if (typeof context !== 'undefined' && context !== null) { 8123 if (typeof context.options !== 'undefined') { 8124 httpRequest.timeout = context.options.timeout 8125 } 8126 } 8127 httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 8128 httpRequest.send(serialize(params)); 8129 return httpRequest 8130 } 8131 function xmlHttpGet(url, params, callback, context) { 8132 var httpRequest = createRequest(callback, context); 8133 httpRequest.open('GET', url + '?' + serialize(params), !0); 8134 if (typeof context !== 'undefined' && context !== null) { 8135 if (typeof context.options !== 'undefined') { 8136 httpRequest.timeout = context.options.timeout 8137 } 8138 } 8139 httpRequest.send(null); 8140 return httpRequest 8141 } 8142 function request(url, params, callback, context) { 8143 var paramString = serialize(params); 8144 var httpRequest = createRequest(callback, context); 8145 var requestLength = (url + '?' + paramString).length; 8146 if (requestLength <= 2000 && Support.cors) { 8147 httpRequest.open('GET', url + '?' + paramString) 8148 } else if (requestLength > 2000 && Support.cors) { 8149 httpRequest.open('POST', url); 8150 httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8') 8151 } 8152 if (typeof context !== 'undefined' && context !== null) { 8153 if (typeof context.options !== 'undefined') { 8154 httpRequest.timeout = context.options.timeout 8155 } 8156 } 8157 if (requestLength <= 2000 && Support.cors) { 8158 httpRequest.send(null) 8159 } else if (requestLength > 2000 && Support.cors) { 8160 httpRequest.send(paramString) 8161 } else if (requestLength <= 2000 && !Support.cors) { 8162 return jsonp(url, params, callback, context) 8163 } else { 8164 warn('a request to ' + url + ' was longer then 2000 characters and this browser cannot make a cross-domain post request. Please use a proxy http://esri.github.io/esri-leaflet/api-reference/request.html'); 8165 return 8166 } 8167 return httpRequest 8168 } 8169 function jsonp(url, params, callback, context) { 8170 window._EsrileafletCallbacks = window._EsrileafletCallbacks || {}; 8171 var callbackId = 'c' + callbacks; 8172 params.callback = 'window._EsrileafletCallbacks.' + callbackId; 8173 window._EsrileafletCallbacks[callbackId] = function (response) { 8174 if (window._EsrileafletCallbacks[callbackId] !== !0) { 8175 var error; 8176 var responseType = Object.prototype.toString.call(response); 8177 if (!(responseType === '[object Object]' || responseType === '[object Array]')) { 8178 error = { 8179 error: { 8180 code: 500, 8181 message: 'Expected array or object as JSONP response' 8182 } 8183 }; 8184 response = null 8185 } 8186 if (!error && response.error) { 8187 error = response; 8188 response = null 8189 } 8190 callback.call(context, error, response); 8191 window._EsrileafletCallbacks[callbackId] = !0 8192 } 8193 } 8194 ; 8195 var script = leaflet.DomUtil.create('script', null, document.body); 8196 script.type = 'text/javascript'; 8197 script.src = url + '?' + serialize(params); 8198 script.id = callbackId; 8199 script.onerror = function (error) { 8200 if (error && window._EsrileafletCallbacks[callbackId] !== !0) { 8201 var err = { 8202 error: { 8203 code: 500, 8204 message: 'An unknown error occurred' 8205 } 8206 }; 8207 callback.call(context, err); 8208 window._EsrileafletCallbacks[callbackId] = !0 8209 } 8210 } 8211 ; 8212 leaflet.DomUtil.addClass(script, 'esri-leaflet-jsonp'); 8213 callbacks++; 8214 return { 8215 id: callbackId, 8216 url: script.src, 8217 abort: function () { 8218 window._EsrileafletCallbacks._callback[callbackId]({ 8219 code: 0, 8220 message: 'Request aborted.'
8221 }) 8222 } 8223 } 8224 } 8225 var get = ((Support.cors) ? xmlHttpGet : jsonp); 8226 get.CORS = xmlHttpGet; 8227 get.JSONP = jsonp; 8228 var Request = { 8229 request: request, 8230 get: get, 8231 post: xmlHttpPost 8232 }; 8233 function pointsEqual(a, b) { 8234 for (var i = 0; i < a.length; i++) { 8235 if (a[i] !== b[i]) { 8236 return !1 8237 } 8238 } 8239 return !0 8240 } 8241 function closeRing(coordinates) { 8242 if (!pointsEqual(coordinates[0], coordinates[coordinates.length - 1])) { 8243 coordinates.push(coordinates[0]) 8244 } 8245 return coordinates 8246 } 8247 function ringIsClockwise(ringToTest) { 8248 var total = 0; 8249 var i = 0; 8250 var rLength = ringToTest.length; 8251 var pt1 = ringToTest[i]; 8252 var pt2; 8253 for (i; i < rLength - 1; i++) { 8254 pt2 = ringToTest[i + 1]; 8255 total += (pt2[0] - pt1[0]) * (pt2[1] + pt1[1]); 8256 pt1 = pt2 8257 } 8258 return (total >= 0) 8259 } 8260 function vertexIntersectsVertex(a1, a2, b1, b2) { 8261 var uaT = ((b2[0] - b1[0]) * (a1[1] - b1[1])) - ((b2[1] - b1[1]) * (a1[0] - b1[0])); 8262 var ubT = ((a2[0] - a1[0]) * (a1[1] - b1[1])) - ((a2[1] - a1[1]) * (a1[0] - b1[0])); 8263 var uB = ((b2[1] - b1[1]) * (a2[0] - a1[0])) - ((b2[0] - b1[0]) * (a2[1] - a1[1])); 8264 if (uB !== 0) { 8265 var ua = uaT / uB; 8266 var ub = ubT / uB; 8267 if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) { 8268 return !0 8269 } 8270 } 8271 return !1 8272 } 8273 function arrayIntersectsArray(a, b) { 8274 for (var i = 0; i < a.length - 1; i++) { 8275 for (var j = 0; j < b.length - 1; j++) { 8276 if (vertexIntersectsVertex(a[i], a[i + 1], b[j], b[j + 1])) { 8277 return !0 8278 } 8279 } 8280 } 8281 return !1 8282 } 8283 function coordinatesContainPoint(coordinates, point) { 8284 var contains = !1; 8285 for (var i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) { 8286 if (((coordinates[i][1] <= point[1] && point[1] < coordinates[j][1]) || (coordinates[j][1] <= point[1] && point[1] < coordinates[i][1])) && (point[0] < (((coordinates[j][0] - coordinates[i][0]) * (point[1] - coordinates[i][1])) / (coordinates[j][1] - coordinates[i][1])) + coordinates[i][0])) { 8287 contains = !contains 8288 } 8289 } 8290 return contains 8291 } 8292 function coordinatesContainCoordinates(outer, inner) { 8293 var intersects = arrayIntersectsArray(outer, inner); 8294 var contains = coordinatesContainPoint(outer, inner[0]); 8295 if (!intersects && contains) { 8296 return !0 8297 } 8298 return !1 8299 } 8300 function convertRingsToGeoJSON(rings) { 8301 var outerRings = []; 8302 var holes = []; 8303 var x; 8304 var outerRing; 8305 var hole; 8306 for (var r = 0; r < rings.length; r++) { 8307 var ring = closeRing(rings[r].slice(0)); 8308 if (ring.length < 4) { 8309 continue 8310 } 8311 if (ringIsClockwise(ring)) { 8312 var polygon = [ring.slice().reverse()]; 8313 outerRings.push(polygon) 8314 } else { 8315 holes.push(ring.slice().reverse()) 8316 } 8317 } 8318 var uncontainedHoles = []; 8319 while (holes.length) { 8320 hole = holes.pop(); 8321 var contained = !1; 8322 for (x = outerRings.length - 1; x >= 0; x--) { 8323 outerRing = outerRings[x][0]; 8324 if (coordinatesContainCoordinates(outerRing, hole)) { 8325 outerRings[x].push(hole); 8326 contained = !0; 8327 break 8328 } 8329 } 8330 if (!contained) { 8331 uncontainedHoles.push(hole) 8332 } 8333 } 8334 while (uncontainedHoles.length) { 8335 hole = uncontainedHoles.pop(); 8336 var intersects = !1; 8337 for (x = outerRings.length - 1; x >= 0; x--) { 8338 outerRing = outerRings[x][0]; 8339 if (arrayIntersectsArray(outerRing, hole)) { 8340 outerRings[x].push(hole); 8341 intersects = !0; 8342 break 8343 } 8344 } 8345 if (!intersects) { 8346 outerRings.push([hole.reverse()]) 8347 } 8348 } 8349 if (outerRings.length === 1) { 8350 return { 8351 type: 'Polygon', 8352 coordinates: outerRings[0] 8353 } 8354 } else { 8355 return { 8356 type: 'MultiPolygon', 8357 coordinates: outerRings 8358 } 8359 } 8360 } 8361 function orientRings(poly) { 8362 var output = []; 8363 var polygon = poly.slice(0); 8364 var outerRing = closeRing(polygon.shift().slice(0)); 8365 if (outerRing.length >= 4) { 8366 if (!ringIsClockwise(outerRing)) { 8367 outerRing.reverse() 8368 } 8369 output.push(outerRing); 8370 for (var i = 0; i < polygon.length; i++) { 8371 var hole = closeRing(polygon[i].slice(0)); 8372 if (hole.length >= 4) { 8373 if (ringIsClockwise(hole)) { 8374 hole.reverse() 8375 } 8376 output.push(hole) 8377 } 8378 } 8379 } 8380 return output 8381 } 8382 function flattenMultiPolygonRings(rings) { 8383 var output = []; 8384 for (var i = 0; i < rings.length; i++) { 8385 var polygon = orientRings(rings[i]); 8386 for (var x = polygon.length - 1; x >= 0; x--) { 8387 var ring = polygon[x].slice(0); 8388 output.push(ring) 8389 } 8390 } 8391 return output 8392 } 8393 function shallowClone(obj) { 8394 var target = {}; 8395 for (var i in obj) { 8396 if (obj.hasOwnProperty(i)) { 8397 target[i] = obj[i] 8398 } 8399 } 8400 return target 8401 } 8402 function getId(attributes, idAttribute) { 8403 var keys = idAttribute ? [idAttribute, 'OBJECTID', 'FID'] : ['OBJECTID', 'FID']; 8404 for (var i = 0; i < keys.length; i++) { 8405 var key = keys[i]; 8406 if (key in attributes && (typeof attributes[key] === 'string' || typeof attributes[key] === 'number')) { 8407 return attributes[key] 8408 } 8409 } 8410 throw Error('No valid id attribute found') 8411 } 8412 function arcgisToGeoJSON(arcgis, idAttribute) { 8413 var geojson = {}; 8414 if (arcgis.features) { 8415 geojson.type = 'FeatureCollection'; 8416 geojson.features = []; 8417 for (var i = 0; i < arcgis.features.length; i++) { 8418 geojson.features.push(arcgisToGeoJSON(arcgis.features[i], idAttribute)) 8419 } 8420 } 8421 if (typeof arcgis.x === 'number' && typeof arcgis.y === 'number') { 8422 geojson.type = 'Point'; 8423 geojson.coordinates = [arcgis.x, arcgis.y]; 8424 if (typeof arcgis.z === 'number') { 8425 geojson.coordinates.push(arcgis.z) 8426 } 8427 } 8428 if (arcgis.points) { 8429 geojson.type = 'MultiPoint'; 8430 geojson.coordinates = arcgis.points.slice(0) 8431 } 8432 if (arcgis.paths) { 8433 if (arcgis.paths.length === 1) { 8434 geojson.type = 'LineString'; 8435 geojson.coordinates = arcgis.paths[0].slice(0) 8436 } else { 8437 geojson.type = 'MultiLineString'; 8438 geojson.coordinates = arcgis.paths.slice(0) 8439 } 8440 } 8441 if (arcgis.rings) { 8442 geojson = convertRingsToGeoJSON(arcgis.rings.slice(0)) 8443 } 8444 if (typeof arcgis.xmin === 'number' && typeof arcgis.ymin === 'number' && typeof arcgis.xmax === 'number' && typeof arcgis.ymax === 'number') { 8445 geojson.type = 'Polygon'; 8446 geojson.coordinates = [[[arcgis.xmax, arcgis.ymax], [arcgis.xmin, arcgis.ymax], [arcgis.xmin, arcgis.ymin], [arcgis.xmax, arcgis.ymin], [arcgis.xmax, arcgis.ymax]]] 8447 } 8448 if (arcgis.geometry || arcgis.attributes) { 8449 geojson.type = 'Feature'; 8450 geojson.geometry = (arcgis.geometry) ? arcgisToGeoJSON(arcgis.geometry) : null; 8451 geojson.properties = (arcgis.attributes) ? shallowClone(arcgis.attributes) : null; 8452 if (arcgis.attributes) { 8453 try { 8454 geojson.id = getId(arcgis.attributes, idAttribute) 8455 } catch (err) { } 8456 } 8457 } 8458 if (JSON.stringify(geojson.geometry) === JSON.stringify({})) { 8459 geojson.geometry = null 8460 } 8461 if (arcgis.spatialReference && arcgis.spatialReference.wkid && arcgis.spatialReference.wkid !== 4326) { 8462 console.warn('Object converted in non-standard crs - ' + JSON.stringify(arcgis.spatialReference)) 8463 } 8464 return geojson 8465 } 8466 function geojsonToArcGIS(geojson, idAttribute) { 8467 idAttribute = idAttribute || 'OBJECTID'; 8468 var spatialReference = { 8469 wkid: 4326 8470 }; 8471 var result = {}; 8472 var i; 8473 switch (geojson.type) { 8474 case 'Point': 8475 result.x = geojson.coordinates[0]; 8476 result.y = geojson.coordinates[1]; 8477 result.spatialReference = spatialReference; 8478 break; 8479 case 'MultiPoint': 8480 result.points = geojson.coordinates.slice(0); 8481 result.spatialReference = spatialReference; 8482 break; 8483 case 'LineString': 8484 result.paths = [geojson.coordinates.slice(0)]; 8485 result.spatialReference = spatialReference; 8486 break; 8487 case 'MultiLineString': 8488 result.paths = geojson.coordinates.slice(0); 8489 result.spatialReference = spatialReference; 8490 break; 8491 case 'Polygon': 8492 result.rings = orientRings(geojson.coordinates.slice(0)); 8493 result.spatialReference = spatialReference; 8494 break; 8495 case 'MultiPolygon': 8496 result.rings = flattenMultiPolygonRings(geojson.coordinates.slice(0)); 8497 result.spatialReference = spatialReference; 8498 break; 8499 case 'Feature': 8500 if (geojson.geometry) { 8501 result.geometry = geojsonToArcGIS(geojson.geometry, idAttribute) 8502 } 8503 result.attributes = (geojson.properties) ? shallowClone(geojson.properties) : {}; 8504 if (geojson.id) { 8505 result.attributes[idAttribute] = geojson.id 8506 } 8507 break; 8508 case 'FeatureCollection': 8509 result = []; 8510 for (i = 0; i < geojson.features.length; i++) { 8511 result.push(geojsonToArcGIS(geojson.features[i], idAttribute)) 8512 } 8513 break; 8514 case 'GeometryCollection': 8515 result = []; 8516 for (i = 0; i < geojson.geometries.length; i++) { 8517 result.push(geojsonToArcGIS(geojson.geometries[i], idAttribute)) 8518 } 8519 break 8520 } 8521 return result 8522 } 8523 function geojsonToArcGIS$1(geojson, idAttr) { 8524 return geojsonToArcGIS(geojson, idAttr) 8525 } 8526 function arcgisToGeoJSON$1(arcgis, idAttr) { 8527 return arcgisToGeoJSON(arcgis, idAttr) 8528 } 8529 function extentToBounds(extent) { 8530 if (extent.xmin !== 'NaN' && extent.ymin !== 'NaN' && extent.xmax !== 'NaN' && extent.ymax !== 'NaN') { 8531 var sw = leaflet.latLng(extent.ymin, extent.xmin); 8532 var ne = leaflet.latLng(extent.ymax, extent.xmax); 8533 return leaflet.latLngBounds(sw, ne) 8534 } else { 8535 return null 8536 } 8537 } 8538 function boundsToExtent(bounds) { 8539 bounds = leaflet.latLngBounds(bounds); 8540 return {
8541 'xmin': bounds.getSouthWest().lng, 8542 'ymin': bounds.getSouthWest().lat, 8543 'xmax': bounds.getNorthEast().lng, 8544 'ymax': bounds.getNorthEast().lat, 8545 'spatialReference': { 8546 'wkid': 4326 8547 } 8548 } 8549 } 8550 var knownFieldNames = /^(OBJECTID|FID|OID|ID)$/i; 8551 function _findIdAttributeFromResponse(response) { 8552 var result; 8553 if (response.objectIdFieldName) { 8554 result = response.objectIdFieldName 8555 } else if (response.fields) { 8556 for (var j = 0; j <= response.fields.length - 1; j++) { 8557 if (response.fields[j].type === 'esriFieldTypeOID') { 8558 result = response.fields[j].name; 8559 break 8560 } 8561 } 8562 if (!result) { 8563 for (j = 0; j <= response.fields.length - 1; j++) { 8564 if (response.fields[j].name.match(knownFieldNames)) { 8565 result = response.fields[j].name; 8566 break 8567 } 8568 } 8569 } 8570 } 8571 return result 8572 } 8573 function _findIdAttributeFromFeature(feature) { 8574 for (var key in feature.attributes) { 8575 if (key.match(knownFieldNames)) { 8576 return key 8577 } 8578 } 8579 } 8580 function responseToFeatureCollection(response, idAttribute) { 8581 var objectIdField; 8582 var features = response.features || response.results; 8583 var count = features.length; 8584 if (idAttribute) { 8585 objectIdField = idAttribute 8586 } else { 8587 objectIdField = _findIdAttributeFromResponse(response) 8588 } 8589 var featureCollection = { 8590 type: 'FeatureCollection', 8591 features: [] 8592 }; 8593 if (count) { 8594 for (var i = features.length - 1; i >= 0; i--) { 8595 var feature = arcgisToGeoJSON$1(features[i], objectIdField || _findIdAttributeFromFeature(features[i])); 8596 featureCollection.features.push(feature) 8597 } 8598 } 8599 return featureCollection 8600 } 8601 function cleanUrl(url) { 8602 url = leaflet.Util.trim(url); 8603 if (url[url.length - 1] !== '/') { 8604 url += '/' 8605 } 8606 return url 8607 } 8608 function getUrlParams(options$$1) { 8609 if (options$$1.url.indexOf('?') !== -1) { 8610 options$$1.requestParams = options$$1.requestParams || {}; 8611 var queryString = options$$1.url.substring(options$$1.url.indexOf('?') + 1); 8612 options$$1.url = options$$1.url.split('?')[0]; 8613 options$$1.requestParams = JSON.parse('{"' + decodeURI(queryString).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}') 8614 } 8615 options$$1.url = cleanUrl(options$$1.url.split('?')[0]); 8616 return options$$1 8617 } 8618 function isArcgisOnline(url) { 8619 return (/^(?!.*utility\.arcgis\.com).*\.arcgis\.com.*FeatureServer/i).test(url) 8620 } 8621 function geojsonTypeToArcGIS(geoJsonType) { 8622 var arcgisGeometryType; 8623 switch (geoJsonType) { 8624 case 'Point': 8625 arcgisGeometryType = 'esriGeometryPoint'; 8626 break; 8627 case 'MultiPoint': 8628 arcgisGeometryType = 'esriGeometryMultipoint'; 8629 break; 8630 case 'LineString': 8631 arcgisGeometryType = 'esriGeometryPolyline'; 8632 break; 8633 case 'MultiLineString': 8634 arcgisGeometryType = 'esriGeometryPolyline'; 8635 break; 8636 case 'Polygon': 8637 arcgisGeometryType = 'esriGeometryPolygon'; 8638 break; 8639 case 'MultiPolygon': 8640 arcgisGeometryType = 'esriGeometryPolygon'; 8641 break 8642 } 8643 return arcgisGeometryType 8644 } 8645 function warn() { 8646 if (console && console.warn) { 8647 console.warn.apply(console, arguments) 8648 } 8649 } 8650 function calcAttributionWidth(map) { 8651 return (map.getSize().x - options.attributionWidthOffset) + 'px' 8652 } 8653 function setEsriAttribution(map) { 8654 if (map.attributionControl && !map.attributionControl._esriAttributionAdded) { 8655 map.attributionControl.setPrefix('<a href="http://tehran.ir" title="A JS library for interactive maps">tehran.ir</a>'); 8656 var hoverAttributionStyle = document.createElement('style'); 8657 hoverAttributionStyle.type = 'text/css'; 8658 hoverAttributionStyle.innerHTML = '.esri-truncated-attribution:hover {' + 'white-space: normal;' + '}'; 8659 document.getElementsByTagName('head')[0].appendChild(hoverAttributionStyle); 8660 leaflet.DomUtil.addClass(map.attributionControl._container, 'esri-truncated-attribution:hover'); 8661 var attributionStyle = document.createElement('style'); 8662 attributionStyle.type = 'text/css'; 8663 attributionStyle.innerHTML = '.esri-truncated-attribution {' + 'vertical-align: -3px;' + 'white-space: nowrap;' + 'overflow: hidden;' + 'text-overflow: ellipsis;' + 'display: inline-block;' + 'transition: 0s white-space;' + 'transition-delay: 1s;' + 'max-width: ' + calcAttributionWidth(map) + ';' + '}'; 8664 document.getElementsByTagName('head')[0].appendChild(attributionStyle); 8665 leaflet.DomUtil.addClass(map.attributionControl._container, 'esri-truncated-attribution'); 8666 map.on('resize', function (e) { 8667 map.attributionControl._container.style.maxWidth = calcAttributionWidth(e.target) 8668 }); 8669 map.on('unload', function () { 8670 hoverAttributionStyle.parentNode.removeChild(hoverAttributionStyle); 8671 attributionStyle.parentNode.removeChild(attributionStyle); 8672 var nodeList = document.querySelectorAll('.esri-leaflet-jsonp'); 8673 for (var i = 0; i < nodeList.length; i++) { 8674 nodeList.item(i).parentNode.removeChild(nodeList.item(i)) 8675 } 8676 }); 8677 map.attributionControl._esriAttributionAdded = !0 8678 } 8679 } 8680 function _setGeometry(geometry) { 8681 var params = { 8682 geometry: null, 8683 geometryType: null 8684 }; 8685 if (geometry instanceof leaflet.LatLngBounds) { 8686 params.geometry = boundsToExtent(geometry); 8687 params.geometryType = 'esriGeometryEnvelope'; 8688 return params 8689 } 8690 if (geometry.getLatLng) { 8691 geometry = geometry.getLatLng() 8692 } 8693 if (geometry instanceof leaflet.LatLng) { 8694 geometry = { 8695 type: 'Point', 8696 coordinates: [geometry.lng, geometry.lat] 8697 } 8698 } 8699 if (geometry instanceof leaflet.GeoJSON) { 8700 geometry = geometry.getLayers()[0].feature.geometry; 8701 params.geometry = geojsonToArcGIS$1(geometry); 8702 params.geometryType = geojsonTypeToArcGIS(geometry.type) 8703 } 8704 if (geometry.toGeoJSON) { 8705 geometry = geometry.toGeoJSON() 8706 } 8707 if (geometry.type === 'Feature') { 8708 geometry = geometry.geometry 8709 } 8710 if (geometry.type === 'Point' || geometry.type === 'LineString' || geometry.type === 'Polygon' || geometry.type === 'MultiPolygon') { 8711 params.geometry = geojsonToArcGIS$1(geometry); 8712 params.geometryType = geojsonTypeToArcGIS(geometry.type); 8713 return params 8714 } 8715 warn('invalid geometry passed to spatial query. Should be L.LatLng, L.LatLngBounds, L.Marker or a GeoJSON Point, Line, Polygon or MultiPolygon object'); 8716 return 8717 } 8718 function _getAttributionData(url, map) { 8719 jsonp(url, {}, leaflet.Util.bind(function (error, attributions) { 8720 if (error) { 8721 return 8722 } 8723 map._esriAttributions = []; 8724 for (var c = 0; c < attributions.contributors.length; c++) { 8725 var contributor = attributions.contributors[c]; 8726 for (var i = 0; i < contributor.coverageAreas.length; i++) { 8727 var coverageArea = contributor.coverageAreas[i]; 8728 var southWest = leaflet.latLng(coverageArea.bbox[0], coverageArea.bbox[1]); 8729 var northEast = leaflet.latLng(coverageArea.bbox[2], coverageArea.bbox[3]); 8730 map._esriAttributions.push({ 8731 attribution: contributor.attribution, 8732 score: coverageArea.score, 8733 bounds: leaflet.latLngBounds(southWest, northEast), 8734 minZoom: coverageArea.zoomMin, 8735 maxZoom: coverageArea.zoomMax 8736 }) 8737 } 8738 } 8739 map._esriAttributions.sort(function (a, b) { 8740 return b.score - a.score 8741 }); 8742 var obj = { 8743 target: map 8744 }; 8745 _updateMapAttribution(obj) 8746 }, this)) 8747 } 8748 function _updateMapAttribution(evt) { 8749 var map = evt.target; 8750 var oldAttributions = map._esriAttributions; 8751 var attributionElement = map.attributionControl._container.querySelector('.esri-dynamic-attribution'); 8752 if (map && map.attributionControl && attributionElement && oldAttributions) { 8753 var newAttributions = ''; 8754 var bounds = map.getBounds(); 8755 var wrappedBounds = leaflet.latLngBounds(bounds.getSouthWest
8755().wrap(), bounds.getNorthEast().wrap()); 8756 var zoom = map.getZoom(); 8757 for (var i = 0; i < oldAttributions.length; i++) { 8758 var attribution = oldAttributions[i]; 8759 var text = attribution.attribution; 8760 if (!newAttributions.match(text) && attribution.bounds.intersects(wrappedBounds) && zoom >= attribution.minZoom && zoom <= attribution.maxZoom) { 8761 newAttributions += (', ' + text) 8762 } 8763 } 8764 newAttributions = newAttributions.substr(2); 8765 attributionElement.innerHTML = newAttributions; 8766 attributionElement.style.maxWidth = calcAttributionWidth(map); 8767 map.fire('attributionupdated', { 8768 attribution: newAttributions 8769 }) 8770 } 8771 } 8772 var EsriUtil = { 8773 warn: warn, 8774 cleanUrl: cleanUrl, 8775 getUrlParams: getUrlParams, 8776 isArcgisOnline: isArcgisOnline, 8777 geojsonTypeToArcGIS: geojsonTypeToArcGIS, 8778 responseToFeatureCollection: responseToFeatureCollection, 8779 geojsonToArcGIS: geojsonToArcGIS$1, 8780 arcgisToGeoJSON: arcgisToGeoJSON$1, 8781 boundsToExtent: boundsToExtent, 8782 extentToBounds: extentToBounds, 8783 calcAttributionWidth: calcAttributionWidth, 8784 setEsriAttribution: setEsriAttribution, 8785 _setGeometry: _setGeometry, 8786 _getAttributionData: _getAttributionData, 8787 _updateMapAttribution: _updateMapAttribution, 8788 _findIdAttributeFromFeature: _findIdAttributeFromFeature, 8789 _findIdAttributeFromResponse: _findIdAttributeFromResponse 8790 }; 8791 var Task = leaflet.Class.extend({ 8792 options: { 8793 proxy: !1, 8794 useCors: cors 8795 }, 8796 generateSetter: function (param, context) { 8797 return leaflet.Util.bind(function (value) { 8798 this.params[param] = value; 8799 return this 8800 }, context) 8801 }, 8802 initialize: function (endpoint) { 8803 if (endpoint.request && endpoint.options) { 8804 this._service = endpoint; 8805 leaflet.Util.setOptions(this, endpoint.options) 8806 } else { 8807 leaflet.Util.setOptions(this, endpoint); 8808 this.options.url = cleanUrl(endpoint.url) 8809 } 8810 this.params = leaflet.Util.extend({}, this.params || {}); 8811 if (this.setters) { 8812 for (var setter in this.setters) { 8813 var param = this.setters[setter]; 8814 this[setter] = this.generateSetter(param, this) 8815 } 8816 } 8817 }, 8818 token: function (token) { 8819 if (this._service) { 8820 this._service.authenticate(token) 8821 } else { 8822 this.params.token = token 8823 } 8824 return this 8825 }, 8826 format: function (boolean) { 8827 this.params.returnUnformattedValues = !boolean; 8828 return this 8829 }, 8830 request: function (callback, context) { 8831 if (this.options.requestParams) { 8832 leaflet.Util.extend(this.params, this.options.requestParams) 8833 } 8834 if (this._service) { 8835 return this._service.request(this.path, this.params, callback, context) 8836 } 8837 return this._request('request', this.path, this.params, callback, context) 8838 }, 8839 _request: function (method, path, params, callback, context) { 8840 var url = (this.options.proxy) ? this.options.proxy + '?' + this.options.url + path : this.options.url + path; 8841 if ((method === 'get' || method === 'request') && !this.options.useCors) { 8842 return Request.get.JSONP(url, params, callback, context) 8843 } 8844 return Request[method](url, params, callback, context) 8845 } 8846 }); 8847 function task(options) { 8848 options = getUrlParams(options); 8849 return new Task(options) 8850 } 8851 var Query = Task.extend({ 8852 setters: { 8853 'offset': 'resultOffset', 8854 'limit': 'resultRecordCount', 8855 'fields': 'outFields', 8856 'precision': 'geometryPrecision', 8857 'featureIds': 'objectIds', 8858 'returnGeometry': 'returnGeometry', 8859 'returnM': 'returnM', 8860 'transform': 'datumTransformation', 8861 'token': 'token' 8862 }, 8863 path: 'query', 8864 params: { 8865 returnGeometry: !0, 8866 where: '1=1', 8867 outSr: 4326, 8868 outFields: '*' 8869 }, 8870 within: function (geometry) { 8871 this._setGeometryParams(geometry); 8872 this.params.spatialRel = 'esriSpatialRelContains'; 8873 return this 8874 }, 8875 intersects: function (geometry) { 8876 this._setGeometryParams(geometry); 8877 this.params.spatialRel = 'esriSpatialRelIntersects'; 8878 return this 8879 }, 8880 contains: function (geometry) { 8881 this._setGeometryParams(geometry); 8882 this.params.spatialRel = 'esriSpatialRelWithin'; 8883 return this 8884 }, 8885 crosses: function (geometry) { 8886 this._setGeometryParams(geometry); 8887 this.params.spatialRel = 'esriSpatialRelCrosses'; 8888 return this 8889 }, 8890 touches: function (geometry) { 8891 this._setGeometryParams(geometry); 8892 this.params.spatialRel = 'esriSpatialRelTouches'; 8893 return this 8894 }, 8895 overlaps: function (geometry) { 8896 this._setGeometryParams(geometry); 8897 this.params.spatialRel = 'esriSpatialRelOverlaps'; 8898 return this 8899 }, 8900 bboxIntersects: function (geometry) { 8901 this._setGeometryParams(geometry); 8902 this.params.spatialRel = 'esriSpatialRelEnvelopeIntersects'; 8903 return this 8904 }, 8905 indexIntersects: function (geometry) { 8906 this._setGeometryParams(geometry); 8907 this.params.spatialRel = 'esriSpatialRelIndexIntersects'; 8908 return this 8909 }, 8910 nearby: function (latlng, radius) { 8911 latlng = leaflet.latLng(latlng); 8912 this.params.geometry = [latlng.lng, latlng.lat]; 8913 this.params.geometryType = 'esriGeometryPoint'; 8914 this.params.spatialRel = 'esriSpatialRelIntersects'; 8915 this.params.units = 'esriSRUnit_Meter'; 8916 this.params.distance = radius; 8917 this.params.inSr = 4326; 8918 return this 8919 }, 8920 where: function (string) { 8921 this.params.where = string; 8922 return this 8923 }, 8924 between: function (start, end) { 8925 this.params.time = [start.valueOf(), end.valueOf()]; 8926 return this 8927 }, 8928 simplify: function (map, factor) { 8929 var mapWidth = Math.abs(map.getBounds().getWest() - map.getBounds().getEast()); 8930 this.params.maxAllowableOffset = (mapWidth / map.getSize().y) * factor; 8931 return this 8932 }, 8933 orderBy: function (fieldName, order) { 8934 order = order || 'ASC'; 8935 this.params.orderByFields = (this.params.orderByFields) ? this.params.orderByFields + ',' : ''; 8936 this.params.orderByFields += ([fieldName, order]).join(' '); 8937 return this 8938 }, 8939 run: function (callback, context) { 8940 this._cleanParams(); 8941 if (this.options.isModern || isArcgisOnline(this.options.url)) { 8942 this.params.f = 'geojson'; 8943 return this.request(function (error, response) { 8944 this._trapSQLerrors(error); 8945 callback.call(context, error, response, response) 8946 }, this) 8947 } else { 8948 return this.request(function (error, response) { 8949 this._trapSQLerrors(error); 8950 callback.call(context, error, (response && responseToFeatureCollection(response)), response) 8951 }, this) 8952 } 8953 }, 8954 count: function (callback, context) { 8955 this._cleanParams(); 8956 this.params.returnCountOnly = !0; 8957 return this.request(function (error, response) { 8958 callback.call(this, error, (response && response.count), response) 8959 }, context) 8960 }, 8961 ids: function (callback, context) { 8962 this._cleanParams(); 8963 this.params.returnIdsOnly = !0; 8964 return this.request(function (error, response) { 8965 callback.call(this, error, (response && response.objectIds), response) 8966 }, context) 8967 }, 8968 bounds: function (callback, context) { 8969 this._cleanParams(); 8970 this.params.returnExtentOnly = !0; 8971 return this.request(function (error, response) { 8972 if (response && response.extent && extentToBounds(response.extent)) { 8973 callback.call(context, error, extentToBounds(response.extent), response) 8974 } else { 8975 error = { 8976 message: 'Invalid Bounds' 8977 }; 8978 callback.call(context, error, null, response) 8979 } 8980 }, context) 8981 }, 8982 distinct: function () { 8983 this.params.returnGeometry = !1; 8984 this.params.returnDistinctValues = !0; 8985 return this 8986 }, 8987 pixelSize: function (rawPoint) { 8988 var castPoint = leaflet.point(rawPoint); 8989 this.params.pixelSize = [castPoint.x, castPoint.y]; 8990 return this 8991 }, 8992 layer: function (layer) { 8993 this.path = layer + '/query'; 8994 return this 8995 }, 8996 _trapSQLerrors: function (error) { 8997 if (error) { 8998 if (error.code === '400') { 8999 warn('one common syntax error in query requests is encasing str
8999ing values in double quotes instead of single quotes') 9000 } 9001 } 9002 }, 9003 _cleanParams: function () { 9004 delete this.params.returnIdsOnly; 9005 delete this.params.returnExtentOnly; 9006 delete this.params.returnCountOnly 9007 }, 9008 _setGeometryParams: function (geometry) { 9009 this.params.inSr = 4326; 9010 var converted = _setGeometry(geometry); 9011 this.params.geometry = converted.geometry; 9012 this.params.geometryType = converted.geometryType 9013 } 9014 }); 9015 function query(options) { 9016 return new Query(options) 9017 } 9018 var Find = Task.extend({ 9019 setters: { 9020 'contains': 'contains', 9021 'text': 'searchText', 9022 'fields': 'searchFields', 9023 'spatialReference': 'sr', 9024 'sr': 'sr', 9025 'layers': 'layers', 9026 'returnGeometry': 'returnGeometry', 9027 'maxAllowableOffset': 'maxAllowableOffset', 9028 'precision': 'geometryPrecision', 9029 'dynamicLayers': 'dynamicLayers', 9030 'returnZ': 'returnZ', 9031 'returnM': 'returnM', 9032 'gdbVersion': 'gdbVersion', 9033 'token': 'token' 9034 }, 9035 path: 'find', 9036 params: { 9037 sr: 4326, 9038 contains: !0, 9039 returnGeometry: !0, 9040 returnZ: !0, 9041 returnM: !1 9042 }, 9043 layerDefs: function (id, where) { 9044 this.params.layerDefs = (this.params.layerDefs) ? this.params.layerDefs + ';' : ''; 9045 this.params.layerDefs += ([id, where]).join(':'); 9046 return this 9047 }, 9048 simplify: function (map, factor) { 9049 var mapWidth = Math.abs(map.getBounds().getWest() - map.getBounds().getEast()); 9050 this.params.maxAllowableOffset = (mapWidth / map.getSize().y) * factor; 9051 return this 9052 }, 9053 run: function (callback, context) { 9054 return this.request(function (error, response) { 9055 callback.call(context, error, (response && responseToFeatureCollection(response)), response) 9056 }, context) 9057 } 9058 }); 9059 function find(options) { 9060 return new Find(options) 9061 } 9062 var Identify = Task.extend({ 9063 path: 'identify', 9064 between: function (start, end) { 9065 this.params.time = [start.valueOf(), end.valueOf()]; 9066 return this 9067 } 9068 }); 9069 function identify(options) { 9070 return new Identify(options) 9071 } 9072 var IdentifyFeatures = Identify.extend({ 9073 setters: { 9074 'layers': 'layers', 9075 'precision': 'geometryPrecision', 9076 'tolerance': 'tolerance', 9077 'returnGeometry': 'returnGeometry' 9078 }, 9079 params: { 9080 sr: 4326, 9081 layers: 'all', 9082 tolerance: 3, 9083 returnGeometry: !0 9084 }, 9085 on: function (map) { 9086 var extent = boundsToExtent(map.getBounds()); 9087 var size = map.getSize(); 9088 this.params.imageDisplay = [size.x, size.y, 96]; 9089 this.params.mapExtent = [extent.xmin, extent.ymin, extent.xmax, extent.ymax]; 9090 return this 9091 }, 9092 at: function (geometry) { 9093 if (geometry.length === 2) { 9094 geometry = leaflet.latLng(geometry) 9095 } 9096 this._setGeometryParams(geometry); 9097 return this 9098 }, 9099 layerDef: function (id, where) { 9100 this.params.layerDefs = (this.params.layerDefs) ? this.params.layerDefs + ';' : ''; 9101 this.params.layerDefs += ([id, where]).join(':'); 9102 return this 9103 }, 9104 simplify: function (map, factor) { 9105 var mapWidth = Math.abs(map.getBounds().getWest() - map.getBounds().getEast()); 9106 this.params.maxAllowableOffset = (mapWidth / map.getSize().y) * factor; 9107 return this 9108 }, 9109 run: function (callback, context) { 9110 return this.request(function (error, response) { 9111 if (error) { 9112 callback.call(context, error, undefined, response); 9113 return 9114 } else { 9115 var featureCollection = responseToFeatureCollection(response); 9116 response.results = response.results.reverse(); 9117 for (var i = 0; i < featureCollection.features.length; i++) { 9118 var feature = featureCollection.features[i]; 9119 feature.layerId = response.results[i].layerId 9120 } 9121 callback.call(context, undefined, featureCollection, response) 9122 } 9123 }) 9124 }, 9125 _setGeometryParams: function (geometry) { 9126 var converted = _setGeometry(geometry); 9127 this.params.geometry = converted.geometry; 9128 this.params.geometryType = converted.geometryType 9129 } 9130 }); 9131 function identifyFeatures(options) { 9132 return new IdentifyFeatures(options) 9133 } 9134 var IdentifyImage = Identify.extend({ 9135 setters: { 9136 'setMosaicRule': 'mosaicRule', 9137 'setRenderingRule': 'renderingRule', 9138 'setPixelSize': 'pixelSize',
9139 'returnCatalogItems': 'returnCatalogItems', 9140 'returnGeometry': 'returnGeometry' 9141 }, 9142 params: { 9143 returnGeometry: !1 9144 }, 9145 at: function (latlng) { 9146 latlng = leaflet.latLng(latlng); 9147 this.params.geometry = JSON.stringify({ 9148 x: latlng.lng, 9149 y: latlng.lat, 9150 spatialReference: { 9151 wkid: 4326 9152 } 9153 }); 9154 this.params.geometryType = 'esriGeometryPoint'; 9155 return this 9156 }, 9157 getMosaicRule: function () { 9158 return this.params.mosaicRule 9159 }, 9160 getRenderingRule: function () { 9161 return this.params.renderingRule 9162 }, 9163 getPixelSize: function () { 9164 return this.params.pixelSize 9165 }, 9166 run: function (callback, context) { 9167 return this.request(function (error, response) { 9168 callback.call(context, error, (response && this._responseToGeoJSON(response)), response) 9169 }, this) 9170 }, 9171 _responseToGeoJSON: function (response) { 9172 var location = response.location; 9173 var catalogItems = response.catalogItems; 9174 var catalogItemVisibilities = response.catalogItemVisibilities; 9175 var geoJSON = { 9176 'pixel': { 9177 'type': 'Feature', 9178 'geometry': { 9179 'type': 'Point', 9180 'coordinates': [location.x, location.y] 9181 }, 9182 'crs': { 9183 'type': 'EPSG', 9184 'properties': { 9185 'code': location.spatialReference.wkid 9186 } 9187 }, 9188 'properties': { 9189 'OBJECTID': response.objectId, 9190 'name': response.name, 9191 'value': response.value 9192 }, 9193 'id': response.objectId 9194 } 9195 }; 9196 if (response.properties && response.properties.Values) { 9197 geoJSON.pixel.properties.values = response.properties.Values 9198 } 9199 if (catalogItems && catalogItems.features) { 9200 geoJSON.catalogItems = responseToFeatureCollection(catalogItems); 9201 if (catalogItemVisibilities && catalogItemVisibilities.length === geoJSON.catalogItems.features.length) { 9202 for (var i = catalogItemVisibilities.length - 1; i >= 0; i--) { 9203 geoJSON.catalogItems.features[i].properties.catalogItemVisibility = catalogItemVisibilities[i] 9204 } 9205 } 9206 } 9207 return geoJSON 9208 } 9209 }); 9210 function identifyImage(params) { 9211 return new IdentifyImage(params) 9212 } 9213 var Service = leaflet.Evented.extend({ 9214 options: { 9215 proxy: !1, 9216 useCors: cors, 9217 timeout: 0 9218 }, 9219 initialize: function (options) { 9220 options = options || {}; 9221 this._requestQueue = []; 9222 this._authenticating = !1; 9223 leaflet.Util.setOptions(this, options); 9224 this.options.url = cleanUrl(this.options.url) 9225 }, 9226 get: function (path, params, callback, context) { 9227 return this._request('get', path, params, callback, context) 9228 }, 9229 post: function (path, params, callback, context) { 9230 return this._request('post', path, params, callback, context) 9231 }, 9232 request: function (path, params, callback, context) { 9233 return this._request('request', path, params, callback, context) 9234 }, 9235 metadata: function (callback, context) { 9236 return this._request('get', '', {}, callback, context) 9237 }, 9238 authenticate: function (token) { 9239 this._authenticating = !1; 9240 this.options.token = token; 9241 this._runQueue(); 9242 return this 9243 }, 9244 getTimeout: function () { 9245 return this.options.timeout 9246 }, 9247 setTimeout: function (timeout) { 9248 this.options.timeout = timeout 9249 }, 9250 _request: function (method, path, params, callback, context) { 9251 this.fire('requeststart', { 9252 url: this.options.url + path, 9253 params: params, 9254 method: method 9255 }, !0); 9256 var wrappedCallback = this._createServiceCallback(method, path, params, callback, context); 9257 if (this.options.token) { 9258 params.token = this.options.token 9259 } 9260 if (this.options.requestParams) {
9261 leaflet.Util.extend(params, this.options.requestParams) 9262 } 9263 if (this._authenticating) { 9264 this._requestQueue.push([method, path, params, callback, context]); 9265 return 9266 } else { 9267 var url = (this.options.proxy) ? this.options.proxy + '?' + this.options.url + path : this.options.url + path; 9268 if ((method === 'get' || method === 'request') && !this.options.useCors) { 9269 return Request.get.JSONP(url, params, wrappedCallback, context) 9270 } else { 9271 return Request[method](url, params, wrappedCallback, context) 9272 } 9273 } 9274 }, 9275 _createServiceCallback: function (method, path, params, callback, context) { 9276 return leaflet.Util.bind(function (error, response) { 9277 if (error && (error.code === 499 || error.code === 498)) { 9278 this._authenticating = !0; 9279 this._requestQueue.push([method, path, params, callback, context]); 9280 this.fire('authenticationrequired', { 9281 authenticate: leaflet.Util.bind(this.authenticate, this) 9282 }, !0); 9283 error.authenticate = leaflet.Util.bind(this.authenticate, this) 9284 } 9285 callback.call(context, error, response); 9286 if (error) { 9287 this.fire('requesterror', { 9288 url: this.options.url + path, 9289 params: params, 9290 message: error.message, 9291 code: error.code, 9292 method: method 9293 }, !0) 9294 } else { 9295 this.fire('requestsuccess', { 9296 url: this.options.url + path, 9297 params: params, 9298 response: response, 9299 method: method 9300 }, !0) 9301 } 9302 this.fire('requestend', { 9303 url: this.options.url + path, 9304 params: params, 9305 method: method 9306 }, !0) 9307 }, this) 9308 }, 9309 _runQueue: function () { 9310 for (var i = this._requestQueue.length - 1; i >= 0; i--) { 9311 var request$$1 = this._requestQueue[i]; 9312 var method = request$$1.shift(); 9313 this[method].apply(this, request$$1) 9314 } 9315 this._requestQueue = [] 9316 } 9317 }); 9318 function service(options) { 9319 options = getUrlParams(options); 9320 return new Service(options) 9321 } 9322 var MapService = Service.extend({ 9323 identify: function () { 9324 return identifyFeatures(this) 9325 }, 9326 find: function () { 9327 return find(this) 9328 }, 9329 query: function () { 9330 return query(this) 9331 } 9332 }); 9333 function mapService(options) { 9334 return new MapService(options) 9335 } 9336 var ImageService = Service.extend({ 9337 query: function () { 9338 return query(this) 9339 }, 9340 identify: function () { 9341 return identifyImage(this) 9342 } 9343 }); 9344 function imageService(options) { 9345 return new ImageService(options) 9346 } 9347 var FeatureLayerService = Service.extend({ 9348 options: { 9349 idAttribute: 'OBJECTID' 9350 }, 9351 query: function () { 9352 return query(this) 9353 }, 9354 addFeature: function (feature, callback, context) { 9355 this.addFeatures(feature, callback, context) 9356 }, 9357 addFeatures: function (features, callback, context) { 9358 var featuresArray = features.features ? features.features : [features]; 9359 for (var i = featuresArray.length - 1; i >= 0; i--) { 9360 delete featuresArray[i].id 9361 } 9362 features = geojsonToArcGIS$1(features); 9363 features = featuresArray.length > 1 ? features : [features]; 9364 return this.post('addFeatures', { 9365 features: features 9366 }, function (error, response) { 9367 var result = (response && response.addResults) ? response.addResults.length > 1 ? response.addResults : response.addResults[0] : undefined; 9368 if (callback) { 9369 callback.call(context, error || response.addResults[0].error, result) 9370 } 9371 }, context) 9372 }, 9373 updateFeature: function (feature, callback, context) { 9374 this.updateFeatures(feature, callback, context) 9375 }, 9376 updateFeatures: function (features, callback, context) { 9377 var featuresArray = features.features ? features.features : [features]; 9378 features = geojsonToArcGIS$1(features, this.options.idAttribute); 9379 features = featuresArray.length > 1 ? features : [features]; 9380 return this.post('updateFeatures', { 9381 features: features 9382 }, function (error, response) { 9383 var result = (response && response.updateResults) ? response.updateResults.length > 1 ? response.updateResults : response.updateResults[0] : undefined; 9384 if (callback) { 9385 callback.call(context, error || response.updateResults[0].error, result) 9386 } 9387 }, context) 9388 }, 9389 deleteFeature: function (id, callback, context) { 9390 this.deleteFeatures(id, callback, context) 9391 }, 9392 deleteFeatures: function (ids, callback, context) { 9393 return this.post('deleteFeatures', { 9394 objectIds: ids 9395 }, function (error, response) { 9396 var result = (response && response.deleteResults) ? response.deleteResults.length > 1 ? response.deleteResults : response.deleteResults[0] : undefined; 9397 if (callback) { 9398 callback.call(context, error || response.deleteResults[0].error, result) 9399 } 9400 }, context) 9401 } 9402 }); 9403 function featureLayerService(options) { 9404 return new FeatureLayerService(options) 9405 } 9406 var tileProtocol = (window.location.protocol !== 'https:') ? 'http:' : 'https:'; 9407 var BasemapLayer = leaflet.TileLayer.extend({ 9408 statics: { 9409 TILES: { 9410 Streets: { 9411 urlTemplate: tileProtocol + '//leaflet.tehran.ir:6080/arcgis/rest/services/Tehran_basemap_new/MapServer/tile/{z}/{y}/{x}', 9412 },
9413 Topographic: { 9414 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}', 9415 options: { 9416 minZoom: 1, 9417 maxZoom: 19, 9418 subdomains: ['server', 'services'], 9419 attribution: 'USGS, NOAA', 9420 attributionUrl: 'https://static.arcgis.com/attribution/World_Topo_Map' 9421 } 9422 }, 9423 Oceans: { 9424 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Base/MapServer/tile/{z}/{y}/{x}', 9425 options: { 9426 minZoom: 1, 9427 maxZoom: 16, 9428 subdomains: ['server', 'services'], 9429 attribution: 'USGS, NOAA', 9430 attributionUrl: 'https://static.arcgis.com/attribution/Ocean_Basemap' 9431 } 9432 }, 9433 OceansLabels: { 9434 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Reference/MapServer/tile/{z}/{y}/{x}', 9435 options: { 9436 minZoom: 1, 9437 maxZoom: 16, 9438 subdomains: ['server', 'services'], 9439 pane: (pointerEvents) ? 'esri-labels' : 'tilePane', 9440 attribution: '' 9441 } 9442 }, 9443 NationalGeographic: { 9444 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{z}/{y}/{x}', 9445 options: { 9446 minZoom: 1, 9447 maxZoom: 16, 9448 subdomains: ['server', 'services'], 9449 attribution: 'National Geographic, DeLorme, HERE, UNEP-WCMC, USGS, NASA, ESA, METI, NRCAN, GEBCO, NOAA, increment P Corp.' 9450 } 9451 }, 9452 DarkGray: { 9453 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Dark_Gray_Base/MapServer/tile/{z}/{y}/{x}', 9454 options: { 9455 minZoom: 1, 9456 maxZoom: 16, 9457 subdomains: ['server', 'services'], 9458 attribution: 'HERE, DeLorme, MapmyIndia, © OpenStreetMap contributors' 9459 } 9460 }, 9461 DarkGrayLabels: { 9462 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Dark_Gray_Reference/MapServer/tile/{z}/{y}/{x}', 9463 options: { 9464 minZoom: 1, 9465 maxZoom: 16, 9466 subdomains: ['server', 'services'], 9467 pane: (pointerEvents) ? 'esri-labels' : 'tilePane', 9468 attribution: '' 9469 } 9470 }, 9471 Gray: { 9472 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}', 9473 options: { 9474 minZoom: 1, 9475 maxZoom: 16, 9476 subdomains: ['server', 'services'], 9477 attribution: 'HERE, DeLorme, MapmyIndia, © OpenStreetMap contributors' 9478 } 9479 }, 9480 GrayLabels: { 9481 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Reference/MapServer/tile/{z}/{y}/{x}', 9482 options: { 9483 minZoom: 1, 9484 maxZoom: 16, 9485 subdomains: ['server', 'services'], 9486 pane: (pointerEvents) ? 'esri-labels' : 'tilePane', 9487 attribution: '' 9488 } 9489 }, 9490 Imagery: { 9491 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', 9492 options: { 9493 minZoom: 1, 9494 maxZoom: 19, 9495 subdomains: ['server', 'services'], 9496 attribution: 'DigitalGlobe, GeoEye, i-cubed, USDA, USGS, AEX, Getmapping, Aerogrid, IGN, IGP, swisstopo, and the GIS User Community', 9497 attributionUrl: 'https://static.arcgis.com/attribution/World_Imagery' 9498 } 9499 }, 9500 ImageryLabels: { 9501 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{z}/{y}/{x}', 9502 options: { 9503 minZoom: 1, 9504 maxZoom: 19, 9505 subdomains: ['server', 'services'], 9506 pane: (pointerEvents) ? 'esri-labels' : 'tilePane', 9507 attribution: '' 9508 } 9509 }, 9510 ImageryTransportation: { 9511 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Transportation/MapServer/tile/{z}/{y}/{x}', 9512 options: { 9513 minZoom: 1, 9514 maxZoom: 19, 9515 subdomains: ['server', 'services'], 9516 pane: (pointerEvents) ? 'esri-labels' : 'tilePane', 9517 attribution: '' 9518 } 9519 }, 9520 ShadedRelief: { 9521 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer/tile/{z}/{y}/{x}', 9522 options: { 9523 minZoom: 1, 9524 maxZoom: 13, 9525 subdomains: ['server', 'services'], 9526 attribution: 'USGS' 9527 } 9528 }, 9529 ShadedReliefLabels: { 9530 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places_Alternate/MapServer/tile/{z}/{y}/{x}', 9531 options: { 9532 minZoom: 1, 9533 maxZoom: 12, 9534 subdomains: ['server', 'services'], 9535 pane: (pointerEvents) ? 'esri-labels' : 'tilePane', 9536 attribution: '' 9537 } 9538 }, 9539 Terrain: { 9540 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer/tile/{z}/{y}/{x}', 9541 options: { 9542 minZoom: 1, 9543 maxZoom: 13, 9544 subdomains: ['server', 'services'], 9545 attribution: 'USGS, NOAA' 9546 } 9547 }, 9548 TerrainLabels: { 9549 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Reference_Overlay/MapServer/tile/{z}/{y}/{x}', 9550 options: { 9551 minZoom: 1, 9552 maxZoom: 13, 9553 subdomains: ['server', 'services'], 9554 pane: (pointerEvents) ? 'esri-labels' : 'tilePane', 9555 attribution: '' 9556 } 9557 }, 9558 USATopo: { 9559 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer/tile/{z}/{y}/{x}', 9560 options: { 9561 minZoom: 1, 9562 maxZoom: 15, 9563 subdomains: ['server', 'services'], 9564 attribution: 'USGS, National Geographic Society, i-cubed' 9565 } 9566 }, 9567 ImageryClarity: { 9568 urlTemplate: tileProtocol + '//clarity.maptiles.arcgis.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', 9569 options: { 9570 minZoom: 1, 9571 maxZoom: 19, 9572 attribution: 'Esri, DigitalGlobe, GeoEye, Earthstar Geographics, CNES/Airbus DS, USDA, USGS, AeroGRID, IGN, and the GIS User Community' 9573 } 9574 }, 9575 Physical: { 9576 urlTemplate: tileProtocol + '//{s}.arcgisonline.com/arcgis/rest/services/World_Physical_Map/MapServer/tile/{z}/{y}/{x}', 9577 options: { 9578 minZoom: 1, 9579 maxZoom: 8, 9580 subdomains: ['server', 'services'], 9581 attribution: 'U.S. National Park Service' 9582 } 9583 }, 9584 ImageryFirefly: { 9585 urlTemplate: tileProtocol + '//fly.maptiles.arcgis.com/arcgis/rest/services/World_Imagery_Firefly/MapServer/tile/{z}/{y}/{x}', 9586 options: { 9587 minZoom: 1, 9588 maxZoom: 19, 9589 attribution: 'Esri, DigitalGlobe, GeoEye, Earthstar Geographics, CNES/Airbus DS, USDA, USGS, AeroGRID, IGN, and the GIS User Community', 9590 attributionUrl: 'https://static.arcgis.com/attribution/World_Imagery' 9591 } 9592 } 9593 } 9594 }, 9595 initialize: function (key, options) { 9596 var config; 9597 if (typeof key === 'object' && key.urlTemplate && key.options) { 9598 config = key 9599 } else if (typeof key === 'string' && BasemapLayer.TILES[key]) { 9600 config = BasemapLayer.TILES[key] 9601 } else { 9602 throw new Error('L.esri.BasemapLayer: Invalid parameter. Use one of "Streets", "Topographic", "Oceans", "OceansLabels", "NationalGeographic", "Physical", "Gray", "GrayLabels", "DarkGray", "DarkGrayLabels", "Imagery", "ImageryLabels", "ImageryTransportation", "ImageryClarity", "ImageryFirefly", ShadedRelief", "ShadedReliefLabels", "Terrain", "TerrainLabels" or "USATopo"') 9603 } 9604 var tileOptions = leaflet.Util.extend(config.options, options); 9605 leaflet.Util.setOptions(this, tileOptions); 9606 if (this.options.token && config.urlTemplate.indexOf('token=') === -1) {
9607 config.urlTemplate += ('?token=' + this.options.token) 9608 } 9609 leaflet.TileLayer.prototype.initialize.call(this, config.urlTemplate, tileOptions) 9610 }, 9611 onAdd: function (map) { 9612 setEsriAttribution(map); 9613 if (this.options.pane === 'esri-labels') { 9614 this._initPane() 9615 } 9616 if (this.options.attributionUrl) { 9617 _getAttributionData(this.options.attributionUrl, map) 9618 } 9619 map.on('moveend', _updateMapAttribution); 9620 leaflet.TileLayer.prototype.onAdd.call(this, map) 9621 }, 9622 onRemove: function (map) { 9623 map.off('moveend', _updateMapAttribution); 9624 leaflet.TileLayer.prototype.onRemove.call(this, map) 9625 }, 9626 _initPane: function () { 9627 if (!this._map.getPane(this.options.pane)) { 9628 var pane = this._map.createPane(this.options.pane); 9629 pane.style.pointerEvents = 'none'; 9630 pane.style.zIndex = 500 9631 } 9632 }, 9633 getAttribution: function () { 9634 if (this.options.attribution) { 9635 var attribution = '<span class="esri-dynamic-attribution">' + this.options.attribution + '</span>' 9636 } 9637 return attribution 9638 } 9639 }); 9640 function basemapLayer(key, options) { 9641 return new BasemapLayer(key, options) 9642 } 9643 var TiledMapLayer = leaflet.TileLayer.extend({ 9644 options: { 9645 zoomOffsetAllowance: 0.1, 9646 errorTileUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEABAMAAACuXLVVAAAAA1BMVEUzNDVszlHHAAAAAXRSTlMAQObYZgAAAAlwSFlzAAAAAAAAAAAB6mUWpAAAADZJREFUeJztwQEBAAAAgiD/r25IQAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA7waBAAABw08RwAAAAABJRU5ErkJggg==' 9647 }, 9648 statics: { 9649 MercatorZoomLevels: { 9650 '0': 156543.03392799999, 9651 '1': 78271.516963999893, 9652 '2': 39135.758482000099, 9653 '3': 19567.879240999901, 9654 '4': 9783.9396204999593, 9655 '5': 4891.9698102499797, 9656 '6': 2445.9849051249898, 9657 '7': 1222.9924525624899, 9658 '8': 611.49622628138002, 9659 '9': 305.74811314055802, 9660 '10': 152.874056570411, 9661 '11': 76.437028285073197, 9662 '12': 38.218514142536598, 9663 '13': 19.109257071268299, 9664 '14': 9.5546285356341496, 9665 '15': 4.7773142679493699, 9666 '16': 2.38865713397468, 9667 '17': 1.1943285668550501, 9668 '18': 0.59716428355981699, 9669 '19': 0.29858214164761698, 9670 '20': 0.14929107082381, 9671 '21': 0.07464553541191, 9672 '22': 0.0373227677059525, 9673 '23': 0.0186613838529763 9674 } 9675 }, 9676 initialize: function (options) { 9677 options = leaflet.Util.setOptions(this, options); 9678 options = getUrlParams(options); 9679 this.tileUrl = (options.proxy ? options.proxy + '?' : '') + options.url + 'tile/{z}/{y}/{x}' + (options.requestParams && Object.keys(options.requestParams).length > 0 ? leaflet.Util.getParamString(options.requestParams) : ''); 9680 if (options.url.indexOf('{s}') !== -1 && options.subdomains) { 9681 options.url = options.url.replace('{s}', options.subdomains[0]) 9682 } 9683 this.service = mapService(options); 9684 this.service.addEventParent(this); 9685 var arcgisonline = new RegExp(/tiles.arcgis(online)?\.com/g); 9686 if (arcgisonline.test(options.url)) { 9687 this.tileUrl = this.tileUrl.replace('://tiles', '://tiles{s}'); 9688 options.subdomains = ['1', '2', '3', '4'] 9689 } 9690 if (this.options.token) { 9691 this.tileUrl += ('?token=' + this.options.token) 9692 } 9693 leaflet.TileLayer.prototype.initialize.call(this, this.tileUrl, options) 9694 }, 9695 getTileUrl: function (tilePoint) { 9696 var zoom = this._getZoomForUrl(); 9697 return leaflet.Util.template(this.tileUrl, leaflet.Util.extend({ 9698 s: this._getSubdomain(tilePoint), 9699 x: tilePoint.x, 9700 y: tilePoint.y, 9701 z: (this._lodMap && this._lodMap[zoom]) ? this._lodMap[zoom] : zoom 9702 }, this.options)) 9703 }, 9704 createTile: function (coords, done) { 9705 var tile = document.createElement('img'); 9706 leaflet.DomEvent.on(tile, 'load', leaflet.Util.bind(this._tileOnLoad, this, done, tile)); 9707 leaflet.DomEvent.on(tile, 'error', leaflet.Util.bind(this._tileOnError, this, done, tile)); 9708 if (this.options.crossOrigin) { 9709 tile.crossOrigin = '' 9710 } 9711 tile.alt = ''; 9712 if (!this._lodMap || (this._lodMap && this._lodMap[this._getZoomForUrl()])) { 9713 tile.src = this.getTileUrl(coords) 9714 } else { 9715 this.once('lodmap', function () { 9716 tile.src = this.getTileUrl(coords) 9717 }, this) 9718 } 9719 return tile 9720 }, 9721 onAdd: function (map) { 9722 setEsriAttribution(map); 9723 if (!this._lodMap) { 9724 this.metadata(function (error, metadata) { 9725 if (!error && metadata.spatialReference) { 9726 var sr = metadata.spatialReference.latestWkid || metadata.spatialReference.wkid;
9727 if (!this.options.attribution && map.attributionControl && metadata.copyrightText) { 9728 this.options.attribution = metadata.copyrightText; 9729 map.attributionControl.addAttribution(this.getAttribution()) 9730 } 9731 if (map.options.crs === leaflet.CRS.EPSG3857 && (sr === 102100 || sr === 3857)) { 9732 this._lodMap = {}; 9733 var arcgisLODs = metadata.tileInfo.lods; 9734 var correctResolutions = TiledMapLayer.MercatorZoomLevels; 9735 for (var i = 0; i < arcgisLODs.length; i++) { 9736 var arcgisLOD = arcgisLODs[i]; 9737 for (var ci in correctResolutions) { 9738 var correctRes = correctResolutions[ci]; 9739 if (this._withinPercentage(arcgisLOD.resolution, correctRes, this.options.zoomOffsetAllowance)) { 9740 this._lodMap[ci] = arcgisLOD.level; 9741 break 9742 } 9743 } 9744 } 9745 this.fire('lodmap') 9746 } else if (map.options.crs && map.options.crs.code && (map.options.crs.code.indexOf(sr) > -1)) { } else { 9747 warn('L.esri.TiledMapLayer is using a non-mercator spatial reference. Support may be available through Proj4leaflet http://esri.github.io/esri-leaflet/examples/non-mercator-projection.html') 9748 } 9749 } 9750 }, this) 9751 } 9752 leaflet.TileLayer.prototype.onAdd.call(this, map) 9753 }, 9754 metadata: function (callback, context) { 9755 this.service.metadata(callback, context); 9756 return this 9757 }, 9758 identify: function () { 9759 return this.service.identify() 9760 }, 9761 find: function () { 9762 return this.service.find() 9763 }, 9764 query: function () { 9765 return this.service.query() 9766 }, 9767 authenticate: function (token) { 9768 var tokenQs = '?token=' + token; 9769 this.tileUrl = (this.options.token) ? this.tileUrl.replace(/\?token=(.+)/g, tokenQs) : this.tileUrl + tokenQs; 9770 this.options.token = token; 9771 this.service.authenticate(token); 9772 return this 9773 }, 9774 _withinPercentage: function (a, b, percentage) { 9775 var diff = Math.abs((a / b) - 1); 9776 return diff < percentage 9777 } 9778 }); 9779 function tiledMapLayer(url, options) { 9780 return new TiledMapLayer(url, options) 9781 } 9782 var Overlay = leaflet.ImageOverlay.extend({ 9783 onAdd: function (map) { 9784 this._topLeft = map.getPixelBounds().min; 9785 leaflet.ImageOverlay.prototype.onAdd.call(this, map) 9786 }, 9787 _reset: function () { 9788 if (this._map.options.crs === leaflet.CRS.EPSG3857) { 9789 leaflet.ImageOverlay.prototype._reset.call(this) 9790 } else { 9791 leaflet.DomUtil.setPosition(this._image, this._topLeft.subtract(this._map.getPixelOrigin())) 9792 } 9793 } 9794 }); 9795 var RasterLayer = leaflet.Layer.extend({ 9796 options: { 9797 opacity: 1, 9798 position: 'front', 9799 f: 'image', 9800 useCors: cors, 9801 attribution: null, 9802 interactive: !1, 9803 alt: '' 9804 }, 9805 onAdd: function (map) { 9806 setEsriAttribution(map); 9807 this._update = leaflet.Util.throttle(this._update, this.options.updateInterval, this); 9808 map.on('moveend', this._update, this); 9809 if (this._currentImage && this._currentImage._bounds.equals(this._map.getBounds())) { 9810 map.addLayer(this._currentImage) 9811 } else if (this._currentImage) { 9812 this._map.removeLayer(this._currentImage); 9813 this._currentImage = null 9814 } 9815 this._update(); 9816 if (this._popup) { 9817 this._map.on('click', this._getPopupData, this); 9818 this._map.on('dblclick', this._resetPopupState, this) 9819 } 9820 this.metadata(function (err, metadata) { 9821 if (!err && !this.options.attribution && map.attributionControl && metadata.copyrightText) { 9822 this.options.attribution = metadata.copyrightText; 9823 map.attributionControl.addAttribution(this.getAttribution()) 9824 } 9825 }, this) 9826 }, 9827 onRemove: function (map) { 9828 if (this._currentImage) { 9829 this._map.removeLayer(this._currentImage) 9830 } 9831 if (this._popup) { 9832 this._map.off('click', this._getPopupData, this); 9833 this._map.off('dblclick', this._resetPopupState, this) 9834 } 9835 this._map.off('moveend', this._update, this) 9836 }, 9837 bindPopup: function (fn, popupOptions) { 9838 this._shouldRenderPopup = !1; 9839 this._lastClick = !1; 9840 this._popup = leaflet.popup(popupOptions); 9841 this._popupFunction = fn; 9842 if (this._map) { 9843 this._map.on('click', this._getPopupData, this); 9844 this._map.on('dblclick', this._resetPopupState, this) 9845 } 9846 return this 9847 }, 9848 unbindPopup: function () { 9849 if (this._map) { 9850 this._map.closePopup(this._popup); 9851 this._map.off('click', this._getPopupData, this); 9852 this._map.off('dblclick', this._resetPopupState, this) 9853 } 9854 this._popup = !1; 9855 return this 9856 }, 9857 bringToFront: function () { 9858 this.options.position = 'front'; 9859 if (this._currentImage) { 9860 this._currentImage.bringToFront() 9861 } 9862 return this 9863 }, 9864 bringToBack: function () { 9865 this.options.position = 'back'; 9866 if (this._currentImage) { 9867 this._currentImage.bringToBack() 9868 } 9869 return this 9870 }, 9871 getAttribution: function () { 9872 return this.options.attribution 9873 }, 9874 getOpacity: function () { 9875 return this.options.opacity 9876 }, 9877 setOpacity: function (opacity) { 9878 this.options.opacity = opacity; 9879 if (this._currentImage) { 9880 this._currentImage.setOpacity(opacity) 9881 } 9882 return this 9883 }, 9884 getTimeRange: function () { 9885 return [this.options.from, this.options.to] 9886 }, 9887 setTimeRange: function (from, to) { 9888 this.options.from = from; 9889 this.options.to = to; 9890 this._update(); 9891 return this 9892 }, 9893 metadata: function (callback, context) { 9894 this.service.metadata(callback, context); 9895 return this 9896 }, 9897 authenticate: function (token) { 9898 this.service.authenticate(token); 9899 return this 9900 }, 9901 redraw: function () { 9902 this._update() 9903 }, 9904 _renderImage: function (url, bounds, contentType) { 9905 if (this._map) { 9906 if (contentType) { 9907 url = 'data:' + contentType + ';base64,' + url 9908 } 9909 if (!url) 9910 return; 9911 var image = new Overlay(url, bounds, { 9912 opacity: 0, 9913 crossOrigin: this.options.useCors, 9914 alt: this.options.alt, 9915 pane: this.options.pane || this.getPane(), 9916 interactive: this.options.interactive 9917 }).addTo(this._map); 9918 var onOverlayError = function () { 9919 this._map.removeLayer(image); 9920 this.fire('error'); 9921 image.off('load', onOverlayLoad, this) 9922 }; 9923 var onOverlayLoad = function (e) { 9924 image.off('error', onOverlayLoad, this); 9925 if (this._map) { 9926 var newImage = e.target; 9927 var oldImage = this._currentImage; 9928 if (newImage._bounds.equals(bounds) && newImage._bounds.equals(this._map.getBounds())) { 9929 this._currentImage = newImage; 9930 if (this.options.position === 'front') { 9931 this.bringToFront() 9932 } else { 9933 this.bringToBack() 9934 } 9935 if (this._map && this._currentImage._map) { 9936 this._currentImage.setOpacity(this.options.opacity) 9937 } else { 9938 this._currentImage._map.removeLayer(this._currentImage) 9939 } 9940 if (oldImage && this._map) { 9941 this._map.removeLayer(oldImage) 9942 } 9943 if (oldImage && oldImage._map) { 9944 oldImage._map.removeLayer(oldImage) 9945 } 9946 } else { 9947 this._map.removeLayer(newImage) 9948 } 9949 } 9950 this.fire('load', {
9951 bounds: bounds 9952 }) 9953 }; 9954 image.once('error', onOverlayError, this); 9955 image.once('load', onOverlayLoad, this); 9956 this.fire('loading', { 9957 bounds: bounds 9958 }) 9959 } 9960 }, 9961 _update: function () { 9962 if (!this._map) { 9963 return 9964 } 9965 var zoom = this._map.getZoom(); 9966 var bounds = this._map.getBounds(); 9967 if (this._animatingZoom) { 9968 return 9969 } 9970 if (this._map._panTransition && this._map._panTransition._inProgress) { 9971 return 9972 } 9973 if (zoom > this.options.maxZoom || zoom < this.options.minZoom) { 9974 if (this._currentImage) { 9975 this._currentImage._map.removeLayer(this._currentImage); 9976 this._currentImage = null 9977 } 9978 return 9979 } 9980 var params = this._buildExportParams(); 9981 leaflet.Util.extend(params, this.options.requestParams); 9982 if (params) { 9983 this._requestExport(params, bounds) 9984 } else if (this._currentImage) { 9985 this._currentImage._map.removeLayer(this._currentImage); 9986 this._currentImage = null 9987 } 9988 }, 9989 _renderPopup: function (latlng, error, results, response) { 9990 latlng = leaflet.latLng(latlng); 9991 if (this._shouldRenderPopup && this._lastClick.equals(latlng)) { 9992 var content = this._popupFunction(error, results, response); 9993 if (content) { 9994 this._popup.setLatLng(latlng).setContent(content).openOn(this._map) 9995 } 9996 } 9997 }, 9998 _resetPopupState: function (e) { 9999 this._shouldRenderPopup = !1; 10000 this._lastClick = e.latlng 10001 }, 10002 _calculateBbox: function () { 10003 var pixelBounds = this._map.getPixelBounds(); 10004 var sw = this._map.unproject(pixelBounds.getBottomLeft()); 10005 var ne = this._map.unproject(pixelBounds.getTopRight()); 10006 var neProjected = this._map.options.crs.project(ne); 10007 var swProjected = this._map.options.crs.project(sw); 10008 var boundsProjected = leaflet.bounds(neProjected, swProjected); 10009 return [boundsProjected.getBottomLeft().x, boundsProjected.getBottomLeft().y, boundsProjected.getTopRight().x, boundsProjected.getTopRight().y].join(',') 10010 }, 10011 _calculateImageSize: function () { 10012 var bounds = this._map.getPixelBounds(); 10013 var size = this._map.getSize(); 10014 var sw = this._map.unproject(bounds.getBottomLeft()); 10015 var ne = this._map.unproject(bounds.getTopRight()); 10016 var top = this._map.latLngToLayerPoint(ne).y; 10017 var bottom = this._map.latLngToLayerPoint(sw).y; 10018 if (top > 0 || bottom < size.y) { 10019 size.y = bottom - top 10020 } 10021 return size.x + ',' + size.y 10022 } 10023 }); 10024 var ImageMapLayer = RasterLayer.extend({ 10025 options: { 10026 updateInterval: 150, 10027 format: 'jpgpng', 10028 transparent: !0, 10029 f: 'image' 10030 }, 10031 query: function () { 10032 return this.service.query() 10033 }, 10034 identify: function () { 10035 return this.service.identify() 10036 }, 10037 initialize: function (options) { 10038 options = getUrlParams(options); 10039 this.service = imageService(options); 10040 this.service.addEventParent(this); 10041 leaflet.Util.setOptions(this, options) 10042 }, 10043 setPixelType: function (pixelType) { 10044 this.options.pixelType = pixelType; 10045 this._update(); 10046 return this 10047 }, 10048 getPixelType: function () { 10049 return this.options.pixelType 10050 }, 10051 setBandIds: function (bandIds) { 10052 if (leaflet.Util.isArray(bandIds)) { 10053 this.options.bandIds = bandIds.join(',') 10054 } else { 10055 this.options.bandIds = bandIds.toString() 10056 } 10057 this._update(); 10058 return this 10059 }, 10060 getBandIds: function () { 10061 return this.options.bandIds 10062 }, 10063 setNoData: function (noData, noDataInterpretation) { 10064 if (leaflet.Util.isArray(noData)) { 10065 this.options.noData = noData.join(',') 10066 } else { 10067 this.options.noData = noData.toString() 10068 } 10069 if (noDataInterpretation) { 10070 this.options.noDataInterpretation = noDataInterpretation 10071 } 10072 this._update(); 10073 return this 10074 }, 10075 getNoData: function () { 10076 return this.options.noData 10077 }, 10078 getNoDataInterpretation: function () { 10079 return this.options.noDataInterpretation 10080 }, 10081 setRenderingRule: function (renderingRule) { 10082 this.options.renderingRule = renderingRule; 10083 this._update() 10084 }, 10085 getRenderingRule: function () { 10086 return this.options.renderingRule 10087 }, 10088 setMosaicRule: function (mosaicRule) { 10089 this.options.mosaicRule = mosaicRule; 10090 this._update() 10091 }, 10092 getMosaicRule: function () { 10093 return this.options.mosaicRule 10094 }, 10095 _getPopupData: function (e) { 10096 var callback = leaflet.Util.bind(function (error, results, response) { 10097 if (error) { 10098 return 10099 } 10100 setTimeout(leaflet.Util.bind(function () { 10101 this._renderPopup(e.latlng, error, results, response) 10102 }, this), 300) 10103 }, this); 10104 var identifyRequest = this.identify().at(e.latlng); 10105 if (this.options.mosaicRule) { 10106 identifyRequest.setMosaicRule(this.options.mosaicRule) 10107 } 10108 identifyRequest.run(callback); 10109 this._shouldRenderPopup = !0; 10110 this._lastClick = e.latlng 10111 }, 10112 _buildExportParams: function () { 10113 var sr = parseInt(this._map.options.crs.code.split(':')[1], 10); 10114 var params = { 10115 bbox: this._calculateBbox(), 10116 size: this._calculateImageSize(), 10117 format: this.options.format, 10118 transparent: this.options.transparent, 10119 bboxSR: sr, 10120 imageSR: sr 10121 }; 10122 if (this.options.from && this.options.to) { 10123 params.time = this.options.from.valueOf() + ',' + this.options.to.valueOf() 10124 } 10125 if (this.options.pixelType) { 10126 params.pixelType = this.options.pixelType 10127 } 10128 if (this.options.interpolation) { 10129 params.interpolation = this.options.interpolation 10130 } 10131 if (this.options.compressionQuality) { 10132 params.compressionQuality = this.options.compressionQuality 10133 } 10134 if (this.options.bandIds) { 10135 params.bandIds = this.options.bandIds 10136 } 10137 if (this.options.noData === 0 || this.options.noData) { 10138 params.noData = this.options.noData 10139 } 10140 if (this.options.noDataInterpretation) { 10141 params.noDataInterpretation = this.options.noDataInterpretation 10142 } 10143 if (this.service.options.token) { 10144 params.token = this.service.options.token 10145 } 10146 if (this.options.renderingRule) { 10147 params.renderingRule = JSON.stringify(this.options.renderingRule) 10148 } 10149 if (this.options.mosaicRule) { 10150 params.mosaicRule = JSON.stringify(this.options.mosaicRule) 10151 } 10152 return params 10153 }, 10154 _requestExport: function (params, bounds) { 10155 if (this.options.f === 'json') { 10156 this.service.request('exportImage', params, function (error, response) { 10157 if (error) { 10158 return 10159 } 10160 if (this.options.token) {
10161 response.href += ('?token=' + this.options.token) 10162 } 10163 this._renderImage(response.href, bounds) 10164 }, this) 10165 } else { 10166 params.f = 'image'; 10167 this._renderImage(this.options.url + 'exportImage' + leaflet.Util.getParamString(params), bounds) 10168 } 10169 } 10170 }); 10171 function imageMapLayer(url, options) { 10172 return new ImageMapLayer(url, options) 10173 } 10174 var DynamicMapLayer = RasterLayer.extend({ 10175 options: { 10176 updateInterval: 150, 10177 layers: !1, 10178 layerDefs: !1, 10179 timeOptions: !1, 10180 format: 'png24', 10181 transparent: !0, 10182 f: 'json' 10183 }, 10184 initialize: function (options) { 10185 options = getUrlParams(options); 10186 this.service = mapService(options); 10187 this.service.addEventParent(this); 10188 if ((options.proxy || options.token) && options.f !== 'json') { 10189 options.f = 'json' 10190 } 10191 leaflet.Util.setOptions(this, options) 10192 }, 10193 getDynamicLayers: function () { 10194 return this.options.dynamicLayers 10195 }, 10196 setDynamicLayers: function (dynamicLayers) { 10197 this.options.dynamicLayers = dynamicLayers; 10198 this._update(); 10199 return this 10200 }, 10201 getLayers: function () { 10202 return this.options.layers 10203 }, 10204 setLayers: function (layers) { 10205 this.options.layers = layers; 10206 this._update(); 10207 return this 10208 }, 10209 getLayerDefs: function () { 10210 return this.options.layerDefs 10211 }, 10212 setLayerDefs: function (layerDefs) { 10213 this.options.layerDefs = layerDefs; 10214 this._update(); 10215 return this 10216 }, 10217 getTimeOptions: function () { 10218 return this.options.timeOptions 10219 }, 10220 setTimeOptions: function (timeOptions) { 10221 this.options.timeOptions = timeOptions; 10222 this._update(); 10223 return this 10224 }, 10225 query: function () { 10226 return this.service.query() 10227 }, 10228 identify: function () { 10229 return this.service.identify() 10230 }, 10231 find: function () { 10232 return this.service.find() 10233 }, 10234 _getPopupData: function (e) { 10235 var callback = leaflet.Util.bind(function (error, featureCollection, response) { 10236 if (error) { 10237 return 10238 } 10239 setTimeout(leaflet.Util.bind(function () { 10240 this._renderPopup(e.latlng, error, featureCollection, response) 10241 }, this), 300) 10242 }, this); 10243 var identifyRequest; 10244 if (this.options.popup) { 10245 identifyRequest = this.options.popup.on(this._map).at(e.latlng) 10246 } else { 10247 identifyRequest = this.identify().on(this._map).at(e.latlng) 10248 } 10249 identifyRequest.params.maxAllowableOffset ? !0 : identifyRequest.simplify(this._map, 0.5); 10250 if (!(this.options.popup && this.options.popup.params && this.options.popup.params.layers)) { 10251 if (this.options.layers) { 10252 identifyRequest.layers('visible:' + this.options.layers.join(',')) 10253 } else { 10254 identifyRequest.layers('visible') 10255 } 10256 } 10257 if (this.options.layerDefs && typeof this.options.layerDefs !== 'string' && !identifyRequest.params.layerDefs) { 10258 for (var id in this.options.layerDefs) { 10259 if (this.options.layerDefs.hasOwnProperty(id)) { 10260 identifyRequest.layerDef(id, this.options.layerDefs[id]) 10261 } 10262 } 10263 } 10264 identifyRequest.run(callback); 10265 this._shouldRenderPopup = !0; 10266 this._lastClick = e.latlng 10267 }, 10268 _buildExportParams: function () { 10269 var sr = parseInt(this._map.options.crs.code.split(':')[1], 10); 10270 var params = { 10271 bbox: this._calculateBbox(), 10272 size: this._calculateImageSize(), 10273 dpi: 96, 10274 format: this.options.format, 10275 transparent: this.options.transparent, 10276 bboxSR: sr, 10277 imageSR: sr 10278 }; 10279 if (this.options.dynamicLayers) { 10280 params.dynamicLayers = this.options.dynamicLayers 10281 } 10282 if (this.options.layers) { 10283 if (this.options.layers.length === 0) { 10284 return 10285 } else { 10286 params.layers = 'show:' + this.options.layers.join(',') 10287 } 10288 } 10289 if (this.options.layerDefs) { 10290 params.layerDefs = typeof this.options.layerDefs === 'string' ? this.options.layerDefs : JSON.stringify(this.options.layerDefs) 10291 } 10292 if (this.options.timeOptions) { 10293 params.timeOptions = JSON.stringify(this.options.timeOptions) 10294 } 10295 if (this.options.from && this.options.to) { 10296 params.time = this.options.from.valueOf() + ',' + this.options.to.valueOf() 10297 } 10298 if (this.service.options.token) { 10299 params.token = this.service.options.token 10300 } 10301 if (this.options.proxy) { 10302 params.proxy = this.options.proxy 10303 } 10304 if (this.options.disableCache) { 10305 params._ts = Date.now() 10306 } 10307 return params 10308 }, 10309 _requestExport: function (params, bounds) { 10310 if (this.options.f === 'json') { 10311 this.service.request('export', params, function (error, response) { 10312 if (error) { 10313 return 10314 } 10315 if (this.options.token) {
10316 response.href += ('?token=' + this.options.token) 10317 } 10318 if (this.options.proxy) { 10319 response.href = this.options.proxy + '?' + response.href 10320 } 10321 if (response.href) { 10322 this._renderImage(response.href, bounds) 10323 } else { 10324 this._renderImage(response.imageData, bounds, response.contentType) 10325 } 10326 }, this) 10327 } else { 10328 params.f = 'image'; 10329 this._renderImage(this.options.url + 'export' + leaflet.Util.getParamString(params), bounds) 10330 } 10331 } 10332 }); 10333 function dynamicMapLayer(url, options) { 10334 return new DynamicMapLayer(url, options) 10335 } 10336 var VirtualGrid = leaflet.Layer.extend({ 10337 options: { 10338 cellSize: 512, 10339 updateInterval: 150 10340 }, 10341 initialize: function (options) { 10342 options = leaflet.setOptions(this, options); 10343 this._zooming = !1 10344 }, 10345 onAdd: function (map) { 10346 this._map = map; 10347 this._update = leaflet.Util.throttle(this._update, this.options.updateInterval, this); 10348 this._reset(); 10349 this._update() 10350 }, 10351 onRemove: function () { 10352 this._map.removeEventListener(this.getEvents(), this); 10353 this._removeCells() 10354 }, 10355 getEvents: function () { 10356 var events = { 10357 moveend: this._update, 10358 zoomstart: this._zoomstart, 10359 zoomend: this._reset 10360 }; 10361 return events 10362 }, 10363 addTo: function (map) { 10364 map.addLayer(this); 10365 return this 10366 }, 10367 removeFrom: function (map) { 10368 map.removeLayer(this); 10369 return this 10370 }, 10371 _zoomstart: function () { 10372 this._zooming = !0 10373 }, 10374 _reset: function () { 10375 this._removeCells(); 10376 this._cells = {}; 10377 this._activeCells = {}; 10378 this._cellsToLoad = 0; 10379 this._cellsTotal = 0; 10380 this._cellNumBounds = this._getCellNumBounds(); 10381 this._resetWrap(); 10382 this._zooming = !1 10383 }, 10384 _resetWrap: function () { 10385 var map = this._map; 10386 var crs = map.options.crs; 10387 if (crs.infinite) { 10388 return 10389 } 10390 var cellSize = this._getCellSize(); 10391 if (crs.wrapLng) { 10392 this._wrapLng = [Math.floor(map.project([0, crs.wrapLng[0]]).x / cellSize), Math.ceil(map.project([0, crs.wrapLng[1]]).x / cellSize)] 10393 } 10394 if (crs.wrapLat) { 10395 this._wrapLat = [Math.floor(map.project([crs.wrapLat[0], 0]).y / cellSize), Math.ceil(map.project([crs.wrapLat[1], 0]).y / cellSize)] 10396 } 10397 }, 10398 _getCellSize: function () { 10399 return this.options.cellSize 10400 }, 10401 _update: function () { 10402 if (!this._map) { 10403 return 10404 } 10405 var mapBounds = this._map.getPixelBounds(); 10406 var cellSize = this._getCellSize(); 10407 var cellBounds = leaflet.bounds(mapBounds.min.divideBy(cellSize).floor(), mapBounds.max.divideBy(cellSize).floor()); 10408 this._removeOtherCells(cellBounds); 10409 this._addCells(cellBounds); 10410 this.fire('cellsupdated') 10411 }, 10412 _addCells: function (cellBounds) { 10413 var queue = []; 10414 var center = cellBounds.getCenter(); 10415 var zoom = this._map.getZoom(); 10416 var j, i, coords; 10417 for (j = cellBounds.min.y; j <= cellBounds.max.y; j++) { 10418 for (i = cellBounds.min.x; i <= cellBounds.max.x; i++) { 10419 coords = leaflet.point(i, j); 10420 coords.z = zoom; 10421 if (this._isValidCell(coords)) { 10422 queue.push(coords) 10423 } 10424 } 10425 } 10426 var cellsToLoad = queue.length; 10427 if (cellsToLoad === 0) { 10428 return 10429 } 10430 this._cellsToLoad += cellsToLoad; 10431 this._cellsTotal += cellsToLoad; 10432 queue.sort(function (a, b) { 10433 return a.distanceTo(center) - b.distanceTo(center) 10434 }); 10435 for (i = 0; i < cellsToLoad; i++) { 10436 this._addCell(queue[i]) 10437 } 10438 }, 10439 _isValidCell: function (coords) { 10440 var crs = this._map.options.crs; 10441 if (!crs.infinite) { 10442 var cellNumBounds = this._cellNumBounds; 10443 if (!cellNumBounds) 10444 return !1; 10445 if ((!crs.wrapLng && (coords.x < cellNumBounds.min.x || coords.x > cellNumBounds.max.x)) || (!crs.wrapLat && (coords.y < cellNumBounds.min.y || coords.y > cellNumBounds.max.y))) { 10446 return !1 10447 } 10448 } 10449 if (!this.options.bounds) { 10450 return !0 10451 } 10452 var cellBounds = this._cellCoordsToBounds(coords);
10453 return leaflet.latLngBounds(this.options.bounds).intersects(cellBounds) 10454 }, 10455 _cellCoordsToBounds: function (coords) { 10456 var map = this._map; 10457 var cellSize = this.options.cellSize; 10458 var nwPoint = coords.multiplyBy(cellSize); 10459 var sePoint = nwPoint.add([cellSize, cellSize]); 10460 var nw = map.wrapLatLng(map.unproject(nwPoint, coords.z)); 10461 var se = map.wrapLatLng(map.unproject(sePoint, coords.z)); 10462 return leaflet.latLngBounds(nw, se) 10463 }, 10464 _cellCoordsToKey: function (coords) { 10465 return coords.x + ':' + coords.y 10466 }, 10467 _keyToCellCoords: function (key) { 10468 var kArr = key.split(':'); 10469 var x = parseInt(kArr[0], 10); 10470 var y = parseInt(kArr[1], 10); 10471 return leaflet.point(x, y) 10472 }, 10473 _removeOtherCells: function (bounds) { 10474 for (var key in this._cells) { 10475 if (!bounds.contains(this._keyToCellCoords(key))) { 10476 this._removeCell(key) 10477 } 10478 } 10479 }, 10480 _removeCell: function (key) { 10481 var cell = this._activeCells[key]; 10482 if (cell) { 10483 delete this._activeCells[key]; 10484 if (this.cellLeave) { 10485 this.cellLeave(cell.bounds, cell.coords) 10486 } 10487 this.fire('cellleave', { 10488 bounds: cell.bounds, 10489 coords: cell.coords 10490 }) 10491 } 10492 }, 10493 _removeCells: function () { 10494 for (var key in this._cells) { 10495 var cellBounds = this._cells[key].bounds; 10496 var coords = this._cells[key].coords; 10497 if (this.cellLeave) { 10498 this.cellLeave(cellBounds, coords) 10499 } 10500 this.fire('cellleave', { 10501 bounds: cellBounds, 10502 coords: coords 10503 }) 10504 } 10505 }, 10506 _addCell: function (coords) { 10507 this._wrapCoords(coords); 10508 var key = this._cellCoordsToKey(coords); 10509 var cell = this._cells[key]; 10510 if (cell && !this._activeCells[key]) { 10511 if (this.cellEnter) { 10512 this.cellEnter(cell.bounds, coords) 10513 } 10514 this.fire('cellenter', { 10515 bounds: cell.bounds, 10516 coords: coords 10517 }); 10518 this._activeCells[key] = cell 10519 } 10520 if (!cell) { 10521 cell = { 10522 coords: coords, 10523 bounds: this._cellCoordsToBounds(coords) 10524 }; 10525 this._cells[key] = cell; 10526 this._activeCells[key] = cell; 10527 if (this.createCell) { 10528 this.createCell(cell.bounds, coords) 10529 } 10530 this.fire('cellcreate', { 10531 bounds: cell.bounds, 10532 coords: coords 10533 }) 10534 } 10535 }, 10536 _wrapCoords: function (coords) { 10537 coords.x = this._wrapLng ? leaflet.Util.wrapNum(coords.x, this._wrapLng) : coords.x; 10538 coords.y = this._wrapLat ? leaflet.Util.wrapNum(coords.y, this._wrapLat) : coords.y 10539 }, 10540 _getCellNumBounds: function () { 10541 var worldBounds = this._map.getPixelWorldBounds(); 10542 var size = this._getCellSize(); 10543 return worldBounds ? leaflet.bounds(worldBounds.min.divideBy(size).floor(), worldBounds.max.divideBy(size).ceil().subtract([1, 1])) : null 10544 } 10545 }); 10546 function BinarySearchIndex(values) { 10547 this.values = [].concat(values || []) 10548 } 10549 BinarySearchIndex.prototype.query = function (value) { 10550 var index = this.getIndex(value); 10551 return this.values[index] 10552 } 10553 ; 10554 BinarySearchIndex.prototype.getIndex = function getIndex(value) { 10555 if (this.dirty) { 10556 this.sort() 10557 } 10558 var minIndex = 0; 10559 var maxIndex = this.values.length - 1; 10560 var currentIndex; 10561 var currentElement; 10562 while (minIndex <= maxIndex) { 10563 currentIndex = (minIndex + maxIndex) / 2 | 0; 10564 currentElement = this.values[Math.round(currentIndex)]; 10565 if (+currentElement.value < +value) { 10566 minIndex = currentIndex + 1 10567 } else if (+currentElement.value > +value) { 10568 maxIndex = currentIndex - 1 10569 } else { 10570 return currentIndex 10571 } 10572 } 10573 return Math.abs(~maxIndex) 10574 } 10575 ; 10576 BinarySearchIndex.prototype.between = function between(start, end) { 10577 var startIndex = this.getIndex(start); 10578 var endIndex = this.getIndex(end); 10579 if (startIndex === 0 && endIndex === 0) { 10580 return [] 10581 } 10582 while (this.values[startIndex - 1] && this.values[startIndex - 1].value === start) { 10583 startIndex-- 10584 } 10585 while (this.values[endIndex + 1] && this.values[endIndex + 1].value === end) { 10586 endIndex++ 10587 } 10588 if (this.values[endIndex] && this.values[endIndex].value === end && this.values[endIndex + 1]) { 10589 endIndex++ 10590 } 10591 return this.values.slice(startIndex, endIndex) 10592 } 10593 ; 10594 BinarySearchIndex.prototype.insert = function insert(item) { 10595 this.values.splice(this.getIndex(item.value), 0, item); 10596 return this 10597 } 10598 ; 10599 BinarySearchIndex.prototype.bulkAdd = function bulkAdd(items, sort) { 10600 this.values = this.values.concat([].concat(items || [])); 10601 if (sort) { 10602 this.sort() 10603 } else { 10604 this.dirty = !0 10605 } 10606 return this 10607 } 10608 ; 10609 BinarySearchIndex.prototype.sort = function sort() { 10610 this.values.sort(function (a, b) { 10611 return +b.value - +a.value 10612 }).reverse(); 10613 this.dirty = !1; 10614 return this 10615 } 10616 ; 10617 var FeatureManager = VirtualGrid.extend({ 10618 options: { 10619 attribution: null, 10620 where: '1=1', 10621 fields: ['*'], 10622 from: !1, 10623 to: !1, 10624 timeField: !1, 10625 timeFilterMode: 'server', 10626 simplifyFactor: 0, 10627 precision: 6 10628 }, 10629 initialize: function (options) { 10630 VirtualGrid.prototype.initialize.call(this, options); 10631 options = getUrlParams(options); 10632 options = leaflet.Util.setOptions(this, options); 10633 this.service = featureLayerService(options); 10634 this.service.addEventParent(this); 10635 if (this.options.fields[0] !== '*') { 10636 var oidCheck = !1; 10637 for (var i = 0; i < this.options.fields.length; i++) { 10638 if (this.options.fields[i].match(/^(OBJECTID|FID|OID|ID)$/i)) { 10639 oidCheck = !0 10640 } 10641 } 10642 if (oidCheck === !1) { 10643 warn('no known esriFieldTypeOID field detected in fields Array. Please add an attribute field containing unique IDs to ensure the layer can be drawn correctly.') 10644 } 10645 } 10646 if (this.options.timeField.start && this.options.timeField.end) { 10647 this._startTimeIndex = new BinarySearchIndex(); 10648 this._endTimeIndex = new BinarySearchIndex() 10649 } else if (this.options.timeField) { 10650 this._timeIndex = new BinarySearchIndex() 10651 } 10652 this._cache = {}; 10653 this._currentSnapshot = []; 10654 this._activeRequests = 0 10655 }, 10656 onAdd: function (map) { 10657 setEsriAttribution(map); 10658 this.service.metadata(function (err, metadata) { 10659 if (!err) { 10660 var supportedFormats = metadata.supportedQueryFormats; 10661 var forceJsonFormat = !1; 10662 if (this.service.options.isModern === !1) { 10663 forceJsonFormat = !0 10664 } 10665 if (!forceJsonFormat && supportedFormats && supportedFormats.indexOf('geoJSON') !== -1) { 10666 this.service.options.isModern = !0 10667 } 10668 if (metadata.objectIdField) { 10669 this.service.options.idAttribute = metadata.objectIdField 10670 } 10671 if (!this.options.attribution && map.attributionControl && metadata.copyrightText) { 10672 this.options.attribution = metadata.copyrightText; 10673 map.attributionControl.addAttribution(this.getAttribution()) 10674 } 10675 } 10676 }, this); 10677 map.on('zoomend', this._handleZoomChange, this); 10678 return VirtualGrid.prototype.onAdd.call(this, map) 10679 }, 10680 onRemove: function (map) { 10681 map.off('zoomend', this._handleZoomChange, this); 10682 return VirtualGrid.prototype.onRemove.call(this, map) 10683 }, 10684 getAttribution: function () { 10685 return this.options.attribution 10686 }, 10687 createCell: function (bounds, coords) { 10688 if (this._visibleZoom()) { 10689 this._requestFeatures(bounds, coords) 10690 } 10691 }, 10692 _requestFeatures: function (bounds, coords, callback) { 10693 this._activeRequests++; 10694 if (this._activeRequests === 1) { 10695 this.fire('loading', {
10696 bounds: bounds 10697 }, !0) 10698 } 10699 return this._buildQuery(bounds).run(function (error, featureCollection, response) { 10700 if (response && response.exceededTransferLimit) { 10701 this.fire('drawlimitexceeded') 10702 } 10703 if (!error && featureCollection && featureCollection.features.length) { 10704 leaflet.Util.requestAnimFrame(leaflet.Util.bind(function () { 10705 this._addFeatures(featureCollection.features, coords); 10706 this._postProcessFeatures(bounds) 10707 }, this)) 10708 } 10709 if (!error && featureCollection && !featureCollection.features.length) { 10710 this._postProcessFeatures(bounds) 10711 } 10712 if (error) { 10713 this._postProcessFeatures(bounds) 10714 } 10715 if (callback) { 10716 callback.call(this, error, featureCollection) 10717 } 10718 }, this) 10719 }, 10720 _postProcessFeatures: function (bounds) { 10721 this._activeRequests--; 10722 if (this._activeRequests <= 0) { 10723 this.fire('load', { 10724 bounds: bounds 10725 }) 10726 } 10727 }, 10728 _cacheKey: function (coords) { 10729 return coords.z + ':' + coords.x + ':' + coords.y 10730 }, 10731 _addFeatures: function (features, coords) { 10732 var key = this._cacheKey(coords); 10733 this._cache[key] = this._cache[key] || []; 10734 for (var i = features.length - 1; i >= 0; i--) { 10735 var id = features[i].id; 10736 if (this._currentSnapshot.indexOf(id) === -1) { 10737 this._currentSnapshot.push(id) 10738 } 10739 if (this._cache[key].indexOf(id) === -1) { 10740 this._cache[key].push(id) 10741 } 10742 } 10743 if (this.options.timeField) { 10744 this._buildTimeIndexes(features) 10745 } 10746 this.createLayers(features) 10747 }, 10748 _buildQuery: function (bounds) { 10749 var query = this.service.query().intersects(bounds).where(this.options.where).fields(this.options.fields).precision(this.options.precision); 10750 if (this.options.requestParams) { 10751 leaflet.Util.extend(query.params, this.options.requestParams) 10752 } 10753 if (this.options.simplifyFactor) { 10754 query.simplify(this._map, this.options.simplifyFactor) 10755 } 10756 if (this.options.timeFilterMode === 'server' && this.options.from && this.options.to) { 10757 query.between(this.options.from, this.options.to) 10758 } 10759 return query 10760 }, 10761 setWhere: function (where, callback, context) { 10762 this.options.where = (where && where.length) ? where : '1=1'; 10763 var oldSnapshot = []; 10764 var newSnapshot = []; 10765 var pendingRequests = 0; 10766 var requestError = null; 10767 var requestCallback = leaflet.Util.bind(function (error, featureCollection) { 10768 if (error) { 10769 requestError = error 10770 } 10771 if (featureCollection) { 10772 for (var i = featureCollection.features.length - 1; i >= 0; i--) { 10773 newSnapshot.push(featureCollection.features[i].id) 10774 } 10775 } 10776 pendingRequests--; 10777 if (pendingRequests <= 0 && this._visibleZoom()) { 10778 this._currentSnapshot = newSnapshot; 10779 leaflet.Util.requestAnimFrame(leaflet.Util.bind(function () { 10780 this.removeLayers(oldSnapshot); 10781 this.addLayers(newSnapshot); 10782 if (callback) { 10783 callback.call(context, requestError) 10784 } 10785 }, this)) 10786 } 10787 }, this); 10788 for (var i = this._currentSnapshot.length - 1; i >= 0; i--) { 10789 oldSnapshot.push(this._currentSnapshot[i]) 10790 } 10791 for (var key in this._activeCells) { 10792 pendingRequests++; 10793 var coords = this._keyToCellCoords(key); 10794 var bounds = this._cellCoordsToBounds(coords); 10795 this._requestFeatures(bounds, key, requestCallback) 10796 } 10797 return this 10798 }, 10799 getWhere: function () { 10800 return this.options.where 10801 }, 10802 getTimeRange: function () { 10803 return [this.options.from, this.options.to] 10804 }, 10805 setTimeRange: function (from, to, callback, context) { 10806 var oldFrom = this.options.from; 10807 var oldTo = this.options.to; 10808 var pendingRequests = 0; 10809 var requestError = null; 10810 var requestCallback = leaflet.Util.bind(function (error) { 10811 if (error) { 10812 requestError = error 10813 } 10814 this._filterExistingFeatures(oldFrom, oldTo, from, to); 10815 pendingRequests--; 10816 if (callback && pendingRequests <= 0) { 10817 callback.call(context, requestError) 10818 } 10819 }, this); 10820 this.options.from = from; 10821 this.options.to = to; 10822 this._filterExistingFeatures(oldFrom, oldTo, from, to); 10823 if (this.options.timeFilterMode === 'server') { 10824 for (var key in this._activeCells) { 10825 pendingRequests++; 10826 var coords = this._keyToCellCoords(key); 10827 var bounds = this._cellCoordsToBounds(coords);
10828 this._requestFeatures(bounds, key, requestCallback) 10829 } 10830 } 10831 return this 10832 }, 10833 refresh: function () { 10834 for (var key in this._activeCells) { 10835 var coords = this._keyToCellCoords(key); 10836 var bounds = this._cellCoordsToBounds(coords); 10837 this._requestFeatures(bounds, key) 10838 } 10839 if (this.redraw) { 10840 this.once('load', function () { 10841 this.eachFeature(function (layer) { 10842 this._redraw(layer.feature.id) 10843 }, this) 10844 }, this) 10845 } 10846 }, 10847 _filterExistingFeatures: function (oldFrom, oldTo, newFrom, newTo) { 10848 var layersToRemove = (oldFrom && oldTo) ? this._getFeaturesInTimeRange(oldFrom, oldTo) : this._currentSnapshot; 10849 var layersToAdd = this._getFeaturesInTimeRange(newFrom, newTo); 10850 if (layersToAdd.indexOf) { 10851 for (var i = 0; i < layersToAdd.length; i++) { 10852 var shouldRemoveLayer = layersToRemove.indexOf(layersToAdd[i]); 10853 if (shouldRemoveLayer >= 0) { 10854 layersToRemove.splice(shouldRemoveLayer, 1) 10855 } 10856 } 10857 } 10858 leaflet.Util.requestAnimFrame(leaflet.Util.bind(function () { 10859 this.removeLayers(layersToRemove); 10860 this.addLayers(layersToAdd) 10861 }, this)) 10862 }, 10863 _getFeaturesInTimeRange: function (start, end) { 10864 var ids = []; 10865 var search; 10866 if (this.options.timeField.start && this.options.timeField.end) { 10867 var startTimes = this._startTimeIndex.between(start, end); 10868 var endTimes = this._endTimeIndex.between(start, end); 10869 search = startTimes.concat(endTimes) 10870 } else { 10871 search = this._timeIndex.between(start, end) 10872 } 10873 for (var i = search.length - 1; i >= 0; i--) { 10874 ids.push(search[i].id) 10875 } 10876 return ids 10877 }, 10878 _buildTimeIndexes: function (geojson) { 10879 var i; 10880 var feature; 10881 if (this.options.timeField.start && this.options.timeField.end) { 10882 var startTimeEntries = []; 10883 var endTimeEntries = []; 10884 for (i = geojson.length - 1; i >= 0; i--) { 10885 feature = geojson[i]; 10886 startTimeEntries.push({ 10887 id: feature.id, 10888 value: new Date(feature.properties[this.options.timeField.start]) 10889 }); 10890 endTimeEntries.push({ 10891 id: feature.id, 10892 value: new Date(feature.properties[this.options.timeField.end]) 10893 }) 10894 } 10895 this._startTimeIndex.bulkAdd(startTimeEntries); 10896 this._endTimeIndex.bulkAdd(endTimeEntries) 10897 } else { 10898 var timeEntries = []; 10899 for (i = geojson.length - 1; i >= 0; i--) { 10900 feature = geojson[i]; 10901 timeEntries.push({ 10902 id: feature.id, 10903 value: new Date(feature.properties[this.options.timeField]) 10904 }) 10905 } 10906 this._timeIndex.bulkAdd(timeEntries) 10907 } 10908 }, 10909 _featureWithinTimeRange: function (feature) { 10910 if (!this.options.from || !this.options.to) { 10911 return !0 10912 } 10913 var from = +this.options.from.valueOf(); 10914 var to = +this.options.to.valueOf(); 10915 if (typeof this.options.timeField === 'string') { 10916 var date = +feature.properties[this.options.timeField]; 10917 return (date >= from) && (date <= to) 10918 } 10919 if (this.options.timeField.start && this.options.timeField.end) { 10920 var startDate = +feature.properties[this.options.timeField.start]; 10921 var endDate = +feature.properties[this.options.timeField.end]; 10922 return ((startDate >= from) && (startDate <= to)) || ((endDate >= from) && (endDate <= to)) 10923 } 10924 }, 10925 _visibleZoom: function () { 10926 if (!this._map) { 10927 return !1 10928 } 10929 var zoom = this._map.getZoom(); 10930 if (zoom > this.options.maxZoom || zoom < this.options.minZoom) { 10931 return !1 10932 } else { 10933 return !0 10934 } 10935 }, 10936 _handleZoomChange: function () { 10937 if (!this._visibleZoom()) { 10938 this.removeLayers(this._currentSnapshot); 10939 this._currentSnapshot = [] 10940 } else { 10941 for (var i in this._activeCells) { 10942 var coords = this._activeCells[i].coords; 10943 var key = this._cacheKey(coords);
10944 if (this._cache[key]) { 10945 this.addLayers(this._cache[key]) 10946 } 10947 } 10948 } 10949 }, 10950 authenticate: function (token) { 10951 this.service.authenticate(token); 10952 return this 10953 }, 10954 metadata: function (callback, context) { 10955 this.service.metadata(callback, context); 10956 return this 10957 }, 10958 query: function () { 10959 return this.service.query() 10960 }, 10961 _getMetadata: function (callback) { 10962 if (this._metadata) { 10963 var error; 10964 callback(error, this._metadata) 10965 } else { 10966 this.metadata(leaflet.Util.bind(function (error, response) { 10967 this._metadata = response; 10968 callback(error, this._metadata) 10969 }, this)) 10970 } 10971 }, 10972 addFeature: function (feature, callback, context) { 10973 this.addFeatures(feature, callback, context) 10974 }, 10975 addFeatures: function (features, callback, context) { 10976 this._getMetadata(leaflet.Util.bind(function (error, metadata) { 10977 if (error) { 10978 if (callback) { 10979 callback.call(this, error, null) 10980 } 10981 return 10982 } 10983 var featuresArray = features.features ? features.features : [features]; 10984 this.service.addFeatures(features, leaflet.Util.bind(function (error, response) { 10985 if (!error) { 10986 for (var i = featuresArray.length - 1; i >= 0; i--) { 10987 featuresArray[i].properties[metadata.objectIdField] = featuresArray.length > 1 ? response[i].objectId : response.objectId; 10988 featuresArray[i].id = featuresArray.length > 1 ? response[i].objectId : response.objectId 10989 } 10990 this.createLayers(featuresArray) 10991 } 10992 if (callback) { 10993 callback.call(context, error, response) 10994 } 10995 }, this)) 10996 }, this)) 10997 }, 10998 updateFeature: function (feature, callback, context) { 10999 this.updateFeatures(feature, callback, context) 11000 }, 11001 updateFeatures: function (features, callback, context) { 11002 var featuresArray = features.features ? features.features : [features]; 11003 this.service.updateFeatures(features, function (error, response) { 11004 if (!error) { 11005 for (var i = featuresArray.length - 1; i >= 0; i--) { 11006 this.removeLayers([featuresArray[i].id], !0) 11007 } 11008 this.createLayers(featuresArray) 11009 } 11010 if (callback) { 11011 callback.call(context, error, response) 11012 } 11013 }, this) 11014 }, 11015 deleteFeature: function (id, callback, context) { 11016 this.deleteFeatures(id, callback, context) 11017 }, 11018 deleteFeatures: function (ids, callback, context) { 11019 return this.service.deleteFeatures(ids, function (error, response) { 11020 var responseArray = response.length ? response : [response]; 11021 if (!error && responseArray.length > 0) { 11022 for (var i = responseArray.length - 1; i >= 0; i--) { 11023 this.removeLayers([responseArray[i].objectId], !0) 11024 } 11025 } 11026 if (callback) { 11027 callback.call(context, error, response) 11028 } 11029 }, this) 11030 } 11031 }); 11032 var FeatureLayer = FeatureManager.extend({ 11033 options: { 11034 cacheLayers: !0 11035 }, 11036 initialize: function (options) { 11037 FeatureManager.prototype.initialize.call(this, options); 11038 this._originalStyle = this.options.style; 11039 this._layers = {} 11040 }, 11041 onRemove: function (map) { 11042 for (var i in this._layers) { 11043 map.removeLayer(this._layers[i]); 11044 this.fire('removefeature', { 11045 feature: this._layers[i].feature, 11046 permanent: !1 11047 }, !0) 11048 } 11049 return FeatureManager.prototype.onRemove.call(this, map) 11050 }, 11051 createNewLayer: function (geojson) { 11052 var layer = leaflet.GeoJSON.geometryToLayer(geojson, this.options); 11053 if (layer) { 11054 layer.defaultOptions = layer.options 11055 } 11056 return layer 11057 }, 11058 _updateLayer: function (layer, geojson) { 11059 var latlngs = []; 11060 var coordsToLatLng = this.options.coordsToLatLng || leaflet.GeoJSON.coordsToLatLng; 11061 if (geojson.properties) { 11062 layer.feature.properties = geojson.properties 11063 } 11064 switch (geojson.geometry.type) { 11065 case 'Point': 11066 latlngs = leaflet.GeoJSON.coordsToLatLng(geojson.geometry.coordinates); 11067 layer.setLatLng(latlngs); 11068 break; 11069 case 'LineString': 11070 latlngs = leaflet.GeoJSON.coordsToLatLngs(geojson.geometry.coordinates, 0, coordsToLatLng); 11071 layer.setLatLngs(latlngs); 11072 break; 11073 case 'MultiLineString': 11074 latlngs = leaflet.GeoJSON.coordsToLatLngs(geojson.geometry.coordinates, 1, coordsToLatLng); 11075 layer.setLatLngs(latlngs); 11076 break; 11077 case 'Polygon': 11078 latlngs = leaflet.GeoJSON.coordsToLatLngs(geojson.geometry.coordinates, 1, coordsToLatLng); 11079 layer.setLatLngs(latlngs); 11080 break; 11081 case 'MultiPolygon': 11082 latlngs = leaflet.GeoJSON.coordsToLatLngs(geojson.geometry.coordinates, 2, coordsToLatLng); 11083 layer.setLatLngs(latlngs); 11084 break 11085 } 11086 }, 11087 createLayers: function (features) { 11088 for (var i = features.length - 1; i >= 0; i--) { 11089 var geojson = features[i]; 11090 var layer = this._layers[geojson.id]; 11091 var newLayer; 11092 if (this._visibleZoom() && layer && !this._map.hasLayer(layer)) { 11093 this._map.addLayer(layer); 11094 this.fire('addfeature', { 11095 feature: layer.feature 11096 }, !0) 11097 } 11098 if (layer && this.options.simplifyFactor > 0 && (layer.setLatLngs || layer.setLatLng)) { 11099 this._updateLayer(layer, geojson) 11100 } 11101 if (!layer) { 11102 newLayer = this.createNewLayer(geojson); 11103 if (!newLayer) { 11104 warn('invalid GeoJSON encountered') 11105 } else { 11106 newLayer.feature = geojson; 11107 newLayer.addEventParent(this); 11108 if (this.options.onEachFeature) { 11109 this.options.onEachFeature(newLayer.feature, newLayer) 11110 } 11111 this._layers[newLayer.feature.id] = newLayer; 11112 this.setFeatureStyle(newLayer.feature.id, this.options.style); 11113 this.fire('createfeature', { 11114 feature: newLayer.feature 11115 }, !0); 11116 if (this._visibleZoom() && (!this.options.timeField || (this.options.timeField && this._featureWithinTimeRange(geojson)))) { 11117 this._map.addLayer(newLayer) 11118 } 11119 } 11120 } 11121 } 11122 }, 11123 addLayers: function (ids) { 11124 for (var i = ids.length - 1; i >= 0; i--) { 11125 var layer = this._layers[ids[i]]; 11126 if (layer) { 11127 this._map.addLayer(layer) 11128 } 11129 } 11130 }, 11131 removeLayers: function (ids, permanent) { 11132 for (var i = ids.length - 1; i >= 0; i--) { 11133 var id = ids[i]; 11134 var layer = this._layers[id]; 11135 if (layer) { 11136 this.fire('removefeature', { 11137 feature: layer.feature, 11138 permanent: permanent 11139 }, !0); 11140 this._map.removeLayer(layer) 11141 } 11142 if (layer && permanent) { 11143 delete this._layers[id] 11144 } 11145 } 11146 }, 11147 cellEnter: function (bounds, coords) { 11148 if (this._visibleZoom() && !this._zooming && this._map) {
11149 leaflet.Util.requestAnimFrame(leaflet.Util.bind(function () { 11150 var cacheKey = this._cacheKey(coords); 11151 var cellKey = this._cellCoordsToKey(coords); 11152 var layers = this._cache[cacheKey]; 11153 if (this._activeCells[cellKey] && layers) { 11154 this.addLayers(layers) 11155 } 11156 }, this)) 11157 } 11158 }, 11159 cellLeave: function (bounds, coords) { 11160 if (!this._zooming) { 11161 leaflet.Util.requestAnimFrame(leaflet.Util.bind(function () { 11162 if (this._map) { 11163 var cacheKey = this._cacheKey(coords); 11164 var cellKey = this._cellCoordsToKey(coords); 11165 var layers = this._cache[cacheKey]; 11166 var mapBounds = this._map.getBounds(); 11167 if (!this._activeCells[cellKey] && layers) { 11168 var removable = !0; 11169 for (var i = 0; i < layers.length; i++) { 11170 var layer = this._layers[layers[i]]; 11171 if (layer && layer.getBounds && mapBounds.intersects(layer.getBounds())) { 11172 removable = !1 11173 } 11174 } 11175 if (removable) { 11176 this.removeLayers(layers, !this.options.cacheLayers) 11177 } 11178 if (!this.options.cacheLayers && removable) { 11179 delete this._cache[cacheKey]; 11180 delete this._cells[cellKey]; 11181 delete this._activeCells[cellKey] 11182 } 11183 } 11184 } 11185 }, this)) 11186 } 11187 }, 11188 resetStyle: function () { 11189 this.options.style = this._originalStyle; 11190 this.eachFeature(function (layer) { 11191 this.resetFeatureStyle(layer.feature.id) 11192 }, this); 11193 return this 11194 }, 11195 setStyle: function (style) { 11196 this.options.style = style; 11197 this.eachFeature(function (layer) { 11198 this.setFeatureStyle(layer.feature.id, style) 11199 }, this); 11200 return this 11201 }, 11202 resetFeatureStyle: function (id) { 11203 var layer = this._layers[id]; 11204 var style = this._originalStyle || leaflet.Path.prototype.options; 11205 if (layer) { 11206 leaflet.Util.extend(layer.options, layer.defaultOptions); 11207 this.setFeatureStyle(id, style) 11208 } 11209 return this 11210 }, 11211 setFeatureStyle: function (id, style) { 11212 var layer = this._layers[id]; 11213 if (typeof style === 'function') { 11214 style = style(layer.feature) 11215 } 11216 if (layer.setStyle) { 11217 layer.setStyle(style) 11218 } 11219 return this 11220 }, 11221 eachActiveFeature: function (fn, context) { 11222 if (this._map) { 11223 var activeBounds = this._map.getBounds(); 11224 for (var i in this._layers) { 11225 if (this._currentSnapshot.indexOf(this._layers[i].feature.id) !== -1) { 11226 if (typeof this._layers[i].getLatLng === 'function' && activeBounds.contains(this._layers[i].getLatLng())) { 11227 fn.call(context, this._layers[i]) 11228 } else if (typeof this._layers[i].getBounds === 'function' && activeBounds.intersects(this._layers[i].getBounds())) { 11229 fn.call(context, this._layers[i]) 11230 } 11231 } 11232 } 11233 } 11234 return this 11235 }, 11236 eachFeature: function (fn, context) { 11237 for (var i in this._layers) { 11238 fn.call(context, this._layers[i]) 11239 } 11240 return this 11241 }, 11242 getFeature: function (id) { 11243 return this._layers[id] 11244 }, 11245 bringToBack: function () { 11246 this.eachFeature(function (layer) { 11247 if (layer.bringToBack) { 11248 layer.bringToBack() 11249 } 11250 }) 11251 }, 11252 bringToFront: function () { 11253 this.eachFeature(function (layer) { 11254 if (layer.bringToFront) { 11255 layer.bringToFront() 11256 } 11257 }) 11258 }, 11259 redraw: function (id) { 11260 if (id) { 11261 this._redraw(id) 11262 } 11263 return this 11264 }, 11265 _redraw: function (id) { 11266 var layer = this._layers[id]; 11267 var geojson = layer.feature; 11268 if (layer && layer.setIcon && this.options.pointToLayer) { 11269 if (this.options.pointToLayer) { 11270 var getIcon = this.options.pointToLayer(geojson, leaflet.latLng(geojson.geometry.coordinates[1], geojson.geometry.coordinates[0])); 11271 var updatedIcon = getIcon.options.icon; 11272 layer.setIcon(updatedIcon) 11273 } 11274 } 11275 if (layer && layer.setStyle && this.options.pointToLayer) { 11276 var getStyle = this.options.pointToLayer(geojson, leaflet.latLng(geojson.geometry.coordinates[1], geojson.geometry.coordinates[0])); 11277 var updatedStyle = getStyle.options; 11278 this.setFeatureStyle(geojson.id, updatedStyle) 11279 } 11280 if (layer && layer.setStyle && this.options.style) { 11281 this.resetStyle(geojson.id) 11282 } 11283 } 11284 }); 11285 function featureLayer(options) { 11286 return new FeatureLayer(options) 11287 } 11288 exports.VERSION = version;
11289 exports.Support = Support; 11290 exports.options = options; 11291 exports.Util = EsriUtil; 11292 exports.get = get; 11293 exports.post = xmlHttpPost; 11294 exports.request = request; 11295 exports.Task = Task; 11296 exports.task = task; 11297 exports.Query = Query; 11298 exports.query = query; 11299 exports.Find = Find; 11300 exports.find = find; 11301 exports.Identify = Identify; 11302 exports.identify = identify; 11303 exports.IdentifyFeatures = IdentifyFeatures; 11304 exports.identifyFeatures = identifyFeatures; 11305 exports.IdentifyImage = IdentifyImage; 11306 exports.identifyImage = identifyImage; 11307 exports.Service = Service; 11308 exports.service = service; 11309 exports.MapService = MapService; 11310 exports.mapService = mapService; 11311 exports.ImageService = ImageService; 11312 exports.imageService = imageService; 11313 exports.FeatureLayerService = FeatureLayerService; 11314 exports.featureLayerService = featureLayerService; 11315 exports.BasemapLayer = BasemapLayer; 11316 exports.basemapLayer = basemapLayer; 11317 exports.TiledMapLayer = TiledMapLayer; 11318 exports.tiledMapLayer = tiledMapLayer; 11319 exports.RasterLayer = RasterLayer; 11320 exports.ImageMapLayer = ImageMapLayer; 11321 exports.imageMapLayer = imageMapLayer; 11322 exports.DynamicMapLayer = DynamicMapLayer; 11323 exports.dynamicMapLayer = dynamicMapLayer; 11324 exports.FeatureManager = FeatureManager; 11325 exports.FeatureLayer = FeatureLayer; 11326 exports.featureLayer = featureLayer; 11327 Object.defineProperty(exports, '__esModule', { 11328 value: !0 11329 }) 11330} 11331))); 11332L.drawVersion = '0.4.2'; 11333L.Draw = {}; 11334L.drawLocal = { 11335 draw: { 11336 toolbar: { 11337 actions: { 11338 title: 'Ø§ÙØµØ±Ø§Ù', 11339 text: 'Ø§ÙØµØ±Ø§Ù' 11340 }, 11341 finish: { 11342 title: 'Ù¾Ø§ÛØ§Ù', 11343 text: 'Ù¾Ø§ÛØ§Ù' 11344 }, 11345 undo: { 11346 title: 'ØØ°Ù آخرÛÙ ÙÙØ·Ù', 11347 text: 'ØØ°Ù آخرÛÙ ÙÙØ·Ù' 11348 }, 11349 buttons: { 11350 polyline: 'ترسÛ٠خط', 11351 polygon: 'ترسÛÙ ÚÙØ¯ Ø¶ÙØ¹Û', 11352 rectangle: 'ترسÛ٠٠ستطÛÙ', 11353 circle: 'ترسÛÙ Ø¯Ø§ÛØ±Ù', 11354 marker: 'ترسÛÙ ÙÙØ·Ù', 11355 circlemarker: 'ترسÛÙ ÙÙØ·Ù Ø¯Ø§ÛØ±Ù' 11356 } 11357 }, 11358 handlers: { 11359 circle: { 11360 tooltip: { 11361 start: 'شعاع Ø¯Ø§ÛØ±Ù را ترسÛÙ Ú©Ù' 11362 }, 11363 radius: 'شعاع' 11364 }, 11365 circlemarker: { 11366 tooltip: { 11367 start: 'رÙÛ ÙÙØ´Ù Ú©ÙÛÚ© Ú©Ù' 11368 } 11369 }, 11370 marker: { 11371 tooltip: { 11372 start: 'رÙÛ ÙÙØ´Ù Ú©ÙÛÚ© Ú©Ù' 11373 } 11374 }, 11375 polygon: { 11376 tooltip: { 11377 start: 'رÙÛ ÙÙØ´Ù Ú©ÙÛÚ© Ú©Ù', 11378 cont: 'Ø¬ÙØª ادا٠٠ترسÛÙ Ú©ÙÛÚ© Ú©Ù', 11379 end: 'Ú©ÙÛÚ© رÙÛ ÙÙØ·Ù اÙ٠٠بست٠ÚÙØ¯ Ø¶ÙØ¹Û' 11380 } 11381 }, 11382 polyline: { 11383 error: '<strong>Ù Ø´Ú©Ù:</strong> Ø®Ø·ÙØ· Ø¨Ù Ø¯Ø±Ø³ØªÛ ÛØ±Ø³ÛÙ ÙØ´Ø¯!', 11384 tooltip: { 11385 start: 'رÙÛ ÙÙØ´Ù Ú©ÙÛÚ© Ú©Ù', 11386 cont: 'Ø¬ÙØª ادا٠٠ترسÛÙ Ú©ÙÛÚ© Ú©Ù', 11387 end: 'Ú©ÙÛÚ© رÙÛ ÙÙØ·Ù آخر ٠بست٠ÚÙØ¯ Ø¶ÙØ¹Û' 11388 } 11389 }, 11390 rectangle: { 11391 tooltip: { 11392 start: 'Ú©ÙÛÚ© ک٠٠٠ستطÛ٠را ترسÛÙ Ú©Ù' 11393 } 11394 }, 11395 simpleshape: { 11396 tooltip: { 11397 end: 'Ø¨Ø±Ø§Û Ù¾Ø§ÛØ§Ù ترسÛÙ ÙÙØ´Ù را Ø±ÙØ§ Ú©Ù' 11398 } 11399 } 11400 } 11401 }, 11402 edit: { 11403 toolbar: { 11404 actions: { 11405 save: { 11406 title: 'Ø°Ø®ÛØ±Ù', 11407 text: 'Ø°Ø®ÛØ±Ù' 11408 }, 11409 cancel: { 11410 title: 'Ø§ÙØµØ±Ø§Ù ÙÛØ±Ø§ÛØ´', 11411 text: 'Ø§ÙØµØ±Ø§Ù' 11412 }, 11413 clearAll: { 11414 title: 'پاک کرد٠ÙÙ Ù ÙØ§ÛÙ', 11415 text: 'پاک کرد٠ÙÙ Ù' 11416 } 11417 }, 11418 buttons: { 11419 edit: 'ÙÛØ±Ø§ÛØ´ ÙØ§ÛÙ', 11420 editDisabled: 'ترسÛÙ Ø§ÙØ¬Ø§Ù ÙØ´Ø¯Ù', 11421 remove: 'پاک Ú©Ø±Ø¯Ù ÙØ§ÛÙ', 11422 removeDisabled: 'ترسÛÙ Ø§ÙØ¬Ø§Ù ÙØ´Ø¯Ù' 11423 } 11424 }, 11425 handlers: { 11426 edit: { 11427 tooltip: { 11428 text: 'ÙÙØ·Ù را جابجا Ú©Ù', 11429 subtext: 'Ø¨Ø±Ø§Û Ø§ÙØµØ±Ø§Ù Ø¯Ú©Ù Ù Ø§ÙØµØ±Ø§Ù را بزÙ' 11430 } 11431 }, 11432 remove: { 11433 tooltip: { 11434 text: 'Ø¨Ø±Ø§Û Ù¾Ø§Ú© کرد٠رÙÛ ÙÙØ·Ù Ú©ÙÛÚ© Ú©Ù' 11435 } 11436 } 11437 } 11438 } 11439}; 11440L.Draw.Event = {}; 11441L.Draw.Event.CREATED = 'draw:created'; 11442L.Draw.Event.EDITED = 'draw:edited'; 11443L.Draw.Event.DELETED = 'draw:deleted'; 11444L.Draw.Event.DRAWSTART = 'draw:drawstart'; 11445L.Draw.Event.DRAWSTOP = 'draw:drawstop'; 11446L.Draw.Event.DRAWVERTEX = 'draw:drawvertex';
11447L.Draw.Event.EDITSTART = 'draw:editstart'; 11448L.Draw.Event.EDITMOVE = 'draw:editmove'; 11449L.Draw.Event.EDITRESIZE = 'draw:editresize'; 11450L.Draw.Event.EDITVERTEX = 'draw:editvertex'; 11451L.Draw.Event.EDITSTOP = 'draw:editstop'; 11452L.Draw.Event.DELETESTART = 'draw:deletestart'; 11453L.Draw.Event.DELETESTOP = 'draw:deletestop'; 11454L.Draw.Event.TOOLBAROPENED = 'draw:toolbaropened'; 11455L.Draw.Event.TOOLBARCLOSED = 'draw:toolbarclosed'; 11456L.Draw.Event.MARKERCONTEXT = 'draw:markercontext'; 11457L.Toolbar = L.Class.extend({ 11458 initialize: function (options) { 11459 L.setOptions(this, options); 11460 this._modes = {}; 11461 this._actionButtons = []; 11462 this._activeMode = null; 11463 var version = L.version.split('.'); 11464 if (parseInt(version[0], 10) === 1 && parseInt(version[1], 10) >= 2) { 11465 L.Toolbar.include(L.Evented.prototype) 11466 } else { 11467 L.Toolbar.include(L.Mixin.Events) 11468 } 11469 }, 11470 enabled: function () { 11471 return this._activeMode !== null 11472 }, 11473 disable: function () { 11474 if (!this.enabled()) { 11475 return 11476 } 11477 this._activeMode.handler.disable() 11478 }, 11479 addToolbar: function (map) { 11480 var container = L.DomUtil.create('div', 'leaflet-draw-section'), buttonIndex = 0, buttonClassPrefix = this._toolbarClass || '', modeHandlers = this.getModeHandlers(map), i; 11481 this._toolbarContainer = L.DomUtil.create('div', 'leaflet-draw-toolbar leaflet-bar'); 11482 this._map = map; 11483 for (i = 0; i < modeHandlers.length; i++) { 11484 if (modeHandlers[i].enabled) { 11485 this._initModeHandler(modeHandlers[i].handler, this._toolbarContainer, buttonIndex++, buttonClassPrefix, modeHandlers[i].title) 11486 } 11487 } 11488 if (!buttonIndex) { 11489 return 11490 } 11491 this._lastButtonIndex = --buttonIndex; 11492 this._actionsContainer = L.DomUtil.create('ul', 'leaflet-draw-actions'); 11493 container.appendChild(this._toolbarContainer); 11494 container.appendChild(this._actionsContainer); 11495 return container 11496 }, 11497 removeToolbar: function () { 11498 for (var handlerId in this._modes) { 11499 if (this._modes.hasOwnProperty(handlerId)) { 11500 this._disposeButton(this._modes[handlerId].button, this._modes[handlerId].handler.enable, this._modes[handlerId].handler); 11501 this._modes[handlerId].handler.disable(); 11502 this._modes[handlerId].handler.off('enabled', this._handlerActivated, this).off('disabled', this._handlerDeactivated, this) 11503 } 11504 } 11505 this._modes = {}; 11506 for (var i = 0, l = this._actionButtons.length; i < l; i++) { 11507 this._disposeButton(this._actionButtons[i].button, this._actionButtons[i].callback, this) 11508 } 11509 this._actionButtons = []; 11510 this._actionsContainer = null 11511 }, 11512 _initModeHandler: function (handler, container, buttonIndex, classNamePredix, buttonTitle) { 11513 var type = handler.type; 11514 this._modes[type] = {}; 11515 this._modes[type].handler = handler; 11516 this._modes[type].button = this._createButton({ 11517 type: type, 11518 title: buttonTitle, 11519 className: classNamePredix + '-' + type, 11520 container: container, 11521 callback: this._modes[type].handler.enable, 11522 context: this._modes[type].handler 11523 }); 11524 this._modes[type].buttonIndex = buttonIndex; 11525 this._modes[type].handler.on('enabled', this._handlerActivated, this).on('disabled', this._handlerDeactivated, this) 11526 }, 11527 _detectIOS: function () { 11528 var iOS = (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream); 11529 return iOS 11530 }, 11531 _createButton: function (options) { 11532 var link = L.DomUtil.create('a', options.className || '', options.container); 11533 var sr = L.DomUtil.create('span', 'sr-only', options.container); 11534 link.href = '#'; 11535 link.appendChild(sr); 11536 if (options.title) { 11537 link.title = options.title; 11538 sr.innerHTML = options.title 11539 } 11540 if (options.text) { 11541 link.innerHTML = options.text; 11542 sr.innerHTML = options.text 11543 } 11544 var buttonEvent = this._detectIOS() ? 'touchstart' : 'click'; 11545 L.DomEvent.on(link, 'click', L.DomEvent.stopPropagation).on(link, 'mousedown', L.DomEvent.stopPropagation).on(link, 'dblclick', L.DomEvent.stopPropagation).on(link, 'touchstart', L.DomEvent.stopPropagation).on(link, 'click', L.DomEvent.preventDefault).on(link, buttonEvent, options.callback, options.context); 11546 return link 11547 }, 11548 _disposeButton: function (button, callback) { 11549 var buttonEvent = this._detectIOS() ? 'touchstart' : 'click'; 11550 L.DomEvent.off(button, 'click', L.DomEvent.stopPropagation).off(button, 'mousedown', L.DomEvent.stopPropagation).off(button, 'dblclick', L.DomEvent.stopPropagation).off(button, 'touchstart', L.DomEvent.stopPropagation).off(button, 'click', L.DomEvent.preventDefault).off(button, buttonEvent, callback) 11551 }, 11552 _handlerActivated: function (e) { 11553 this.disable(); 11554 this._activeMode = this._modes[e.handler]; 11555 L.DomUtil.addClass(this._activeMode.button, 'leaflet-draw-toolbar-button-enabled'); 11556 this._showActionsToolbar(); 11557 this.fire('enable') 11558 }, 11559 _handlerDeactivated: function () { 11560 this._hideActionsToolbar(); 11561 L.DomUtil.removeClass(this._activeMode.button, 'leaflet-draw-toolbar-button-enabled'); 11562 this._activeMode = null; 11563 this.fire('disable') 11564 }, 11565 _createActions: function (handler) { 11566 var container = this._actionsContainer, buttons = this.getActions(handler), l = buttons.length, li, di, dl, button; 11567 for (di = 0, 11568 dl = this._actionButtons.length; di < dl; di++) { 11569 this._disposeButton(this._actionButtons[di].button, this._actionButtons[di].callback) 11570 } 11571 this._actionButtons = []; 11572 while (container.firstChild) { 11573 container.removeChild(container.firstChild) 11574 } 11575 for (var i = 0; i < l; i++) { 11576 if ('enabled' in buttons[i] && !buttons[i].enabled) { 11577 continue 11578 } 11579 li = L.DomUtil.create('li', '', container); 11580 button = this._createButton({ 11581 title: buttons[i].title, 11582 text: buttons[i].text, 11583 container: li, 11584 callback: buttons[i].callback, 11585 context: buttons[i].context 11586 }); 11587 this._actionButtons.push({ 11588 button: button, 11589 callback: buttons[i].callback 11590 }) 11591 } 11592 }, 11593 _showActionsToolbar: function () { 11594 var buttonIndex = this._activeMode.buttonIndex 11595 , lastButtonIndex = this._lastButtonIndex 11596 , toolbarPosition = this._activeMode.button.offsetTop - 1; 11597 this._createActions(this._activeMode.handler); 11598 this._actionsContainer.style.top = toolbarPosition + 'px'; 11599 if (buttonIndex === 0) { 11600 L.DomUtil.addClass(this._toolbarContainer, 'leaflet-draw-toolbar-notop'); 11601 L.DomUtil.addClass(this._actionsContainer, 'leaflet-draw-actions-top') 11602 } 11603 if (buttonIndex === lastButtonIndex) { 11604 L.DomUtil.addClass(this._toolbarContainer, 'leaflet-draw-toolbar-nobottom'); 11605 L.DomUtil.addClass(this._actionsContainer, 'leaflet-draw-actions-bottom') 11606 } 11607 this._actionsContainer.style.display = 'block'; 11608 this._map.fire(L.Draw.Event.TOOLBAROPENED) 11609 }, 11610 _hideActionsToolbar: function () { 11611 this._actionsContainer.style.display = 'none'; 11612 L.DomUtil.removeClass(this._toolbarContainer, 'leaflet-draw-toolbar-notop'); 11613 L.DomUtil.removeClass(this._toolbarContainer, 'leaflet-draw-toolbar-nobottom'); 11614 L.DomUtil.removeClass(this._actionsContainer, 'leaflet-draw-actions-top'); 11615 L.DomUtil.removeClass(this._actionsContainer, 'leaflet-draw-actions-bottom'); 11616 this._map.fire(L.Draw.Event.TOOLBARCLOSED) 11617 } 11618}); 11619L.Draw = L.Draw || {}; 11620L.Draw.Tooltip = L.Class.extend({ 11621 initialize: function (map) { 11622 this._map = map; 11623 this._popupPane = map._panes.popupPane; 11624 this._visible = !1; 11625 this._container = map.options.drawControlTooltips ? L.DomUtil.create('div', 'leaflet-draw-tooltip', this._popupPane) : null; 11626 this._singleLineLabel = !1; 11627 this._map.on('mouseout', this._onMouseOut, this) 11628 }, 11629 dispose: function () { 11630 this._map.off('mouseout', this._onMouseOut, this); 11631 if (this._container) { 11632 this._popupPane.removeChild(this._container); 11633 this._container = null 11634 } 11635 }, 11636 updateContent: function (labelText) { 11637 if (!this._container) { 11638 return this 11639 } 11640 labelText.subtext = labelText.subtext || ''; 11641 if (labelText.subtext.length === 0 && !this._singleLineLabel) { 11642 L.DomUtil.addClass(this._container, 'leaflet-draw-tooltip-single'); 11643 this._singleLineLabel = !0 11644 } else if (labelText.subtext.length > 0 && this._singleLineLabel) { 11645 L.DomUtil.removeClass(this._container, 'leaflet-draw-tooltip-single'); 11646 this._singleLineLabel = !1 11647 } 11648 this._container.innerHTML = (labelText.subtext.length > 0 ? '<span class="leaflet-draw-tooltip-subtext">' + labelText.subtext + '</span>' + '<br />' : '') + '<span>' + labelText.text + '</span>'; 11649 if (!labelText.text && !labelText.subtext) { 11650 this._visible = !1; 11651 this._container.style.visibility = 'hidden' 11652 } else { 11653 this._visible = !0; 11654 this._container.style.visibility = 'inherit' 11655 } 11656 return this 11657 }, 11658 updatePosition: function (latlng) { 11659 var pos = this._map.latLngToLayerPoint(latlng) 11660 , tooltipContainer = this._container; 11661 if (this._container) { 11662 if (this._visible) { 11663 tooltipContainer.style.visibility = 'inherit' 11664 } 11665 L.DomUtil.setPosition(tooltipContainer, pos) 11666 } 11667 return this 11668 }, 11669 showAsError: function () { 11670 if (this._container) { 11671 L.DomUtil.addClass(this._container, 'leaflet-error-draw-tooltip') 11672 } 11673 return this 11674 }, 11675 removeError: function () { 11676 if (this._container) { 11677 L.DomUtil.removeClass(this._container, 'leaflet-error-draw-tooltip') 11678 } 11679 return this 11680 }, 11681 _onMouseOut: function () { 11682 if (this._container) { 11683 this._container.style.visibility = 'hidden' 11684 } 11685 } 11686}); 11687L.leafletDrawItems = L.Control.extend({ 11688 options: { 11689 position: 'topleft', 11690 draw: { 11691 rectangle: !1, 11692 circlemarker: !1 11693 }, 11694 edit: !1 11695 }, 11696 initialize: function (options) { 11697 if (L.version < '0.7') { 11698 throw new Error('leaflet.draw 0.2.3+ requires leaflet 0.7.0+. Download latest from https://github.com/leaflet/leaflet/') 11699 } 11700 L.Control.prototype.initialize.call(this, options); 11701 var toolbar; 11702 this._toolbars = {}; 11703 if (L.DrawToolbar && this.options.draw) { 11704 toolbar = new L.DrawToolbar(this.options.draw);
11705 this._toolbars[L.DrawToolbar.TYPE] = toolbar; 11706 this._toolbars[L.DrawToolbar.TYPE].on('enable', this._toolbarEnabled, this) 11707 } 11708 if (L.EditToolbar && this.options.edit) { 11709 toolbar = new L.EditToolbar(this.options.edit); 11710 this._toolbars[L.EditToolbar.TYPE] = toolbar; 11711 this._toolbars[L.EditToolbar.TYPE].on('enable', this._toolbarEnabled, this) 11712 } 11713 L.toolbar = this 11714 }, 11715 onAdd: function (map) { 11716 var container = L.DomUtil.create('div', 'leaflet-draw'), addedTopClass = !1, topClassName = 'leaflet-draw-toolbar-top', toolbarContainer; 11717 for (var toolbarId in this._toolbars) { 11718 if (this._toolbars.hasOwnProperty(toolbarId)) { 11719 toolbarContainer = this._toolbars[toolbarId].addToolbar(map); 11720 if (toolbarContainer) { 11721 if (!addedTopClass) { 11722 if (!L.DomUtil.hasClass(toolbarContainer, topClassName)) { 11723 L.DomUtil.addClass(toolbarContainer.childNodes[0], topClassName) 11724 } 11725 addedTopClass = !0 11726 } 11727 container.appendChild(toolbarContainer) 11728 } 11729 } 11730 } 11731 return container 11732 }, 11733 onRemove: function () { 11734 for (var toolbarId in this._toolbars) { 11735 if (this._toolbars.hasOwnProperty(toolbarId)) { 11736 this._toolbars[toolbarId].removeToolbar() 11737 } 11738 } 11739 }, 11740 setDrawingOptions: function (options) { 11741 for (var toolbarId in this._toolbars) { 11742 if (this._toolbars[toolbarId] instanceof L.DrawToolbar) { 11743 this._toolbars[toolbarId].setOptions(options) 11744 } 11745 } 11746 }, 11747 _toolbarEnabled: function (e) { 11748 var enabledToolbar = e.target; 11749 for (var toolbarId in this._toolbars) { 11750 if (this._toolbars[toolbarId] !== enabledToolbar) { 11751 this._toolbars[toolbarId].disable() 11752 } 11753 } 11754 } 11755}); 11756L.Map.mergeOptions({ 11757 drawControlTooltips: !0, 11758 drawControl: !1 11759}); 11760L.Map.addInitHook(function () { 11761 if (this.options.drawControl) { 11762 this.drawControl = new L.leafletDrawItems();
11763 this.addControl(this.drawControl) 11764 } 11765}); 11766(function () { 11767 var defaultPrecision = { 11768 km: 2, 11769 ha: 2, 11770 m: 0, 11771 mi: 2, 11772 ac: 2, 11773 yd: 0, 11774 ft: 0, 11775 nm: 2 11776 }; 11777 L.GeometryUtil = L.extend(L.GeometryUtil || {}, { 11778 geodesicArea: function (latLngs) { 11779 var pointsCount = latLngs.length, area = 0.0, d2r = Math.PI / 180, p1, p2; 11780 if (pointsCount > 2) { 11781 for (var i = 0; i < pointsCount; i++) { 11782 p1 = latLngs[i]; 11783 p2 = latLngs[(i + 1) % pointsCount]; 11784 area += ((p2.lng - p1.lng) * d2r) * (2 + Math.sin(p1.lat * d2r) + Math.sin(p2.lat * d2r)) 11785 } 11786 area = area * 6378137.0 * 6378137.0 / 2.0 11787 } 11788 return Math.abs(area) 11789 }, 11790 formattedNumber: function (n, precision) { 11791 var formatted = parseFloat(n).toFixed(precision) 11792 , format = L.drawLocal.format && L.drawLocal.format.numeric 11793 , delimiters = format && format.delimiters 11794 , thousands = delimiters && delimiters.thousands 11795 , decimal = delimiters && delimiters.decimal; 11796 if (thousands || decimal) { 11797 var splitValue = formatted.split('.'); 11798 formatted = thousands ? splitValue[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + thousands) : splitValue[0]; 11799 decimal = decimal || '.'; 11800 if (splitValue.length > 1) { 11801 formatted = formatted + decimal + splitValue[1] 11802 } 11803 } 11804 return formatted 11805 }, 11806 readableArea: function (area, isMetric, precision) { 11807 var areaStr, units, precision = L.Util.extend({}, defaultPrecision, precision); 11808 if (isMetric) { 11809 units = ['ha', 'm']; 11810 type = typeof isMetric; 11811 if (type === 'string') { 11812 units = [isMetric] 11813 } else if (type !== 'boolean') { 11814 units = isMetric 11815 } 11816 if (area >= 1000000 && units.indexOf('km') !== -1) { 11817 areaStr = L.GeometryUtil.formattedNumber(area * 0.000001, precision.km) + ' km
11817²' 11818 } else if (area >= 10000 && units.indexOf('ha') !== -1) { 11819 areaStr = L.GeometryUtil.formattedNumber(area * 0.0001, precision.ha) + ' ha' 11820 } else { 11821 areaStr = L.GeometryUtil.formattedNumber(area, precision.m) + ' m²' 11822 } 11823 } else { 11824 area /= 0.836127; 11825 if (area >= 3097600) { 11826 areaStr = L.GeometryUtil.formattedNumber(area / 3097600, precision.mi) + ' mi²' 11827 } else if (area >= 4840) { 11828 areaStr = L.GeometryUtil.formattedNumber(area / 4840, precision.ac) + ' acres' 11829 } else { 11830 areaStr = L.GeometryUtil.formattedNumber(area, precision.yd) + ' yd²' 11831 } 11832 } 11833 return areaStr 11834 }, 11835 readableDistance: function (distance, isMetric, isFeet, isNauticalMile, precision) { 11836 var distanceStr, units, precision = L.Util.extend({}, defaultPrecision, precision); 11837 if (isMetric) { 11838 units = typeof isMetric == 'string' ? isMetric : 'metric' 11839 } else if (isFeet) { 11840 units = 'feet' 11841 } else if (isNauticalMile) { 11842 units = 'nauticalMile' 11843 } else { 11844 units = 'yards' 11845 } 11846 switch (units) { 11847 case 'metric': 11848 if (distance > 1000) { 11849 distanceStr = L.GeometryUtil.formattedNumber(distance / 1000, precision.km) + ' km' 11850 } else { 11851 distanceStr = L.GeometryUtil.formattedNumber(distance, precision.m) + ' m' 11852 } 11853 break; 11854 case 'feet': 11855 distance *= 1.09361 * 3; 11856 distanceStr = L.GeometryUtil.formattedNumber(distance, precision.ft) + ' ft'; 11857 break; 11858 case 'nauticalMile': 11859 distance *= 0.53996; 11860 distanceStr = L.GeometryUtil.formattedNumber(distance / 1000, precision.nm) + ' nm'; 11861 break; 11862 case 'yards': 11863 default: 11864 distance *= 1.09361; 11865 if (distance > 1760) { 11866 distanceStr = L.GeometryUtil.formattedNumber(distance / 1760, precision.mi) + ' miles' 11867 } else { 11868 distanceStr = L.GeometryUtil.formattedNumber(distance, precision.yd) + ' yd' 11869 } 11870 break 11871 } 11872 return distanceStr 11873 }, 11874 isVersion07x: function () { 11875 var version = L.version.split('.'); 11876 return parseInt(version[0], 10) === 0 && parseInt(version[1], 10) === 7 11877 }, 11878 }) 11879} 11880)(); 11881L.LatLngUtil = { 11882 cloneLatLngs: function (latlngs) { 11883 var clone = []; 11884 for (var i = 0, l = latlngs.length; i < l; i++) { 11885 if (Array.isArray(latlngs[i])) { 11886 clone.push(L.LatLngUtil.cloneLatLngs(latlngs[i])) 11887 } else { 11888 clone.push(this.cloneLatLng(latlngs[i])) 11889 } 11890 } 11891 return clone 11892 }, 11893 cloneLatLng: function (latlng) { 11894 return L.latLng(latlng.lat, latlng.lng) 11895 } 11896}; 11897L.Util.extend(L.LineUtil, { 11898 segmentsIntersect: function (p, p1, p2, p3) { 11899 return this._checkCounterclockwise(p, p2, p3) !== this._checkCounterclockwise(p1, p2, p3) && this._checkCounterclockwise(p, p1, p2) !== this._checkCounterclockwise(p, p1, p3) 11900 }, 11901 _checkCounterclockwise: function (p, p1, p2) { 11902 return (p2.y - p.y) * (p1.x - p.x) > (p1.y - p.y) * (p2.x - p.x) 11903 } 11904}); 11905L.Polygon.include({ 11906 intersects: function () { 11907 var polylineIntersects, points = this._getProjectedPoints(), len, firstPoint, lastPoint, maxIndex; 11908 if (this._tooFewPointsForIntersection()) { 11909 return !1 11910 } 11911 polylineIntersects = L.Polyline.prototype.intersects.call(this); 11912 if (polylineIntersects) { 11913 return !0 11914 } 11915 len = points.length; 11916 firstPoint = points[0]; 11917 lastPoint = points[len - 1]; 11918 maxIndex = len - 2; 11919 return this._lineSegmentsIntersectsRange(lastPoint, firstPoint, maxIndex, 1) 11920 } 11921}); 11922L.Polyline.include({ 11923 intersects: function () { 11924 var points = this._getProjectedPoints(), len = points ? points.length : 0, i, p, p1; 11925 if (this._tooFewPointsForIntersection()) { 11926 return !1 11927 } 11928 for (i = len - 1; i >= 3; i--) { 11929 p = points[i - 1]; 11930 p1 = points[i]; 11931 if (this._lineSegmentsIntersectsRange(p, p1, i - 2)) { 11932 return !0 11933 } 11934 } 11935 return !1 11936 }, 11937 newLatLngIntersects: function (latlng, skipFirst) { 11938 if (!this._map) { 11939 return !1 11940 } 11941 return this.newPointIntersects(this._map.latLngToLayerPoint(latlng), skipFirst) 11942 }, 11943 newPointIntersects: function (newPoint, skipFirst) { 11944 var points = this._getProjectedPoints() 11945 , len = points ? points.length : 0 11946 , lastPoint = points ? points[len - 1] : null 11947 , maxIndex = len - 2; 11948 if (this._tooFewPointsForIntersection(1)) { 11949 return !1 11950 } 11951 return this._lineSegmentsIntersectsRange(lastPoint, newPoint, maxIndex, skipFirst ? 1 : 0) 11952 }, 11953 _tooFewPointsForIntersection: function (extraPoints) { 11954 var points = this._getProjectedPoints() 11955 , len = points ? points.length : 0; 11956 len += extraPoints || 0; 11957 return !points || len <= 3 11958 }, 11959 _lineSegmentsIntersectsRange: function (p, p1, maxIndex, minIndex) { 11960 var points = this._getProjectedPoints(), p2, p3; 11961 minIndex = minIndex || 0; 11962 for (var j = maxIndex; j > minIndex; j--) { 11963 p2 = points[j - 1]; 11964 p3 = points[j];
11965 if (L.LineUtil.segmentsIntersect(p, p1, p2, p3)) { 11966 return !0 11967 } 11968 } 11969 return !1 11970 }, 11971 _getProjectedPoints: function () { 11972 if (!this._defaultShape) { 11973 return this._originalPoints 11974 } 11975 var points = [] 11976 , _shape = this._defaultShape(); 11977 for (var i = 0; i < _shape.length; i++) { 11978 points.push(this._map.latLngToLayerPoint(_shape[i])) 11979 } 11980 return points 11981 } 11982}); 11983L.Map.mergeOptions({ 11984 touchExtend: !0 11985}); 11986L.Map.TouchExtend = L.Handler.extend({ 11987 initialize: function (map) { 11988 this._map = map; 11989 this._container = map._container; 11990 this._pane = map._panes.overlayPane 11991 }, 11992 addHooks: function () { 11993 L.DomEvent.on(this._container, 'touchstart', this._onTouchStart, this); 11994 L.DomEvent.on(this._container, 'touchend', this._onTouchEnd, this); 11995 L.DomEvent.on(this._container, 'touchmove', this._onTouchMove, this); 11996 if (this._detectIE()) { 11997 L.DomEvent.on(this._container, 'MSPointerDown', this._onTouchStart, this); 11998 L.DomEvent.on(this._container, 'MSPointerUp', this._onTouchEnd, this); 11999 L.DomEvent.on(this._container, 'MSPointerMove', this._onTouchMove, this); 12000 L.DomEvent.on(this._container, 'MSPointerCancel', this._onTouchCancel, this) 12001 } else { 12002 L.DomEvent.on(this._container, 'touchcancel', this._onTouchCancel, this); 12003 L.DomEvent.on(this._container, 'touchleave', this._onTouchLeave, this) 12004 } 12005 }, 12006 removeHooks: function () { 12007 L.DomEvent.off(this._container, 'touchstart', this._onTouchStart, this); 12008 L.DomEvent.off(this._container, 'touchend', this._onTouchEnd, this); 12009 L.DomEvent.off(this._container, 'touchmove', this._onTouchMove, this); 12010 if (this._detectIE()) { 12011 L.DomEvent.off(this._container, 'MSPointerDown', this._onTouchStart, this); 12012 L.DomEvent.off(this._container, 'MSPointerUp', this._onTouchEnd, this); 12013 L.DomEvent.off(this._container, 'MSPointerMove', this._onTouchMove, this); 12014 L.DomEvent.off(this._container, 'MSPointerCancel', this._onTouchCancel, this) 12015 } else { 12016 L.DomEvent.off(this._container, 'touchcancel', this._onTouchCancel, this); 12017 L.DomEvent.off(this._container, 'touchleave', this._onTouchLeave, this) 12018 } 12019 }, 12020 _touchEvent: function (e, type) { 12021 var touchEvent = {}; 12022 if (typeof e.touches !== 'undefined') { 12023 if (!e.touches.length) { 12024 return 12025 } 12026 touchEvent = e.touches[0] 12027 } else if (e.pointerType === 'touch') { 12028 touchEvent = e; 12029 if (!this._filterClick(e)) { 12030 return 12031 } 12032 } else { 12033 return 12034 } 12035 var containerPoint = this._map.mouseEventToContainerPoint(touchEvent) 12036 , layerPoint = this._map.mouseEventToLayerPoint(touchEvent) 12037 , latlng = this._map.layerPointToLatLng(layerPoint); 12038 this._map.fire(type, { 12039 latlng: latlng, 12040 layerPoint: layerPoint, 12041 containerPoint: containerPoint, 12042 pageX: touchEvent.pageX, 12043 pageY: touchEvent.pageY, 12044 originalEvent: e 12045 }) 12046 }, 12047 _filterClick: function (e) { 12048 var timeStamp = (e.timeStamp || e.originalEvent.timeStamp) 12049 , elapsed = L.DomEvent._lastClick && (timeStamp - L.DomEvent._lastClick); 12050 if ((elapsed && elapsed > 100 && elapsed < 500) || (e.target._simulatedClick && !e._simulated)) { 12051 L.DomEvent.stop(e); 12052 return !1 12053 } 12054 L.DomEvent._lastClick = timeStamp; 12055 return !0 12056 }, 12057 _onTouchStart: function (e) { 12058 if (!this._map._loaded) { 12059 return 12060 } 12061 var type = 'touchstart';
12062 this._touchEvent(e, type) 12063 }, 12064 _onTouchEnd: function (e) { 12065 if (!this._map._loaded) { 12066 return 12067 } 12068 var type = 'touchend'; 12069 this._touchEvent(e, type) 12070 }, 12071 _onTouchCancel: function (e) { 12072 if (!this._map._loaded) { 12073 return 12074 } 12075 var type = 'touchcancel'; 12076 if (this._detectIE()) { 12077 type = 'pointercancel' 12078 } 12079 this._touchEvent(e, type) 12080 }, 12081 _onTouchLeave: function (e) { 12082 if (!this._map._loaded) { 12083 return 12084 } 12085 var type = 'touchleave'; 12086 this._touchEvent(e, type) 12087 }, 12088 _onTouchMove: function (e) { 12089 if (!this._map._loaded) { 12090 return 12091 } 12092 var type = 'touchmove'; 12093 this._touchEvent(e, type) 12094 }, 12095 _detectIE: function () { 12096 var ua = window.navigator.userAgent; 12097 var msie = ua.indexOf('MSIE '); 12098 if (msie > 0) { 12099 return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10) 12100 } 12101 var trident = ua.indexOf('Trident/'); 12102 if (trident > 0) { 12103 var rv = ua.indexOf('rv:'); 12104 return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10) 12105 } 12106 var edge = ua.indexOf('Edge/'); 12107 if (edge > 0) { 12108 return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10) 12109 } 12110 return !1 12111 } 12112}); 12113L.Map.addInitHook('addHandler', 'touchExtend', L.Map.TouchExtend); 12114L.Marker.Touch = L.Marker.extend({ 12115 _initInteraction: function () { 12116 if (!this.addInteractiveTarget) { 12117 return this._initInteractionLegacy() 12118 } 12119 return L.Marker.prototype._initInteraction.apply(this) 12120 }, 12121 _initInteractionLegacy: function () { 12122 if (!this.options.clickable) { 12123 return 12124 } 12125 var icon = this._icon 12126 , events = ['dblclick', 'mousedown', 'mouseover', 'mouseout', 'contextmenu', 'touchstart', 'touchend', 'touchmove']; 12127 if (this._detectIE) { 12128 events.concat(['MSPointerDown', 'MSPointerUp', 'MSPointerMove', 'MSPointerCancel']) 12129 } else { 12130 events.concat(['touchcancel']) 12131 } 12132 L.DomUtil.addClass(icon, 'leaflet-clickable'); 12133 L.DomEvent.on(icon, 'click', this._onMouseClick, this); 12134 L.DomEvent.on(icon, 'keypress', this._onKeyPress, this); 12135 for (var i = 0; i < events.length; i++) { 12136 L.DomEvent.on(icon, events[i], this._fireMouseEvent, this) 12137 } 12138 if (L.Handler.MarkerDrag) { 12139 this.dragging = new L.Handler.MarkerDrag(this); 12140 if (this.options.draggable) { 12141 this.dragging.enable() 12142 } 12143 } 12144 }, 12145 _detectIE: function () { 12146 var ua = window.navigator.userAgent; 12147 var msie = ua.indexOf('MSIE '); 12148 if (msie > 0) { 12149 return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10) 12150 } 12151 var trident = ua.indexOf('Trident/'); 12152 if (trident > 0) { 12153 var rv = ua.indexOf('rv:'); 12154 return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10) 12155 } 12156 var edge = ua.indexOf('Edge/'); 12157 if (edge > 0) { 12158 return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10) 12159 } 12160 return !1 12161 } 12162}); 12163L.DrawToolbar = L.Toolbar.extend({ 12164 statics: { 12165 TYPE: 'draw' 12166 }, 12167 options: { 12168 polyline: {}, 12169 polygon: {}, 12170 rectangle: {}, 12171 circle: {}, 12172 marker: {}, 12173 circlemarker: {} 12174 }, 12175 initialize: function (options) { 12176 for (var type in this.options) { 12177 if (this.options.hasOwnProperty(type)) { 12178 if (options[type]) { 12179 options[type] = L.extend({}, this.options[type], options[type]) 12180 } 12181 } 12182 } 12183 this._toolbarClass = 'leaflet-draw-draw'; 12184 L.Toolbar.prototype.initialize.call(this, options) 12185 }, 12186 getModeHandlers: function (map) { 12187 return [{ 12188 enabled: this.options.polyline, 12189 handler: new L.Draw.Polyline(map, this.options.polyline), 12190 title: L.drawLocal.draw.toolbar.buttons.polyline 12191 }, { 12192 enabled: this.options.polygon, 12193 handler: new L.Draw.Polygon(map, this.options.polygon), 12194 title: L.drawLocal.draw.toolbar.buttons.polygon 12195 }, { 12196 enabled: this.options.rectangle, 12197 handler: new L.Draw.Rectangle(map, this.options.rectangle), 12198 title: L.drawLocal.draw.toolbar.buttons.rectangle 12199 }, { 12200 enabled: this.options.circle, 12201 handler: new L.Draw.Circle(map, this.options.circle), 12202 title: L.drawLocal.draw.toolbar.buttons.circle 12203 }, { 12204 enabled: this.options.marker, 12205 handler: new L.Draw.Marker(map, this.options.marker), 12206 title: L.drawLocal.draw.toolbar.buttons.marker 12207 }, { 12208 enabled: this.options.circlemarker, 12209 handler: new L.Draw.CircleMarker(map, this.options.circlemarker), 12210 title: L.drawLocal.draw.toolbar.buttons.circlemarker 12211 }] 12212 }, 12213 getActions: function (handler) { 12214 return [{ 12215 enabled: handler.completeShape, 12216 title: L.drawLocal.draw.toolbar.finish.title, 12217 text: L.drawLocal.draw.toolbar.finish.text, 12218 callback: handler.completeShape, 12219 context: handler 12220 }, { 12221 enabled: handler.deleteLastVertex, 12222 title: L.drawLocal.draw.toolbar.undo.title, 12223 text: L.drawLocal.draw.toolbar.undo.text, 12224 callback: handler.deleteLastVertex, 12225 context: handler 12226 }, { 12227 title: L.drawLocal.draw.toolbar.actions.title, 12228 text: L.drawLocal.draw.toolbar.actions.text, 12229 callback: this.disable, 12230 context: this 12231 }] 12232 }, 12233 setOptions: function (options) { 12234 L.setOptions(this, options); 12235 for (var type in this._modes) { 12236 if (this._modes.hasOwnProperty(type) && options.hasOwnProperty(type)) { 12237 this._modes[type].handler.setOptions(options[type]) 12238 } 12239 } 12240 } 12241}); 12242L.Draw = L.Draw || {}; 12243L.Draw.Feature = L.Handler.extend({ 12244 initialize: function (map, options) { 12245 this._map = map; 12246 this._container = map._container; 12247 this._overlayPane = map._panes.overlayPane; 12248 this._popupPane = map._panes.popupPane; 12249 if (options && options.shapeOptions) { 12250 options.shapeOptions = L.Util.extend({}, this.options.shapeOptions, options.shapeOptions) 12251 } 12252 L.setOptions(this, options); 12253 var version = L.version.split('.'); 12254 if (parseInt(version[0], 10) === 1 && parseInt(version[1], 10) >= 2) { 12255 L.Draw.Feature.include(L.Evented.prototype) 12256 } else { 12257 L.Draw.Feature.include(L.Mixin.Events) 12258 } 12259 }, 12260 enable: function () { 12261 if (this._enabled) { 12262 return 12263 } 12264 L.Handler.prototype.enable.call(this); 12265 this.fire('enabled', { 12266 handler: this.type 12267 });
12268 this._map.fire(L.Draw.Event.DRAWSTART, { 12269 layerType: this.type 12270 }) 12271 }, 12272 disable: function () { 12273 if (!this._enabled) { 12274 return 12275 } 12276 L.Handler.prototype.disable.call(this); 12277 this._map.fire(L.Draw.Event.DRAWSTOP, { 12278 layerType: this.type 12279 }); 12280 this.fire('disabled', { 12281 handler: this.type 12282 }) 12283 }, 12284 addHooks: function () { 12285 var map = this._map; 12286 if (map) { 12287 L.DomUtil.disableTextSelection(); 12288 map.getContainer().focus(); 12289 this._tooltip = new L.Draw.Tooltip(this._map); 12290 L.DomEvent.on(this._container, 'keyup', this._cancelDrawing, this) 12291 } 12292 }, 12293 removeHooks: function () { 12294 if (this._map) { 12295 L.DomUtil.enableTextSelection(); 12296 this._tooltip.dispose(); 12297 this._tooltip = null; 12298 L.DomEvent.off(this._container, 'keyup', this._cancelDrawing, this) 12299 } 12300 }, 12301 setOptions: function (options) { 12302 L.setOptions(this, options) 12303 }, 12304 _fireCreatedEvent: function (layer) { 12305 this._map.fire(L.Draw.Event.CREATED, { 12306 layer: layer, 12307 layerType: this.type 12308 }) 12309 }, 12310 _cancelDrawing: function (e) { 12311 if (e.keyCode === 27) { 12312 this._map.fire('draw:canceled', { 12313 layerType: this.type 12314 }); 12315 this.disable() 12316 } 12317 } 12318}); 12319L.SimpleShape = {}; 12320L.Draw.SimpleShape = L.Draw.Feature.extend({ 12321 options: { 12322 repeatMode: !1 12323 }, 12324 initialize: function (map, options) { 12325 this._endLabelText = L.drawLocal.draw.handlers.simpleshape.tooltip.end; 12326 L.Draw.Feature.prototype.initialize.call(this, map, options) 12327 }, 12328 addHooks: function () { 12329 L.Draw.Feature.prototype.addHooks.call(this); 12330 if (this._map) { 12331 this._mapDraggable = this._map.dragging.enabled(); 12332 if (this._mapDraggable) { 12333 this._map.dragging.disable() 12334 } 12335 this._container.style.cursor = 'crosshair'; 12336 this._tooltip.updateContent({ 12337 text: this._initialLabelText 12338 }); 12339 this._map.on('mousedown', this._onMouseDown, this).on('mousemove', this._onMouseMove, this).on('touchstart', this._onMouseDown, this).on('touchmove', this._onMouseMove, this); 12340 document.addEventListener('touchstart', L.DomEvent.preventDefault, { 12341 passive: !1 12342 }) 12343 } 12344 }, 12345 removeHooks: function () { 12346 L.Draw.Feature.prototype.removeHooks.call(this); 12347 if (this._map) { 12348 if (this._mapDraggable) { 12349 this._map.dragging.enable() 12350 } 12351 this._container.style.cursor = ''; 12352 this._map.off('mousedown', this._onMouseDown, this).off('mousemove', this._onMouseMove, this).off('touchstart', this._onMouseDown, this).off('touchmove', this._onMouseMove, this); 12353 L.DomEvent.off(document, 'mouseup', this._onMouseUp, this); 12354 L.DomEvent.off(document, 'touchend', this._onMouseUp, this); 12355 document.removeEventListener('touchstart', L.DomEvent.preventDefault); 12356 if (this._shape) { 12357 this._map.removeLayer(this._shape); 12358 delete this._shape 12359 } 12360 } 12361 this._isDrawing = !1 12362 }, 12363 _getTooltipText: function () { 12364 return { 12365 text: this._endLabelText 12366 } 12367 }, 12368 _onMouseDown: function (e) { 12369 this._isDrawing = !0; 12370 this._startLatLng = e.latlng; 12371 L.DomEvent.on(document, 'mouseup', this._onMouseUp, this).on(document, 'touchend', this._onMouseUp, this).preventDefault(e.originalEvent) 12372 }, 12373 _onMouseMove: function (e) { 12374 var latlng = e.latlng; 12375 this._tooltip.updatePosition(latlng); 12376 if (this._isDrawing) { 12377 this._tooltip.updateContent(this._getTooltipText()); 12378 this._drawShape(latlng) 12379 } 12380 }, 12381 _onMouseUp: function () { 12382 if (this._shape) { 12383 this._fireCreatedEvent() 12384 } 12385 this.disable(); 12386 if (this.options.repeatMode) { 12387 this.enable() 12388 } 12389 } 12390}); 12391L.Draw.Polyline = L.Draw.Feature.extend({ 12392 statics: { 12393 TYPE: 'polyline' 12394 }, 12395 Poly: L.Polyline, 12396 options: { 12397 allowIntersection: !0, 12398 repeatMode: !1, 12399 drawError: { 12400 color: '#b00b00', 12401 timeout: 2500 12402 }, 12403 icon: new L.DivIcon({ 12404 iconSize: new L.Point(8, 8), 12405 className: 'leaflet-div-icon leaflet-editing-icon' 12406 }), 12407 touchIcon: new L.DivIcon({ 12408 iconSize: new L.Point(20, 20), 12409 className: 'leaflet-div-icon leaflet-editing-icon leaflet-touch-icon' 12410 }), 12411 guidelineDistance: 20, 12412 maxGuideLineLength: 4000, 12413 shapeOptions: { 12414 stroke: !0, 12415 color: '#3388ff', 12416 weight: 4, 12417 opacity: 0.5, 12418 fill: !1, 12419 clickable: !0 12420 }, 12421 metric: !0, 12422 feet: !0, 12423 nautic: !1, 12424 showLength: !0, 12425 zIndexOffset: 2000, 12426 factor: 1, 12427 maxPoints: 0 12428 }, 12429 initialize: function (map, options) { 12430 if (L.Browser.touch) { 12431 this.options.icon = this.options.touchIcon 12432 } 12433 this.options.drawError.message = L.drawLocal.draw.handlers.pol
12433yline.error; 12434 if (options && options.drawError) { 12435 options.drawError = L.Util.extend({}, this.options.drawError, options.drawError) 12436 } 12437 this.type = L.Draw.Polyline.TYPE; 12438 L.Draw.Feature.prototype.initialize.call(this, map, options) 12439 }, 12440 addHooks: function () { 12441 L.Draw.Feature.prototype.addHooks.call(this); 12442 if (this._map) { 12443 this._markers = []; 12444 this._markerGroup = new L.LayerGroup(); 12445 this._map.addLayer(this._markerGroup); 12446 this._poly = new L.Polyline([], this.options.shapeOptions); 12447 this._tooltip.updateContent(this._getTooltipText()); 12448 if (!this._mouseMarker) { 12449 this._mouseMarker = L.marker(this._map.getCenter(), { 12450 icon: L.divIcon({ 12451 className: 'leaflet-mouse-marker', 12452 iconAnchor: [20, 20], 12453 iconSize: [40, 40] 12454 }), 12455 opacity: 0, 12456 zIndexOffset: this.options.zIndexOffset 12457 }) 12458 } 12459 this._mouseMarker.on('mouseout', this._onMouseOut, this).on('mousemove', this._onMouseMove, this).on('mousedown', this._onMouseDown, this).on('mouseup', this._onMouseUp, this).addTo(this._map); 12460 this._map.on('mouseup', this._onMouseUp, this).on('mousemove', this._onMouseMove, this).on('zoomlevelschange', this._onZoomEnd, this).on('touchstart', this._onTouch, this).on('zoomend', this._onZoomEnd, this) 12461 } 12462 }, 12463 removeHooks: function () { 12464 L.Draw.Feature.prototype.removeHooks.call(this); 12465 this._clearHideErrorTimeout(); 12466 this._cleanUpShape(); 12467 this._map.removeLayer(this._markerGroup); 12468 delete this._markerGroup; 12469 delete this._markers; 12470 this._map.removeLayer(this._poly); 12471 delete this._poly; 12472 this._mouseMarker.off('mousedown', this._onMouseDown, this).off('mouseout', this._onMouseOut, this).off('mouseup', this._onMouseUp, this).off('mousemove', this._onMouseMove, this); 12473 this._map.removeLayer(this._mouseMarker); 12474 delete this._mouseMarker; 12475 this._clearGuides(); 12476 this._map.off('mouseup', this._onMouseUp, this).off('mousemove', this._onMouseMove, this).off('zoomlevelschange', this._onZoomEnd, this).off('zoomend', this._onZoomEnd, this).off('touchstart', this._onTouch, this).off('click', this._onTouch, this) 12477 }, 12478 deleteLastVertex: function () { 12479 if (this._markers.length <= 1) { 12480 return 12481 } 12482 var lastMarker = this._markers.pop() 12483 , poly = this._poly 12484 , latlngs = poly.getLatLngs() 12485 , latlng = latlngs.splice(-1, 1)[0]; 12486 this._poly.setLatLngs(latlngs); 12487 this._markerGroup.removeLayer(lastMarker); 12488 if (poly.getLatLngs().length < 2) { 12489 this._map.removeLayer(poly) 12490 } 12491 this._vertexChanged(latlng, !1) 12492 }, 12493 addVertex: function (latlng) { 12494 var markersLength = this._markers.length; 12495 if (markersLength >= 2 && !this.options.allowIntersection && this._poly.newLatLngIntersects(latlng)) { 12496 this._showErrorTooltip(); 12497 return 12498 } else if (this._errorShown) { 12499 this._hideErrorTooltip() 12500 } 12501 this._markers.push(this._createMarker(latlng)); 12502 this._poly.addLatLng(latlng); 12503 if (this._poly.getLatLngs().length === 2) { 12504 this._map.addLayer(this._poly) 12505 } 12506 this._vertexChanged(latlng, !0) 12507 }, 12508 completeShape: function () { 12509 if (this._markers.length <= 1 || !this._shapeIsValid()) { 12510 return 12511 } 12512 this._fireCreatedEvent(); 12513 this.disable(); 12514 if (this.options.repeatMode) { 12515 this.enable() 12516 } 12517 }, 12518 _finishShape: function () { 12519 var latlngs = this._poly._defaultShape ? this._poly._defaultShape() : this._poly.getLatLngs(); 12520 var intersects = this._poly.newLatLngIntersects(latlngs[latlngs.length - 1]); 12521 if ((!this.options.allowIntersection && intersects) || !this._shapeIsValid()) { 12522 this._showErrorTooltip(); 12523 return 12524 } 12525 this._fireCreatedEvent(); 12526 this.disable(); 12527 if (this.options.repeatMode) { 12528 this.enable() 12529 } 12530 }, 12531 _shapeIsValid: function () { 12532 return !0 12533 }, 12534 _onZoomEnd: function () { 12535 if (this._markers !== null) { 12536 this._updateGuide() 12537 } 12538 }, 12539 _onMouseMove: function (e) { 12540 var newPos = this._map.mouseEventToLayerPoint(e.originalEvent); 12541 var latlng = this._map.layerPointToLatLng(newPos); 12542 this._currentLatLng = latlng; 12543 this._updateTooltip(latlng); 12544 this._updateGuide(newPos); 12545 this._mouseMarker.setLatLng(latlng); 12546 L.DomEvent.preventDefault(e.originalEvent) 12547 }, 12548 _vertexChanged: function (latlng, added) { 12549 this._map.fire(L.Draw.Event.DRAWVERTEX, { 12550 layers: this._markerGroup 12551 });
12552 this._updateFinishHandler(); 12553 this._updateRunningMeasure(latlng, added); 12554 this._clearGuides(); 12555 this._updateTooltip() 12556 }, 12557 _onMouseDown: function (e) { 12558 if (!this._clickHandled && !this._touchHandled && !this._disableMarkers) { 12559 this._onMouseMove(e); 12560 this._clickHandled = !0; 12561 this._disableNewMarkers(); 12562 var originalEvent = e.originalEvent; 12563 var clientX = originalEvent.clientX; 12564 var clientY = originalEvent.clientY; 12565 this._startPoint.call(this, clientX, clientY) 12566 } 12567 }, 12568 _startPoint: function (clientX, clientY) { 12569 this._mouseDownOrigin = L.point(clientX, clientY) 12570 }, 12571 _onMouseUp: function (e) { 12572 var originalEvent = e.originalEvent; 12573 var clientX = originalEvent.clientX; 12574 var clientY = originalEvent.clientY; 12575 this._endPoint.call(this, clientX, clientY, e); 12576 this._clickHandled = null 12577 }, 12578 _endPoint: function (clientX, clientY, e) { 12579 if (this._mouseDownOrigin) { 12580 var dragCheckDistance = L.point(clientX, clientY).distanceTo(this._mouseDownOrigin); 12581 var lastPtDistance = this._calculateFinishDistance(e.latlng); 12582 if (this.options.maxPoints > 1 && this.options.maxPoints == this._markers.length + 1) { 12583 this.addVertex(e.latlng); 12584 this._finishShape() 12585 } else if (lastPtDistance < 10 && L.Browser.touch) { 12586 this._finishShape() 12587 } else if (Math.abs(dragCheckDistance) < 9 * (window.devicePixelRatio || 1)) { 12588 this.addVertex(e.latlng) 12589 } 12590 this._enableNewMarkers() 12591 } 12592 this._mouseDownOrigin = null 12593 }, 12594 _onTouch: function (e) { 12595 var originalEvent = e.originalEvent; 12596 var clientX; 12597 var clientY; 12598 if (originalEvent.touches && originalEvent.touches[0] && !this._clickHandled && !this._touchHandled && !this._disableMarkers) { 12599 clientX = originalEvent.touches[0].clientX; 12600 clientY = originalEvent.touches[0].clientY; 12601 this._disableNewMarkers(); 12602 this._touchHandled = !0; 12603 this._startPoint.call(this, clientX, clientY); 12604 this._endPoint.call(this, clientX, clientY, e); 12605 this._touchHandled = null 12606 } 12607 this._clickHandled = null 12608 }, 12609 _onMouseOut: function () { 12610 if (this._tooltip) { 12611 this._tooltip._onMouseOut.call(this._tooltip) 12612 } 12613 }, 12614 _calculateFinishDistance: function (potentialLatLng) { 12615 var lastPtDistance; 12616 if (this._markers.length > 0) { 12617 var finishMarker; 12618 if (this.type === L.Draw.Polyline.TYPE) { 12619 finishMarker = this._markers[this._markers.length - 1] 12620 } else if (this.type === L.Draw.Polygon.TYPE) { 12621 finishMarker = this._markers[0] 12622 } else { 12623 return Infinity 12624 } 12625 var lastMarkerPoint = this._map.latLngToContainerPoint(finishMarker.getLatLng()) 12626 , potentialMarker = new L.Marker(potentialLatLng, { 12627 icon: this.options.icon, 12628 zIndexOffset: this.options.zIndexOffset * 2 12629 }); 12630 var potentialMarkerPint = this._map.latLngToContainerPoint(potentialMarker.getLatLng()); 12631 lastPtDistance = lastMarkerPoint.distanceTo(potentialMarkerPint) 12632 } else { 12633 lastPtDistance = Infinity 12634 } 12635 return lastPtDistance 12636 }, 12637 _updateFinishHandler: function () { 12638 var markerCount = this._markers.length; 12639 if (markerCount > 1) { 12640 this._markers[markerCount - 1].on('click', this._finishShape, this) 12641 } 12642 if (markerCount > 2) { 12643 this._markers[markerCount - 2].off('click', this._finishShape, this) 12644 } 12645 }, 12646 _createMarker: function (latlng) { 12647 var marker = new L.Marker(latlng, { 12648 icon: this.options.icon, 12649 zIndexOffset: this.options.zIndexOffset * 2 12650 }); 12651 this._markerGroup.addLayer(marker); 12652 return marker 12653 }, 12654 _updateGuide: function (newPos) { 12655 var markerCount = this._markers ? this._markers.length : 0; 12656 if (markerCount > 0) { 12657 newPos = newPos || this._map.latLngToLayerPoint(this._currentLatLng); 12658 this._clearGuides(); 12659 this._drawGuide(this._map.latLngToLayerPoint(this._markers[markerCount - 1].getLatLng()), newPos) 12660 } 12661 }, 12662 _updateTooltip: function (latLng) { 12663 var text = this._getTooltipText(); 12664 if (latLng) { 12665 this._tooltip.updatePosition(latLng) 12666 } 12667 if (!this._errorShown) { 12668 this._tooltip.updateContent(text) 12669 } 12670 }, 12671 _drawGuide: function (pointA, pointB) { 12672 var length = Math.floor(Math.sqrt(Math.pow((pointB.x - pointA.x), 2) + Math.pow((pointB.y - pointA.y), 2))), guidelineDistance = this.options.guidelineDistance, maxGuideLineLength = this.options.maxGuideLineLength, i = length > maxGuideLineLength ? length - maxGuideLineLength : guidelineDistance, fraction, dashPoint, dash; 12673 if (!this._guidesContainer) { 12674 this._guidesContainer = L.DomUtil.create('div', 'leaflet-draw-guides', this._overlayPane) 12675 } 12676 for (; i < length; i += this.options.guidelineDistance) { 12677 fraction = i / length; 12678 dashPoint = { 12679 x: Math.floor((pointA.x * (1 - fraction)) + (fraction * pointB.x)), 12680 y: Math.floor((pointA.y * (1 - fraction)) + (fraction * pointB.y)) 12681 }; 12682 dash = L.DomUtil.create('div', 'leaflet-draw-guide-dash', this._guidesContainer); 12683 dash.style.backgroundColor = !this._errorShown ? this.options.shapeOptions.color : this.options.drawError.color; 12684 L.DomUtil.setPosition(dash, dashPoint) 12685 } 12686 }, 12687 _updateGuideColor: function (color) { 12688 if (this._guidesContainer) { 12689 for (var i = 0, l = this._guidesContainer.childNodes.length; i < l; i++) { 12690 this._guidesContainer.childNodes[i].style.backgroundColor = color 12691 } 12692 } 12693 }, 12694 _clearGuides: function () { 12695 if (this._guidesContainer) { 12696 while (this._guidesContainer.firstChild) { 12697 this._guidesContainer.removeChild(this._guidesContainer.firstChild) 12698 } 12699 } 12700 }, 12701 _getTooltipText: function () { 12702 var showLength = this.options.showLength, labelText, distanceStr; 12703 if (this._markers.length === 0) { 12704 labelText = {
12705 text: L.drawLocal.draw.handlers.polyline.tooltip.start 12706 } 12707 } else { 12708 distanceStr = showLength ? this._getMeasurementString() : ''; 12709 if (this._markers.length === 1) { 12710 labelText = { 12711 text: L.drawLocal.draw.handlers.polyline.tooltip.cont, 12712 subtext: distanceStr 12713 } 12714 } else { 12715 labelText = { 12716 text: L.drawLocal.draw.handlers.polyline.tooltip.end, 12717 subtext: distanceStr 12718 } 12719 } 12720 } 12721 return labelText 12722 }, 12723 _updateRunningMeasure: function (latlng, added) { 12724 var markersLength = this._markers.length, previousMarkerIndex, distance; 12725 if (this._markers.length === 1) { 12726 this._measurementRunningTotal = 0 12727 } else { 12728 previousMarkerIndex = markersLength - (added ? 2 : 1); 12729 if (L.GeometryUtil.isVersion07x()) { 12730 distance = latlng.distanceTo(this._markers[previousMarkerIndex].getLatLng()) * (this.options.factor || 1) 12731 } else { 12732 distance = this._map.distance(latlng, this._markers[previousMarkerIndex].getLatLng()) * (this.options.factor || 1) 12733 } 12734 this._measurementRunningTotal += distance * (added ? 1 : -1) 12735 } 12736 }, 12737 _getMeasurementString: function () { 12738 var currentLatLng = this._currentLatLng, previousLatLng = this._markers[this._markers.length - 1].getLatLng(), distance; 12739 if (L.GeometryUtil.isVersion07x()) { 12740 distance = previousLatLng && currentLatLng && currentLatLng.distanceTo ? this._measurementRunningTotal + currentLatLng.distanceTo(previousLatLng) * (this.options.factor || 1) : this._measurementRunningTotal || 0 12741 } else { 12742 distance = previousLatLng && currentLatLng ? this._measurementRunningTotal + this._map.distance(currentLatLng, previousLatLng) * (this.options.factor || 1) : this._measurementRunningTotal || 0 12743 } 12744 return L.GeometryUtil.readableDistance(distance, this.options.metric, this.options.feet, this.options.nautic, this.options.precision) 12745 }, 12746 _showErrorTooltip: function () { 12747 this._errorShown = !0; 12748 this._tooltip.showAsError().updateContent({ 12749 text: this.options.drawError.message 12750 }); 12751 this._updateGuideColor(this.options.drawError.color); 12752 this._poly.setStyle({ 12753 color: this.options.drawError.color 12754 }); 12755 this._clearHideErrorTimeout(); 12756 this._hideErrorTimeout = setTimeout(L.Util.bind(this._hideErrorTooltip, this), this.options.drawError.timeout) 12757 }, 12758 _hideErrorTooltip: function () { 12759 this._errorShown = !1; 12760 this._clearHideErrorTimeout(); 12761 this._tooltip.removeError().updateContent(this._getTooltipText()); 12762 this._updateGuideColor(this.options.shapeOptions.color); 12763 this._poly.setStyle({ 12764 color: this.options.shapeOptions.color 12765 }) 12766 }, 12767 _clearHideErrorTimeout: function () { 12768 if (this._hideErrorTimeout) { 12769 clearTimeout(this._hideErrorTimeout); 12770 this._hideErrorTimeout = null 12771 } 12772 }, 12773 _disableNewMarkers: function () { 12774 this._disableMarkers = !0 12775 }, 12776 _enableNewMarkers: function () { 12777 setTimeout(function () { 12778 this._disableMarkers = !1 12779 } 12780 .bind(this), 50) 12781 }, 12782 _cleanUpShape: function () { 12783 if (this._markers.length > 1) { 12784 this._markers[this._markers.length - 1].off('click', this._finishShape, this) 12785 } 12786 }, 12787 _fireCreatedEvent: function () { 12788 var poly = new this.Poly(this._poly.getLatLngs(), this.options.shapeOptions); 12789 L.Draw.Feature.prototype._fireCreatedEvent.call(this, poly) 12790 } 12791}); 12792L.Draw.Marker = L.Draw.Feature.extend({ 12793 statics: { 12794 TYPE: 'marker' 12795 }, 12796 options: { 12797 icon: new L.Icon.Default(), 12798 repeatMode: !1, 12799 zIndexOffset: 2000 12800 }, 12801 initialize: function (map, options) { 12802 this.type = L.Draw.Marker.TYPE; 12803 this._initialLabelText = L.drawLocal.draw.handlers.marker.tooltip.start; 12804 L.Draw.Feature.prototype.initialize.call(this, map, options) 12805 }, 12806 addHooks: function () { 12807 L.Draw.Feature.prototype.addHooks.call(this); 12808 if (this._map) { 12809 this._tooltip.updateContent({ 12810 text: this._initialLabelText 12811 }); 12812 if (!this._mouseMarker) { 12813 this._mouseMarker = L.marker(this._map.getCenter(), { 12814 icon: L.divIcon({ 12815 className: 'leaflet-mouse-marker', 12816 iconAnchor: [20, 20], 12817 iconSize: [40, 40] 12818 }), 12819 opacity: 0, 12820 zIndexOffset: this.options.zIndexOffset 12821 }) 12822 } 12823 this._mouseMarker.on('click', this._onClick, this).addTo(this._map); 12824 this._map.on('mousemove', this._onMouseMove, this); 12825 this._map.on('click', this._onTouch, this) 12826 } 12827 }, 12828 removeHooks: function () { 12829 L.Draw.Feature.prototype.removeHooks.call(this); 12830 if (this._map) { 12831 this._map.off('click', this._onClick, this).off('click', this._onTouch, this); 12832 if (this._marker) { 12833 this._marker.off('click', this._onClick, this); 12834 this._map.removeLayer(this._marker); 12835 delete this._marker 12836 } 12837 this._mouseMarker.off('click', this._onClick, this); 12838 this._map.removeLayer(this._mouseMarker); 12839 delete this._mouseMarker; 12840 this._map.off('mousemove', this._onMouseMove, this) 12841 } 12842 }, 12843 _onMouseMove: function (e) { 12844 var latlng = e.latlng; 12845 this._tooltip.updatePosition(latlng); 12846 this._mouseMarker.setLatLng(latlng); 12847 if (!this._marker) { 12848 this._marker = this._createMarker(latlng); 12849 this._marker.on('click', this._onClick, this); 12850 this._map.on('click', this._onClick, this).addLayer(this._marker) 12851 } else { 12852 latlng = this._mouseMarker.getLatLng(); 12853 this._marker.setLatLng(latlng) 12854 } 12855 }, 12856 _createMarker: function (latlng) { 12857 return new L.Marker(latlng, { 12858 icon: this.options.icon, 12859 zIndexOffset: this.options.zIndexOffset 12860 }) 12861 }, 12862 _onClick: function () { 12863 this._fireCreatedEvent(); 12864 this.disable(); 12865 if (this.options.repeatMode) { 12866 this.enable() 12867 } 12868 }, 12869 _onTouch: function (e) { 12870 this._onMouseMove(e); 12871 this._onClick() 12872 }, 12873 _fireCreatedEvent: function () { 12874 var marker = new L.Marker.Touch(this._marker.getLatLng(), { 12875 icon: this.options.icon 12876 });
12877 L.Draw.Feature.prototype._fireCreatedEvent.call(this, marker) 12878 } 12879}); 12880L.Draw.CircleMarker = L.Draw.Marker.extend({ 12881 statics: { 12882 TYPE: 'circlemarker' 12883 }, 12884 options: { 12885 stroke: !0, 12886 color: '#3388ff', 12887 weight: 4, 12888 opacity: 0.5, 12889 fill: !0, 12890 fillColor: null, 12891 fillOpacity: 0.2, 12892 clickable: !0, 12893 zIndexOffset: 2000 12894 }, 12895 initialize: function (map, options) { 12896 this.type = L.Draw.CircleMarker.TYPE; 12897 this._initialLabelText = L.drawLocal.draw.handlers.circlemarker.tooltip.start; 12898 L.Draw.Feature.prototype.initialize.call(this, map, options) 12899 }, 12900 _fireCreatedEvent: function () { 12901 var circleMarker = new L.CircleMarker(this._marker.getLatLng(), this.options); 12902 L.Draw.Feature.prototype._fireCreatedEvent.call(this, circleMarker) 12903 }, 12904 _createMarker: function (latlng) { 12905 return new L.CircleMarker(latlng, this.options) 12906 } 12907}); 12908L.Draw.Circle = L.Draw.SimpleShape.extend({ 12909 statics: { 12910 TYPE: 'circle' 12911 }, 12912 options: { 12913 shapeOptions: { 12914 stroke: !0, 12915 color: '#3388ff', 12916 weight: 4, 12917 opacity: 0.5, 12918 fill: !0, 12919 fillColor: null, 12920 fillOpacity: 0.2, 12921 clickable: !0 12922 }, 12923 showRadius: !0, 12924 metric: !0, 12925 feet: !0, 12926 nautic: !1 12927 }, 12928 initialize: function (map, options) { 12929 this.type = L.Draw.Circle.TYPE; 12930 this._initialLabelText = L.drawLocal.draw.handlers.circle.tooltip.start; 12931 L.Draw.SimpleShape.prototype.initialize.call(this, map, options) 12932 }, 12933 _drawShape: function (latlng) { 12934 if (L.GeometryUtil.isVersion07x()) { 12935 var distance = this._startLatLng.distanceTo(latlng) 12936 } else { 12937 var distance = this._map.distance(this._startLatLng, latlng) 12938 } 12939 if (!this._shape) { 12940 this._shape = new L.Circle(this._startLatLng, distance, this.options.shapeOptions); 12941 this._map.addLayer(this._shape) 12942 } else { 12943 this._shape.setRadius(distance) 12944 } 12945 }, 12946 _fireCreatedEvent: function () { 12947 var circle = new L.Circle(this._startLatLng, this._shape.getRadius(), this.options.shapeOptions); 12948 L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, circle) 12949 }, 12950 _onMouseMove: function (e) { 12951 var latlng = e.latlng, showRadius = this.options.showRadius, useMetric = this.options.metric, radius; 12952 this._tooltip.updatePosition(latlng); 12953 if (this._isDrawing) { 12954 this._drawShape(latlng); 12955 radius = this._shape.getRadius().toFixed(1); 12956 var subtext = ''; 12957 if (showRadius) { 12958 subtext = L.drawLocal.draw.handlers.circle.radius + ': ' + L.GeometryUtil.readableDistance(radius, useMetric, this.options.feet, this.options.nautic) 12959 } 12960 this._tooltip.updateContent({ 12961 text: this._endLabelText, 12962 subtext: subtext 12963 }) 12964 } 12965 } 12966}); 12967L.Draw.Polygon = L.Draw.Polyline.extend({ 12968 statics: { 12969 TYPE: 'polygon' 12970 }, 12971 Poly: L.Polygon, 12972 options: { 12973 showArea: !1, 12974 showLength: !1, 12975 shapeOptions: { 12976 stroke: !0, 12977 color: '#3388ff', 12978 weight: 4, 12979 opacity: 0.5, 12980 fill: !0, 12981 fillColor: null, 12982 fillOpacity: 0.2, 12983 clickable: !0 12984 }, 12985 metric: !0, 12986 feet: !0, 12987 nautic: !1, 12988 precision: {} 12989 }, 12990 initialize: function (map, options) { 12991 L.Draw.Polyline.prototype.initialize.call(this, map, options); 12992 this.type = L.Draw.Polygon.TYPE 12993 }, 12994 _updateFinishHandler: function () { 12995 var markerCount = this._markers.length; 12996 if (markerCount === 1) { 12997 this._markers[0].on('click', this._finishShape, this) 12998 } 12999 if (markerCount > 2) { 13000 this._markers[markerCount - 1].on('dblclick', this._finishShape, this); 13001 if (markerCount > 3) { 13002 this._markers[markerCount - 2].off('dblclick', this._finishShape, this) 13003 } 13004 } 13005 }, 13006 _getTooltipText: function () { 13007 var text, subtext; 13008 if (this._markers.length === 0) { 13009 text = L.drawLocal.draw.handlers.polygon.tooltip.start 13010 } else if (this._markers.length < 3) { 13011 text = L.drawLocal.draw.handlers.polygon.tooltip.cont; 13012 subtext = this._getMeasurementString() 13013 } else {
13014 text = L.drawLocal.draw.handlers.polygon.tooltip.end; 13015 subtext = this._getMeasurementString() 13016 } 13017 return { 13018 text: text, 13019 subtext: subtext 13020 } 13021 }, 13022 _getMeasurementString: function () { 13023 var area = this._area 13024 , measurementString = ''; 13025 if (!area && !this.options.showLength) { 13026 return null 13027 } 13028 if (this.options.showLength) { 13029 measurementString = L.Draw.Polyline.prototype._getMeasurementString.call(this) 13030 } 13031 if (area) { 13032 measurementString += '<br>' + L.GeometryUtil.readableArea(area, this.options.metric, this.options.precision) 13033 } 13034 return measurementString 13035 }, 13036 _shapeIsValid: function () { 13037 return this._markers.length >= 3 13038 }, 13039 _vertexChanged: function (latlng, added) { 13040 var latLngs; 13041 if (!this.options.allowIntersection && this.options.showArea) { 13042 latLngs = this._poly.getLatLngs(); 13043 this._area = L.GeometryUtil.geodesicArea(latLngs) 13044 } 13045 L.Draw.Polyline.prototype._vertexChanged.call(this, latlng, added) 13046 }, 13047 _cleanUpShape: function () { 13048 var markerCount = this._markers.length; 13049 if (markerCount > 0) { 13050 this._markers[0].off('click', this._finishShape, this); 13051 if (markerCount > 2) { 13052 this._markers[markerCount - 1].off('dblclick', this._finishShape, this) 13053 } 13054 } 13055 } 13056}); 13057L.Draw.Rectangle = L.Draw.SimpleShape.extend({ 13058 statics: { 13059 TYPE: 'rectangle' 13060 }, 13061 options: { 13062 shapeOptions: { 13063 stroke: !0, 13064 color: '#3388ff', 13065 weight: 4, 13066 opacity: 0.5, 13067 fill: !0, 13068 fillColor: null, 13069 fillOpacity: 0.2, 13070 clickable: !0 13071 }, 13072 showArea: !0, 13073 metric: !0 13074 }, 13075 initialize: function (map, options) { 13076 this.type = L.Draw.Rectangle.TYPE; 13077 this._initialLabelText = L.drawLocal.draw.handlers.rectangle.tooltip.start; 13078 L.Draw.SimpleShape.prototype.initialize.call(this, map, options) 13079 }, 13080 disable: function () { 13081 if (!this._enabled) { 13082 return 13083 } 13084 this._isCurrentlyTwoClickDrawing = !1; 13085 L.Draw.SimpleShape.prototype.disable.call(this) 13086 }, 13087 _onMouseUp: function (e) { 13088 if (!this._shape && !this._isCurrentlyTwoClickDrawing) { 13089 this._isCurrentlyTwoClickDrawing = !0; 13090 return 13091 } 13092 if (this._isCurrentlyTwoClickDrawing && !_hasAncestor(e.target, 'leaflet-pane')) { 13093 return 13094 } 13095 L.Draw.SimpleShape.prototype._onMouseUp.call(this) 13096 }, 13097 _drawShape: function (latlng) { 13098 if (!this._shape) { 13099 this._shape = new L.Rectangle(new L.LatLngBounds(this._startLatLng, latlng), this.options.shapeOptions); 13100 this._map.addLayer(this._shape) 13101 } else { 13102 this._shape.setBounds(new L.LatLngBounds(this._startLatLng, latlng)) 13103 } 13104 }, 13105 _fireCreatedEvent: function () { 13106 var rectangle = new L.Rectangle(this._shape.getBounds(), this.options.shapeOptions); 13107 L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, rectangle) 13108 }, 13109 _getTooltipText: function () { 13110 var tooltipText = L.Draw.SimpleShape.prototype._getTooltipText.call(this), shape = this._shape, showArea = this.options.showArea, latLngs, area, subtext; 13111 if (shape) { 13112 latLngs = this._shape._defaultShape ? this._shape._defaultShape() : this._shape.getLatLngs(); 13113 area = L.GeometryUtil.geodesicArea(latLngs); 13114 subtext = showArea ? L.GeometryUtil.readableArea(area, this.options.metric) : '' 13115 } 13116 return { 13117 text: tooltipText.text, 13118 subtext: subtext 13119 } 13120 } 13121}); 13122function _hasAncestor(el, cls) { 13123 while ((el = el.parentElement) && !el.classList.contains(cls)) { } 13124 return el 13125} 13126L.EditToolbar = L.Toolbar.extend({ 13127 statics: { 13128 TYPE: 'edit' 13129 }, 13130 options: { 13131 edit: { 13132 selectedPathOptions: { 13133 dashArray: '10, 10', 13134 fill: !0, 13135 fillColor: '#fe57a1', 13136 fillOpacity: 0.1, 13137 maintainColor: !1 13138 } 13139 }, 13140 remove: {}, 13141 poly: null, 13142 featureGroup: null 13143 }, 13144 initialize: function (options) { 13145 if (options.edit) { 13146 if (typeof options.edit.selectedPathOptions === 'undefined') { 13147 options.edit.selectedPathOptions = this.options.edit.selectedPathOptions 13148 } 13149 options.edit.selectedPathOptions = L.extend({}, this.options.edit.selectedPathOptions, options.edit.selectedPathOptions) 13150 } 13151 if (options.remove) { 13152 options.remove = L.extend({}, this.options.remove, options.remove) 13153 } 13154 if (options.poly) { 13155 options.poly = L.extend({}, this.options.poly, options.poly) 13156 } 13157 this._toolbarClass = 'leaflet-draw-edit'; 13158 L.Toolbar.prototype.initialize.call(this, options); 13159 this._selectedFeatureCount = 0 13160 }, 13161 getModeHandlers: function (map) { 13162 var featureGroup = this.options.featureGroup; 13163 return [{ 13164 enabled: this.options.edit, 13165 handler: new L.EditToolbar.Edit(map, { 13166 featureGroup: featureGroup, 13167 selectedPathOptions: this.options.edit.selectedPathOptions, 13168 poly: this.options.poly 13169 }), 13170 title: L.drawLocal.edit.toolbar.buttons.edit 13171 }, { 13172 enabled: this.options.remove, 13173 handler: new L.EditToolbar.Delete(map, { 13174 featureGroup: featureGroup 13175 }), 13176 title: L.drawLocal.edit.toolbar.buttons.remove 13177 }] 13178 }, 13179 getActions: function (handler) { 13180 var actions = [{ 13181 title: L.drawLocal.edit.toolbar.actions.save.title, 13182 text: L.drawLocal.edit.toolbar.actions.save.text, 13183 callback: this._save, 13184 context: this 13185 }, { 13186 title: L.drawLocal.edit.toolbar.actions.cancel.title, 13187 text: L.drawLocal.edit.toolbar.actions.cancel.text, 13188 callback: this.disable, 13189 context: this 13190 }]; 13191 if (handler.removeAllLayers) { 13192 actions.push({ 13193 title: L.drawLocal.edit.toolbar.actions.clearAll.title, 13194 text: L.drawLocal.edit.toolbar.actions.clearAll.text, 13195 callback: this._clearAllLayers, 13196 context: this 13197 }) 13198 } 13199 return actions 13200 }, 13201 addToolbar: function (map) { 13202 var container = L.Toolbar.prototype.addToolbar.call(this, map); 13203 this._checkDisabled(); 13204 this.options.featureGroup.on('layeradd layerremove', this._checkDisabled, this); 13205 return container 13206 }, 13207 removeToolbar: function () { 13208 this.options.featureGroup.off('layeradd layerremove', this._checkDisabled, this); 13209 L.Toolbar.prototype.removeToolbar.call(this) 13210 }, 13211 disable: function () { 13212 if (!this.enabled()) { 13213 return 13214 } 13215 this._activeMode.handler.revertLayers(); 13216 L.Toolbar.prototype.disable.call(this) 13217 }, 13218 _save: function () { 13219 this._activeMode.handler.save(); 13220 if (this._activeMode) { 13221 this._activeMode.handler.disable() 13222 } 13223 }, 13224 _clearAllLayers: function () { 13225 this._activeMode.handler.removeAllLayers(); 13226 if (this._activeMode) { 13227 this._activeMode.handler.disable() 13228 } 13229 }, 13230 _checkDisabled: function () { 13231 var featureGroup = this.options.featureGroup, hasLayers = featureGroup.getLayers().length !== 0, button; 13232 if (this.options.edit) { 13233 button = this._modes[L.EditToolbar.Edit.TYPE].button; 13234 if (hasLayers) { 13235 L.DomUtil.removeClass(button, 'leaflet-disabled') 13236 } else { 13237 L.DomUtil.addClass(button, 'leaflet-disabled') 13238 } 13239 button.setAttribute('title', hasLayers ? L.drawLocal.edit.toolbar.buttons.edit : L.drawLocal.edit.toolbar.buttons.editDisabled) 13240 } 13241 if (this.options.remove) { 13242 button = this._modes[L.EditToolbar.Delete.TYPE].button; 13243 if (hasLayers) { 13244 L.DomUtil.removeClass(button, 'leaflet-disabled') 13245 } else { 13246 L.DomUtil.addClass(button, 'leaflet-disabled') 13247 } 13248 button.setAttribute('title', hasLayers ? L.drawLocal.edit.toolbar.buttons.remove : L.drawLocal.edit.toolbar.buttons.removeDisabled) 13249 } 13250 } 13251}); 13252L.EditToolbar.Edit = L.Handler.extend({ 13253 statics: { 13254 TYPE: 'edit' 13255 }, 13256 initialize: function (map, options) { 13257 L.Handler.prototype.initialize.call(this, map); 13258 L.setOptions(this, options); 13259 this._featureGroup = options.featureGroup; 13260 if (!(this._featureGroup instanceof L.FeatureGroup)) { 13261 throw new Error('options.featureGroup must be a L.FeatureGroup') 13262 } 13263 this._uneditedLayerProps = {}; 13264 this.type = L.EditToolbar.Edit.TYPE; 13265 var version = L.version.split('.'); 13266 if (parseInt(version[0], 10) === 1 && parseInt(version[1], 10) >= 2) { 13267 L.EditToolbar.Edit.include(L.Evented.prototype) 13268 } else { 13269 L.EditToolbar.Edit.include(L.Mixin.Events) 13270 } 13271 }, 13272 enable: function () { 13273 if (this._enabled || !this._hasAvailableLayers()) { 13274 return 13275 } 13276 this.fire('enabled', { 13277 handler: this.type 13278 });
13279 this._map.fire(L.Draw.Event.EDITSTART, { 13280 handler: this.type 13281 }); 13282 L.Handler.prototype.enable.call(this); 13283 this._featureGroup.on('layeradd', this._enableLayerEdit, this).on('layerremove', this._disableLayerEdit, this) 13284 }, 13285 disable: function () { 13286 if (!this._enabled) { 13287 return 13288 } 13289 this._featureGroup.off('layeradd', this._enableLayerEdit, this).off('layerremove', this._disableLayerEdit, this); 13290 L.Handler.prototype.disable.call(this); 13291 this._map.fire(L.Draw.Event.EDITSTOP, { 13292 handler: this.type 13293 }); 13294 this.fire('disabled', { 13295 handler: this.type 13296 }) 13297 }, 13298 addHooks: function () { 13299 var map = this._map; 13300 if (map) { 13301 map.getContainer().focus(); 13302 this._featureGroup.eachLayer(this._enableLayerEdit, this); 13303 this._tooltip = new L.Draw.Tooltip(this._map); 13304 this._tooltip.updateContent({ 13305 text: L.drawLocal.edit.handlers.edit.tooltip.text, 13306 subtext: L.drawLocal.edit.handlers.edit.tooltip.subtext 13307 }); 13308 map._editTooltip = this._tooltip; 13309 this._updateTooltip(); 13310 this._map.on('mousemove', this._onMouseMove, this).on('touchmove', this._onMouseMove, this).on('MSPointerMove', this._onMouseMove, this).on(L.Draw.Event.EDITVERTEX, this._updateTooltip, this) 13311 } 13312 }, 13313 removeHooks: function () { 13314 if (this._map) { 13315 this._featureGroup.eachLayer(this._disableLayerEdit, this); 13316 this._uneditedLayerProps = {}; 13317 this._tooltip.dispose(); 13318 this._tooltip = null; 13319 this._map.off('mousemove', this._onMouseMove, this).off('touchmove', this._onMouseMove, this).off('MSPointerMove', this._onMouseMove, this).off(L.Draw.Event.EDITVERTEX, this._updateTooltip, this) 13320 } 13321 }, 13322 revertLayers: function () { 13323 this._featureGroup.eachLayer(function (layer) { 13324 this._revertLayer(layer) 13325 }, this) 13326 }, 13327 save: function () { 13328 var editedLayers = new L.LayerGroup(); 13329 this._featureGroup.eachLayer(function (layer) { 13330 if (layer.edited) { 13331 editedLayers.addLayer(layer); 13332 layer.edited = !1 13333 } 13334 }); 13335 this._map.fire(L.Draw.Event.EDITED, { 13336 layers: editedLayers 13337 }) 13338 }, 13339 _backupLayer: function (layer) { 13340 var id = L.Util.stamp(layer); 13341 if (!this._uneditedLayerProps[id]) { 13342 if (layer instanceof L.Polyline || layer instanceof L.Polygon || layer instanceof L.Rectangle) { 13343 this._uneditedLayerProps[id] = { 13344 latlngs: L.LatLngUtil.cloneLatLngs(layer.getLatLngs()) 13345 } 13346 } else if (layer instanceof L.Circle) { 13347 this._uneditedLayerProps[id] = { 13348 latlng: L.LatLngUtil.cloneLatLng(layer.getLatLng()), 13349 radius: layer.getRadius() 13350 } 13351 } else if (layer instanceof L.Marker || layer instanceof L.CircleMarker) { 13352 this._uneditedLayerProps[id] = { 13353 latlng: L.LatLngUtil.cloneLatLng(layer.getLatLng()) 13354 } 13355 } 13356 } 13357 }, 13358 _getTooltipText: function () { 13359 return ({ 13360 text: L.drawLocal.edit.handlers.edit.tooltip.text, 13361 subtext: L.drawLocal.edit.handlers.edit.tooltip.subtext 13362 }) 13363 }, 13364 _updateTooltip: function () { 13365 this._tooltip.updateContent(this._getTooltipText()) 13366 }, 13367 _revertLayer: function (layer) { 13368 var id = L.Util.stamp(layer); 13369 layer.edited = !1; 13370 if (this._uneditedLayerProps.hasOwnProperty(id)) { 13371 if (layer instanceof L.Polyline || layer instanceof L.Polygon || layer instanceof L.Rectangle) { 13372 layer.setLatLngs(this._uneditedLayerProps[id].latlngs) 13373 } else if (layer instanceof L.Circle) { 13374 layer.setLatLng(this._uneditedLayerProps[id].latlng); 13375 layer.setRadius(this._uneditedLayerProps[id].radius) 13376 } else if (layer instanceof L.Marker || layer instanceof L.CircleMarker) { 13377 layer.setLatLng(this._uneditedLayerProps[id].latlng) 13378 } 13379 layer.fire('revert-edited', { 13380 layer: layer 13381 }) 13382 } 13383 }, 13384 _enableLayerEdit: function (e) { 13385 var layer = e.layer || e.target || e, pathOptions, poly; 13386 this._backupLayer(layer); 13387 if (this.options.poly) { 13388 poly = L.Util.extend({}, this.options.poly); 13389 layer.options.poly = poly 13390 } 13391 if (this.options.selectedPathOptions) { 13392 pathOptions = L.Util.extend({}, this.options.selectedPathOptions); 13393 if (pathOptions.maintainColor) { 13394 pathOptions.color = layer.options.color; 13395 pathOptions.fillColor = layer.options.fillColor 13396 } 13397 layer.options.original = L.extend({}, layer.options); 13398 layer.options.editing = pathOptions 13399 } 13400 if (layer instanceof L.Marker) { 13401 if (layer.editing) { 13402 layer.editing.enable() 13403 } 13404 layer.dragging.enable(); 13405 layer.on('dragend', this._onMarkerDragEnd).on('touchmove', this._onTouchMove, this).on('MSPointerMove', this._onTouchMove, this).on('touchend', this._onMarkerDragEnd, this).on('MSPointerUp', this._onMarkerDragEnd, this) 13406 } else { 13407 layer.editing.enable() 13408 } 13409 }, 13410 _disableLayerEdit: function (e) { 13411 var layer = e.layer || e.target || e; 13412 layer.edited = !1; 13413 if (layer.editing) { 13414 layer.editing.disable() 13415 } 13416 delete layer.options.editing; 13417 delete layer.options.original; 13418 if (this._selectedPathOptions) { 13419 if (layer instanceof L.Marker) { 13420 this._toggleMarkerHighlight(layer) 13421 } else { 13422 layer.setStyle(layer.options.previousOptions); 13423 delete layer.options.previousOptions 13424 } 13425 } 13426 if (layer instanceof L.Marker) { 13427 layer.dragging.disable(); 13428 layer.off('dragend', this._onMarkerDragEnd, this).off('touchmove', this._onTouchMove, this).off('MSPointerMove', this._onTouchMove, this).off('touchend', this._onMarkerDragEnd, this).off('MSPointerUp', this._onMarkerDragEnd, this) 13429 } else { 13430 layer.editing.disable() 13431 } 13432 }, 13433 _onMouseMove: function (e) { 13434 this._tooltip.updatePosition(e.latlng) 13435 }, 13436 _onMarkerDragEnd: function (e) { 13437 var layer = e.target; 13438 layer.edited = !0; 13439 this._map.fire(L.Draw.Event.EDITMOVE, { 13440 layer: layer 13441 }) 13442 }, 13443 _onTouchMove: function (e) { 13444 var touchEvent = e.originalEvent.changedTouches[0] 13445 , layerPoint = this._map.mouseEventToLayerPoint(touchEvent) 13446 , latlng = this._map.layerPointToLatLng(layerPoint); 13447 e.target.setLatLng(latlng) 13448 }, 13449 _hasAvailableLayers: function () { 13450 return this._featureGroup.getLayers().length !== 0 13451 } 13452}); 13453L.EditToolbar.Delete = L.Handler.extend({ 13454 statics: { 13455 TYPE: 'remove' 13456 }, 13457 initialize: function (map, options) { 13458 L.Handler.prototype.initialize.call(this, map); 13459 L.Util.setOptions(this, options); 13460 this._deletableLayers = this.options.featureGroup; 13461 if (!(this._deletableLayers instanceof L.FeatureGroup)) { 13462 throw new Error('options.featureGroup must be a L.FeatureGroup') 13463 } 13464 this.type = L.EditToolbar.Delete.TYPE; 13465 var version = L.version.split('.'); 13466 if (parseInt(version[0], 10) === 1 && parseInt(version[1], 10) >= 2) { 13467 L.EditToolbar.Delete.include(L.Evented.prototype) 13468 } else { 13469 L.EditToolbar.Delete.include(L.Mixin.Events) 13470 } 13471 }, 13472 enable: function () { 13473 if (this._enabled || !this._hasAvailableLayers()) { 13474 return 13475 } 13476 this.fire('enabled', { 13477 handler: this.type 13478 });
13479 this._map.fire(L.Draw.Event.DELETESTART, { 13480 handler: this.type 13481 }); 13482 L.Handler.prototype.enable.call(this); 13483 this._deletableLayers.on('layeradd', this._enableLayerDelete, this).on('layerremove', this._disableLayerDelete, this) 13484 }, 13485 disable: function () { 13486 if (!this._enabled) { 13487 return 13488 } 13489 this._deletableLayers.off('layeradd', this._enableLayerDelete, this).off('layerremove', this._disableLayerDelete, this); 13490 L.Handler.prototype.disable.call(this); 13491 this._map.fire(L.Draw.Event.DELETESTOP, { 13492 handler: this.type 13493 }); 13494 this.fire('disabled', { 13495 handler: this.type 13496 }) 13497 }, 13498 addHooks: function () { 13499 var map = this._map; 13500 if (map) { 13501 map.getContainer().focus(); 13502 this._deletableLayers.eachLayer(this._enableLayerDelete, this); 13503 this._deletedLayers = new L.LayerGroup(); 13504 this._tooltip = new L.Draw.Tooltip(this._map); 13505 this._tooltip.updateContent({ 13506 text: L.drawLocal.edit.handlers.remove.tooltip.text 13507 }); 13508 this._map.on('mousemove', this._onMouseMove, this) 13509 } 13510 }, 13511 removeHooks: function () { 13512 if (this._map) { 13513 this._deletableLayers.eachLayer(this._disableLayerDelete, this); 13514 this._deletedLayers = null; 13515 this._tooltip.dispose(); 13516 this._tooltip = null; 13517 this._map.off('mousemove', this._onMouseMove, this) 13518 } 13519 }, 13520 revertLayers: function () { 13521 this._deletedLayers.eachLayer(function (layer) { 13522 this._deletableLayers.addLayer(layer); 13523 layer.fire('revert-deleted', { 13524 layer: layer 13525 }) 13526 }, this) 13527 }, 13528 save: function () { 13529 this._map.fire(L.Draw.Event.DELETED, { 13530 layers: this._deletedLayers 13531 }) 13532 }, 13533 removeAllLayers: function () { 13534 this._deletableLayers.eachLayer(function (layer) { 13535 this._removeLayer({ 13536 layer: layer 13537 }) 13538 }, this); 13539 this.save() 13540 }, 13541 _enableLayerDelete: function (e) { 13542 var layer = e.layer || e.target || e; 13543 layer.on('click', this._removeLayer, this) 13544 }, 13545 _disableLayerDelete: function (e) { 13546 var layer = e.layer || e.target || e; 13547 layer.off('click', this._removeLayer, this); 13548 this._deletedLayers.removeLayer(layer) 13549 }, 13550 _removeLayer: function (e) { 13551 var layer = e.layer || e.target || e; 13552 this._deletableLayers.removeLayer(layer); 13553 this._deletedLayers.addLayer(layer); 13554 layer.fire('deleted') 13555 }, 13556 _onMouseMove: function (e) { 13557 this._tooltip.updatePosition(e.latlng) 13558 }, 13559 _hasAvailableLayers: function () { 13560 return this._deletableLayers.getLayers().length !== 0 13561 } 13562}); 13563L.Edit = L.Edit || {}; 13564L.Edit.Poly = L.Handler.extend({ 13565 initialize: function (poly) { 13566 this.latlngs = [poly._latlngs]; 13567 if (poly._holes) { 13568 this.latlngs = this.latlngs.concat(poly._holes) 13569 } 13570 this._poly = poly; 13571 this._poly.on('revert-edited', this._updateLatLngs, this) 13572 }, 13573 _defaultShape: function () { 13574 if (!L.Polyline._flat) { 13575 return this._poly._latlngs 13576 } 13577 return L.Polyline._flat(this._poly._latlngs) ? this._poly._latlngs : this._poly._latlngs[0] 13578 }, 13579 _eachVertexHandler: function (callback) { 13580 for (var i = 0; i < this._verticesHandlers.length; i++) { 13581 callback(this._verticesHandlers[i]) 13582 } 13583 }, 13584 addHooks: function () { 13585 this._initHandlers(); 13586 this._eachVertexHandler(function (handler) { 13587 handler.addHooks() 13588 }) 13589 }, 13590 removeHooks: function () { 13591 this._eachVertexHandler(function (handler) { 13592 handler.removeHooks() 13593 }) 13594 }, 13595 updateMarkers: function () { 13596 this._eachVertexHandler(function (handler) { 13597 handler.updateMarkers() 13598 }) 13599 }, 13600 _initHandlers: function () { 13601 this._verticesHandlers = []; 13602 for (var i = 0; i < this.latlngs.length; i++) { 13603 this._verticesHandlers.push(new L.Edit.PolyVerticesEdit(this._poly, this.latlngs[i], this._poly.options.poly)) 13604 } 13605 }, 13606 _updateLatLngs: function (e) { 13607 this.latlngs = [e.layer._latlngs]; 13608 if (e.layer._holes) { 13609 this.latlngs = this.latlngs.concat(e.layer._holes) 13610 } 13611 } 13612}); 13613L.Edit.PolyVerticesEdit = L.Handler.extend({ 13614 options: { 13615 icon: new L.DivIcon({ 13616 iconSize: new L.Point(8, 8), 13617 className: 'leaflet-div-icon leaflet-editing-icon' 13618 }), 13619 touchIcon: new L.DivIcon({ 13620 iconSize: new L.Point(20, 20), 13621 className: 'leaflet-div-icon leaflet-editing-icon leaflet-touch-icon' 13622 }), 13623 drawError: { 13624 color: '#b00b00', 13625 timeout: 1000 13626 } 13627 }, 13628 initialize: function (poly, latlngs, options) { 13629 if (L.Browser.touch) { 13630 this.options.icon = this.options.touchIcon 13631 } 13632 this._poly = poly; 13633 if (options && options.drawError) { 13634 options.drawError = L.Util.extend({}, this.options.drawError, options.drawError) 13635 } 13636 this._latlngs = latlngs; 13637 L.setOptions(this, options) 13638 }, 13639 _defaultShape: function () { 13640 if (!L.Polyline._flat) { 13641 return this._latlngs 13642 } 13643 return L.Polyline._flat(this._latlngs) ? this._latlngs : this._latlngs[0] 13644 }, 13645 addHooks: function () { 13646 var poly = this._poly; 13647 var path = poly._path; 13648 if (!(poly instanceof L.Polygon)) { 13649 poly.options.fill = !1; 13650 if (poly.options.editing) { 13651 poly.options.editing.fill = !1 13652 } 13653 } 13654 if (path) { 13655 if (poly.options.editing && poly.options.editing.className) { 13656 if (poly.options.original.className) { 13657 poly.options.original.className.split(' ').forEach(function (className) { 13658 L.DomUtil.removeClass(path, className) 13659 }) 13660 } 13661 poly.options.editing.className.split(' ').forEach(function (className) { 13662 L.DomUtil.addClass(path, className) 13663 }) 13664 } 13665 } 13666 poly.setStyle(poly.options.editing); 13667 if (this._poly._map) { 13668 this._map = this._poly._map; 13669 if (!this._markerGroup) { 13670 this._initMarkers() 13671 } 13672 this._poly._map.addLayer(this._markerGroup) 13673 } 13674 }, 13675 removeHooks: function () { 13676 var poly = this._poly; 13677 var path = poly._path; 13678 if (path) { 13679 if (poly.options.editing && poly.options.editing.className) { 13680 poly.options.editing.className.split(' ').forEach(function (className) { 13681 L.DomUtil.removeClass(path, className) 13682 }); 13683 if (poly.options.original.className) { 13684 poly.options.original.className.split(' ').forEach(function (className) { 13685 L.DomUtil.addClass(path, className) 13686 }) 13687 } 13688 } 13689 } 13690 poly.setStyle(poly.options.original); 13691 if (poly._map) { 13692 poly._map.removeLayer(this._markerGroup); 13693 delete this._markerGroup; 13694 delete this._markers 13695 } 13696 }, 13697 updateMarkers: function () { 13698 this._markerGroup.clearLayers(); 13699 this._initMarkers() 13700 }, 13701 _initMarkers: function () { 13702 if (!this._markerGroup) { 13703 this._markerGroup = new L.LayerGroup() 13704 } 13705 this._markers = []; 13706 var latlngs = this._defaultShape(), i, j, len, marker; 13707 for (i = 0, 13708 len = latlngs.length; i < len; i++) { 13709 marker = this._createMarker(latlngs[i], i); 13710 marker.on('click', this._onMarkerClick, this); 13711 marker.on('contextmenu', this._onContextMenu, this); 13712 this._markers.push(marker) 13713 } 13714 var markerLeft, markerRight; 13715 for (i = 0, 13716 j = len - 1; i < len; j = i++) { 13717 if (i === 0 && !(L.Polygon && (this._poly instanceof L.Polygon))) { 13718 continue 13719 } 13720 markerLeft = this._markers[j]; 13721 markerRight = this._markers[i];
13722 this._createMiddleMarker(markerLeft, markerRight); 13723 this._updatePrevNext(markerLeft, markerRight) 13724 } 13725 }, 13726 _createMarker: function (latlng, index) { 13727 var marker = new L.Marker.Touch(latlng, { 13728 draggable: !0, 13729 icon: this.options.icon, 13730 }); 13731 marker._origLatLng = latlng; 13732 marker._index = index; 13733 marker.on('dragstart', this._onMarkerDragStart, this).on('drag', this._onMarkerDrag, this).on('dragend', this._fireEdit, this).on('touchmove', this._onTouchMove, this).on('touchend', this._fireEdit, this).on('MSPointerMove', this._onTouchMove, this).on('MSPointerUp', this._fireEdit, this); 13734 this._markerGroup.addLayer(marker); 13735 return marker 13736 }, 13737 _onMarkerDragStart: function () { 13738 this._poly.fire('editstart') 13739 }, 13740 _spliceLatLngs: function () { 13741 var latlngs = this._defaultShape(); 13742 var removed = [].splice.apply(latlngs, arguments); 13743 this._poly._convertLatLngs(latlngs, !0); 13744 this._poly.redraw(); 13745 return removed 13746 }, 13747 _removeMarker: function (marker) { 13748 var i = marker._index; 13749 this._markerGroup.removeLayer(marker); 13750 this._markers.splice(i, 1); 13751 this._spliceLatLngs(i, 1); 13752 this._updateIndexes(i, -1); 13753 marker.off('dragstart', this._onMarkerDragStart, this).off('drag', this._onMarkerDrag, this).off('dragend', this._fireEdit, this).off('touchmove', this._onMarkerDrag, this).off('touchend', this._fireEdit, this).off('click', this._onMarkerClick, this).off('MSPointerMove', this._onTouchMove, this).off('MSPointerUp', this._fireEdit, this) 13754 }, 13755 _fireEdit: function () { 13756 this._poly.edited = !0; 13757 this._poly.fire('edit'); 13758 this._poly._map.fire(L.Draw.Event.EDITVERTEX, { 13759 layers: this._markerGroup, 13760 poly: this._poly 13761 }) 13762 }, 13763 _onMarkerDrag: function (e) { 13764 var marker = e.target; 13765 var poly = this._poly; 13766 var oldOrigLatLng = L.LatLngUtil.cloneLatLng(marker._origLatLng); 13767 L.extend(marker._origLatLng, marker._latlng); 13768 if (poly.options.poly) { 13769 var tooltip = poly._map._editTooltip; 13770 if (!poly.options.poly.allowIntersection && poly.intersects()) { 13771 L.extend(marker._origLatLng, oldOrigLatLng); 13772 marker.setLatLng(oldOrigLatLng); 13773 var originalColor = poly.options.color; 13774 poly.setStyle({ 13775 color: this.options.drawError.color 13776 }); 13777 if (tooltip) { 13778 tooltip.updateContent({ 13779 text: L.drawLocal.draw.handlers.polyline.error 13780 }) 13781 } 13782 setTimeout(function () { 13783 poly.setStyle({ 13784 color: originalColor 13785 }); 13786 if (tooltip) { 13787 tooltip.updateContent({ 13788 text: L.drawLocal.edit.handlers.edit.tooltip.text, 13789 subtext: L.drawLocal.edit.handlers.edit.tooltip.subtext 13790 }) 13791 } 13792 }, 1000) 13793 } 13794 } 13795 if (marker._middleLeft) { 13796 marker._middleLeft.setLatLng(this._getMiddleLatLng(marker._prev, marker)) 13797 } 13798 if (marker._middleRight) { 13799 marker._middleRight.setLatLng(this._getMiddleLatLng(marker, marker._next)) 13800 } 13801 this._poly._bounds._southWest = L.latLng(Infinity, Infinity); 13802 this._poly._bounds._northEast = L.latLng(-Infinity, -Infinity); 13803 var latlngs = this._poly.getLatLngs(); 13804 this._poly._convertLatLngs(latlngs, !0); 13805 this._poly.redraw(); 13806 this._poly.fire('editdrag') 13807 }, 13808 _onMarkerClick: function (e) { 13809 var minPoints = L.Polygon && (this._poly instanceof L.Polygon) ? 4 : 3 13810 , marker = e.target; 13811 if (this._defaultShape().length < minPoints) { 13812 return 13813 } 13814 this._removeMarker(marker); 13815 this._updatePrevNext(marker._prev, marker._next); 13816 if (marker._middleLeft) { 13817 this._markerGroup.removeLayer(marker._middleLeft) 13818 } 13819 if (marker._middleRight) { 13820 this._markerGroup.removeLayer(marker._middleRight) 13821 } 13822 if (marker._prev && marker._next) { 13823 this._createMiddleMarker(marker._prev, marker._next) 13824 } else if (!marker._prev) { 13825 marker._next._middleLeft = null 13826 } else if (!marker._next) { 13827 marker._prev._middleRight = null 13828 } 13829 this._fireEdit() 13830 }, 13831 _onContextMenu: function (e) { 13832 var marker = e.target; 13833 var poly = this._poly; 13834 this._poly._map.fire(L.Draw.Event.MARKERCONTEXT, { 13835 marker: marker, 13836 layers: this._markerGroup, 13837 poly: this._poly 13838 });
13839 L.DomEvent.stopPropagation 13840 }, 13841 _onTouchMove: function (e) { 13842 var layerPoint = this._map.mouseEventToLayerPoint(e.originalEvent.touches[0]) 13843 , latlng = this._map.layerPointToLatLng(layerPoint) 13844 , marker = e.target; 13845 L.extend(marker._origLatLng, latlng); 13846 if (marker._middleLeft) { 13847 marker._middleLeft.setLatLng(this._getMiddleLatLng(marker._prev, marker)) 13848 } 13849 if (marker._middleRight) { 13850 marker._middleRight.setLatLng(this._getMiddleLatLng(marker, marker._next)) 13851 } 13852 this._poly.redraw(); 13853 this.updateMarkers() 13854 }, 13855 _updateIndexes: function (index, delta) { 13856 this._markerGroup.eachLayer(function (marker) { 13857 if (marker._index > index) { 13858 marker._index += delta 13859 } 13860 }) 13861 }, 13862 _createMiddleMarker: function (marker1, marker2) { 13863 var latlng = this._getMiddleLatLng(marker1, marker2), marker = this._createMarker(latlng), onClick, onDragStart, onDragEnd; 13864 marker.setOpacity(0.6); 13865 marker1._middleRight = marker2._middleLeft = marker; 13866 onDragStart = function () { 13867 marker.off('touchmove', onDragStart, this); 13868 var i = marker2._index; 13869 marker._index = i; 13870 marker.off('click', onClick, this).on('click', this._onMarkerClick, this); 13871 latlng.lat = marker.getLatLng().lat; 13872 latlng.lng = marker.getLatLng().lng; 13873 this._spliceLatLngs(i, 0, latlng); 13874 this._markers.splice(i, 0, marker); 13875 marker.setOpacity(1); 13876 this._updateIndexes(i, 1); 13877 marker2._index++; 13878 this._updatePrevNext(marker1, marker); 13879 this._updatePrevNext(marker, marker2); 13880 this._poly.fire('editstart') 13881 } 13882 ; 13883 onDragEnd = function () { 13884 marker.off('dragstart', onDragStart, this); 13885 marker.off('dragend', onDragEnd, this); 13886 marker.off('touchmove', onDragStart, this); 13887 this._createMiddleMarker(marker1, marker); 13888 this._createMiddleMarker(marker, marker2) 13889 } 13890 ; 13891 onClick = function () { 13892 onDragStart.call(this); 13893 onDragEnd.call(this); 13894 this._fireEdit() 13895 } 13896 ; 13897 marker.on('click', onClick, this).on('dragstart', onDragStart, this).on('dragend', onDragEnd, this).on('touchmove', onDragStart, this); 13898 this._markerGroup.addLayer(marker) 13899 }, 13900 _updatePrevNext: function (marker1, marker2) { 13901 if (marker1) { 13902 marker1._next = marker2 13903 } 13904 if (marker2) { 13905 marker2._prev = marker1 13906 } 13907 }, 13908 _getMiddleLatLng: function (marker1, marker2) { 13909 var map = this._poly._map 13910 , p1 = map.project(marker1.getLatLng()) 13911 , p2 = map.project(marker2.getLatLng()); 13912 return map.unproject(p1._add(p2)._divideBy(2)) 13913 } 13914}); 13915L.Polyline.addInitHook(function () { 13916 if (this.editing) { 13917 return 13918 } 13919 if (L.Edit.Poly) { 13920 this.editing = new L.Edit.Poly(this); 13921 if (this.options.editable) { 13922 this.editing.enable() 13923 } 13924 } 13925 this.on('add', function () { 13926 if (this.editing && this.editing.enabled()) { 13927 this.editing.addHooks() 13928 } 13929 }); 13930 this.on('remove', function () { 13931 if (this.editing && this.editing.enabled()) { 13932 this.editing.removeHooks() 13933 } 13934 }) 13935}); 13936L.Edit = L.Edit || {}; 13937L.Edit.SimpleShape = L.Handler.extend({ 13938 options: { 13939 moveIcon: new L.DivIcon({ 13940 iconSize: new L.Point(8, 8), 13941 className: 'leaflet-div-icon leaflet-editing-icon leaflet-edit-move' 13942 }), 13943 resizeIcon: new L.DivIcon({ 13944 iconSize: new L.Point(8, 8), 13945 className: 'leaflet-div-icon leaflet-editing-icon leaflet-edit-resize' 13946 }), 13947 touchMoveIcon: new L.DivIcon({ 13948 iconSize: new L.Point(20, 20), 13949 className: 'leaflet-div-icon leaflet-editing-icon leaflet-edit-move leaflet-touch-icon' 13950 }), 13951 touchResizeIcon: new L.DivIcon({ 13952 iconSize: new L.Point(20, 20), 13953 className: 'leaflet-div-icon leaflet-editing-icon leaflet-edit-resize leaflet-touch-icon' 13954 }), 13955 }, 13956 initialize: function (shape, options) { 13957 if (L.Browser.touch) { 13958 this.options.moveIcon = this.options.touchMoveIcon; 13959 this.options.resizeIcon = this.options.touchResizeIcon 13960 } 13961 this._shape = shape; 13962 L.Util.setOptions(this, options) 13963 }, 13964 addHooks: function () { 13965 var shape = this._shape; 13966 if (this._shape._map) { 13967 this._map = this._shape._map; 13968 shape.setStyle(shape.options.editing); 13969 if (shape._map) { 13970 this._map = shape._map; 13971 if (!this._markerGroup) { 13972 this._initMarkers() 13973 } 13974 this._map.addLayer(this._markerGroup) 13975 } 13976 } 13977 }, 13978 removeHooks: function () { 13979 var shape = this._shape; 13980 shape.setStyle(shape.options.original); 13981 if (shape._map) { 13982 this._unbindMarker(this._moveMarker); 13983 for (var i = 0, l = this._resizeMarkers.length; i < l; i++) { 13984 this._unbindMarker(this._resizeMarkers[i]) 13985 } 13986 this._resizeMarkers = null; 13987 this._map.removeLayer(this._markerGroup); 13988 delete this._markerGroup 13989 } 13990 this._map = null 13991 }, 13992 updateMarkers: function () { 13993 this._markerGroup.clearLayers(); 13994 this._initMarkers() 13995 }, 13996 _initMarkers: function () { 13997 if (!this._markerGroup) { 13998 this._markerGroup = new L.LayerGroup() 13999 } 14000 this._createMoveMarker(); 14001 this._createResizeMarker() 14002 }, 14003 _createMoveMarker: function () { }, 14004 _createResizeMarker: function () { }, 14005 _createMarker: function (latlng, icon) { 14006 var marker = new L.Marker.Touch(latlng, { 14007 draggable: !0, 14008 icon: icon, 14009 zIndexOffset: 10 14010 });
14011 this._bindMarker(marker); 14012 this._markerGroup.addLayer(marker); 14013 return marker 14014 }, 14015 _bindMarker: function (marker) { 14016 marker.on('dragstart', this._onMarkerDragStart, this).on('drag', this._onMarkerDrag, this).on('dragend', this._onMarkerDragEnd, this).on('touchstart', this._onTouchStart, this).on('touchmove', this._onTouchMove, this).on('MSPointerMove', this._onTouchMove, this).on('touchend', this._onTouchEnd, this).on('MSPointerUp', this._onTouchEnd, this) 14017 }, 14018 _unbindMarker: function (marker) { 14019 marker.off('dragstart', this._onMarkerDragStart, this).off('drag', this._onMarkerDrag, this).off('dragend', this._onMarkerDragEnd, this).off('touchstart', this._onTouchStart, this).off('touchmove', this._onTouchMove, this).off('MSPointerMove', this._onTouchMove, this).off('touchend', this._onTouchEnd, this).off('MSPointerUp', this._onTouchEnd, this) 14020 }, 14021 _onMarkerDragStart: function (e) { 14022 var marker = e.target; 14023 marker.setOpacity(0); 14024 this._shape.fire('editstart') 14025 }, 14026 _fireEdit: function () { 14027 this._shape.edited = !0; 14028 this._shape.fire('edit') 14029 }, 14030 _onMarkerDrag: function (e) { 14031 var marker = e.target 14032 , latlng = marker.getLatLng(); 14033 if (marker === this._moveMarker) { 14034 this._move(latlng) 14035 } else { 14036 this._resize(latlng) 14037 } 14038 this._shape.redraw(); 14039 this._shape.fire('editdrag') 14040 }, 14041 _onMarkerDragEnd: function (e) { 14042 var marker = e.target; 14043 marker.setOpacity(1); 14044 this._fireEdit() 14045 }, 14046 _onTouchStart: function (e) { 14047 L.Edit.SimpleShape.prototype._onMarkerDragStart.call(this, e); 14048 if (typeof (this._getCorners) === 'function') { 14049 var corners = this._getCorners() 14050 , marker = e.target 14051 , currentCornerIndex = marker._cornerIndex; 14052 marker.setOpacity(0); 14053 this._oppositeCorner = corners[(currentCornerIndex + 2) % 4]; 14054 this._toggleCornerMarkers(0, currentCornerIndex) 14055 } 14056 this._shape.fire('editstart') 14057 }, 14058 _onTouchMove: function (e) { 14059 var layerPoint = this._map.mouseEventToLayerPoint(e.originalEvent.touches[0]) 14060 , latlng = this._map.layerPointToLatLng(layerPoint) 14061 , marker = e.target; 14062 if (marker === this._moveMarker) { 14063 this._move(latlng) 14064 } else { 14065 this._resize(latlng) 14066 } 14067 this._shape.redraw(); 14068 return !1 14069 }, 14070 _onTouchEnd: function (e) { 14071 var marker = e.target; 14072 marker.setOpacity(1); 14073 this.updateMarkers(); 14074 this._fireEdit() 14075 }, 14076 _move: function () { }, 14077 _resize: function () { } 14078}); 14079L.Edit = L.Edit || {}; 14080L.Edit.Marker = L.Handler.extend({ 14081 initialize: function (marker, options) { 14082 this._marker = marker; 14083 L.setOptions(this, options) 14084 }, 14085 addHooks: function () { 14086 var marker = this._marker; 14087 marker.dragging.enable(); 14088 marker.on('dragend', this._onDragEnd, marker); 14089 this._toggleMarkerHighlight() 14090 }, 14091 removeHooks: function () { 14092 var marker = this._marker; 14093 marker.dragging.disable(); 14094 marker.off('dragend', this._onDragEnd, marker); 14095 this._toggleMarkerHighlight() 14096 }, 14097 _onDragEnd: function (e) { 14098 var layer = e.target; 14099 layer.edited = !0; 14100 this._map.fire(L.Draw.Event.EDITMOVE, { 14101 layer: layer 14102 }) 14103 }, 14104 _toggleMarkerHighlight: function () { 14105 var icon = this._marker._icon; 14106 if (!icon) { 14107 return 14108 } 14109 icon.style.display = 'none'; 14110 if (L.DomUtil.hasClass(icon, 'leaflet-edit-marker-selected')) { 14111 L.DomUtil.removeClass(icon, 'leaflet-edit-marker-selected'); 14112 this._offsetMarker(icon, -4) 14113 } else { 14114 L.DomUtil.addClass(icon, 'leaflet-edit-marker-selected'); 14115 this._offsetMarker(icon, 4) 14116 } 14117 icon.style.display = '' 14118 }, 14119 _offsetMarker: function (icon, offset) { 14120 var iconMarginTop = parseInt(icon.style.marginTop, 10) - offset 14121 , iconMarginLeft = parseInt(icon.style.marginLeft, 10) - offset; 14122 icon.style.marginTop = iconMarginTop + 'px'; 14123 icon.style.marginLeft = iconMarginLeft + 'px' 14124 } 14125}); 14126L.Marker.addInitHook(function () { 14127 if (L.Edit.Marker) { 14128 this.editing = new L.Edit.Marker(this); 14129 if (this.options.editable) { 14130 this.editing.enable() 14131 } 14132 } 14133}); 14134L.Edit = L.Edit || {}; 14135L.Edit.CircleMarker = L.Edit.SimpleShape.extend({ 14136 _createMoveMarker: function () { 14137 var center = this._shape.getLatLng(); 14138 this._moveMarker = this._createMarker(center, this.options.moveIcon) 14139 }, 14140 _createResizeMarker: function () { 14141 this._resizeMarkers = [] 14142 }, 14143 _move: function (latlng) { 14144 if (this._resizeMarkers.length) { 14145 var resizemarkerPoint = this._getResizeMarkerPoint(latlng); 14146 this._resizeMarkers[0].setLatLng(resizemarkerPoint) 14147 } 14148 this._shape.setLatLng(latlng); 14149 this._map.fire(L.Draw.Event.EDITMOVE, { 14150 layer: this._shape 14151 }) 14152 }, 14153}); 14154L.CircleMarker.addInitHook(function () { 14155 if (L.Edit.CircleMarker) { 14156 this.editing = new L.Edit.CircleMarker(this); 14157 if (this.options.editable) { 14158 this.editing.enable() 14159 } 14160 } 14161 this.on('add', function () { 14162 if (this.editing && this.editing.enabled()) { 14163 this.editing.addHooks() 14164 } 14165 }); 14166 this.on('remove', function () { 14167 if (this.editing && this.editing.enabled()) { 14168 this.editing.removeHooks() 14169 } 14170 }) 14171}); 14172L.Edit = L.Edit || {}; 14173L.Edit.Circle = L.Edit.CircleMarker.extend({ 14174 _createResizeMarker: function () { 14175 var center = this._shape.getLatLng() 14176 , resizemarkerPoint = this._getResizeMarkerPoint(center); 14177 this._resizeMarkers = []; 14178 this._resizeMarkers.push(this._createMarker(resizemarkerPoint, this.options.resizeIcon)) 14179 }, 14180 _getResizeMarkerPoint: function (latlng) { 14181 var delta = this._shape._radius * Math.cos(Math.PI / 4) 14182 , point = this._map.project(latlng); 14183 return this._map.unproject([point.x + delta, point.y - delta]) 14184 }, 14185 _resize: function (latlng) { 14186 var moveLatLng = this._moveMarker.getLatLng(); 14187 if (L.GeometryUtil.isVersion07x()) { 14188 radius = moveLatLng.distanceTo(latlng) 14189 } else { 14190 radius = this._map.distance(moveLatLng, latlng) 14191 } 14192 this._shape.setRadius(radius); 14193 if (this._map.editTooltip) { 14194 this._map._editTooltip.updateContent({ 14195 text: L.drawLocal.edit.handlers.edit.tooltip.subtext + '<br />' + L.drawLocal.edit.handlers.edit.tooltip.text, 14196 subtext: L.drawLocal.draw.handlers.circle.radius + ': ' + L.GeometryUtil.readableDistance(radius, !0, this.options.feet, this.options.nautic) 14197 }) 14198 } 14199 this._shape.setRadius(radius); 14200 this._map.fire(L.Draw.Event.EDITRESIZE, { 14201 layer: this._shape 14202 }) 14203 } 14204}); 14205L.Circle.addInitHook(function () { 14206 if (L.Edit.Circle) { 14207 this.editing = new L.Edit.Circle(this); 14208 if (this.options.editable) { 14209 this.editing.enable() 14210 } 14211 } 14212}); 14213L.Edit = L.Edit || {}; 14214L.Edit.Rectangle = L.Edit.SimpleShape.extend({ 14215 _createMoveMarker: function () { 14216 var bounds = this._shape.getBounds() 14217 , center = bounds.getCenter(); 14218 this._moveMarker = this._createMarker(center, this.options.moveIcon) 14219 }, 14220 _createResizeMarker: function () { 14221 var corners = this._getCorners(); 14222 this._resizeMarkers = []; 14223 for (var i = 0, l = corners.length; i < l; i++) { 14224 this._resizeMarkers.push(this._createMarker(corners[i], this.options.resizeIcon)); 14225 this._resizeMarkers[i]._cornerIndex = i 14226 } 14227 }, 14228 _onMarkerDragStart: function (e) { 14229 L.Edit.SimpleShape.prototype._onMarkerDragStart.call(this, e); 14230 var corners = this._getCorners() 14231 , marker = e.target 14232 , currentCornerIndex = marker._cornerIndex; 14233 this._oppositeCorner = corners[(currentCornerIndex + 2) % 4]; 14234 this._toggleCornerMarkers(0, currentCornerIndex) 14235 }, 14236 _onMarkerDragEnd: function (e) { 14237 var marker = e.target, bounds, center; 14238 if (marker === this._moveMarker) { 14239 bounds = this._shape.getBounds(); 14240 center = bounds.getCenter(); 14241 marker.setLatLng(center) 14242 } 14243 this._toggleCornerMarkers(1); 14244 this._repositionCornerMarkers(); 14245 L.Edit.SimpleShape.prototype._onMarkerDragEnd.call(this, e) 14246 }, 14247 _move: function (newCenter) { 14248 var latlngs = this._shape._defaultShape ? this._shape._defaultShape() : this._shape.getLatLngs(), bounds = this._shape.getBounds(), center = bounds.getCenter(), offset, newLatLngs = []; 14249 for (var i = 0, l = latlngs.length; i < l; i++) { 14250 offset = [latlngs[i].lat - center.lat, latlngs[i].lng - center.lng]; 14251 newLatLngs.push([newCenter.lat + offset[0], newCenter.lng + offset[1]]) 14252 } 14253 this._shape.setLatLngs(newLatLngs); 14254 this._repositionCornerMarkers(); 14255 this._map.fire(L.Draw.Event.EDITMOVE, { 14256 layer: this._shape 14257 }) 14258 }, 14259 _resize: function (latlng) { 14260 var bounds; 14261 this._shape.setBounds(L.latLngBounds(latlng, this._oppositeCorner)); 14262 bounds = this._shape.getBounds(); 14263 this._moveMarker.setLatLng(bounds.getCenter()); 14264 this._map.fire(L.Draw.Event.EDITRESIZE, { 14265 layer: this._shape 14266 }) 14267 }, 14268 _getCorners: function () { 14269 var bounds = this._shape.getBounds() 14270 , nw = bounds.getNorthWest() 14271 , ne = bounds.getNorthEast() 14272 , se = bounds.getSouthEast()
14273 , sw = bounds.getSouthWest(); 14274 return [nw, ne, se, sw] 14275 }, 14276 _toggleCornerMarkers: function (opacity) { 14277 for (var i = 0, l = this._resizeMarkers.length; i < l; i++) { 14278 this._resizeMarkers[i].setOpacity(opacity) 14279 } 14280 }, 14281 _repositionCornerMarkers: function () { 14282 var corners = this._getCorners(); 14283 for (var i = 0, l = this._resizeMarkers.length; i < l; i++) { 14284 this._resizeMarkers[i].setLatLng(corners[i]) 14285 } 14286 } 14287}); 14288L.Rectangle.addInitHook(function () { 14289 if (L.Edit.Rectangle) { 14290 this.editing = new L.Edit.Rectangle(this); 14291 if (this.options.editable) { 14292 this.editing.enable() 14293 } 14294 } 14295}) 14296 14297/*! Version: 0.66.1 14298Copyright (c) 2016 Dominik Moritz */ 14299 14300!function (t, i) { 14301 "function" == typeof define && define.amd ? define(["leaflet"], t) : "object" == typeof exports && (void 0 !== i && i.L ? module.exports = t(L) : module.exports = t(require("leaflet"))), 14302 void 0 !== i && i.L && (i.L.Control.Locate = t(L)) 14303}(function (h) { 14304 var o = function (i, o, t) { 14305 (t = t.split(" ")).forEach(function (t) { 14306 h.DomUtil[i].call(this, o, t) 14307 }) 14308 } 14309 , i = function (t, i) { 14310 o("addClass", t, i) 14311 } 14312 , s = function (t, i) { 14313 o("removeClass", t, i) 14314 } 14315 , t = h.Marker.extend({ 14316 initialize: function (t, i) { 14317 h.Util.setOptions(this, i), 14318 this._latlng = t, 14319 this.createIcon() 14320 }, 14321 createIcon: function () { 14322 var t = this.options 14323 , i = ""; 14324 void 0 !== t.color && (i += "stroke:" + t.color + ";"), 14325 void 0 !== t.weight && (i += "stroke-width:" + t.weight + ";"), 14326 void 0 !== t.fillColor && (i += "fill:" + t.fillColor + ";"), 14327 void 0 !== t.fillOpacity && (i += "fill-opacity:" + t.fillOpacity + ";"), 14328 void 0 !== t.opacity && (i += "opacity:" + t.opacity + ";"); 14329 var o = this._getIconSVG(t, i); 14330 this._locationIcon = h.divIcon({ 14331 className: o.className, 14332 html: o.svg, 14333 iconSize: [o.w, o.h] 14334 }), 14335 this.setIcon(this._locationIcon) 14336 }, 14337 _getIconSVG: function (t, i) { 14338 var o = t.radius 14339 , s = o + t.weight 14340 , e = 2 * s; 14341 return { 14342 className: "leaflet-control-locate-location", 14343 svg: '<svg xmlns="http://www.w3.org/2000/svg" width="' + e + '" height="' + e + '" version="1.1" viewBox="-' + s + " -" + s + " " + e + " " + e + '"><circle r="' + o + '" style="' + i + '" /></svg>', 14344 w: e, 14345 h: e 14346 } 14347 }, 14348 setStyle: function (t) { 14349 h.Util.setOptions(this, t), 14350 this.createIcon() 14351 } 14352 }) 14353 , e = t.extend({ 14354 initialize: function (t, i, o) { 14355 h.Util.setOptions(this, o), 14356 this._latlng = t, 14357 this._heading = i, 14358 this.createIcon() 14359 }, 14360 setHeading: function (t) { 14361 this._heading = t 14362 }, 14363 _getIconSVG: function (t, i) { 14364 var o = t.radius 14365 , s = t.width + t.weight 14366 , e = 2 * (o + t.depth + t.weight) 14367 , n = "M0,0 l" + t.width / 2 + "," + t.depth + " l-" + s + ",0 z"; 14368 return { 14369 className: "leafet-control-locate-heading", 14370 svg: '<svg xmlns="http://www.w3.org/2000/svg" width="' + s + '" height="' + e + '" version="1.1" viewBox="-' + s / 2 + " 0 " + s + " " + e + '" style="' + ("transform: rotate(" + this._heading + "deg)") + '"><path d="' + n + '" style="' + i + '" /></svg>', 14371 w: s, 14372 h: e 14373 } 14374 } 14375 }) 14376 , n = h.Control.extend({ 14377 options: { 14378 position: "topleft", 14379 layer: void 0, 14380 setView: "untilPanOrZoom", 14381 keepCurrentZoomLevel: !1, 14382 getLocationBounds: function (t) { 14383 return t.bounds 14384 }, 14385 flyTo: !1, 14386 clickBehavior: { 14387 inView: "stop", 14388 outOfView: "setView", 14389 inViewNotFollowing: "inView" 14390 }, 14391 returnToPrevBounds: !1, 14392 cacheLocation: !0, 14393 drawCircle: !0, 14394 drawMarker: !0, 14395 showCompass: !0, 14396 markerClass: t, 14397 compassClass: e, 14398 circleStyle: { 14399 className: "leaflet-control-locate-circle", 14400 color: "#136AEC", 14401 fillColor: "#136AEC", 14402 fillOpacity: .15, 14403 weight: 0 14404 }, 14405 markerStyle: { 14406 className: "leaflet-control-locate-marker", 14407 color: "#fff", 14408 fillColor: "#2A93EE", 14409 fillOpacity: 1, 14410 weight: 3, 14411 opacity: 1, 14412 radius: 9 14413 }, 14414 compassStyle: { 14415 fillColor: "#2A93EE", 14416 fillOpacity: 1, 14417 weight: 0, 14418 color: "#fff", 14419 opacity: 1, 14420 radius: 9, 14421 width: 9, 14422 depth: 6 14423 }, 14424 followCircleStyle: {}, 14425 followMarkerStyle: {}, 14426 followCompassStyle: {}, 14427 icon: "fa fa-map-marker", 14428 iconLoading: "fa fa-spinner fa-spin", 14429 iconElementTag: "span", 14430 circlePadding: [0, 0], 14431 metric: !0, 14432 createButtonCallback: function (t, i) { 14433 var o = h.DomUtil.create("a", "leaflet-bar-part leaflet-bar-part-single", t); 14434 return o.title = i.strings.title, 14435 { 14436 link: o, 14437 icon: h.DomUtil.create(i.iconElementTag, i.icon, o) 14438 } 14439 }, 14440 onLocationError: function (t, i) { 14441 alert(t.message) 14442 }, 14443 onLocationOutsideMapBounds: function (t) { 14444 t.stop(), 14445 alert(t.options.strings.outsideMapBoundsMsg) 14446 }, 14447 showPopup: !0,
14448 strings: { 14449 title: "Show me where I am", 14450 metersUnit: "meters", 14451 feetUnit: "feet", 14452 popup: "You are within {distance} {unit} from this point", 14453 outsideMapBoundsMsg: "You seem located outside the boundaries of the map" 14454 }, 14455 locateOptions: { 14456 maxZoom: 1 / 0, 14457 watch: !0, 14458 setView: !1 14459 } 14460 }, 14461 initialize: function (t) { 14462 for (var i in t) 14463 "object" == typeof this.options[i] ? h.extend(this.options[i], t[i]) : this.options[i] = t[i]; 14464 this.options.followMarkerStyle = h.extend({}, this.options.markerStyle, this.options.followMarkerStyle), 14465 this.options.followCircleStyle = h.extend({}, this.options.circleStyle, this.options.followCircleStyle), 14466 this.options.followCompassStyle = h.extend({}, this.options.compassStyle, this.options.followCompassStyle) 14467 }, 14468 onAdd: function (t) { 14469 var i = h.DomUtil.create("div", "leaflet-control-locate leaflet-bar leaflet-control"); 14470 this._layer = this.options.layer || new h.LayerGroup, 14471 this._layer.addTo(t), 14472 this._event = void 0, 14473 this._compassHeading = null, 14474 this._prevBounds = null; 14475 var o = this.options.createButtonCallback(i, this.options); 14476 return this._link = o.link, 14477 this._icon = o.icon, 14478 h.DomEvent.on(this._link, "click", h.DomEvent.stopPropagation).on(this._link, "click", h.DomEvent.preventDefault).on(this._link, "click", this._onClick, this).on(this._link, "dblclick", h.DomEvent.stopPropagation), 14479 this._resetVariables(), 14480 this._map.on("unload", this._unload, this), 14481 i 14482 }, 14483 _onClick: function () { 14484 this._justClicked = !0; 14485 var t = this._isFollowing(); 14486 if (this._userPanned = !1, 14487 this._userZoomed = !1, 14488 this._active && !this._event) 14489 this.stop(); 14490 else if (this._active && void 0 !== this._event) { 14491 var i = this.options.clickBehavior 14492 , o = i.outOfView; 14493 switch (this._map.getBounds().contains(this._event.latlng) && (o = t ? i.inView : i.inViewNotFollowing), 14494 i[o] && (o = i[o]), 14495 o) { 14496 case "setView": 14497 this.setView(); 14498 break; 14499 case "stop": 14500 if (this.stop(), 14501 this.options.returnToPrevBounds) 14502 (this.options.flyTo ? this._map.flyToBounds : this._map.fitBounds).bind(this._map)(this._prevBounds) 14503 } 14504 } else 14505 this.options.returnToPrevBounds && (this._prevBounds = this._map.getBounds()), 14506 this.start(); 14507 this._updateContainerStyle() 14508 }, 14509 start: function () { 14510 this._activate(), 14511 this._event && (this._drawMarker(this._map), 14512 this.options.setView && this.setView()), 14513 this._updateContainerStyle() 14514 }, 14515 stop: function () { 14516 this._deactivate(), 14517 this._cleanClasses(), 14518 this._resetVariables(), 14519 this._removeMarker() 14520 }, 14521 stopFollowing: function () { 14522 this._userPanned = !0, 14523 this._updateContainerStyle(), 14524 this._drawMarker() 14525 }, 14526 _activate: function () { 14527 this._active || (this._map.locate(this.options.locateOptions), 14528 this._active = !0, 14529 this._map.on("locationfound", this._onLocationFound, this), 14530 this._map.on("locationerror", this._onLocationError, this), 14531 this._map.on("dragstart", this._onDrag, this), 14532 this._map.on("zoomstart", this._onZoom, this), 14533 this._map.on("zoomend", this._onZoomEnd, this), 14534 this.options.showCompass && ("ondeviceorientationabsolute" in window ? h.DomEvent.on(window, "deviceorientationabsolute", this._onDeviceOrientation, this) : "ondeviceorientation" in window && h.DomEvent.on(window, "deviceorientation", this._onDeviceOrientation, this))) 14535 }, 14536 _deactivate: function () { 14537 this._map.stopLocate(), 14538 this._active = !1, 14539 this.options.cacheLocation || (this._event = void 0), 14540 this._map.off("locationfound", this._onLocationFound, this), 14541 this._map.off("locationerror", this._onLocationError, this), 14542 this._map.off("dragstart", this._onDrag, this), 14543 this._map.off("zoomstart", this._onZoom, this), 14544 this._map.off("zoomend", this._onZoomEnd, this), 14545 this.options.showCompass && (this._compassHeading = null, 14546 "ondeviceorientationabsolute" in window ? h.DomEvent.off(window, "deviceorientationabsolute", this._onDeviceOrientation, this) : "ondeviceorientation" in window && h.DomEvent.off(window, "deviceorientation", this._onDeviceOrientation, this)) 14547 },
14548 setView: function () { 14549 if (this._drawMarker(), 14550 this._isOutsideMapBounds()) 14551 this._event = void 0, 14552 this.options.onLocationOutsideMapBounds(this); 14553 else if (this.options.keepCurrentZoomLevel) { 14554 (t = this.options.flyTo ? this._map.flyTo : this._map.panTo).bind(this._map)([this._event.latitude, this._event.longitude]) 14555 } else { 14556 var t = this.options.flyTo ? this._map.flyToBounds : this._map.fitBounds; 14557 this._ignoreEvent = !0, 14558 t.bind(this._map)(this.options.getLocationBounds(this._event), { 14559 padding: this.options.circlePadding, 14560 maxZoom: this.options.locateOptions.maxZoom 14561 }), 14562 h.Util.requestAnimFrame(function () { 14563 this._ignoreEvent = !1 14564 }, this) 14565 } 14566 }, 14567 _drawCompass: function () { 14568 var t = this._event.latlng; 14569 if (this.options.showCompass && t && null !== this._compassHeading) { 14570 var i = this._isFollowing() ? this.options.followCompassStyle : this.options.compassStyle; 14571 this._compass ? (this._compass.setLatLng(t), 14572 this._compass.setHeading(this._compassHeading), 14573 this._compass.setStyle && this._compass.setStyle(i)) : this._compass = new this.options.compassClass(t, this._compassHeading, i).addTo(this._layer) 14574 } 14575 !this._compass || this.options.showCompass && null !== this._compassHeading || (this._compass.removeFrom(this._layer), 14576 this._compass = null) 14577 }, 14578 _drawMarker: function () { 14579 void 0 === this._event.accuracy && (this._event.accuracy = 0); 14580 var t, i, o = this._event.accuracy, s = this._event.latlng; 14581 if (this.options.drawCircle) { 14582 var e = this._isFollowing() ? this.options.followCircleStyle : this.options.circleStyle; 14583 this._circle ? this._circle.setLatLng(s).setRadius(o).setStyle(e) : this._circle = h.circle(s, o, e).addTo(this._layer) 14584 } 14585 if (i = this.options.metric ? (t = o.toFixed(0), 14586 this.options.strings.metersUnit) : (t = (3.2808399 * o).toFixed(0), 14587 this.options.strings.feetUnit), 14588 this.options.drawMarker) { 14589 var n = this._isFollowing() ? this.options.followMarkerStyle : this.options.markerStyle; 14590 this._marker ? (this._marker.setLatLng(s), 14591 this._marker.setStyle && this._marker.setStyle(n)) : this._marker = new this.options.markerClass(s, n).addTo(this._layer) 14592 } 14593 this._drawCompass(); 14594 var a = this.options.strings.popup; 14595 this.options.showPopup && a && this._marker && this._marker.bindPopup(h.Util.template(a, { 14596 distance: t, 14597 unit: i 14598 }))._popup.setLatLng(s), 14599 this.options.showPopup && a && this._compass && this._compass.bindPopup(h.Util.template(a, { 14600 distance: t, 14601 unit: i 14602 }))._popup.setLatLng(s) 14603 }, 14604 _removeMarker: function () { 14605 this._layer.clearLayers(), 14606 this._marker = void 0, 14607 this._circle = void 0 14608 }, 14609 _unload: function () { 14610 this.stop(), 14611 this._map.off("unload", this._unload, this) 14612 }, 14613 _setCompassHeading: function (t) { 14614 !isNaN(parseFloat(t)) && isFinite(t) ? (t = Math.round(t), 14615 this._compassHeading = t, 14616 h.Util.requestAnimFrame(this._drawCompass, this)) : this._compassHeading = null 14617 }, 14618 _onCompassNeedsCalibration: function () { 14619 this._setCompassHeading() 14620 }, 14621 _onDeviceOrientation: function (t) { 14622 this._active && (t.webkitCompassHeading ? this._setCompassHeading(t.webkitCompassHeading) : t.absolute && t.alpha && this._setCompassHeading(360 - t.alpha)) 14623 }, 14624 _onLocationError: function (t) { 14625 3 == t.code && this.options.locateOptions.watch || (this.stop(), 14626 this.options.onLocationError(t, this)) 14627 }, 14628 _onLocationFound: function (t) { 14629 if ((!this._event || this._event.latlng.lat !== t.latlng.lat || this._event.latlng.lng !== t.latlng.lng || this._event.accuracy !== t.accuracy) && this._active) { 14630 switch (this._event = t, 14631 this._drawMarker(), 14632 this._updateContainerStyle(), 14633 this.options.setView) { 14634 case "once": 14635 this._justClicked && this.setView(); 14636 break; 14637 case "untilPan": 14638 this._userPanned || this.setView(); 14639 break; 14640 case "untilPanOrZoom": 14641 this._userPanned || this._userZoomed || this.setView(); 14642 break; 14643 case "always": 14644 this.setView() 14645 } 14646 this._justClicked = !1 14647 } 14648 }, 14649 _onDrag: function () { 14650 this._event && !this._ignoreEvent && (this._userPanned = !0, 14651 this._updateContainerStyle(), 14652 this._drawMarker()) 14653 }, 14654 _onZoom: function () { 14655 this._event && !this._ignoreEvent && (this._userZoomed = !0, 14656 this._updateContainerStyle(), 14657 this._drawMarker()) 14658 }, 14659 _onZoomEnd: function () { 14660 this._event && this._drawCompass(), 14661 this._event && !this._ignoreEvent && this._marker && !this._map.getBounds().pad(-.3).contains(this._marker.getLatLng()) && (this._userPanned = !0, 14662 this._updateContainerStyle(), 14663 this._drawMarker()) 14664 }, 14665 _isFollowing: function () { 14666 return !!this._active && ("always" === this.options.setView || ("untilPan" === this.options.setView ? !this._userPanned : "untilPanOrZoom" === this.options.setView ? !this._userPanned && !this._userZoomed : void 0)) 14667 }, 14668 _isOutsideMapBounds: function () { 14669 return void 0 !== this._event && (this._map.options.maxBounds && !this._map.options.maxBounds.contains(this._event.latlng)) 14670 }, 14671 _updateContainerStyle: function () { 14672 this._container && (this._active && !this._event ? this._setClasses("requesting") : this._isFollowing() ? this._setClasses("following") : this._active ? this._setClasses("active") : this._cleanClasse
14672s()) 14673 }, 14674 _setClasses: function (t) { 14675 "requesting" == t ? (s(this._container, "active following"), 14676 i(this._container, "requesting"), 14677 s(this._icon, this.options.icon), 14678 i(this._icon, this.options.iconLoading)) : "active" == t ? (s(this._container, "requesting following"), 14679 i(this._container, "active"), 14680 s(this._icon, this.options.iconLoading), 14681 i(this._icon, this.options.icon)) : "following" == t && (s(this._container, "requesting"), 14682 i(this._container, "active following"), 14683 s(this._icon, this.options.iconLoading), 14684 i(this._icon, this.options.icon)) 14685 }, 14686 _cleanClasses: function () { 14687 h.DomUtil.removeClass(this._container, "requesting"), 14688 h.DomUtil.removeClass(this._container, "active"), 14689 h.DomUtil.removeClass(this._container, "following"), 14690 s(this._icon, this.options.iconLoading), 14691 i(this._icon, this.options.icon) 14692 }, 14693 _resetVariables: function () { 14694 this._active = !1, 14695 this._justClicked = !1, 14696 this._userPanned = !1, 14697 this._userZoomed = !1 14698 } 14699 }); 14700 return h.control.locate = function (t) { 14701 return new h.Control.Locate(t) 14702 } 14703 , 14704 n 14705}, window); 14706//# sourceMappingURL=L.Control.Locate.min.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.