1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | module.exports =
|
9 | (function(modules) {
|
10 |
|
11 | var installedModules = {};
|
12 |
|
13 |
|
14 | function __webpack_require__(moduleId) {
|
15 |
|
16 |
|
17 | if(installedModules[moduleId]) {
|
18 | return installedModules[moduleId].exports;
|
19 | }
|
20 |
|
21 | var module = installedModules[moduleId] = {
|
22 | i: moduleId,
|
23 | l: false,
|
24 | exports: {}
|
25 | };
|
26 |
|
27 |
|
28 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
29 |
|
30 |
|
31 | module.l = true;
|
32 |
|
33 |
|
34 | return module.exports;
|
35 | }
|
36 |
|
37 |
|
38 |
|
39 | __webpack_require__.m = modules;
|
40 |
|
41 |
|
42 | __webpack_require__.c = installedModules;
|
43 |
|
44 |
|
45 | __webpack_require__.d = function(exports, name, getter) {
|
46 | if(!__webpack_require__.o(exports, name)) {
|
47 | Object.defineProperty(exports, name, {
|
48 | configurable: false,
|
49 | enumerable: true,
|
50 | get: getter
|
51 | /******/ });
|
52 | /******/ }
|
53 | /******/ };
|
54 | /******/
|
55 | /******/ // getDefaultExport function for compatibility with non-harmony modules
|
56 | /******/ __webpack_require__.n = function(module) {
|
57 | var getter = module && module.__esModule ?
|
58 | function getDefault() { return module['default']; } :
|
59 | function getModuleExports() { return module; };
|
60 | __webpack_require__.d(getter, 'a', getter);
|
61 | return getter;
|
62 | };
|
63 |
|
64 |
|
65 | __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
66 |
|
67 |
|
68 | __webpack_require__.p = "";
|
69 |
|
70 |
|
71 | return __webpack_require__(__webpack_require__.s = 24);
|
72 | })
|
73 |
|
74 | ([
|
75 |
|
76 | (function(module, exports, __webpack_require__) {
|
77 |
|
78 | var freeGlobal = __webpack_require__(14);
|
79 |
|
80 |
|
81 | var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
82 |
|
83 |
|
84 | var root = freeGlobal || freeSelf || Function('return this')();
|
85 |
|
86 | module.exports = root;
|
87 |
|
88 |
|
89 | }),
|
90 |
|
91 | (function(module, exports, __webpack_require__) {
|
92 |
|
93 | var baseIsNative = __webpack_require__(38),
|
94 | getValue = __webpack_require__(43);
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | function getNative(object, key) {
|
105 | var value = getValue(object, key);
|
106 | return baseIsNative(value) ? value : undefined;
|
107 | }
|
108 |
|
109 | module.exports = getNative;
|
110 |
|
111 |
|
112 | }),
|
113 |
|
114 | (function(module, exports, __webpack_require__) {
|
115 |
|
116 | var listCacheClear = __webpack_require__(28),
|
117 | listCacheDelete = __webpack_require__(29),
|
118 | listCacheGet = __webpack_require__(30),
|
119 | listCacheHas = __webpack_require__(31),
|
120 | listCacheSet = __webpack_require__(32);
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | function ListCache(entries) {
|
130 | var index = -1,
|
131 | length = entries == null ? 0 : entries.length;
|
132 |
|
133 | this.clear();
|
134 | while (++index < length) {
|
135 | var entry = entries[index];
|
136 | this.set(entry[0], entry[1]);
|
137 | }
|
138 | }
|
139 |
|
140 |
|
141 | ListCache.prototype.clear = listCacheClear;
|
142 | ListCache.prototype['delete'] = listCacheDelete;
|
143 | ListCache.prototype.get = listCacheGet;
|
144 | ListCache.prototype.has = listCacheHas;
|
145 | ListCache.prototype.set = listCacheSet;
|
146 |
|
147 | module.exports = ListCache;
|
148 |
|
149 |
|
150 | }),
|
151 |
|
152 | (function(module, exports, __webpack_require__) {
|
153 |
|
154 | var eq = __webpack_require__(12);
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | function assocIndexOf(array, key) {
|
165 | var length = array.length;
|
166 | while (length--) {
|
167 | if (eq(array[length][0], key)) {
|
168 | return length;
|
169 | }
|
170 | }
|
171 | return -1;
|
172 | }
|
173 |
|
174 | module.exports = assocIndexOf;
|
175 |
|
176 |
|
177 | }),
|
178 |
|
179 | (function(module, exports, __webpack_require__) {
|
180 |
|
181 | var Symbol = __webpack_require__(9),
|
182 | getRawTag = __webpack_require__(39),
|
183 | objectToString = __webpack_require__(40);
|
184 |
|
185 |
|
186 | var nullTag = '[object Null]',
|
187 | undefinedTag = '[object Undefined]';
|
188 |
|
189 |
|
190 | var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 | function baseGetTag(value) {
|
200 | if (value == null) {
|
201 | return value === undefined ? undefinedTag : nullTag;
|
202 | }
|
203 | return (symToStringTag && symToStringTag in Object(value))
|
204 | ? getRawTag(value)
|
205 | : objectToString(value);
|
206 | }
|
207 |
|
208 | module.exports = baseGetTag;
|
209 |
|
210 |
|
211 | }),
|
212 |
|
213 | (function(module, exports, __webpack_require__) {
|
214 |
|
215 | var getNative = __webpack_require__(1);
|
216 |
|
217 |
|
218 | var nativeCreate = getNative(Object, 'create');
|
219 |
|
220 | module.exports = nativeCreate;
|
221 |
|
222 |
|
223 | }),
|
224 |
|
225 | (function(module, exports, __webpack_require__) {
|
226 |
|
227 | var isKeyable = __webpack_require__(52);
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 | function getMapData(map, key) {
|
238 | var data = map.__data__;
|
239 | return isKeyable(key)
|
240 | ? data[typeof key == 'string' ? 'string' : 'hash']
|
241 | : data.map;
|
242 | }
|
243 |
|
244 | module.exports = getMapData;
|
245 |
|
246 |
|
247 | }),
|
248 |
|
249 | (function(module, exports) {
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 | function isObjectLike(value) {
|
276 | return value != null && typeof value == 'object';
|
277 | }
|
278 |
|
279 | module.exports = isObjectLike;
|
280 |
|
281 |
|
282 | }),
|
283 |
|
284 | (function(module, exports, __webpack_require__) {
|
285 |
|
286 | var getNative = __webpack_require__(1),
|
287 | root = __webpack_require__(0);
|
288 |
|
289 |
|
290 | var Map = getNative(root, 'Map');
|
291 |
|
292 | module.exports = Map;
|
293 |
|
294 |
|
295 | }),
|
296 |
|
297 | (function(module, exports, __webpack_require__) {
|
298 |
|
299 | var root = __webpack_require__(0);
|
300 |
|
301 |
|
302 | var Symbol = root.Symbol;
|
303 |
|
304 | module.exports = Symbol;
|
305 |
|
306 |
|
307 | }),
|
308 |
|
309 | (function(module, exports) {
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 | var isArray = Array.isArray;
|
335 |
|
336 | module.exports = isArray;
|
337 |
|
338 |
|
339 | }),
|
340 |
|
341 | (function(module, exports, __webpack_require__) {
|
342 |
|
343 | "use strict";
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 | var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
354 |
|
355 | module.exports = ReactPropTypesSecret;
|
356 |
|
357 |
|
358 | }),
|
359 |
|
360 | (function(module, exports) {
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 | function eq(value, other) {
|
395 | return value === other || (value !== value && other !== other);
|
396 | }
|
397 |
|
398 | module.exports = eq;
|
399 |
|
400 |
|
401 | }),
|
402 |
|
403 | (function(module, exports, __webpack_require__) {
|
404 |
|
405 | var baseGetTag = __webpack_require__(4),
|
406 | isObject = __webpack_require__(16);
|
407 |
|
408 |
|
409 | var asyncTag = '[object AsyncFunction]',
|
410 | funcTag = '[object Function]',
|
411 | genTag = '[object GeneratorFunction]',
|
412 | proxyTag = '[object Proxy]';
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 | function isFunction(value) {
|
432 | if (!isObject(value)) {
|
433 | return false;
|
434 | }
|
435 |
|
436 |
|
437 | var tag = baseGetTag(value);
|
438 | return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
439 | }
|
440 |
|
441 | module.exports = isFunction;
|
442 |
|
443 |
|
444 | }),
|
445 |
|
446 | (function(module, exports, __webpack_require__) {
|
447 |
|
448 | (function(global) {
|
449 | var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
450 |
|
451 | module.exports = freeGlobal;
|
452 |
|
453 | }.call(exports, __webpack_require__(15)))
|
454 |
|
455 | }),
|
456 |
|
457 | (function(module, exports) {
|
458 |
|
459 | var g;
|
460 |
|
461 |
|
462 | g = (function() {
|
463 | return this;
|
464 | })();
|
465 |
|
466 | try {
|
467 |
|
468 | g = g || Function("return this")() || (1,eval)("this");
|
469 | } catch(e) {
|
470 |
|
471 | if(typeof window === "object")
|
472 | g = window;
|
473 | }
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 | module.exports = g;
|
480 |
|
481 |
|
482 | }),
|
483 |
|
484 | (function(module, exports) {
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 | function isObject(value) {
|
512 | var type = typeof value;
|
513 | return value != null && (type == 'object' || type == 'function');
|
514 | }
|
515 |
|
516 | module.exports = isObject;
|
517 |
|
518 |
|
519 | }),
|
520 |
|
521 | (function(module, exports) {
|
522 |
|
523 |
|
524 | var funcProto = Function.prototype;
|
525 |
|
526 |
|
527 | var funcToString = funcProto.toString;
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 | function toSource(func) {
|
537 | if (func != null) {
|
538 | try {
|
539 | return funcToString.call(func);
|
540 | } catch (e) {}
|
541 | try {
|
542 | return (func + '');
|
543 | } catch (e) {}
|
544 | }
|
545 | return '';
|
546 | }
|
547 |
|
548 | module.exports = toSource;
|
549 |
|
550 |
|
551 | }),
|
552 |
|
553 | (function(module, exports, __webpack_require__) {
|
554 |
|
555 | var mapCacheClear = __webpack_require__(44),
|
556 | mapCacheDelete = __webpack_require__(51),
|
557 | mapCacheGet = __webpack_require__(53),
|
558 | mapCacheHas = __webpack_require__(54),
|
559 | mapCacheSet = __webpack_require__(55);
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 | function MapCache(entries) {
|
569 | var index = -1,
|
570 | length = entries == null ? 0 : entries.length;
|
571 |
|
572 | this.clear();
|
573 | while (++index < length) {
|
574 | var entry = entries[index];
|
575 | this.set(entry[0], entry[1]);
|
576 | }
|
577 | }
|
578 |
|
579 |
|
580 | MapCache.prototype.clear = mapCacheClear;
|
581 | MapCache.prototype['delete'] = mapCacheDelete;
|
582 | MapCache.prototype.get = mapCacheGet;
|
583 | MapCache.prototype.has = mapCacheHas;
|
584 | MapCache.prototype.set = mapCacheSet;
|
585 |
|
586 | module.exports = MapCache;
|
587 |
|
588 |
|
589 | }),
|
590 |
|
591 | (function(module, exports, __webpack_require__) {
|
592 |
|
593 | var SetCache = __webpack_require__(56),
|
594 | arraySome = __webpack_require__(59),
|
595 | cacheHas = __webpack_require__(60);
|
596 |
|
597 |
|
598 | var COMPARE_PARTIAL_FLAG = 1,
|
599 | COMPARE_UNORDERED_FLAG = 2;
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 | function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
|
615 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
616 | arrLength = array.length,
|
617 | othLength = other.length;
|
618 |
|
619 | if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
|
620 | return false;
|
621 | }
|
622 |
|
623 | var stacked = stack.get(array);
|
624 | if (stacked && stack.get(other)) {
|
625 | return stacked == other;
|
626 | }
|
627 | var index = -1,
|
628 | result = true,
|
629 | seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
|
630 |
|
631 | stack.set(array, other);
|
632 | stack.set(other, array);
|
633 |
|
634 |
|
635 | while (++index < arrLength) {
|
636 | var arrValue = array[index],
|
637 | othValue = other[index];
|
638 |
|
639 | if (customizer) {
|
640 | var compared = isPartial
|
641 | ? customizer(othValue, arrValue, index, other, array, stack)
|
642 | : customizer(arrValue, othValue, index, array, other, stack);
|
643 | }
|
644 | if (compared !== undefined) {
|
645 | if (compared) {
|
646 | continue;
|
647 | }
|
648 | result = false;
|
649 | break;
|
650 | }
|
651 |
|
652 | if (seen) {
|
653 | if (!arraySome(other, function(othValue, othIndex) {
|
654 | if (!cacheHas(seen, othIndex) &&
|
655 | (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
|
656 | return seen.push(othIndex);
|
657 | }
|
658 | })) {
|
659 | result = false;
|
660 | break;
|
661 | }
|
662 | } else if (!(
|
663 | arrValue === othValue ||
|
664 | equalFunc(arrValue, othValue, bitmask, customizer, stack)
|
665 | )) {
|
666 | result = false;
|
667 | break;
|
668 | }
|
669 | }
|
670 | stack['delete'](array);
|
671 | stack['delete'](other);
|
672 | return result;
|
673 | }
|
674 |
|
675 | module.exports = equalArrays;
|
676 |
|
677 |
|
678 | }),
|
679 |
|
680 | (function(module, exports, __webpack_require__) {
|
681 |
|
682 | (function(module) {var root = __webpack_require__(0),
|
683 | stubFalse = __webpack_require__(77);
|
684 |
|
685 |
|
686 | var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
|
687 |
|
688 |
|
689 | var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
|
690 |
|
691 |
|
692 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
693 |
|
694 |
|
695 | var Buffer = moduleExports ? root.Buffer : undefined;
|
696 |
|
697 |
|
698 | var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 | var isBuffer = nativeIsBuffer || stubFalse;
|
718 |
|
719 | module.exports = isBuffer;
|
720 |
|
721 | }.call(exports, __webpack_require__(21)(module)))
|
722 |
|
723 | }),
|
724 |
|
725 | (function(module, exports) {
|
726 |
|
727 | module.exports = function(module) {
|
728 | if(!module.webpackPolyfill) {
|
729 | module.deprecate = function() {};
|
730 | module.paths = [];
|
731 |
|
732 | if(!module.children) module.children = [];
|
733 | Object.defineProperty(module, "loaded", {
|
734 | enumerable: true,
|
735 | get: function() {
|
736 | return module.l;
|
737 | }
|
738 | });
|
739 | Object.defineProperty(module, "id", {
|
740 | enumerable: true,
|
741 | get: function() {
|
742 | return module.i;
|
743 | }
|
744 | });
|
745 | module.webpackPolyfill = 1;
|
746 | }
|
747 | return module;
|
748 | };
|
749 |
|
750 |
|
751 | }),
|
752 |
|
753 | (function(module, exports, __webpack_require__) {
|
754 |
|
755 | var baseIsTypedArray = __webpack_require__(79),
|
756 | baseUnary = __webpack_require__(80),
|
757 | nodeUtil = __webpack_require__(81);
|
758 |
|
759 |
|
760 | var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 |
|
771 |
|
772 |
|
773 |
|
774 |
|
775 |
|
776 |
|
777 |
|
778 |
|
779 | var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
|
780 |
|
781 | module.exports = isTypedArray;
|
782 |
|
783 |
|
784 | }),
|
785 |
|
786 | (function(module, exports) {
|
787 |
|
788 |
|
789 | var MAX_SAFE_INTEGER = 9007199254740991;
|
790 |
|
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 | function isLength(value) {
|
818 | return typeof value == 'number' &&
|
819 | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
820 | }
|
821 |
|
822 | module.exports = isLength;
|
823 |
|
824 |
|
825 | }),
|
826 |
|
827 | (function(module, __webpack_exports__, __webpack_require__) {
|
828 |
|
829 | "use strict";
|
830 | Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
|
831 |
|
832 |
|
833 | var maptalks = __webpack_require__(97);
|
834 | var maptalks_default = __webpack_require__.n(maptalks);
|
835 |
|
836 |
|
837 | var external___root___React___commonjs2___react___commonjs___react___amd___react__ = __webpack_require__(98);
|
838 | var external___root___React___commonjs2___react___commonjs___react___amd___react___default = __webpack_require__.n(external___root___React___commonjs2___react___commonjs___react___amd___react__);
|
839 |
|
840 |
|
841 | var isEqual = __webpack_require__(99);
|
842 | var isEqual_default = __webpack_require__.n(isEqual);
|
843 |
|
844 |
|
845 | var prop_types = __webpack_require__(100);
|
846 | var prop_types_default = __webpack_require__.n(prop_types);
|
847 |
|
848 |
|
849 | var maptalks_es = __webpack_require__(101);
|
850 |
|
851 |
|
852 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
853 |
|
854 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
855 |
|
856 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
857 |
|
858 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 | var map_Map = function (_React$Component) {
|
866 | _inherits(Map, _React$Component);
|
867 |
|
868 | function Map(props) {
|
869 | _classCallCheck(this, Map);
|
870 |
|
871 | var _this = _possibleConstructorReturn(this, (Map.__proto__ || Object.getPrototypeOf(Map)).call(this, props));
|
872 |
|
873 | _this.setRef = function () {
|
874 | var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
875 |
|
876 | _this.container = x;
|
877 | };
|
878 |
|
879 | _this.state = {
|
880 | isLoad: false,
|
881 | isMounted: false
|
882 | };
|
883 |
|
884 | |
885 |
|
886 |
|
887 |
|
888 | _this.map = null;
|
889 |
|
890 | _this.container = null;
|
891 |
|
892 | _this.events = {};
|
893 | return _this;
|
894 | }
|
895 |
|
896 | _createClass(Map, [{
|
897 | key: 'getChildContext',
|
898 | value: function getChildContext() {
|
899 | return {
|
900 | map: this.map
|
901 | };
|
902 | }
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 | }, {
|
914 | key: 'componentWillReceiveProps',
|
915 | value: function componentWillReceiveProps(nextProps) {
|
916 | var _props = this.props,
|
917 | center = _props.center,
|
918 | zoom = _props.zoom,
|
919 | spatialReference = _props.spatialReference,
|
920 | cursor = _props.cursor,
|
921 | maxExtent = _props.maxExtent,
|
922 | maxZoom = _props.maxZoom,
|
923 | minZoom = _props.minZoom,
|
924 | pitch = _props.pitch,
|
925 | bearing = _props.bearing,
|
926 | fov = _props.fov;
|
927 |
|
928 | if (!this.map) {
|
929 | return null;
|
930 | }
|
931 |
|
932 | if (!isEqual_default()(nextProps.center, center) || !isEqual_default()(nextProps.zoom, zoom)) {
|
933 | if (!isEqual_default()(nextProps.center, center) && isEqual_default()(nextProps.zoom, zoom)) {
|
934 | this.map.setCenter(nextProps.center);
|
935 | }
|
936 | if (isEqual_default()(nextProps.center, center) && !isEqual_default()(nextProps.zoom, zoom)) {
|
937 | this.map.setZoom(nextProps.zoom);
|
938 | }
|
939 | if (!isEqual_default()(nextProps.center, center) && !isEqual_default()(nextProps.zoom, zoom)) {
|
940 | this.map.setCenterAndZoom(nextProps.center, nextProps.zoom);
|
941 | }
|
942 | }
|
943 |
|
944 | if (!isEqual_default()(nextProps.spatialReference, spatialReference)) {
|
945 | this.map.setSpatialReference(nextProps.zoom);
|
946 | }
|
947 | if (!isEqual_default()(nextProps.cursor, cursor)) {
|
948 | this.map.setCursor(nextProps.cursor);
|
949 | }
|
950 | if (!isEqual_default()(nextProps.maxExtent, maxExtent)) {
|
951 | this.map.setMaxExtent(nextProps.maxExtent);
|
952 | }
|
953 | if (!isEqual_default()(nextProps.maxZoom, maxZoom)) {
|
954 | this.map.setMaxZoom(nextProps.maxZoom);
|
955 | }
|
956 | if (!isEqual_default()(nextProps.minZoom, minZoom)) {
|
957 | this.map.setMinZoom(nextProps.minZoom);
|
958 | }
|
959 | if (!isEqual_default()(nextProps.fov, fov)) {
|
960 | this.map.setFov(nextProps.fov);
|
961 | }
|
962 | if (!isEqual_default()(nextProps.bearing, bearing)) {
|
963 | this.map.setBearing(nextProps.bearing);
|
964 | }
|
965 | if (!isEqual_default()(nextProps.pitch, pitch)) {
|
966 | this.map.setPitch(nextProps.pitch);
|
967 | }
|
968 | return null;
|
969 | }
|
970 |
|
971 | |
972 |
|
973 |
|
974 |
|
975 |
|
976 |
|
977 | }, {
|
978 | key: 'setBaseLayer',
|
979 | value: function setBaseLayer(layers) {
|
980 | if (!this.map) {
|
981 | return null;
|
982 | }
|
983 | if (layers && layers.length > 0) {
|
984 | this.map.setBaseLayer();
|
985 | }
|
986 | }
|
987 |
|
988 | |
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 | }, {
|
995 | key: 'setLayers',
|
996 | value: function setLayers(layers) {
|
997 | if (!this.map) {
|
998 | return null;
|
999 | }
|
1000 | if (layers && layers.length > 0) {
|
1001 |
|
1002 | }
|
1003 | }
|
1004 | }, {
|
1005 | key: 'componentDidMount',
|
1006 | value: function componentDidMount() {
|
1007 | var _props2 = this.props,
|
1008 | center = _props2.center,
|
1009 | zoom = _props2.zoom,
|
1010 | events = _props2.events,
|
1011 | fov = _props2.fov,
|
1012 | bearing = _props2.bearing,
|
1013 | pitch = _props2.pitch;
|
1014 |
|
1015 | var options = {
|
1016 | zoom: zoom,
|
1017 | center: center,
|
1018 | fov: Math.max(0.01, Math.min(59, fov)),
|
1019 | bearing: bearing,
|
1020 | pitch: pitch
|
1021 | };
|
1022 | this.map = new maptalks_es["e" ](this.container, options);
|
1023 | if (this.map.isLoaded()) {
|
1024 | this.setState({
|
1025 | isLoad: true
|
1026 | });
|
1027 | for (var key in events) {
|
1028 | if (key === 'onload') {
|
1029 | events[key](this.map, this);
|
1030 | } else {
|
1031 | this.map.on(key, events[key], this);
|
1032 | }
|
1033 | }
|
1034 | }
|
1035 | this.setState({
|
1036 | isMounted: true
|
1037 | });
|
1038 | }
|
1039 | }, {
|
1040 | key: 'componentWillUnmount',
|
1041 | value: function componentWillUnmount() {
|
1042 | if (this.map) {
|
1043 | this.map = null;
|
1044 | this.setState({
|
1045 | isMounted: false
|
1046 | });
|
1047 | }
|
1048 | }
|
1049 | }, {
|
1050 | key: 'render',
|
1051 | value: function render() {
|
1052 | var _state = this.state,
|
1053 | isMounted = _state.isMounted,
|
1054 | isLoad = _state.isLoad;
|
1055 | var _props3 = this.props,
|
1056 | className = _props3.className,
|
1057 | children = _props3.children;
|
1058 |
|
1059 | return external___root___React___commonjs2___react___commonjs___react___amd___react___default.a.createElement(
|
1060 | 'div',
|
1061 | { ref: this.setRef, className: className },
|
1062 | isMounted && isLoad ? children : null
|
1063 | );
|
1064 | }
|
1065 | }]);
|
1066 |
|
1067 | return Map;
|
1068 | }(external___root___React___commonjs2___react___commonjs___react___amd___react___default.a.Component);
|
1069 |
|
1070 | map_Map.defaultProps = {};
|
1071 | map_Map.childContextTypes = {
|
1072 | map: prop_types_default.a.instanceOf(maptalks_es["e" ])
|
1073 | };
|
1074 |
|
1075 |
|
1076 | var src_map = (map_Map);
|
1077 |
|
1078 | var Layer__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
1079 |
|
1080 | function Layer__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
1081 |
|
1082 | function Layer__possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
1083 |
|
1084 | function Layer__inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 | var Layer_TileLayer = function (_React$Component) {
|
1091 | Layer__inherits(TileLayer, _React$Component);
|
1092 |
|
1093 | function TileLayer(props, context) {
|
1094 | Layer__classCallCheck(this, TileLayer);
|
1095 |
|
1096 | var _this = Layer__possibleConstructorReturn(this, (TileLayer.__proto__ || Object.getPrototypeOf(TileLayer)).call(this, props, context));
|
1097 |
|
1098 | _this.layer = null;
|
1099 | return _this;
|
1100 | }
|
1101 |
|
1102 | Layer__createClass(TileLayer, [{
|
1103 | key: 'render',
|
1104 | value: function render() {
|
1105 | return null;
|
1106 | }
|
1107 |
|
1108 | |
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 | }, {
|
1114 | key: 'createLayer',
|
1115 | value: function createLayer(nextProps) {
|
1116 | if (nextProps) {
|
1117 | var map = this.context.map;
|
1118 |
|
1119 | if (!map) return;
|
1120 | if (this.layer) {
|
1121 | map.removeLayer(this.layer);
|
1122 | }
|
1123 | var id = nextProps.id;
|
1124 |
|
1125 | this.layer = new maptalks_es["c" ](id, nextProps);
|
1126 | map.addLayer(this.layer);
|
1127 | }
|
1128 | }
|
1129 | }, {
|
1130 | key: 'componentDidMount',
|
1131 | value: function componentDidMount() {
|
1132 | this.createLayer(this.props);
|
1133 | }
|
1134 | }, {
|
1135 | key: 'componentWillReceiveProps',
|
1136 | value: function componentWillReceiveProps(nextProps) {
|
1137 | this.createLayer(nextProps);
|
1138 | return null;
|
1139 | }
|
1140 | }, {
|
1141 | key: 'componentWillUnmount',
|
1142 | value: function componentWillUnmount() {
|
1143 | var map = this.context.map;
|
1144 |
|
1145 | if (!map || !this.layer) return;
|
1146 | map.removeLayer(this.layer);
|
1147 | }
|
1148 | }]);
|
1149 |
|
1150 | return TileLayer;
|
1151 | }(external___root___React___commonjs2___react___commonjs___react___amd___react___default.a.Component);
|
1152 |
|
1153 | Layer_TileLayer.defaultProps = {
|
1154 | attribution: null,
|
1155 | minZoom: null,
|
1156 | maxZoom: null,
|
1157 | visible: true,
|
1158 | opacity: 1,
|
1159 | globalCompositeOperation: null,
|
1160 | renderer: 'canvas',
|
1161 | debugOutline: '#0f0',
|
1162 | cssFilter: null,
|
1163 | forceRenderOnMoving: false,
|
1164 | forceRenderOnZooming: false,
|
1165 | forceRenderOnRotating: false
|
1166 | };
|
1167 | Layer_TileLayer.contextTypes = {
|
1168 | map: prop_types_default.a.instanceOf(maptalks_es["e" ])
|
1169 | };
|
1170 |
|
1171 |
|
1172 | var Layer = (Layer_TileLayer);
|
1173 |
|
1174 | var TileLayer__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
1175 |
|
1176 | function TileLayer__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
1177 |
|
1178 | function TileLayer__possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
1179 |
|
1180 | function TileLayer__inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
1181 |
|
1182 |
|
1183 |
|
1184 |
|
1185 |
|
1186 | var TileLayer_TileLayer = function (_Layer) {
|
1187 | TileLayer__inherits(TileLayer, _Layer);
|
1188 |
|
1189 | function TileLayer(props, context) {
|
1190 | TileLayer__classCallCheck(this, TileLayer);
|
1191 |
|
1192 | |
1193 |
|
1194 |
|
1195 |
|
1196 | var _this = TileLayer__possibleConstructorReturn(this, (TileLayer.__proto__ || Object.getPrototypeOf(TileLayer)).call(this, props, context));
|
1197 |
|
1198 | _this.state = {
|
1199 | isAdd: false
|
1200 | };
|
1201 |
|
1202 | _this.layer = null;
|
1203 | return _this;
|
1204 | }
|
1205 |
|
1206 | |
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 |
|
1212 | TileLayer__createClass(TileLayer, [{
|
1213 | key: 'createLayer',
|
1214 | value: function createLayer(nextProps) {
|
1215 | var _this2 = this;
|
1216 |
|
1217 | if (nextProps) {
|
1218 | var map = this.context.map;
|
1219 |
|
1220 | if (!map) return;
|
1221 | if (this.layer) {
|
1222 | map.removeLayer(this.layer);
|
1223 | }
|
1224 | var id = nextProps.id;
|
1225 |
|
1226 | this.layer = new maptalks_es["l" ](id, nextProps);
|
1227 | this.layer.on('add', function () {
|
1228 | _this2.setState({
|
1229 | isAdd: true
|
1230 | });
|
1231 | });
|
1232 | map.addLayer(this.layer);
|
1233 | }
|
1234 | }
|
1235 | }]);
|
1236 |
|
1237 | return TileLayer;
|
1238 | }(Layer);
|
1239 |
|
1240 | TileLayer_TileLayer.defaultProps = {
|
1241 | subdomains: null,
|
1242 | repeatWorld: true,
|
1243 | background: true,
|
1244 | backgroundZoomDiff: 6,
|
1245 | loadingLimitOnInteracting: 3,
|
1246 | placeholder: false,
|
1247 | crossOrigin: null,
|
1248 | tileSize: [256, 256],
|
1249 | offset: [0, 0],
|
1250 | tileSystem: null,
|
1251 | fadeAnimation: true,
|
1252 | debug: false,
|
1253 | spatialReference: null,
|
1254 | maxCacheSize: 256,
|
1255 | clipByPitch: true,
|
1256 | maxAvailableZoom: null,
|
1257 | cascadeTiles: true,
|
1258 | minPitchToCascade: 35
|
1259 | };
|
1260 | TileLayer_TileLayer.propTypes = {
|
1261 | urlTemplate: prop_types_default.a.oneOfType([prop_types_default.a.string, prop_types_default.a.func]).isRequired,
|
1262 | subdomains: prop_types_default.a.oneOfType([prop_types_default.a.arrayOf(prop_types_default.a.string), prop_types_default.a.arrayOf(prop_types_default.a.number)]),
|
1263 | repeatWorld: prop_types_default.a.bool,
|
1264 | background: prop_types_default.a.bool,
|
1265 | backgroundZoomDiff: prop_types_default.a.number,
|
1266 | loadingLimitOnInteracting: prop_types_default.a.number,
|
1267 | placeholder: prop_types_default.a.bool,
|
1268 | crossOrigin: prop_types_default.a.string,
|
1269 | tileSize: prop_types_default.a.arrayOf(prop_types_default.a.number),
|
1270 | offset: prop_types_default.a.arrayOf(prop_types_default.a.number),
|
1271 | tileSystem: prop_types_default.a.arrayOf(prop_types_default.a.number),
|
1272 | fadeAnimation: prop_types_default.a.bool,
|
1273 | debug: prop_types_default.a.bool,
|
1274 | spatialReference: prop_types_default.a.object,
|
1275 | maxCacheSize: prop_types_default.a.number,
|
1276 | clipByPitch: prop_types_default.a.bool,
|
1277 | maxAvailableZoom: prop_types_default.a.number,
|
1278 | cascadeTiles: prop_types_default.a.bool,
|
1279 | minPitchToCascade: prop_types_default.a.number
|
1280 | };
|
1281 |
|
1282 |
|
1283 | var tile_TileLayer = (TileLayer_TileLayer);
|
1284 |
|
1285 | var OverlayLayer__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
1286 |
|
1287 | function OverlayLayer__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
1288 |
|
1289 | function OverlayLayer__possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
1290 |
|
1291 | function OverlayLayer__inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 | var OverlayLayer_OverlayLayer = function (_Layer) {
|
1298 | OverlayLayer__inherits(OverlayLayer, _Layer);
|
1299 |
|
1300 | function OverlayLayer(props, context) {
|
1301 | OverlayLayer__classCallCheck(this, OverlayLayer);
|
1302 |
|
1303 | var _this = OverlayLayer__possibleConstructorReturn(this, (OverlayLayer.__proto__ || Object.getPrototypeOf(OverlayLayer)).call(this, props, context));
|
1304 |
|
1305 | _this.layer = null;
|
1306 | return _this;
|
1307 | }
|
1308 |
|
1309 | |
1310 |
|
1311 |
|
1312 |
|
1313 |
|
1314 |
|
1315 | OverlayLayer__createClass(OverlayLayer, [{
|
1316 | key: 'createLayer',
|
1317 | value: function createLayer(nextProps) {
|
1318 | if (nextProps) {
|
1319 | var map = this.context.map;
|
1320 |
|
1321 | if (!map) return;
|
1322 | if (this.layer) {
|
1323 | map.removeLayer(this.layer);
|
1324 | }
|
1325 | var id = nextProps.id,
|
1326 | geometries = nextProps.geometries;
|
1327 |
|
1328 | this.layer = new maptalks_es["j" ](id, geometries, nextProps);
|
1329 | map.addLayer(this.layer);
|
1330 | }
|
1331 | }
|
1332 | }]);
|
1333 |
|
1334 | return OverlayLayer;
|
1335 | }(Layer);
|
1336 |
|
1337 | OverlayLayer_OverlayLayer.defaultProps = {
|
1338 | drawImmediate: false
|
1339 | };
|
1340 | OverlayLayer_OverlayLayer.propTypes = {
|
1341 | drawImmediate: prop_types_default.a.bool
|
1342 | };
|
1343 |
|
1344 |
|
1345 | var layers_OverlayLayer = (OverlayLayer_OverlayLayer);
|
1346 |
|
1347 | var VectorLayer__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
1348 |
|
1349 | function VectorLayer__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
1350 |
|
1351 | function VectorLayer__possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
1352 |
|
1353 | function VectorLayer__inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
1354 |
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 | var VectorLayer_VectorLayer = function (_OverlayLayer) {
|
1360 | VectorLayer__inherits(VectorLayer, _OverlayLayer);
|
1361 |
|
1362 | function VectorLayer(props, context) {
|
1363 | VectorLayer__classCallCheck(this, VectorLayer);
|
1364 |
|
1365 | var _this = VectorLayer__possibleConstructorReturn(this, (VectorLayer.__proto__ || Object.getPrototypeOf(VectorLayer)).call(this, props, context));
|
1366 |
|
1367 | _this.layer = null;
|
1368 |
|
1369 | |
1370 |
|
1371 |
|
1372 |
|
1373 | _this.state = {
|
1374 | isAdd: false
|
1375 | };
|
1376 | return _this;
|
1377 | }
|
1378 |
|
1379 | |
1380 |
|
1381 |
|
1382 |
|
1383 |
|
1384 |
|
1385 | VectorLayer__createClass(VectorLayer, [{
|
1386 | key: 'createLayer',
|
1387 | value: function createLayer(nextProps) {
|
1388 | var _this2 = this;
|
1389 |
|
1390 | if (nextProps) {
|
1391 | var map = this.context.map;
|
1392 |
|
1393 | if (!map) return;
|
1394 | if (this.layer) {
|
1395 | map.removeLayer(this.layer);
|
1396 | }
|
1397 | var id = nextProps.id,
|
1398 | geometries = nextProps.geometries;
|
1399 |
|
1400 | this.layer = new maptalks_es["m" ](id, geometries, nextProps);
|
1401 | this.layer.on('add', function () {
|
1402 | _this2.setState({
|
1403 | isAdd: true
|
1404 | });
|
1405 | });
|
1406 | map.addLayer(this.layer);
|
1407 | }
|
1408 | }
|
1409 | }, {
|
1410 | key: 'componentWillReceiveProps',
|
1411 | value: function componentWillReceiveProps(nextProps) {
|
1412 | this.createLayer(nextProps);
|
1413 | }
|
1414 | }, {
|
1415 | key: 'getChildContext',
|
1416 | value: function getChildContext() {
|
1417 | return {
|
1418 | layer: this.layer
|
1419 | };
|
1420 | }
|
1421 |
|
1422 | |
1423 |
|
1424 |
|
1425 |
|
1426 |
|
1427 | }, {
|
1428 | key: 'render',
|
1429 | value: function render() {
|
1430 | var isAdd = this.state.isAdd;
|
1431 |
|
1432 | console.log(isAdd);
|
1433 | var children = this.props.children;
|
1434 |
|
1435 | return isAdd ? children : null;
|
1436 | }
|
1437 | }]);
|
1438 |
|
1439 | return VectorLayer;
|
1440 | }(layers_OverlayLayer);
|
1441 |
|
1442 | VectorLayer_VectorLayer.defaultProps = {
|
1443 | cursor: 'default',
|
1444 | enableSimplify: true,
|
1445 | geometryEvents: true,
|
1446 | defaultIconSize: [20, 20],
|
1447 | cacheVectorOnCanvas: true,
|
1448 | cacheSvgOnCanvas: true,
|
1449 | enableAltitude: false,
|
1450 | altitudeProperty: 'altitude',
|
1451 | drawAltitude: false
|
1452 | };
|
1453 | VectorLayer_VectorLayer.propTypes = {
|
1454 | cursor: prop_types_default.a.string,
|
1455 | enableSimplify: prop_types_default.a.bool,
|
1456 | geometryEvents: prop_types_default.a.bool,
|
1457 | defaultIconSize: prop_types_default.a.arrayOf(prop_types_default.a.number),
|
1458 | cacheVectorOnCanvas: prop_types_default.a.bool,
|
1459 | cacheSvgOnCanvas: prop_types_default.a.bool,
|
1460 | enableAltitude: prop_types_default.a.bool,
|
1461 | altitudeProperty: prop_types_default.a.string,
|
1462 | drawAltitude: prop_types_default.a.bool
|
1463 | };
|
1464 | VectorLayer_VectorLayer.childContextTypes = {
|
1465 | layer: prop_types_default.a.instanceOf(maptalks_es["c" ])
|
1466 | };
|
1467 |
|
1468 |
|
1469 | var layers_VectorLayer = (VectorLayer_VectorLayer);
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 |
|
1478 |
|
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 |
|
1485 |
|
1486 | var Geometry__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
1487 |
|
1488 | function Geometry__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
1489 |
|
1490 | function Geometry__possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
1491 |
|
1492 | function Geometry__inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 | var Geometry_Geometry = function (_React$Component) {
|
1499 | Geometry__inherits(Geometry, _React$Component);
|
1500 |
|
1501 | |
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 | function Geometry(props, context) {
|
1507 | Geometry__classCallCheck(this, Geometry);
|
1508 |
|
1509 | |
1510 |
|
1511 |
|
1512 |
|
1513 | var _this = Geometry__possibleConstructorReturn(this, (Geometry.__proto__ || Object.getPrototypeOf(Geometry)).call(this, props, context));
|
1514 |
|
1515 | _this.geometry = null;
|
1516 | return _this;
|
1517 | }
|
1518 |
|
1519 | |
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 | Geometry__createClass(Geometry, [{
|
1526 | key: 'createGeometry',
|
1527 | value: function createGeometry(nextProps) {
|
1528 | if (nextProps) {
|
1529 | var layer = this.context.layer;
|
1530 |
|
1531 | if (!layer) return;
|
1532 | this.geometry = new maptalks_es["b" ]();
|
1533 | layer.addGeometry(this.geometry);
|
1534 | }
|
1535 | }
|
1536 | }, {
|
1537 | key: 'componentDidMount',
|
1538 | value: function componentDidMount() {
|
1539 | this.createGeometry(this.props);
|
1540 | }
|
1541 | }, {
|
1542 | key: 'componentWillReceiveProps',
|
1543 | value: function componentWillReceiveProps(nextProps) {
|
1544 | this.createGeometry(nextProps);
|
1545 | return null;
|
1546 | }
|
1547 | }, {
|
1548 | key: 'componentWillUnmount',
|
1549 | value: function componentWillUnmount() {
|
1550 | var layer = this.context.layer;
|
1551 |
|
1552 | if (!layer) return;
|
1553 | layer.removeGeometry(this.geometry);
|
1554 | }
|
1555 |
|
1556 | |
1557 |
|
1558 |
|
1559 |
|
1560 |
|
1561 | }, {
|
1562 | key: 'render',
|
1563 | value: function render() {
|
1564 | return null;
|
1565 | }
|
1566 | }]);
|
1567 |
|
1568 | return Geometry;
|
1569 | }(external___root___React___commonjs2___react___commonjs___react___amd___react___default.a.Component);
|
1570 |
|
1571 | Geometry_Geometry.contextTypes = {
|
1572 | layer: prop_types_default.a.instanceOf(maptalks_es["c" ])
|
1573 | };
|
1574 |
|
1575 |
|
1576 | var geometry_Geometry = (Geometry_Geometry);
|
1577 |
|
1578 | var Marker__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
1579 |
|
1580 | function Marker__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
1581 |
|
1582 | function Marker__possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
1583 |
|
1584 | function Marker__inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 | var Marker_Marker = function (_Geometry) {
|
1592 | Marker__inherits(Marker, _Geometry);
|
1593 |
|
1594 | |
1595 |
|
1596 |
|
1597 |
|
1598 |
|
1599 | function Marker(props, context) {
|
1600 | Marker__classCallCheck(this, Marker);
|
1601 |
|
1602 | |
1603 |
|
1604 |
|
1605 |
|
1606 | var _this = Marker__possibleConstructorReturn(this, (Marker.__proto__ || Object.getPrototypeOf(Marker)).call(this, props, context));
|
1607 |
|
1608 | _this.geometry = null;
|
1609 | return _this;
|
1610 | }
|
1611 |
|
1612 | |
1613 |
|
1614 |
|
1615 |
|
1616 |
|
1617 |
|
1618 | Marker__createClass(Marker, [{
|
1619 | key: 'createGeometry',
|
1620 | value: function createGeometry(nextProps) {
|
1621 | if (nextProps) {
|
1622 | var layer = this.context.layer;
|
1623 |
|
1624 | if (!layer) return;
|
1625 | var id = nextProps.id,
|
1626 | coordinates = nextProps.coordinates,
|
1627 | options = nextProps.options;
|
1628 |
|
1629 | this.geometry = new maptalks_es["f" ](coordinates, options);
|
1630 | this.geometry.setId(id);
|
1631 | this.geometry.setProperties(options);
|
1632 | layer.addGeometry(this.geometry);
|
1633 | }
|
1634 | }
|
1635 | }, {
|
1636 | key: 'componentDidMount',
|
1637 | value: function componentDidMount() {
|
1638 | this.createGeometry(this.props);
|
1639 | }
|
1640 | }, {
|
1641 | key: 'componentWillReceiveProps',
|
1642 | value: function componentWillReceiveProps(nextProps) {
|
1643 | var _props = this.props,
|
1644 | id = _props.id,
|
1645 | coordinates = _props.coordinates,
|
1646 | options = _props.options;
|
1647 |
|
1648 | if (!this.geometry) {
|
1649 | return null;
|
1650 | }
|
1651 | if (!isEqual_default()(nextProps.id, id)) {
|
1652 | this.geometry.setId(nextProps.id);
|
1653 | }
|
1654 | if (!isEqual_default()(nextProps.coordinates, coordinates)) {
|
1655 | this.geometry.setCoordinates(nextProps.coordinates);
|
1656 | }
|
1657 | if (!isEqual_default()(nextProps.options, options)) {
|
1658 | this.geometry.setProperties(nextProps.options);
|
1659 | }
|
1660 | }
|
1661 | }, {
|
1662 | key: 'componentWillUnmount',
|
1663 | value: function componentWillUnmount() {
|
1664 | var layer = this.context.layer;
|
1665 |
|
1666 | if (!layer) return;
|
1667 | layer.removeGeometry(this.geometry);
|
1668 | }
|
1669 |
|
1670 | |
1671 |
|
1672 |
|
1673 |
|
1674 |
|
1675 | }, {
|
1676 | key: 'render',
|
1677 | value: function render() {
|
1678 | return null;
|
1679 | }
|
1680 | }]);
|
1681 |
|
1682 | return Marker;
|
1683 | }(geometry_Geometry);
|
1684 |
|
1685 | Marker_Marker.propTypes = {
|
1686 | id: prop_types_default.a.oneOfType([prop_types_default.a.number, prop_types_default.a.string]).isRequired,
|
1687 | coordinates: prop_types_default.a.arrayOf(prop_types_default.a.number),
|
1688 | options: prop_types_default.a.any
|
1689 | };
|
1690 | Marker_Marker.contextTypes = {
|
1691 | layer: prop_types_default.a.instanceOf(maptalks_es["c" ])
|
1692 | };
|
1693 |
|
1694 |
|
1695 | var geometry_Marker = (Marker_Marker);
|
1696 |
|
1697 | var LineString__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
1698 |
|
1699 | function LineString__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
1700 |
|
1701 | function LineString__possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
1702 |
|
1703 | function LineString__inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
1704 |
|
1705 |
|
1706 |
|
1707 |
|
1708 |
|
1709 |
|
1710 | var LineString_LineString = function (_Geometry) {
|
1711 | LineString__inherits(LineString, _Geometry);
|
1712 |
|
1713 | |
1714 |
|
1715 |
|
1716 |
|
1717 |
|
1718 | function LineString(props, context) {
|
1719 | LineString__classCallCheck(this, LineString);
|
1720 |
|
1721 | |
1722 |
|
1723 |
|
1724 |
|
1725 | var _this = LineString__possibleConstructorReturn(this, (LineString.__proto__ || Object.getPrototypeOf(LineString)).call(this, props, context));
|
1726 |
|
1727 | _this.geometry = null;
|
1728 | return _this;
|
1729 | }
|
1730 |
|
1731 | |
1732 |
|
1733 |
|
1734 |
|
1735 |
|
1736 |
|
1737 | LineString__createClass(LineString, [{
|
1738 | key: 'createGeometry',
|
1739 | value: function createGeometry(nextProps) {
|
1740 | if (nextProps) {
|
1741 | var layer = this.context.layer;
|
1742 |
|
1743 | if (!layer) return;
|
1744 | var id = nextProps.id,
|
1745 | coordinates = nextProps.coordinates,
|
1746 | options = nextProps.options;
|
1747 |
|
1748 | this.geometry = new maptalks_es["d" ](coordinates, options);
|
1749 | this.geometry.setId(id);
|
1750 | this.geometry.setProperties(options);
|
1751 | layer.addGeometry(this.geometry);
|
1752 | }
|
1753 | }
|
1754 | }, {
|
1755 | key: 'componentDidMount',
|
1756 | value: function componentDidMount() {
|
1757 | this.createGeometry(this.props);
|
1758 | }
|
1759 | }, {
|
1760 | key: 'componentWillReceiveProps',
|
1761 | value: function componentWillReceiveProps(nextProps) {
|
1762 | var _props = this.props,
|
1763 | id = _props.id,
|
1764 | coordinates = _props.coordinates,
|
1765 | options = _props.options;
|
1766 |
|
1767 | if (!this.geometry) {
|
1768 | return null;
|
1769 | }
|
1770 | if (!isEqual_default()(nextProps.id, id)) {
|
1771 | this.geometry.setId(nextProps.id);
|
1772 | }
|
1773 | if (!isEqual_default()(nextProps.coordinates, coordinates)) {
|
1774 | this.geometry.setCoordinates(nextProps.coordinates);
|
1775 | }
|
1776 | if (!isEqual_default()(nextProps.options, options)) {
|
1777 | this.geometry.setProperties(nextProps.options);
|
1778 | }
|
1779 | }
|
1780 | }, {
|
1781 | key: 'componentWillUnmount',
|
1782 | value: function componentWillUnmount() {
|
1783 | var layer = this.context.layer;
|
1784 |
|
1785 | if (!layer) return;
|
1786 | layer.removeGeometry(this.geometry);
|
1787 | }
|
1788 |
|
1789 | |
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 | }, {
|
1795 | key: 'render',
|
1796 | value: function render() {
|
1797 | return null;
|
1798 | }
|
1799 | }]);
|
1800 |
|
1801 | return LineString;
|
1802 | }(geometry_Geometry);
|
1803 |
|
1804 | LineString_LineString.propTypes = {
|
1805 | id: prop_types_default.a.oneOfType([prop_types_default.a.number, prop_types_default.a.string]).isRequired,
|
1806 | coordinates: prop_types_default.a.arrayOf(prop_types_default.a.any),
|
1807 | options: prop_types_default.a.any
|
1808 | };
|
1809 | LineString_LineString.contextTypes = {
|
1810 | layer: prop_types_default.a.instanceOf(maptalks_es["c" ])
|
1811 | };
|
1812 |
|
1813 |
|
1814 | var geometry_LineString = (LineString_LineString);
|
1815 |
|
1816 | var Polygon__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
1817 |
|
1818 | function Polygon__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
1819 |
|
1820 | function Polygon__possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
1821 |
|
1822 | function Polygon__inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 | var Polygon_Polygon = function (_Geometry) {
|
1830 | Polygon__inherits(Polygon, _Geometry);
|
1831 |
|
1832 | |
1833 |
|
1834 |
|
1835 |
|
1836 |
|
1837 | function Polygon(props, context) {
|
1838 | Polygon__classCallCheck(this, Polygon);
|
1839 |
|
1840 | |
1841 |
|
1842 |
|
1843 |
|
1844 | var _this = Polygon__possibleConstructorReturn(this, (Polygon.__proto__ || Object.getPrototypeOf(Polygon)).call(this, props, context));
|
1845 |
|
1846 | _this.geometry = null;
|
1847 | return _this;
|
1848 | }
|
1849 |
|
1850 | |
1851 |
|
1852 |
|
1853 |
|
1854 |
|
1855 |
|
1856 | Polygon__createClass(Polygon, [{
|
1857 | key: 'createGeometry',
|
1858 | value: function createGeometry(nextProps) {
|
1859 | if (nextProps) {
|
1860 | var layer = this.context.layer;
|
1861 |
|
1862 | if (!layer) return;
|
1863 | var id = nextProps.id,
|
1864 | coordinates = nextProps.coordinates,
|
1865 | options = nextProps.options;
|
1866 |
|
1867 | this.geometry = new maptalks_es["k" ](coordinates, options);
|
1868 | this.geometry.setId(id);
|
1869 | this.geometry.setProperties(options);
|
1870 | layer.addGeometry(this.geometry);
|
1871 | }
|
1872 | }
|
1873 | }, {
|
1874 | key: 'componentDidMount',
|
1875 | value: function componentDidMount() {
|
1876 | this.createGeometry(this.props);
|
1877 | }
|
1878 | }, {
|
1879 | key: 'componentWillReceiveProps',
|
1880 | value: function componentWillReceiveProps(nextProps) {
|
1881 | var _props = this.props,
|
1882 | id = _props.id,
|
1883 | coordinates = _props.coordinates,
|
1884 | options = _props.options;
|
1885 |
|
1886 | if (!this.geometry) {
|
1887 | return null;
|
1888 | }
|
1889 | if (!isEqual_default()(nextProps.id, id)) {
|
1890 | this.geometry.setId(nextProps.id);
|
1891 | }
|
1892 | if (!isEqual_default()(nextProps.coordinates, coordinates)) {
|
1893 | this.geometry.setCoordinates(nextProps.coordinates);
|
1894 | }
|
1895 | if (!isEqual_default()(nextProps.options, options)) {
|
1896 | this.geometry.setProperties(nextProps.options);
|
1897 | }
|
1898 | }
|
1899 | }, {
|
1900 | key: 'componentWillUnmount',
|
1901 | value: function componentWillUnmount() {
|
1902 | var layer = this.context.layer;
|
1903 |
|
1904 | if (!layer) return;
|
1905 | layer.removeGeometry(this.geometry);
|
1906 | }
|
1907 |
|
1908 | |
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 | }, {
|
1914 | key: 'render',
|
1915 | value: function render() {
|
1916 | return null;
|
1917 | }
|
1918 | }]);
|
1919 |
|
1920 | return Polygon;
|
1921 | }(geometry_Geometry);
|
1922 |
|
1923 | Polygon_Polygon.propTypes = {
|
1924 | id: prop_types_default.a.oneOfType([prop_types_default.a.number, prop_types_default.a.string]).isRequired,
|
1925 | coordinates: prop_types_default.a.arrayOf(prop_types_default.a.array),
|
1926 | options: prop_types_default.a.any
|
1927 | };
|
1928 | Polygon_Polygon.contextTypes = {
|
1929 | layer: prop_types_default.a.instanceOf(maptalks_es["c" ])
|
1930 | };
|
1931 |
|
1932 |
|
1933 | var geometry_Polygon = (Polygon_Polygon);
|
1934 |
|
1935 | var MultiPoint__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
1936 |
|
1937 | function MultiPoint__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
1938 |
|
1939 | function MultiPoint__possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
1940 |
|
1941 | function MultiPoint__inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
1942 |
|
1943 |
|
1944 |
|
1945 |
|
1946 |
|
1947 |
|
1948 | var MultiPoint_MultiPoint = function (_Geometry) {
|
1949 | MultiPoint__inherits(MultiPoint, _Geometry);
|
1950 |
|
1951 | |
1952 |
|
1953 |
|
1954 |
|
1955 |
|
1956 | function MultiPoint(props, context) {
|
1957 | MultiPoint__classCallCheck(this, MultiPoint);
|
1958 |
|
1959 | |
1960 |
|
1961 |
|
1962 |
|
1963 | var _this = MultiPoint__possibleConstructorReturn(this, (MultiPoint.__proto__ || Object.getPrototypeOf(MultiPoint)).call(this, props, context));
|
1964 |
|
1965 | _this.geometry = null;
|
1966 | return _this;
|
1967 | }
|
1968 |
|
1969 | |
1970 |
|
1971 |
|
1972 |
|
1973 |
|
1974 |
|
1975 | MultiPoint__createClass(MultiPoint, [{
|
1976 | key: 'createGeometry',
|
1977 | value: function createGeometry(nextProps) {
|
1978 | if (nextProps) {
|
1979 | var layer = this.context.layer;
|
1980 |
|
1981 | if (!layer) return;
|
1982 | var id = nextProps.id,
|
1983 | coordinates = nextProps.coordinates,
|
1984 | options = nextProps.options;
|
1985 |
|
1986 | this.geometry = new maptalks_es["h" ](coordinates, options);
|
1987 | this.geometry.setId(id);
|
1988 | this.geometry.setProperties(options);
|
1989 | layer.addGeometry(this.geometry);
|
1990 | }
|
1991 | }
|
1992 | }, {
|
1993 | key: 'componentDidMount',
|
1994 | value: function componentDidMount() {
|
1995 | this.createGeometry(this.props);
|
1996 | }
|
1997 | }, {
|
1998 | key: 'componentWillReceiveProps',
|
1999 | value: function componentWillReceiveProps(nextProps) {
|
2000 | var _props = this.props,
|
2001 | id = _props.id,
|
2002 | coordinates = _props.coordinates,
|
2003 | options = _props.options;
|
2004 |
|
2005 | if (!this.geometry) {
|
2006 | return null;
|
2007 | }
|
2008 | if (!isEqual_default()(nextProps.id, id)) {
|
2009 | this.geometry.setId(nextProps.id);
|
2010 | }
|
2011 | if (!isEqual_default()(nextProps.coordinates, coordinates)) {
|
2012 | this.geometry.setCoordinates(nextProps.coordinates);
|
2013 | }
|
2014 | if (!isEqual_default()(nextProps.options, options)) {
|
2015 | this.geometry.setProperties(nextProps.options);
|
2016 | }
|
2017 | }
|
2018 | }, {
|
2019 | key: 'componentWillUnmount',
|
2020 | value: function componentWillUnmount() {
|
2021 | var layer = this.context.layer;
|
2022 |
|
2023 | if (!layer) return;
|
2024 | layer.removeGeometry(this.geometry);
|
2025 | }
|
2026 |
|
2027 | |
2028 |
|
2029 |
|
2030 |
|
2031 |
|
2032 | }, {
|
2033 | key: 'render',
|
2034 | value: function render() {
|
2035 | return null;
|
2036 | }
|
2037 | }]);
|
2038 |
|
2039 | return MultiPoint;
|
2040 | }(geometry_Geometry);
|
2041 |
|
2042 | MultiPoint_MultiPoint.propTypes = {
|
2043 | id: prop_types_default.a.oneOfType([prop_types_default.a.number, prop_types_default.a.string]).isRequired,
|
2044 | coordinates: prop_types_default.a.arrayOf(prop_types_default.a.arrayOf(prop_types_default.a.number)),
|
2045 | options: prop_types_default.a.any
|
2046 | };
|
2047 | MultiPoint_MultiPoint.contextTypes = {
|
2048 | layer: prop_types_default.a.instanceOf(maptalks_es["c" ])
|
2049 | };
|
2050 |
|
2051 |
|
2052 | var geometry_MultiPoint = (MultiPoint_MultiPoint);
|
2053 |
|
2054 | var MultiLineString__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
2055 |
|
2056 | function MultiLineString__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
2057 |
|
2058 | function MultiLineString__possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
2059 |
|
2060 | function MultiLineString__inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
2061 |
|
2062 |
|
2063 |
|
2064 |
|
2065 |
|
2066 |
|
2067 | var MultiLineString_MultiLineString = function (_Geometry) {
|
2068 | MultiLineString__inherits(MultiLineString, _Geometry);
|
2069 |
|
2070 | |
2071 |
|
2072 |
|
2073 |
|
2074 |
|
2075 | function MultiLineString(props, context) {
|
2076 | MultiLineString__classCallCheck(this, MultiLineString);
|
2077 |
|
2078 | |
2079 |
|
2080 |
|
2081 |
|
2082 | var _this = MultiLineString__possibleConstructorReturn(this, (MultiLineString.__proto__ || Object.getPrototypeOf(MultiLineString)).call(this, props, context));
|
2083 |
|
2084 | _this.geometry = null;
|
2085 | return _this;
|
2086 | }
|
2087 |
|
2088 | |
2089 |
|
2090 |
|
2091 |
|
2092 |
|
2093 |
|
2094 | MultiLineString__createClass(MultiLineString, [{
|
2095 | key: 'createGeometry',
|
2096 | value: function createGeometry(nextProps) {
|
2097 | if (nextProps) {
|
2098 | var layer = this.context.layer;
|
2099 |
|
2100 | if (!layer) return;
|
2101 | var id = nextProps.id,
|
2102 | coordinates = nextProps.coordinates,
|
2103 | options = nextProps.options;
|
2104 |
|
2105 | this.geometry = new maptalks_es["g" ](coordinates, options);
|
2106 | this.geometry.setId(id);
|
2107 | this.geometry.setProperties(options);
|
2108 | layer.addGeometry(this.geometry);
|
2109 | }
|
2110 | }
|
2111 | }, {
|
2112 | key: 'componentDidMount',
|
2113 | value: function componentDidMount() {
|
2114 | this.createGeometry(this.props);
|
2115 | }
|
2116 | }, {
|
2117 | key: 'componentWillReceiveProps',
|
2118 | value: function componentWillReceiveProps(nextProps) {
|
2119 | var _props = this.props,
|
2120 | id = _props.id,
|
2121 | coordinates = _props.coordinates,
|
2122 | options = _props.options;
|
2123 |
|
2124 | if (!this.geometry) {
|
2125 | return null;
|
2126 | }
|
2127 | if (!isEqual_default()(nextProps.id, id)) {
|
2128 | this.geometry.setId(nextProps.id);
|
2129 | }
|
2130 | if (!isEqual_default()(nextProps.coordinates, coordinates)) {
|
2131 | this.geometry.setCoordinates(nextProps.coordinates);
|
2132 | }
|
2133 | if (!isEqual_default()(nextProps.options, options)) {
|
2134 | this.geometry.setProperties(nextProps.options);
|
2135 | }
|
2136 | }
|
2137 | }, {
|
2138 | key: 'componentWillUnmount',
|
2139 | value: function componentWillUnmount() {
|
2140 | var layer = this.context.layer;
|
2141 |
|
2142 | if (!layer) return;
|
2143 | layer.removeGeometry(this.geometry);
|
2144 | }
|
2145 |
|
2146 | |
2147 |
|
2148 |
|
2149 |
|
2150 |
|
2151 | }, {
|
2152 | key: 'render',
|
2153 | value: function render() {
|
2154 | return null;
|
2155 | }
|
2156 | }]);
|
2157 |
|
2158 | return MultiLineString;
|
2159 | }(geometry_Geometry);
|
2160 |
|
2161 | MultiLineString_MultiLineString.propTypes = {
|
2162 | id: prop_types_default.a.oneOfType([prop_types_default.a.number, prop_types_default.a.string]).isRequired,
|
2163 | coordinates: prop_types_default.a.arrayOf(prop_types_default.a.arrayOf(prop_types_default.a.arrayOf(prop_types_default.a.number))),
|
2164 | options: prop_types_default.a.any
|
2165 | };
|
2166 | MultiLineString_MultiLineString.contextTypes = {
|
2167 | layer: prop_types_default.a.instanceOf(maptalks_es["c" ])
|
2168 | };
|
2169 |
|
2170 |
|
2171 | var geometry_MultiLineString = (MultiLineString_MultiLineString);
|
2172 |
|
2173 | var MultiPolygon__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
2174 |
|
2175 | function MultiPolygon__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
2176 |
|
2177 | function MultiPolygon__possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
2178 |
|
2179 | function MultiPolygon__inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
2180 |
|
2181 |
|
2182 |
|
2183 |
|
2184 |
|
2185 |
|
2186 | var MultiPolygon_MultiPolygon = function (_Geometry) {
|
2187 | MultiPolygon__inherits(MultiPolygon, _Geometry);
|
2188 |
|
2189 | |
2190 |
|
2191 |
|
2192 |
|
2193 |
|
2194 | function MultiPolygon(props, context) {
|
2195 | MultiPolygon__classCallCheck(this, MultiPolygon);
|
2196 |
|
2197 | |
2198 |
|
2199 |
|
2200 |
|
2201 | var _this = MultiPolygon__possibleConstructorReturn(this, (MultiPolygon.__proto__ || Object.getPrototypeOf(MultiPolygon)).call(this, props, context));
|
2202 |
|
2203 | _this.geometry = null;
|
2204 | return _this;
|
2205 | }
|
2206 |
|
2207 | |
2208 |
|
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 | MultiPolygon__createClass(MultiPolygon, [{
|
2214 | key: 'createGeometry',
|
2215 | value: function createGeometry(nextProps) {
|
2216 | if (nextProps) {
|
2217 | var layer = this.context.layer;
|
2218 |
|
2219 | if (!layer) return;
|
2220 | var id = nextProps.id,
|
2221 | coordinates = nextProps.coordinates,
|
2222 | options = nextProps.options;
|
2223 |
|
2224 | this.geometry = new maptalks_es["i" ](coordinates, options);
|
2225 | this.geometry.setId(id);
|
2226 | this.geometry.setProperties(options);
|
2227 | layer.addGeometry(this.geometry);
|
2228 | }
|
2229 | }
|
2230 | }, {
|
2231 | key: 'componentDidMount',
|
2232 | value: function componentDidMount() {
|
2233 | this.createGeometry(this.props);
|
2234 | }
|
2235 | }, {
|
2236 | key: 'componentWillReceiveProps',
|
2237 | value: function componentWillReceiveProps(nextProps) {
|
2238 | var _props = this.props,
|
2239 | id = _props.id,
|
2240 | coordinates = _props.coordinates,
|
2241 | options = _props.options;
|
2242 |
|
2243 | if (!this.geometry) {
|
2244 | return null;
|
2245 | }
|
2246 | if (!isEqual_default()(nextProps.id, id)) {
|
2247 | this.geometry.setId(nextProps.id);
|
2248 | }
|
2249 | if (!isEqual_default()(nextProps.coordinates, coordinates)) {
|
2250 | this.geometry.setCoordinates(nextProps.coordinates);
|
2251 | }
|
2252 | if (!isEqual_default()(nextProps.options, options)) {
|
2253 | this.geometry.setProperties(nextProps.options);
|
2254 | }
|
2255 | }
|
2256 | }, {
|
2257 | key: 'componentWillUnmount',
|
2258 | value: function componentWillUnmount() {
|
2259 | var layer = this.context.layer;
|
2260 |
|
2261 | if (!layer) return;
|
2262 | layer.removeGeometry(this.geometry);
|
2263 | }
|
2264 |
|
2265 | |
2266 |
|
2267 |
|
2268 |
|
2269 |
|
2270 | }, {
|
2271 | key: 'render',
|
2272 | value: function render() {
|
2273 | return null;
|
2274 | }
|
2275 | }]);
|
2276 |
|
2277 | return MultiPolygon;
|
2278 | }(geometry_Geometry);
|
2279 |
|
2280 | MultiPolygon_MultiPolygon.propTypes = {
|
2281 | id: prop_types_default.a.oneOfType([prop_types_default.a.number, prop_types_default.a.string]).isRequired,
|
2282 | coordinates: prop_types_default.a.arrayOf(prop_types_default.a.array),
|
2283 | options: prop_types_default.a.any
|
2284 | };
|
2285 | MultiPolygon_MultiPolygon.contextTypes = {
|
2286 | layer: prop_types_default.a.instanceOf(maptalks_es["c" ])
|
2287 | };
|
2288 |
|
2289 |
|
2290 | var geometry_MultiPolygon = (MultiPolygon_MultiPolygon);
|
2291 |
|
2292 | var Circle__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
2293 |
|
2294 | function Circle__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
2295 |
|
2296 | function Circle__possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
2297 |
|
2298 | function Circle__inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
2299 |
|
2300 |
|
2301 |
|
2302 |
|
2303 |
|
2304 |
|
2305 | var Circle_Circle = function (_Geometry) {
|
2306 | Circle__inherits(Circle, _Geometry);
|
2307 |
|
2308 | |
2309 |
|
2310 |
|
2311 |
|
2312 |
|
2313 | function Circle(props, context) {
|
2314 | Circle__classCallCheck(this, Circle);
|
2315 |
|
2316 | |
2317 |
|
2318 |
|
2319 |
|
2320 | var _this = Circle__possibleConstructorReturn(this, (Circle.__proto__ || Object.getPrototypeOf(Circle)).call(this, props, context));
|
2321 |
|
2322 | _this.geometry = null;
|
2323 | return _this;
|
2324 | }
|
2325 |
|
2326 | |
2327 |
|
2328 |
|
2329 |
|
2330 |
|
2331 |
|
2332 | Circle__createClass(Circle, [{
|
2333 | key: 'createGeometry',
|
2334 | value: function createGeometry(nextProps) {
|
2335 | if (nextProps) {
|
2336 | var layer = this.context.layer;
|
2337 |
|
2338 | if (!layer) return;
|
2339 | var id = nextProps.id,
|
2340 | center = nextProps.center,
|
2341 | radius = nextProps.radius,
|
2342 | options = nextProps.options;
|
2343 |
|
2344 | this.geometry = new maptalks_es["a" ](center, radius, options);
|
2345 | this.geometry.setId(id);
|
2346 | this.geometry.setProperties(options);
|
2347 | layer.addGeometry(this.geometry);
|
2348 | }
|
2349 | }
|
2350 | }, {
|
2351 | key: 'componentDidMount',
|
2352 | value: function componentDidMount() {
|
2353 | this.createGeometry(this.props);
|
2354 | }
|
2355 | }, {
|
2356 | key: 'componentWillReceiveProps',
|
2357 | value: function componentWillReceiveProps(nextProps) {
|
2358 | console.log(nextProps);
|
2359 | var _props = this.props,
|
2360 | id = _props.id,
|
2361 | center = _props.center,
|
2362 | radius = _props.radius,
|
2363 | options = _props.options;
|
2364 |
|
2365 | if (!this.geometry) {
|
2366 | return null;
|
2367 | }
|
2368 | if (!isEqual_default()(nextProps.id, id)) {
|
2369 | this.geometry.setId(nextProps.id);
|
2370 | }
|
2371 | if (!isEqual_default()(nextProps.center, center)) {
|
2372 | this.geometry.setCoordinates(nextProps.center);
|
2373 | }
|
2374 | if (!isEqual_default()(nextProps.radius, radius)) {
|
2375 | this.geometry.setRadius(nextProps.radius);
|
2376 | }
|
2377 | if (!isEqual_default()(nextProps.options, options)) {
|
2378 | this.geometry.setProperties(nextProps.options);
|
2379 | }
|
2380 | }
|
2381 | }, {
|
2382 | key: 'componentWillUnmount',
|
2383 | value: function componentWillUnmount() {
|
2384 | var layer = this.context.layer;
|
2385 |
|
2386 | if (!layer) return;
|
2387 | layer.removeGeometry(this.geometry);
|
2388 | }
|
2389 |
|
2390 | |
2391 |
|
2392 |
|
2393 |
|
2394 |
|
2395 | }, {
|
2396 | key: 'render',
|
2397 | value: function render() {
|
2398 | return null;
|
2399 | }
|
2400 | }]);
|
2401 |
|
2402 | return Circle;
|
2403 | }(geometry_Geometry);
|
2404 |
|
2405 | Circle_Circle.propTypes = {
|
2406 | id: prop_types_default.a.oneOfType([prop_types_default.a.number, prop_types_default.a.string]).isRequired,
|
2407 | center: prop_types_default.a.arrayOf(prop_types_default.a.number),
|
2408 | radius: prop_types_default.a.number,
|
2409 | options: prop_types_default.a.any
|
2410 | };
|
2411 | Circle_Circle.contextTypes = {
|
2412 | layer: prop_types_default.a.instanceOf(maptalks_es["c" ])
|
2413 | };
|
2414 |
|
2415 |
|
2416 | var geometry_Circle = (Circle_Circle);
|
2417 |
|
2418 |
|
2419 |
|
2420 |
|
2421 |
|
2422 |
|
2423 |
|
2424 |
|
2425 |
|
2426 |
|
2427 |
|
2428 |
|
2429 |
|
2430 |
|
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 |
|
2436 |
|
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 |
|
2442 | __webpack_require__.d(__webpack_exports__, "Map", function() { return src_map; });
|
2443 | __webpack_require__.d(__webpack_exports__, "TileLayer", function() { return tile_TileLayer; });
|
2444 | __webpack_require__.d(__webpack_exports__, "OverlayLayer", function() { return layers_OverlayLayer; });
|
2445 | __webpack_require__.d(__webpack_exports__, "VectorLayer", function() { return layers_VectorLayer; });
|
2446 | __webpack_require__.d(__webpack_exports__, "Circle", function() { return geometry_Circle; });
|
2447 | __webpack_require__.d(__webpack_exports__, "Geometry", function() { return geometry_Geometry; });
|
2448 | __webpack_require__.d(__webpack_exports__, "LineString", function() { return geometry_LineString; });
|
2449 | __webpack_require__.d(__webpack_exports__, "Marker", function() { return geometry_Marker; });
|
2450 | __webpack_require__.d(__webpack_exports__, "MultiLineString", function() { return geometry_MultiLineString; });
|
2451 | __webpack_require__.d(__webpack_exports__, "MultiPoint", function() { return geometry_MultiPoint; });
|
2452 | __webpack_require__.d(__webpack_exports__, "MultiPolygon", function() { return geometry_MultiPolygon; });
|
2453 | __webpack_require__.d(__webpack_exports__, "Polygon", function() { return geometry_Polygon; });
|
2454 |
|
2455 |
|
2456 |
|
2457 |
|
2458 |
|
2459 |
|
2460 |
|
2461 | var src = __webpack_exports__["default"] = ({
|
2462 | Map: src_map,
|
2463 | TileLayer: tile_TileLayer,
|
2464 | OverlayLayer: layers_OverlayLayer,
|
2465 | VectorLayer: layers_VectorLayer,
|
2466 | Circle: geometry_Circle,
|
2467 | Geometry: geometry_Geometry,
|
2468 | LineString: geometry_LineString,
|
2469 | Marker: geometry_Marker,
|
2470 | MultiLineString: geometry_MultiLineString,
|
2471 | MultiPoint: geometry_MultiPoint,
|
2472 | MultiPolygon: geometry_MultiPolygon,
|
2473 | Polygon: geometry_Polygon
|
2474 | });
|
2475 |
|
2476 | }),
|
2477 |
|
2478 | (function(module, exports, __webpack_require__) {
|
2479 |
|
2480 | var baseIsEqualDeep = __webpack_require__(26),
|
2481 | isObjectLike = __webpack_require__(7);
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 |
|
2487 |
|
2488 |
|
2489 |
|
2490 |
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 | function baseIsEqual(value, other, bitmask, customizer, stack) {
|
2498 | if (value === other) {
|
2499 | return true;
|
2500 | }
|
2501 | if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
|
2502 | return value !== value && other !== other;
|
2503 | }
|
2504 | return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
|
2505 | }
|
2506 |
|
2507 | module.exports = baseIsEqual;
|
2508 |
|
2509 |
|
2510 | }),
|
2511 |
|
2512 | (function(module, exports, __webpack_require__) {
|
2513 |
|
2514 | var Stack = __webpack_require__(27),
|
2515 | equalArrays = __webpack_require__(19),
|
2516 | equalByTag = __webpack_require__(61),
|
2517 | equalObjects = __webpack_require__(65),
|
2518 | getTag = __webpack_require__(87),
|
2519 | isArray = __webpack_require__(10),
|
2520 | isBuffer = __webpack_require__(20),
|
2521 | isTypedArray = __webpack_require__(22);
|
2522 |
|
2523 |
|
2524 | var COMPARE_PARTIAL_FLAG = 1;
|
2525 |
|
2526 |
|
2527 | var argsTag = '[object Arguments]',
|
2528 | arrayTag = '[object Array]',
|
2529 | objectTag = '[object Object]';
|
2530 |
|
2531 |
|
2532 | var objectProto = Object.prototype;
|
2533 |
|
2534 |
|
2535 | var hasOwnProperty = objectProto.hasOwnProperty;
|
2536 |
|
2537 |
|
2538 |
|
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 | function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
|
2552 | var objIsArr = isArray(object),
|
2553 | othIsArr = isArray(other),
|
2554 | objTag = objIsArr ? arrayTag : getTag(object),
|
2555 | othTag = othIsArr ? arrayTag : getTag(other);
|
2556 |
|
2557 | objTag = objTag == argsTag ? objectTag : objTag;
|
2558 | othTag = othTag == argsTag ? objectTag : othTag;
|
2559 |
|
2560 | var objIsObj = objTag == objectTag,
|
2561 | othIsObj = othTag == objectTag,
|
2562 | isSameTag = objTag == othTag;
|
2563 |
|
2564 | if (isSameTag && isBuffer(object)) {
|
2565 | if (!isBuffer(other)) {
|
2566 | return false;
|
2567 | }
|
2568 | objIsArr = true;
|
2569 | objIsObj = false;
|
2570 | }
|
2571 | if (isSameTag && !objIsObj) {
|
2572 | stack || (stack = new Stack);
|
2573 | return (objIsArr || isTypedArray(object))
|
2574 | ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
|
2575 | : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
|
2576 | }
|
2577 | if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
|
2578 | var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
|
2579 | othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
|
2580 |
|
2581 | if (objIsWrapped || othIsWrapped) {
|
2582 | var objUnwrapped = objIsWrapped ? object.value() : object,
|
2583 | othUnwrapped = othIsWrapped ? other.value() : other;
|
2584 |
|
2585 | stack || (stack = new Stack);
|
2586 | return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
|
2587 | }
|
2588 | }
|
2589 | if (!isSameTag) {
|
2590 | return false;
|
2591 | }
|
2592 | stack || (stack = new Stack);
|
2593 | return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
|
2594 | }
|
2595 |
|
2596 | module.exports = baseIsEqualDeep;
|
2597 |
|
2598 |
|
2599 | }),
|
2600 |
|
2601 | (function(module, exports, __webpack_require__) {
|
2602 |
|
2603 | var ListCache = __webpack_require__(2),
|
2604 | stackClear = __webpack_require__(33),
|
2605 | stackDelete = __webpack_require__(34),
|
2606 | stackGet = __webpack_require__(35),
|
2607 | stackHas = __webpack_require__(36),
|
2608 | stackSet = __webpack_require__(37);
|
2609 |
|
2610 |
|
2611 |
|
2612 |
|
2613 |
|
2614 |
|
2615 |
|
2616 |
|
2617 | function Stack(entries) {
|
2618 | var data = this.__data__ = new ListCache(entries);
|
2619 | this.size = data.size;
|
2620 | }
|
2621 |
|
2622 |
|
2623 | Stack.prototype.clear = stackClear;
|
2624 | Stack.prototype['delete'] = stackDelete;
|
2625 | Stack.prototype.get = stackGet;
|
2626 | Stack.prototype.has = stackHas;
|
2627 | Stack.prototype.set = stackSet;
|
2628 |
|
2629 | module.exports = Stack;
|
2630 |
|
2631 |
|
2632 | }),
|
2633 |
|
2634 | (function(module, exports) {
|
2635 |
|
2636 |
|
2637 |
|
2638 |
|
2639 |
|
2640 |
|
2641 |
|
2642 |
|
2643 | function listCacheClear() {
|
2644 | this.__data__ = [];
|
2645 | this.size = 0;
|
2646 | }
|
2647 |
|
2648 | module.exports = listCacheClear;
|
2649 |
|
2650 |
|
2651 | }),
|
2652 |
|
2653 | (function(module, exports, __webpack_require__) {
|
2654 |
|
2655 | var assocIndexOf = __webpack_require__(3);
|
2656 |
|
2657 |
|
2658 | var arrayProto = Array.prototype;
|
2659 |
|
2660 |
|
2661 | var splice = arrayProto.splice;
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 |
|
2668 |
|
2669 |
|
2670 |
|
2671 |
|
2672 | function listCacheDelete(key) {
|
2673 | var data = this.__data__,
|
2674 | index = assocIndexOf(data, key);
|
2675 |
|
2676 | if (index < 0) {
|
2677 | return false;
|
2678 | }
|
2679 | var lastIndex = data.length - 1;
|
2680 | if (index == lastIndex) {
|
2681 | data.pop();
|
2682 | } else {
|
2683 | splice.call(data, index, 1);
|
2684 | }
|
2685 | --this.size;
|
2686 | return true;
|
2687 | }
|
2688 |
|
2689 | module.exports = listCacheDelete;
|
2690 |
|
2691 |
|
2692 | }),
|
2693 |
|
2694 | (function(module, exports, __webpack_require__) {
|
2695 |
|
2696 | var assocIndexOf = __webpack_require__(3);
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 |
|
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 | function listCacheGet(key) {
|
2708 | var data = this.__data__,
|
2709 | index = assocIndexOf(data, key);
|
2710 |
|
2711 | return index < 0 ? undefined : data[index][1];
|
2712 | }
|
2713 |
|
2714 | module.exports = listCacheGet;
|
2715 |
|
2716 |
|
2717 | }),
|
2718 |
|
2719 | (function(module, exports, __webpack_require__) {
|
2720 |
|
2721 | var assocIndexOf = __webpack_require__(3);
|
2722 |
|
2723 |
|
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 |
|
2729 |
|
2730 |
|
2731 |
|
2732 | function listCacheHas(key) {
|
2733 | return assocIndexOf(this.__data__, key) > -1;
|
2734 | }
|
2735 |
|
2736 | module.exports = listCacheHas;
|
2737 |
|
2738 |
|
2739 | }),
|
2740 |
|
2741 | (function(module, exports, __webpack_require__) {
|
2742 |
|
2743 | var assocIndexOf = __webpack_require__(3);
|
2744 |
|
2745 |
|
2746 |
|
2747 |
|
2748 |
|
2749 |
|
2750 |
|
2751 |
|
2752 |
|
2753 |
|
2754 |
|
2755 | function listCacheSet(key, value) {
|
2756 | var data = this.__data__,
|
2757 | index = assocIndexOf(data, key);
|
2758 |
|
2759 | if (index < 0) {
|
2760 | ++this.size;
|
2761 | data.push([key, value]);
|
2762 | } else {
|
2763 | data[index][1] = value;
|
2764 | }
|
2765 | return this;
|
2766 | }
|
2767 |
|
2768 | module.exports = listCacheSet;
|
2769 |
|
2770 |
|
2771 | }),
|
2772 |
|
2773 | (function(module, exports, __webpack_require__) {
|
2774 |
|
2775 | var ListCache = __webpack_require__(2);
|
2776 |
|
2777 |
|
2778 |
|
2779 |
|
2780 |
|
2781 |
|
2782 |
|
2783 |
|
2784 | function stackClear() {
|
2785 | this.__data__ = new ListCache;
|
2786 | this.size = 0;
|
2787 | }
|
2788 |
|
2789 | module.exports = stackClear;
|
2790 |
|
2791 |
|
2792 | }),
|
2793 |
|
2794 | (function(module, exports) {
|
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 |
|
2804 |
|
2805 | function stackDelete(key) {
|
2806 | var data = this.__data__,
|
2807 | result = data['delete'](key);
|
2808 |
|
2809 | this.size = data.size;
|
2810 | return result;
|
2811 | }
|
2812 |
|
2813 | module.exports = stackDelete;
|
2814 |
|
2815 |
|
2816 | }),
|
2817 |
|
2818 | (function(module, exports) {
|
2819 |
|
2820 |
|
2821 |
|
2822 |
|
2823 |
|
2824 |
|
2825 |
|
2826 |
|
2827 |
|
2828 |
|
2829 | function stackGet(key) {
|
2830 | return this.__data__.get(key);
|
2831 | }
|
2832 |
|
2833 | module.exports = stackGet;
|
2834 |
|
2835 |
|
2836 | }),
|
2837 |
|
2838 | (function(module, exports) {
|
2839 |
|
2840 |
|
2841 |
|
2842 |
|
2843 |
|
2844 |
|
2845 |
|
2846 |
|
2847 |
|
2848 |
|
2849 | function stackHas(key) {
|
2850 | return this.__data__.has(key);
|
2851 | }
|
2852 |
|
2853 | module.exports = stackHas;
|
2854 |
|
2855 |
|
2856 | }),
|
2857 |
|
2858 | (function(module, exports, __webpack_require__) {
|
2859 |
|
2860 | var ListCache = __webpack_require__(2),
|
2861 | Map = __webpack_require__(8),
|
2862 | MapCache = __webpack_require__(18);
|
2863 |
|
2864 |
|
2865 | var LARGE_ARRAY_SIZE = 200;
|
2866 |
|
2867 |
|
2868 |
|
2869 |
|
2870 |
|
2871 |
|
2872 |
|
2873 |
|
2874 |
|
2875 |
|
2876 |
|
2877 | function stackSet(key, value) {
|
2878 | var data = this.__data__;
|
2879 | if (data instanceof ListCache) {
|
2880 | var pairs = data.__data__;
|
2881 | if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
|
2882 | pairs.push([key, value]);
|
2883 | this.size = ++data.size;
|
2884 | return this;
|
2885 | }
|
2886 | data = this.__data__ = new MapCache(pairs);
|
2887 | }
|
2888 | data.set(key, value);
|
2889 | this.size = data.size;
|
2890 | return this;
|
2891 | }
|
2892 |
|
2893 | module.exports = stackSet;
|
2894 |
|
2895 |
|
2896 | }),
|
2897 |
|
2898 | (function(module, exports, __webpack_require__) {
|
2899 |
|
2900 | var isFunction = __webpack_require__(13),
|
2901 | isMasked = __webpack_require__(41),
|
2902 | isObject = __webpack_require__(16),
|
2903 | toSource = __webpack_require__(17);
|
2904 |
|
2905 |
|
2906 |
|
2907 |
|
2908 |
|
2909 | var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
2910 |
|
2911 |
|
2912 | var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
2913 |
|
2914 |
|
2915 | var funcProto = Function.prototype,
|
2916 | objectProto = Object.prototype;
|
2917 |
|
2918 |
|
2919 | var funcToString = funcProto.toString;
|
2920 |
|
2921 |
|
2922 | var hasOwnProperty = objectProto.hasOwnProperty;
|
2923 |
|
2924 |
|
2925 | var reIsNative = RegExp('^' +
|
2926 | funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
2927 | .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
2928 | );
|
2929 |
|
2930 |
|
2931 |
|
2932 |
|
2933 |
|
2934 |
|
2935 |
|
2936 |
|
2937 |
|
2938 | function baseIsNative(value) {
|
2939 | if (!isObject(value) || isMasked(value)) {
|
2940 | return false;
|
2941 | }
|
2942 | var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
|
2943 | return pattern.test(toSource(value));
|
2944 | }
|
2945 |
|
2946 | module.exports = baseIsNative;
|
2947 |
|
2948 |
|
2949 | }),
|
2950 |
|
2951 | (function(module, exports, __webpack_require__) {
|
2952 |
|
2953 | var Symbol = __webpack_require__(9);
|
2954 |
|
2955 |
|
2956 | var objectProto = Object.prototype;
|
2957 |
|
2958 |
|
2959 | var hasOwnProperty = objectProto.hasOwnProperty;
|
2960 |
|
2961 |
|
2962 |
|
2963 |
|
2964 |
|
2965 |
|
2966 | var nativeObjectToString = objectProto.toString;
|
2967 |
|
2968 |
|
2969 | var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
|
2970 |
|
2971 |
|
2972 |
|
2973 |
|
2974 |
|
2975 |
|
2976 |
|
2977 |
|
2978 | function getRawTag(value) {
|
2979 | var isOwn = hasOwnProperty.call(value, symToStringTag),
|
2980 | tag = value[symToStringTag];
|
2981 |
|
2982 | try {
|
2983 | value[symToStringTag] = undefined;
|
2984 | var unmasked = true;
|
2985 | } catch (e) {}
|
2986 |
|
2987 | var result = nativeObjectToString.call(value);
|
2988 | if (unmasked) {
|
2989 | if (isOwn) {
|
2990 | value[symToStringTag] = tag;
|
2991 | } else {
|
2992 | delete value[symToStringTag];
|
2993 | }
|
2994 | }
|
2995 | return result;
|
2996 | }
|
2997 |
|
2998 | module.exports = getRawTag;
|
2999 |
|
3000 |
|
3001 | }),
|
3002 |
|
3003 | (function(module, exports) {
|
3004 |
|
3005 |
|
3006 | var objectProto = Object.prototype;
|
3007 |
|
3008 |
|
3009 |
|
3010 |
|
3011 |
|
3012 |
|
3013 | var nativeObjectToString = objectProto.toString;
|
3014 |
|
3015 |
|
3016 |
|
3017 |
|
3018 |
|
3019 |
|
3020 |
|
3021 |
|
3022 | function objectToString(value) {
|
3023 | return nativeObjectToString.call(value);
|
3024 | }
|
3025 |
|
3026 | module.exports = objectToString;
|
3027 |
|
3028 |
|
3029 | }),
|
3030 |
|
3031 | (function(module, exports, __webpack_require__) {
|
3032 |
|
3033 | var coreJsData = __webpack_require__(42);
|
3034 |
|
3035 |
|
3036 | var maskSrcKey = (function() {
|
3037 | var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
3038 | return uid ? ('Symbol(src)_1.' + uid) : '';
|
3039 | }());
|
3040 |
|
3041 |
|
3042 |
|
3043 |
|
3044 |
|
3045 |
|
3046 |
|
3047 |
|
3048 | function isMasked(func) {
|
3049 | return !!maskSrcKey && (maskSrcKey in func);
|
3050 | }
|
3051 |
|
3052 | module.exports = isMasked;
|
3053 |
|
3054 |
|
3055 | }),
|
3056 |
|
3057 | (function(module, exports, __webpack_require__) {
|
3058 |
|
3059 | var root = __webpack_require__(0);
|
3060 |
|
3061 |
|
3062 | var coreJsData = root['__core-js_shared__'];
|
3063 |
|
3064 | module.exports = coreJsData;
|
3065 |
|
3066 |
|
3067 | }),
|
3068 |
|
3069 | (function(module, exports) {
|
3070 |
|
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 |
|
3077 |
|
3078 |
|
3079 | function getValue(object, key) {
|
3080 | return object == null ? undefined : object[key];
|
3081 | }
|
3082 |
|
3083 | module.exports = getValue;
|
3084 |
|
3085 |
|
3086 | }),
|
3087 |
|
3088 | (function(module, exports, __webpack_require__) {
|
3089 |
|
3090 | var Hash = __webpack_require__(45),
|
3091 | ListCache = __webpack_require__(2),
|
3092 | Map = __webpack_require__(8);
|
3093 |
|
3094 |
|
3095 |
|
3096 |
|
3097 |
|
3098 |
|
3099 |
|
3100 |
|
3101 | function mapCacheClear() {
|
3102 | this.size = 0;
|
3103 | this.__data__ = {
|
3104 | 'hash': new Hash,
|
3105 | 'map': new (Map || ListCache),
|
3106 | 'string': new Hash
|
3107 | };
|
3108 | }
|
3109 |
|
3110 | module.exports = mapCacheClear;
|
3111 |
|
3112 |
|
3113 | }),
|
3114 |
|
3115 | (function(module, exports, __webpack_require__) {
|
3116 |
|
3117 | var hashClear = __webpack_require__(46),
|
3118 | hashDelete = __webpack_require__(47),
|
3119 | hashGet = __webpack_require__(48),
|
3120 | hashHas = __webpack_require__(49),
|
3121 | hashSet = __webpack_require__(50);
|
3122 |
|
3123 |
|
3124 |
|
3125 |
|
3126 |
|
3127 |
|
3128 |
|
3129 |
|
3130 | function Hash(entries) {
|
3131 | var index = -1,
|
3132 | length = entries == null ? 0 : entries.length;
|
3133 |
|
3134 | this.clear();
|
3135 | while (++index < length) {
|
3136 | var entry = entries[index];
|
3137 | this.set(entry[0], entry[1]);
|
3138 | }
|
3139 | }
|
3140 |
|
3141 |
|
3142 | Hash.prototype.clear = hashClear;
|
3143 | Hash.prototype['delete'] = hashDelete;
|
3144 | Hash.prototype.get = hashGet;
|
3145 | Hash.prototype.has = hashHas;
|
3146 | Hash.prototype.set = hashSet;
|
3147 |
|
3148 | module.exports = Hash;
|
3149 |
|
3150 |
|
3151 | }),
|
3152 |
|
3153 | (function(module, exports, __webpack_require__) {
|
3154 |
|
3155 | var nativeCreate = __webpack_require__(5);
|
3156 |
|
3157 |
|
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 |
|
3163 |
|
3164 | function hashClear() {
|
3165 | this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
3166 | this.size = 0;
|
3167 | }
|
3168 |
|
3169 | module.exports = hashClear;
|
3170 |
|
3171 |
|
3172 | }),
|
3173 |
|
3174 | (function(module, exports) {
|
3175 |
|
3176 |
|
3177 |
|
3178 |
|
3179 |
|
3180 |
|
3181 |
|
3182 |
|
3183 |
|
3184 |
|
3185 |
|
3186 | function hashDelete(key) {
|
3187 | var result = this.has(key) && delete this.__data__[key];
|
3188 | this.size -= result ? 1 : 0;
|
3189 | return result;
|
3190 | }
|
3191 |
|
3192 | module.exports = hashDelete;
|
3193 |
|
3194 |
|
3195 | }),
|
3196 |
|
3197 | (function(module, exports, __webpack_require__) {
|
3198 |
|
3199 | var nativeCreate = __webpack_require__(5);
|
3200 |
|
3201 |
|
3202 | var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
3203 |
|
3204 |
|
3205 | var objectProto = Object.prototype;
|
3206 |
|
3207 |
|
3208 | var hasOwnProperty = objectProto.hasOwnProperty;
|
3209 |
|
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 |
|
3215 |
|
3216 |
|
3217 |
|
3218 |
|
3219 | function hashGet(key) {
|
3220 | var data = this.__data__;
|
3221 | if (nativeCreate) {
|
3222 | var result = data[key];
|
3223 | return result === HASH_UNDEFINED ? undefined : result;
|
3224 | }
|
3225 | return hasOwnProperty.call(data, key) ? data[key] : undefined;
|
3226 | }
|
3227 |
|
3228 | module.exports = hashGet;
|
3229 |
|
3230 |
|
3231 | }),
|
3232 |
|
3233 | (function(module, exports, __webpack_require__) {
|
3234 |
|
3235 | var nativeCreate = __webpack_require__(5);
|
3236 |
|
3237 |
|
3238 | var objectProto = Object.prototype;
|
3239 |
|
3240 |
|
3241 | var hasOwnProperty = objectProto.hasOwnProperty;
|
3242 |
|
3243 |
|
3244 |
|
3245 |
|
3246 |
|
3247 |
|
3248 |
|
3249 |
|
3250 |
|
3251 |
|
3252 | function hashHas(key) {
|
3253 | var data = this.__data__;
|
3254 | return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
|
3255 | }
|
3256 |
|
3257 | module.exports = hashHas;
|
3258 |
|
3259 |
|
3260 | }),
|
3261 |
|
3262 | (function(module, exports, __webpack_require__) {
|
3263 |
|
3264 | var nativeCreate = __webpack_require__(5);
|
3265 |
|
3266 |
|
3267 | var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
3268 |
|
3269 |
|
3270 |
|
3271 |
|
3272 |
|
3273 |
|
3274 |
|
3275 |
|
3276 |
|
3277 |
|
3278 |
|
3279 | function hashSet(key, value) {
|
3280 | var data = this.__data__;
|
3281 | this.size += this.has(key) ? 0 : 1;
|
3282 | data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
3283 | return this;
|
3284 | }
|
3285 |
|
3286 | module.exports = hashSet;
|
3287 |
|
3288 |
|
3289 | }),
|
3290 |
|
3291 | (function(module, exports, __webpack_require__) {
|
3292 |
|
3293 | var getMapData = __webpack_require__(6);
|
3294 |
|
3295 |
|
3296 |
|
3297 |
|
3298 |
|
3299 |
|
3300 |
|
3301 |
|
3302 |
|
3303 |
|
3304 | function mapCacheDelete(key) {
|
3305 | var result = getMapData(this, key)['delete'](key);
|
3306 | this.size -= result ? 1 : 0;
|
3307 | return result;
|
3308 | }
|
3309 |
|
3310 | module.exports = mapCacheDelete;
|
3311 |
|
3312 |
|
3313 | }),
|
3314 |
|
3315 | (function(module, exports) {
|
3316 |
|
3317 |
|
3318 |
|
3319 |
|
3320 |
|
3321 |
|
3322 |
|
3323 |
|
3324 | function isKeyable(value) {
|
3325 | var type = typeof value;
|
3326 | return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
3327 | ? (value !== '__proto__')
|
3328 | : (value === null);
|
3329 | }
|
3330 |
|
3331 | module.exports = isKeyable;
|
3332 |
|
3333 |
|
3334 | }),
|
3335 |
|
3336 | (function(module, exports, __webpack_require__) {
|
3337 |
|
3338 | var getMapData = __webpack_require__(6);
|
3339 |
|
3340 |
|
3341 |
|
3342 |
|
3343 |
|
3344 |
|
3345 |
|
3346 |
|
3347 |
|
3348 |
|
3349 | function mapCacheGet(key) {
|
3350 | return getMapData(this, key).get(key);
|
3351 | }
|
3352 |
|
3353 | module.exports = mapCacheGet;
|
3354 |
|
3355 |
|
3356 | }),
|
3357 |
|
3358 | (function(module, exports, __webpack_require__) {
|
3359 |
|
3360 | var getMapData = __webpack_require__(6);
|
3361 |
|
3362 |
|
3363 |
|
3364 |
|
3365 |
|
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 |
|
3371 | function mapCacheHas(key) {
|
3372 | return getMapData(this, key).has(key);
|
3373 | }
|
3374 |
|
3375 | module.exports = mapCacheHas;
|
3376 |
|
3377 |
|
3378 | }),
|
3379 |
|
3380 | (function(module, exports, __webpack_require__) {
|
3381 |
|
3382 | var getMapData = __webpack_require__(6);
|
3383 |
|
3384 |
|
3385 |
|
3386 |
|
3387 |
|
3388 |
|
3389 |
|
3390 |
|
3391 |
|
3392 |
|
3393 |
|
3394 | function mapCacheSet(key, value) {
|
3395 | var data = getMapData(this, key),
|
3396 | size = data.size;
|
3397 |
|
3398 | data.set(key, value);
|
3399 | this.size += data.size == size ? 0 : 1;
|
3400 | return this;
|
3401 | }
|
3402 |
|
3403 | module.exports = mapCacheSet;
|
3404 |
|
3405 |
|
3406 | }),
|
3407 |
|
3408 | (function(module, exports, __webpack_require__) {
|
3409 |
|
3410 | var MapCache = __webpack_require__(18),
|
3411 | setCacheAdd = __webpack_require__(57),
|
3412 | setCacheHas = __webpack_require__(58);
|
3413 |
|
3414 |
|
3415 |
|
3416 |
|
3417 |
|
3418 |
|
3419 |
|
3420 |
|
3421 |
|
3422 | function SetCache(values) {
|
3423 | var index = -1,
|
3424 | length = values == null ? 0 : values.length;
|
3425 |
|
3426 | this.__data__ = new MapCache;
|
3427 | while (++index < length) {
|
3428 | this.add(values[index]);
|
3429 | }
|
3430 | }
|
3431 |
|
3432 |
|
3433 | SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
|
3434 | SetCache.prototype.has = setCacheHas;
|
3435 |
|
3436 | module.exports = SetCache;
|
3437 |
|
3438 |
|
3439 | }),
|
3440 |
|
3441 | (function(module, exports) {
|
3442 |
|
3443 |
|
3444 | var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
3445 |
|
3446 |
|
3447 |
|
3448 |
|
3449 |
|
3450 |
|
3451 |
|
3452 |
|
3453 |
|
3454 |
|
3455 |
|
3456 | function setCacheAdd(value) {
|
3457 | this.__data__.set(value, HASH_UNDEFINED);
|
3458 | return this;
|
3459 | }
|
3460 |
|
3461 | module.exports = setCacheAdd;
|
3462 |
|
3463 |
|
3464 | }),
|
3465 |
|
3466 | (function(module, exports) {
|
3467 |
|
3468 |
|
3469 |
|
3470 |
|
3471 |
|
3472 |
|
3473 |
|
3474 |
|
3475 |
|
3476 |
|
3477 | function setCacheHas(value) {
|
3478 | return this.__data__.has(value);
|
3479 | }
|
3480 |
|
3481 | module.exports = setCacheHas;
|
3482 |
|
3483 |
|
3484 | }),
|
3485 |
|
3486 | (function(module, exports) {
|
3487 |
|
3488 |
|
3489 |
|
3490 |
|
3491 |
|
3492 |
|
3493 |
|
3494 |
|
3495 |
|
3496 |
|
3497 |
|
3498 | function arraySome(array, predicate) {
|
3499 | var index = -1,
|
3500 | length = array == null ? 0 : array.length;
|
3501 |
|
3502 | while (++index < length) {
|
3503 | if (predicate(array[index], index, array)) {
|
3504 | return true;
|
3505 | }
|
3506 | }
|
3507 | return false;
|
3508 | }
|
3509 |
|
3510 | module.exports = arraySome;
|
3511 |
|
3512 |
|
3513 | }),
|
3514 |
|
3515 | (function(module, exports) {
|
3516 |
|
3517 |
|
3518 |
|
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 |
|
3524 |
|
3525 | function cacheHas(cache, key) {
|
3526 | return cache.has(key);
|
3527 | }
|
3528 |
|
3529 | module.exports = cacheHas;
|
3530 |
|
3531 |
|
3532 | }),
|
3533 |
|
3534 | (function(module, exports, __webpack_require__) {
|
3535 |
|
3536 | var Symbol = __webpack_require__(9),
|
3537 | Uint8Array = __webpack_require__(62),
|
3538 | eq = __webpack_require__(12),
|
3539 | equalArrays = __webpack_require__(19),
|
3540 | mapToArray = __webpack_require__(63),
|
3541 | setToArray = __webpack_require__(64);
|
3542 |
|
3543 |
|
3544 | var COMPARE_PARTIAL_FLAG = 1,
|
3545 | COMPARE_UNORDERED_FLAG = 2;
|
3546 |
|
3547 |
|
3548 | var boolTag = '[object Boolean]',
|
3549 | dateTag = '[object Date]',
|
3550 | errorTag = '[object Error]',
|
3551 | mapTag = '[object Map]',
|
3552 | numberTag = '[object Number]',
|
3553 | regexpTag = '[object RegExp]',
|
3554 | setTag = '[object Set]',
|
3555 | stringTag = '[object String]',
|
3556 | symbolTag = '[object Symbol]';
|
3557 |
|
3558 | var arrayBufferTag = '[object ArrayBuffer]',
|
3559 | dataViewTag = '[object DataView]';
|
3560 |
|
3561 |
|
3562 | var symbolProto = Symbol ? Symbol.prototype : undefined,
|
3563 | symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
|
3564 |
|
3565 |
|
3566 |
|
3567 |
|
3568 |
|
3569 |
|
3570 |
|
3571 |
|
3572 |
|
3573 |
|
3574 |
|
3575 |
|
3576 |
|
3577 |
|
3578 |
|
3579 |
|
3580 |
|
3581 |
|
3582 | function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
|
3583 | switch (tag) {
|
3584 | case dataViewTag:
|
3585 | if ((object.byteLength != other.byteLength) ||
|
3586 | (object.byteOffset != other.byteOffset)) {
|
3587 | return false;
|
3588 | }
|
3589 | object = object.buffer;
|
3590 | other = other.buffer;
|
3591 |
|
3592 | case arrayBufferTag:
|
3593 | if ((object.byteLength != other.byteLength) ||
|
3594 | !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
|
3595 | return false;
|
3596 | }
|
3597 | return true;
|
3598 |
|
3599 | case boolTag:
|
3600 | case dateTag:
|
3601 | case numberTag:
|
3602 |
|
3603 |
|
3604 | return eq(+object, +other);
|
3605 |
|
3606 | case errorTag:
|
3607 | return object.name == other.name && object.message == other.message;
|
3608 |
|
3609 | case regexpTag:
|
3610 | case stringTag:
|
3611 |
|
3612 |
|
3613 |
|
3614 | return object == (other + '');
|
3615 |
|
3616 | case mapTag:
|
3617 | var convert = mapToArray;
|
3618 |
|
3619 | case setTag:
|
3620 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
|
3621 | convert || (convert = setToArray);
|
3622 |
|
3623 | if (object.size != other.size && !isPartial) {
|
3624 | return false;
|
3625 | }
|
3626 |
|
3627 | var stacked = stack.get(object);
|
3628 | if (stacked) {
|
3629 | return stacked == other;
|
3630 | }
|
3631 | bitmask |= COMPARE_UNORDERED_FLAG;
|
3632 |
|
3633 |
|
3634 | stack.set(object, other);
|
3635 | var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
|
3636 | stack['delete'](object);
|
3637 | return result;
|
3638 |
|
3639 | case symbolTag:
|
3640 | if (symbolValueOf) {
|
3641 | return symbolValueOf.call(object) == symbolValueOf.call(other);
|
3642 | }
|
3643 | }
|
3644 | return false;
|
3645 | }
|
3646 |
|
3647 | module.exports = equalByTag;
|
3648 |
|
3649 |
|
3650 | }),
|
3651 |
|
3652 | (function(module, exports, __webpack_require__) {
|
3653 |
|
3654 | var root = __webpack_require__(0);
|
3655 |
|
3656 |
|
3657 | var Uint8Array = root.Uint8Array;
|
3658 |
|
3659 | module.exports = Uint8Array;
|
3660 |
|
3661 |
|
3662 | }),
|
3663 |
|
3664 | (function(module, exports) {
|
3665 |
|
3666 |
|
3667 |
|
3668 |
|
3669 |
|
3670 |
|
3671 |
|
3672 |
|
3673 | function mapToArray(map) {
|
3674 | var index = -1,
|
3675 | result = Array(map.size);
|
3676 |
|
3677 | map.forEach(function(value, key) {
|
3678 | result[++index] = [key, value];
|
3679 | });
|
3680 | return result;
|
3681 | }
|
3682 |
|
3683 | module.exports = mapToArray;
|
3684 |
|
3685 |
|
3686 | }),
|
3687 |
|
3688 | (function(module, exports) {
|
3689 |
|
3690 |
|
3691 |
|
3692 |
|
3693 |
|
3694 |
|
3695 |
|
3696 |
|
3697 | function setToArray(set) {
|
3698 | var index = -1,
|
3699 | result = Array(set.size);
|
3700 |
|
3701 | set.forEach(function(value) {
|
3702 | result[++index] = value;
|
3703 | });
|
3704 | return result;
|
3705 | }
|
3706 |
|
3707 | module.exports = setToArray;
|
3708 |
|
3709 |
|
3710 | }),
|
3711 |
|
3712 | (function(module, exports, __webpack_require__) {
|
3713 |
|
3714 | var getAllKeys = __webpack_require__(66);
|
3715 |
|
3716 |
|
3717 | var COMPARE_PARTIAL_FLAG = 1;
|
3718 |
|
3719 |
|
3720 | var objectProto = Object.prototype;
|
3721 |
|
3722 |
|
3723 | var hasOwnProperty = objectProto.hasOwnProperty;
|
3724 |
|
3725 |
|
3726 |
|
3727 |
|
3728 |
|
3729 |
|
3730 |
|
3731 |
|
3732 |
|
3733 |
|
3734 |
|
3735 |
|
3736 |
|
3737 |
|
3738 | function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
|
3739 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
3740 | objProps = getAllKeys(object),
|
3741 | objLength = objProps.length,
|
3742 | othProps = getAllKeys(other),
|
3743 | othLength = othProps.length;
|
3744 |
|
3745 | if (objLength != othLength && !isPartial) {
|
3746 | return false;
|
3747 | }
|
3748 | var index = objLength;
|
3749 | while (index--) {
|
3750 | var key = objProps[index];
|
3751 | if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
|
3752 | return false;
|
3753 | }
|
3754 | }
|
3755 |
|
3756 | var stacked = stack.get(object);
|
3757 | if (stacked && stack.get(other)) {
|
3758 | return stacked == other;
|
3759 | }
|
3760 | var result = true;
|
3761 | stack.set(object, other);
|
3762 | stack.set(other, object);
|
3763 |
|
3764 | var skipCtor = isPartial;
|
3765 | while (++index < objLength) {
|
3766 | key = objProps[index];
|
3767 | var objValue = object[key],
|
3768 | othValue = other[key];
|
3769 |
|
3770 | if (customizer) {
|
3771 | var compared = isPartial
|
3772 | ? customizer(othValue, objValue, key, other, object, stack)
|
3773 | : customizer(objValue, othValue, key, object, other, stack);
|
3774 | }
|
3775 |
|
3776 | if (!(compared === undefined
|
3777 | ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
|
3778 | : compared
|
3779 | )) {
|
3780 | result = false;
|
3781 | break;
|
3782 | }
|
3783 | skipCtor || (skipCtor = key == 'constructor');
|
3784 | }
|
3785 | if (result && !skipCtor) {
|
3786 | var objCtor = object.constructor,
|
3787 | othCtor = other.constructor;
|
3788 |
|
3789 |
|
3790 | if (objCtor != othCtor &&
|
3791 | ('constructor' in object && 'constructor' in other) &&
|
3792 | !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
|
3793 | typeof othCtor == 'function' && othCtor instanceof othCtor)) {
|
3794 | result = false;
|
3795 | }
|
3796 | }
|
3797 | stack['delete'](object);
|
3798 | stack['delete'](other);
|
3799 | return result;
|
3800 | }
|
3801 |
|
3802 | module.exports = equalObjects;
|
3803 |
|
3804 |
|
3805 | }),
|
3806 |
|
3807 | (function(module, exports, __webpack_require__) {
|
3808 |
|
3809 | var baseGetAllKeys = __webpack_require__(67),
|
3810 | getSymbols = __webpack_require__(69),
|
3811 | keys = __webpack_require__(72);
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 |
|
3820 | function getAllKeys(object) {
|
3821 | return baseGetAllKeys(object, keys, getSymbols);
|
3822 | }
|
3823 |
|
3824 | module.exports = getAllKeys;
|
3825 |
|
3826 |
|
3827 | }),
|
3828 |
|
3829 | (function(module, exports, __webpack_require__) {
|
3830 |
|
3831 | var arrayPush = __webpack_require__(68),
|
3832 | isArray = __webpack_require__(10);
|
3833 |
|
3834 |
|
3835 |
|
3836 |
|
3837 |
|
3838 |
|
3839 |
|
3840 |
|
3841 |
|
3842 |
|
3843 |
|
3844 |
|
3845 | function baseGetAllKeys(object, keysFunc, symbolsFunc) {
|
3846 | var result = keysFunc(object);
|
3847 | return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
|
3848 | }
|
3849 |
|
3850 | module.exports = baseGetAllKeys;
|
3851 |
|
3852 |
|
3853 | }),
|
3854 |
|
3855 | (function(module, exports) {
|
3856 |
|
3857 |
|
3858 |
|
3859 |
|
3860 |
|
3861 |
|
3862 |
|
3863 |
|
3864 |
|
3865 | function arrayPush(array, values) {
|
3866 | var index = -1,
|
3867 | length = values.length,
|
3868 | offset = array.length;
|
3869 |
|
3870 | while (++index < length) {
|
3871 | array[offset + index] = values[index];
|
3872 | }
|
3873 | return array;
|
3874 | }
|
3875 |
|
3876 | module.exports = arrayPush;
|
3877 |
|
3878 |
|
3879 | }),
|
3880 |
|
3881 | (function(module, exports, __webpack_require__) {
|
3882 |
|
3883 | var arrayFilter = __webpack_require__(70),
|
3884 | stubArray = __webpack_require__(71);
|
3885 |
|
3886 |
|
3887 | var objectProto = Object.prototype;
|
3888 |
|
3889 |
|
3890 | var propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
3891 |
|
3892 |
|
3893 | var nativeGetSymbols = Object.getOwnPropertySymbols;
|
3894 |
|
3895 |
|
3896 |
|
3897 |
|
3898 |
|
3899 |
|
3900 |
|
3901 |
|
3902 | var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
|
3903 | if (object == null) {
|
3904 | return [];
|
3905 | }
|
3906 | object = Object(object);
|
3907 | return arrayFilter(nativeGetSymbols(object), function(symbol) {
|
3908 | return propertyIsEnumerable.call(object, symbol);
|
3909 | });
|
3910 | };
|
3911 |
|
3912 | module.exports = getSymbols;
|
3913 |
|
3914 |
|
3915 | }),
|
3916 |
|
3917 | (function(module, exports) {
|
3918 |
|
3919 |
|
3920 |
|
3921 |
|
3922 |
|
3923 |
|
3924 |
|
3925 |
|
3926 |
|
3927 |
|
3928 | function arrayFilter(array, predicate) {
|
3929 | var index = -1,
|
3930 | length = array == null ? 0 : array.length,
|
3931 | resIndex = 0,
|
3932 | result = [];
|
3933 |
|
3934 | while (++index < length) {
|
3935 | var value = array[index];
|
3936 | if (predicate(value, index, array)) {
|
3937 | result[resIndex++] = value;
|
3938 | }
|
3939 | }
|
3940 | return result;
|
3941 | }
|
3942 |
|
3943 | module.exports = arrayFilter;
|
3944 |
|
3945 |
|
3946 | }),
|
3947 |
|
3948 | (function(module, exports) {
|
3949 |
|
3950 |
|
3951 |
|
3952 |
|
3953 |
|
3954 |
|
3955 |
|
3956 |
|
3957 |
|
3958 |
|
3959 |
|
3960 |
|
3961 |
|
3962 |
|
3963 |
|
3964 |
|
3965 |
|
3966 |
|
3967 |
|
3968 | function stubArray() {
|
3969 | return [];
|
3970 | }
|
3971 |
|
3972 | module.exports = stubArray;
|
3973 |
|
3974 |
|
3975 | }),
|
3976 |
|
3977 | (function(module, exports, __webpack_require__) {
|
3978 |
|
3979 | var arrayLikeKeys = __webpack_require__(73),
|
3980 | baseKeys = __webpack_require__(82),
|
3981 | isArrayLike = __webpack_require__(86);
|
3982 |
|
3983 |
|
3984 |
|
3985 |
|
3986 |
|
3987 |
|
3988 |
|
3989 |
|
3990 |
|
3991 |
|
3992 |
|
3993 |
|
3994 |
|
3995 |
|
3996 |
|
3997 |
|
3998 |
|
3999 |
|
4000 |
|
4001 |
|
4002 |
|
4003 |
|
4004 |
|
4005 |
|
4006 |
|
4007 |
|
4008 |
|
4009 |
|
4010 |
|
4011 | function keys(object) {
|
4012 | return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
|
4013 | }
|
4014 |
|
4015 | module.exports = keys;
|
4016 |
|
4017 |
|
4018 | }),
|
4019 |
|
4020 | (function(module, exports, __webpack_require__) {
|
4021 |
|
4022 | var baseTimes = __webpack_require__(74),
|
4023 | isArguments = __webpack_require__(75),
|
4024 | isArray = __webpack_require__(10),
|
4025 | isBuffer = __webpack_require__(20),
|
4026 | isIndex = __webpack_require__(78),
|
4027 | isTypedArray = __webpack_require__(22);
|
4028 |
|
4029 |
|
4030 | var objectProto = Object.prototype;
|
4031 |
|
4032 |
|
4033 | var hasOwnProperty = objectProto.hasOwnProperty;
|
4034 |
|
4035 |
|
4036 |
|
4037 |
|
4038 |
|
4039 |
|
4040 |
|
4041 |
|
4042 |
|
4043 | function arrayLikeKeys(value, inherited) {
|
4044 | var isArr = isArray(value),
|
4045 | isArg = !isArr && isArguments(value),
|
4046 | isBuff = !isArr && !isArg && isBuffer(value),
|
4047 | isType = !isArr && !isArg && !isBuff && isTypedArray(value),
|
4048 | skipIndexes = isArr || isArg || isBuff || isType,
|
4049 | result = skipIndexes ? baseTimes(value.length, String) : [],
|
4050 | length = result.length;
|
4051 |
|
4052 | for (var key in value) {
|
4053 | if ((inherited || hasOwnProperty.call(value, key)) &&
|
4054 | !(skipIndexes && (
|
4055 |
|
4056 | key == 'length' ||
|
4057 |
|
4058 | (isBuff && (key == 'offset' || key == 'parent')) ||
|
4059 |
|
4060 | (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
|
4061 |
|
4062 | isIndex(key, length)
|
4063 | ))) {
|
4064 | result.push(key);
|
4065 | }
|
4066 | }
|
4067 | return result;
|
4068 | }
|
4069 |
|
4070 | module.exports = arrayLikeKeys;
|
4071 |
|
4072 |
|
4073 | }),
|
4074 |
|
4075 | (function(module, exports) {
|
4076 |
|
4077 |
|
4078 |
|
4079 |
|
4080 |
|
4081 |
|
4082 |
|
4083 |
|
4084 |
|
4085 |
|
4086 | function baseTimes(n, iteratee) {
|
4087 | var index = -1,
|
4088 | result = Array(n);
|
4089 |
|
4090 | while (++index < n) {
|
4091 | result[index] = iteratee(index);
|
4092 | }
|
4093 | return result;
|
4094 | }
|
4095 |
|
4096 | module.exports = baseTimes;
|
4097 |
|
4098 |
|
4099 | }),
|
4100 |
|
4101 | (function(module, exports, __webpack_require__) {
|
4102 |
|
4103 | var baseIsArguments = __webpack_require__(76),
|
4104 | isObjectLike = __webpack_require__(7);
|
4105 |
|
4106 |
|
4107 | var objectProto = Object.prototype;
|
4108 |
|
4109 |
|
4110 | var hasOwnProperty = objectProto.hasOwnProperty;
|
4111 |
|
4112 |
|
4113 | var propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
4114 |
|
4115 |
|
4116 |
|
4117 |
|
4118 |
|
4119 |
|
4120 |
|
4121 |
|
4122 |
|
4123 |
|
4124 |
|
4125 |
|
4126 |
|
4127 |
|
4128 |
|
4129 |
|
4130 |
|
4131 |
|
4132 |
|
4133 | var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
|
4134 | return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
|
4135 | !propertyIsEnumerable.call(value, 'callee');
|
4136 | };
|
4137 |
|
4138 | module.exports = isArguments;
|
4139 |
|
4140 |
|
4141 | }),
|
4142 |
|
4143 | (function(module, exports, __webpack_require__) {
|
4144 |
|
4145 | var baseGetTag = __webpack_require__(4),
|
4146 | isObjectLike = __webpack_require__(7);
|
4147 |
|
4148 |
|
4149 | var argsTag = '[object Arguments]';
|
4150 |
|
4151 |
|
4152 |
|
4153 |
|
4154 |
|
4155 |
|
4156 |
|
4157 |
|
4158 | function baseIsArguments(value) {
|
4159 | return isObjectLike(value) && baseGetTag(value) == argsTag;
|
4160 | }
|
4161 |
|
4162 | module.exports = baseIsArguments;
|
4163 |
|
4164 |
|
4165 | }),
|
4166 |
|
4167 | (function(module, exports) {
|
4168 |
|
4169 |
|
4170 |
|
4171 |
|
4172 |
|
4173 |
|
4174 |
|
4175 |
|
4176 |
|
4177 |
|
4178 |
|
4179 |
|
4180 |
|
4181 |
|
4182 | function stubFalse() {
|
4183 | return false;
|
4184 | }
|
4185 |
|
4186 | module.exports = stubFalse;
|
4187 |
|
4188 |
|
4189 | }),
|
4190 |
|
4191 | (function(module, exports) {
|
4192 |
|
4193 |
|
4194 | var MAX_SAFE_INTEGER = 9007199254740991;
|
4195 |
|
4196 |
|
4197 | var reIsUint = /^(?:0|[1-9]\d*)$/;
|
4198 |
|
4199 |
|
4200 |
|
4201 |
|
4202 |
|
4203 |
|
4204 |
|
4205 |
|
4206 |
|
4207 | function isIndex(value, length) {
|
4208 | var type = typeof value;
|
4209 | length = length == null ? MAX_SAFE_INTEGER : length;
|
4210 |
|
4211 | return !!length &&
|
4212 | (type == 'number' ||
|
4213 | (type != 'symbol' && reIsUint.test(value))) &&
|
4214 | (value > -1 && value % 1 == 0 && value < length);
|
4215 | }
|
4216 |
|
4217 | module.exports = isIndex;
|
4218 |
|
4219 |
|
4220 | }),
|
4221 |
|
4222 | (function(module, exports, __webpack_require__) {
|
4223 |
|
4224 | var baseGetTag = __webpack_require__(4),
|
4225 | isLength = __webpack_require__(23),
|
4226 | isObjectLike = __webpack_require__(7);
|
4227 |
|
4228 |
|
4229 | var argsTag = '[object Arguments]',
|
4230 | arrayTag = '[object Array]',
|
4231 | boolTag = '[object Boolean]',
|
4232 | dateTag = '[object Date]',
|
4233 | errorTag = '[object Error]',
|
4234 | funcTag = '[object Function]',
|
4235 | mapTag = '[object Map]',
|
4236 | numberTag = '[object Number]',
|
4237 | objectTag = '[object Object]',
|
4238 | regexpTag = '[object RegExp]',
|
4239 | setTag = '[object Set]',
|
4240 | stringTag = '[object String]',
|
4241 | weakMapTag = '[object WeakMap]';
|
4242 |
|
4243 | var arrayBufferTag = '[object ArrayBuffer]',
|
4244 | dataViewTag = '[object DataView]',
|
4245 | float32Tag = '[object Float32Array]',
|
4246 | float64Tag = '[object Float64Array]',
|
4247 | int8Tag = '[object Int8Array]',
|
4248 | int16Tag = '[object Int16Array]',
|
4249 | int32Tag = '[object Int32Array]',
|
4250 | uint8Tag = '[object Uint8Array]',
|
4251 | uint8ClampedTag = '[object Uint8ClampedArray]',
|
4252 | uint16Tag = '[object Uint16Array]',
|
4253 | uint32Tag = '[object Uint32Array]';
|
4254 |
|
4255 |
|
4256 | var typedArrayTags = {};
|
4257 | typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
|
4258 | typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
|
4259 | typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
|
4260 | typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
|
4261 | typedArrayTags[uint32Tag] = true;
|
4262 | typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
|
4263 | typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
|
4264 | typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
|
4265 | typedArrayTags[errorTag] = typedArrayTags[funcTag] =
|
4266 | typedArrayTags[mapTag] = typedArrayTags[numberTag] =
|
4267 | typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
|
4268 | typedArrayTags[setTag] = typedArrayTags[stringTag] =
|
4269 | typedArrayTags[weakMapTag] = false;
|
4270 |
|
4271 |
|
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 |
|
4277 |
|
4278 | function baseIsTypedArray(value) {
|
4279 | return isObjectLike(value) &&
|
4280 | isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
|
4281 | }
|
4282 |
|
4283 | module.exports = baseIsTypedArray;
|
4284 |
|
4285 |
|
4286 | }),
|
4287 |
|
4288 | (function(module, exports) {
|
4289 |
|
4290 |
|
4291 |
|
4292 |
|
4293 |
|
4294 |
|
4295 |
|
4296 |
|
4297 | function baseUnary(func) {
|
4298 | return function(value) {
|
4299 | return func(value);
|
4300 | };
|
4301 | }
|
4302 |
|
4303 | module.exports = baseUnary;
|
4304 |
|
4305 |
|
4306 | }),
|
4307 |
|
4308 | (function(module, exports, __webpack_require__) {
|
4309 |
|
4310 | (function(module) {var freeGlobal = __webpack_require__(14);
|
4311 |
|
4312 |
|
4313 | var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
|
4314 |
|
4315 |
|
4316 | var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
|
4317 |
|
4318 |
|
4319 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
4320 |
|
4321 |
|
4322 | var freeProcess = moduleExports && freeGlobal.process;
|
4323 |
|
4324 |
|
4325 | var nodeUtil = (function() {
|
4326 | try {
|
4327 |
|
4328 | var types = freeModule && freeModule.require && freeModule.require('util').types;
|
4329 |
|
4330 | if (types) {
|
4331 | return types;
|
4332 | }
|
4333 |
|
4334 |
|
4335 | return freeProcess && freeProcess.binding && freeProcess.binding('util');
|
4336 | } catch (e) {}
|
4337 | }());
|
4338 |
|
4339 | module.exports = nodeUtil;
|
4340 |
|
4341 | }.call(exports, __webpack_require__(21)(module)))
|
4342 |
|
4343 | }),
|
4344 |
|
4345 | (function(module, exports, __webpack_require__) {
|
4346 |
|
4347 | var isPrototype = __webpack_require__(83),
|
4348 | nativeKeys = __webpack_require__(84);
|
4349 |
|
4350 |
|
4351 | var objectProto = Object.prototype;
|
4352 |
|
4353 |
|
4354 | var hasOwnProperty = objectProto.hasOwnProperty;
|
4355 |
|
4356 |
|
4357 |
|
4358 |
|
4359 |
|
4360 |
|
4361 |
|
4362 |
|
4363 | function baseKeys(object) {
|
4364 | if (!isPrototype(object)) {
|
4365 | return nativeKeys(object);
|
4366 | }
|
4367 | var result = [];
|
4368 | for (var key in Object(object)) {
|
4369 | if (hasOwnProperty.call(object, key) && key != 'constructor') {
|
4370 | result.push(key);
|
4371 | }
|
4372 | }
|
4373 | return result;
|
4374 | }
|
4375 |
|
4376 | module.exports = baseKeys;
|
4377 |
|
4378 |
|
4379 | }),
|
4380 |
|
4381 | (function(module, exports) {
|
4382 |
|
4383 |
|
4384 | var objectProto = Object.prototype;
|
4385 |
|
4386 |
|
4387 |
|
4388 |
|
4389 |
|
4390 |
|
4391 |
|
4392 |
|
4393 | function isPrototype(value) {
|
4394 | var Ctor = value && value.constructor,
|
4395 | proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
4396 |
|
4397 | return value === proto;
|
4398 | }
|
4399 |
|
4400 | module.exports = isPrototype;
|
4401 |
|
4402 |
|
4403 | }),
|
4404 |
|
4405 | (function(module, exports, __webpack_require__) {
|
4406 |
|
4407 | var overArg = __webpack_require__(85);
|
4408 |
|
4409 |
|
4410 | var nativeKeys = overArg(Object.keys, Object);
|
4411 |
|
4412 | module.exports = nativeKeys;
|
4413 |
|
4414 |
|
4415 | }),
|
4416 |
|
4417 | (function(module, exports) {
|
4418 |
|
4419 |
|
4420 |
|
4421 |
|
4422 |
|
4423 |
|
4424 |
|
4425 |
|
4426 |
|
4427 | function overArg(func, transform) {
|
4428 | return function(arg) {
|
4429 | return func(transform(arg));
|
4430 | };
|
4431 | }
|
4432 |
|
4433 | module.exports = overArg;
|
4434 |
|
4435 |
|
4436 | }),
|
4437 |
|
4438 | (function(module, exports, __webpack_require__) {
|
4439 |
|
4440 | var isFunction = __webpack_require__(13),
|
4441 | isLength = __webpack_require__(23);
|
4442 |
|
4443 |
|
4444 |
|
4445 |
|
4446 |
|
4447 |
|
4448 |
|
4449 |
|
4450 |
|
4451 |
|
4452 |
|
4453 |
|
4454 |
|
4455 |
|
4456 |
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 |
|
4463 |
|
4464 |
|
4465 |
|
4466 |
|
4467 |
|
4468 | function isArrayLike(value) {
|
4469 | return value != null && isLength(value.length) && !isFunction(value);
|
4470 | }
|
4471 |
|
4472 | module.exports = isArrayLike;
|
4473 |
|
4474 |
|
4475 | }),
|
4476 |
|
4477 | (function(module, exports, __webpack_require__) {
|
4478 |
|
4479 | var DataView = __webpack_require__(88),
|
4480 | Map = __webpack_require__(8),
|
4481 | Promise = __webpack_require__(89),
|
4482 | Set = __webpack_require__(90),
|
4483 | WeakMap = __webpack_require__(91),
|
4484 | baseGetTag = __webpack_require__(4),
|
4485 | toSource = __webpack_require__(17);
|
4486 |
|
4487 |
|
4488 | var mapTag = '[object Map]',
|
4489 | objectTag = '[object Object]',
|
4490 | promiseTag = '[object Promise]',
|
4491 | setTag = '[object Set]',
|
4492 | weakMapTag = '[object WeakMap]';
|
4493 |
|
4494 | var dataViewTag = '[object DataView]';
|
4495 |
|
4496 |
|
4497 | var dataViewCtorString = toSource(DataView),
|
4498 | mapCtorString = toSource(Map),
|
4499 | promiseCtorString = toSource(Promise),
|
4500 | setCtorString = toSource(Set),
|
4501 | weakMapCtorString = toSource(WeakMap);
|
4502 |
|
4503 |
|
4504 |
|
4505 |
|
4506 |
|
4507 |
|
4508 |
|
4509 |
|
4510 | var getTag = baseGetTag;
|
4511 |
|
4512 |
|
4513 | if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
|
4514 | (Map && getTag(new Map) != mapTag) ||
|
4515 | (Promise && getTag(Promise.resolve()) != promiseTag) ||
|
4516 | (Set && getTag(new Set) != setTag) ||
|
4517 | (WeakMap && getTag(new WeakMap) != weakMapTag)) {
|
4518 | getTag = function(value) {
|
4519 | var result = baseGetTag(value),
|
4520 | Ctor = result == objectTag ? value.constructor : undefined,
|
4521 | ctorString = Ctor ? toSource(Ctor) : '';
|
4522 |
|
4523 | if (ctorString) {
|
4524 | switch (ctorString) {
|
4525 | case dataViewCtorString: return dataViewTag;
|
4526 | case mapCtorString: return mapTag;
|
4527 | case promiseCtorString: return promiseTag;
|
4528 | case setCtorString: return setTag;
|
4529 | case weakMapCtorString: return weakMapTag;
|
4530 | }
|
4531 | }
|
4532 | return result;
|
4533 | };
|
4534 | }
|
4535 |
|
4536 | module.exports = getTag;
|
4537 |
|
4538 |
|
4539 | }),
|
4540 |
|
4541 | (function(module, exports, __webpack_require__) {
|
4542 |
|
4543 | var getNative = __webpack_require__(1),
|
4544 | root = __webpack_require__(0);
|
4545 |
|
4546 |
|
4547 | var DataView = getNative(root, 'DataView');
|
4548 |
|
4549 | module.exports = DataView;
|
4550 |
|
4551 |
|
4552 | }),
|
4553 |
|
4554 | (function(module, exports, __webpack_require__) {
|
4555 |
|
4556 | var getNative = __webpack_require__(1),
|
4557 | root = __webpack_require__(0);
|
4558 |
|
4559 |
|
4560 | var Promise = getNative(root, 'Promise');
|
4561 |
|
4562 | module.exports = Promise;
|
4563 |
|
4564 |
|
4565 | }),
|
4566 |
|
4567 | (function(module, exports, __webpack_require__) {
|
4568 |
|
4569 | var getNative = __webpack_require__(1),
|
4570 | root = __webpack_require__(0);
|
4571 |
|
4572 |
|
4573 | var Set = getNative(root, 'Set');
|
4574 |
|
4575 | module.exports = Set;
|
4576 |
|
4577 |
|
4578 | }),
|
4579 |
|
4580 | (function(module, exports, __webpack_require__) {
|
4581 |
|
4582 | var getNative = __webpack_require__(1),
|
4583 | root = __webpack_require__(0);
|
4584 |
|
4585 |
|
4586 | var WeakMap = getNative(root, 'WeakMap');
|
4587 |
|
4588 | module.exports = WeakMap;
|
4589 |
|
4590 |
|
4591 | }),
|
4592 |
|
4593 | (function(module, exports, __webpack_require__) {
|
4594 |
|
4595 | "use strict";
|
4596 |
|
4597 |
|
4598 |
|
4599 |
|
4600 |
|
4601 |
|
4602 |
|
4603 |
|
4604 |
|
4605 | var assign = __webpack_require__(93);
|
4606 |
|
4607 | var ReactPropTypesSecret = __webpack_require__(11);
|
4608 | var checkPropTypes = __webpack_require__(94);
|
4609 |
|
4610 | var printWarning = function() {};
|
4611 |
|
4612 | if ("production".NODE_ENV !== 'production') {
|
4613 | printWarning = function(text) {
|
4614 | var message = 'Warning: ' + text;
|
4615 | if (typeof console !== 'undefined') {
|
4616 | console.error(message);
|
4617 | }
|
4618 | try {
|
4619 |
|
4620 |
|
4621 |
|
4622 | throw new Error(message);
|
4623 | } catch (x) {}
|
4624 | };
|
4625 | }
|
4626 |
|
4627 | function emptyFunctionThatReturnsNull() {
|
4628 | return null;
|
4629 | }
|
4630 |
|
4631 | module.exports = function(isValidElement, throwOnDirectAccess) {
|
4632 |
|
4633 | var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
4634 | var FAUX_ITERATOR_SYMBOL = '@@iterator';
|
4635 |
|
4636 | |
4637 |
|
4638 |
|
4639 |
|
4640 |
|
4641 |
|
4642 |
|
4643 |
|
4644 |
|
4645 |
|
4646 |
|
4647 |
|
4648 |
|
4649 |
|
4650 | function getIteratorFn(maybeIterable) {
|
4651 | var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
4652 | if (typeof iteratorFn === 'function') {
|
4653 | return iteratorFn;
|
4654 | }
|
4655 | }
|
4656 |
|
4657 | |
4658 |
|
4659 |
|
4660 |
|
4661 |
|
4662 |
|
4663 |
|
4664 |
|
4665 |
|
4666 |
|
4667 |
|
4668 |
|
4669 |
|
4670 |
|
4671 |
|
4672 |
|
4673 |
|
4674 |
|
4675 |
|
4676 |
|
4677 |
|
4678 |
|
4679 |
|
4680 |
|
4681 |
|
4682 |
|
4683 |
|
4684 |
|
4685 |
|
4686 |
|
4687 |
|
4688 |
|
4689 |
|
4690 |
|
4691 |
|
4692 |
|
4693 |
|
4694 |
|
4695 |
|
4696 |
|
4697 |
|
4698 |
|
4699 |
|
4700 |
|
4701 |
|
4702 |
|
4703 |
|
4704 | var ANONYMOUS = '<<anonymous>>';
|
4705 |
|
4706 |
|
4707 |
|
4708 | var ReactPropTypes = {
|
4709 | array: createPrimitiveTypeChecker('array'),
|
4710 | bool: createPrimitiveTypeChecker('boolean'),
|
4711 | func: createPrimitiveTypeChecker('function'),
|
4712 | number: createPrimitiveTypeChecker('number'),
|
4713 | object: createPrimitiveTypeChecker('object'),
|
4714 | string: createPrimitiveTypeChecker('string'),
|
4715 | symbol: createPrimitiveTypeChecker('symbol'),
|
4716 |
|
4717 | any: createAnyTypeChecker(),
|
4718 | arrayOf: createArrayOfTypeChecker,
|
4719 | element: createElementTypeChecker(),
|
4720 | instanceOf: createInstanceTypeChecker,
|
4721 | node: createNodeChecker(),
|
4722 | objectOf: createObjectOfTypeChecker,
|
4723 | oneOf: createEnumTypeChecker,
|
4724 | oneOfType: createUnionTypeChecker,
|
4725 | shape: createShapeTypeChecker,
|
4726 | exact: createStrictShapeTypeChecker,
|
4727 | };
|
4728 |
|
4729 | |
4730 |
|
4731 |
|
4732 |
|
4733 |
|
4734 | function is(x, y) {
|
4735 |
|
4736 | if (x === y) {
|
4737 |
|
4738 |
|
4739 | return x !== 0 || 1 / x === 1 / y;
|
4740 | } else {
|
4741 |
|
4742 | return x !== x && y !== y;
|
4743 | }
|
4744 | }
|
4745 |
|
4746 |
|
4747 | |
4748 |
|
4749 |
|
4750 |
|
4751 |
|
4752 |
|
4753 |
|
4754 | function PropTypeError(message) {
|
4755 | this.message = message;
|
4756 | this.stack = '';
|
4757 | }
|
4758 |
|
4759 | PropTypeError.prototype = Error.prototype;
|
4760 |
|
4761 | function createChainableTypeChecker(validate) {
|
4762 | if ("production".NODE_ENV !== 'production') {
|
4763 | var manualPropTypeCallCache = {};
|
4764 | var manualPropTypeWarningCount = 0;
|
4765 | }
|
4766 | function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
4767 | componentName = componentName || ANONYMOUS;
|
4768 | propFullName = propFullName || propName;
|
4769 |
|
4770 | if (secret !== ReactPropTypesSecret) {
|
4771 | if (throwOnDirectAccess) {
|
4772 |
|
4773 | var err = new Error(
|
4774 | 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
4775 | 'Use `PropTypes.checkPropTypes()` to call them. ' +
|
4776 | 'Read more at http://fb.me/use-check-prop-types'
|
4777 | );
|
4778 | err.name = 'Invariant Violation';
|
4779 | throw err;
|
4780 | } else if ("production".NODE_ENV !== 'production' && typeof console !== 'undefined') {
|
4781 |
|
4782 | var cacheKey = componentName + ':' + propName;
|
4783 | if (
|
4784 | !manualPropTypeCallCache[cacheKey] &&
|
4785 |
|
4786 | manualPropTypeWarningCount < 3
|
4787 | ) {
|
4788 | printWarning(
|
4789 | 'You are manually calling a React.PropTypes validation ' +
|
4790 | 'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
|
4791 | 'and will throw in the standalone `prop-types` package. ' +
|
4792 | 'You may be seeing this warning due to a third-party PropTypes ' +
|
4793 | 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
|
4794 | );
|
4795 | manualPropTypeCallCache[cacheKey] = true;
|
4796 | manualPropTypeWarningCount++;
|
4797 | }
|
4798 | }
|
4799 | }
|
4800 | if (props[propName] == null) {
|
4801 | if (isRequired) {
|
4802 | if (props[propName] === null) {
|
4803 | return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
|
4804 | }
|
4805 | return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
|
4806 | }
|
4807 | return null;
|
4808 | } else {
|
4809 | return validate(props, propName, componentName, location, propFullName);
|
4810 | }
|
4811 | }
|
4812 |
|
4813 | var chainedCheckType = checkType.bind(null, false);
|
4814 | chainedCheckType.isRequired = checkType.bind(null, true);
|
4815 |
|
4816 | return chainedCheckType;
|
4817 | }
|
4818 |
|
4819 | function createPrimitiveTypeChecker(expectedType) {
|
4820 | function validate(props, propName, componentName, location, propFullName, secret) {
|
4821 | var propValue = props[propName];
|
4822 | var propType = getPropType(propValue);
|
4823 | if (propType !== expectedType) {
|
4824 |
|
4825 |
|
4826 |
|
4827 | var preciseType = getPreciseType(propValue);
|
4828 |
|
4829 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
|
4830 | }
|
4831 | return null;
|
4832 | }
|
4833 | return createChainableTypeChecker(validate);
|
4834 | }
|
4835 |
|
4836 | function createAnyTypeChecker() {
|
4837 | return createChainableTypeChecker(emptyFunctionThatReturnsNull);
|
4838 | }
|
4839 |
|
4840 | function createArrayOfTypeChecker(typeChecker) {
|
4841 | function validate(props, propName, componentName, location, propFullName) {
|
4842 | if (typeof typeChecker !== 'function') {
|
4843 | return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
|
4844 | }
|
4845 | var propValue = props[propName];
|
4846 | if (!Array.isArray(propValue)) {
|
4847 | var propType = getPropType(propValue);
|
4848 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
4849 | }
|
4850 | for (var i = 0; i < propValue.length; i++) {
|
4851 | var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
|
4852 | if (error instanceof Error) {
|
4853 | return error;
|
4854 | }
|
4855 | }
|
4856 | return null;
|
4857 | }
|
4858 | return createChainableTypeChecker(validate);
|
4859 | }
|
4860 |
|
4861 | function createElementTypeChecker() {
|
4862 | function validate(props, propName, componentName, location, propFullName) {
|
4863 | var propValue = props[propName];
|
4864 | if (!isValidElement(propValue)) {
|
4865 | var propType = getPropType(propValue);
|
4866 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
4867 | }
|
4868 | return null;
|
4869 | }
|
4870 | return createChainableTypeChecker(validate);
|
4871 | }
|
4872 |
|
4873 | function createInstanceTypeChecker(expectedClass) {
|
4874 | function validate(props, propName, componentName, location, propFullName) {
|
4875 | if (!(props[propName] instanceof expectedClass)) {
|
4876 | var expectedClassName = expectedClass.name || ANONYMOUS;
|
4877 | var actualClassName = getClassName(props[propName]);
|
4878 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
4879 | }
|
4880 | return null;
|
4881 | }
|
4882 | return createChainableTypeChecker(validate);
|
4883 | }
|
4884 |
|
4885 | function createEnumTypeChecker(expectedValues) {
|
4886 | if (!Array.isArray(expectedValues)) {
|
4887 | "production".NODE_ENV !== 'production' ? printWarning('Invalid argument supplied to oneOf, expected an instance of array.') : void 0;
|
4888 | return emptyFunctionThatReturnsNull;
|
4889 | }
|
4890 |
|
4891 | function validate(props, propName, componentName, location, propFullName) {
|
4892 | var propValue = props[propName];
|
4893 | for (var i = 0; i < expectedValues.length; i++) {
|
4894 | if (is(propValue, expectedValues[i])) {
|
4895 | return null;
|
4896 | }
|
4897 | }
|
4898 |
|
4899 | var valuesString = JSON.stringify(expectedValues);
|
4900 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
4901 | }
|
4902 | return createChainableTypeChecker(validate);
|
4903 | }
|
4904 |
|
4905 | function createObjectOfTypeChecker(typeChecker) {
|
4906 | function validate(props, propName, componentName, location, propFullName) {
|
4907 | if (typeof typeChecker !== 'function') {
|
4908 | return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
4909 | }
|
4910 | var propValue = props[propName];
|
4911 | var propType = getPropType(propValue);
|
4912 | if (propType !== 'object') {
|
4913 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
4914 | }
|
4915 | for (var key in propValue) {
|
4916 | if (propValue.hasOwnProperty(key)) {
|
4917 | var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
4918 | if (error instanceof Error) {
|
4919 | return error;
|
4920 | }
|
4921 | }
|
4922 | }
|
4923 | return null;
|
4924 | }
|
4925 | return createChainableTypeChecker(validate);
|
4926 | }
|
4927 |
|
4928 | function createUnionTypeChecker(arrayOfTypeCheckers) {
|
4929 | if (!Array.isArray(arrayOfTypeCheckers)) {
|
4930 | "production".NODE_ENV !== 'production' ? printWarning('Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
|
4931 | return emptyFunctionThatReturnsNull;
|
4932 | }
|
4933 |
|
4934 | for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
4935 | var checker = arrayOfTypeCheckers[i];
|
4936 | if (typeof checker !== 'function') {
|
4937 | printWarning(
|
4938 | 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
|
4939 | 'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'
|
4940 | );
|
4941 | return emptyFunctionThatReturnsNull;
|
4942 | }
|
4943 | }
|
4944 |
|
4945 | function validate(props, propName, componentName, location, propFullName) {
|
4946 | for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
4947 | var checker = arrayOfTypeCheckers[i];
|
4948 | if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret) == null) {
|
4949 | return null;
|
4950 | }
|
4951 | }
|
4952 |
|
4953 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
|
4954 | }
|
4955 | return createChainableTypeChecker(validate);
|
4956 | }
|
4957 |
|
4958 | function createNodeChecker() {
|
4959 | function validate(props, propName, componentName, location, propFullName) {
|
4960 | if (!isNode(props[propName])) {
|
4961 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
4962 | }
|
4963 | return null;
|
4964 | }
|
4965 | return createChainableTypeChecker(validate);
|
4966 | }
|
4967 |
|
4968 | function createShapeTypeChecker(shapeTypes) {
|
4969 | function validate(props, propName, componentName, location, propFullName) {
|
4970 | var propValue = props[propName];
|
4971 | var propType = getPropType(propValue);
|
4972 | if (propType !== 'object') {
|
4973 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
4974 | }
|
4975 | for (var key in shapeTypes) {
|
4976 | var checker = shapeTypes[key];
|
4977 | if (!checker) {
|
4978 | continue;
|
4979 | }
|
4980 | var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
4981 | if (error) {
|
4982 | return error;
|
4983 | }
|
4984 | }
|
4985 | return null;
|
4986 | }
|
4987 | return createChainableTypeChecker(validate);
|
4988 | }
|
4989 |
|
4990 | function createStrictShapeTypeChecker(shapeTypes) {
|
4991 | function validate(props, propName, componentName, location, propFullName) {
|
4992 | var propValue = props[propName];
|
4993 | var propType = getPropType(propValue);
|
4994 | if (propType !== 'object') {
|
4995 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
4996 | }
|
4997 |
|
4998 |
|
4999 | var allKeys = assign({}, props[propName], shapeTypes);
|
5000 | for (var key in allKeys) {
|
5001 | var checker = shapeTypes[key];
|
5002 | if (!checker) {
|
5003 | return new PropTypeError(
|
5004 | 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
|
5005 | '\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
|
5006 | '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
|
5007 | );
|
5008 | }
|
5009 | var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
5010 | if (error) {
|
5011 | return error;
|
5012 | }
|
5013 | }
|
5014 | return null;
|
5015 | }
|
5016 |
|
5017 | return createChainableTypeChecker(validate);
|
5018 | }
|
5019 |
|
5020 | function isNode(propValue) {
|
5021 | switch (typeof propValue) {
|
5022 | case 'number':
|
5023 | case 'string':
|
5024 | case 'undefined':
|
5025 | return true;
|
5026 | case 'boolean':
|
5027 | return !propValue;
|
5028 | case 'object':
|
5029 | if (Array.isArray(propValue)) {
|
5030 | return propValue.every(isNode);
|
5031 | }
|
5032 | if (propValue === null || isValidElement(propValue)) {
|
5033 | return true;
|
5034 | }
|
5035 |
|
5036 | var iteratorFn = getIteratorFn(propValue);
|
5037 | if (iteratorFn) {
|
5038 | var iterator = iteratorFn.call(propValue);
|
5039 | var step;
|
5040 | if (iteratorFn !== propValue.entries) {
|
5041 | while (!(step = iterator.next()).done) {
|
5042 | if (!isNode(step.value)) {
|
5043 | return false;
|
5044 | }
|
5045 | }
|
5046 | } else {
|
5047 |
|
5048 | while (!(step = iterator.next()).done) {
|
5049 | var entry = step.value;
|
5050 | if (entry) {
|
5051 | if (!isNode(entry[1])) {
|
5052 | return false;
|
5053 | }
|
5054 | }
|
5055 | }
|
5056 | }
|
5057 | } else {
|
5058 | return false;
|
5059 | }
|
5060 |
|
5061 | return true;
|
5062 | default:
|
5063 | return false;
|
5064 | }
|
5065 | }
|
5066 |
|
5067 | function isSymbol(propType, propValue) {
|
5068 |
|
5069 | if (propType === 'symbol') {
|
5070 | return true;
|
5071 | }
|
5072 |
|
5073 |
|
5074 | if (propValue['@@toStringTag'] === 'Symbol') {
|
5075 | return true;
|
5076 | }
|
5077 |
|
5078 |
|
5079 | if (typeof Symbol === 'function' && propValue instanceof Symbol) {
|
5080 | return true;
|
5081 | }
|
5082 |
|
5083 | return false;
|
5084 | }
|
5085 |
|
5086 |
|
5087 | function getPropType(propValue) {
|
5088 | var propType = typeof propValue;
|
5089 | if (Array.isArray(propValue)) {
|
5090 | return 'array';
|
5091 | }
|
5092 | if (propValue instanceof RegExp) {
|
5093 |
|
5094 |
|
5095 |
|
5096 | return 'object';
|
5097 | }
|
5098 | if (isSymbol(propType, propValue)) {
|
5099 | return 'symbol';
|
5100 | }
|
5101 | return propType;
|
5102 | }
|
5103 |
|
5104 |
|
5105 |
|
5106 | function getPreciseType(propValue) {
|
5107 | if (typeof propValue === 'undefined' || propValue === null) {
|
5108 | return '' + propValue;
|
5109 | }
|
5110 | var propType = getPropType(propValue);
|
5111 | if (propType === 'object') {
|
5112 | if (propValue instanceof Date) {
|
5113 | return 'date';
|
5114 | } else if (propValue instanceof RegExp) {
|
5115 | return 'regexp';
|
5116 | }
|
5117 | }
|
5118 | return propType;
|
5119 | }
|
5120 |
|
5121 |
|
5122 |
|
5123 | function getPostfixForTypeWarning(value) {
|
5124 | var type = getPreciseType(value);
|
5125 | switch (type) {
|
5126 | case 'array':
|
5127 | case 'object':
|
5128 | return 'an ' + type;
|
5129 | case 'boolean':
|
5130 | case 'date':
|
5131 | case 'regexp':
|
5132 | return 'a ' + type;
|
5133 | default:
|
5134 | return type;
|
5135 | }
|
5136 | }
|
5137 |
|
5138 |
|
5139 | function getClassName(propValue) {
|
5140 | if (!propValue.constructor || !propValue.constructor.name) {
|
5141 | return ANONYMOUS;
|
5142 | }
|
5143 | return propValue.constructor.name;
|
5144 | }
|
5145 |
|
5146 | ReactPropTypes.checkPropTypes = checkPropTypes;
|
5147 | ReactPropTypes.PropTypes = ReactPropTypes;
|
5148 |
|
5149 | return ReactPropTypes;
|
5150 | };
|
5151 |
|
5152 |
|
5153 | }),
|
5154 |
|
5155 | (function(module, exports, __webpack_require__) {
|
5156 |
|
5157 | "use strict";
|
5158 |
|
5159 |
|
5160 |
|
5161 |
|
5162 |
|
5163 |
|
5164 |
|
5165 |
|
5166 | var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
5167 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
5168 | var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
5169 |
|
5170 | function toObject(val) {
|
5171 | if (val === null || val === undefined) {
|
5172 | throw new TypeError('Object.assign cannot be called with null or undefined');
|
5173 | }
|
5174 |
|
5175 | return Object(val);
|
5176 | }
|
5177 |
|
5178 | function shouldUseNative() {
|
5179 | try {
|
5180 | if (!Object.assign) {
|
5181 | return false;
|
5182 | }
|
5183 |
|
5184 |
|
5185 |
|
5186 |
|
5187 | var test1 = new String('abc');
|
5188 | test1[5] = 'de';
|
5189 | if (Object.getOwnPropertyNames(test1)[0] === '5') {
|
5190 | return false;
|
5191 | }
|
5192 |
|
5193 |
|
5194 | var test2 = {};
|
5195 | for (var i = 0; i < 10; i++) {
|
5196 | test2['_' + String.fromCharCode(i)] = i;
|
5197 | }
|
5198 | var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
|
5199 | return test2[n];
|
5200 | });
|
5201 | if (order2.join('') !== '0123456789') {
|
5202 | return false;
|
5203 | }
|
5204 |
|
5205 |
|
5206 | var test3 = {};
|
5207 | 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
|
5208 | test3[letter] = letter;
|
5209 | });
|
5210 | if (Object.keys(Object.assign({}, test3)).join('') !==
|
5211 | 'abcdefghijklmnopqrst') {
|
5212 | return false;
|
5213 | }
|
5214 |
|
5215 | return true;
|
5216 | } catch (err) {
|
5217 |
|
5218 | return false;
|
5219 | }
|
5220 | }
|
5221 |
|
5222 | module.exports = shouldUseNative() ? Object.assign : function (target, source) {
|
5223 | var from;
|
5224 | var to = toObject(target);
|
5225 | var symbols;
|
5226 |
|
5227 | for (var s = 1; s < arguments.length; s++) {
|
5228 | from = Object(arguments[s]);
|
5229 |
|
5230 | for (var key in from) {
|
5231 | if (hasOwnProperty.call(from, key)) {
|
5232 | to[key] = from[key];
|
5233 | }
|
5234 | }
|
5235 |
|
5236 | if (getOwnPropertySymbols) {
|
5237 | symbols = getOwnPropertySymbols(from);
|
5238 | for (var i = 0; i < symbols.length; i++) {
|
5239 | if (propIsEnumerable.call(from, symbols[i])) {
|
5240 | to[symbols[i]] = from[symbols[i]];
|
5241 | }
|
5242 | }
|
5243 | }
|
5244 | }
|
5245 |
|
5246 | return to;
|
5247 | };
|
5248 |
|
5249 |
|
5250 | }),
|
5251 |
|
5252 | (function(module, exports, __webpack_require__) {
|
5253 |
|
5254 | "use strict";
|
5255 |
|
5256 |
|
5257 |
|
5258 |
|
5259 |
|
5260 |
|
5261 |
|
5262 |
|
5263 |
|
5264 | var printWarning = function() {};
|
5265 |
|
5266 | if ("production".NODE_ENV !== 'production') {
|
5267 | var ReactPropTypesSecret = __webpack_require__(11);
|
5268 | var loggedTypeFailures = {};
|
5269 |
|
5270 | printWarning = function(text) {
|
5271 | var message = 'Warning: ' + text;
|
5272 | if (typeof console !== 'undefined') {
|
5273 | console.error(message);
|
5274 | }
|
5275 | try {
|
5276 |
|
5277 |
|
5278 |
|
5279 | throw new Error(message);
|
5280 | } catch (x) {}
|
5281 | };
|
5282 | }
|
5283 |
|
5284 |
|
5285 |
|
5286 |
|
5287 |
|
5288 |
|
5289 |
|
5290 |
|
5291 |
|
5292 |
|
5293 |
|
5294 |
|
5295 | function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
5296 | if ("production".NODE_ENV !== 'production') {
|
5297 | for (var typeSpecName in typeSpecs) {
|
5298 | if (typeSpecs.hasOwnProperty(typeSpecName)) {
|
5299 | var error;
|
5300 |
|
5301 |
|
5302 |
|
5303 | try {
|
5304 |
|
5305 |
|
5306 | if (typeof typeSpecs[typeSpecName] !== 'function') {
|
5307 | var err = Error(
|
5308 | (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
|
5309 | 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
|
5310 | );
|
5311 | err.name = 'Invariant Violation';
|
5312 | throw err;
|
5313 | }
|
5314 | error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
|
5315 | } catch (ex) {
|
5316 | error = ex;
|
5317 | }
|
5318 | if (error && !(error instanceof Error)) {
|
5319 | printWarning(
|
5320 | (componentName || 'React class') + ': type specification of ' +
|
5321 | location + ' `' + typeSpecName + '` is invalid; the type checker ' +
|
5322 | 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
|
5323 | 'You may have forgotten to pass an argument to the type checker ' +
|
5324 | 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
|
5325 | 'shape all require an argument).'
|
5326 | )
|
5327 |
|
5328 | }
|
5329 | if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
5330 |
|
5331 |
|
5332 | loggedTypeFailures[error.message] = true;
|
5333 |
|
5334 | var stack = getStack ? getStack() : '';
|
5335 |
|
5336 | printWarning(
|
5337 | 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
|
5338 | );
|
5339 | }
|
5340 | }
|
5341 | }
|
5342 | }
|
5343 | }
|
5344 |
|
5345 | module.exports = checkPropTypes;
|
5346 |
|
5347 |
|
5348 | }),
|
5349 |
|
5350 | (function(module, exports, __webpack_require__) {
|
5351 |
|
5352 | "use strict";
|
5353 |
|
5354 |
|
5355 |
|
5356 |
|
5357 |
|
5358 |
|
5359 |
|
5360 |
|
5361 |
|
5362 | var ReactPropTypesSecret = __webpack_require__(11);
|
5363 |
|
5364 | function emptyFunction() {}
|
5365 |
|
5366 | module.exports = function() {
|
5367 | function shim(props, propName, componentName, location, propFullName, secret) {
|
5368 | if (secret === ReactPropTypesSecret) {
|
5369 |
|
5370 | return;
|
5371 | }
|
5372 | var err = new Error(
|
5373 | 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
5374 | 'Use PropTypes.checkPropTypes() to call them. ' +
|
5375 | 'Read more at http://fb.me/use-check-prop-types'
|
5376 | );
|
5377 | err.name = 'Invariant Violation';
|
5378 | throw err;
|
5379 | };
|
5380 | shim.isRequired = shim;
|
5381 | function getShim() {
|
5382 | return shim;
|
5383 | };
|
5384 |
|
5385 |
|
5386 | var ReactPropTypes = {
|
5387 | array: shim,
|
5388 | bool: shim,
|
5389 | func: shim,
|
5390 | number: shim,
|
5391 | object: shim,
|
5392 | string: shim,
|
5393 | symbol: shim,
|
5394 |
|
5395 | any: shim,
|
5396 | arrayOf: getShim,
|
5397 | element: shim,
|
5398 | instanceOf: getShim,
|
5399 | node: shim,
|
5400 | objectOf: getShim,
|
5401 | oneOf: getShim,
|
5402 | oneOfType: getShim,
|
5403 | shape: getShim,
|
5404 | exact: getShim
|
5405 | };
|
5406 |
|
5407 | ReactPropTypes.checkPropTypes = emptyFunction;
|
5408 | ReactPropTypes.PropTypes = ReactPropTypes;
|
5409 |
|
5410 | return ReactPropTypes;
|
5411 | };
|
5412 |
|
5413 |
|
5414 | }),
|
5415 |
|
5416 | (function(module, exports) {
|
5417 |
|
5418 |
|
5419 | var process = module.exports = {};
|
5420 |
|
5421 |
|
5422 |
|
5423 |
|
5424 |
|
5425 |
|
5426 | var cachedSetTimeout;
|
5427 | var cachedClearTimeout;
|
5428 |
|
5429 | function defaultSetTimout() {
|
5430 | throw new Error('setTimeout has not been defined');
|
5431 | }
|
5432 | function defaultClearTimeout () {
|
5433 | throw new Error('clearTimeout has not been defined');
|
5434 | }
|
5435 | (function () {
|
5436 | try {
|
5437 | if (typeof setTimeout === 'function') {
|
5438 | cachedSetTimeout = setTimeout;
|
5439 | } else {
|
5440 | cachedSetTimeout = defaultSetTimout;
|
5441 | }
|
5442 | } catch (e) {
|
5443 | cachedSetTimeout = defaultSetTimout;
|
5444 | }
|
5445 | try {
|
5446 | if (typeof clearTimeout === 'function') {
|
5447 | cachedClearTimeout = clearTimeout;
|
5448 | } else {
|
5449 | cachedClearTimeout = defaultClearTimeout;
|
5450 | }
|
5451 | } catch (e) {
|
5452 | cachedClearTimeout = defaultClearTimeout;
|
5453 | }
|
5454 | } ())
|
5455 | function runTimeout(fun) {
|
5456 | if (cachedSetTimeout === setTimeout) {
|
5457 |
|
5458 | return setTimeout(fun, 0);
|
5459 | }
|
5460 |
|
5461 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
5462 | cachedSetTimeout = setTimeout;
|
5463 | return setTimeout(fun, 0);
|
5464 | }
|
5465 | try {
|
5466 |
|
5467 | return cachedSetTimeout(fun, 0);
|
5468 | } catch(e){
|
5469 | try {
|
5470 |
|
5471 | return cachedSetTimeout.call(null, fun, 0);
|
5472 | } catch(e){
|
5473 |
|
5474 | return cachedSetTimeout.call(this, fun, 0);
|
5475 | }
|
5476 | }
|
5477 |
|
5478 |
|
5479 | }
|
5480 | function runClearTimeout(marker) {
|
5481 | if (cachedClearTimeout === clearTimeout) {
|
5482 |
|
5483 | return clearTimeout(marker);
|
5484 | }
|
5485 |
|
5486 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
5487 | cachedClearTimeout = clearTimeout;
|
5488 | return clearTimeout(marker);
|
5489 | }
|
5490 | try {
|
5491 |
|
5492 | return cachedClearTimeout(marker);
|
5493 | } catch (e){
|
5494 | try {
|
5495 |
|
5496 | return cachedClearTimeout.call(null, marker);
|
5497 | } catch (e){
|
5498 |
|
5499 |
|
5500 | return cachedClearTimeout.call(this, marker);
|
5501 | }
|
5502 | }
|
5503 |
|
5504 |
|
5505 |
|
5506 | }
|
5507 | var queue = [];
|
5508 | var draining = false;
|
5509 | var currentQueue;
|
5510 | var queueIndex = -1;
|
5511 |
|
5512 | function cleanUpNextTick() {
|
5513 | if (!draining || !currentQueue) {
|
5514 | return;
|
5515 | }
|
5516 | draining = false;
|
5517 | if (currentQueue.length) {
|
5518 | queue = currentQueue.concat(queue);
|
5519 | } else {
|
5520 | queueIndex = -1;
|
5521 | }
|
5522 | if (queue.length) {
|
5523 | drainQueue();
|
5524 | }
|
5525 | }
|
5526 |
|
5527 | function drainQueue() {
|
5528 | if (draining) {
|
5529 | return;
|
5530 | }
|
5531 | var timeout = runTimeout(cleanUpNextTick);
|
5532 | draining = true;
|
5533 |
|
5534 | var len = queue.length;
|
5535 | while(len) {
|
5536 | currentQueue = queue;
|
5537 | queue = [];
|
5538 | while (++queueIndex < len) {
|
5539 | if (currentQueue) {
|
5540 | currentQueue[queueIndex].run();
|
5541 | }
|
5542 | }
|
5543 | queueIndex = -1;
|
5544 | len = queue.length;
|
5545 | }
|
5546 | currentQueue = null;
|
5547 | draining = false;
|
5548 | runClearTimeout(timeout);
|
5549 | }
|
5550 |
|
5551 | process.nextTick = function (fun) {
|
5552 | var args = new Array(arguments.length - 1);
|
5553 | if (arguments.length > 1) {
|
5554 | for (var i = 1; i < arguments.length; i++) {
|
5555 | args[i - 1] = arguments[i];
|
5556 | }
|
5557 | }
|
5558 | queue.push(new Item(fun, args));
|
5559 | if (queue.length === 1 && !draining) {
|
5560 | runTimeout(drainQueue);
|
5561 | }
|
5562 | };
|
5563 |
|
5564 |
|
5565 | function Item(fun, array) {
|
5566 | this.fun = fun;
|
5567 | this.array = array;
|
5568 | }
|
5569 | Item.prototype.run = function () {
|
5570 | this.fun.apply(null, this.array);
|
5571 | };
|
5572 | process.title = 'browser';
|
5573 | process.browser = true;
|
5574 | process.env = {};
|
5575 | process.argv = [];
|
5576 | process.version = '';
|
5577 | process.versions = {};
|
5578 |
|
5579 | function noop() {}
|
5580 |
|
5581 | process.on = noop;
|
5582 | process.addListener = noop;
|
5583 | process.once = noop;
|
5584 | process.off = noop;
|
5585 | process.removeListener = noop;
|
5586 | process.removeAllListeners = noop;
|
5587 | process.emit = noop;
|
5588 | process.prependListener = noop;
|
5589 | process.prependOnceListener = noop;
|
5590 |
|
5591 | process.listeners = function (name) { return [] }
|
5592 |
|
5593 | process.binding = function (name) {
|
5594 | throw new Error('process.binding is not supported');
|
5595 | };
|
5596 |
|
5597 | process.cwd = function () { return '/' };
|
5598 | process.chdir = function (dir) {
|
5599 | throw new Error('process.chdir is not supported');
|
5600 | };
|
5601 | process.umask = function() { return 0; };
|
5602 |
|
5603 |
|
5604 | }),
|
5605 |
|
5606 | (function(module, exports) {
|
5607 |
|
5608 |
|
5609 |
|
5610 | }),
|
5611 |
|
5612 | (function(module, exports) {
|
5613 |
|
5614 | module.exports = require("react");
|
5615 |
|
5616 | }),
|
5617 |
|
5618 | (function(module, exports, __webpack_require__) {
|
5619 |
|
5620 | var baseIsEqual = __webpack_require__(25);
|
5621 |
|
5622 |
|
5623 |
|
5624 |
|
5625 |
|
5626 |
|
5627 |
|
5628 |
|
5629 |
|
5630 |
|
5631 |
|
5632 |
|
5633 |
|
5634 |
|
5635 |
|
5636 |
|
5637 |
|
5638 |
|
5639 |
|
5640 |
|
5641 |
|
5642 |
|
5643 |
|
5644 |
|
5645 |
|
5646 |
|
5647 |
|
5648 |
|
5649 |
|
5650 | function isEqual(value, other) {
|
5651 | return baseIsEqual(value, other);
|
5652 | }
|
5653 |
|
5654 | module.exports = isEqual;
|
5655 |
|
5656 |
|
5657 | }),
|
5658 |
|
5659 | (function(module, exports, __webpack_require__) {
|
5660 |
|
5661 |
|
5662 |
|
5663 |
|
5664 |
|
5665 |
|
5666 |
|
5667 |
|
5668 | if ("production".NODE_ENV !== 'production') {
|
5669 | var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' &&
|
5670 | Symbol.for &&
|
5671 | Symbol.for('react.element')) ||
|
5672 | 0xeac7;
|
5673 |
|
5674 | var isValidElement = function(object) {
|
5675 | return typeof object === 'object' &&
|
5676 | object !== null &&
|
5677 | object.$$typeof === REACT_ELEMENT_TYPE;
|
5678 | };
|
5679 |
|
5680 |
|
5681 |
|
5682 | var throwOnDirectAccess = true;
|
5683 | module.exports = __webpack_require__(92)(isValidElement, throwOnDirectAccess);
|
5684 | } else {
|
5685 |
|
5686 |
|
5687 | module.exports = __webpack_require__(95)();
|
5688 | }
|
5689 |
|
5690 |
|
5691 | }),
|
5692 |
|
5693 | (function(module, __webpack_exports__, __webpack_require__) {
|
5694 |
|
5695 | "use strict";
|
5696 | (function(process, global) {
|
5697 |
|
5698 |
|
5699 |
|
5700 |
|
5701 |
|
5702 |
|
5703 |
|
5704 |
|
5705 |
|
5706 |
|
5707 |
|
5708 |
|
5709 |
|
5710 |
|
5711 |
|
5712 |
|
5713 |
|
5714 |
|
5715 |
|
5716 |
|
5717 |
|
5718 |
|
5719 |
|
5720 |
|
5721 |
|
5722 |
|
5723 |
|
5724 |
|
5725 |
|
5726 |
|
5727 |
|
5728 |
|
5729 |
|
5730 |
|
5731 |
|
5732 |
|
5733 |
|
5734 |
|
5735 | __webpack_require__.d(__webpack_exports__, "e", function() { return Map; });
|
5736 | __webpack_require__.d(__webpack_exports__, "c", function() { return Layer; });
|
5737 | __webpack_require__.d(__webpack_exports__, "l", function() { return TileLayer; });
|
5738 |
|
5739 |
|
5740 |
|
5741 |
|
5742 | __webpack_require__.d(__webpack_exports__, "j", function() { return OverlayLayer; });
|
5743 | __webpack_require__.d(__webpack_exports__, "m", function() { return VectorLayer; });
|
5744 |
|
5745 |
|
5746 |
|
5747 |
|
5748 |
|
5749 | __webpack_require__.d(__webpack_exports__, "a", function() { return Circle; });
|
5750 |
|
5751 |
|
5752 |
|
5753 |
|
5754 |
|
5755 |
|
5756 | __webpack_require__.d(__webpack_exports__, "b", function() { return Geometry; });
|
5757 |
|
5758 |
|
5759 | __webpack_require__.d(__webpack_exports__, "d", function() { return LineString; });
|
5760 | __webpack_require__.d(__webpack_exports__, "f", function() { return Marker; });
|
5761 | __webpack_require__.d(__webpack_exports__, "g", function() { return MultiLineString; });
|
5762 | __webpack_require__.d(__webpack_exports__, "h", function() { return MultiPoint; });
|
5763 | __webpack_require__.d(__webpack_exports__, "i", function() { return MultiPolygon; });
|
5764 | __webpack_require__.d(__webpack_exports__, "k", function() { return Polygon; });
|
5765 |
|
5766 |
|
5767 |
|
5768 |
|
5769 |
|
5770 |
|
5771 |
|
5772 |
|
5773 |
|
5774 |
|
5775 | var INTERNAL_LAYER_PREFIX = '_maptalks__internal_layer_';
|
5776 |
|
5777 | var GEOMETRY_COLLECTION_TYPES = ['MultiPoint', 'MultiLineString', 'MultiPolygon', 'GeometryCollection'];
|
5778 |
|
5779 | var GEOJSON_TYPES = ['FeatureCollection', 'Feature', 'Point', 'LineString', 'Polygon'].concat(GEOMETRY_COLLECTION_TYPES);
|
5780 |
|
5781 | var RESOURCE_PROPERTIES = ['markerFile', 'polygonPatternFile', 'linePatternFile', 'markerFillPatternFile', 'markerLinePatternFile'];
|
5782 |
|
5783 | var RESOURCE_SIZE_PROPERTIES = [['markerWidth', 'markerHeight'], [], [null, 'lineWidth'], [], [null, 'markerLineWidth']];
|
5784 |
|
5785 | var NUMERICAL_PROPERTIES = {
|
5786 | 'lineWidth': 1,
|
5787 | 'lineOpacity': 1,
|
5788 | 'lineDx': 1,
|
5789 | 'lineDy': 1,
|
5790 | 'polygonOpacity': 1,
|
5791 | 'markerWidth': 1,
|
5792 | 'markerHeight': 1,
|
5793 | 'markerDx': 1,
|
5794 | 'markerDy': 1,
|
5795 | 'markerOpacity': 1,
|
5796 | 'markerFillOpacity': 1,
|
5797 | 'markerLineWidth': 1,
|
5798 | 'markerLineOpacity': 1,
|
5799 | 'textSize': 1,
|
5800 | 'textOpacity': 1,
|
5801 | 'textHaloRadius': 1,
|
5802 | 'textWrapWidth': 1,
|
5803 | 'textLineSpacing': 1,
|
5804 | 'textDx': 1,
|
5805 | 'textDy': 1
|
5806 | };
|
5807 |
|
5808 | var COLOR_PROPERTIES = ['lineColor', 'polygonFill', 'markerFill', 'markerLineColor', 'textFill'];
|
5809 |
|
5810 | function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
5811 |
|
5812 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
5813 | return typeof obj;
|
5814 | } : function (obj) {
|
5815 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
5816 | };
|
5817 |
|
5818 |
|
5819 |
|
5820 |
|
5821 |
|
5822 |
|
5823 |
|
5824 |
|
5825 |
|
5826 |
|
5827 |
|
5828 | var classCallCheck = function (instance, Constructor) {
|
5829 | if (!(instance instanceof Constructor)) {
|
5830 | throw new TypeError("Cannot call a class as a function");
|
5831 | }
|
5832 | };
|
5833 |
|
5834 |
|
5835 |
|
5836 |
|
5837 |
|
5838 |
|
5839 |
|
5840 |
|
5841 |
|
5842 |
|
5843 |
|
5844 | var inherits = function (subClass, superClass) {
|
5845 | if (typeof superClass !== "function" && superClass !== null) {
|
5846 | throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
5847 | }
|
5848 |
|
5849 | subClass.prototype = Object.create(superClass && superClass.prototype, {
|
5850 | constructor: {
|
5851 | value: subClass,
|
5852 | enumerable: false,
|
5853 | writable: true,
|
5854 | configurable: true
|
5855 | }
|
5856 | });
|
5857 | if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass);
|
5858 | };
|
5859 |
|
5860 |
|
5861 |
|
5862 |
|
5863 |
|
5864 |
|
5865 |
|
5866 |
|
5867 |
|
5868 |
|
5869 |
|
5870 | var possibleConstructorReturn = function (self, call) {
|
5871 | if (!self) {
|
5872 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
5873 | }
|
5874 |
|
5875 | return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
5876 | };
|
5877 |
|
5878 | function now() {
|
5879 | return Date.now();
|
5880 | }
|
5881 |
|
5882 | function extend(dest) {
|
5883 | for (var i = 1; i < arguments.length; i++) {
|
5884 | var src = arguments[i];
|
5885 | for (var k in src) {
|
5886 | dest[k] = src[k];
|
5887 | }
|
5888 | }
|
5889 | return dest;
|
5890 | }
|
5891 |
|
5892 | function isNil(obj) {
|
5893 | return obj == null;
|
5894 | }
|
5895 |
|
5896 | function isNumber(val) {
|
5897 | return typeof val === 'number' && !isNaN(val);
|
5898 | }
|
5899 |
|
5900 | function isInteger(n) {
|
5901 | return (n | 0) === n;
|
5902 | }
|
5903 |
|
5904 | function isObject(obj) {
|
5905 | return (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && !!obj;
|
5906 | }
|
5907 |
|
5908 | function isString(obj) {
|
5909 | if (isNil(obj)) {
|
5910 | return false;
|
5911 | }
|
5912 | return typeof obj === 'string' || obj.constructor !== null && obj.constructor === String;
|
5913 | }
|
5914 |
|
5915 | function isFunction(obj) {
|
5916 | if (isNil(obj)) {
|
5917 | return false;
|
5918 | }
|
5919 | return typeof obj === 'function' || obj.constructor !== null && obj.constructor === Function;
|
5920 | }
|
5921 |
|
5922 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
5923 |
|
5924 | function hasOwn(obj, key) {
|
5925 | return hasOwnProperty.call(obj, key);
|
5926 | }
|
5927 |
|
5928 | function join(arr, seperator) {
|
5929 | if (arr.join) {
|
5930 | return arr.join(seperator || ',');
|
5931 | } else {
|
5932 | return Array.prototype.join.call(arr, seperator || ',');
|
5933 | }
|
5934 | }
|
5935 |
|
5936 | var pi = Math.PI / 180;
|
5937 |
|
5938 | function toRadian(d) {
|
5939 | return d * pi;
|
5940 | }
|
5941 |
|
5942 | function toDegree(r) {
|
5943 | return r / pi;
|
5944 | }
|
5945 |
|
5946 | var IS_NODE = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]' && !process.versions['electron'] && !process.versions['nw'] && !process.versions['node-webkit'];
|
5947 |
|
5948 | var requestAnimFrame = void 0;
|
5949 | var cancelAnimFrame = void 0;
|
5950 |
|
5951 | (function () {
|
5952 | if (IS_NODE) {
|
5953 | requestAnimFrame = function requestAnimFrame(fn) {
|
5954 | return setTimeout(fn, 16);
|
5955 | };
|
5956 |
|
5957 | cancelAnimFrame = clearTimeout;
|
5958 | return;
|
5959 | }
|
5960 |
|
5961 | var requestFn = void 0,
|
5962 | cancelFn = void 0;
|
5963 |
|
5964 | var timeToCall = 1000 / 30;
|
5965 | function timeoutDefer(fn) {
|
5966 | return setTimeout(fn, timeToCall);
|
5967 | }
|
5968 |
|
5969 | function getPrefixed(name) {
|
5970 | return window['webkit' + name] || window['moz' + name] || window['ms' + name];
|
5971 | }
|
5972 | if (typeof window != 'undefined') {
|
5973 |
|
5974 | requestFn = window['requestAnimationFrame'] || getPrefixed('RequestAnimationFrame') || timeoutDefer;
|
5975 | cancelFn = window['cancelAnimationFrame'] || getPrefixed('CancelAnimationFrame') || getPrefixed('CancelRequestAnimationFrame') || function (id) {
|
5976 | window.clearTimeout(id);
|
5977 | };
|
5978 | } else {
|
5979 | requestFn = timeoutDefer;
|
5980 | cancelFn = clearTimeout;
|
5981 | }
|
5982 |
|
5983 | requestAnimFrame = function requestAnimFrame(fn) {
|
5984 | return requestFn(fn);
|
5985 | };
|
5986 |
|
5987 | cancelAnimFrame = function cancelAnimFrame(id) {
|
5988 | if (id) {
|
5989 | cancelFn(id);
|
5990 | }
|
5991 | };
|
5992 | })();
|
5993 | function isSVG(url) {
|
5994 | var prefix = 'data:image/svg+xml';
|
5995 | if (url.length > 4 && url.slice(-4) === '.svg') {
|
5996 | return 1;
|
5997 | } else if (url.slice(0, prefix.length) === prefix) {
|
5998 | return 2;
|
5999 | }
|
6000 | return 0;
|
6001 | }
|
6002 |
|
6003 | function loadImage(img, imgDesc) {
|
6004 | if (IS_NODE && loadImage.node) {
|
6005 | loadImage.node(img, imgDesc);
|
6006 | return;
|
6007 | }
|
6008 | img.src = imgDesc[0];
|
6009 | }
|
6010 |
|
6011 | var uid = 0;
|
6012 |
|
6013 | function UID() {
|
6014 | return uid++;
|
6015 | }
|
6016 | var GUID = UID;
|
6017 |
|
6018 | function parseJSON(str) {
|
6019 | if (!str || !isString(str)) {
|
6020 | return str;
|
6021 | }
|
6022 | return JSON.parse(str);
|
6023 | }
|
6024 |
|
6025 | function pushIn(dest) {
|
6026 | for (var i = 1; i < arguments.length; i++) {
|
6027 | var src = arguments[i];
|
6028 | if (src) {
|
6029 | for (var ii = 0, ll = src.length; ii < ll; ii++) {
|
6030 | dest.push(src[ii]);
|
6031 | }
|
6032 | }
|
6033 | }
|
6034 | return dest.length;
|
6035 | }
|
6036 |
|
6037 | function removeFromArray(obj, array) {
|
6038 | var i = array.indexOf(obj);
|
6039 | if (i > -1) {
|
6040 | array.splice(i, 1);
|
6041 | }
|
6042 | }
|
6043 |
|
6044 | function forEachCoord(arr, fn, context) {
|
6045 | if (!Array.isArray(arr)) {
|
6046 | return context ? fn.call(context, arr) : fn(arr);
|
6047 | }
|
6048 | var result = [];
|
6049 | var p = void 0,
|
6050 | pp = void 0;
|
6051 | for (var i = 0, len = arr.length; i < len; i++) {
|
6052 | p = arr[i];
|
6053 | if (isNil(p)) {
|
6054 | result.push(null);
|
6055 | continue;
|
6056 | }
|
6057 | if (Array.isArray(p)) {
|
6058 | result.push(forEachCoord(p, fn, context));
|
6059 | } else {
|
6060 | pp = context ? fn.call(context, p) : fn(p);
|
6061 | result.push(pp);
|
6062 | }
|
6063 | }
|
6064 | return result;
|
6065 | }
|
6066 |
|
6067 | function getValueOrDefault(v, d) {
|
6068 | return v === undefined ? d : v;
|
6069 | }
|
6070 |
|
6071 | function sign(x) {
|
6072 | if (Math.sign) {
|
6073 | return Math.sign(x);
|
6074 | }
|
6075 | x = +x;
|
6076 | if (x === 0 || isNaN(x)) {
|
6077 | return Number(x);
|
6078 | }
|
6079 | return x > 0 ? 1 : -1;
|
6080 | }
|
6081 |
|
6082 | function log2(x) {
|
6083 | if (Math.log2) {
|
6084 | return Math.log2(x);
|
6085 | }
|
6086 | var v = Math.log(x) * Math.LOG2E;
|
6087 | var rounded = Math.round(v);
|
6088 | if (Math.abs(rounded - v) < 1E-14) {
|
6089 | return rounded;
|
6090 | } else {
|
6091 | return v;
|
6092 | }
|
6093 | }
|
6094 |
|
6095 | function interpolate(a, b, t) {
|
6096 | return a * (1 - t) + b * t;
|
6097 | }
|
6098 |
|
6099 | function wrap(n, min, max) {
|
6100 | if (n === max || n === min) {
|
6101 | return n;
|
6102 | }
|
6103 | var d = max - min;
|
6104 | var w = ((n - min) % d + d) % d + min;
|
6105 | return w;
|
6106 | }
|
6107 |
|
6108 | function clamp(n, min, max) {
|
6109 | return Math.min(max, Math.max(min, n));
|
6110 | }
|
6111 |
|
6112 | function isArrayHasData(obj) {
|
6113 | return Array.isArray(obj) && obj.length > 0;
|
6114 | }
|
6115 |
|
6116 | function isURL(url) {
|
6117 | if (!url) {
|
6118 | return false;
|
6119 | }
|
6120 | var head = url.slice(0, 6);
|
6121 | if (head === 'http:/' || head === 'https:' || head === 'file:/') {
|
6122 | return true;
|
6123 | }
|
6124 | return false;
|
6125 | }
|
6126 |
|
6127 | var cssUrlReWithQuote = /^url\((['"])(.+)\1\)$/i;
|
6128 |
|
6129 | var cssUrlRe = /^url\(([^'"].*[^'"])\)$/i;
|
6130 |
|
6131 | function isCssUrl(str) {
|
6132 | if (!isString(str)) {
|
6133 | return 0;
|
6134 | }
|
6135 | var head = str.slice(0, 6);
|
6136 | if (head === 'http:/' || head === 'https:') {
|
6137 | return 3;
|
6138 | }
|
6139 | if (cssUrlRe.test(str)) {
|
6140 | return 1;
|
6141 | }
|
6142 | if (cssUrlReWithQuote.test(str)) {
|
6143 | return 2;
|
6144 | }
|
6145 | return 0;
|
6146 | }
|
6147 |
|
6148 | function extractCssUrl(str) {
|
6149 | var test = isCssUrl(str);
|
6150 | var matches = void 0;
|
6151 | if (test === 3) {
|
6152 | return str;
|
6153 | }
|
6154 | if (test === 1) {
|
6155 | matches = cssUrlRe.exec(str);
|
6156 | return matches[1];
|
6157 | } else if (test === 2) {
|
6158 | matches = cssUrlReWithQuote.exec(str);
|
6159 | return matches[2];
|
6160 | } else {
|
6161 | return str;
|
6162 | }
|
6163 | }
|
6164 |
|
6165 | var b64chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
6166 |
|
6167 | function btoa(input) {
|
6168 | if (typeof window !== 'undefined' && window.btoa) {
|
6169 | return window.btoa(input);
|
6170 | }
|
6171 | var str = String(input);
|
6172 | var output = '';
|
6173 | for (var block, charCode, idx = 0, map = b64chrs; str.charAt(idx | 0) || (map = '=', idx % 1); output += map.charAt(63 & block >> 8 - idx % 1 * 8)) {
|
6174 | charCode = str.charCodeAt(idx += 3 / 4);
|
6175 | if (charCode > 0xFF) {
|
6176 | throw new Error('\'btoa\' failed: The string to be encoded contains characters outside of the Latin1 range.');
|
6177 | }
|
6178 | block = block << 8 | charCode;
|
6179 | }
|
6180 | return output;
|
6181 | }
|
6182 |
|
6183 | function b64toBlob(b64Data, contentType) {
|
6184 | var byteCharacters = atob(b64Data);
|
6185 | var arraybuffer = new ArrayBuffer(byteCharacters.length);
|
6186 | var view = new Uint8Array(arraybuffer);
|
6187 | for (var i = 0; i < byteCharacters.length; i++) {
|
6188 | view[i] = byteCharacters.charCodeAt(i) & 0xff;
|
6189 | }
|
6190 | var blob = new Blob([arraybuffer], { type: contentType });
|
6191 | return blob;
|
6192 | }
|
6193 |
|
6194 | function computeDegree(x0, y0, x1, y1) {
|
6195 | var dx = x1 - x0;
|
6196 | var dy = y1 - y0;
|
6197 | return Math.atan2(dy, dx);
|
6198 | }
|
6199 |
|
6200 | var emptyImageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
6201 |
|
6202 | function equalMapView(obj1, obj2) {
|
6203 | if (!obj1 && !obj2) {
|
6204 | return true;
|
6205 | } else if (!obj1 || !obj2) {
|
6206 | return false;
|
6207 | }
|
6208 | for (var p in obj1) {
|
6209 | if (p === 'center') {
|
6210 | if (!obj2[p] || !approx(obj1[p][0], obj2[p][0]) || !approx(obj1[p][1], obj2[p][1])) {
|
6211 | return false;
|
6212 | }
|
6213 | } else if (obj1[p] !== obj2[p]) {
|
6214 | return false;
|
6215 | }
|
6216 | }
|
6217 | return true;
|
6218 | }
|
6219 |
|
6220 | function approx(val, expected, delta) {
|
6221 | if (delta == null) {
|
6222 | delta = 1e-6;
|
6223 | }
|
6224 | return val >= expected - delta && val <= expected + delta;
|
6225 | }
|
6226 |
|
6227 | function flash(interval, count, cb, context) {
|
6228 | if (!interval) {
|
6229 | interval = 100;
|
6230 | }
|
6231 | if (!count) {
|
6232 | count = 4;
|
6233 | }
|
6234 | var me = this;
|
6235 | count *= 2;
|
6236 | if (this._flashTimeout) {
|
6237 | clearTimeout(this._flashTimeout);
|
6238 | }
|
6239 |
|
6240 | function flashGeo() {
|
6241 | if (count === 0) {
|
6242 | me.show();
|
6243 | if (cb) {
|
6244 | if (context) {
|
6245 | cb.call(context);
|
6246 | } else {
|
6247 | cb();
|
6248 | }
|
6249 | }
|
6250 | return;
|
6251 | }
|
6252 |
|
6253 | if (count % 2 === 0) {
|
6254 | me.hide();
|
6255 | } else {
|
6256 | me.show();
|
6257 | }
|
6258 | count--;
|
6259 | me._flashTimeout = setTimeout(flashGeo, interval);
|
6260 | }
|
6261 | this._flashTimeout = setTimeout(flashGeo, interval);
|
6262 | return this;
|
6263 | }
|
6264 |
|
6265 | var types = ['Unknown', 'Point', 'LineString', 'Polygon', 'MultiPoint', 'MultiLineString', 'MultiPolygon', 'GeometryCollection'];
|
6266 |
|
6267 | function createFilter(filter) {
|
6268 | return new Function('f', 'var p = (f && f.properties || {}); return ' + compile(filter));
|
6269 | }
|
6270 |
|
6271 | function compile(filter) {
|
6272 | if (!filter) return 'true';
|
6273 | var op = filter[0];
|
6274 | if (filter.length <= 1) return op === 'any' ? 'false' : 'true';
|
6275 | var str = op === '==' ? compileComparisonOp(filter[1], filter[2], '===', false) : op === '!=' ? compileComparisonOp(filter[1], filter[2], '!==', false) : op === '<' || op === '>' || op === '<=' || op === '>=' ? compileComparisonOp(filter[1], filter[2], op, true) : op === 'any' ? compileLogicalOp(filter.slice(1), '||') : op === 'all' ? compileLogicalOp(filter.slice(1), '&&') : op === 'none' ? compileNegation(compileLogicalOp(filter.slice(1), '||')) : op === 'in' ? compileInOp(filter[1], filter.slice(2)) : op === '!in' ? compileNegation(compileInOp(filter[1], filter.slice(2))) : op === 'has' ? compileHasOp(filter[1]) : op === '!has' ? compileNegation(compileHasOp(filter[1])) : 'true';
|
6276 | return '(' + str + ')';
|
6277 | }
|
6278 |
|
6279 | function compilePropertyReference(property) {
|
6280 | return property[0] === '$' ? 'f.' + property.substring(1) : 'p[' + JSON.stringify(property) + ']';
|
6281 | }
|
6282 |
|
6283 | function compileComparisonOp(property, value, op, checkType) {
|
6284 | var left = compilePropertyReference(property);
|
6285 | var right = property === '$type' ? types.indexOf(value) : JSON.stringify(value);
|
6286 | return (checkType ? 'typeof ' + left + '=== typeof ' + right + '&&' : '') + left + op + right;
|
6287 | }
|
6288 |
|
6289 | function compileLogicalOp(expressions, op) {
|
6290 | return expressions.map(compile).join(op);
|
6291 | }
|
6292 |
|
6293 | function compileInOp(property, values) {
|
6294 | if (property === '$type') values = values.map(function (value) {
|
6295 | return types.indexOf(value);
|
6296 | });
|
6297 | var left = JSON.stringify(values.sort(compare));
|
6298 | var right = compilePropertyReference(property);
|
6299 |
|
6300 | if (values.length <= 200) return left + '.indexOf(' + right + ') !== -1';
|
6301 |
|
6302 | return '' + ('function(v, a, i, j) {' + 'while (i <= j) { var m = (i + j) >> 1;' + ' if (a[m] === v) return true; if (a[m] > v) j = m - 1; else i = m + 1;' + '}' + 'return false; }(') + right + ', ' + left + ',0,' + (values.length - 1) + ')';
|
6303 | }
|
6304 |
|
6305 | function compileHasOp(property) {
|
6306 | return property === '$id' ? '"id" in f' : JSON.stringify(property) + ' in p';
|
6307 | }
|
6308 |
|
6309 | function compileNegation(expression) {
|
6310 | return '!(' + expression + ')';
|
6311 | }
|
6312 |
|
6313 | function compare(a, b) {
|
6314 | return a < b ? -1 : a > b ? 1 : 0;
|
6315 | }
|
6316 |
|
6317 | function getFilterFeature(geometry) {
|
6318 | var json = geometry._toJSON(),
|
6319 | g = json['feature'];
|
6320 | g['type'] = types.indexOf(g['geometry']['type']);
|
6321 | g['subType'] = json['subType'];
|
6322 | return g;
|
6323 | }
|
6324 |
|
6325 | function compileStyle(styles) {
|
6326 | if (!Array.isArray(styles)) {
|
6327 | return compileStyle([styles]);
|
6328 | }
|
6329 | var compiled = [];
|
6330 | for (var i = 0; i < styles.length; i++) {
|
6331 | var filter = void 0;
|
6332 | if (styles[i]['filter'] === true) {
|
6333 | filter = function filter() {
|
6334 | return true;
|
6335 | };
|
6336 | } else {
|
6337 | filter = createFilter(styles[i]['filter']);
|
6338 | }
|
6339 | compiled.push(extend({}, styles[i], {
|
6340 | filter: filter
|
6341 | }));
|
6342 | }
|
6343 | return compiled;
|
6344 | }
|
6345 |
|
6346 | function createFunction(parameters, defaultType) {
|
6347 | var fun;
|
6348 |
|
6349 | if (!isFunctionDefinition(parameters)) {
|
6350 | fun = function fun() {
|
6351 | return parameters;
|
6352 | };
|
6353 | fun.isFeatureConstant = true;
|
6354 | fun.isZoomConstant = true;
|
6355 | } else {
|
6356 | var zoomAndFeatureDependent = parameters.stops && _typeof(parameters.stops[0][0]) === 'object';
|
6357 | var featureDependent = zoomAndFeatureDependent || parameters.property !== undefined;
|
6358 | var zoomDependent = zoomAndFeatureDependent || !featureDependent;
|
6359 | var type = parameters.type || defaultType || 'exponential';
|
6360 |
|
6361 | var innerFun;
|
6362 | if (type === 'exponential') {
|
6363 | innerFun = evaluateExponentialFunction;
|
6364 | } else if (type === 'interval') {
|
6365 | innerFun = evaluateIntervalFunction;
|
6366 | } else if (type === 'categorical') {
|
6367 | innerFun = evaluateCategoricalFunction;
|
6368 | } else if (type === 'identity') {
|
6369 | innerFun = evaluateIdentityFunction;
|
6370 | } else {
|
6371 | throw new Error('Unknown function type "' + type + '"');
|
6372 | }
|
6373 |
|
6374 | if (zoomAndFeatureDependent) {
|
6375 | var featureFunctions = {};
|
6376 | var featureFunctionStops = [];
|
6377 | for (var s = 0; s < parameters.stops.length; s++) {
|
6378 | var stop = parameters.stops[s];
|
6379 | if (featureFunctions[stop[0].zoom] === undefined) {
|
6380 | featureFunctions[stop[0].zoom] = {
|
6381 | zoom: stop[0].zoom,
|
6382 | type: parameters.type,
|
6383 | property: parameters.property,
|
6384 | stops: []
|
6385 | };
|
6386 | }
|
6387 | featureFunctions[stop[0].zoom].stops.push([stop[0].value, stop[1]]);
|
6388 | }
|
6389 |
|
6390 | for (var z in featureFunctions) {
|
6391 | featureFunctionStops.push([featureFunctions[z].zoom, createFunction(featureFunctions[z])]);
|
6392 | }
|
6393 | fun = function fun(zoom, feature) {
|
6394 | return evaluateExponentialFunction({ stops: featureFunctionStops, base: parameters.base }, zoom)(zoom, feature);
|
6395 | };
|
6396 | fun.isFeatureConstant = false;
|
6397 | fun.isZoomConstant = false;
|
6398 | } else if (zoomDependent) {
|
6399 | fun = function fun(zoom) {
|
6400 | return innerFun(parameters, zoom);
|
6401 | };
|
6402 | fun.isFeatureConstant = true;
|
6403 | fun.isZoomConstant = false;
|
6404 | } else {
|
6405 | fun = function fun(zoom, feature) {
|
6406 | return innerFun(parameters, feature[parameters.property]);
|
6407 | };
|
6408 | fun.isFeatureConstant = false;
|
6409 | fun.isZoomConstant = true;
|
6410 | }
|
6411 | }
|
6412 |
|
6413 | return fun;
|
6414 | }
|
6415 |
|
6416 | function evaluateCategoricalFunction(parameters, input) {
|
6417 | for (var i = 0; i < parameters.stops.length; i++) {
|
6418 | if (input === parameters.stops[i][0]) {
|
6419 | return parameters.stops[i][1];
|
6420 | }
|
6421 | }
|
6422 | return parameters.stops[0][1];
|
6423 | }
|
6424 |
|
6425 | function evaluateIntervalFunction(parameters, input) {
|
6426 | for (var i = 0; i < parameters.stops.length; i++) {
|
6427 | if (input < parameters.stops[i][0]) break;
|
6428 | }
|
6429 | return parameters.stops[Math.max(i - 1, 0)][1];
|
6430 | }
|
6431 |
|
6432 | function evaluateExponentialFunction(parameters, input) {
|
6433 | var base = parameters.base !== undefined ? parameters.base : 1;
|
6434 |
|
6435 | var i = 0;
|
6436 | while (true) {
|
6437 | if (i >= parameters.stops.length) break;else if (input <= parameters.stops[i][0]) break;else i++;
|
6438 | }
|
6439 |
|
6440 | if (i === 0) {
|
6441 | return parameters.stops[i][1];
|
6442 | } else if (i === parameters.stops.length) {
|
6443 | return parameters.stops[i - 1][1];
|
6444 | } else {
|
6445 | return interpolate$1(input, base, parameters.stops[i - 1][0], parameters.stops[i][0], parameters.stops[i - 1][1], parameters.stops[i][1]);
|
6446 | }
|
6447 | }
|
6448 |
|
6449 | function evaluateIdentityFunction(parameters, input) {
|
6450 | return input;
|
6451 | }
|
6452 |
|
6453 | function interpolate$1(input, base, inputLower, inputUpper, outputLower, outputUpper) {
|
6454 | if (typeof outputLower === 'function') {
|
6455 | return function () {
|
6456 | var evaluatedLower = outputLower.apply(undefined, arguments);
|
6457 | var evaluatedUpper = outputUpper.apply(undefined, arguments);
|
6458 | return interpolate$1(input, base, inputLower, inputUpper, evaluatedLower, evaluatedUpper);
|
6459 | };
|
6460 | } else if (outputLower.length) {
|
6461 | return interpolateArray(input, base, inputLower, inputUpper, outputLower, outputUpper);
|
6462 | } else {
|
6463 | return interpolateNumber(input, base, inputLower, inputUpper, outputLower, outputUpper);
|
6464 | }
|
6465 | }
|
6466 |
|
6467 | function interpolateNumber(input, base, inputLower, inputUpper, outputLower, outputUpper) {
|
6468 | var difference = inputUpper - inputLower;
|
6469 | var progress = input - inputLower;
|
6470 |
|
6471 | var ratio;
|
6472 | if (base === 1) {
|
6473 | ratio = progress / difference;
|
6474 | } else {
|
6475 | ratio = (Math.pow(base, progress) - 1) / (Math.pow(base, difference) - 1);
|
6476 | }
|
6477 |
|
6478 | return outputLower * (1 - ratio) + outputUpper * ratio;
|
6479 | }
|
6480 |
|
6481 | function interpolateArray(input, base, inputLower, inputUpper, outputLower, outputUpper) {
|
6482 | var output = [];
|
6483 | for (var i = 0; i < outputLower.length; i++) {
|
6484 | output[i] = interpolateNumber(input, base, inputLower, inputUpper, outputLower[i], outputUpper[i]);
|
6485 | }
|
6486 | return output;
|
6487 | }
|
6488 |
|
6489 | function isFunctionDefinition(obj) {
|
6490 | return obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && (obj.stops || obj.property && obj.type === 'identity');
|
6491 | }
|
6492 |
|
6493 | function hasFunctionDefinition(obj) {
|
6494 | for (var p in obj) {
|
6495 | if (isFunctionDefinition(obj[p])) {
|
6496 | return true;
|
6497 | }
|
6498 | }
|
6499 | return false;
|
6500 | }
|
6501 |
|
6502 | function interpolated(parameters) {
|
6503 | return createFunction(parameters, 'exponential');
|
6504 | }
|
6505 |
|
6506 | function piecewiseConstant(parameters) {
|
6507 | return createFunction(parameters, 'interval');
|
6508 | }
|
6509 |
|
6510 | function loadFunctionTypes(obj, argFn) {
|
6511 | if (!obj) {
|
6512 | return null;
|
6513 | }
|
6514 | var hit = false;
|
6515 | if (Array.isArray(obj)) {
|
6516 | var multResult = [],
|
6517 | loaded;
|
6518 | for (var i = 0; i < obj.length; i++) {
|
6519 | loaded = loadFunctionTypes(obj[i], argFn);
|
6520 | if (!loaded) {
|
6521 | multResult.push(obj[i]);
|
6522 | } else {
|
6523 | multResult.push(loaded);
|
6524 | hit = true;
|
6525 | }
|
6526 | }
|
6527 | return hit ? multResult : obj;
|
6528 | }
|
6529 | var result = {
|
6530 | '__fn_types_loaded': true
|
6531 | },
|
6532 | props = [],
|
6533 | p;
|
6534 | for (p in obj) {
|
6535 | if (obj.hasOwnProperty(p)) {
|
6536 | props.push(p);
|
6537 | }
|
6538 | }
|
6539 |
|
6540 | for (var _i = 0, len = props.length; _i < len; _i++) {
|
6541 | p = props[_i];
|
6542 | if (isFunctionDefinition(obj[p])) {
|
6543 | hit = true;
|
6544 | result['_' + p] = obj[p];
|
6545 | (function (_p) {
|
6546 | Object.defineProperty(result, _p, {
|
6547 | get: function get$$1() {
|
6548 | if (!this['__fn_' + _p]) {
|
6549 | this['__fn_' + _p] = interpolated(this['_' + _p]);
|
6550 | }
|
6551 | return this['__fn_' + _p].apply(this, argFn());
|
6552 | },
|
6553 | set: function set$$1(v) {
|
6554 | this['_' + _p] = v;
|
6555 | },
|
6556 | configurable: true,
|
6557 | enumerable: true
|
6558 | });
|
6559 | })(p);
|
6560 | } else {
|
6561 | result[p] = obj[p];
|
6562 | }
|
6563 | }
|
6564 | return hit ? result : obj;
|
6565 | }
|
6566 |
|
6567 | function getFunctionTypeResources(t) {
|
6568 | if (!t || !t.stops) {
|
6569 | return [];
|
6570 | }
|
6571 | var res = [];
|
6572 | for (var i = 0, l = t.stops.length; i < l; i++) {
|
6573 | res.push(t.stops[i][1]);
|
6574 | }
|
6575 | return res;
|
6576 | }
|
6577 |
|
6578 |
|
6579 |
|
6580 | var index$1 = Object.freeze({
|
6581 | createFilter: createFilter,
|
6582 | getFilterFeature: getFilterFeature,
|
6583 | compileStyle: compileStyle,
|
6584 | isFunctionDefinition: isFunctionDefinition,
|
6585 | hasFunctionDefinition: hasFunctionDefinition,
|
6586 | interpolated: interpolated,
|
6587 | piecewiseConstant: piecewiseConstant,
|
6588 | loadFunctionTypes: loadFunctionTypes,
|
6589 | getFunctionTypeResources: getFunctionTypeResources
|
6590 | });
|
6591 |
|
6592 | function translateToSVGStyles(s) {
|
6593 | var result = {
|
6594 | 'stroke': {
|
6595 | 'stroke': s['markerLineColor'],
|
6596 | 'stroke-width': s['markerLineWidth'],
|
6597 | 'stroke-opacity': s['markerLineOpacity'],
|
6598 | 'stroke-dasharray': null,
|
6599 | 'stroke-linecap': 'butt',
|
6600 | 'stroke-linejoin': 'round'
|
6601 | },
|
6602 | 'fill': {
|
6603 | 'fill': s['markerFill'],
|
6604 | 'fill-opacity': s['markerFillOpacity']
|
6605 | }
|
6606 | };
|
6607 |
|
6608 | if (result['stroke']['stroke-linecap'] === 'butt') {
|
6609 | if (Browser$1.vml) {
|
6610 | result['stroke']['stroke-linecap'] = 'flat';
|
6611 | }
|
6612 | }
|
6613 | if (result['stroke']['stroke-width'] === 0) {
|
6614 | result['stroke']['stroke-opacity'] = 0;
|
6615 | }
|
6616 | return result;
|
6617 | }
|
6618 |
|
6619 | function getMarkerPathBase64(symbol, width, height) {
|
6620 | if (!symbol['markerPath']) {
|
6621 | return null;
|
6622 | }
|
6623 | var op = 1;
|
6624 | var styles = translateToSVGStyles(symbol);
|
6625 |
|
6626 | if (isNumber(symbol['markerOpacity'])) {
|
6627 | op = symbol['markerOpacity'];
|
6628 | }
|
6629 | if (isNumber(symbol['opacity'])) {
|
6630 | op *= symbol['opacity'];
|
6631 | }
|
6632 | var svgStyles = {};
|
6633 | if (styles) {
|
6634 | for (var p in styles['stroke']) {
|
6635 | if (styles['stroke'].hasOwnProperty(p)) {
|
6636 | if (!isNil(styles['stroke'][p])) {
|
6637 | svgStyles[p] = styles['stroke'][p];
|
6638 | }
|
6639 | }
|
6640 | }
|
6641 | for (var _p in styles['fill']) {
|
6642 | if (styles['fill'].hasOwnProperty(_p)) {
|
6643 | if (!isNil(styles['fill'][_p])) {
|
6644 | svgStyles[_p] = styles['fill'][_p];
|
6645 | }
|
6646 | }
|
6647 | }
|
6648 | }
|
6649 |
|
6650 | var pathes = Array.isArray(symbol['markerPath']) ? symbol['markerPath'] : [symbol['markerPath']];
|
6651 | var path = void 0;
|
6652 | var pathesToRender = [];
|
6653 | for (var i = 0; i < pathes.length; i++) {
|
6654 | path = isString(pathes[i]) ? {
|
6655 | 'path': pathes[i]
|
6656 | } : pathes[i];
|
6657 | path = extend({}, path, svgStyles);
|
6658 | path['d'] = path['path'];
|
6659 | delete path['path'];
|
6660 | pathesToRender.push(path);
|
6661 | }
|
6662 | var svg = ['<svg version="1.1"', 'xmlns="http://www.w3.org/2000/svg"'];
|
6663 | if (op < 1) {
|
6664 | svg.push('opacity="' + op + '"');
|
6665 | }
|
6666 |
|
6667 | if (symbol['markerPathWidth'] && symbol['markerPathHeight']) {
|
6668 | svg.push('viewBox="0 0 ' + symbol['markerPathWidth'] + ' ' + symbol['markerPathHeight'] + '"');
|
6669 | }
|
6670 | svg.push('preserveAspectRatio="none"');
|
6671 | if (width) {
|
6672 | svg.push('width="' + width + '"');
|
6673 | }
|
6674 | if (height) {
|
6675 | svg.push('height="' + height + '"');
|
6676 | }
|
6677 | svg.push('><defs></defs>');
|
6678 |
|
6679 | for (var _i = 0; _i < pathesToRender.length; _i++) {
|
6680 | var strPath = '<path ';
|
6681 | for (var _p2 in pathesToRender[_i]) {
|
6682 | if (pathesToRender[_i].hasOwnProperty(_p2)) {
|
6683 | strPath += ' ' + _p2 + '="' + pathesToRender[_i][_p2] + '"';
|
6684 | }
|
6685 | }
|
6686 | strPath += '></path>';
|
6687 | svg.push(strPath);
|
6688 | }
|
6689 | svg.push('</svg>');
|
6690 | var b64 = 'data:image/svg+xml;base64,' + btoa(svg.join(' '));
|
6691 | return b64;
|
6692 | }
|
6693 |
|
6694 | function getExternalResources(symbol, toAbsolute) {
|
6695 | if (!symbol) {
|
6696 | return [];
|
6697 | }
|
6698 | var symbols = symbol;
|
6699 | if (!Array.isArray(symbol)) {
|
6700 | symbols = [symbol];
|
6701 | }
|
6702 | var resources = [];
|
6703 | var props = RESOURCE_PROPERTIES;
|
6704 | var res = void 0,
|
6705 | resSizeProp = void 0;
|
6706 | var w = void 0,
|
6707 | h = void 0;
|
6708 | for (var i = symbols.length - 1; i >= 0; i--) {
|
6709 | symbol = symbols[i];
|
6710 | if (!symbol) {
|
6711 | continue;
|
6712 | }
|
6713 | if (toAbsolute) {
|
6714 | symbol = convertResourceUrl(symbol);
|
6715 | }
|
6716 | for (var ii = 0; ii < props.length; ii++) {
|
6717 | res = symbol[props[ii]];
|
6718 | if (isFunctionDefinition(res)) {
|
6719 | res = getFunctionTypeResources(res);
|
6720 | }
|
6721 | if (!res) {
|
6722 | continue;
|
6723 | }
|
6724 | if (!Array.isArray(res)) {
|
6725 | res = [res];
|
6726 | }
|
6727 | for (var iii = 0; iii < res.length; iii++) {
|
6728 | if (res[iii].slice(0, 4) === 'url(') {
|
6729 | res[iii] = extractCssUrl(res[iii]);
|
6730 | }
|
6731 | resSizeProp = RESOURCE_SIZE_PROPERTIES[ii];
|
6732 | resources.push([res[iii], symbol[resSizeProp[0]], symbol[resSizeProp[1]]]);
|
6733 | }
|
6734 | }
|
6735 | if (symbol['markerType'] === 'path' && symbol['markerPath']) {
|
6736 | w = isFunctionDefinition(symbol['markerWidth']) ? 200 : symbol['markerWidth'];
|
6737 | h = isFunctionDefinition(symbol['markerHeight']) ? 200 : symbol['markerHeight'];
|
6738 | if (isFunctionDefinition(symbol['markerPath'])) {
|
6739 | res = getFunctionTypeResources(symbol['markerPath']);
|
6740 | var path = symbol['markerPath'];
|
6741 | for (var _iii = 0; _iii < res.length; _iii++) {
|
6742 | symbol['markerPath'] = res[_iii];
|
6743 | resources.push([getMarkerPathBase64(symbol), w, h]);
|
6744 | }
|
6745 | symbol['markerPath'] = path;
|
6746 | } else {
|
6747 | resources.push([getMarkerPathBase64(symbol), w, h]);
|
6748 | }
|
6749 | }
|
6750 | }
|
6751 | return resources;
|
6752 | }
|
6753 |
|
6754 | function convertResourceUrl(symbol) {
|
6755 | if (!symbol) {
|
6756 | return null;
|
6757 | }
|
6758 |
|
6759 | var s = symbol;
|
6760 | if (IS_NODE) {
|
6761 | return s;
|
6762 | }
|
6763 | var props = RESOURCE_PROPERTIES;
|
6764 | var res = void 0;
|
6765 | for (var ii = 0, len = props.length; ii < len; ii++) {
|
6766 | res = s[props[ii]];
|
6767 | if (!res) {
|
6768 | continue;
|
6769 | }
|
6770 | s[props[ii]] = _convertUrlToAbsolute(res);
|
6771 | }
|
6772 | return s;
|
6773 | }
|
6774 |
|
6775 | function _convertUrlToAbsolute(res) {
|
6776 | if (isFunctionDefinition(res)) {
|
6777 | var stops = res.stops;
|
6778 | for (var i = 0; i < stops.length; i++) {
|
6779 | stops[i][1] = _convertUrlToAbsolute(stops[i][1]);
|
6780 | }
|
6781 | return res;
|
6782 | }
|
6783 | var embed = 'data:';
|
6784 | if (res.slice(0, 4) === 'url(') {
|
6785 | res = extractCssUrl(res);
|
6786 | }
|
6787 | if (!isURL(res) && (res.length <= embed.length || res.substring(0, embed.length) !== embed)) {
|
6788 | res = _absolute(location.href, res);
|
6789 | }
|
6790 | return res;
|
6791 | }
|
6792 |
|
6793 | function _absolute(base, relative) {
|
6794 | var stack = base.split('/'),
|
6795 | parts = relative.split('/');
|
6796 | if (relative.slice(0, 1) === 0) {
|
6797 | return stack.slice(0, 3).join('/') + relative;
|
6798 | } else {
|
6799 | stack.pop();
|
6800 | for (var i = 0; i < parts.length; i++) {
|
6801 | if (parts[i] === '.') continue;
|
6802 | if (parts[i] === '..') stack.pop();else stack.push(parts[i]);
|
6803 | }
|
6804 | return stack.join('/');
|
6805 | }
|
6806 | }
|
6807 |
|
6808 | function isGradient(g) {
|
6809 | return g && g['colorStops'];
|
6810 | }
|
6811 |
|
6812 | function getGradientStamp(g) {
|
6813 | var keys = [g['type']];
|
6814 | if (g['places']) {
|
6815 | keys.push(g['places'].join());
|
6816 | }
|
6817 | if (g['colorStops']) {
|
6818 | var stops = [];
|
6819 | for (var i = g['colorStops'].length - 1; i >= 0; i--) {
|
6820 | stops.push(g['colorStops'][i].join());
|
6821 | }
|
6822 | keys.push(stops.join(','));
|
6823 | }
|
6824 | return keys.join('_');
|
6825 | }
|
6826 |
|
6827 | function getSymbolStamp(symbol) {
|
6828 | var keys = [];
|
6829 | if (Array.isArray(symbol)) {
|
6830 | for (var i = 0; i < symbol.length; i++) {
|
6831 | keys.push(getSymbolStamp(symbol[i]));
|
6832 | }
|
6833 | return '[ ' + keys.join(' , ') + ' ]';
|
6834 | }
|
6835 | for (var p in symbol) {
|
6836 | if (hasOwn(symbol, p)) {
|
6837 | if (!isFunction(symbol[p])) {
|
6838 | if (isGradient(symbol[p])) {
|
6839 | keys.push(p + '=' + getGradientStamp(symbol[p]));
|
6840 | } else {
|
6841 | keys.push(p + '=' + symbol[p]);
|
6842 | }
|
6843 | }
|
6844 | }
|
6845 | }
|
6846 | return keys.join(';');
|
6847 | }
|
6848 |
|
6849 | function lowerSymbolOpacity(symbol, ratio) {
|
6850 | function s(_symbol, _ratio) {
|
6851 | var op = _symbol['opacity'];
|
6852 | if (isNil(op)) {
|
6853 | _symbol['opacity'] = _ratio;
|
6854 | } else {
|
6855 | _symbol['opacity'] *= _ratio;
|
6856 | }
|
6857 | }
|
6858 | var lower = void 0;
|
6859 | if (Array.isArray(symbol)) {
|
6860 | lower = [];
|
6861 | for (var i = 0; i < symbol.length; i++) {
|
6862 | var d = extend({}, symbol[i]);
|
6863 | s(d, ratio);
|
6864 | lower.push(d);
|
6865 | }
|
6866 | } else {
|
6867 | lower = extend({}, symbol);
|
6868 | s(lower, ratio);
|
6869 | }
|
6870 | return lower;
|
6871 | }
|
6872 |
|
6873 | function extendSymbol(symbol) {
|
6874 | var sources = Array.prototype.slice.call(arguments, 1);
|
6875 | if (!sources || !sources.length) {
|
6876 | sources = [{}];
|
6877 | }
|
6878 | if (Array.isArray(symbol)) {
|
6879 | var s = void 0,
|
6880 | dest = void 0;
|
6881 | var result = [];
|
6882 | for (var i = 0, l = symbol.length; i < l; i++) {
|
6883 | s = symbol[i];
|
6884 | dest = {};
|
6885 | for (var ii = 0, ll = sources.length; ii < ll; ii++) {
|
6886 | if (!Array.isArray(sources[ii])) {
|
6887 | extend(dest, s, sources[ii] ? sources[ii] : {});
|
6888 | } else if (!isNil(sources[ii][i])) {
|
6889 | extend(dest, s, sources[ii][i]);
|
6890 | } else {
|
6891 | extend(dest, s ? s : {});
|
6892 | }
|
6893 | }
|
6894 | result.push(dest);
|
6895 | }
|
6896 | return result;
|
6897 | } else {
|
6898 | var args = [{}, symbol];
|
6899 | args.push.apply(args, sources);
|
6900 | return extend.apply(this, args);
|
6901 | }
|
6902 | }
|
6903 |
|
6904 |
|
6905 |
|
6906 | var index = Object.freeze({
|
6907 | now: now,
|
6908 | extend: extend,
|
6909 | isNil: isNil,
|
6910 | isNumber: isNumber,
|
6911 | isInteger: isInteger,
|
6912 | isObject: isObject,
|
6913 | isString: isString,
|
6914 | isFunction: isFunction,
|
6915 | hasOwn: hasOwn,
|
6916 | join: join,
|
6917 | toRadian: toRadian,
|
6918 | toDegree: toDegree,
|
6919 | IS_NODE: IS_NODE,
|
6920 | get requestAnimFrame () { return requestAnimFrame; },
|
6921 | get cancelAnimFrame () { return cancelAnimFrame; },
|
6922 | isSVG: isSVG,
|
6923 | loadImage: loadImage,
|
6924 | UID: UID,
|
6925 | GUID: GUID,
|
6926 | parseJSON: parseJSON,
|
6927 | pushIn: pushIn,
|
6928 | removeFromArray: removeFromArray,
|
6929 | forEachCoord: forEachCoord,
|
6930 | getValueOrDefault: getValueOrDefault,
|
6931 | sign: sign,
|
6932 | log2: log2,
|
6933 | interpolate: interpolate,
|
6934 | wrap: wrap,
|
6935 | clamp: clamp,
|
6936 | isArrayHasData: isArrayHasData,
|
6937 | isURL: isURL,
|
6938 | isCssUrl: isCssUrl,
|
6939 | extractCssUrl: extractCssUrl,
|
6940 | btoa: btoa,
|
6941 | b64toBlob: b64toBlob,
|
6942 | computeDegree: computeDegree,
|
6943 | emptyImageUrl: emptyImageUrl,
|
6944 | equalMapView: equalMapView,
|
6945 | flash: flash,
|
6946 | translateToSVGStyles: translateToSVGStyles,
|
6947 | getMarkerPathBase64: getMarkerPathBase64,
|
6948 | getExternalResources: getExternalResources,
|
6949 | convertResourceUrl: convertResourceUrl,
|
6950 | isGradient: isGradient,
|
6951 | getGradientStamp: getGradientStamp,
|
6952 | getSymbolStamp: getSymbolStamp,
|
6953 | lowerSymbolOpacity: lowerSymbolOpacity,
|
6954 | extendSymbol: extendSymbol
|
6955 | });
|
6956 |
|
6957 | var Browser = {};
|
6958 |
|
6959 | if (!IS_NODE) {
|
6960 | var ua = navigator.userAgent.toLowerCase(),
|
6961 | doc = document.documentElement,
|
6962 | ie = 'ActiveXObject' in window,
|
6963 | webkit = ua.indexOf('webkit') !== -1,
|
6964 | phantomjs = ua.indexOf('phantom') !== -1,
|
6965 | android23 = ua.search('android [23]') !== -1,
|
6966 | chrome = ua.indexOf('chrome') !== -1,
|
6967 | gecko = ua.indexOf('gecko') !== -1 && !webkit && !window.opera && !ie,
|
6968 | mobile = typeof orientation !== 'undefined' || ua.indexOf('mobile') !== -1,
|
6969 | msPointer = !window.PointerEvent && window.MSPointerEvent,
|
6970 | pointer = window.PointerEvent && navigator.pointerEnabled || msPointer,
|
6971 | ie3d = ie && 'transition' in doc.style,
|
6972 | webkit3d = 'WebKitCSSMatrix' in window && 'm11' in new window.WebKitCSSMatrix() && !android23,
|
6973 | gecko3d = 'MozPerspective' in doc.style,
|
6974 | opera12 = 'OTransition' in doc.style,
|
6975 | any3d = (ie3d || webkit3d || gecko3d) && !opera12 && !phantomjs;
|
6976 |
|
6977 | var chromeVersion = 0;
|
6978 | if (chrome) {
|
6979 | chromeVersion = ua.match(/chrome\/([\d.]+)/)[1];
|
6980 | }
|
6981 |
|
6982 | var touch = !phantomjs && (pointer || 'ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch);
|
6983 |
|
6984 | var webgl = void 0;
|
6985 | try {
|
6986 | var canvas = document.createElement('canvas');
|
6987 | var gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
|
6988 | webgl = gl && gl instanceof WebGLRenderingContext;
|
6989 | } catch (err) {
|
6990 | webgl = false;
|
6991 | }
|
6992 |
|
6993 | Browser = {
|
6994 | ie: ie,
|
6995 | ielt9: ie && !document.addEventListener,
|
6996 | edge: 'msLaunchUri' in navigator && !('documentMode' in document),
|
6997 | webkit: webkit,
|
6998 | gecko: gecko,
|
6999 | android: ua.indexOf('android') !== -1,
|
7000 | android23: android23,
|
7001 | chrome: chrome,
|
7002 | chromeVersion: chromeVersion,
|
7003 | safari: !chrome && ua.indexOf('safari') !== -1,
|
7004 | phantomjs: phantomjs,
|
7005 |
|
7006 | ie3d: ie3d,
|
7007 | webkit3d: webkit3d,
|
7008 | gecko3d: gecko3d,
|
7009 | opera12: opera12,
|
7010 | any3d: any3d,
|
7011 |
|
7012 | mobile: mobile,
|
7013 | mobileWebkit: mobile && webkit,
|
7014 | mobileWebkit3d: mobile && webkit3d,
|
7015 | mobileOpera: mobile && window.opera,
|
7016 | mobileGecko: mobile && gecko,
|
7017 |
|
7018 | touch: !!touch,
|
7019 | msPointer: !!msPointer,
|
7020 | pointer: !!pointer,
|
7021 |
|
7022 | retina: (window.devicePixelRatio || window.screen.deviceXDPI / window.screen.logicalXDPI) > 1,
|
7023 |
|
7024 | language: navigator.browserLanguage ? navigator.browserLanguage : navigator.language,
|
7025 | ie9: ie && document.documentMode === 9,
|
7026 | ie10: ie && document.documentMode === 10,
|
7027 |
|
7028 | webgl: webgl
|
7029 | };
|
7030 | }
|
7031 |
|
7032 | var Browser$1 = Browser;
|
7033 |
|
7034 | var Position = function () {
|
7035 | function Position(x, y) {
|
7036 | classCallCheck(this, Position);
|
7037 |
|
7038 | if (!isNil(x) && !isNil(y)) {
|
7039 | this.x = +x;
|
7040 |
|
7041 | this.y = +y;
|
7042 | } else if (!isNil(x.x) && !isNil(x.y)) {
|
7043 | this.x = +x.x;
|
7044 | this.y = +x.y;
|
7045 | } else if (Array.isArray(x)) {
|
7046 | this.x = +x[0];
|
7047 | this.y = +x[1];
|
7048 | }
|
7049 | if (this._isNaN()) {
|
7050 | throw new Error('Position is NaN');
|
7051 | }
|
7052 | }
|
7053 |
|
7054 | Position.prototype.abs = function abs() {
|
7055 | return new this.constructor(Math.abs(this.x), Math.abs(this.y));
|
7056 | };
|
7057 |
|
7058 | Position.prototype._abs = function _abs() {
|
7059 | this.x = Math.abs(this.x);
|
7060 | this.y = Math.abs(this.y);
|
7061 | return this;
|
7062 | };
|
7063 |
|
7064 | Position.prototype._round = function _round() {
|
7065 | this.x = Math.round(this.x);
|
7066 | this.y = Math.round(this.y);
|
7067 | return this;
|
7068 | };
|
7069 |
|
7070 | Position.prototype.round = function round() {
|
7071 | return new this.constructor(Math.round(this.x), Math.round(this.y));
|
7072 | };
|
7073 |
|
7074 | Position.prototype._ceil = function _ceil() {
|
7075 | this.x = Math.ceil(this.x);
|
7076 | this.y = Math.ceil(this.y);
|
7077 | return this;
|
7078 | };
|
7079 |
|
7080 | Position.prototype.ceil = function ceil() {
|
7081 | return new this.constructor(Math.ceil(this.x), Math.ceil(this.y));
|
7082 | };
|
7083 |
|
7084 | Position.prototype._floor = function _floor() {
|
7085 | this.x = Math.floor(this.x);
|
7086 | this.y = Math.floor(this.y);
|
7087 | return this;
|
7088 | };
|
7089 |
|
7090 | Position.prototype.floor = function floor() {
|
7091 | return new this.constructor(Math.floor(this.x), Math.floor(this.y));
|
7092 | };
|
7093 |
|
7094 | Position.prototype.copy = function copy() {
|
7095 | return new this.constructor(this.x, this.y);
|
7096 | };
|
7097 |
|
7098 | Position.prototype._add = function _add(x, y) {
|
7099 | if (!isNil(x.x)) {
|
7100 | this.x += x.x;
|
7101 | this.y += x.y;
|
7102 | } else if (!isNil(x[0])) {
|
7103 | this.x += x[0];
|
7104 | this.y += x[1];
|
7105 | } else {
|
7106 | this.x += x;
|
7107 | this.y += y;
|
7108 | }
|
7109 | return this;
|
7110 | };
|
7111 |
|
7112 | Position.prototype.add = function add(x, y) {
|
7113 | var nx = void 0,
|
7114 | ny = void 0;
|
7115 | if (!isNil(x.x)) {
|
7116 | nx = this.x + x.x;
|
7117 | ny = this.y + x.y;
|
7118 | } else if (!isNil(x[0])) {
|
7119 | nx = this.x + x[0];
|
7120 | ny = this.y + x[1];
|
7121 | } else {
|
7122 | nx = this.x + x;
|
7123 | ny = this.y + y;
|
7124 | }
|
7125 | return new this.constructor(nx, ny);
|
7126 | };
|
7127 |
|
7128 | Position.prototype._sub = function _sub(x, y) {
|
7129 | if (!isNil(x.x)) {
|
7130 | this.x -= x.x;
|
7131 | this.y -= x.y;
|
7132 | } else if (!isNil(x[0])) {
|
7133 | this.x -= x[0];
|
7134 | this.y -= x[1];
|
7135 | } else {
|
7136 | this.x -= x;
|
7137 | this.y -= y;
|
7138 | }
|
7139 | return this;
|
7140 | };
|
7141 |
|
7142 | Position.prototype._substract = function _substract() {
|
7143 | return this._sub.apply(this, arguments);
|
7144 | };
|
7145 |
|
7146 | Position.prototype.sub = function sub(x, y) {
|
7147 | var nx = void 0,
|
7148 | ny = void 0;
|
7149 | if (!isNil(x.x)) {
|
7150 | nx = this.x - x.x;
|
7151 | ny = this.y - x.y;
|
7152 | } else if (!isNil(x[0])) {
|
7153 | nx = this.x - x[0];
|
7154 | ny = this.y - x[1];
|
7155 | } else {
|
7156 | nx = this.x - x;
|
7157 | ny = this.y - y;
|
7158 | }
|
7159 | return new this.constructor(nx, ny);
|
7160 | };
|
7161 |
|
7162 | Position.prototype.substract = function substract() {
|
7163 | return this.sub.apply(this, arguments);
|
7164 | };
|
7165 |
|
7166 | Position.prototype.multi = function multi(ratio) {
|
7167 | return new this.constructor(this.x * ratio, this.y * ratio);
|
7168 | };
|
7169 |
|
7170 | Position.prototype._multi = function _multi(ratio) {
|
7171 | this.x *= ratio;
|
7172 | this.y *= ratio;
|
7173 | return this;
|
7174 | };
|
7175 |
|
7176 | Position.prototype.div = function div(n) {
|
7177 | return this.multi(1 / n);
|
7178 | };
|
7179 |
|
7180 | Position.prototype._div = function _div(n) {
|
7181 | return this._multi(1 / n);
|
7182 | };
|
7183 |
|
7184 | Position.prototype.equals = function equals(c) {
|
7185 | if (!(c instanceof this.constructor)) {
|
7186 | return false;
|
7187 | }
|
7188 | return this.x === c.x && this.y === c.y;
|
7189 | };
|
7190 |
|
7191 | Position.prototype._isNaN = function _isNaN() {
|
7192 | return isNaN(this.x) || isNaN(this.y);
|
7193 | };
|
7194 |
|
7195 | Position.prototype.isZero = function isZero() {
|
7196 | return this.x === 0 && this.y === 0;
|
7197 | };
|
7198 |
|
7199 | Position.prototype.toArray = function toArray$$1() {
|
7200 | return [this.x, this.y];
|
7201 | };
|
7202 |
|
7203 | Position.prototype.toFixed = function toFixed(n) {
|
7204 | return new this.constructor(this.x.toFixed(n), this.y.toFixed(n));
|
7205 | };
|
7206 |
|
7207 | Position.prototype.toJSON = function toJSON() {
|
7208 | return {
|
7209 | x: this.x,
|
7210 | y: this.y
|
7211 | };
|
7212 | };
|
7213 |
|
7214 | return Position;
|
7215 | }();
|
7216 |
|
7217 | var Point = function (_Position) {
|
7218 | inherits(Point, _Position);
|
7219 |
|
7220 | function Point() {
|
7221 | classCallCheck(this, Point);
|
7222 | return possibleConstructorReturn(this, _Position.apply(this, arguments));
|
7223 | }
|
7224 |
|
7225 | Point.prototype.closeTo = function closeTo(p, delta) {
|
7226 | if (!delta) {
|
7227 | delta = 0;
|
7228 | }
|
7229 | return this.x >= p.x - delta && this.x <= p.x + delta && this.y >= p.y - delta && this.y <= p.y + delta;
|
7230 | };
|
7231 |
|
7232 | Point.prototype.distanceTo = function distanceTo(point) {
|
7233 | var x = point.x - this.x,
|
7234 | y = point.y - this.y;
|
7235 | return Math.sqrt(x * x + y * y);
|
7236 | };
|
7237 |
|
7238 | Point.prototype.mag = function mag() {
|
7239 | return Math.sqrt(this.x * this.x + this.y * this.y);
|
7240 | };
|
7241 |
|
7242 | Point.prototype.unit = function unit() {
|
7243 | return this.copy()._unit();
|
7244 | };
|
7245 |
|
7246 | Point.prototype._unit = function _unit() {
|
7247 | this._div(this.mag());
|
7248 | return this;
|
7249 | };
|
7250 |
|
7251 | Point.prototype.perp = function perp() {
|
7252 | return this.copy()._perp();
|
7253 | };
|
7254 |
|
7255 | Point.prototype._perp = function _perp() {
|
7256 | var y = this.y;
|
7257 | this.y = this.x;
|
7258 | this.x = -y;
|
7259 | return this;
|
7260 | };
|
7261 |
|
7262 | Point.prototype.angleWith = function angleWith(b) {
|
7263 | return this.angleWithSep(b.x, b.y);
|
7264 | };
|
7265 |
|
7266 | Point.prototype.angleWithSep = function angleWithSep(x, y) {
|
7267 | return Math.atan2(this.x * y - this.y * x, this.x * x + this.y * y);
|
7268 | };
|
7269 |
|
7270 | Point.prototype._rotate = function _rotate(angle) {
|
7271 | var cos = Math.cos(angle),
|
7272 | sin = Math.sin(angle),
|
7273 | x = cos * this.x - sin * this.y,
|
7274 | y = sin * this.x + cos * this.y;
|
7275 | this.x = x;
|
7276 | this.y = y;
|
7277 | return this;
|
7278 | };
|
7279 |
|
7280 | Point.prototype.rotate = function rotate(a) {
|
7281 | return this.copy()._rotate(a);
|
7282 | };
|
7283 |
|
7284 | return Point;
|
7285 | }(Position);
|
7286 |
|
7287 | var Size = function () {
|
7288 | function Size(width, height) {
|
7289 | classCallCheck(this, Size);
|
7290 |
|
7291 | if (isNumber(width) && isNumber(height)) {
|
7292 | this.width = width;
|
7293 |
|
7294 | this.height = height;
|
7295 | } else if (isNumber(width['width'])) {
|
7296 | this.width = width.width;
|
7297 | this.height = width.height;
|
7298 | } else if (Array.isArray(width)) {
|
7299 | this.width = width[0];
|
7300 | this.height = width[1];
|
7301 | }
|
7302 | }
|
7303 |
|
7304 | Size.prototype.copy = function copy() {
|
7305 | return new Size(this['width'], this['height']);
|
7306 | };
|
7307 |
|
7308 | Size.prototype.add = function add(x, y) {
|
7309 | var w = void 0,
|
7310 | h = void 0;
|
7311 | if (x instanceof Size) {
|
7312 | w = this.width + x.width;
|
7313 | h = this.height + x.height;
|
7314 | } else {
|
7315 | w = this.width + x;
|
7316 | h = this.height + y;
|
7317 | }
|
7318 | return new Size(w, h);
|
7319 | };
|
7320 |
|
7321 | Size.prototype.equals = function equals(size) {
|
7322 | return this['width'] === size['width'] && this['height'] === size['height'];
|
7323 | };
|
7324 |
|
7325 | Size.prototype.multi = function multi(ratio) {
|
7326 | return new Size(this['width'] * ratio, this['height'] * ratio);
|
7327 | };
|
7328 |
|
7329 | Size.prototype._multi = function _multi(ratio) {
|
7330 | this['width'] *= ratio;
|
7331 | this['height'] *= ratio;
|
7332 | return this;
|
7333 | };
|
7334 |
|
7335 | Size.prototype._round = function _round() {
|
7336 | this['width'] = Math.round(this['width']);
|
7337 | this['height'] = Math.round(this['height']);
|
7338 | return this;
|
7339 | };
|
7340 |
|
7341 | Size.prototype.toPoint = function toPoint() {
|
7342 | return new Point(this['width'], this['height']);
|
7343 | };
|
7344 |
|
7345 | Size.prototype.toArray = function toArray$$1() {
|
7346 | return [this['width'], this['height']];
|
7347 | };
|
7348 |
|
7349 | Size.prototype.toJSON = function toJSON() {
|
7350 | return {
|
7351 | 'width': this['width'],
|
7352 | 'height': this['height']
|
7353 | };
|
7354 | };
|
7355 |
|
7356 | return Size;
|
7357 | }();
|
7358 |
|
7359 | function trim(str) {
|
7360 | return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
|
7361 | }
|
7362 |
|
7363 | var specialPattern = /[\b\t\r\v\f]/igm;
|
7364 |
|
7365 | function escapeSpecialChars(str) {
|
7366 | if (!isString(str)) {
|
7367 | return str;
|
7368 | }
|
7369 | return str.replace(specialPattern, '');
|
7370 | }
|
7371 |
|
7372 | function splitWords(chr) {
|
7373 | return trim(chr).split(/\s+/);
|
7374 | }
|
7375 |
|
7376 | var rulerCtx = typeof document !== 'undefined' ? document.createElement('canvas').getContext('2d') : null;
|
7377 |
|
7378 | function stringWidth(text, font) {
|
7379 | if (stringWidth.node) {
|
7380 | return stringWidth.node(text, font);
|
7381 | }
|
7382 | rulerCtx.font = font;
|
7383 | return rulerCtx.measureText(text).width;
|
7384 | }
|
7385 |
|
7386 | var fontHeight = {};
|
7387 |
|
7388 | function stringLength(text, font) {
|
7389 | if (stringLength.node) {
|
7390 | return stringLength.node(text, font);
|
7391 | } else {
|
7392 | var w = stringWidth(text, font);
|
7393 | if (!font) {
|
7394 | font = '_default_';
|
7395 | }
|
7396 | if (!fontHeight[font]) {
|
7397 | fontHeight[font] = getFontHeight(font);
|
7398 | }
|
7399 | return new Size(w, fontHeight[font]);
|
7400 | }
|
7401 | }
|
7402 |
|
7403 | function getFontHeight(font) {
|
7404 | var domRuler = getDomRuler();
|
7405 | if (font !== '_default_') {
|
7406 | domRuler.style.font = font;
|
7407 | }
|
7408 | domRuler.innerHTML = '秦';
|
7409 | var h = domRuler.clientHeight;
|
7410 |
|
7411 | removeDomNode(domRuler);
|
7412 | return h;
|
7413 | }
|
7414 |
|
7415 | function splitContent(content, font, wrapWidth, textWidth) {
|
7416 | if (!content || content.length === 0) {
|
7417 | return [{ 'text': '', 'width': 0 }];
|
7418 | }
|
7419 | var width = isNil(textWidth) ? stringWidth(content, font) : textWidth;
|
7420 | var chrWidth = width / content.length,
|
7421 | minChrCount = Math.floor(wrapWidth / chrWidth / 2);
|
7422 | if (chrWidth >= wrapWidth || minChrCount <= 0) {
|
7423 | return [{ 'text': '', 'width': wrapWidth }];
|
7424 | }
|
7425 | if (width <= wrapWidth) return [{ 'text': content, 'width': width }];
|
7426 | var result = [];
|
7427 | var testStr = content.substring(0, minChrCount),
|
7428 | prew = chrWidth * minChrCount;
|
7429 | for (var i = minChrCount, l = content.length; i < l; i++) {
|
7430 | var chr = content[i];
|
7431 | var w = stringWidth(testStr + chr);
|
7432 | if (w >= wrapWidth) {
|
7433 | result.push({ 'text': testStr, 'width': prew });
|
7434 | testStr = content.substring(i, minChrCount + i);
|
7435 | i += minChrCount - 1;
|
7436 | prew = chrWidth * minChrCount;
|
7437 | } else {
|
7438 | testStr += chr;
|
7439 | prew = w;
|
7440 | }
|
7441 | if (i >= l - 1) {
|
7442 | prew = stringWidth(testStr);
|
7443 | result.push({ 'text': testStr, 'width': prew });
|
7444 | }
|
7445 | }
|
7446 | return result;
|
7447 | }
|
7448 |
|
7449 | var contentExpRe = /\{([\w_]+)\}/g;
|
7450 |
|
7451 | function replaceVariable(str, props) {
|
7452 | if (!isString(str)) {
|
7453 | return str;
|
7454 | }
|
7455 | return str.replace(contentExpRe, function (str, key) {
|
7456 | if (!props) {
|
7457 | return '';
|
7458 | }
|
7459 | var value = props[key];
|
7460 | if (isNil(value)) {
|
7461 | return '';
|
7462 | } else if (Array.isArray(value)) {
|
7463 | return value.join();
|
7464 | }
|
7465 | return value;
|
7466 | });
|
7467 | }
|
7468 |
|
7469 | function getAlignPoint(size, horizontalAlignment, verticalAlignment) {
|
7470 | var width = size['width'],
|
7471 | height = size['height'];
|
7472 | var alignW = void 0,
|
7473 | alignH = void 0;
|
7474 | if (horizontalAlignment === 'left') {
|
7475 | alignW = -width;
|
7476 | } else if (horizontalAlignment === 'right') {
|
7477 | alignW = 0;
|
7478 | } else {
|
7479 | alignW = -width / 2;
|
7480 | }
|
7481 | if (verticalAlignment === 'top') {
|
7482 | alignH = -height;
|
7483 | } else if (verticalAlignment === 'bottom') {
|
7484 | alignH = 0;
|
7485 | } else {
|
7486 | alignH = -height / 2;
|
7487 | }
|
7488 | return new Point(alignW, alignH);
|
7489 | }
|
7490 |
|
7491 | function getFont(style) {
|
7492 | if (style['textFont']) {
|
7493 | return style['textFont'];
|
7494 | } else {
|
7495 | return (style['textStyle'] && style['textStyle'] !== 'normal' ? style['textStyle'] + ' ' : '') + (style['textWeight'] && style['textWeight'] !== 'normal' ? style['textWeight'] + ' ' : '') + style['textSize'] + 'px ' + (style['textFaceName'][0] === '"' ? style['textFaceName'] : '"' + style['textFaceName'] + '"');
|
7496 | }
|
7497 | }
|
7498 |
|
7499 | function splitTextToRow(text, style) {
|
7500 | var font = getFont(style),
|
7501 | lineSpacing = style['textLineSpacing'] || 0,
|
7502 | size = stringLength(text, font),
|
7503 | textWidth = size['width'],
|
7504 | textHeight = size['height'],
|
7505 | wrapChar = style['textWrapCharacter'],
|
7506 | textRows = [];
|
7507 | var wrapWidth = style['textWrapWidth'];
|
7508 | if (!wrapWidth || wrapWidth > textWidth) {
|
7509 | wrapWidth = textWidth;
|
7510 | }
|
7511 | if (!isString(text)) {
|
7512 | text += '';
|
7513 | }
|
7514 | var actualWidth = 0;
|
7515 | if (wrapChar && text.indexOf(wrapChar) >= 0) {
|
7516 | var texts = text.split(wrapChar);
|
7517 | for (var i = 0, l = texts.length; i < l; i++) {
|
7518 | var t = texts[i];
|
7519 | var tWidth = stringWidth(t, font);
|
7520 | if (tWidth > wrapWidth) {
|
7521 | var contents = splitContent(t, font, wrapWidth, tWidth);
|
7522 | for (var ii = 0, ll = contents.length; ii < ll; ii++) {
|
7523 | var w = contents[ii].width;
|
7524 | if (w > actualWidth) {
|
7525 | actualWidth = w;
|
7526 | }
|
7527 | textRows.push({
|
7528 | 'text': contents[ii].text,
|
7529 | 'size': new Size(w, textHeight)
|
7530 | });
|
7531 | }
|
7532 | } else {
|
7533 | if (tWidth > actualWidth) {
|
7534 | actualWidth = tWidth;
|
7535 | }
|
7536 | textRows.push({
|
7537 | 'text': t,
|
7538 | 'size': new Size(tWidth, textHeight)
|
7539 | });
|
7540 | }
|
7541 | }
|
7542 | } else if (textWidth > wrapWidth) {
|
7543 | var _contents = splitContent(text, font, wrapWidth, textWidth);
|
7544 | for (var _i = 0; _i < _contents.length; _i++) {
|
7545 | var _w = _contents[_i].width;
|
7546 | if (_w > actualWidth) {
|
7547 | actualWidth = _w;
|
7548 | }
|
7549 | textRows.push({
|
7550 | 'text': _contents[_i].text,
|
7551 | 'size': new Size(_w, textHeight)
|
7552 | });
|
7553 | }
|
7554 | } else {
|
7555 | if (textWidth > actualWidth) {
|
7556 | actualWidth = textWidth;
|
7557 | }
|
7558 | textRows.push({
|
7559 | 'text': text,
|
7560 | 'size': size
|
7561 | });
|
7562 | }
|
7563 |
|
7564 | var rowNum = textRows.length;
|
7565 | var textSize = new Size(actualWidth, textHeight * rowNum + lineSpacing * (rowNum - 1));
|
7566 | return {
|
7567 | 'total': rowNum,
|
7568 | 'size': textSize,
|
7569 | 'rows': textRows,
|
7570 | 'rawSize': size
|
7571 | };
|
7572 | }
|
7573 |
|
7574 | var strings = Object.freeze({
|
7575 | trim: trim,
|
7576 | escapeSpecialChars: escapeSpecialChars,
|
7577 | splitWords: splitWords,
|
7578 | stringWidth: stringWidth,
|
7579 | stringLength: stringLength,
|
7580 | getFontHeight: getFontHeight,
|
7581 | splitContent: splitContent,
|
7582 | replaceVariable: replaceVariable,
|
7583 | getAlignPoint: getAlignPoint,
|
7584 | getFont: getFont,
|
7585 | splitTextToRow: splitTextToRow
|
7586 | });
|
7587 |
|
7588 | var first = function first(props) {
|
7589 | return props[0];
|
7590 | };
|
7591 |
|
7592 | var testProp = IS_NODE ? first : function (props) {
|
7593 |
|
7594 | var style = document.documentElement.style;
|
7595 |
|
7596 | for (var i = 0; i < props.length; i++) {
|
7597 | if (props[i] in style) {
|
7598 | return props[i];
|
7599 | }
|
7600 | }
|
7601 | return false;
|
7602 | };
|
7603 |
|
7604 | var TRANSFORM = testProp(['transform', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform']);
|
7605 |
|
7606 | var TRANSFORMORIGIN = testProp(['transformOrigin', 'WebkitTransformOrigin', 'OTransformOrigin', 'MozTransformOrigin', 'msTransformOrigin']);
|
7607 |
|
7608 | var TRANSITION = testProp(['transition', 'WebkitTransition', 'OTransition', 'MozTransition', 'msTransition']);
|
7609 |
|
7610 | var CSSFILTER = testProp(['filter', 'WebkitFilter', 'OFilter', 'MozFilter', 'msFilter']);
|
7611 |
|
7612 | function createEl(tagName, className) {
|
7613 | var el = document.createElement(tagName);
|
7614 | if (className) {
|
7615 | setClass(el, className);
|
7616 | }
|
7617 | return el;
|
7618 | }
|
7619 |
|
7620 | function createElOn(tagName, style, container) {
|
7621 | var el = createEl(tagName);
|
7622 | if (style) {
|
7623 | setStyle(el, style);
|
7624 | }
|
7625 | if (container) {
|
7626 | container.appendChild(el);
|
7627 | }
|
7628 | return el;
|
7629 | }
|
7630 |
|
7631 | function removeDomNode(node) {
|
7632 | if (!node) {
|
7633 | return this;
|
7634 | }
|
7635 | if (Browser$1.ielt9 || Browser$1.ie9) {
|
7636 | var d = createEl('div');
|
7637 | d.appendChild(node);
|
7638 | d.innerHTML = '';
|
7639 | d = null;
|
7640 | } else if (node.parentNode) {
|
7641 | node.parentNode.removeChild(node);
|
7642 | }
|
7643 | return this;
|
7644 | }
|
7645 |
|
7646 | function addDomEvent(obj, typeArr, handler, context) {
|
7647 | if (!obj || !obj.addEventListener || !typeArr || !handler) {
|
7648 | return this;
|
7649 | }
|
7650 | var eventHandler = function eventHandler(e) {
|
7651 | if (!e) {
|
7652 | e = window.event;
|
7653 | }
|
7654 | handler.call(context || obj, e);
|
7655 | return;
|
7656 | };
|
7657 | var types = typeArr.split(' ');
|
7658 | for (var i = types.length - 1; i >= 0; i--) {
|
7659 | var type = types[i];
|
7660 | if (!type) {
|
7661 | continue;
|
7662 | }
|
7663 |
|
7664 | if (!obj['Z__' + type]) {
|
7665 | obj['Z__' + type] = [];
|
7666 | }
|
7667 | var hit = listensDomEvent(obj, type, handler);
|
7668 | if (hit >= 0) {
|
7669 | removeDomEvent(obj, type, handler);
|
7670 | }
|
7671 | obj['Z__' + type].push({
|
7672 | callback: eventHandler,
|
7673 | src: handler
|
7674 | });
|
7675 |
|
7676 | if (type === 'mousewheel' && Browser$1.gecko) {
|
7677 | type = 'DOMMouseScroll';
|
7678 | }
|
7679 | obj.addEventListener(type, eventHandler, false);
|
7680 | }
|
7681 | return this;
|
7682 | }
|
7683 |
|
7684 | function removeDomEvent(obj, typeArr, handler) {
|
7685 | function doRemove(type, callback) {
|
7686 | if (type === 'mousewheel' && Browser$1.gecko) {
|
7687 | type = 'DOMMouseScroll';
|
7688 | }
|
7689 | obj.removeEventListener(type, callback, false);
|
7690 | }
|
7691 | if (!obj || !obj.removeEventListener || !typeArr) {
|
7692 | return this;
|
7693 | }
|
7694 | var types = typeArr.split(' ');
|
7695 | for (var i = types.length - 1; i >= 0; i--) {
|
7696 | var type = types[i];
|
7697 | if (!type) {
|
7698 | continue;
|
7699 | }
|
7700 |
|
7701 | if (!handler && obj['Z__' + type]) {
|
7702 | var handlers = obj['Z__' + type];
|
7703 | for (var j = 0, jlen = handlers.length; j < jlen; j++) {
|
7704 | doRemove(handlers[j].callback);
|
7705 | }
|
7706 | delete obj['Z__' + type];
|
7707 | return this;
|
7708 | }
|
7709 | var hit = listensDomEvent(obj, type, handler);
|
7710 | if (hit < 0) {
|
7711 | return this;
|
7712 | }
|
7713 | var hitHandler = obj['Z__' + type][hit];
|
7714 | doRemove(type, hitHandler.callback);
|
7715 | obj['Z__' + type].splice(hit, 1);
|
7716 | }
|
7717 | return this;
|
7718 | }
|
7719 |
|
7720 | function listensDomEvent(obj, type, handler) {
|
7721 | if (!obj || !obj['Z__' + type] || !handler) {
|
7722 | return -1;
|
7723 | }
|
7724 | var handlers = obj['Z__' + type];
|
7725 | for (var i = 0, len = handlers.length; i < len; i++) {
|
7726 | if (handlers[i].src === handler) {
|
7727 | return i;
|
7728 | }
|
7729 | }
|
7730 | return -1;
|
7731 | }
|
7732 |
|
7733 | function preventDefault(event) {
|
7734 | if (event.preventDefault) {
|
7735 | event.preventDefault();
|
7736 | } else {
|
7737 | event.returnValue = false;
|
7738 | }
|
7739 | return this;
|
7740 | }
|
7741 |
|
7742 | function stopPropagation(e) {
|
7743 | if (e.stopPropagation) {
|
7744 | e.stopPropagation();
|
7745 | } else {
|
7746 | e.cancelBubble = true;
|
7747 | }
|
7748 | return this;
|
7749 | }
|
7750 |
|
7751 | function preventSelection(dom) {
|
7752 | dom.onselectstart = function () {
|
7753 | return false;
|
7754 | };
|
7755 | dom.ondragstart = function () {
|
7756 | return false;
|
7757 | };
|
7758 | dom.setAttribute('unselectable', 'on');
|
7759 | return this;
|
7760 | }
|
7761 |
|
7762 | function offsetDom(dom, offset) {
|
7763 | if (!dom) {
|
7764 | return null;
|
7765 | }
|
7766 |
|
7767 | if (Browser$1.any3d) {
|
7768 | setTransform(dom, offset);
|
7769 | } else {
|
7770 | dom.style.left = offset.x + 'px';
|
7771 | dom.style.top = offset.y + 'px';
|
7772 | }
|
7773 | return offset;
|
7774 | }
|
7775 |
|
7776 | function computeDomPosition(dom) {
|
7777 | var style = window.getComputedStyle(dom);
|
7778 | var padding = [parseInt(style['padding-left']), parseInt(style['padding-top'])];
|
7779 | var rect = dom.getBoundingClientRect();
|
7780 |
|
7781 | var offsetWidth = dom.offsetWidth,
|
7782 | offsetHeight = dom.offsetHeight;
|
7783 | var scaleX = offsetWidth ? rect.width / offsetWidth : 1,
|
7784 | scaleY = offsetHeight ? rect.height / offsetHeight : 1;
|
7785 | dom.__position = [rect.left + padding[0], rect.top + padding[1], scaleX, scaleY];
|
7786 | return dom.__position;
|
7787 | }
|
7788 |
|
7789 | function getEventContainerPoint(ev, dom) {
|
7790 | if (!ev) {
|
7791 | ev = window.event;
|
7792 | }
|
7793 | var domPos = dom.__position;
|
7794 | if (!domPos) {
|
7795 | domPos = computeDomPosition(dom);
|
7796 | }
|
7797 |
|
7798 | return new Point(ev.clientX / domPos[2] - domPos[0] - dom.clientLeft, ev.clientY / domPos[3] - domPos[1] - dom.clientTop);
|
7799 | }
|
7800 |
|
7801 | function endsWith(str, suffix) {
|
7802 | var l = str.length - suffix.length;
|
7803 | return l >= 0 && str.indexOf(suffix, l) === l;
|
7804 | }
|
7805 |
|
7806 | function setStyle(dom, strCss) {
|
7807 | var cssText = dom.style.cssText;
|
7808 | if (!endsWith(cssText, ';')) {
|
7809 | cssText += ';';
|
7810 | }
|
7811 | dom.style.cssText = cssText + strCss;
|
7812 | return this;
|
7813 | }
|
7814 |
|
7815 | function hasClass(el, name) {
|
7816 | if (el.classList !== undefined) {
|
7817 | return el.classList.contains(name);
|
7818 | }
|
7819 | var className = getClass(el);
|
7820 | return className.length > 0 && new RegExp('(^|\\s)' + name + '(\\s|$)').test(className);
|
7821 | }
|
7822 |
|
7823 | function addClass(el, name) {
|
7824 | if (el.classList !== undefined && !hasClass(el, name)) {
|
7825 | var classes = splitWords(name);
|
7826 | for (var i = 0, len = classes.length; i < len; i++) {
|
7827 | el.classList.add(classes[i]);
|
7828 | }
|
7829 | } else {
|
7830 | var className = getClass(el);
|
7831 | setClass(el, (className ? className + ' ' : '') + name);
|
7832 | }
|
7833 | return this;
|
7834 | }
|
7835 |
|
7836 | function setClass(el, name) {
|
7837 | if (isNil(el.className.baseVal)) {
|
7838 | el.className = name;
|
7839 | } else {
|
7840 | el.className.baseVal = name;
|
7841 | }
|
7842 | return this;
|
7843 | }
|
7844 |
|
7845 | function getClass(el) {
|
7846 | return isNil(el.className.baseVal) ? el.className : el.className.baseVal;
|
7847 | }
|
7848 |
|
7849 | function setOpacity(el, value) {
|
7850 | el.style.opacity = value;
|
7851 | return this;
|
7852 | }
|
7853 |
|
7854 | function setTransform(el, offset) {
|
7855 | var pos = offset || new Point(0, 0);
|
7856 | el.style[TRANSFORM] = Browser$1.any3d ? 'translate3d(' + pos.x + 'px,' + pos.y + 'px,0px)' : 'translate(' + pos.x + 'px,' + pos.y + 'px)';
|
7857 |
|
7858 | return this;
|
7859 | }
|
7860 |
|
7861 | function setTransformMatrix(el, m) {
|
7862 | var text = 'matrix(' + (isString(m) ? m : m.join()) + ')';
|
7863 | if (el.style[TRANSFORM] !== text) {
|
7864 | el.style[TRANSFORM] = text;
|
7865 | }
|
7866 | return this;
|
7867 | }
|
7868 |
|
7869 | function removeTransform(el) {
|
7870 | if (el.style[TRANSFORM]) {
|
7871 | el.style[TRANSFORM] = '';
|
7872 | }
|
7873 | return this;
|
7874 | }
|
7875 |
|
7876 | function isHTML(str) {
|
7877 | return (/<[a-z\][\s\S]*>/i.test(str)
|
7878 | );
|
7879 | }
|
7880 |
|
7881 | function measureDom(parentTag, dom) {
|
7882 | var ruler = getDomRuler(parentTag);
|
7883 | if (isString(dom)) {
|
7884 | ruler.innerHTML = dom;
|
7885 | } else {
|
7886 | ruler.appendChild(dom);
|
7887 | }
|
7888 | var result = new Size(ruler.clientWidth, ruler.clientHeight);
|
7889 | removeDomNode(ruler);
|
7890 | return result;
|
7891 | }
|
7892 |
|
7893 | function getDomRuler(tag) {
|
7894 | var span = document.createElement(tag);
|
7895 | span.style.cssText = 'position:absolute;left:-10000px;top:-10000px;';
|
7896 | document.body.appendChild(span);
|
7897 | return span;
|
7898 | }
|
7899 |
|
7900 | var on = addDomEvent;
|
7901 |
|
7902 | var off = removeDomEvent;
|
7903 |
|
7904 | var dom = Object.freeze({
|
7905 | TRANSFORM: TRANSFORM,
|
7906 | TRANSFORMORIGIN: TRANSFORMORIGIN,
|
7907 | TRANSITION: TRANSITION,
|
7908 | CSSFILTER: CSSFILTER,
|
7909 | createEl: createEl,
|
7910 | createElOn: createElOn,
|
7911 | removeDomNode: removeDomNode,
|
7912 | addDomEvent: addDomEvent,
|
7913 | removeDomEvent: removeDomEvent,
|
7914 | listensDomEvent: listensDomEvent,
|
7915 | preventDefault: preventDefault,
|
7916 | stopPropagation: stopPropagation,
|
7917 | preventSelection: preventSelection,
|
7918 | offsetDom: offsetDom,
|
7919 | computeDomPosition: computeDomPosition,
|
7920 | getEventContainerPoint: getEventContainerPoint,
|
7921 | setStyle: setStyle,
|
7922 | hasClass: hasClass,
|
7923 | addClass: addClass,
|
7924 | setClass: setClass,
|
7925 | getClass: getClass,
|
7926 | setOpacity: setOpacity,
|
7927 | setTransform: setTransform,
|
7928 | setTransformMatrix: setTransformMatrix,
|
7929 | removeTransform: removeTransform,
|
7930 | isHTML: isHTML,
|
7931 | measureDom: measureDom,
|
7932 | getDomRuler: getDomRuler,
|
7933 | on: on,
|
7934 | off: off
|
7935 | });
|
7936 |
|
7937 | var Ajax = {
|
7938 | jsonp: function jsonp(url, callback) {
|
7939 | var name = '_maptalks_jsonp_' + UID();
|
7940 | if (url.match(/\?/)) url += '&callback=' + name;else url += '?callback=' + name;
|
7941 |
|
7942 | var script = document.createElement('script');
|
7943 | script.type = 'text/javascript';
|
7944 | script.src = url;
|
7945 |
|
7946 | window[name] = function (data) {
|
7947 | callback(null, data);
|
7948 | document.getElementsByTagName('head')[0].removeChild(script);
|
7949 | script = null;
|
7950 | delete window[name];
|
7951 | };
|
7952 |
|
7953 | document.getElementsByTagName('head')[0].appendChild(script);
|
7954 | return this;
|
7955 | },
|
7956 |
|
7957 | get: function get(url, options, cb) {
|
7958 | if (isFunction(options)) {
|
7959 | var t = cb;
|
7960 | cb = options;
|
7961 | options = t;
|
7962 | }
|
7963 | if (IS_NODE && Ajax.get.node) {
|
7964 | return Ajax.get.node(url, cb, options);
|
7965 | }
|
7966 | var client = Ajax._getClient(cb);
|
7967 | client.open('GET', url, true);
|
7968 | if (options) {
|
7969 | for (var k in options.headers) {
|
7970 | client.setRequestHeader(k, options.headers[k]);
|
7971 | }
|
7972 | client.withCredentials = options.credentials === 'include';
|
7973 | if (options['responseType']) {
|
7974 | client.responseType = options['responseType'];
|
7975 | }
|
7976 | }
|
7977 | client.send(null);
|
7978 | return client;
|
7979 | },
|
7980 |
|
7981 | post: function post(url, options, cb) {
|
7982 | var postData = void 0;
|
7983 | if (!isString(url)) {
|
7984 | var t = cb;
|
7985 | postData = options;
|
7986 | options = url;
|
7987 | url = options.url;
|
7988 | cb = t;
|
7989 | } else {
|
7990 | if (isFunction(options)) {
|
7991 | var _t = cb;
|
7992 | cb = options;
|
7993 | options = _t;
|
7994 | }
|
7995 | options = options || {};
|
7996 | postData = options.postData;
|
7997 | }
|
7998 | if (IS_NODE && Ajax.post.node) {
|
7999 | options.url = url;
|
8000 | return Ajax.post.node(options, postData, cb);
|
8001 | }
|
8002 | var client = Ajax._getClient(cb);
|
8003 | client.open('POST', options.url, true);
|
8004 | if (!options.headers) {
|
8005 | options.headers = {};
|
8006 | }
|
8007 | if (!options.headers['Content-Type']) {
|
8008 | options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
8009 | }
|
8010 | if ('setRequestHeader' in client) {
|
8011 | for (var p in options.headers) {
|
8012 | if (options.headers.hasOwnProperty(p)) {
|
8013 | client.setRequestHeader(p, options.headers[p]);
|
8014 | }
|
8015 | }
|
8016 | }
|
8017 | if (!isString(postData)) {
|
8018 | postData = JSON.stringify(postData);
|
8019 | }
|
8020 | client.send(postData);
|
8021 | return client;
|
8022 | },
|
8023 |
|
8024 | _wrapCallback: function _wrapCallback(client, cb) {
|
8025 | return function () {
|
8026 | if (client.readyState === 4) {
|
8027 | if (client.status === 200) {
|
8028 | if (client.responseType === 'arraybuffer') {
|
8029 | var response = client.response;
|
8030 | if (response.byteLength === 0) {
|
8031 | cb(new Error('http status 200 returned without content.'));
|
8032 | } else {
|
8033 | cb(null, {
|
8034 | data: client.response,
|
8035 | cacheControl: client.getResponseHeader('Cache-Control'),
|
8036 | expires: client.getResponseHeader('Expires'),
|
8037 | contentType: client.getResponseHeader('Content-Type')
|
8038 | });
|
8039 | }
|
8040 | } else {
|
8041 | cb(null, client.responseText);
|
8042 | }
|
8043 | } else {
|
8044 | cb(new Error(client.statusText + ',' + client.status));
|
8045 | }
|
8046 | }
|
8047 | };
|
8048 | },
|
8049 |
|
8050 | _getClient: function _getClient(cb) {
|
8051 | var client = void 0;
|
8052 | try {
|
8053 | client = new XMLHttpRequest();
|
8054 | } catch (e) {
|
8055 | try {
|
8056 | client = new ActiveXObject('Msxml2.XMLHTTP');
|
8057 | } catch (e) {
|
8058 | try {
|
8059 | client = new ActiveXObject('Microsoft.XMLHTTP');
|
8060 | } catch (e) {}
|
8061 | }
|
8062 | }
|
8063 | client.onreadystatechange = Ajax._wrapCallback(client, cb);
|
8064 | return client;
|
8065 | },
|
8066 | getArrayBuffer: function getArrayBuffer(url, options, cb) {
|
8067 | if (isFunction(options)) {
|
8068 | var t = cb;
|
8069 | cb = options;
|
8070 | options = t;
|
8071 | }
|
8072 | if (!options) {
|
8073 | options = {};
|
8074 | }
|
8075 | options['responseType'] = 'arraybuffer';
|
8076 | return Ajax.get(url, options, cb);
|
8077 | },
|
8078 | getImage: function getImage(img, url, options) {
|
8079 | return Ajax.getArrayBuffer(url, options, function (err, imgData) {
|
8080 | if (err) {
|
8081 | if (img.onerror) {
|
8082 | img.onerror(err);
|
8083 | }
|
8084 | } else if (imgData) {
|
8085 | var URL = window.URL || window.webkitURL;
|
8086 | var onload = img.onload;
|
8087 | img.onload = function () {
|
8088 | if (onload) {
|
8089 | onload();
|
8090 | }
|
8091 | URL.revokeObjectURL(img.src);
|
8092 | };
|
8093 | var blob = new Blob([new Uint8Array(imgData.data)], { type: imgData.contentType });
|
8094 | img.cacheControl = imgData.cacheControl;
|
8095 | img.expires = imgData.expires;
|
8096 | img.src = imgData.data.byteLength ? URL.createObjectURL(blob) : emptyImageUrl;
|
8097 | }
|
8098 | });
|
8099 | }
|
8100 | };
|
8101 |
|
8102 | Ajax.getJSON = function (url, options, cb) {
|
8103 | if (isFunction(options)) {
|
8104 | var t = cb;
|
8105 | cb = options;
|
8106 | options = t;
|
8107 | }
|
8108 | var callback = function callback(err, resp) {
|
8109 | var data = resp ? parseJSON(resp) : null;
|
8110 | cb(err, data);
|
8111 | };
|
8112 | if (options && options['jsonp']) {
|
8113 | return Ajax.jsonp(url, callback);
|
8114 | }
|
8115 | return Ajax.get(url, options, callback);
|
8116 | };
|
8117 |
|
8118 | var DEFAULT_STROKE_COLOR = '#000';
|
8119 | var DEFAULT_FILL_COLOR = 'rgba(255,255,255,0)';
|
8120 | var DEFAULT_TEXT_COLOR = '#000';
|
8121 |
|
8122 | var hitTesting = false;
|
8123 |
|
8124 | var Canvas = {
|
8125 | setHitTesting: function setHitTesting(testing) {
|
8126 | hitTesting = testing;
|
8127 | },
|
8128 | createCanvas: function createCanvas(width, height, canvasClass) {
|
8129 | var canvas = void 0;
|
8130 | if (!IS_NODE) {
|
8131 | canvas = createEl('canvas');
|
8132 | canvas.width = width;
|
8133 | canvas.height = height;
|
8134 | } else {
|
8135 | canvas = new canvasClass(width, height);
|
8136 | }
|
8137 | return canvas;
|
8138 | },
|
8139 | prepareCanvasFont: function prepareCanvasFont(ctx, style) {
|
8140 | ctx.textBaseline = 'top';
|
8141 | ctx.font = getFont(style);
|
8142 | var fill = style['textFill'];
|
8143 | if (!fill) {
|
8144 | fill = DEFAULT_TEXT_COLOR;
|
8145 | }
|
8146 | ctx.fillStyle = Canvas.getRgba(fill, style['textOpacity']);
|
8147 | },
|
8148 | prepareCanvas: function prepareCanvas(ctx, style, resources, testing) {
|
8149 | if (!style) {
|
8150 | return;
|
8151 | }
|
8152 | var strokeWidth = style['lineWidth'];
|
8153 | if (!isNil(strokeWidth) && ctx.lineWidth !== strokeWidth) {
|
8154 | ctx.lineWidth = strokeWidth;
|
8155 | }
|
8156 | var strokeColor = style['linePatternFile'] || style['lineColor'] || DEFAULT_STROKE_COLOR;
|
8157 | if (testing) {
|
8158 | ctx.strokeStyle = '#000';
|
8159 | } else if (isImageUrl(strokeColor) && resources) {
|
8160 | var patternOffset = void 0;
|
8161 | if (style['linePatternDx'] || style['linePatternDy']) {
|
8162 | patternOffset = [style['linePatternDx'], style['linePatternDy']];
|
8163 | }
|
8164 | Canvas._setStrokePattern(ctx, strokeColor, strokeWidth, patternOffset, resources);
|
8165 |
|
8166 | style['lineDasharray'] = [];
|
8167 | } else if (isGradient(strokeColor)) {
|
8168 | if (style['lineGradientExtent']) {
|
8169 | ctx.strokeStyle = Canvas._createGradient(ctx, strokeColor, style['lineGradientExtent']);
|
8170 | } else {
|
8171 | ctx.strokeStyle = DEFAULT_STROKE_COLOR;
|
8172 | }
|
8173 | } else {
|
8174 | ctx.strokeStyle = strokeColor;
|
8175 | }
|
8176 | if (style['lineJoin']) {
|
8177 | ctx.lineJoin = style['lineJoin'];
|
8178 | }
|
8179 | if (style['lineCap']) {
|
8180 | ctx.lineCap = style['lineCap'];
|
8181 | }
|
8182 | if (ctx.setLineDash && isArrayHasData(style['lineDasharray'])) {
|
8183 | ctx.setLineDash(style['lineDasharray']);
|
8184 | }
|
8185 | var fill = style['polygonPatternFile'] || style['polygonFill'] || DEFAULT_FILL_COLOR;
|
8186 | if (testing) {
|
8187 | ctx.fillStyle = '#000';
|
8188 | } else if (isImageUrl(fill) && resources) {
|
8189 | var fillImgUrl = extractImageUrl(fill);
|
8190 | var fillTexture = resources.getImage([fillImgUrl, null, null]);
|
8191 | if (!fillTexture) {
|
8192 | fillTexture = resources.getImage([fillImgUrl + '-texture', null, strokeWidth]);
|
8193 | }
|
8194 | if (isSVG(fillImgUrl) && fillTexture instanceof Image && (Browser$1.edge || Browser$1.ie)) {
|
8195 | var w = fillTexture.width || 20,
|
8196 | h = fillTexture.height || 20;
|
8197 | var canvas = Canvas.createCanvas(w, h);
|
8198 | Canvas.image(canvas.getContext('2d'), fillTexture, 0, 0, w, h);
|
8199 | fillTexture = canvas;
|
8200 | }
|
8201 | if (!fillTexture) {
|
8202 | if (typeof console !== 'undefined') {
|
8203 | console.warn('img not found for', fillImgUrl);
|
8204 | }
|
8205 | } else {
|
8206 | ctx.fillStyle = ctx.createPattern(fillTexture, 'repeat');
|
8207 | if (style['polygonPatternDx'] || style['polygonPatternDy']) {
|
8208 | ctx.fillStyle['polygonPatternOffset'] = [style['polygonPatternDx'], style['polygonPatternDy']];
|
8209 | }
|
8210 | }
|
8211 | } else if (isGradient(fill)) {
|
8212 | if (style['polygonGradientExtent']) {
|
8213 | ctx.fillStyle = Canvas._createGradient(ctx, fill, style['polygonGradientExtent']);
|
8214 | } else {
|
8215 | ctx.fillStyle = 'rgba(255,255,255,0)';
|
8216 | }
|
8217 | } else {
|
8218 | ctx.fillStyle = fill;
|
8219 | }
|
8220 | },
|
8221 | _createGradient: function _createGradient(ctx, g, extent) {
|
8222 | var gradient = null,
|
8223 | places = g['places'];
|
8224 | var min = extent.getMin(),
|
8225 | max = extent.getMax(),
|
8226 | width = extent.getWidth(),
|
8227 | height = extent.getHeight();
|
8228 | if (!g['type'] || g['type'] === 'linear') {
|
8229 | if (!places) {
|
8230 | places = [min.x, min.y, max.x, min.y];
|
8231 | } else {
|
8232 | if (places.length !== 4) {
|
8233 | throw new Error('A linear gradient\'s places should have 4 numbers.');
|
8234 | }
|
8235 | places = [min.x + places[0] * width, min.y + places[1] * height, min.x + places[2] * width, min.y + places[3] * height];
|
8236 | }
|
8237 | gradient = ctx.createLinearGradient.apply(ctx, places);
|
8238 | } else if (g['type'] === 'radial') {
|
8239 | if (!places) {
|
8240 | var c = extent.getCenter()._round();
|
8241 | places = [c.x, c.y, Math.abs(c.x - min.x), c.x, c.y, 0];
|
8242 | } else {
|
8243 | if (places.length !== 6) {
|
8244 | throw new Error('A radial gradient\'s places should have 6 numbers.');
|
8245 | }
|
8246 | places = [min.x + places[0] * width, min.y + places[1] * height, width * places[2], min.x + places[3] * width, min.y + places[4] * height, width * places[5]];
|
8247 | }
|
8248 | gradient = ctx.createRadialGradient.apply(ctx, places);
|
8249 | }
|
8250 | g['colorStops'].forEach(function (stop) {
|
8251 | gradient.addColorStop.apply(gradient, stop);
|
8252 | });
|
8253 | return gradient;
|
8254 | },
|
8255 | _setStrokePattern: function _setStrokePattern(ctx, strokePattern, strokeWidth, linePatternOffset, resources) {
|
8256 | var imgUrl = extractImageUrl(strokePattern);
|
8257 | var imageTexture = void 0;
|
8258 | if (IS_NODE) {
|
8259 | imageTexture = resources.getImage([imgUrl, null, strokeWidth]);
|
8260 | } else {
|
8261 | var key = imgUrl + '-texture-' + strokeWidth;
|
8262 | imageTexture = resources.getImage(key);
|
8263 | if (!imageTexture) {
|
8264 | var imageRes = resources.getImage([imgUrl, null, null]);
|
8265 | if (imageRes) {
|
8266 | var w = void 0;
|
8267 | if (!imageRes.width || !imageRes.height) {
|
8268 | w = strokeWidth;
|
8269 | } else {
|
8270 | w = Math.round(imageRes.width * strokeWidth / imageRes.height);
|
8271 | }
|
8272 | var patternCanvas = Canvas.createCanvas(w, strokeWidth, ctx.canvas.constructor);
|
8273 | Canvas.image(patternCanvas.getContext('2d'), imageRes, 0, 0, w, strokeWidth);
|
8274 | resources.addResource([key, null, strokeWidth], patternCanvas);
|
8275 | imageTexture = patternCanvas;
|
8276 | }
|
8277 | }
|
8278 | }
|
8279 | if (imageTexture) {
|
8280 | ctx.strokeStyle = ctx.createPattern(imageTexture, 'repeat');
|
8281 | ctx.strokeStyle['linePatternOffset'] = linePatternOffset;
|
8282 | } else if (typeof console !== 'undefined') {
|
8283 | console.warn('img not found for', imgUrl);
|
8284 | }
|
8285 | },
|
8286 | clearRect: function clearRect(ctx, x1, y1, x2, y2) {
|
8287 | ctx.canvas._drawn = false;
|
8288 | ctx.clearRect(x1, y1, x2, y2);
|
8289 | },
|
8290 | fillCanvas: function fillCanvas(ctx, fillOpacity, x, y) {
|
8291 | if (hitTesting) {
|
8292 | fillOpacity = 1;
|
8293 | }
|
8294 | ctx.canvas._drawn = true;
|
8295 | if (fillOpacity === 0) {
|
8296 | return;
|
8297 | }
|
8298 | var isPattern = Canvas._isPattern(ctx.fillStyle);
|
8299 |
|
8300 | var offset = ctx.fillStyle && ctx.fillStyle['polygonPatternOffset'];
|
8301 | var dx = offset ? offset[0] : 0,
|
8302 | dy = offset ? offset[1] : 0;
|
8303 |
|
8304 | if (isNil(fillOpacity)) {
|
8305 | fillOpacity = 1;
|
8306 | }
|
8307 | var alpha = void 0;
|
8308 | if (fillOpacity < 1) {
|
8309 | alpha = ctx.globalAlpha;
|
8310 | ctx.globalAlpha *= fillOpacity;
|
8311 | }
|
8312 | if (isPattern) {
|
8313 | x = x || 0;
|
8314 | y = y || 0;
|
8315 |
|
8316 | ctx.translate(x + dx, y + dy);
|
8317 | }
|
8318 | ctx.fill();
|
8319 | if (isPattern) {
|
8320 | ctx.translate(-x - dx, -y - dy);
|
8321 | }
|
8322 | if (fillOpacity < 1) {
|
8323 | ctx.globalAlpha = alpha;
|
8324 | }
|
8325 | },
|
8326 | getRgba: function getRgba(color, op) {
|
8327 | if (isNil(op)) {
|
8328 | op = 1;
|
8329 | }
|
8330 | if (color[0] !== '#') {
|
8331 | return color;
|
8332 | }
|
8333 | var r = void 0,
|
8334 | g = void 0,
|
8335 | b = void 0;
|
8336 | if (color.length === 7) {
|
8337 | r = parseInt(color.substring(1, 3), 16);
|
8338 | g = parseInt(color.substring(3, 5), 16);
|
8339 | b = parseInt(color.substring(5, 7), 16);
|
8340 | } else {
|
8341 | r = parseInt(color.substring(1, 2), 16) * 17;
|
8342 | g = parseInt(color.substring(2, 3), 16) * 17;
|
8343 | b = parseInt(color.substring(3, 4), 16) * 17;
|
8344 | }
|
8345 | return 'rgba(' + r + ',' + g + ',' + b + ',' + op + ')';
|
8346 | },
|
8347 | image: function image(ctx, img, x, y, width, height) {
|
8348 | ctx.canvas._drawn = true;
|
8349 | try {
|
8350 | if (isNumber(width) && isNumber(height)) {
|
8351 | ctx.drawImage(img, x, y, width, height);
|
8352 | } else {
|
8353 | ctx.drawImage(img, x, y);
|
8354 | }
|
8355 | } catch (error) {
|
8356 | if (console) {
|
8357 | console.warn('error when drawing image on canvas:', error);
|
8358 | console.warn(img);
|
8359 | }
|
8360 | }
|
8361 | },
|
8362 | text: function text(ctx, _text, pt, style, textDesc) {
|
8363 | Canvas._textOnMultiRow(ctx, textDesc['rows'], style, pt, textDesc['size'], textDesc['rawSize']);
|
8364 | },
|
8365 | _textOnMultiRow: function _textOnMultiRow(ctx, texts, style, point, splitTextSize, textSize) {
|
8366 | var ptAlign = getAlignPoint(splitTextSize, style['textHorizontalAlignment'], style['textVerticalAlignment']),
|
8367 | lineHeight = textSize['height'] + style['textLineSpacing'],
|
8368 | basePoint = point.add(0, ptAlign.y),
|
8369 | maxHeight = style['textMaxHeight'];
|
8370 | var text = void 0,
|
8371 | rowAlign = void 0,
|
8372 | height = 0;
|
8373 | for (var i = 0, len = texts.length; i < len; i++) {
|
8374 | text = texts[i]['text'];
|
8375 | rowAlign = getAlignPoint(texts[i]['size'], style['textHorizontalAlignment'], style['textVerticalAlignment']);
|
8376 | Canvas._textOnLine(ctx, text, basePoint.add(rowAlign.x, i * lineHeight), style['textHaloRadius'], style['textHaloFill'], style['textHaloOpacity']);
|
8377 | if (maxHeight > 0) {
|
8378 | height += lineHeight;
|
8379 | if (height + textSize['height'] >= maxHeight) {
|
8380 | break;
|
8381 | }
|
8382 | }
|
8383 | }
|
8384 | },
|
8385 | _textOnLine: function _textOnLine(ctx, text, pt, textHaloRadius, textHaloFill, textHaloAlpha) {
|
8386 | if (hitTesting) {
|
8387 | textHaloAlpha = 1;
|
8388 | }
|
8389 | var drawHalo = textHaloAlpha !== 0 && textHaloRadius !== 0;
|
8390 |
|
8391 | ctx.textBaseline = 'top';
|
8392 | var gco = void 0,
|
8393 | fill = void 0;
|
8394 | var shadowBlur = ctx.shadowBlur,
|
8395 | shadowOffsetX = ctx.shadowOffsetX,
|
8396 | shadowOffsetY = ctx.shadowOffsetY;
|
8397 | if (drawHalo) {
|
8398 | var alpha = ctx.globalAlpha;
|
8399 |
|
8400 | ctx.globalAlpha *= textHaloAlpha;
|
8401 |
|
8402 | ctx.miterLimit = 2;
|
8403 | ctx.lineJoin = 'round';
|
8404 | ctx.lineCap = 'round';
|
8405 | ctx.lineWidth = textHaloRadius * 2;
|
8406 | ctx.strokeStyle = textHaloFill;
|
8407 | ctx.strokeText(text, Math.round(pt.x), Math.round(pt.y));
|
8408 | ctx.miterLimit = 10;
|
8409 |
|
8410 | ctx.globalAlpha = alpha;
|
8411 |
|
8412 | gco = ctx.globalCompositeOperation;
|
8413 | ctx.globalCompositeOperation = 'destination-out';
|
8414 | fill = ctx.fillStyle;
|
8415 | ctx.fillStyle = '#000';
|
8416 | }
|
8417 |
|
8418 | if (shadowBlur && drawHalo) {
|
8419 | ctx.shadowBlur = ctx.shadowOffsetX = ctx.shadowOffsetY = 0;
|
8420 | }
|
8421 | Canvas.fillText(ctx, text, pt);
|
8422 | if (gco) {
|
8423 | ctx.globalCompositeOperation = gco;
|
8424 | Canvas.fillText(ctx, text, pt, fill);
|
8425 | if (shadowBlur) {
|
8426 | ctx.shadowBlur = shadowBlur;
|
8427 | ctx.shadowOffsetX = shadowOffsetX;
|
8428 | ctx.shadowOffsetY = shadowOffsetY;
|
8429 | }
|
8430 | }
|
8431 | },
|
8432 | fillText: function fillText(ctx, text, point, rgba) {
|
8433 | ctx.canvas._drawn = true;
|
8434 | if (rgba) {
|
8435 | ctx.fillStyle = rgba;
|
8436 | }
|
8437 | ctx.fillText(text, Math.round(point.x), Math.round(point.y));
|
8438 | },
|
8439 | _stroke: function _stroke(ctx, strokeOpacity, x, y) {
|
8440 | if (hitTesting) {
|
8441 | strokeOpacity = 1;
|
8442 | }
|
8443 | ctx.canvas._drawn = true;
|
8444 | if (strokeOpacity === 0) {
|
8445 | return;
|
8446 | }
|
8447 | var offset = ctx.strokeStyle && ctx.strokeStyle['linePatternOffset'];
|
8448 | var dx = offset ? offset[0] : 0,
|
8449 | dy = offset ? offset[1] : 0;
|
8450 |
|
8451 | var isPattern = Canvas._isPattern(ctx.strokeStyle) && (!isNil(x) && !isNil(y) || !isNil(dx) && !isNil(dy));
|
8452 |
|
8453 | if (isNil(strokeOpacity)) {
|
8454 | strokeOpacity = 1;
|
8455 | }
|
8456 | var alpha = void 0;
|
8457 | if (strokeOpacity < 1) {
|
8458 | alpha = ctx.globalAlpha;
|
8459 | ctx.globalAlpha *= strokeOpacity;
|
8460 | }
|
8461 | if (isPattern) {
|
8462 | x = x || 0;
|
8463 | y = y || 0;
|
8464 |
|
8465 | ctx.translate(x + dx, y + dy);
|
8466 | }
|
8467 | ctx.stroke();
|
8468 | if (isPattern) {
|
8469 | ctx.translate(-x - dx, -y - dy);
|
8470 | }
|
8471 | if (strokeOpacity < 1) {
|
8472 | ctx.globalAlpha = alpha;
|
8473 | }
|
8474 | },
|
8475 | _path: function _path(ctx, points, lineDashArray, lineOpacity, ignoreStrokePattern) {
|
8476 | if (!isArrayHasData(points)) {
|
8477 | return;
|
8478 | }
|
8479 |
|
8480 | function fillWithPattern(p1, p2) {
|
8481 | var degree = computeDegree(p1.x, p1.y, p2.x, p2.y);
|
8482 | ctx.save();
|
8483 | ctx.translate(p1.x, p1.y - ctx.lineWidth / 2 / Math.cos(degree));
|
8484 | ctx.rotate(degree);
|
8485 | Canvas._stroke(ctx, lineOpacity);
|
8486 | ctx.restore();
|
8487 | }
|
8488 |
|
8489 | var isDashed = isArrayHasData(lineDashArray);
|
8490 | var isPatternLine = ignoreStrokePattern === true ? false : Canvas._isPattern(ctx.strokeStyle);
|
8491 | var point = void 0,
|
8492 | prePoint = void 0,
|
8493 | nextPoint = void 0;
|
8494 | for (var i = 0, len = points.length; i < len; i++) {
|
8495 | point = points[i];
|
8496 | if (!isDashed || ctx.setLineDash) {
|
8497 | ctx.lineTo(point.x, point.y);
|
8498 | if (isPatternLine && i > 0) {
|
8499 | prePoint = points[i - 1];
|
8500 | fillWithPattern(prePoint, point);
|
8501 | ctx.beginPath();
|
8502 | ctx.moveTo(point.x, point.y);
|
8503 | }
|
8504 | } else if (isDashed) {
|
8505 | if (i === len - 1) {
|
8506 | break;
|
8507 | }
|
8508 | nextPoint = points[i + 1];
|
8509 | drawDashLine(ctx, point, nextPoint, lineDashArray, isPatternLine);
|
8510 | }
|
8511 | }
|
8512 | },
|
8513 | path: function path(ctx, points, lineOpacity, fillOpacity, lineDashArray) {
|
8514 | if (!isArrayHasData(points)) {
|
8515 | return;
|
8516 | }
|
8517 | ctx.beginPath();
|
8518 | ctx.moveTo(points[0].x, points[0].y);
|
8519 | Canvas._path(ctx, points, lineDashArray, lineOpacity);
|
8520 | Canvas._stroke(ctx, lineOpacity);
|
8521 | },
|
8522 | polygon: function polygon(ctx, points, lineOpacity, fillOpacity, lineDashArray, smoothness) {
|
8523 | if (!isArrayHasData(points)) {
|
8524 | return;
|
8525 | }
|
8526 | function fillPolygon(points, i, op) {
|
8527 | Canvas.fillCanvas(ctx, op, points[i][0].x, points[i][0].y);
|
8528 | }
|
8529 | var isPatternLine = Canvas._isPattern(ctx.strokeStyle),
|
8530 | fillFirst = isArrayHasData(lineDashArray) && !ctx.setLineDash || isPatternLine && !smoothness;
|
8531 | if (!isArrayHasData(points[0])) {
|
8532 | points = [points];
|
8533 | }
|
8534 | var op = void 0,
|
8535 | i = void 0,
|
8536 | len = void 0;
|
8537 | if (fillFirst) {
|
8538 | ctx.save();
|
8539 | for (i = 0, len = points.length; i < len; i++) {
|
8540 | if (!isArrayHasData(points[i])) {
|
8541 | continue;
|
8542 | }
|
8543 | Canvas._ring(ctx, points[i], null, 0, true);
|
8544 | op = fillOpacity;
|
8545 | if (i > 0) {
|
8546 | ctx.globalCompositeOperation = 'destination-out';
|
8547 | op = 1;
|
8548 | }
|
8549 | fillPolygon(points, i, op);
|
8550 | if (i > 0) {
|
8551 | ctx.globalCompositeOperation = 'source-over';
|
8552 | } else if (len > 1) {
|
8553 | ctx.fillStyle = '#fff';
|
8554 | }
|
8555 | Canvas._stroke(ctx, 0);
|
8556 | }
|
8557 | ctx.restore();
|
8558 | }
|
8559 | for (i = 0, len = points.length; i < len; i++) {
|
8560 | if (!isArrayHasData(points[i])) {
|
8561 | continue;
|
8562 | }
|
8563 |
|
8564 | if (smoothness) {
|
8565 | Canvas.paintSmoothLine(ctx, points[i], lineOpacity, smoothness, true);
|
8566 | ctx.closePath();
|
8567 | } else {
|
8568 | Canvas._ring(ctx, points[i], lineDashArray, lineOpacity);
|
8569 | }
|
8570 |
|
8571 | if (!fillFirst) {
|
8572 | op = fillOpacity;
|
8573 | if (i > 0) {
|
8574 | ctx.globalCompositeOperation = 'destination-out';
|
8575 | op = 1;
|
8576 | }
|
8577 | fillPolygon(points, i, op);
|
8578 | if (i > 0) {
|
8579 | ctx.globalCompositeOperation = 'source-over';
|
8580 | } else if (len > 1) {
|
8581 | ctx.fillStyle = '#fff';
|
8582 | }
|
8583 | }
|
8584 | Canvas._stroke(ctx, lineOpacity);
|
8585 | }
|
8586 | },
|
8587 | _ring: function _ring(ctx, ring, lineDashArray, lineOpacity, ignorePattern) {
|
8588 | var isPattern = Canvas._isPattern(ctx.strokeStyle);
|
8589 | if (!ignorePattern && isPattern && !ring[0].equals(ring[ring.length - 1])) {
|
8590 | ring = ring.concat([ring[0]]);
|
8591 | }
|
8592 | ctx.beginPath();
|
8593 | ctx.moveTo(ring[0].x, ring[0].y);
|
8594 | Canvas._path(ctx, ring, lineDashArray, lineOpacity, ignorePattern);
|
8595 | if (!isPattern) {
|
8596 | ctx.closePath();
|
8597 | }
|
8598 | },
|
8599 | paintSmoothLine: function paintSmoothLine(ctx, points, lineOpacity, smoothValue, close, tailIdx, tailRatio) {
|
8600 | if (!points) {
|
8601 | return;
|
8602 | }
|
8603 | if (points.length <= 2 || !smoothValue) {
|
8604 | Canvas.path(ctx, points, lineOpacity);
|
8605 | return;
|
8606 | }
|
8607 |
|
8608 | function interpolate(t0, t1, x1, y1, bx1, by1, bx2, by2, x2, y2) {
|
8609 | var u0 = 1.0 - t0;
|
8610 | var u1 = 1.0 - t1;
|
8611 |
|
8612 | var qxa = x1 * u0 * u0 + bx1 * 2 * t0 * u0 + bx2 * t0 * t0;
|
8613 | var qxb = x1 * u1 * u1 + bx1 * 2 * t1 * u1 + bx2 * t1 * t1;
|
8614 | var qxc = bx1 * u0 * u0 + bx2 * 2 * t0 * u0 + x2 * t0 * t0;
|
8615 | var qxd = bx1 * u1 * u1 + bx2 * 2 * t1 * u1 + x2 * t1 * t1;
|
8616 |
|
8617 | var qya = y1 * u0 * u0 + by1 * 2 * t0 * u0 + by2 * t0 * t0;
|
8618 | var qyb = y1 * u1 * u1 + by1 * 2 * t1 * u1 + by2 * t1 * t1;
|
8619 | var qyc = by1 * u0 * u0 + by2 * 2 * t0 * u0 + y2 * t0 * t0;
|
8620 | var qyd = by1 * u1 * u1 + by2 * 2 * t1 * u1 + y2 * t1 * t1;
|
8621 |
|
8622 | var xb = qxa * u1 + qxc * t1;
|
8623 | var xc = qxb * u0 + qxd * t0;
|
8624 | var xd = qxb * u1 + qxd * t1;
|
8625 |
|
8626 | var yb = qya * u1 + qyc * t1;
|
8627 | var yc = qyb * u0 + qyd * t0;
|
8628 | var yd = qyb * u1 + qyd * t1;
|
8629 |
|
8630 | return [xb, yb, xc, yc, xd, yd];
|
8631 | }
|
8632 |
|
8633 | function getCubicControlPoints(x0, y0, x1, y1, x2, y2, x3, y3, smoothValue, t) {
|
8634 | var xc1 = (x0 + x1) / 2.0,
|
8635 | yc1 = (y0 + y1) / 2.0;
|
8636 | var xc2 = (x1 + x2) / 2.0,
|
8637 | yc2 = (y1 + y2) / 2.0;
|
8638 | var xc3 = (x2 + x3) / 2.0,
|
8639 | yc3 = (y2 + y3) / 2.0;
|
8640 |
|
8641 | var len1 = Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
|
8642 | var len2 = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
8643 | var len3 = Math.sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
|
8644 |
|
8645 | var k1 = len1 / (len1 + len2);
|
8646 | var k2 = len2 / (len2 + len3);
|
8647 |
|
8648 | var xm1 = xc1 + (xc2 - xc1) * k1,
|
8649 | ym1 = yc1 + (yc2 - yc1) * k1;
|
8650 |
|
8651 | var xm2 = xc2 + (xc3 - xc2) * k2,
|
8652 | ym2 = yc2 + (yc3 - yc2) * k2;
|
8653 |
|
8654 | var ctrl1X = xm1 + (xc2 - xm1) * smoothValue + x1 - xm1,
|
8655 | ctrl1Y = ym1 + (yc2 - ym1) * smoothValue + y1 - ym1,
|
8656 | ctrl2X = xm2 + (xc2 - xm2) * smoothValue + x2 - xm2,
|
8657 | ctrl2Y = ym2 + (yc2 - ym2) * smoothValue + y2 - ym2;
|
8658 |
|
8659 | var ctrlPoints = [ctrl1X, ctrl1Y, ctrl2X, ctrl2Y];
|
8660 | if (t < 1) {
|
8661 | return interpolate(0, t, x1, y1, ctrl1X, ctrl1Y, ctrl2X, ctrl2Y, x2, y2);
|
8662 | } else {
|
8663 | return ctrlPoints;
|
8664 | }
|
8665 | }
|
8666 | var count = points.length;
|
8667 | var l = close ? count : count - 1;
|
8668 |
|
8669 | ctx.beginPath();
|
8670 | ctx.moveTo(points[0].x, points[0].y);
|
8671 | if (tailRatio !== undefined) l -= Math.max(l - tailIdx - 1, 0);
|
8672 | var preCtrlPoints = void 0;
|
8673 | for (var i = 0; i < l; i++) {
|
8674 | var x1 = points[i].x,
|
8675 | y1 = points[i].y;
|
8676 |
|
8677 | var x0 = void 0,
|
8678 | y0 = void 0,
|
8679 | x2 = void 0,
|
8680 | y2 = void 0,
|
8681 | x3 = void 0,
|
8682 | y3 = void 0;
|
8683 | if (i - 1 < 0) {
|
8684 | if (!close) {
|
8685 | x0 = points[i + 1].x;
|
8686 | y0 = points[i + 1].y;
|
8687 | } else {
|
8688 | x0 = points[l - 1].x;
|
8689 | y0 = points[l - 1].y;
|
8690 | }
|
8691 | } else {
|
8692 | x0 = points[i - 1].x;
|
8693 | y0 = points[i - 1].y;
|
8694 | }
|
8695 | if (i + 1 < count) {
|
8696 | x2 = points[i + 1].x;
|
8697 | y2 = points[i + 1].y;
|
8698 | } else {
|
8699 | x2 = points[i + 1 - count].x;
|
8700 | y2 = points[i + 1 - count].y;
|
8701 | }
|
8702 | if (i + 2 < count) {
|
8703 | x3 = points[i + 2].x;
|
8704 | y3 = points[i + 2].y;
|
8705 | } else if (!close) {
|
8706 | x3 = points[i].x;
|
8707 | y3 = points[i].y;
|
8708 | } else {
|
8709 | x3 = points[i + 2 - count].x;
|
8710 | y3 = points[i + 2 - count].y;
|
8711 | }
|
8712 |
|
8713 | var ctrlPoints = getCubicControlPoints(x0, y0, x1, y1, x2, y2, x3, y3, smoothValue, i === l - 1 ? tailRatio : 1);
|
8714 | if (i === l - 1 && tailRatio >= 0 && tailRatio < 1) {
|
8715 | ctx.bezierCurveTo(ctrlPoints[0], ctrlPoints[1], ctrlPoints[2], ctrlPoints[3], ctrlPoints[4], ctrlPoints[5]);
|
8716 | points.splice(l - 1, count - (l - 1) - 1);
|
8717 | var lastPoint = new Point(ctrlPoints[4], ctrlPoints[5]);
|
8718 | lastPoint.prevCtrlPoint = new Point(ctrlPoints[2], ctrlPoints[3]);
|
8719 | points.push(lastPoint);
|
8720 | count = points.length;
|
8721 | } else {
|
8722 | ctx.bezierCurveTo(ctrlPoints[0], ctrlPoints[1], ctrlPoints[2], ctrlPoints[3], x2, y2);
|
8723 | }
|
8724 | points[i].nextCtrlPoint = ctrlPoints.slice(0, 2);
|
8725 | points[i].prevCtrlPoint = preCtrlPoints ? preCtrlPoints.slice(2) : null;
|
8726 | preCtrlPoints = ctrlPoints;
|
8727 | }
|
8728 | if (!close && points[1].prevCtrlPoint) {
|
8729 | points[0].nextCtrlPoint = points[1].prevCtrlPoint;
|
8730 | delete points[0].prevCtrlPoint;
|
8731 | }
|
8732 | if (!points[count - 1].prevCtrlPoint) {
|
8733 | points[count - 1].prevCtrlPoint = points[count - 2].nextCtrlPoint;
|
8734 | }
|
8735 | Canvas._stroke(ctx, lineOpacity);
|
8736 | },
|
8737 | _arcBetween: function _arcBetween(ctx, p1, p2, degree) {
|
8738 | var a = degree,
|
8739 | dist = p1.distanceTo(p2),
|
8740 | r = dist / 2 / Math.sin(a / 2);
|
8741 |
|
8742 | var p1p2 = Math.asin((p2.y - p1.y) / dist);
|
8743 | if (p1.x > p2.x) {
|
8744 | p1p2 = Math.PI - p1p2;
|
8745 | }
|
8746 |
|
8747 | var cp2 = 90 * Math.PI / 180 - a / 2,
|
8748 | da = p1p2 - cp2;
|
8749 |
|
8750 | var dx = Math.cos(da) * r,
|
8751 | dy = Math.sin(da) * r,
|
8752 | cx = p1.x + dx,
|
8753 | cy = p1.y + dy;
|
8754 |
|
8755 | var startAngle = Math.asin((p2.y - cy) / r);
|
8756 | if (cx > p2.x) {
|
8757 | startAngle = Math.PI - startAngle;
|
8758 | }
|
8759 | var endAngle = startAngle + a;
|
8760 |
|
8761 | ctx.beginPath();
|
8762 | ctx.arc(cx, cy, r, startAngle, endAngle);
|
8763 | return [cx, cy];
|
8764 | },
|
8765 | _lineTo: function _lineTo(ctx, p) {
|
8766 | ctx.lineTo(p.x, p.y);
|
8767 | },
|
8768 | bezierCurveAndFill: function bezierCurveAndFill(ctx, points, lineOpacity, fillOpacity) {
|
8769 | ctx.beginPath();
|
8770 | var start = points[0];
|
8771 | ctx.moveTo(start.x, start.y);
|
8772 | var args = [ctx];
|
8773 | args.push.apply(args, points.splice(1));
|
8774 | Canvas._bezierCurveTo.apply(Canvas, args);
|
8775 | Canvas.fillCanvas(ctx, fillOpacity);
|
8776 | Canvas._stroke(ctx, lineOpacity);
|
8777 | },
|
8778 | _bezierCurveTo: function _bezierCurveTo(ctx, p1, p2, p3) {
|
8779 | ctx.bezierCurveTo(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
|
8780 | },
|
8781 | ellipse: function ellipse(ctx, pt, width, height, lineOpacity, fillOpacity) {
|
8782 | function bezierEllipse(x, y, a, b) {
|
8783 | var k = 0.5522848,
|
8784 | ox = a * k,
|
8785 | oy = b * k;
|
8786 | ctx.moveTo(x - a, y);
|
8787 | ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
|
8788 | ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
|
8789 | ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
|
8790 | ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
|
8791 | ctx.closePath();
|
8792 | }
|
8793 | ctx.beginPath();
|
8794 | if (width === height) {
|
8795 | ctx.arc(pt.x, pt.y, width, 0, 2 * Math.PI);
|
8796 | } else if (ctx.ellipse) {
|
8797 | ctx.ellipse(pt.x, pt.y, width, height, 0, 0, Math.PI / 180 * 360);
|
8798 | } else {
|
8799 | bezierEllipse(pt.x, pt.y, width, height);
|
8800 | }
|
8801 | Canvas.fillCanvas(ctx, fillOpacity, pt.x - width, pt.y - height);
|
8802 | Canvas._stroke(ctx, lineOpacity, pt.x - width, pt.y - height);
|
8803 | },
|
8804 | rectangle: function rectangle(ctx, pt, size, lineOpacity, fillOpacity) {
|
8805 | ctx.beginPath();
|
8806 | ctx.rect(pt.x, pt.y, size['width'], size['height']);
|
8807 | Canvas.fillCanvas(ctx, fillOpacity, pt.x, pt.y);
|
8808 | Canvas._stroke(ctx, lineOpacity, pt.x, pt.y);
|
8809 | },
|
8810 | sector: function sector(ctx, pt, size, angles, lineOpacity, fillOpacity) {
|
8811 | var rad = Math.PI / 180;
|
8812 | var startAngle = angles[0],
|
8813 | endAngle = angles[1];
|
8814 |
|
8815 | function sector(ctx, x, y, radius, startAngle, endAngle) {
|
8816 | var sDeg = rad * -endAngle;
|
8817 | var eDeg = rad * -startAngle;
|
8818 | ctx.beginPath();
|
8819 | ctx.moveTo(x, y);
|
8820 | ctx.arc(x, y, radius, sDeg, eDeg);
|
8821 | ctx.lineTo(x, y);
|
8822 | Canvas.fillCanvas(ctx, fillOpacity, x - radius, y - radius);
|
8823 | Canvas._stroke(ctx, lineOpacity, x - radius, y - radius);
|
8824 | }
|
8825 | sector(ctx, pt.x, pt.y, size, startAngle, endAngle);
|
8826 | },
|
8827 | _isPattern: function _isPattern(style) {
|
8828 | return !isString(style) && !('addColorStop' in style);
|
8829 | },
|
8830 | drawCross: function drawCross(ctx, p, lineWidth, color) {
|
8831 | ctx.canvas._drawn = true;
|
8832 | ctx.strokeStyle = color;
|
8833 | ctx.lineWidth = lineWidth;
|
8834 | ctx.beginPath();
|
8835 | ctx.moveTo(p.x - 5, p.y);
|
8836 | ctx.lineTo(p.x + 5, p.y);
|
8837 | ctx.moveTo(p.x, p.y - 5);
|
8838 | ctx.lineTo(p.x, p.y + 5);
|
8839 | ctx.stroke();
|
8840 | },
|
8841 | copy: function copy(canvas, c) {
|
8842 | var target = c || createEl('canvas');
|
8843 | target.width = canvas.width;
|
8844 | target.height = canvas.height;
|
8845 | target.getContext('2d').drawImage(canvas, 0, 0);
|
8846 | return target;
|
8847 | }
|
8848 | };
|
8849 |
|
8850 | function drawDashLine(ctx, startPoint, endPoint, dashArray) {
|
8851 | var fromX = startPoint.x,
|
8852 | fromY = startPoint.y,
|
8853 | toX = endPoint.x,
|
8854 | toY = endPoint.y;
|
8855 | var pattern = dashArray;
|
8856 | var lt = function lt(a, b) {
|
8857 | return a <= b;
|
8858 | };
|
8859 | var gt = function gt(a, b) {
|
8860 | return a >= b;
|
8861 | };
|
8862 | var capmin = function capmin(a, b) {
|
8863 | return Math.min(a, b);
|
8864 | };
|
8865 | var capmax = function capmax(a, b) {
|
8866 | return Math.max(a, b);
|
8867 | };
|
8868 |
|
8869 | var checkX = {
|
8870 | thereYet: gt,
|
8871 | cap: capmin
|
8872 | };
|
8873 | var checkY = {
|
8874 | thereYet: gt,
|
8875 | cap: capmin
|
8876 | };
|
8877 |
|
8878 | if (fromY - toY > 0) {
|
8879 | checkY.thereYet = lt;
|
8880 | checkY.cap = capmax;
|
8881 | }
|
8882 | if (fromX - toX > 0) {
|
8883 | checkX.thereYet = lt;
|
8884 | checkX.cap = capmax;
|
8885 | }
|
8886 |
|
8887 | ctx.moveTo(fromX, fromY);
|
8888 | var offsetX = fromX;
|
8889 | var offsetY = fromY;
|
8890 | var idx = 0,
|
8891 | dash = true;
|
8892 | var ang = void 0,
|
8893 | len = void 0;
|
8894 | while (!(checkX.thereYet(offsetX, toX) && checkY.thereYet(offsetY, toY))) {
|
8895 | ang = Math.atan2(toY - fromY, toX - fromX);
|
8896 | len = pattern[idx];
|
8897 |
|
8898 | offsetX = checkX.cap(toX, offsetX + Math.cos(ang) * len);
|
8899 | offsetY = checkY.cap(toY, offsetY + Math.sin(ang) * len);
|
8900 |
|
8901 | if (dash) {
|
8902 | ctx.lineTo(offsetX, offsetY);
|
8903 | } else {
|
8904 | ctx.moveTo(offsetX, offsetY);
|
8905 | }
|
8906 |
|
8907 | idx = (idx + 1) % pattern.length;
|
8908 | dash = !dash;
|
8909 | }
|
8910 | }
|
8911 |
|
8912 | var prefix = 'data:image/';
|
8913 | function isImageUrl(url) {
|
8914 | return url.length > prefix.length && url.substring(0, prefix.length) === prefix || isCssUrl(url);
|
8915 | }
|
8916 |
|
8917 | function extractImageUrl(url) {
|
8918 | if (url.substring(0, prefix.length) === prefix) {
|
8919 | return url;
|
8920 | }
|
8921 | return extractCssUrl(url);
|
8922 | }
|
8923 |
|
8924 | var Eventable = function Eventable(Base) {
|
8925 | return function (_Base) {
|
8926 | inherits(_class, _Base);
|
8927 |
|
8928 | function _class() {
|
8929 | classCallCheck(this, _class);
|
8930 | return possibleConstructorReturn(this, _Base.apply(this, arguments));
|
8931 | }
|
8932 |
|
8933 | _class.prototype.on = function on$$1(eventsOn, handler, context) {
|
8934 | if (!eventsOn) {
|
8935 | return this;
|
8936 | }
|
8937 | if (!isString(eventsOn)) {
|
8938 | return this._switch('on', eventsOn, handler);
|
8939 | }
|
8940 | if (!handler) {
|
8941 | return this;
|
8942 | }
|
8943 | if (!this._eventMap) {
|
8944 | this._eventMap = {};
|
8945 | }
|
8946 | var eventTypes = eventsOn.toLowerCase().split(' ');
|
8947 | var evtType = void 0;
|
8948 | if (!context) {
|
8949 | context = this;
|
8950 | }
|
8951 | var handlerChain = void 0;
|
8952 | for (var ii = 0, ll = eventTypes.length; ii < ll; ii++) {
|
8953 | evtType = eventTypes[ii];
|
8954 | handlerChain = this._eventMap[evtType];
|
8955 | if (!handlerChain) {
|
8956 | handlerChain = [];
|
8957 | this._eventMap[evtType] = handlerChain;
|
8958 | }
|
8959 | var l = handlerChain.length;
|
8960 | if (l > 0) {
|
8961 | for (var i = 0; i < l; i++) {
|
8962 | if (handler === handlerChain[i].handler && handlerChain[i].context === context) {
|
8963 | return this;
|
8964 | }
|
8965 | }
|
8966 | }
|
8967 | handlerChain.push({
|
8968 | handler: handler,
|
8969 | context: context
|
8970 | });
|
8971 | }
|
8972 | return this;
|
8973 | };
|
8974 |
|
8975 | _class.prototype.addEventListener = function addEventListener() {
|
8976 | return this.on.apply(this, arguments);
|
8977 | };
|
8978 |
|
8979 | _class.prototype.once = function once(eventTypes, handler, context) {
|
8980 | if (!isString(eventTypes)) {
|
8981 | var once = {};
|
8982 | for (var p in eventTypes) {
|
8983 | if (eventTypes.hasOwnProperty(p)) {
|
8984 | once[p] = this._wrapOnceHandler(p, eventTypes[p], context);
|
8985 | }
|
8986 | }
|
8987 | return this._switch('on', once);
|
8988 | }
|
8989 | var evetTypes = eventTypes.split(' ');
|
8990 | for (var i = 0, l = evetTypes.length; i < l; i++) {
|
8991 | this.on(evetTypes[i], this._wrapOnceHandler(evetTypes[i], handler, context));
|
8992 | }
|
8993 | return this;
|
8994 | };
|
8995 |
|
8996 | _class.prototype.off = function off$$1(eventsOff, handler, context) {
|
8997 | if (!this._eventMap || !eventsOff) {
|
8998 | return this;
|
8999 | }
|
9000 | if (!isString(eventsOff)) {
|
9001 | return this._switch('off', eventsOff, handler);
|
9002 | }
|
9003 | if (!handler) {
|
9004 | return this;
|
9005 | }
|
9006 | var eventTypes = eventsOff.split(' ');
|
9007 | var eventType = void 0,
|
9008 | listeners = void 0,
|
9009 | wrapKey = void 0;
|
9010 | if (!context) {
|
9011 | context = this;
|
9012 | }
|
9013 | for (var j = 0, jl = eventTypes.length; j < jl; j++) {
|
9014 | eventType = eventTypes[j].toLowerCase();
|
9015 | wrapKey = 'Z__' + eventType;
|
9016 | listeners = this._eventMap[eventType];
|
9017 | if (!listeners) {
|
9018 | return this;
|
9019 | }
|
9020 | for (var i = listeners.length - 1; i >= 0; i--) {
|
9021 | var listener = listeners[i];
|
9022 | if ((handler === listener.handler || handler === listener.handler[wrapKey]) && listener.context === context) {
|
9023 | delete listener.handler[wrapKey];
|
9024 | listeners.splice(i, 1);
|
9025 | }
|
9026 | }
|
9027 | }
|
9028 | return this;
|
9029 | };
|
9030 |
|
9031 | _class.prototype.removeEventListener = function removeEventListener() {
|
9032 | return this.off.apply(this, arguments);
|
9033 | };
|
9034 |
|
9035 | _class.prototype.listens = function listens(eventType, handler, context) {
|
9036 | if (!this._eventMap || !isString(eventType)) {
|
9037 | return 0;
|
9038 | }
|
9039 | var handlerChain = this._eventMap[eventType.toLowerCase()];
|
9040 | if (!handlerChain || !handlerChain.length) {
|
9041 | return 0;
|
9042 | }
|
9043 | var count = 0;
|
9044 | for (var i = 0, len = handlerChain.length; i < len; i++) {
|
9045 | if (handler) {
|
9046 | if (handler === handlerChain[i].handler && (isNil(context) || handlerChain[i].context === context)) {
|
9047 | return 1;
|
9048 | }
|
9049 | } else {
|
9050 | count++;
|
9051 | }
|
9052 | }
|
9053 | return count;
|
9054 | };
|
9055 |
|
9056 | _class.prototype.copyEventListeners = function copyEventListeners(target) {
|
9057 | var eventMap = target._eventMap;
|
9058 | if (!eventMap) {
|
9059 | return this;
|
9060 | }
|
9061 | var handlerChain = void 0;
|
9062 | for (var eventType in eventMap) {
|
9063 | handlerChain = eventMap[eventType];
|
9064 | for (var i = 0, len = handlerChain.length; i < len; i++) {
|
9065 | this.on(eventType, handlerChain[i].handler, handlerChain[i].context);
|
9066 | }
|
9067 | }
|
9068 | return this;
|
9069 | };
|
9070 |
|
9071 | _class.prototype.fire = function fire() {
|
9072 | if (this._eventParent) {
|
9073 | return this._eventParent.fire.apply(this._eventParent, arguments);
|
9074 | }
|
9075 | return this._fire.apply(this, arguments);
|
9076 | };
|
9077 |
|
9078 | _class.prototype._wrapOnceHandler = function _wrapOnceHandler(evtType, handler, context) {
|
9079 | var me = this;
|
9080 | var key = 'Z__' + evtType;
|
9081 | var called = false;
|
9082 | var fn = function onceHandler() {
|
9083 | if (called) {
|
9084 | return;
|
9085 | }
|
9086 | delete fn[key];
|
9087 | called = true;
|
9088 | if (context) {
|
9089 | handler.apply(context, arguments);
|
9090 | } else {
|
9091 | handler.apply(this, arguments);
|
9092 | }
|
9093 | me.off(evtType, onceHandler, this);
|
9094 | };
|
9095 | fn[key] = handler;
|
9096 | return fn;
|
9097 | };
|
9098 |
|
9099 | _class.prototype._switch = function _switch(to, eventKeys, context) {
|
9100 | for (var p in eventKeys) {
|
9101 | if (eventKeys.hasOwnProperty(p)) {
|
9102 | this[to](p, eventKeys[p], context);
|
9103 | }
|
9104 | }
|
9105 | return this;
|
9106 | };
|
9107 |
|
9108 | _class.prototype._clearListeners = function _clearListeners(eventType) {
|
9109 | if (!this._eventMap || !isString(eventType)) {
|
9110 | return;
|
9111 | }
|
9112 | var handlerChain = this._eventMap[eventType.toLowerCase()];
|
9113 | if (!handlerChain) {
|
9114 | return;
|
9115 | }
|
9116 | this._eventMap[eventType] = null;
|
9117 | };
|
9118 |
|
9119 | _class.prototype._clearAllListeners = function _clearAllListeners() {
|
9120 | this._eventMap = null;
|
9121 | };
|
9122 |
|
9123 | _class.prototype._setEventParent = function _setEventParent(parent) {
|
9124 | this._eventParent = parent;
|
9125 | return this;
|
9126 | };
|
9127 |
|
9128 | _class.prototype._fire = function _fire(eventType, param) {
|
9129 | if (!this._eventMap) {
|
9130 | return this;
|
9131 | }
|
9132 | var handlerChain = this._eventMap[eventType.toLowerCase()];
|
9133 | if (!handlerChain) {
|
9134 | return this;
|
9135 | }
|
9136 | if (!param) {
|
9137 | param = {};
|
9138 | }
|
9139 | param['type'] = eventType;
|
9140 | param['target'] = this;
|
9141 |
|
9142 | var queue = handlerChain.slice(0);
|
9143 | var context = void 0,
|
9144 | bubble = void 0,
|
9145 | passed = void 0;
|
9146 | for (var i = 0, len = queue.length; i < len; i++) {
|
9147 | if (!queue[i]) {
|
9148 | continue;
|
9149 | }
|
9150 | context = queue[i].context;
|
9151 | bubble = true;
|
9152 | passed = extend({}, param);
|
9153 | if (context) {
|
9154 | bubble = queue[i].handler.call(context, passed);
|
9155 | } else {
|
9156 | bubble = queue[i].handler(passed);
|
9157 | }
|
9158 |
|
9159 | if (bubble === false) {
|
9160 | if (param['domEvent']) {
|
9161 | stopPropagation(param['domEvent']);
|
9162 | }
|
9163 | }
|
9164 | }
|
9165 | return this;
|
9166 | };
|
9167 |
|
9168 | return _class;
|
9169 | }(Base);
|
9170 | };
|
9171 |
|
9172 | var Handler = function () {
|
9173 | function Handler(target) {
|
9174 | classCallCheck(this, Handler);
|
9175 |
|
9176 | this.target = target;
|
9177 | }
|
9178 |
|
9179 | Handler.prototype.enable = function enable() {
|
9180 | if (this._enabled) {
|
9181 | return this;
|
9182 | }
|
9183 | this._enabled = true;
|
9184 | this.addHooks();
|
9185 | return this;
|
9186 | };
|
9187 |
|
9188 | Handler.prototype.disable = function disable() {
|
9189 | if (!this._enabled) {
|
9190 | return this;
|
9191 | }
|
9192 | this._enabled = false;
|
9193 | this.removeHooks();
|
9194 | return this;
|
9195 | };
|
9196 |
|
9197 | Handler.prototype.enabled = function enabled() {
|
9198 | return !!this._enabled;
|
9199 | };
|
9200 |
|
9201 | Handler.prototype.remove = function remove() {
|
9202 | this.disable();
|
9203 | delete this.target;
|
9204 | delete this.dom;
|
9205 | };
|
9206 |
|
9207 | return Handler;
|
9208 | }();
|
9209 |
|
9210 | var Handler$1 = Eventable(Handler);
|
9211 |
|
9212 | var Class = function () {
|
9213 | function Class(options) {
|
9214 | classCallCheck(this, Class);
|
9215 |
|
9216 | if (!this || !this.setOptions) {
|
9217 | throw new Error('Class instance is being created without "new" operator.');
|
9218 | }
|
9219 | this.setOptions(options);
|
9220 | this.callInitHooks();
|
9221 | }
|
9222 |
|
9223 | Class.prototype.callInitHooks = function callInitHooks() {
|
9224 | var proto = Object.getPrototypeOf(this);
|
9225 | this._visitInitHooks(proto);
|
9226 | return this;
|
9227 | };
|
9228 |
|
9229 | Class.prototype.setOptions = function setOptions(options) {
|
9230 | if (!this.hasOwnProperty('options')) {
|
9231 | this.options = this.options ? Object.create(this.options) : {};
|
9232 | }
|
9233 | if (!options) {
|
9234 | return this;
|
9235 | }
|
9236 | for (var i in options) {
|
9237 | this.options[i] = options[i];
|
9238 | }
|
9239 | return this;
|
9240 | };
|
9241 |
|
9242 | Class.prototype.config = function config(conf) {
|
9243 | if (!conf) {
|
9244 | var config = {};
|
9245 | for (var p in this.options) {
|
9246 | if (this.options.hasOwnProperty(p)) {
|
9247 | config[p] = this.options[p];
|
9248 | }
|
9249 | }
|
9250 | return config;
|
9251 | } else {
|
9252 | if (arguments.length === 2) {
|
9253 | var t = {};
|
9254 | t[conf] = arguments[1];
|
9255 | conf = t;
|
9256 | }
|
9257 | for (var i in conf) {
|
9258 | this.options[i] = conf[i];
|
9259 |
|
9260 | if (this[i] && this[i] instanceof Handler$1) {
|
9261 | if (conf[i]) {
|
9262 | this[i].enable();
|
9263 | } else {
|
9264 | this[i].disable();
|
9265 | }
|
9266 | }
|
9267 | }
|
9268 |
|
9269 | this.onConfig(conf);
|
9270 | }
|
9271 | return this;
|
9272 | };
|
9273 |
|
9274 | Class.prototype.onConfig = function onConfig() {};
|
9275 |
|
9276 | Class.prototype._visitInitHooks = function _visitInitHooks(proto) {
|
9277 | if (this._initHooksCalled) {
|
9278 | return;
|
9279 | }
|
9280 | var parentProto = Object.getPrototypeOf(proto);
|
9281 | if (parentProto._visitInitHooks) {
|
9282 | parentProto._visitInitHooks.call(this, parentProto);
|
9283 | }
|
9284 | this._initHooksCalled = true;
|
9285 | var hooks = proto._initHooks;
|
9286 | if (hooks && hooks !== parentProto._initHooks) {
|
9287 | for (var i = 0; i < hooks.length; i++) {
|
9288 | hooks[i].call(this);
|
9289 | }
|
9290 | }
|
9291 | };
|
9292 |
|
9293 | Class.addInitHook = function addInitHook(fn) {
|
9294 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
9295 | args[_key - 1] = arguments[_key];
|
9296 | }
|
9297 |
|
9298 | var init = typeof fn === 'function' ? fn : function () {
|
9299 | this[fn].apply(this, args);
|
9300 | };
|
9301 | var proto = this.prototype;
|
9302 | var parentProto = Object.getPrototypeOf(proto);
|
9303 | if (!proto._initHooks || proto._initHooks === parentProto._initHooks) {
|
9304 | proto._initHooks = [];
|
9305 | }
|
9306 | proto._initHooks.push(init);
|
9307 | return this;
|
9308 | };
|
9309 |
|
9310 | Class.include = function include() {
|
9311 | for (var _len2 = arguments.length, sources = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
9312 | sources[_key2] = arguments[_key2];
|
9313 | }
|
9314 |
|
9315 | for (var i = 0; i < sources.length; i++) {
|
9316 | extend(this.prototype, sources[i]);
|
9317 | }
|
9318 | return this;
|
9319 | };
|
9320 |
|
9321 | Class.mergeOptions = function mergeOptions(options) {
|
9322 | var proto = this.prototype;
|
9323 | var parentProto = Object.getPrototypeOf(proto);
|
9324 | if (!proto.options || proto.options === parentProto.options) {
|
9325 | proto.options = proto.options ? Object.create(proto.options) : {};
|
9326 | }
|
9327 | extend(proto.options, options);
|
9328 | return this;
|
9329 | };
|
9330 |
|
9331 | return Class;
|
9332 | }();
|
9333 |
|
9334 | var registeredTypes = {};
|
9335 |
|
9336 | var JSONAble = (function (Base) {
|
9337 | return function (_Base) {
|
9338 | inherits(_class, _Base);
|
9339 |
|
9340 | function _class() {
|
9341 | classCallCheck(this, _class);
|
9342 | return possibleConstructorReturn(this, _Base.apply(this, arguments));
|
9343 | }
|
9344 |
|
9345 | _class.registerJSONType = function registerJSONType(type) {
|
9346 | if (!type) {
|
9347 | return this;
|
9348 | }
|
9349 | registeredTypes[type] = this;
|
9350 | return this;
|
9351 | };
|
9352 |
|
9353 | _class.getJSONClass = function getJSONClass(type) {
|
9354 | if (!type) {
|
9355 | return null;
|
9356 | }
|
9357 | return registeredTypes[type];
|
9358 | };
|
9359 |
|
9360 | _class.prototype.getJSONType = function getJSONType() {
|
9361 | if (this._jsonType === undefined) {
|
9362 | var clazz = Object.getPrototypeOf(this).constructor;
|
9363 | for (var p in registeredTypes) {
|
9364 | if (registeredTypes[p] === clazz) {
|
9365 | this._jsonType = p;
|
9366 | break;
|
9367 | }
|
9368 | }
|
9369 | }
|
9370 | if (!this._jsonType) {
|
9371 | throw new Error('Found an unregistered geometry class!');
|
9372 | }
|
9373 | return this._jsonType;
|
9374 | };
|
9375 |
|
9376 | return _class;
|
9377 | }(Base);
|
9378 | });
|
9379 |
|
9380 | var Handlerable = function (Base) {
|
9381 | return function (_Base) {
|
9382 | inherits(_class, _Base);
|
9383 |
|
9384 | function _class() {
|
9385 | classCallCheck(this, _class);
|
9386 | return possibleConstructorReturn(this, _Base.apply(this, arguments));
|
9387 | }
|
9388 |
|
9389 | _class.prototype.addHandler = function addHandler(name, handlerClass) {
|
9390 | if (!handlerClass) {
|
9391 | return this;
|
9392 | }
|
9393 | if (!this._handlers) {
|
9394 | this._handlers = [];
|
9395 | }
|
9396 |
|
9397 | if (this[name]) {
|
9398 | this[name].enable();
|
9399 | return this;
|
9400 | }
|
9401 |
|
9402 | var handler = this[name] = new handlerClass(this);
|
9403 |
|
9404 | this._handlers.push(handler);
|
9405 |
|
9406 | if (this.options[name]) {
|
9407 | handler.enable();
|
9408 | }
|
9409 | return this;
|
9410 | };
|
9411 |
|
9412 | _class.prototype.removeHandler = function removeHandler(name) {
|
9413 | if (!name) {
|
9414 | return this;
|
9415 | }
|
9416 | var handler = this[name];
|
9417 | if (handler) {
|
9418 | var hit = this._handlers.indexOf(handler);
|
9419 | if (hit >= 0) {
|
9420 | this._handlers.splice(hit, 1);
|
9421 | }
|
9422 | this[name].remove();
|
9423 | delete this[name];
|
9424 | }
|
9425 | return this;
|
9426 | };
|
9427 |
|
9428 | _class.prototype._clearHandlers = function _clearHandlers() {
|
9429 | for (var i = 0, len = this._handlers.length; i < len; i++) {
|
9430 | this._handlers[i].remove();
|
9431 | }
|
9432 | this._handlers = [];
|
9433 | };
|
9434 |
|
9435 | return _class;
|
9436 | }(Base);
|
9437 | };
|
9438 |
|
9439 | var START_EVENTS = 'touchstart mousedown';
|
9440 | var MOVE_EVENTS = {
|
9441 | mousedown: 'mousemove',
|
9442 | touchstart: 'touchmove',
|
9443 | pointerdown: 'touchmove',
|
9444 | MSPointerDown: 'touchmove'
|
9445 | };
|
9446 | var END_EVENTS = {
|
9447 | mousedown: 'mouseup',
|
9448 | touchstart: 'touchend',
|
9449 | pointerdown: 'touchend',
|
9450 | MSPointerDown: 'touchend'
|
9451 | };
|
9452 |
|
9453 | var DragHandler = function (_Handler) {
|
9454 | inherits(DragHandler, _Handler);
|
9455 |
|
9456 | function DragHandler(dom) {
|
9457 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
9458 | classCallCheck(this, DragHandler);
|
9459 |
|
9460 | var _this = possibleConstructorReturn(this, _Handler.call(this, null));
|
9461 |
|
9462 | _this.dom = dom;
|
9463 | _this.options = options;
|
9464 | return _this;
|
9465 | }
|
9466 |
|
9467 | DragHandler.prototype.enable = function enable() {
|
9468 | if (!this.dom) {
|
9469 | return this;
|
9470 | }
|
9471 |
|
9472 | this._onMouseDown = function (e) {
|
9473 | return this.onMouseDown(e);
|
9474 | };
|
9475 | on(this.dom, START_EVENTS, this._onMouseDown, this);
|
9476 | return this;
|
9477 | };
|
9478 |
|
9479 | DragHandler.prototype.disable = function disable() {
|
9480 | if (!this.dom) {
|
9481 | return this;
|
9482 | }
|
9483 | this._offEvents();
|
9484 | off(this.dom, START_EVENTS, this._onMouseDown);
|
9485 | delete this._onMouseDown;
|
9486 | return this;
|
9487 | };
|
9488 |
|
9489 | DragHandler.prototype.onMouseDown = function onMouseDown(event) {
|
9490 | if (!this.options['rightclick'] && event.button === 2) {
|
9491 | return;
|
9492 | }
|
9493 | if (event.touches && event.touches.length > 1) {
|
9494 | return;
|
9495 | }
|
9496 | if (this.options['cancelOn'] && this.options['cancelOn'](event) === true) {
|
9497 | return;
|
9498 | }
|
9499 | var dom = this.dom;
|
9500 | if (dom.setCapture) {
|
9501 | dom.setCapture();
|
9502 | } else if (window.captureEvents) {
|
9503 | window.captureEvents(window['Event'].MOUSEMOVE | window['Event'].MOUSEUP);
|
9504 | }
|
9505 | dom['ondragstart'] = function () {
|
9506 | return false;
|
9507 | };
|
9508 | delete this.moved;
|
9509 | var actual = event.touches ? event.touches[0] : event;
|
9510 | this.startPos = new Point(actual.clientX, actual.clientY);
|
9511 | on(document, MOVE_EVENTS[event.type], this.onMouseMove, this);
|
9512 | on(document, END_EVENTS[event.type], this.onMouseUp, this);
|
9513 | if (!this.options['ignoreMouseleave']) {
|
9514 | on(this.dom, 'mouseleave', this.onMouseUp, this);
|
9515 | }
|
9516 | this.fire('mousedown', {
|
9517 | 'domEvent': event,
|
9518 | 'mousePos': new Point(actual.clientX, actual.clientY)
|
9519 | });
|
9520 | };
|
9521 |
|
9522 | DragHandler.prototype.onMouseMove = function onMouseMove(event) {
|
9523 | if (event.touches && event.touches.length > 1) {
|
9524 | if (this.moved) {
|
9525 | this.interupted = true;
|
9526 | this.onMouseUp(event);
|
9527 | }
|
9528 | return;
|
9529 | }
|
9530 | var actual = event.touches ? event.touches[0] : event;
|
9531 |
|
9532 | var newPos = new Point(actual.clientX, actual.clientY),
|
9533 | offset = newPos.sub(this.startPos);
|
9534 | if (!offset.x && !offset.y) {
|
9535 | return;
|
9536 | }
|
9537 | if (!this.moved) {
|
9538 | this.fire('dragstart', {
|
9539 | 'domEvent': event,
|
9540 | 'mousePos': this.startPos.copy()
|
9541 | });
|
9542 | this.moved = true;
|
9543 | } else {
|
9544 | this.fire('dragging', {
|
9545 | 'domEvent': event,
|
9546 | 'mousePos': new Point(actual.clientX, actual.clientY)
|
9547 | });
|
9548 | }
|
9549 | };
|
9550 |
|
9551 | DragHandler.prototype.onMouseUp = function onMouseUp(event) {
|
9552 | var actual = event.changedTouches ? event.changedTouches[0] : event;
|
9553 | this._offEvents();
|
9554 | var param = {
|
9555 | 'domEvent': event
|
9556 | };
|
9557 | if (isNumber(actual.clientX)) {
|
9558 | param['mousePos'] = new Point(parseInt(actual.clientX, 0), parseInt(actual.clientY, 0));
|
9559 | }
|
9560 | if (this.moved) {
|
9561 | param.interupted = this.interupted;
|
9562 | this.fire('dragend', param);
|
9563 | delete this.interupted;
|
9564 | delete this.moved;
|
9565 | }
|
9566 |
|
9567 | this.fire('mouseup', param);
|
9568 | };
|
9569 |
|
9570 | DragHandler.prototype._offEvents = function _offEvents() {
|
9571 | var dom = this.dom;
|
9572 | off(dom, 'mouseleave', this.onMouseUp, this);
|
9573 | if (typeof document === 'undefined' || typeof window === 'undefined') {
|
9574 | return;
|
9575 | }
|
9576 | for (var i in MOVE_EVENTS) {
|
9577 | off(document, MOVE_EVENTS[i], this.onMouseMove, this);
|
9578 | off(document, END_EVENTS[i], this.onMouseUp, this);
|
9579 | }
|
9580 |
|
9581 | if (dom['releaseCapture']) {
|
9582 | dom['releaseCapture']();
|
9583 | } else if (window.captureEvents) {
|
9584 | window.captureEvents(window['Event'].MOUSEMOVE | window['Event'].MOUSEUP);
|
9585 | }
|
9586 | };
|
9587 |
|
9588 | return DragHandler;
|
9589 | }(Handler$1);
|
9590 |
|
9591 | var Coordinate = function (_Position) {
|
9592 | inherits(Coordinate, _Position);
|
9593 |
|
9594 | function Coordinate() {
|
9595 | classCallCheck(this, Coordinate);
|
9596 | return possibleConstructorReturn(this, _Position.apply(this, arguments));
|
9597 | }
|
9598 |
|
9599 | Coordinate.toNumberArrays = function toNumberArrays(coordinates) {
|
9600 | if (!Array.isArray(coordinates)) {
|
9601 | return [coordinates.x, coordinates.y];
|
9602 | }
|
9603 | return forEachCoord(coordinates, function (coord) {
|
9604 | return [coord.x, coord.y];
|
9605 | });
|
9606 | };
|
9607 |
|
9608 | Coordinate.toCoordinates = function toCoordinates(coordinates) {
|
9609 | if (isNumber(coordinates[0]) && isNumber(coordinates[1])) {
|
9610 | return new Coordinate(coordinates);
|
9611 | }
|
9612 | var result = [];
|
9613 | for (var i = 0, len = coordinates.length; i < len; i++) {
|
9614 | var child = coordinates[i];
|
9615 | if (Array.isArray(child)) {
|
9616 | if (isNumber(child[0])) {
|
9617 | result.push(new Coordinate(child));
|
9618 | } else {
|
9619 | result.push(Coordinate.toCoordinates(child));
|
9620 | }
|
9621 | } else {
|
9622 | result.push(new Coordinate(child));
|
9623 | }
|
9624 | }
|
9625 | return result;
|
9626 | };
|
9627 |
|
9628 | return Coordinate;
|
9629 | }(Position);
|
9630 |
|
9631 | var CRS = function () {
|
9632 | function CRS(type, properties) {
|
9633 | classCallCheck(this, CRS);
|
9634 |
|
9635 | this.type = type;
|
9636 | this.properties = properties;
|
9637 | }
|
9638 |
|
9639 | CRS.createProj4 = function createProj4(proj) {
|
9640 | return new CRS('proj4', {
|
9641 | 'proj': proj
|
9642 | });
|
9643 | };
|
9644 |
|
9645 | CRS.fromProjectionCode = function fromProjectionCode(code) {
|
9646 | if (!code) {
|
9647 | return null;
|
9648 | }
|
9649 | code = code.toUpperCase().replace(':', '');
|
9650 | return CRS[code] || null;
|
9651 | };
|
9652 |
|
9653 | return CRS;
|
9654 | }();
|
9655 |
|
9656 | CRS.WGS84 = CRS.createProj4('+proj=longlat +datum=WGS84 +no_defs');
|
9657 |
|
9658 | CRS.EPSG4326 = CRS.WGS84;
|
9659 |
|
9660 | CRS.EPSG3857 = CRS.createProj4('+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs');
|
9661 |
|
9662 | CRS.IDENTITY = CRS.createProj4('+proj=identity +no_defs');
|
9663 |
|
9664 | CRS.CGCS2000 = CRS.createProj4('+proj=longlat +datum=CGCS2000');
|
9665 |
|
9666 | CRS.EPSG4490 = CRS.CGCS2000;
|
9667 |
|
9668 | CRS.BD09LL = CRS.createProj4('+proj=longlat +datum=BD09');
|
9669 |
|
9670 | CRS.GCJ02 = CRS.createProj4('+proj=longlat +datum=GCJ02');
|
9671 |
|
9672 | var Extent = function () {
|
9673 | function Extent(p1, p2, p3, p4) {
|
9674 | classCallCheck(this, Extent);
|
9675 |
|
9676 | this._clazz = Coordinate;
|
9677 | var l = arguments.length;
|
9678 | var proj = l > 0 ? arguments[l - 1] : null;
|
9679 | if (proj && proj.unproject) {
|
9680 | this.projection = arguments[l - 1];
|
9681 | }
|
9682 | this._dirty = true;
|
9683 | this._initialize(p1, p2, p3, p4);
|
9684 | }
|
9685 |
|
9686 | Extent.prototype._initialize = function _initialize(p1, p2, p3, p4) {
|
9687 | this.xmin = null;
|
9688 |
|
9689 | this.xmax = null;
|
9690 |
|
9691 | this.ymin = null;
|
9692 |
|
9693 | this.ymax = null;
|
9694 | if (isNil(p1)) {
|
9695 | return;
|
9696 | }
|
9697 | var projection = this.projection;
|
9698 |
|
9699 | if (isNumber(p1) && isNumber(p2) && isNumber(p3) && isNumber(p4)) {
|
9700 | if (projection) {
|
9701 | this['xmin'] = p1;
|
9702 | this['ymin'] = p2;
|
9703 | this['xmax'] = p3;
|
9704 | this['ymax'] = p4;
|
9705 | } else {
|
9706 | this['xmin'] = Math.min(p1, p3);
|
9707 | this['ymin'] = Math.min(p2, p4);
|
9708 | this['xmax'] = Math.max(p1, p3);
|
9709 | this['ymax'] = Math.max(p2, p4);
|
9710 | }
|
9711 | return;
|
9712 | } else if (Array.isArray(p1)) {
|
9713 | if (projection) {
|
9714 | this['xmin'] = p1[0];
|
9715 | this['ymin'] = p1[1];
|
9716 | this['xmax'] = p1[2];
|
9717 | this['ymax'] = p1[3];
|
9718 | } else {
|
9719 | this['xmin'] = Math.min(p1[0], p1[2]);
|
9720 | this['ymin'] = Math.min(p1[1], p1[3]);
|
9721 | this['xmax'] = Math.max(p1[0], p1[2]);
|
9722 | this['ymax'] = Math.max(p1[1], p1[3]);
|
9723 | }
|
9724 | } else if (isNumber(p1.x) && isNumber(p2.x) && isNumber(p1.y) && isNumber(p2.y)) {
|
9725 | if (projection) {
|
9726 | this['xmin'] = p1.x;
|
9727 | this['ymin'] = p1.y;
|
9728 | this['xmax'] = p2.x;
|
9729 | this['ymax'] = p2.y;
|
9730 | } else {
|
9731 | if (p1.x > p2.x) {
|
9732 | this['xmin'] = p2.x;
|
9733 | this['xmax'] = p1.x;
|
9734 | } else {
|
9735 | this['xmin'] = p1.x;
|
9736 | this['xmax'] = p2.x;
|
9737 | }
|
9738 | if (p1.y > p2.y) {
|
9739 | this['ymin'] = p2.y;
|
9740 | this['ymax'] = p1.y;
|
9741 | } else {
|
9742 | this['ymin'] = p1.y;
|
9743 | this['ymax'] = p2.y;
|
9744 | }
|
9745 | }
|
9746 | } else if (isNumber(p1['xmin']) && isNumber(p1['xmax']) && isNumber(p1['ymin']) && isNumber(p1['ymax'])) {
|
9747 | this['xmin'] = p1['xmin'];
|
9748 | this['ymin'] = p1['ymin'];
|
9749 | this['xmax'] = p1['xmax'];
|
9750 | this['ymax'] = p1['ymax'];
|
9751 | }
|
9752 | };
|
9753 |
|
9754 | Extent.prototype._add = function _add(p) {
|
9755 | this._dirty = true;
|
9756 | if (!isNil(p.x)) {
|
9757 | this['xmin'] += p.x;
|
9758 | this['ymin'] += p.y;
|
9759 | this['xmax'] += p.x;
|
9760 | this['ymax'] += p.y;
|
9761 | } else if (!isNil(p.xmin)) {
|
9762 | this['xmin'] += p.xmin;
|
9763 | this['ymin'] += p.ymin;
|
9764 | this['xmax'] += p.xmax;
|
9765 | this['ymax'] += p.ymax;
|
9766 | } else if (!isNil(p[0])) {
|
9767 | this['xmin'] += p[0];
|
9768 | this['ymin'] += p[1];
|
9769 | this['xmax'] += p[0];
|
9770 | this['ymax'] += p[1];
|
9771 | }
|
9772 | return this;
|
9773 | };
|
9774 |
|
9775 | Extent.prototype.add = function add() {
|
9776 | var e = new this.constructor(this['xmin'], this['ymin'], this['xmax'], this['ymax'], this.projection);
|
9777 | return e._add.apply(e, arguments);
|
9778 | };
|
9779 |
|
9780 | Extent.prototype._sub = function _sub(p) {
|
9781 | this._dirty = true;
|
9782 | if (!isNil(p.x)) {
|
9783 | this['xmin'] -= p.x;
|
9784 | this['ymin'] -= p.y;
|
9785 | this['xmax'] -= p.x;
|
9786 | this['ymax'] -= p.y;
|
9787 | } else if (!isNil(p.xmin)) {
|
9788 | this['xmin'] -= p.xmin;
|
9789 | this['ymin'] -= p.ymin;
|
9790 | this['xmax'] -= p.xmax;
|
9791 | this['ymax'] -= p.ymax;
|
9792 | } else if (!isNil(p[0])) {
|
9793 | this['xmin'] -= p[0];
|
9794 | this['ymin'] -= p[1];
|
9795 | this['xmax'] -= p[0];
|
9796 | this['ymax'] -= p[1];
|
9797 | }
|
9798 | return this;
|
9799 | };
|
9800 |
|
9801 | Extent.prototype._substract = function _substract() {
|
9802 | return this._sub.apply(this, arguments);
|
9803 | };
|
9804 |
|
9805 | Extent.prototype.sub = function sub() {
|
9806 | var e = new this.constructor(this['xmin'], this['ymin'], this['xmax'], this['ymax'], this.projection);
|
9807 | return e._sub.apply(e, arguments);
|
9808 | };
|
9809 |
|
9810 | Extent.prototype.substract = function substract() {
|
9811 | return this.sub.apply(this, arguments);
|
9812 | };
|
9813 |
|
9814 | Extent.prototype.round = function round() {
|
9815 | return new this.constructor(Math.round(this['xmin']), Math.round(this['ymin']), Math.round(this['xmax']), Math.round(this['ymax']), this.projection);
|
9816 | };
|
9817 |
|
9818 | Extent.prototype._round = function _round() {
|
9819 | this._dirty = true;
|
9820 | this['xmin'] = Math.round(this['xmin']);
|
9821 | this['ymin'] = Math.round(this['ymin']);
|
9822 | this['xmax'] = Math.round(this['xmax']);
|
9823 | this['ymax'] = Math.round(this['ymax']);
|
9824 | return this;
|
9825 | };
|
9826 |
|
9827 | Extent.prototype.getMin = function getMin() {
|
9828 | return new this._clazz(this['xmin'], this['ymin']);
|
9829 | };
|
9830 |
|
9831 | Extent.prototype.getMax = function getMax() {
|
9832 | return new this._clazz(this['xmax'], this['ymax']);
|
9833 | };
|
9834 |
|
9835 | Extent.prototype.getCenter = function getCenter() {
|
9836 | return new this._clazz((this['xmin'] + this['xmax']) / 2, (this['ymin'] + this['ymax']) / 2);
|
9837 | };
|
9838 |
|
9839 | Extent.prototype.isValid = function isValid() {
|
9840 | return isNumber(this['xmin']) && isNumber(this['ymin']) && isNumber(this['xmax']) && isNumber(this['ymax']);
|
9841 | };
|
9842 |
|
9843 | Extent.prototype.equals = function equals(ext2) {
|
9844 | return this['xmin'] === ext2['xmin'] && this['xmax'] === ext2['xmax'] && this['ymin'] === ext2['ymin'] && this['ymax'] === ext2['ymax'];
|
9845 | };
|
9846 |
|
9847 | Extent.prototype.intersects = function intersects(ext2) {
|
9848 | this._project(this);
|
9849 | this._project(ext2);
|
9850 | var rxmin = Math.max(this['pxmin'], ext2['pxmin']);
|
9851 | var rymin = Math.max(this['pymin'], ext2['pymin']);
|
9852 | var rxmax = Math.min(this['pxmax'], ext2['pxmax']);
|
9853 | var rymax = Math.min(this['pymax'], ext2['pymax']);
|
9854 | var intersects = !(rxmin > rxmax || rymin > rymax);
|
9855 | return intersects;
|
9856 | };
|
9857 |
|
9858 | Extent.prototype.within = function within(extent) {
|
9859 | this._project(this);
|
9860 | this._project(extent);
|
9861 | return this.pxmin >= extent.pxmin && this.pxmax <= extent.pxmax && this.pymin >= extent.pymin && this.pymax <= extent.pymax;
|
9862 | };
|
9863 |
|
9864 | Extent.prototype.contains = function contains(c) {
|
9865 | if (!c) {
|
9866 | return false;
|
9867 | }
|
9868 | this._project(this);
|
9869 | var proj = this.projection;
|
9870 | if (Array.isArray(c)) {
|
9871 | c = new this._clazz(c);
|
9872 | }
|
9873 | if (proj) {
|
9874 | c = proj.project(c);
|
9875 | }
|
9876 | return c.x >= this.pxmin && c.x <= this.pxmax && c.y >= this.pymin && c.y <= this.pymax;
|
9877 | };
|
9878 |
|
9879 | Extent.prototype.getWidth = function getWidth() {
|
9880 | return Math.abs(this['xmax'] - this['xmin']);
|
9881 | };
|
9882 |
|
9883 | Extent.prototype.getHeight = function getHeight() {
|
9884 | return Math.abs(this['ymax'] - this['ymin']);
|
9885 | };
|
9886 |
|
9887 | Extent.prototype.getSize = function getSize() {
|
9888 | return new Size(this.getWidth(), this.getHeight());
|
9889 | };
|
9890 |
|
9891 | Extent.prototype.__combine = function __combine(extent) {
|
9892 | if (!(extent instanceof this.constructor)) {
|
9893 | extent = new this.constructor(extent, extent);
|
9894 | }
|
9895 | this._project(extent);
|
9896 | this._project(this);
|
9897 | var xmin = this['pxmin'];
|
9898 | if (!isNumber(xmin)) {
|
9899 | xmin = extent['pxmin'];
|
9900 | } else if (isNumber(extent['pxmin'])) {
|
9901 | if (xmin > extent['pxmin']) {
|
9902 | xmin = extent['pxmin'];
|
9903 | }
|
9904 | }
|
9905 |
|
9906 | var xmax = this['pxmax'];
|
9907 | if (!isNumber(xmax)) {
|
9908 | xmax = extent['pxmax'];
|
9909 | } else if (isNumber(extent['pxmax'])) {
|
9910 | if (xmax < extent['pxmax']) {
|
9911 | xmax = extent['pxmax'];
|
9912 | }
|
9913 | }
|
9914 |
|
9915 | var ymin = this['pymin'];
|
9916 | if (!isNumber(ymin)) {
|
9917 | ymin = extent['pymin'];
|
9918 | } else if (isNumber(extent['pymin'])) {
|
9919 | if (ymin > extent['pymin']) {
|
9920 | ymin = extent['pymin'];
|
9921 | }
|
9922 | }
|
9923 |
|
9924 | var ymax = this['pymax'];
|
9925 | if (!isNumber(ymax)) {
|
9926 | ymax = extent['pymax'];
|
9927 | } else if (isNumber(extent['pymax'])) {
|
9928 | if (ymax < extent['pymax']) {
|
9929 | ymax = extent['pymax'];
|
9930 | }
|
9931 | }
|
9932 | var proj = this.projection;
|
9933 | if (proj) {
|
9934 | var min = proj.unproject(new this._clazz(xmin, ymin)),
|
9935 | max = proj.unproject(new this._clazz(xmax, ymax));
|
9936 | xmin = min.x;
|
9937 | ymin = min.y;
|
9938 | xmax = max.x;
|
9939 | ymax = max.y;
|
9940 | }
|
9941 | return [xmin, ymin, xmax, ymax];
|
9942 | };
|
9943 |
|
9944 | Extent.prototype._combine = function _combine(extent) {
|
9945 | if (!extent) {
|
9946 | return this;
|
9947 | }
|
9948 | var ext = this.__combine(extent);
|
9949 | this['xmin'] = ext[0];
|
9950 | this['ymin'] = ext[1];
|
9951 | this['xmax'] = ext[2];
|
9952 | this['ymax'] = ext[3];
|
9953 | this._dirty = true;
|
9954 | return this;
|
9955 | };
|
9956 |
|
9957 | Extent.prototype.combine = function combine(extent) {
|
9958 | if (!extent) {
|
9959 | return this;
|
9960 | }
|
9961 | var ext = this.__combine(extent);
|
9962 | return new this.constructor(ext[0], ext[1], ext[2], ext[3], this.projection);
|
9963 | };
|
9964 |
|
9965 | Extent.prototype.intersection = function intersection(extent) {
|
9966 | if (!this.intersects(extent)) {
|
9967 | return null;
|
9968 | }
|
9969 | var min = new this._clazz(Math.max(this['pxmin'], extent['pxmin']), Math.max(this['pymin'], extent['pymin'])),
|
9970 | max = new this._clazz(Math.min(this['pxmax'], extent['pxmax']), Math.min(this['pymax'], extent['pymax']));
|
9971 | var proj = this.projection;
|
9972 | if (proj) {
|
9973 | min = proj.unproject(min);
|
9974 | max = proj.unproject(max);
|
9975 | }
|
9976 | return new this.constructor(min, max, proj);
|
9977 | };
|
9978 |
|
9979 | Extent.prototype.expand = function expand(distance) {
|
9980 | var w = void 0,
|
9981 | h = void 0;
|
9982 | if (!isNumber(distance)) {
|
9983 | w = distance['width'] || distance['x'] || distance[0] || 0;
|
9984 | h = distance['height'] || distance['y'] || distance[1] || 0;
|
9985 | } else {
|
9986 | w = h = distance;
|
9987 | }
|
9988 | return new this.constructor(this['xmin'] - w, this['ymin'] - h, this['xmax'] + w, this['ymax'] + h, this.projection);
|
9989 | };
|
9990 |
|
9991 | Extent.prototype._expand = function _expand(distance) {
|
9992 | var w = void 0,
|
9993 | h = void 0;
|
9994 | if (!isNumber(distance)) {
|
9995 | w = distance['width'] || distance['x'] || distance[0] || 0;
|
9996 | h = distance['height'] || distance['y'] || distance[1] || 0;
|
9997 | } else {
|
9998 | w = h = distance;
|
9999 | }
|
10000 | this['xmin'] -= w;
|
10001 | this['ymin'] -= h;
|
10002 | this['xmax'] += w;
|
10003 | this['ymax'] += h;
|
10004 | this._dirty = true;
|
10005 | return this;
|
10006 | };
|
10007 |
|
10008 | Extent.prototype.toJSON = function toJSON() {
|
10009 | return {
|
10010 | 'xmin': this['xmin'],
|
10011 | 'ymin': this['ymin'],
|
10012 | 'xmax': this['xmax'],
|
10013 | 'ymax': this['ymax']
|
10014 | };
|
10015 | };
|
10016 |
|
10017 | Extent.prototype.toArray = function toArray$$1() {
|
10018 | var xmin = this['xmin'],
|
10019 | ymin = this['ymin'],
|
10020 | xmax = this['xmax'],
|
10021 | ymax = this['ymax'];
|
10022 | return [new this._clazz([xmin, ymax]), new this._clazz([xmax, ymax]), new this._clazz([xmax, ymin]), new this._clazz([xmin, ymin]), new this._clazz([xmin, ymax])];
|
10023 | };
|
10024 |
|
10025 | Extent.prototype.toString = function toString() {
|
10026 | return this.xmin + ',' + this.ymin + ',' + this.xmax + ',' + this.ymax;
|
10027 | };
|
10028 |
|
10029 | Extent.prototype.copy = function copy() {
|
10030 | return new this.constructor(this['xmin'], this['ymin'], this['xmax'], this['ymax'], this.projection);
|
10031 | };
|
10032 |
|
10033 | Extent.prototype.convertTo = function convertTo(fn) {
|
10034 | if (!this.isValid()) {
|
10035 | return null;
|
10036 | }
|
10037 | var e = new this.constructor();
|
10038 | var coord = new this._clazz(this.xmin, this.ymax);
|
10039 | e._combine(fn(coord));
|
10040 | coord.x = this.xmax;
|
10041 | e._combine(fn(coord));
|
10042 | coord.y = this.ymin;
|
10043 | e._combine(fn(coord));
|
10044 | coord.x = this.xmin;
|
10045 | e._combine(fn(coord));
|
10046 | return e;
|
10047 | };
|
10048 |
|
10049 | Extent.prototype._project = function _project(ext) {
|
10050 | if (!ext || !ext.isValid()) {
|
10051 | return;
|
10052 | }
|
10053 | var proj = this.projection;
|
10054 | if (proj) {
|
10055 | if (ext._dirty) {
|
10056 | var minmax = [ext.getMin(), ext.getMax()];
|
10057 | minmax = proj.projectCoords(minmax);
|
10058 | var min = minmax[0],
|
10059 | max = minmax[1];
|
10060 | ext.pxmin = Math.min(min.x, max.x);
|
10061 | ext.pymin = Math.min(min.y, max.y);
|
10062 | ext.pxmax = Math.max(min.x, max.x);
|
10063 | ext.pymax = Math.max(min.y, max.y);
|
10064 | }
|
10065 | delete ext._dirty;
|
10066 | } else {
|
10067 | ext.pxmin = ext.xmin;
|
10068 | ext.pxmax = ext.xmax;
|
10069 | ext.pymin = ext.ymin;
|
10070 | ext.pymax = ext.ymax;
|
10071 | }
|
10072 | };
|
10073 |
|
10074 | return Extent;
|
10075 | }();
|
10076 |
|
10077 | var PointExtent = function (_Extent) {
|
10078 | inherits(PointExtent, _Extent);
|
10079 |
|
10080 | function PointExtent(p1, p2, p3, p4) {
|
10081 | classCallCheck(this, PointExtent);
|
10082 |
|
10083 | var _this = possibleConstructorReturn(this, _Extent.call(this, p1, p2, p3, p4));
|
10084 |
|
10085 | _this._clazz = Point;
|
10086 | return _this;
|
10087 | }
|
10088 |
|
10089 | return PointExtent;
|
10090 | }(Extent);
|
10091 |
|
10092 | var Transformation = function () {
|
10093 | function Transformation(matrix) {
|
10094 | classCallCheck(this, Transformation);
|
10095 |
|
10096 | this.matrix = matrix;
|
10097 | }
|
10098 |
|
10099 | Transformation.prototype.transform = function transform(coordinates, scale) {
|
10100 | return new Point(this.matrix[0] * (coordinates.x - this.matrix[2]) / scale, this.matrix[1] * (coordinates.y - this.matrix[3]) / scale);
|
10101 | };
|
10102 |
|
10103 | Transformation.prototype.untransform = function untransform(point, scale) {
|
10104 | return new Coordinate(point.x * scale / this.matrix[0] + this.matrix[2], point.y * scale / this.matrix[1] + this.matrix[3]);
|
10105 | };
|
10106 |
|
10107 | return Transformation;
|
10108 | }();
|
10109 |
|
10110 | var Common = {
|
10111 | project: function project() {},
|
10112 | unproject: function unproject() {},
|
10113 | projectCoords: function projectCoords(coordinates) {
|
10114 | var _this = this;
|
10115 |
|
10116 | if (!coordinates) {
|
10117 | return [];
|
10118 | }
|
10119 | if (!Array.isArray(coordinates)) {
|
10120 | return this.project(coordinates);
|
10121 | }
|
10122 | if (coordinates.length === 0) {
|
10123 | return [];
|
10124 | }
|
10125 | if (!this.isSphere()) {
|
10126 | return forEachCoord(coordinates, this.project, this);
|
10127 | }
|
10128 | if (Array.isArray(coordinates[0])) {
|
10129 | return coordinates.map(function (coords) {
|
10130 | return _this.projectCoords(coords);
|
10131 | });
|
10132 | } else {
|
10133 | var circum = this.getCircum();
|
10134 | var extent = this.getSphereExtent(),
|
10135 | sx = extent.sx,
|
10136 | sy = extent.sy;
|
10137 | var wrapX = void 0,
|
10138 | wrapY = void 0;
|
10139 | var pre = coordinates[0],
|
10140 | current = void 0,
|
10141 | dx = void 0,
|
10142 | dy = void 0,
|
10143 | p = void 0;
|
10144 | var prj = [this.project(pre)];
|
10145 | for (var i = 1, l = coordinates.length; i < l; i++) {
|
10146 | current = coordinates[i];
|
10147 | dx = current.x - pre.x;
|
10148 | dy = current.y - pre.y;
|
10149 | p = this.project(current);
|
10150 | if (Math.abs(dx) > 180) {
|
10151 | if (wrapX === undefined) {
|
10152 | wrapX = current.x < pre.x;
|
10153 | }
|
10154 | if (wrapX) {
|
10155 | p._add(-circum.x * sign(dx) * sx, 0);
|
10156 | current._add(-360 * sign(dx), 0);
|
10157 | }
|
10158 | }
|
10159 | if (Math.abs(dy) > 90) {
|
10160 | if (wrapY === undefined) {
|
10161 | wrapY = current.y < pre.y;
|
10162 | }
|
10163 | if (wrapY) {
|
10164 | p._add(0, -circum.y * sign(dy) * sy);
|
10165 | current._add(0, -180 * sign(dy));
|
10166 | }
|
10167 | }
|
10168 | pre = current;
|
10169 | prj.push(p);
|
10170 | }
|
10171 | return prj;
|
10172 | }
|
10173 | },
|
10174 | unprojectCoords: function unprojectCoords(projCoords) {
|
10175 | if (!projCoords) {
|
10176 | return [];
|
10177 | }
|
10178 | if (!Array.isArray(projCoords)) {
|
10179 | return this.unproject(projCoords);
|
10180 | }
|
10181 | return forEachCoord(projCoords, this.unproject, this);
|
10182 | },
|
10183 | isSphere: function isSphere() {
|
10184 | return !!this.sphere;
|
10185 | },
|
10186 | isOutSphere: function isOutSphere(pcoord) {
|
10187 | if (!this.isSphere()) {
|
10188 | return false;
|
10189 | }
|
10190 | var extent = this.getSphereExtent();
|
10191 | return !extent.contains(pcoord);
|
10192 | },
|
10193 | wrapCoord: function wrapCoord(pcoord) {
|
10194 | if (!this.isSphere()) {
|
10195 | return pcoord;
|
10196 | }
|
10197 | var extent = this.getSphereExtent();
|
10198 | var wrapped = new Coordinate(pcoord);
|
10199 | if (!extent.contains(wrapped)) {
|
10200 | wrapped.x = wrap(pcoord.x, extent.xmin, extent.xmax);
|
10201 | wrapped.y = wrap(pcoord.y, extent.ymin, extent.ymax);
|
10202 | }
|
10203 | return wrapped;
|
10204 | },
|
10205 | getCircum: function getCircum() {
|
10206 | if (!this.circum && this.isSphere()) {
|
10207 | var extent = this.getSphereExtent();
|
10208 | this.circum = {
|
10209 | x: extent.getWidth(),
|
10210 | y: extent.getHeight()
|
10211 | };
|
10212 | }
|
10213 | return this.circum;
|
10214 | },
|
10215 | getSphereExtent: function getSphereExtent() {
|
10216 | if (!this.extent && this.isSphere()) {
|
10217 | var max = this.project(new Coordinate(180, 90)),
|
10218 | min = this.project(new Coordinate(-180, -90));
|
10219 | this.extent = new Extent(min, max, this);
|
10220 | this.extent.sx = max.x > min.x ? 1 : -1;
|
10221 | this.extent.sy = max.y > min.y ? 1 : -1;
|
10222 | }
|
10223 | return this.extent;
|
10224 | }
|
10225 | };
|
10226 |
|
10227 | var Common$1 = {
|
10228 | measureLength: function measureLength(c1, c2) {
|
10229 | if (!Array.isArray(c1)) {
|
10230 | return this.measureLenBetween(c1, c2);
|
10231 | }
|
10232 | var len = 0;
|
10233 | for (var i = 0, l = c1.length; i < l - 1; i++) {
|
10234 | len += this.measureLenBetween(c1[i], c1[i + 1]);
|
10235 | }
|
10236 | return len;
|
10237 | }
|
10238 | };
|
10239 |
|
10240 | var Identity = extend({
|
10241 | 'measure': 'IDENTITY',
|
10242 |
|
10243 | measureLenBetween: function measureLenBetween(c1, c2) {
|
10244 | if (!c1 || !c2) {
|
10245 | return 0;
|
10246 | }
|
10247 | try {
|
10248 | return Math.sqrt(Math.pow(c1.x - c2.x, 2) + Math.pow(c1.y - c2.y, 2));
|
10249 | } catch (err) {
|
10250 | return 0;
|
10251 | }
|
10252 | },
|
10253 |
|
10254 | measureArea: function measureArea(coordinates) {
|
10255 | if (!Array.isArray(coordinates)) {
|
10256 | return 0;
|
10257 | }
|
10258 | var area = 0;
|
10259 | for (var i = 0, len = coordinates.length; i < len; i++) {
|
10260 | var c1 = coordinates[i];
|
10261 | var c2 = null;
|
10262 | if (i === len - 1) {
|
10263 | c2 = coordinates[0];
|
10264 | } else {
|
10265 | c2 = coordinates[i + 1];
|
10266 | }
|
10267 | area += c1.x * c2.y - c1.y * c2.x;
|
10268 | }
|
10269 | return Math.abs(area / 2);
|
10270 | },
|
10271 |
|
10272 | locate: function locate(c, xDist, yDist) {
|
10273 | c = new Coordinate(c.x, c.y);
|
10274 | return this._locate(c, xDist, yDist);
|
10275 | },
|
10276 |
|
10277 | _locate: function _locate(c, xDist, yDist) {
|
10278 | if (!c) {
|
10279 | return null;
|
10280 | }
|
10281 | if (!xDist) {
|
10282 | xDist = 0;
|
10283 | }
|
10284 | if (!yDist) {
|
10285 | yDist = 0;
|
10286 | }
|
10287 | if (!xDist && !yDist) {
|
10288 | return c;
|
10289 | }
|
10290 | c.x = c.x + xDist;
|
10291 | c.y = c.y + yDist;
|
10292 | return c;
|
10293 | },
|
10294 |
|
10295 | rotate: function rotate(c, pivot, angle) {
|
10296 | c = new Coordinate(c.x, c.y);
|
10297 | return this._rotate(c, pivot, angle);
|
10298 | },
|
10299 |
|
10300 | _rotate: function () {
|
10301 | var tmp = new Point(0, 0);
|
10302 | return function (c, pivot, angle) {
|
10303 | tmp.x = c.x - pivot.x;
|
10304 | tmp.y = c.y - pivot.y;
|
10305 | tmp._rotate(angle * Math.PI / 180);
|
10306 | return c._add(tmp.x, tmp.y);
|
10307 | };
|
10308 | }()
|
10309 | }, Common$1);
|
10310 |
|
10311 | var Sphere = function () {
|
10312 | function Sphere(radius) {
|
10313 | classCallCheck(this, Sphere);
|
10314 |
|
10315 | this.radius = radius;
|
10316 | }
|
10317 |
|
10318 | Sphere.prototype.measureLenBetween = function measureLenBetween(c1, c2) {
|
10319 | if (!c1 || !c2) {
|
10320 | return 0;
|
10321 | }
|
10322 | var b = toRadian(c1.y);
|
10323 | var d = toRadian(c2.y),
|
10324 | e = b - d,
|
10325 | f = toRadian(c1.x) - toRadian(c2.x);
|
10326 | b = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(e / 2), 2) + Math.cos(b) * Math.cos(d) * Math.pow(Math.sin(f / 2), 2)));
|
10327 | b *= this.radius;
|
10328 | return Math.round(b * 1E5) / 1E5;
|
10329 | };
|
10330 |
|
10331 | Sphere.prototype.measureArea = function measureArea(coordinates) {
|
10332 | var a = toRadian(this.radius);
|
10333 | var b = 0,
|
10334 | c = coordinates,
|
10335 | d = c.length;
|
10336 | if (d < 3) {
|
10337 | return 0;
|
10338 | }
|
10339 | var i = void 0;
|
10340 | for (i = 0; i < d - 1; i++) {
|
10341 | var e = c[i],
|
10342 | f = c[i + 1];
|
10343 | b += e.x * a * Math.cos(toRadian(e.y)) * f.y * a - f.x * a * Math.cos(toRadian(f.y)) * e.y * a;
|
10344 | }
|
10345 | d = c[i];
|
10346 | c = c[0];
|
10347 | b += d.x * a * Math.cos(toRadian(d.y)) * c.y * a - c.x * a * Math.cos(toRadian(c.y)) * d.y * a;
|
10348 | return 0.5 * Math.abs(b);
|
10349 | };
|
10350 |
|
10351 | Sphere.prototype.locate = function locate(c, xDist, yDist) {
|
10352 | c = new Coordinate(c.x, c.y);
|
10353 | return this._locate(c, xDist, yDist);
|
10354 | };
|
10355 |
|
10356 | Sphere.prototype._locate = function _locate(c, xDist, yDist) {
|
10357 | if (!c) {
|
10358 | return null;
|
10359 | }
|
10360 | if (!xDist) {
|
10361 | xDist = 0;
|
10362 | }
|
10363 | if (!yDist) {
|
10364 | yDist = 0;
|
10365 | }
|
10366 | if (!xDist && !yDist) {
|
10367 | return c;
|
10368 | }
|
10369 | var x = void 0,
|
10370 | y = void 0;
|
10371 | var ry = toRadian(c.y);
|
10372 | if (yDist !== 0) {
|
10373 | var dy = Math.abs(yDist);
|
10374 | var sy = Math.sin(dy / (2 * this.radius)) * 2;
|
10375 | ry = ry + sy * (yDist > 0 ? 1 : -1);
|
10376 | y = wrap(ry * 180 / Math.PI, -90, 90);
|
10377 | } else {
|
10378 | y = c.y;
|
10379 | }
|
10380 | if (xDist !== 0) {
|
10381 | var dx = Math.abs(xDist);
|
10382 | var rx = toRadian(c.x);
|
10383 | var sx = 2 * Math.sqrt(Math.pow(Math.sin(dx / (2 * this.radius)), 2) / Math.pow(Math.cos(ry), 2));
|
10384 | rx = rx + sx * (xDist > 0 ? 1 : -1);
|
10385 | x = wrap(rx * 180 / Math.PI, -180, 180);
|
10386 | } else {
|
10387 | x = c.x;
|
10388 | }
|
10389 | c.x = x;
|
10390 | c.y = y;
|
10391 | return c;
|
10392 | };
|
10393 |
|
10394 | Sphere.prototype.rotate = function rotate(c, pivot, angle) {
|
10395 | c = new Coordinate(c);
|
10396 | return this._rotate(c, pivot, angle);
|
10397 | };
|
10398 |
|
10399 | Sphere.prototype._rotate = function _rotate(c, pivot, angle) {
|
10400 | var initialAngle = rhumbBearing(pivot, c);
|
10401 | var finalAngle = initialAngle - angle;
|
10402 | var distance = this.measureLenBetween(pivot, c);
|
10403 | c.x = pivot.x;
|
10404 | c.y = pivot.y;
|
10405 | return calculateRhumbDestination(c, distance, finalAngle, this.radius);
|
10406 | };
|
10407 |
|
10408 | return Sphere;
|
10409 | }();
|
10410 |
|
10411 | function rhumbBearing(start, end) {
|
10412 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
10413 |
|
10414 | var bear360 = void 0;
|
10415 | if (options.final) bear360 = calculateRhumbBearing(end, start);else bear360 = calculateRhumbBearing(start, end);
|
10416 |
|
10417 | var bear180 = bear360 > 180 ? -(360 - bear360) : bear360;
|
10418 |
|
10419 | return bear180;
|
10420 | }
|
10421 |
|
10422 | function calculateRhumbBearing(from, to) {
|
10423 | var phi1 = toRadian(from.y);
|
10424 | var phi2 = toRadian(to.y);
|
10425 | var deltaLambda = toRadian(to.x - from.x);
|
10426 |
|
10427 | if (deltaLambda > Math.PI) deltaLambda -= 2 * Math.PI;
|
10428 | if (deltaLambda < -Math.PI) deltaLambda += 2 * Math.PI;
|
10429 |
|
10430 | var deltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
|
10431 |
|
10432 | var theta = Math.atan2(deltaLambda, deltaPsi);
|
10433 |
|
10434 | return (toDegree(theta) + 360) % 360;
|
10435 | }
|
10436 |
|
10437 | function calculateRhumbDestination(origin, distance, bearing, radius) {
|
10438 |
|
10439 | var delta = distance / radius;
|
10440 | var lambda1 = origin.x * Math.PI / 180;
|
10441 | var phi1 = toRadian(origin.y);
|
10442 | var theta = toRadian(bearing);
|
10443 |
|
10444 | var DeltaPhi = delta * Math.cos(theta);
|
10445 | var phi2 = phi1 + DeltaPhi;
|
10446 |
|
10447 | if (Math.abs(phi2) > Math.PI / 2) phi2 = phi2 > 0 ? Math.PI - phi2 : -Math.PI - phi2;
|
10448 |
|
10449 | var DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
|
10450 | var q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
|
10451 | var DeltaLambda = delta * Math.sin(theta) / q;
|
10452 | var lambda2 = lambda1 + DeltaLambda;
|
10453 |
|
10454 | origin.x = (lambda2 * 180 / Math.PI + 540) % 360 - 180;
|
10455 | origin.y = phi2 * 180 / Math.PI;
|
10456 | return origin;
|
10457 | }
|
10458 |
|
10459 | var WGS84Sphere = extend({
|
10460 | 'measure': 'EPSG:4326',
|
10461 | sphere: new Sphere(6378137),
|
10462 | measureLenBetween: function measureLenBetween() {
|
10463 | return this.sphere.measureLenBetween.apply(this.sphere, arguments);
|
10464 | },
|
10465 | measureArea: function measureArea() {
|
10466 | return this.sphere.measureArea.apply(this.sphere, arguments);
|
10467 | },
|
10468 | _locate: function _locate() {
|
10469 | return this.sphere._locate.apply(this.sphere, arguments);
|
10470 | },
|
10471 | locate: function locate() {
|
10472 | return this.sphere.locate.apply(this.sphere, arguments);
|
10473 | },
|
10474 | _rotate: function _rotate() {
|
10475 | return this.sphere._rotate.apply(this.sphere, arguments);
|
10476 | },
|
10477 | rotate: function rotate() {
|
10478 | return this.sphere.rotate.apply(this.sphere, arguments);
|
10479 | }
|
10480 | }, Common$1);
|
10481 |
|
10482 | var BaiduSphere = extend({
|
10483 | 'measure': 'BAIDU',
|
10484 | sphere: new Sphere(6370996.81),
|
10485 | measureLenBetween: function measureLenBetween() {
|
10486 | return this.sphere.measureLenBetween.apply(this.sphere, arguments);
|
10487 | },
|
10488 | measureArea: function measureArea() {
|
10489 | return this.sphere.measureArea.apply(this.sphere, arguments);
|
10490 | },
|
10491 | _locate: function _locate() {
|
10492 | return this.sphere._locate.apply(this.sphere, arguments);
|
10493 | },
|
10494 | locate: function locate() {
|
10495 | return this.sphere.locate.apply(this.sphere, arguments);
|
10496 | },
|
10497 | _rotate: function _rotate() {
|
10498 | return this.sphere._rotate.apply(this.sphere, arguments);
|
10499 | },
|
10500 | rotate: function rotate() {
|
10501 | return this.sphere.rotate.apply(this.sphere, arguments);
|
10502 | }
|
10503 | }, Common$1);
|
10504 |
|
10505 | var DEFAULT$1 = WGS84Sphere;
|
10506 |
|
10507 | var measurers = {};
|
10508 |
|
10509 | function registerMeasurer(m) {
|
10510 | measurers[m.measure] = m;
|
10511 | }
|
10512 |
|
10513 | registerMeasurer(Identity);
|
10514 | registerMeasurer(WGS84Sphere);
|
10515 | registerMeasurer(BaiduSphere);
|
10516 |
|
10517 | var Measurer = {
|
10518 | getInstance: function getInstance(name) {
|
10519 | if (!name) {
|
10520 | return DEFAULT$1;
|
10521 | }
|
10522 | for (var p in measurers) {
|
10523 | if (hasOwn(measurers, p)) {
|
10524 | var mName = measurers[p]['measure'];
|
10525 | if (!mName) {
|
10526 | continue;
|
10527 | }
|
10528 | if (name.toLowerCase() === mName.toLowerCase()) {
|
10529 | return measurers[p];
|
10530 | }
|
10531 | }
|
10532 | }
|
10533 | return null;
|
10534 | }
|
10535 | };
|
10536 |
|
10537 | var index$2 = Object.freeze({
|
10538 | Identity: Identity,
|
10539 | DEFAULT: DEFAULT$1,
|
10540 | Measurer: Measurer,
|
10541 | WGS84Sphere: WGS84Sphere,
|
10542 | BaiduSphere: BaiduSphere
|
10543 | });
|
10544 |
|
10545 | var EPSG3857 = extend({}, Common, {
|
10546 | code: 'EPSG:3857',
|
10547 | rad: Math.PI / 180,
|
10548 | metersPerDegree: 6378137 * Math.PI / 180,
|
10549 | maxLatitude: 85.0511287798,
|
10550 |
|
10551 | project: function project(lnglat) {
|
10552 | var rad = this.rad,
|
10553 | metersPerDegree = this.metersPerDegree,
|
10554 | max = this.maxLatitude;
|
10555 | var lng = lnglat.x,
|
10556 | lat = Math.max(Math.min(max, lnglat.y), -max);
|
10557 | var c = void 0;
|
10558 | if (lat === 0) {
|
10559 | c = 0;
|
10560 | } else {
|
10561 | c = Math.log(Math.tan((90 + lat) * rad / 2)) / rad;
|
10562 | }
|
10563 | return new Coordinate(lng * metersPerDegree, c * metersPerDegree);
|
10564 | },
|
10565 |
|
10566 | unproject: function unproject(pLnglat) {
|
10567 | var x = pLnglat.x,
|
10568 | y = pLnglat.y;
|
10569 | var rad = this.rad,
|
10570 | metersPerDegree = this.metersPerDegree;
|
10571 | var c = void 0;
|
10572 | if (y === 0) {
|
10573 | c = 0;
|
10574 | } else {
|
10575 | c = y / metersPerDegree;
|
10576 | c = (2 * Math.atan(Math.exp(c * rad)) - Math.PI / 2) / rad;
|
10577 | }
|
10578 | return new Coordinate(wrap(x / metersPerDegree, -180, 180), wrap(c, -this.maxLatitude, this.maxLatitude));
|
10579 | }
|
10580 | }, WGS84Sphere);
|
10581 |
|
10582 | var PROJ4326 = extend({}, Common, {
|
10583 | code: 'EPSG:4326',
|
10584 | project: function project(p) {
|
10585 | return new Coordinate(p);
|
10586 | },
|
10587 | unproject: function unproject(p) {
|
10588 | return new Coordinate(p);
|
10589 | }
|
10590 | }, WGS84Sphere);
|
10591 |
|
10592 | var Projection_EPSG4490 = extend({}, PROJ4326, {
|
10593 | code: 'EPSG:4490'
|
10594 | });
|
10595 |
|
10596 | var Projection_Baidu = extend({}, Common, {
|
10597 | code: 'BAIDU',
|
10598 |
|
10599 | project: function project(p) {
|
10600 | return this.convertLL2MC(p);
|
10601 | },
|
10602 |
|
10603 | unproject: function unproject(p) {
|
10604 | return this.convertMC2LL(p);
|
10605 | }
|
10606 | }, BaiduSphere, {
|
10607 | EARTHRADIUS: 6370996.81,
|
10608 | MCBAND: [12890594.86, 8362377.87, 5591021, 3481989.83, 1678043.12, 0],
|
10609 | LLBAND: [75, 60, 45, 30, 15, 0],
|
10610 | MC2LL: [[1.410526172116255e-8, 0.00000898305509648872, -1.9939833816331, 200.9824383106796, -187.2403703815547, 91.6087516669843, -23.38765649603339, 2.57121317296198, -0.03801003308653, 17337981.2], [-7.435856389565537e-9, 0.000008983055097726239, -0.78625201886289, 96.32687599759846, -1.85204757529826, -59.36935905485877, 47.40033549296737, -16.50741931063887, 2.28786674699375, 10260144.86], [-3.030883460898826e-8, 0.00000898305509983578, 0.30071316287616, 59.74293618442277, 7.357984074871, -25.38371002664745, 13.45380521110908, -3.29883767235584, 0.32710905363475, 6856817.37], [-1.981981304930552e-8, 0.000008983055099779535, 0.03278182852591, 40.31678527705744, 0.65659298677277, -4.44255534477492, 0.85341911805263, 0.12923347998204, -0.04625736007561, 4482777.06], [3.09191371068437e-9, 0.000008983055096812155, 0.00006995724062, 23.10934304144901, -0.00023663490511, -0.6321817810242, -0.00663494467273, 0.03430082397953, -0.00466043876332, 2555164.4], [2.890871144776878e-9, 0.000008983055095805407, -3.068298e-8, 7.47137025468032, -0.00000353937994, -0.02145144861037, -0.00001234426596, 0.00010322952773, -0.00000323890364, 826088.5]],
|
10611 | LL2MC: [[-0.0015702102444, 111320.7020616939, 1704480524535203, -10338987376042340, 26112667856603880, -35149669176653700, 26595700718403920, -10725012454188240, 1800819912950474, 82.5], [0.0008277824516172526, 111320.7020463578, 647795574.6671607, -4082003173.641316, 10774905663.51142, -15171875531.51559, 12053065338.62167, -5124939663.577472, 913311935.9512032, 67.5], [0.00337398766765, 111320.7020202162, 4481351.045890365, -23393751.19931662, 79682215.47186455, -115964993.2797253, 97236711.15602145, -43661946.33752821, 8477230.501135234, 52.5], [0.00220636496208, 111320.7020209128, 51751.86112841131, 3796837.749470245, 992013.7397791013, -1221952.21711287, 1340652.697009075, -620943.6990984312, 144416.9293806241, 37.5], [-0.0003441963504368392, 111320.7020576856, 278.2353980772752, 2485758.690035394, 6070.750963243378, 54821.18345352118, 9540.606633304236, -2710.55326746645, 1405.483844121726, 22.5], [-0.0003218135878613132, 111320.7020701615, 0.00369383431289, 823725.6402795718, 0.46104986909093, 2351.343141331292, 1.58060784298199, 8.77738589078284, 0.37238884252424, 7.45]],
|
10612 |
|
10613 | convertMC2LL: function convertMC2LL(cB) {
|
10614 | var cC = {
|
10615 | x: Math.abs(cB.x),
|
10616 | y: Math.abs(cB.y)
|
10617 | };
|
10618 | var cE = void 0;
|
10619 | for (var cD = 0, len = this.MCBAND.length; cD < len; cD++) {
|
10620 | if (cC.y >= this.MCBAND[cD]) {
|
10621 | cE = this.MC2LL[cD];
|
10622 | break;
|
10623 | }
|
10624 | }
|
10625 | var T = this.convertor(cB, cE);
|
10626 | var result = new Coordinate(T.x, T.y);
|
10627 | return result;
|
10628 | },
|
10629 | convertLL2MC: function convertLL2MC(T) {
|
10630 | var cD = void 0,
|
10631 | cC = void 0,
|
10632 | len = void 0;
|
10633 | T.x = this.getLoop(T.x, -180, 180);
|
10634 | T.y = this.getRange(T.y, -74, 74);
|
10635 | var cB = new Coordinate(T.x, T.y);
|
10636 | for (cC = 0, len = this.LLBAND.length; cC < len; cC++) {
|
10637 | if (cB.y >= this.LLBAND[cC]) {
|
10638 | cD = this.LL2MC[cC];
|
10639 | break;
|
10640 | }
|
10641 | }
|
10642 | if (!cD) {
|
10643 | for (cC = this.LLBAND.length - 1; cC >= 0; cC--) {
|
10644 | if (cB.y <= -this.LLBAND[cC]) {
|
10645 | cD = this.LL2MC[cC];
|
10646 | break;
|
10647 | }
|
10648 | }
|
10649 | }
|
10650 | var cE = this.convertor(T, cD);
|
10651 | var result = new Coordinate(cE.x, cE.y);
|
10652 | return result;
|
10653 | },
|
10654 | convertor: function convertor(cC, cD) {
|
10655 | if (!cC || !cD) {
|
10656 | return null;
|
10657 | }
|
10658 | var T = cD[0] + cD[1] * Math.abs(cC.x);
|
10659 | var cB = Math.abs(cC.y) / cD[9];
|
10660 | var cE = cD[2] + cD[3] * cB + cD[4] * cB * cB + cD[5] * cB * cB * cB + cD[6] * cB * cB * cB * cB + cD[7] * cB * cB * cB * cB * cB + cD[8] * cB * cB * cB * cB * cB * cB;
|
10661 | T *= cC.x < 0 ? -1 : 1;
|
10662 | cE *= cC.y < 0 ? -1 : 1;
|
10663 | return new Coordinate(T, cE);
|
10664 | },
|
10665 | toRadians: function toRadians(T) {
|
10666 | return Math.PI * T / 180;
|
10667 | },
|
10668 | toDegrees: function toDegrees(T) {
|
10669 | return 180 * T / Math.PI;
|
10670 | },
|
10671 | getRange: function getRange(cC, cB, T) {
|
10672 | if (cB != null) {
|
10673 | cC = Math.max(cC, cB);
|
10674 | }
|
10675 | if (T != null) {
|
10676 | cC = Math.min(cC, T);
|
10677 | }
|
10678 | return cC;
|
10679 | },
|
10680 | getLoop: function getLoop(cC, cB, T) {
|
10681 | while (cC > T) {
|
10682 | cC -= T - cB;
|
10683 | }
|
10684 | while (cC < cB) {
|
10685 | cC += T - cB;
|
10686 | }
|
10687 | return cC;
|
10688 | }
|
10689 | });
|
10690 |
|
10691 | var Projection_IDENTITY = extend({}, Common, {
|
10692 | code: 'IDENTITY',
|
10693 | project: function project(p) {
|
10694 | return p.copy();
|
10695 | },
|
10696 | unproject: function unproject(p) {
|
10697 | return p.copy();
|
10698 | }
|
10699 | }, Identity);
|
10700 |
|
10701 | var DEFAULT = EPSG3857;
|
10702 |
|
10703 | var projections = Object.freeze({
|
10704 | EPSG3857: EPSG3857,
|
10705 | DEFAULT: DEFAULT,
|
10706 | EPSG4326: PROJ4326,
|
10707 | EPSG4490: Projection_EPSG4490,
|
10708 | BAIDU: Projection_Baidu,
|
10709 | IDENTITY: Projection_IDENTITY,
|
10710 | Common: Common
|
10711 | });
|
10712 |
|
10713 | var Renderable = (function (Base) {
|
10714 | return function (_Base) {
|
10715 | inherits(_class, _Base);
|
10716 |
|
10717 | function _class() {
|
10718 | classCallCheck(this, _class);
|
10719 | return possibleConstructorReturn(this, _Base.apply(this, arguments));
|
10720 | }
|
10721 |
|
10722 | _class.registerRenderer = function registerRenderer(name, clazz) {
|
10723 | var proto = this.prototype;
|
10724 | var parentProto = Object.getPrototypeOf(proto);
|
10725 | if (!proto._rendererClasses || proto._rendererClasses === parentProto._rendererClasses) {
|
10726 | proto._rendererClasses = proto._rendererClasses ? Object.create(proto._rendererClasses) : {};
|
10727 | }
|
10728 | proto._rendererClasses[name.toLowerCase()] = clazz;
|
10729 | return this;
|
10730 | };
|
10731 |
|
10732 | _class.getRendererClass = function getRendererClass(name) {
|
10733 | var proto = this.prototype;
|
10734 | if (!proto._rendererClasses) {
|
10735 | return null;
|
10736 | }
|
10737 | return proto._rendererClasses[name.toLowerCase()];
|
10738 | };
|
10739 |
|
10740 | return _class;
|
10741 | }(Base);
|
10742 | });
|
10743 |
|
10744 | var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
10745 |
|
10746 |
|
10747 |
|
10748 |
|
10749 |
|
10750 | function createCommonjsModule(fn, module) {
|
10751 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
10752 | }
|
10753 |
|
10754 | var zousanMin = createCommonjsModule(function (module) {
|
10755 | !function (t) {
|
10756 | "use strict";
|
10757 | function e(t) {
|
10758 | if (t) {
|
10759 | var e = this;t(function (t) {
|
10760 | e.resolve(t);
|
10761 | }, function (t) {
|
10762 | e.reject(t);
|
10763 | });
|
10764 | }
|
10765 | }function n(t, e) {
|
10766 | if ("function" == typeof t.y) try {
|
10767 | var n = t.y.call(i, e);t.p.resolve(n);
|
10768 | } catch (o) {
|
10769 | t.p.reject(o);
|
10770 | } else t.p.resolve(e);
|
10771 | }function o(t, e) {
|
10772 | if ("function" == typeof t.n) try {
|
10773 | var n = t.n.call(i, e);t.p.resolve(n);
|
10774 | } catch (o) {
|
10775 | t.p.reject(o);
|
10776 | } else t.p.reject(e);
|
10777 | }var r,
|
10778 | i,
|
10779 | c = "fulfilled",
|
10780 | u = "rejected",
|
10781 | s = "undefined",
|
10782 | f = function () {
|
10783 | function e() {
|
10784 | for (; n.length - o;) {
|
10785 | try {
|
10786 | n[o]();
|
10787 | } catch (e) {
|
10788 | t.console && t.console.error(e);
|
10789 | }n[o++] = i, o == r && (n.splice(0, r), o = 0);
|
10790 | }
|
10791 | }var n = [],
|
10792 | o = 0,
|
10793 | r = 1024,
|
10794 | c = function () {
|
10795 | if ((typeof MutationObserver === "undefined" ? "undefined" : _typeof(MutationObserver)) !== s) {
|
10796 | var t = document.createElement("div"),
|
10797 | n = new MutationObserver(e);return n.observe(t, { attributes: !0 }), function () {
|
10798 | t.setAttribute("a", 0);
|
10799 | };
|
10800 | }return (typeof setImmediate === "undefined" ? "undefined" : _typeof(setImmediate)) !== s ? function () {
|
10801 | setImmediate(e);
|
10802 | } : function () {
|
10803 | setTimeout(e, 0);
|
10804 | };
|
10805 | }();return function (t) {
|
10806 | n.push(t), n.length - o == 1 && c();
|
10807 | };
|
10808 | }();e.prototype = { resolve: function resolve(t) {
|
10809 | if (this.state === r) {
|
10810 | if (t === this) return this.reject(new TypeError("Attempt to resolve promise with self"));var e = this;if (t && ("function" == typeof t || "object" == (typeof t === "undefined" ? "undefined" : _typeof(t)))) try {
|
10811 | var o = !0,
|
10812 | i = t.then;if ("function" == typeof i) return void i.call(t, function (t) {
|
10813 | o && (o = !1, e.resolve(t));
|
10814 | }, function (t) {
|
10815 | o && (o = !1, e.reject(t));
|
10816 | });
|
10817 | } catch (u) {
|
10818 | return void (o && this.reject(u));
|
10819 | }this.state = c, this.v = t, e.c && f(function () {
|
10820 | for (var o = 0, r = e.c.length; r > o; o++) {
|
10821 | n(e.c[o], t);
|
10822 | }
|
10823 | });
|
10824 | }
|
10825 | }, reject: function reject(n) {
|
10826 | if (this.state === r) {
|
10827 | this.state = u, this.v = n;var i = this.c;i ? f(function () {
|
10828 | for (var t = 0, e = i.length; e > t; t++) {
|
10829 | o(i[t], n);
|
10830 | }
|
10831 | }) : !e.suppressUncaughtRejectionError && t.console && t.console.log("You upset Zousan. Please catch rejections: ", n, n ? n.stack : null);
|
10832 | }
|
10833 | }, then: function then(t, i) {
|
10834 | var u = new e(),
|
10835 | s = { y: t, n: i, p: u };if (this.state === r) this.c ? this.c.push(s) : this.c = [s];else {
|
10836 | var l = this.state,
|
10837 | a = this.v;f(function () {
|
10838 | l === c ? n(s, a) : o(s, a);
|
10839 | });
|
10840 | }return u;
|
10841 | }, "catch": function _catch(t) {
|
10842 | return this.then(null, t);
|
10843 | }, "finally": function _finally(t) {
|
10844 | return this.then(t, t);
|
10845 | }, timeout: function timeout(t, n) {
|
10846 | n = n || "Timeout";var o = this;return new e(function (e, r) {
|
10847 | setTimeout(function () {
|
10848 | r(Error(n));
|
10849 | }, t), o.then(function (t) {
|
10850 | e(t);
|
10851 | }, function (t) {
|
10852 | r(t);
|
10853 | });
|
10854 | });
|
10855 | } }, e.resolve = function (t) {
|
10856 | var n = new e();return n.resolve(t), n;
|
10857 | }, e.reject = function (t) {
|
10858 | var n = new e();return n.reject(t), n;
|
10859 | }, e.all = function (t) {
|
10860 | function n(n, c) {
|
10861 | n && "function" == typeof n.then || (n = e.resolve(n)), n.then(function (e) {
|
10862 | o[c] = e, r++, r == t.length && i.resolve(o);
|
10863 | }, function (t) {
|
10864 | i.reject(t);
|
10865 | });
|
10866 | }for (var o = [], r = 0, i = new e(), c = 0; c < t.length; c++) {
|
10867 | n(t[c], c);
|
10868 | }return t.length || i.resolve(o), i;
|
10869 | }, 'object' != s && module.exports && (module.exports = e), t.define && t.define.amd && t.define([], function () {
|
10870 | return e;
|
10871 | }), t.Zousan = e, e.soon = f;
|
10872 | }("undefined" != typeof commonjsGlobal ? commonjsGlobal : commonjsGlobal);
|
10873 | });
|
10874 |
|
10875 | var promise = void 0;
|
10876 |
|
10877 | if (typeof Promise !== 'undefined') {
|
10878 | promise = Promise;
|
10879 | } else {
|
10880 | promise = zousanMin;
|
10881 | }
|
10882 |
|
10883 | var Promise$1 = promise;
|
10884 |
|
10885 | var CanvasRenderer = function (_Class) {
|
10886 | inherits(CanvasRenderer, _Class);
|
10887 |
|
10888 | function CanvasRenderer(layer) {
|
10889 | classCallCheck(this, CanvasRenderer);
|
10890 |
|
10891 | var _this = possibleConstructorReturn(this, _Class.call(this));
|
10892 |
|
10893 | _this.layer = layer;
|
10894 | _this._painted = false;
|
10895 | _this._drawTime = 0;
|
10896 | _this.setToRedraw();
|
10897 | return _this;
|
10898 | }
|
10899 |
|
10900 | CanvasRenderer.prototype.render = function render(framestamp) {
|
10901 | var _this2 = this;
|
10902 |
|
10903 | this.prepareRender();
|
10904 | if (!this.getMap() || !this.layer.isVisible()) {
|
10905 | return;
|
10906 | }
|
10907 | if (!this.resources) {
|
10908 | this.resources = new ResourceCache();
|
10909 | }
|
10910 | if (this.checkResources) {
|
10911 | var resources = this.checkResources();
|
10912 | if (resources.length > 0) {
|
10913 | this._loadingResource = true;
|
10914 | this.loadResources(resources).then(function () {
|
10915 | _this2._loadingResource = false;
|
10916 | if (_this2.layer) {
|
10917 | _this2.layer.fire('resourceload');
|
10918 | _this2.setToRedraw();
|
10919 | }
|
10920 | });
|
10921 | } else {
|
10922 | this._tryToDraw(framestamp);
|
10923 | }
|
10924 | } else {
|
10925 | this._tryToDraw(framestamp);
|
10926 | }
|
10927 | };
|
10928 |
|
10929 | CanvasRenderer.prototype.testIfNeedRedraw = function testIfNeedRedraw() {
|
10930 | var map = this.getMap();
|
10931 | if (this._loadingResource) {
|
10932 | return false;
|
10933 | }
|
10934 | if (this._toRedraw) {
|
10935 | return true;
|
10936 | }
|
10937 | if (map.isInteracting() && !this.drawOnInteracting) {
|
10938 | return false;
|
10939 | }
|
10940 | if (this.needToRedraw()) {
|
10941 | return true;
|
10942 | }
|
10943 | return false;
|
10944 | };
|
10945 |
|
10946 | CanvasRenderer.prototype.needToRedraw = function needToRedraw() {
|
10947 | var map = this.getMap();
|
10948 | if (map.isInteracting()) {
|
10949 | return !(!map.getPitch() && map.isMoving() && !map.isZooming() && !map.isRotating() && !this.layer.options['forceRenderOnMoving']);
|
10950 | }
|
10951 | return false;
|
10952 | };
|
10953 |
|
10954 | CanvasRenderer.prototype.onSkipDrawOnInteracting = function onSkipDrawOnInteracting() {};
|
10955 |
|
10956 | CanvasRenderer.prototype.isRenderComplete = function isRenderComplete() {
|
10957 | return !!this._renderComplete;
|
10958 | };
|
10959 |
|
10960 | CanvasRenderer.prototype.mustRenderOnInteracting = function mustRenderOnInteracting() {
|
10961 | return !this._painted || this.checkResources && this.checkResources().length > 0;
|
10962 | };
|
10963 |
|
10964 | CanvasRenderer.prototype.setToRedraw = function setToRedraw() {
|
10965 | this._toRedraw = true;
|
10966 | return this;
|
10967 | };
|
10968 |
|
10969 | CanvasRenderer.prototype.setCanvasUpdated = function setCanvasUpdated() {
|
10970 | this._canvasUpdated = true;
|
10971 | return this;
|
10972 | };
|
10973 |
|
10974 | CanvasRenderer.prototype.isCanvasUpdated = function isCanvasUpdated() {
|
10975 | return !!this._canvasUpdated;
|
10976 | };
|
10977 |
|
10978 | CanvasRenderer.prototype.remove = function remove() {
|
10979 | this.onRemove();
|
10980 | delete this._loadingResource;
|
10981 | delete this.southWest;
|
10982 | delete this.canvas;
|
10983 | delete this.context;
|
10984 | delete this.canvasExtent2D;
|
10985 | delete this._extent2D;
|
10986 | delete this.resources;
|
10987 | delete this.layer;
|
10988 | };
|
10989 |
|
10990 | CanvasRenderer.prototype.onRemove = function onRemove() {};
|
10991 |
|
10992 | CanvasRenderer.prototype.onAdd = function onAdd() {};
|
10993 |
|
10994 | CanvasRenderer.prototype.getMap = function getMap() {
|
10995 | if (!this.layer) {
|
10996 | return null;
|
10997 | }
|
10998 | return this.layer.getMap();
|
10999 | };
|
11000 |
|
11001 | CanvasRenderer.prototype.getCanvasImage = function getCanvasImage() {
|
11002 | var map = this.getMap();
|
11003 | this._canvasUpdated = false;
|
11004 | if (this._renderZoom !== map.getZoom() || !this.canvas || !this._extent2D) {
|
11005 | return null;
|
11006 | }
|
11007 | if (this.isBlank()) {
|
11008 | return null;
|
11009 | }
|
11010 | if (this.layer.isEmpty && this.layer.isEmpty()) {
|
11011 | return null;
|
11012 | }
|
11013 |
|
11014 | var containerPoint = map._pointToContainerPoint(this.southWest)._add(0, -map.height);
|
11015 | return {
|
11016 | 'image': this.canvas,
|
11017 | 'layer': this.layer,
|
11018 | 'point': containerPoint };
|
11019 | };
|
11020 |
|
11021 | CanvasRenderer.prototype.clear = function clear() {
|
11022 | this.clearCanvas();
|
11023 | };
|
11024 |
|
11025 | CanvasRenderer.prototype.isBlank = function isBlank() {
|
11026 | if (!this._painted) {
|
11027 | return true;
|
11028 | }
|
11029 | return false;
|
11030 | };
|
11031 |
|
11032 | CanvasRenderer.prototype.show = function show() {
|
11033 | this.setToRedraw();
|
11034 | };
|
11035 |
|
11036 | CanvasRenderer.prototype.hide = function hide() {
|
11037 | this.clear();
|
11038 | this.setToRedraw();
|
11039 | };
|
11040 |
|
11041 | CanvasRenderer.prototype.setZIndex = function setZIndex() {
|
11042 | this.setToRedraw();
|
11043 | };
|
11044 |
|
11045 | CanvasRenderer.prototype.hitDetect = function hitDetect(point) {
|
11046 | if (!this.context || this.layer.isEmpty && this.layer.isEmpty() || this.isBlank() || this._errorThrown) {
|
11047 | return false;
|
11048 | }
|
11049 | var map = this.getMap();
|
11050 | var r = Browser$1.retina ? 2 : 1;
|
11051 | var size = map.getSize();
|
11052 | if (point.x < 0 || point.x > size['width'] * r || point.y < 0 || point.y > size['height'] * r) {
|
11053 | return false;
|
11054 | }
|
11055 | try {
|
11056 | var imgData = this.context.getImageData(r * point.x, r * point.y, 1, 1).data;
|
11057 | if (imgData[3] > 0) {
|
11058 | return true;
|
11059 | }
|
11060 | } catch (error) {
|
11061 | if (!this._errorThrown) {
|
11062 | if (console) {
|
11063 | console.warn('hit detect failed with tainted canvas, some geometries have external resources in another domain:\n', error);
|
11064 | }
|
11065 | this._errorThrown = true;
|
11066 | }
|
11067 |
|
11068 | return false;
|
11069 | }
|
11070 | return false;
|
11071 | };
|
11072 |
|
11073 | CanvasRenderer.prototype.loadResources = function loadResources(resourceUrls) {
|
11074 | if (!this.resources) {
|
11075 | this.resources = new ResourceCache();
|
11076 | }
|
11077 | var resources = this.resources,
|
11078 | promises = [];
|
11079 | if (isArrayHasData(resourceUrls)) {
|
11080 | var cache = {};
|
11081 | for (var i = resourceUrls.length - 1; i >= 0; i--) {
|
11082 | var url = resourceUrls[i];
|
11083 | if (!url || !url.length || cache[url.join('-')]) {
|
11084 | continue;
|
11085 | }
|
11086 | cache[url.join('-')] = 1;
|
11087 | if (!resources.isResourceLoaded(url, true)) {
|
11088 | promises.push(new Promise$1(this._promiseResource(url)));
|
11089 | }
|
11090 | }
|
11091 | }
|
11092 | return Promise$1.all(promises);
|
11093 | };
|
11094 |
|
11095 | CanvasRenderer.prototype.prepareRender = function prepareRender() {
|
11096 | delete this._renderComplete;
|
11097 | var map = this.getMap();
|
11098 | this._renderZoom = map.getZoom();
|
11099 | this.canvasExtent2D = this._extent2D = map._get2DExtent();
|
11100 |
|
11101 | this.southWest = map._containerPointToPoint(new Point(0, map.height));
|
11102 | };
|
11103 |
|
11104 | CanvasRenderer.prototype.createCanvas = function createCanvas() {
|
11105 | if (this.canvas) {
|
11106 | return;
|
11107 | }
|
11108 | var map = this.getMap();
|
11109 | var size = map.getSize();
|
11110 | var r = Browser$1.retina ? 2 : 1,
|
11111 | w = r * size.width,
|
11112 | h = r * size.height;
|
11113 | if (this.layer._canvas) {
|
11114 | var canvas = this.layer._canvas;
|
11115 | canvas.width = w;
|
11116 | canvas.height = h;
|
11117 | if (canvas.style) {
|
11118 | canvas.style.width = size.width + 'px';
|
11119 | canvas.style.height = size.height + 'px';
|
11120 | }
|
11121 | this.canvas = this.layer._canvas;
|
11122 | } else {
|
11123 | this.canvas = Canvas.createCanvas(w, h, map.CanvasClass);
|
11124 | }
|
11125 |
|
11126 | this.onCanvasCreate();
|
11127 | };
|
11128 |
|
11129 | CanvasRenderer.prototype.onCanvasCreate = function onCanvasCreate() {};
|
11130 |
|
11131 | CanvasRenderer.prototype.createContext = function createContext() {
|
11132 | if (this.gl && this.gl.canvas === this.canvas || this.context) {
|
11133 | return;
|
11134 | }
|
11135 | this.context = this.canvas.getContext('2d');
|
11136 | if (this.layer.options['globalCompositeOperation']) {
|
11137 | this.context.globalCompositeOperation = this.layer.options['globalCompositeOperation'];
|
11138 | }
|
11139 | if (Browser$1.retina) {
|
11140 | var r = 2;
|
11141 | this.context.scale(r, r);
|
11142 | }
|
11143 | };
|
11144 |
|
11145 | CanvasRenderer.prototype.resetCanvasTransform = function resetCanvasTransform() {
|
11146 | if (!this.context) {
|
11147 | return;
|
11148 | }
|
11149 | var r = Browser$1.retina ? 2 : 1;
|
11150 | this.context.setTransform(r, 0, 0, r, 0, 0);
|
11151 | };
|
11152 |
|
11153 | CanvasRenderer.prototype.resizeCanvas = function resizeCanvas(canvasSize) {
|
11154 | var canvas = this.canvas;
|
11155 | if (!canvas) {
|
11156 | return;
|
11157 | }
|
11158 | var size = canvasSize || this.getMap().getSize();
|
11159 | var r = Browser$1.retina ? 2 : 1;
|
11160 | if (canvas.width === r * size.width && canvas.height === r * size.height) {
|
11161 | return;
|
11162 | }
|
11163 |
|
11164 | canvas.height = r * size.height;
|
11165 | canvas.width = r * size.width;
|
11166 | if (Browser$1.retina && this.context) {
|
11167 | this.context.scale(r, r);
|
11168 | }
|
11169 | if (this.layer._canvas && canvas.style) {
|
11170 | canvas.style.width = size.width + 'px';
|
11171 | canvas.style.height = size.height + 'px';
|
11172 | }
|
11173 | };
|
11174 |
|
11175 | CanvasRenderer.prototype.clearCanvas = function clearCanvas() {
|
11176 | if (!this.context) {
|
11177 | return;
|
11178 | }
|
11179 | Canvas.clearRect(this.context, 0, 0, this.canvas.width, this.canvas.height);
|
11180 | };
|
11181 |
|
11182 | CanvasRenderer.prototype.prepareCanvas = function prepareCanvas() {
|
11183 | if (!this.canvas) {
|
11184 | this.createCanvas();
|
11185 | this.createContext();
|
11186 |
|
11187 | this.layer.fire('canvascreate', {
|
11188 | 'context': this.context,
|
11189 | 'gl': this.gl
|
11190 | });
|
11191 | } else {
|
11192 | this.clearCanvas();
|
11193 | this.resizeCanvas();
|
11194 | this.resetCanvasTransform();
|
11195 | }
|
11196 | delete this._maskExtent;
|
11197 | var mask = this.layer.getMask();
|
11198 |
|
11199 | if (!mask) {
|
11200 | this.layer.fire('renderstart', {
|
11201 | 'context': this.context,
|
11202 | 'gl': this.gl
|
11203 | });
|
11204 | return null;
|
11205 | }
|
11206 | var maskExtent2D = this._maskExtent = mask._getPainter().get2DExtent();
|
11207 | if (!maskExtent2D.intersects(this._extent2D)) {
|
11208 | this.layer.fire('renderstart', {
|
11209 | 'context': this.context,
|
11210 | 'gl': this.gl
|
11211 | });
|
11212 | return maskExtent2D;
|
11213 | }
|
11214 |
|
11215 | this.layer.fire('renderstart', {
|
11216 | 'context': this.context,
|
11217 | 'gl': this.gl
|
11218 | });
|
11219 | return maskExtent2D;
|
11220 | };
|
11221 |
|
11222 | CanvasRenderer.prototype.clipCanvas = function clipCanvas(context) {
|
11223 | var mask = this.layer.getMask();
|
11224 | if (!mask) {
|
11225 | return false;
|
11226 | }
|
11227 | var old = this.southWest;
|
11228 | var map = this.getMap();
|
11229 |
|
11230 | this.southWest = map._containerPointToPoint(new Point(0, map.height));
|
11231 | context.save();
|
11232 | if (Browser$1.retina) {
|
11233 | context.save();
|
11234 | context.scale(2, 2);
|
11235 | }
|
11236 | mask._getPainter().paint(null, context);
|
11237 | if (Browser$1.retina) {
|
11238 | context.restore();
|
11239 | }
|
11240 | context.clip();
|
11241 | this.southWest = old;
|
11242 | return true;
|
11243 | };
|
11244 |
|
11245 | CanvasRenderer.prototype.getViewExtent = function getViewExtent() {
|
11246 | return {
|
11247 | 'extent': this._extent2D,
|
11248 | 'maskExtent': this._maskExtent,
|
11249 | 'zoom': this._renderZoom,
|
11250 | 'southWest': this.southWest
|
11251 | };
|
11252 | };
|
11253 |
|
11254 | CanvasRenderer.prototype.completeRender = function completeRender() {
|
11255 | if (this.getMap()) {
|
11256 | this._renderComplete = true;
|
11257 |
|
11258 | this.layer.fire('renderend', {
|
11259 | 'context': this.context,
|
11260 | 'gl': this.gl
|
11261 | });
|
11262 | this.setCanvasUpdated();
|
11263 | }
|
11264 | };
|
11265 |
|
11266 | CanvasRenderer.prototype.getEvents = function getEvents() {
|
11267 | return {
|
11268 | '_zoomstart': this.onZoomStart,
|
11269 | '_zooming': this.onZooming,
|
11270 | '_zoomend': this.onZoomEnd,
|
11271 | '_resize': this.onResize,
|
11272 | '_movestart': this.onMoveStart,
|
11273 | '_moving': this.onMoving,
|
11274 | '_moveend': this.onMoveEnd,
|
11275 | '_dragrotatestart': this.onDragRotateStart,
|
11276 | '_dragrotating': this.onDragRotating,
|
11277 | '_dragrotateend': this.onDragRotateEnd,
|
11278 | '_spatialreferencechange': this.onSpatialReferenceChange
|
11279 | };
|
11280 | };
|
11281 |
|
11282 | CanvasRenderer.prototype.onZoomStart = function onZoomStart() {};
|
11283 |
|
11284 | CanvasRenderer.prototype.onZoomEnd = function onZoomEnd() {
|
11285 | this.setToRedraw();
|
11286 | };
|
11287 |
|
11288 | CanvasRenderer.prototype.onZooming = function onZooming() {};
|
11289 |
|
11290 | CanvasRenderer.prototype.onMoveStart = function onMoveStart() {};
|
11291 |
|
11292 | CanvasRenderer.prototype.onMoving = function onMoving() {};
|
11293 |
|
11294 | CanvasRenderer.prototype.onMoveEnd = function onMoveEnd() {
|
11295 | this.setToRedraw();
|
11296 | };
|
11297 |
|
11298 | CanvasRenderer.prototype.onResize = function onResize() {
|
11299 | delete this._extent2D;
|
11300 | this.resizeCanvas();
|
11301 | this.setToRedraw();
|
11302 | };
|
11303 |
|
11304 | CanvasRenderer.prototype.onDragRotateStart = function onDragRotateStart() {};
|
11305 |
|
11306 | CanvasRenderer.prototype.onDragRotating = function onDragRotating() {};
|
11307 |
|
11308 | CanvasRenderer.prototype.onDragRotateEnd = function onDragRotateEnd() {
|
11309 | this.setToRedraw();
|
11310 | };
|
11311 |
|
11312 | CanvasRenderer.prototype.onSpatialReferenceChange = function onSpatialReferenceChange() {};
|
11313 |
|
11314 | CanvasRenderer.prototype.getDrawTime = function getDrawTime() {
|
11315 | return this._drawTime;
|
11316 | };
|
11317 |
|
11318 | CanvasRenderer.prototype._tryToDraw = function _tryToDraw(framestamp) {
|
11319 | this._toRedraw = false;
|
11320 | if (!this.canvas && this.layer.isEmpty && this.layer.isEmpty()) {
|
11321 | this._renderComplete = true;
|
11322 |
|
11323 | return;
|
11324 | }
|
11325 | this._drawAndRecord(framestamp);
|
11326 | };
|
11327 |
|
11328 | CanvasRenderer.prototype._drawAndRecord = function _drawAndRecord(framestamp) {
|
11329 | if (!this.getMap()) {
|
11330 | return;
|
11331 | }
|
11332 | var painted = this._painted;
|
11333 | this._painted = true;
|
11334 | var t = now();
|
11335 | this.draw(framestamp);
|
11336 | t = now() - t;
|
11337 |
|
11338 | this._drawTime = painted ? t : t / 2;
|
11339 | if (painted && this.layer.options['logDrawTime']) {
|
11340 | console.log(this.layer.getId(), 'frameTimeStamp:', framestamp, 'drawTime:', this._drawTime);
|
11341 | }
|
11342 | };
|
11343 |
|
11344 | CanvasRenderer.prototype._promiseResource = function _promiseResource(url) {
|
11345 | var me = this,
|
11346 | resources = this.resources,
|
11347 | crossOrigin = this.layer.options['crossOrigin'];
|
11348 | return function (resolve) {
|
11349 | if (resources.isResourceLoaded(url, true)) {
|
11350 | resolve(url);
|
11351 | return;
|
11352 | }
|
11353 | var img = new Image();
|
11354 | if (!isNil(crossOrigin)) {
|
11355 | img['crossOrigin'] = crossOrigin;
|
11356 | }
|
11357 | if (isSVG(url[0]) && !IS_NODE) {
|
11358 | if (url[1]) {
|
11359 | url[1] *= 2;
|
11360 | }
|
11361 | if (url[2]) {
|
11362 | url[2] *= 2;
|
11363 | }
|
11364 | }
|
11365 | img.onload = function () {
|
11366 | me._cacheResource(url, img);
|
11367 | resolve(url);
|
11368 | };
|
11369 | img.onabort = function (err) {
|
11370 | if (console) {
|
11371 | console.warn('image loading aborted: ' + url[0]);
|
11372 | }
|
11373 | if (err) {
|
11374 | if (console) {
|
11375 | console.warn(err);
|
11376 | }
|
11377 | }
|
11378 | resolve(url);
|
11379 | };
|
11380 | img.onerror = function (err) {
|
11381 | if (err && typeof console !== 'undefined') {
|
11382 | console.warn(err);
|
11383 | }
|
11384 | resources.markErrorResource(url);
|
11385 | resolve(url);
|
11386 | };
|
11387 | loadImage(img, url);
|
11388 | };
|
11389 | };
|
11390 |
|
11391 | CanvasRenderer.prototype._cacheResource = function _cacheResource(url, img) {
|
11392 | if (!this.layer || !this.resources) {
|
11393 | return;
|
11394 | }
|
11395 | var w = url[1],
|
11396 | h = url[2];
|
11397 | if (this.layer.options['cacheSvgOnCanvas'] && isSVG(url[0]) === 1 && (Browser$1.edge || Browser$1.ie)) {
|
11398 | if (isNil(w)) {
|
11399 | w = img.width || this.layer.options['defaultIconSize'][0];
|
11400 | }
|
11401 | if (isNil(h)) {
|
11402 | h = img.height || this.layer.options['defaultIconSize'][1];
|
11403 | }
|
11404 | var canvas = Canvas.createCanvas(w, h);
|
11405 | Canvas.image(canvas.getContext('2d'), img, 0, 0, w, h);
|
11406 | img = canvas;
|
11407 | }
|
11408 | this.resources.addResource(url, img);
|
11409 | };
|
11410 |
|
11411 | return CanvasRenderer;
|
11412 | }(Class);
|
11413 |
|
11414 | var ResourceCache = function () {
|
11415 | function ResourceCache() {
|
11416 | classCallCheck(this, ResourceCache);
|
11417 |
|
11418 | this.resources = {};
|
11419 | this._errors = {};
|
11420 | }
|
11421 |
|
11422 | ResourceCache.prototype.addResource = function addResource(url, img) {
|
11423 | this.resources[url[0]] = {
|
11424 | image: img,
|
11425 | width: +url[1],
|
11426 | height: +url[2]
|
11427 | };
|
11428 | };
|
11429 |
|
11430 | ResourceCache.prototype.isResourceLoaded = function isResourceLoaded(url, checkSVG) {
|
11431 | if (!url) {
|
11432 | return false;
|
11433 | }
|
11434 | var imgUrl = this._getImgUrl(url);
|
11435 | if (this._errors[imgUrl]) {
|
11436 | return true;
|
11437 | }
|
11438 | var img = this.resources[imgUrl];
|
11439 | if (!img) {
|
11440 | return false;
|
11441 | }
|
11442 | if (checkSVG && isSVG(url[0]) && (+url[1] > img.width || +url[2] > img.height)) {
|
11443 | return false;
|
11444 | }
|
11445 | return true;
|
11446 | };
|
11447 |
|
11448 | ResourceCache.prototype.getImage = function getImage(url) {
|
11449 | var imgUrl = this._getImgUrl(url);
|
11450 | if (!this.isResourceLoaded(url) || this._errors[imgUrl]) {
|
11451 | return null;
|
11452 | }
|
11453 | return this.resources[imgUrl].image;
|
11454 | };
|
11455 |
|
11456 | ResourceCache.prototype.markErrorResource = function markErrorResource(url) {
|
11457 | this._errors[this._getImgUrl(url)] = 1;
|
11458 | };
|
11459 |
|
11460 | ResourceCache.prototype.merge = function merge(res) {
|
11461 | if (!res) {
|
11462 | return this;
|
11463 | }
|
11464 | for (var p in res.resources) {
|
11465 | var img = res.resources[p];
|
11466 | this.addResource([p, img.width, img.height], img.image);
|
11467 | }
|
11468 | return this;
|
11469 | };
|
11470 |
|
11471 | ResourceCache.prototype.forEach = function forEach(fn) {
|
11472 | if (!this.resources) {
|
11473 | return this;
|
11474 | }
|
11475 | for (var p in this.resources) {
|
11476 | if (hasOwn(this.resources, p)) {
|
11477 | fn(p, this.resources[p]);
|
11478 | }
|
11479 | }
|
11480 | return this;
|
11481 | };
|
11482 |
|
11483 | ResourceCache.prototype._getImgUrl = function _getImgUrl(url) {
|
11484 | if (!Array.isArray(url)) {
|
11485 | return url;
|
11486 | }
|
11487 | return url[0];
|
11488 | };
|
11489 |
|
11490 | return ResourceCache;
|
11491 | }();
|
11492 |
|
11493 | var options$1 = {
|
11494 | 'attribution': null,
|
11495 | 'minZoom': null,
|
11496 | 'maxZoom': null,
|
11497 | 'visible': true,
|
11498 | 'opacity': 1,
|
11499 |
|
11500 | 'globalCompositeOperation': null,
|
11501 | 'renderer': 'canvas',
|
11502 | 'debugOutline': '#0f0',
|
11503 | 'cssFilter': null,
|
11504 | 'forceRenderOnMoving': false,
|
11505 | 'forceRenderOnZooming': false,
|
11506 | 'forceRenderOnRotating': false
|
11507 | };
|
11508 |
|
11509 | var Layer = function (_JSONAble) {
|
11510 | inherits(Layer, _JSONAble);
|
11511 |
|
11512 | function Layer(id, options) {
|
11513 | classCallCheck(this, Layer);
|
11514 |
|
11515 | var canvas = void 0;
|
11516 | if (options) {
|
11517 | canvas = options.canvas;
|
11518 | delete options.canvas;
|
11519 | }
|
11520 |
|
11521 | var _this = possibleConstructorReturn(this, _JSONAble.call(this, options));
|
11522 |
|
11523 | if (canvas) {
|
11524 | _this._canvas = canvas;
|
11525 | }
|
11526 | _this.setId(id);
|
11527 | if (options) {
|
11528 | _this.setZIndex(options.zIndex);
|
11529 | }
|
11530 | return _this;
|
11531 | }
|
11532 |
|
11533 | Layer.prototype.load = function load() {
|
11534 | if (!this.getMap()) {
|
11535 | return this;
|
11536 | }
|
11537 | if (this.onLoad()) {
|
11538 | this._initRenderer();
|
11539 | var zIndex = this.getZIndex();
|
11540 | if (!isNil(zIndex)) {
|
11541 | this._renderer.setZIndex(zIndex);
|
11542 | if (!this.isCanvasRender()) {
|
11543 | this._renderer.render();
|
11544 | }
|
11545 | }
|
11546 | this.onLoadEnd();
|
11547 | }
|
11548 | return this;
|
11549 | };
|
11550 |
|
11551 | Layer.prototype.getId = function getId() {
|
11552 | return this._id;
|
11553 | };
|
11554 |
|
11555 | Layer.prototype.setId = function setId(id) {
|
11556 | var old = this._id;
|
11557 | if (!isNil(id)) {
|
11558 | id = id + '';
|
11559 | }
|
11560 | this._id = id;
|
11561 |
|
11562 | this.fire('idchange', {
|
11563 | 'old': old,
|
11564 | 'new': id
|
11565 | });
|
11566 | return this;
|
11567 | };
|
11568 |
|
11569 | Layer.prototype.addTo = function addTo(map) {
|
11570 | map.addLayer(this);
|
11571 | return this;
|
11572 | };
|
11573 |
|
11574 | Layer.prototype.setZIndex = function setZIndex(zIndex) {
|
11575 | this._zIndex = zIndex;
|
11576 | if (this.map) {
|
11577 | this.map._sortLayersByZIndex();
|
11578 | }
|
11579 | if (this._renderer) {
|
11580 | this._renderer.setZIndex(zIndex);
|
11581 | }
|
11582 | return this;
|
11583 | };
|
11584 |
|
11585 | Layer.prototype.getZIndex = function getZIndex() {
|
11586 | return this._zIndex || 0;
|
11587 | };
|
11588 |
|
11589 | Layer.prototype.getMinZoom = function getMinZoom() {
|
11590 | var map = this.getMap();
|
11591 | var minZoom = this.options['minZoom'];
|
11592 | return map ? Math.max(map.getMinZoom(), minZoom || 0) : minZoom;
|
11593 | };
|
11594 |
|
11595 | Layer.prototype.getMaxZoom = function getMaxZoom() {
|
11596 | var map = this.getMap();
|
11597 | var maxZoom = this.options['maxZoom'];
|
11598 | return map ? Math.min(map.getMaxZoom(), isNil(maxZoom) ? Infinity : maxZoom) : maxZoom;
|
11599 | };
|
11600 |
|
11601 | Layer.prototype.getOpacity = function getOpacity() {
|
11602 | return this.options['opacity'];
|
11603 | };
|
11604 |
|
11605 | Layer.prototype.setOpacity = function setOpacity(op) {
|
11606 | this.config('opacity', op);
|
11607 | return this;
|
11608 | };
|
11609 |
|
11610 | Layer.prototype.isCanvasRender = function isCanvasRender() {
|
11611 | var renderer = this._getRenderer();
|
11612 | return renderer && renderer instanceof CanvasRenderer;
|
11613 | };
|
11614 |
|
11615 | Layer.prototype.getMap = function getMap() {
|
11616 | if (this.map) {
|
11617 | return this.map;
|
11618 | }
|
11619 | return null;
|
11620 | };
|
11621 |
|
11622 | Layer.prototype.getProjection = function getProjection() {
|
11623 | var map = this.getMap();
|
11624 | return map ? map.getProjection() : null;
|
11625 | };
|
11626 |
|
11627 | Layer.prototype.bringToFront = function bringToFront() {
|
11628 | var layers = this._getLayerList();
|
11629 | if (!layers.length) {
|
11630 | return this;
|
11631 | }
|
11632 | var topLayer = layers[layers.length - 1];
|
11633 | if (layers.length === 1 || topLayer === this) {
|
11634 | return this;
|
11635 | }
|
11636 | var max = topLayer.getZIndex();
|
11637 | this.setZIndex(max + 1);
|
11638 | return this;
|
11639 | };
|
11640 |
|
11641 | Layer.prototype.bringToBack = function bringToBack() {
|
11642 | var layers = this._getLayerList();
|
11643 | if (!layers.length) {
|
11644 | return this;
|
11645 | }
|
11646 | var bottomLayer = layers[0];
|
11647 | if (layers.length === 1 || bottomLayer === this) {
|
11648 | return this;
|
11649 | }
|
11650 | var min = bottomLayer.getZIndex();
|
11651 | this.setZIndex(min - 1);
|
11652 | return this;
|
11653 | };
|
11654 |
|
11655 | Layer.prototype.show = function show() {
|
11656 | var _this2 = this;
|
11657 |
|
11658 | if (!this.options['visible']) {
|
11659 | this.options['visible'] = true;
|
11660 | var renderer = this.getRenderer();
|
11661 | if (renderer) {
|
11662 | renderer.show();
|
11663 | }
|
11664 |
|
11665 | var map = this.getMap();
|
11666 | if (renderer && map) {
|
11667 | map.once('renderend', function () {
|
11668 | _this2.fire('show');
|
11669 | });
|
11670 | } else {
|
11671 | this.fire('show');
|
11672 | }
|
11673 | }
|
11674 | return this;
|
11675 | };
|
11676 |
|
11677 | Layer.prototype.hide = function hide() {
|
11678 | var _this3 = this;
|
11679 |
|
11680 | if (this.options['visible']) {
|
11681 | this.options['visible'] = false;
|
11682 | var renderer = this.getRenderer();
|
11683 | if (renderer) {
|
11684 | renderer.hide();
|
11685 | }
|
11686 |
|
11687 | var map = this.getMap();
|
11688 | if (renderer && map) {
|
11689 | map.once('renderend', function () {
|
11690 | _this3.fire('hide');
|
11691 | });
|
11692 | } else {
|
11693 | this.fire('hide');
|
11694 | }
|
11695 | }
|
11696 |
|
11697 | return this;
|
11698 | };
|
11699 |
|
11700 | Layer.prototype.isVisible = function isVisible() {
|
11701 | if (isNumber(this.options['opacity']) && this.options['opacity'] <= 0) {
|
11702 | return false;
|
11703 | }
|
11704 | var map = this.getMap();
|
11705 | if (map) {
|
11706 | var zoom = map.getZoom();
|
11707 | if (!isNil(this.options['maxZoom']) && this.options['maxZoom'] < zoom || !isNil(this.options['minZoom']) && this.options['minZoom'] > zoom) {
|
11708 | return false;
|
11709 | }
|
11710 | }
|
11711 |
|
11712 | if (isNil(this.options['visible'])) {
|
11713 | this.options['visible'] = true;
|
11714 | }
|
11715 | return this.options['visible'];
|
11716 | };
|
11717 |
|
11718 | Layer.prototype.remove = function remove() {
|
11719 | if (this.map) {
|
11720 | this.map.removeLayer(this);
|
11721 | }
|
11722 | return this;
|
11723 | };
|
11724 |
|
11725 | Layer.prototype.getMask = function getMask() {
|
11726 | return this._mask;
|
11727 | };
|
11728 |
|
11729 | Layer.prototype.setMask = function setMask(mask) {
|
11730 | if (!(mask.type === 'Point' && mask._isVectorMarker() || mask.type === 'Polygon')) {
|
11731 | throw new Error('Mask for a layer must be a marker with vector marker symbol or a Polygon.');
|
11732 | }
|
11733 |
|
11734 | if (mask.type === 'Point') {
|
11735 | mask.updateSymbol({
|
11736 | 'markerLineColor': 'rgba(0, 0, 0, 0)',
|
11737 | 'markerFillOpacity': 0
|
11738 | });
|
11739 | } else {
|
11740 | mask.setSymbol({
|
11741 | 'lineColor': 'rgba(0, 0, 0, 0)',
|
11742 | 'polygonOpacity': 0
|
11743 | });
|
11744 | }
|
11745 | mask._bindLayer(this);
|
11746 | this._mask = mask;
|
11747 | if (!this.getMap() || this.getMap().isZooming()) {
|
11748 | return this;
|
11749 | }
|
11750 | var renderer = this._getRenderer();
|
11751 | if (renderer && renderer.setToRedraw) {
|
11752 | this._getRenderer().setToRedraw();
|
11753 | }
|
11754 | return this;
|
11755 | };
|
11756 |
|
11757 | Layer.prototype.removeMask = function removeMask() {
|
11758 | delete this._mask;
|
11759 | if (!this.getMap() || this.getMap().isZooming()) {
|
11760 | return this;
|
11761 | }
|
11762 | var renderer = this._getRenderer();
|
11763 | if (renderer && renderer.setToRedraw) {
|
11764 | this._getRenderer().setToRedraw();
|
11765 | }
|
11766 | return this;
|
11767 | };
|
11768 |
|
11769 | Layer.prototype.onLoad = function onLoad() {
|
11770 | return true;
|
11771 | };
|
11772 |
|
11773 | Layer.prototype.onLoadEnd = function onLoadEnd() {};
|
11774 |
|
11775 | Layer.prototype.isLoaded = function isLoaded() {
|
11776 | return !!this._loaded;
|
11777 | };
|
11778 |
|
11779 | Layer.prototype.getRenderer = function getRenderer() {
|
11780 | return this._getRenderer();
|
11781 | };
|
11782 |
|
11783 | Layer.prototype.onConfig = function onConfig(conf) {
|
11784 | if (isNumber(conf['opacity']) || conf['cssFilter']) {
|
11785 | var renderer = this.getRenderer();
|
11786 | if (renderer) {
|
11787 | renderer.setToRedraw();
|
11788 | }
|
11789 | }
|
11790 | };
|
11791 |
|
11792 | Layer.prototype.onAdd = function onAdd() {};
|
11793 |
|
11794 | Layer.prototype.onRemove = function onRemove() {};
|
11795 |
|
11796 | Layer.prototype._bindMap = function _bindMap(map, zIndex) {
|
11797 | if (!map) {
|
11798 | return;
|
11799 | }
|
11800 | this.map = map;
|
11801 | if (!isNil(zIndex)) {
|
11802 | this.setZIndex(zIndex);
|
11803 | }
|
11804 | this._switchEvents('on', this);
|
11805 |
|
11806 | this.onAdd();
|
11807 |
|
11808 | this.fire('add');
|
11809 | };
|
11810 |
|
11811 | Layer.prototype._initRenderer = function _initRenderer() {
|
11812 | var renderer = this.options['renderer'];
|
11813 | if (!this.constructor.getRendererClass) {
|
11814 | return;
|
11815 | }
|
11816 | var clazz = this.constructor.getRendererClass(renderer);
|
11817 | if (!clazz) {
|
11818 | throw new Error('Invalid renderer for Layer(' + this.getId() + '):' + renderer);
|
11819 | }
|
11820 | this._renderer = new clazz(this);
|
11821 | this._renderer.layer = this;
|
11822 | this._renderer.setZIndex(this.getZIndex());
|
11823 | this._switchEvents('on', this._renderer);
|
11824 |
|
11825 | if (this._renderer.onAdd) {
|
11826 | this._renderer.onAdd();
|
11827 | }
|
11828 |
|
11829 | this.fire('renderercreate', {
|
11830 | 'renderer': this._renderer
|
11831 | });
|
11832 | };
|
11833 |
|
11834 | Layer.prototype._doRemove = function _doRemove() {
|
11835 | this._loaded = false;
|
11836 | this.onRemove();
|
11837 |
|
11838 | this._switchEvents('off', this);
|
11839 | if (this._renderer) {
|
11840 | this._switchEvents('off', this._renderer);
|
11841 | this._renderer.remove();
|
11842 | delete this._renderer;
|
11843 | }
|
11844 | delete this._mask;
|
11845 | delete this.map;
|
11846 | };
|
11847 |
|
11848 | Layer.prototype._switchEvents = function _switchEvents(to, emitter) {
|
11849 | if (emitter && emitter.getEvents) {
|
11850 | this.getMap()[to](emitter.getEvents(), emitter);
|
11851 | }
|
11852 | };
|
11853 |
|
11854 | Layer.prototype._getRenderer = function _getRenderer() {
|
11855 | return this._renderer;
|
11856 | };
|
11857 |
|
11858 | Layer.prototype._getLayerList = function _getLayerList() {
|
11859 | if (!this.map) {
|
11860 | return [];
|
11861 | }
|
11862 | return this.map._layers;
|
11863 | };
|
11864 |
|
11865 | Layer.prototype._getMask2DExtent = function _getMask2DExtent() {
|
11866 | if (!this._mask || !this.getMap()) {
|
11867 | return null;
|
11868 | }
|
11869 | var painter = this._mask._getPainter();
|
11870 | if (!painter) {
|
11871 | return null;
|
11872 | }
|
11873 | return painter.get2DExtent();
|
11874 | };
|
11875 |
|
11876 | return Layer;
|
11877 | }(JSONAble(Eventable(Renderable(Class))));
|
11878 |
|
11879 | Layer.mergeOptions(options$1);
|
11880 |
|
11881 | var fire = Layer.prototype.fire;
|
11882 |
|
11883 | Layer.prototype.fire = function (eventType, param) {
|
11884 | if (eventType === 'layerload') {
|
11885 | this._loaded = true;
|
11886 | }
|
11887 | if (this.map) {
|
11888 | if (!param) {
|
11889 | param = {};
|
11890 | }
|
11891 | param['type'] = eventType;
|
11892 | param['target'] = this;
|
11893 | this.map._onLayerEvent(param);
|
11894 | }
|
11895 | return fire.apply(this, arguments);
|
11896 | };
|
11897 |
|
11898 | var DefaultSpatialRef = {
|
11899 | 'EPSG:3857': {
|
11900 | 'resolutions': function () {
|
11901 | var resolutions = [];
|
11902 | var d = 2 * 6378137 * Math.PI;
|
11903 | for (var i = 0; i < 21; i++) {
|
11904 | resolutions[i] = d / (256 * Math.pow(2, i));
|
11905 | }
|
11906 | return resolutions;
|
11907 | }(),
|
11908 | 'fullExtent': {
|
11909 | 'top': 6378137 * Math.PI,
|
11910 | 'left': -6378137 * Math.PI,
|
11911 | 'bottom': -6378137 * Math.PI,
|
11912 | 'right': 6378137 * Math.PI
|
11913 | }
|
11914 | },
|
11915 | 'EPSG:4326': {
|
11916 | 'fullExtent': {
|
11917 | 'top': 90,
|
11918 | 'left': -180,
|
11919 | 'bottom': -90,
|
11920 | 'right': 180
|
11921 | },
|
11922 | 'resolutions': function () {
|
11923 | var resolutions = [];
|
11924 | for (var i = 0; i < 20; i++) {
|
11925 | resolutions[i] = 180 / (Math.pow(2, i) * 128);
|
11926 | }
|
11927 | return resolutions;
|
11928 | }()
|
11929 | },
|
11930 | 'BAIDU': {
|
11931 | 'resolutions': function () {
|
11932 | var res = Math.pow(2, 18);
|
11933 | var resolutions = [];
|
11934 | for (var i = 0; i < 20; i++) {
|
11935 | resolutions[i] = res;
|
11936 | res *= 0.5;
|
11937 | }
|
11938 | resolutions[0] = null;
|
11939 | resolutions[1] = null;
|
11940 | resolutions[2] = null;
|
11941 | return resolutions;
|
11942 | }(),
|
11943 | 'fullExtent': {
|
11944 | 'top': 33554432,
|
11945 | 'left': -33554432,
|
11946 | 'bottom': -33554432,
|
11947 | 'right': 33554432
|
11948 | }
|
11949 | },
|
11950 | 'IDENTITY': {
|
11951 | 'resolutions': function () {
|
11952 | var res = Math.pow(2, 8);
|
11953 | var resolutions = [];
|
11954 | for (var i = 0; i < 18; i++) {
|
11955 | resolutions[i] = res;
|
11956 | res *= 0.5;
|
11957 | }
|
11958 | return resolutions;
|
11959 | }(),
|
11960 | 'fullExtent': {
|
11961 | 'top': 200000,
|
11962 | 'left': -200000,
|
11963 | 'bottom': -200000,
|
11964 | 'right': 200000
|
11965 | }
|
11966 | }
|
11967 | };
|
11968 |
|
11969 | DefaultSpatialRef['EPSG:4490'] = DefaultSpatialRef['EPSG:4326'];
|
11970 |
|
11971 | var SpatialReference = function () {
|
11972 | function SpatialReference() {
|
11973 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
11974 | classCallCheck(this, SpatialReference);
|
11975 |
|
11976 | this.options = options;
|
11977 | this._initSpatialRef();
|
11978 | }
|
11979 |
|
11980 | SpatialReference.getProjectionInstance = function getProjectionInstance(prjName) {
|
11981 | if (!prjName) {
|
11982 | return null;
|
11983 | }
|
11984 | if (isObject(prjName)) {
|
11985 | return prjName;
|
11986 | }
|
11987 | prjName = (prjName + '').toLowerCase();
|
11988 | for (var p in projections) {
|
11989 | if (hasOwn(projections, p)) {
|
11990 | var code = projections[p]['code'];
|
11991 | if (code && code.toLowerCase() === prjName) {
|
11992 | return projections[p];
|
11993 | }
|
11994 | }
|
11995 | }
|
11996 | return null;
|
11997 | };
|
11998 |
|
11999 | SpatialReference.equals = function equals(sp1, sp2) {
|
12000 | if (!sp1 && !sp2) {
|
12001 | return true;
|
12002 | } else if (!sp1 || !sp2) {
|
12003 | return false;
|
12004 | }
|
12005 | if (sp1.projection !== sp2.projection) {
|
12006 | return false;
|
12007 | }
|
12008 | var f1 = sp1.fullExtent,
|
12009 | f2 = sp2.fullExtent;
|
12010 | if (f1 && f2) {
|
12011 | if (f1.top !== f2.top || f1.bottom !== f2.bottom || f1.left !== f2.left || f1.right !== f2.right) {
|
12012 | return false;
|
12013 | }
|
12014 | }
|
12015 | var r1 = sp1.resolutions,
|
12016 | r2 = sp2.resolutions;
|
12017 | if (r1 && r2) {
|
12018 | if (r1.length !== r2.length) {
|
12019 | return false;
|
12020 | }
|
12021 | for (var i = 0; i < r1.length; i++) {
|
12022 | if (r1[i] !== r2[i]) {
|
12023 | return false;
|
12024 | }
|
12025 | }
|
12026 | }
|
12027 | return true;
|
12028 | };
|
12029 |
|
12030 | SpatialReference.prototype._initSpatialRef = function _initSpatialRef() {
|
12031 | var projection = this.options['projection'];
|
12032 | if (projection) {
|
12033 | projection = SpatialReference.getProjectionInstance(projection);
|
12034 | } else {
|
12035 | projection = DEFAULT;
|
12036 | }
|
12037 | if (!projection) {
|
12038 | throw new Error('must provide a valid projection in map\'s spatial reference.');
|
12039 | }
|
12040 | projection = extend({}, Common, projection);
|
12041 | if (!projection.measureLength) {
|
12042 | extend(projection, Measurer.DEFAULT);
|
12043 | }
|
12044 | this._projection = projection;
|
12045 | var defaultSpatialRef = void 0,
|
12046 | resolutions = this.options['resolutions'];
|
12047 | if (!resolutions) {
|
12048 | if (projection['code']) {
|
12049 | defaultSpatialRef = DefaultSpatialRef[projection['code']];
|
12050 | if (defaultSpatialRef) {
|
12051 | resolutions = defaultSpatialRef['resolutions'];
|
12052 | }
|
12053 | }
|
12054 | if (!resolutions) {
|
12055 | throw new Error('must provide valid resolutions in map\'s spatial reference.');
|
12056 | }
|
12057 | }
|
12058 | this._resolutions = resolutions;
|
12059 | var fullExtent = this.options['fullExtent'];
|
12060 | if (!fullExtent) {
|
12061 | if (projection['code']) {
|
12062 | defaultSpatialRef = DefaultSpatialRef[projection['code']];
|
12063 | if (defaultSpatialRef) {
|
12064 | fullExtent = defaultSpatialRef['fullExtent'];
|
12065 | }
|
12066 | }
|
12067 | if (!fullExtent) {
|
12068 | throw new Error('must provide a valid fullExtent in map\'s spatial reference.');
|
12069 | }
|
12070 | }
|
12071 | if (!isNil(fullExtent['left'])) {
|
12072 | this._fullExtent = new Extent(new Coordinate(fullExtent['left'], fullExtent['top']), new Coordinate(fullExtent['right'], fullExtent['bottom']));
|
12073 | } else {
|
12074 | this._fullExtent = new Extent(fullExtent);
|
12075 | fullExtent['left'] = fullExtent['xmin'];
|
12076 | fullExtent['right'] = fullExtent['xmax'];
|
12077 | fullExtent['top'] = fullExtent['ymax'];
|
12078 | fullExtent['bottom'] = fullExtent['ymin'];
|
12079 | }
|
12080 |
|
12081 | if (isNil(fullExtent['top']) || isNil(fullExtent['bottom']) || isNil(fullExtent['left']) || isNil(fullExtent['right'])) {
|
12082 | throw new Error('must provide valid top/bottom/left/right in fullExtent.');
|
12083 | }
|
12084 |
|
12085 | extend(this._fullExtent, fullExtent);
|
12086 |
|
12087 | this._projection.fullExtent = fullExtent;
|
12088 |
|
12089 | var a = fullExtent['right'] >= fullExtent['left'] ? 1 : -1,
|
12090 | b = fullExtent['top'] >= fullExtent['bottom'] ? -1 : 1;
|
12091 | this._transformation = new Transformation([a, b, 0, 0]);
|
12092 | };
|
12093 |
|
12094 | SpatialReference.prototype.getResolutions = function getResolutions() {
|
12095 | return this._resolutions || [];
|
12096 | };
|
12097 |
|
12098 | SpatialReference.prototype.getResolution = function getResolution(zoom) {
|
12099 | var z = zoom | 0;
|
12100 | if (z < 0) {
|
12101 | z = 0;
|
12102 | } else if (z > this._resolutions.length - 1) {
|
12103 | z = this._resolutions.length - 1;
|
12104 | }
|
12105 | var res = this._resolutions[z];
|
12106 | if (!isInteger(zoom) && z !== this._resolutions.length - 1) {
|
12107 | var next = this._resolutions[z + 1];
|
12108 | return res + (next - res) * (zoom - z);
|
12109 | }
|
12110 | return res;
|
12111 | };
|
12112 |
|
12113 | SpatialReference.prototype.getProjection = function getProjection() {
|
12114 | return this._projection;
|
12115 | };
|
12116 |
|
12117 | SpatialReference.prototype.getFullExtent = function getFullExtent() {
|
12118 | return this._fullExtent;
|
12119 | };
|
12120 |
|
12121 | SpatialReference.prototype.getTransformation = function getTransformation() {
|
12122 | return this._transformation;
|
12123 | };
|
12124 |
|
12125 | SpatialReference.prototype.getMinZoom = function getMinZoom() {
|
12126 | for (var i = 0; i < this._resolutions.length; i++) {
|
12127 | if (!isNil(this._resolutions[i])) {
|
12128 | return i;
|
12129 | }
|
12130 | }
|
12131 | return 0;
|
12132 | };
|
12133 |
|
12134 | SpatialReference.prototype.getMaxZoom = function getMaxZoom() {
|
12135 | for (var i = this._resolutions.length - 1; i >= 0; i--) {
|
12136 | if (!isNil(this._resolutions[i])) {
|
12137 | return i;
|
12138 | }
|
12139 | }
|
12140 | return this._resolutions.length - 1;
|
12141 | };
|
12142 |
|
12143 | SpatialReference.prototype.getZoomDirection = function getZoomDirection() {
|
12144 | return sign(this._resolutions[this.getMinZoom()] - this._resolutions[this.getMaxZoom()]);
|
12145 | };
|
12146 |
|
12147 | SpatialReference.prototype.toJSON = function toJSON() {
|
12148 | if (!this.json) {
|
12149 | this.json = {
|
12150 | 'resolutions': this._resolutions,
|
12151 | 'fullExtent': {
|
12152 | 'top': this._fullExtent.top,
|
12153 | 'left': this._fullExtent.left,
|
12154 | 'bottom': this._fullExtent.bottom,
|
12155 | 'right': this._fullExtent.right
|
12156 | },
|
12157 | 'projection': this._projection.code
|
12158 | };
|
12159 | }
|
12160 | return this.json;
|
12161 | };
|
12162 |
|
12163 | return SpatialReference;
|
12164 | }();
|
12165 |
|
12166 | var options = {
|
12167 | 'maxVisualPitch': 60,
|
12168 | 'maxPitch': 80,
|
12169 | 'centerCross': false,
|
12170 |
|
12171 | 'zoomInCenter': false,
|
12172 | 'zoomAnimation': function () {
|
12173 | return !IS_NODE;
|
12174 | }(),
|
12175 | 'zoomAnimationDuration': 330,
|
12176 |
|
12177 | 'panAnimation': function () {
|
12178 | return !IS_NODE;
|
12179 | }(),
|
12180 |
|
12181 | 'panAnimationDuration': 600,
|
12182 |
|
12183 | 'zoomable': true,
|
12184 | 'enableInfoWindow': true,
|
12185 |
|
12186 | 'hitDetect': function () {
|
12187 | return !Browser$1.mobile;
|
12188 | }(),
|
12189 |
|
12190 | 'hitDetectLimit': 5,
|
12191 |
|
12192 | 'fpsOnInteracting': 25,
|
12193 |
|
12194 | 'layerCanvasLimitOnInteracting': -1,
|
12195 |
|
12196 | 'maxZoom': null,
|
12197 | 'minZoom': null,
|
12198 | 'maxExtent': null,
|
12199 |
|
12200 | 'checkSize': true,
|
12201 |
|
12202 | 'renderer': 'canvas'
|
12203 | };
|
12204 |
|
12205 | var Map = function (_Handlerable) {
|
12206 | inherits(Map, _Handlerable);
|
12207 |
|
12208 | function Map(container, options) {
|
12209 | classCallCheck(this, Map);
|
12210 |
|
12211 | if (!options) {
|
12212 | throw new Error('Invalid options when creating map.');
|
12213 | }
|
12214 | if (!options['center']) {
|
12215 | throw new Error('Invalid center when creating map.');
|
12216 | }
|
12217 |
|
12218 | var opts = extend({}, options);
|
12219 | var zoom = opts['zoom'];
|
12220 | delete opts['zoom'];
|
12221 | var center = new Coordinate(opts['center']);
|
12222 | delete opts['center'];
|
12223 |
|
12224 | var baseLayer = opts['baseLayer'];
|
12225 | delete opts['baseLayer'];
|
12226 | var layers = opts['layers'];
|
12227 | delete opts['layers'];
|
12228 |
|
12229 | var _this = possibleConstructorReturn(this, _Handlerable.call(this, opts));
|
12230 |
|
12231 | Object.defineProperty(_this, 'id', {
|
12232 | value: UID(),
|
12233 | writable: false
|
12234 | });
|
12235 |
|
12236 | _this._loaded = false;
|
12237 | _this._initContainer(container);
|
12238 |
|
12239 | _this._panels = {};
|
12240 |
|
12241 | _this._baseLayer = null;
|
12242 | _this._layers = [];
|
12243 |
|
12244 | _this._zoomLevel = zoom;
|
12245 | _this._center = center;
|
12246 |
|
12247 | _this.setSpatialReference(opts['spatialReference'] || opts['view']);
|
12248 |
|
12249 | _this._mapViewPoint = new Point(0, 0);
|
12250 |
|
12251 | _this._initRenderer();
|
12252 | _this._updateMapSize(_this._getContainerDomSize());
|
12253 |
|
12254 | if (baseLayer) {
|
12255 | _this.setBaseLayer(baseLayer);
|
12256 | }
|
12257 | if (layers) {
|
12258 | _this.addLayer(layers);
|
12259 | }
|
12260 |
|
12261 | _this._Load();
|
12262 | return _this;
|
12263 | }
|
12264 |
|
12265 | Map.addOnLoadHook = function addOnLoadHook(fn) {
|
12266 | var args = Array.prototype.slice.call(arguments, 1);
|
12267 | var onload = typeof fn === 'function' ? fn : function () {
|
12268 | this[fn].apply(this, args);
|
12269 | };
|
12270 | this.prototype._onLoadHooks = this.prototype._onLoadHooks || [];
|
12271 | this.prototype._onLoadHooks.push(onload);
|
12272 | return this;
|
12273 | };
|
12274 |
|
12275 | Map.prototype.isLoaded = function isLoaded() {
|
12276 | return !!this._loaded;
|
12277 | };
|
12278 |
|
12279 | Map.prototype.getContainer = function getContainer() {
|
12280 | return this._containerDOM;
|
12281 | };
|
12282 |
|
12283 | Map.prototype.getSpatialReference = function getSpatialReference() {
|
12284 | return this._spatialReference;
|
12285 | };
|
12286 |
|
12287 | Map.prototype.setSpatialReference = function setSpatialReference(ref) {
|
12288 | var oldRef = this.options['spatialReference'];
|
12289 | if (this._loaded && SpatialReference.equals(oldRef, ref)) {
|
12290 | return this;
|
12291 | }
|
12292 | ref = extend({}, ref);
|
12293 | this._center = this.getCenter();
|
12294 | this.options['spatialReference'] = ref;
|
12295 | this._spatialReference = new SpatialReference(ref);
|
12296 | if (this.options['spatialReference'] && isFunction(this.options['spatialReference']['projection'])) {
|
12297 | var projection = this._spatialReference.getProjection();
|
12298 |
|
12299 | this.options['spatialReference']['projection'] = projection['code'];
|
12300 | }
|
12301 | this._resetMapStatus();
|
12302 |
|
12303 | this._fireEvent('spatialreferencechange', {
|
12304 | 'old': oldRef,
|
12305 | 'new': extend({}, this.options['spatialReference'])
|
12306 | });
|
12307 | return this;
|
12308 | };
|
12309 |
|
12310 | Map.prototype.onConfig = function onConfig(conf) {
|
12311 | var ref = conf['spatialReference'] || conf['view'];
|
12312 | if (!isNil(ref)) {
|
12313 | this.setSpatialReference(ref);
|
12314 | }
|
12315 | return this;
|
12316 | };
|
12317 |
|
12318 | Map.prototype.getProjection = function getProjection() {
|
12319 | if (!this._spatialReference) {
|
12320 | return null;
|
12321 | }
|
12322 | return this._spatialReference.getProjection();
|
12323 | };
|
12324 |
|
12325 | Map.prototype.getFullExtent = function getFullExtent() {
|
12326 | if (!this._spatialReference) {
|
12327 | return null;
|
12328 | }
|
12329 | return this._spatialReference.getFullExtent();
|
12330 | };
|
12331 |
|
12332 | Map.prototype.setCursor = function setCursor(cursor) {
|
12333 | delete this._cursor;
|
12334 | this._trySetCursor(cursor);
|
12335 | this._cursor = cursor;
|
12336 | return this;
|
12337 | };
|
12338 |
|
12339 | Map.prototype.resetCursor = function resetCursor() {
|
12340 | return this.setCursor(null);
|
12341 | };
|
12342 |
|
12343 | Map.prototype.getCenter = function getCenter() {
|
12344 | if (!this._loaded || !this._prjCenter) {
|
12345 | return this._center;
|
12346 | }
|
12347 | var projection = this.getProjection();
|
12348 | return projection.unproject(this._prjCenter);
|
12349 | };
|
12350 |
|
12351 | Map.prototype.setCenter = function setCenter(center) {
|
12352 | if (!center) {
|
12353 | return this;
|
12354 | }
|
12355 | center = new Coordinate(center);
|
12356 | if (!this._verifyExtent(center)) {
|
12357 | return this;
|
12358 | }
|
12359 | if (!this._loaded) {
|
12360 | this._center = center;
|
12361 | return this;
|
12362 | }
|
12363 | this.onMoveStart();
|
12364 | var projection = this.getProjection();
|
12365 | var _pcenter = projection.project(center);
|
12366 | this._setPrjCenter(_pcenter);
|
12367 | this.onMoveEnd(this._parseEventFromCoord(this.getCenter()));
|
12368 | return this;
|
12369 | };
|
12370 |
|
12371 | Map.prototype.getSize = function getSize() {
|
12372 | if (isNil(this.width) || isNil(this.height)) {
|
12373 | return this._getContainerDomSize();
|
12374 | }
|
12375 | return new Size(this.width, this.height);
|
12376 | };
|
12377 |
|
12378 | Map.prototype.getContainerExtent = function getContainerExtent() {
|
12379 | var visualHeight = this.height;
|
12380 | var pitch = this.getPitch(),
|
12381 | maxVisualPitch = this.options['maxVisualPitch'];
|
12382 | if (maxVisualPitch && pitch > maxVisualPitch) {
|
12383 | visualHeight = this._getVisualHeight(maxVisualPitch);
|
12384 | }
|
12385 | return new PointExtent(0, this.height - visualHeight, this.width, this.height);
|
12386 | };
|
12387 |
|
12388 | Map.prototype._getVisualHeight = function _getVisualHeight(maxVisualPitch) {
|
12389 | var pitch = this.getPitch();
|
12390 | var visualDistance = this.height / 2 * Math.tan(maxVisualPitch * Math.PI / 180);
|
12391 | return this.height / 2 + visualDistance * Math.tan((90 - pitch) * Math.PI / 180);
|
12392 | };
|
12393 |
|
12394 | Map.prototype.getExtent = function getExtent() {
|
12395 | return this._pointToExtent(this._get2DExtent());
|
12396 | };
|
12397 |
|
12398 | Map.prototype.getProjExtent = function getProjExtent() {
|
12399 | var extent2D = this._get2DExtent();
|
12400 | return new Extent(this._pointToPrj(extent2D.getMin()), this._pointToPrj(extent2D.getMax()));
|
12401 | };
|
12402 |
|
12403 | Map.prototype.getPrjExtent = function getPrjExtent() {
|
12404 | return this.getProjExtent();
|
12405 | };
|
12406 |
|
12407 | Map.prototype.getMaxExtent = function getMaxExtent() {
|
12408 | if (!this.options['maxExtent']) {
|
12409 | return null;
|
12410 | }
|
12411 | return new Extent(this.options['maxExtent'], this.getProjection());
|
12412 | };
|
12413 |
|
12414 | Map.prototype.setMaxExtent = function setMaxExtent(extent) {
|
12415 | if (extent) {
|
12416 | var maxExt = new Extent(extent, this.getProjection());
|
12417 | this.options['maxExtent'] = maxExt;
|
12418 | var center = this.getCenter();
|
12419 | if (!this._verifyExtent(center)) {
|
12420 | this.panTo(maxExt.getCenter());
|
12421 | }
|
12422 | } else {
|
12423 | delete this.options['maxExtent'];
|
12424 | }
|
12425 | return this;
|
12426 | };
|
12427 |
|
12428 | Map.prototype.getZoom = function getZoom() {
|
12429 | return this._zoomLevel;
|
12430 | };
|
12431 |
|
12432 | Map.prototype.getZoomForScale = function getZoomForScale(scale, fromZoom, isFraction) {
|
12433 | var zoom = this.getZoom();
|
12434 | if (isNil(fromZoom)) {
|
12435 | fromZoom = zoom;
|
12436 | }
|
12437 | if (scale === 1 && fromZoom === zoom) {
|
12438 | return zoom;
|
12439 | }
|
12440 | var res = this._getResolution(fromZoom),
|
12441 | targetRes = res / scale;
|
12442 | var scaleZoom = this.getZoomFromRes(targetRes);
|
12443 | if (isFraction) {
|
12444 | return scaleZoom;
|
12445 | } else {
|
12446 | var delta = 1E-6;
|
12447 | return this.getSpatialReference().getZoomDirection() < 0 ? Math.ceil(scaleZoom - delta) : Math.floor(scaleZoom + delta);
|
12448 | }
|
12449 | };
|
12450 |
|
12451 | Map.prototype.getZoomFromRes = function getZoomFromRes(res) {
|
12452 | var resolutions = this._getResolutions(),
|
12453 | minRes = this._getResolution(this.getMinZoom()),
|
12454 | maxRes = this._getResolution(this.getMaxZoom());
|
12455 | if (minRes <= maxRes) {
|
12456 | if (res <= minRes) {
|
12457 | return this.getMinZoom();
|
12458 | } else if (res >= maxRes) {
|
12459 | return this.getMaxZoom();
|
12460 | }
|
12461 | } else if (res >= minRes) {
|
12462 | return this.getMinZoom();
|
12463 | } else if (res <= maxRes) {
|
12464 | return this.getMaxZoom();
|
12465 | }
|
12466 |
|
12467 | var l = resolutions.length;
|
12468 | for (var i = 0; i < l - 1; i++) {
|
12469 | if (!resolutions[i]) {
|
12470 | continue;
|
12471 | }
|
12472 | var gap = resolutions[i + 1] - resolutions[i];
|
12473 | var test = res - resolutions[i];
|
12474 | if (sign(gap) === sign(test) && Math.abs(gap) >= Math.abs(test)) {
|
12475 | return i + test / gap;
|
12476 | }
|
12477 | }
|
12478 | return l - 1;
|
12479 | };
|
12480 |
|
12481 | Map.prototype.setZoom = function setZoom(zoom) {
|
12482 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { 'animation': true };
|
12483 |
|
12484 | if (isNaN(zoom) || isNil(zoom)) {
|
12485 | return this;
|
12486 | }
|
12487 | if (this._loaded && this.options['zoomAnimation'] && options['animation']) {
|
12488 | this._zoomAnimation(zoom);
|
12489 | } else {
|
12490 | this._zoom(zoom);
|
12491 | }
|
12492 | return this;
|
12493 | };
|
12494 |
|
12495 | Map.prototype.getMaxZoom = function getMaxZoom() {
|
12496 | if (!isNil(this.options['maxZoom'])) {
|
12497 | return this.options['maxZoom'];
|
12498 | }
|
12499 | return this.getMaxNativeZoom();
|
12500 | };
|
12501 |
|
12502 | Map.prototype.setMaxZoom = function setMaxZoom(maxZoom) {
|
12503 | var viewMaxZoom = this.getMaxNativeZoom();
|
12504 | if (maxZoom > viewMaxZoom) {
|
12505 | maxZoom = viewMaxZoom;
|
12506 | }
|
12507 | if (maxZoom !== null && maxZoom < this._zoomLevel) {
|
12508 | this.setZoom(maxZoom);
|
12509 | }
|
12510 | this.options['maxZoom'] = maxZoom;
|
12511 | return this;
|
12512 | };
|
12513 |
|
12514 | Map.prototype.getMinZoom = function getMinZoom() {
|
12515 | if (!isNil(this.options['minZoom'])) {
|
12516 | return this.options['minZoom'];
|
12517 | }
|
12518 | return this._spatialReference.getMinZoom();
|
12519 | };
|
12520 |
|
12521 | Map.prototype.setMinZoom = function setMinZoom(minZoom) {
|
12522 | if (minZoom !== null) {
|
12523 | var viewMinZoom = this._spatialReference.getMinZoom();
|
12524 | if (minZoom < viewMinZoom) {
|
12525 | minZoom = viewMinZoom;
|
12526 | }
|
12527 | if (minZoom > this._zoomLevel) {
|
12528 | this.setZoom(minZoom);
|
12529 | }
|
12530 | }
|
12531 | this.options['minZoom'] = minZoom;
|
12532 | return this;
|
12533 | };
|
12534 |
|
12535 | Map.prototype.getMaxNativeZoom = function getMaxNativeZoom() {
|
12536 | var ref = this.getSpatialReference();
|
12537 | if (!ref) {
|
12538 | return null;
|
12539 | }
|
12540 | return ref.getMaxZoom();
|
12541 | };
|
12542 |
|
12543 | Map.prototype.getGLZoom = function getGLZoom() {
|
12544 | return this.getMaxNativeZoom() / 2;
|
12545 | };
|
12546 |
|
12547 | Map.prototype.getGLScale = function getGLScale(zoom) {
|
12548 | if (isNil(zoom)) {
|
12549 | zoom = this.getZoom();
|
12550 | }
|
12551 | return this.getScale(zoom) / this.getScale(this.getGLZoom());
|
12552 | };
|
12553 |
|
12554 | Map.prototype.zoomIn = function zoomIn() {
|
12555 | return this.setZoom(this.getZoom() + 1);
|
12556 | };
|
12557 |
|
12558 | Map.prototype.zoomOut = function zoomOut() {
|
12559 | return this.setZoom(this.getZoom() - 1);
|
12560 | };
|
12561 |
|
12562 | Map.prototype.isZooming = function isZooming() {
|
12563 | return !!this._zooming;
|
12564 | };
|
12565 |
|
12566 | Map.prototype.isInteracting = function isInteracting() {
|
12567 | return this.isZooming() || this.isMoving() || this.isRotating();
|
12568 | };
|
12569 |
|
12570 | Map.prototype.setCenterAndZoom = function setCenterAndZoom(center, zoom) {
|
12571 | if (!isNil(zoom) && this._zoomLevel !== zoom) {
|
12572 | this.setCenter(center);
|
12573 | this.setZoom(zoom, { animation: false });
|
12574 | } else {
|
12575 | this.setCenter(center);
|
12576 | }
|
12577 | return this;
|
12578 | };
|
12579 |
|
12580 | Map.prototype.getFitZoom = function getFitZoom(extent) {
|
12581 | var _this2 = this;
|
12582 |
|
12583 | if (!extent || !(extent instanceof Extent)) {
|
12584 | return this._zoomLevel;
|
12585 | }
|
12586 |
|
12587 | if (extent['xmin'] === extent['xmax'] && extent['ymin'] === extent['ymax']) {
|
12588 | return this.getMaxZoom();
|
12589 | }
|
12590 | var size = this.getSize();
|
12591 | var containerExtent = extent.convertTo(function (p) {
|
12592 | return _this2.coordToContainerPoint(p);
|
12593 | });
|
12594 | var w = containerExtent.getWidth(),
|
12595 | h = containerExtent.getHeight();
|
12596 | var scaleX = size['width'] / w,
|
12597 | scaleY = size['height'] / h;
|
12598 | var scale = this.getSpatialReference().getZoomDirection() < 0 ? Math.max(scaleX, scaleY) : Math.min(scaleX, scaleY);
|
12599 | var zoom = this.getZoomForScale(scale);
|
12600 | return zoom;
|
12601 | };
|
12602 |
|
12603 | Map.prototype.getView = function getView() {
|
12604 | return {
|
12605 | 'center': this.getCenter().toArray(),
|
12606 | 'zoom': this.getZoom(),
|
12607 | 'pitch': this.getPitch(),
|
12608 | 'bearing': this.getBearing()
|
12609 | };
|
12610 | };
|
12611 |
|
12612 | Map.prototype.setView = function setView(view) {
|
12613 | if (!view) {
|
12614 | return this;
|
12615 | }
|
12616 | if (view['center']) {
|
12617 | this.setCenter(view['center']);
|
12618 | }
|
12619 | if (view['zoom']) {
|
12620 | this.setZoom(view['zoom'], { 'animation': false });
|
12621 | }
|
12622 | if (view['pitch']) {
|
12623 | this.setPitch(view['pitch']);
|
12624 | }
|
12625 | if (view['bearing']) {
|
12626 | this.setBearing(view['bearing']);
|
12627 | }
|
12628 | return this;
|
12629 | };
|
12630 |
|
12631 | Map.prototype.getResolution = function getResolution(zoom) {
|
12632 | return this._getResolution(zoom);
|
12633 | };
|
12634 |
|
12635 | Map.prototype.getScale = function getScale(zoom) {
|
12636 | var z = isNil(zoom) ? this.getZoom() : zoom;
|
12637 | var max = this._getResolution(this.getMaxNativeZoom()),
|
12638 | res = this._getResolution(z);
|
12639 | return res / max;
|
12640 | };
|
12641 |
|
12642 | Map.prototype.fitExtent = function fitExtent(extent, zoomOffset) {
|
12643 | if (!extent) {
|
12644 | return this;
|
12645 | }
|
12646 | extent = new Extent(extent, this.getProjection());
|
12647 | var zoom = this.getFitZoom(extent) + (zoomOffset || 0);
|
12648 | var center = extent.getCenter();
|
12649 | return this.setCenterAndZoom(center, zoom);
|
12650 | };
|
12651 |
|
12652 | Map.prototype.getBaseLayer = function getBaseLayer() {
|
12653 | return this._baseLayer;
|
12654 | };
|
12655 |
|
12656 | Map.prototype.setBaseLayer = function setBaseLayer(baseLayer) {
|
12657 | var isChange = false;
|
12658 | if (this._baseLayer) {
|
12659 | isChange = true;
|
12660 |
|
12661 | this._fireEvent('baselayerchangestart');
|
12662 | this._baseLayer.remove();
|
12663 | }
|
12664 | if (!baseLayer) {
|
12665 | delete this._baseLayer;
|
12666 |
|
12667 | this._fireEvent('baselayerchangeend');
|
12668 |
|
12669 | this._fireEvent('setbaselayer');
|
12670 | return this;
|
12671 | }
|
12672 |
|
12673 | this._baseLayer = baseLayer;
|
12674 | baseLayer._bindMap(this, -1);
|
12675 |
|
12676 | function onbaseLayerload() {
|
12677 | this._fireEvent('baselayerload');
|
12678 | if (isChange) {
|
12679 | isChange = false;
|
12680 | this._fireEvent('baselayerchangeend');
|
12681 | }
|
12682 | }
|
12683 | this._baseLayer.on('layerload', onbaseLayerload, this);
|
12684 | if (this._loaded) {
|
12685 | this._baseLayer.load();
|
12686 | }
|
12687 | this._fireEvent('setbaselayer');
|
12688 | return this;
|
12689 | };
|
12690 |
|
12691 | Map.prototype.removeBaseLayer = function removeBaseLayer() {
|
12692 | if (this._baseLayer) {
|
12693 | this._baseLayer.remove();
|
12694 | delete this._baseLayer;
|
12695 |
|
12696 | this._fireEvent('baselayerremove');
|
12697 | }
|
12698 | return this;
|
12699 | };
|
12700 |
|
12701 | Map.prototype.getLayers = function getLayers(filter) {
|
12702 | return this._getLayers(function (layer) {
|
12703 | if (layer === this._baseLayer || layer.getId().indexOf(INTERNAL_LAYER_PREFIX) >= 0) {
|
12704 | return false;
|
12705 | }
|
12706 | if (filter) {
|
12707 | return filter(layer);
|
12708 | }
|
12709 | return true;
|
12710 | });
|
12711 | };
|
12712 |
|
12713 | Map.prototype.getLayer = function getLayer(id) {
|
12714 | if (!id) {
|
12715 | return null;
|
12716 | }
|
12717 | var layer = this._layerCache ? this._layerCache[id] : null;
|
12718 | if (layer) {
|
12719 | return layer;
|
12720 | }
|
12721 | var baseLayer = this.getBaseLayer();
|
12722 | if (baseLayer && baseLayer.getId() === id) {
|
12723 | return baseLayer;
|
12724 | }
|
12725 | return null;
|
12726 | };
|
12727 |
|
12728 | Map.prototype.addLayer = function addLayer(layers) {
|
12729 | if (!layers) {
|
12730 | return this;
|
12731 | }
|
12732 | if (!Array.isArray(layers)) {
|
12733 | layers = Array.prototype.slice.call(arguments, 0);
|
12734 | return this.addLayer(layers);
|
12735 | }
|
12736 | if (!this._layerCache) {
|
12737 | this._layerCache = {};
|
12738 | }
|
12739 | var mapLayers = this._layers;
|
12740 | for (var i = 0, len = layers.length; i < len; i++) {
|
12741 | var layer = layers[i];
|
12742 | var id = layer.getId();
|
12743 | if (isNil(id)) {
|
12744 | throw new Error('Invalid id for the layer: ' + id);
|
12745 | }
|
12746 | if (layer.getMap() === this) {
|
12747 | continue;
|
12748 | }
|
12749 | if (this._layerCache[id]) {
|
12750 | throw new Error('Duplicate layer id in the map: ' + id);
|
12751 | }
|
12752 | this._layerCache[id] = layer;
|
12753 | layer._bindMap(this);
|
12754 | mapLayers.push(layer);
|
12755 | if (this._loaded) {
|
12756 | layer.load();
|
12757 | }
|
12758 | }
|
12759 |
|
12760 | this._sortLayersByZIndex();
|
12761 |
|
12762 | this._fireEvent('addlayer', {
|
12763 | 'layers': layers
|
12764 | });
|
12765 | return this;
|
12766 | };
|
12767 |
|
12768 | Map.prototype.removeLayer = function removeLayer(layers) {
|
12769 | if (!layers) {
|
12770 | return this;
|
12771 | }
|
12772 | if (!Array.isArray(layers)) {
|
12773 | return this.removeLayer([layers]);
|
12774 | }
|
12775 | var removed = [];
|
12776 | for (var i = 0, len = layers.length; i < len; i++) {
|
12777 | var layer = layers[i];
|
12778 | if (!(layer instanceof Layer)) {
|
12779 | layer = this.getLayer(layer);
|
12780 | }
|
12781 | if (!layer) {
|
12782 | continue;
|
12783 | }
|
12784 | var map = layer.getMap();
|
12785 | if (!map || map !== this) {
|
12786 | continue;
|
12787 | }
|
12788 | removed.push(layer);
|
12789 | this._removeLayer(layer, this._layers);
|
12790 | if (this._loaded) {
|
12791 | layer._doRemove();
|
12792 | }
|
12793 | var id = layer.getId();
|
12794 | if (this._layerCache) {
|
12795 | delete this._layerCache[id];
|
12796 | }
|
12797 | }
|
12798 | if (removed.length > 0) {
|
12799 | this.once('frameend', function () {
|
12800 | removed.forEach(function (layer) {
|
12801 | layer.fire('remove');
|
12802 | });
|
12803 | });
|
12804 | }
|
12805 |
|
12806 | this._fireEvent('removelayer', {
|
12807 | 'layers': layers
|
12808 | });
|
12809 | return this;
|
12810 | };
|
12811 |
|
12812 | Map.prototype.sortLayers = function sortLayers(layers) {
|
12813 | if (!layers || !Array.isArray(layers)) {
|
12814 | return this;
|
12815 | }
|
12816 | var layersToOrder = [];
|
12817 | var minZ = Number.MAX_VALUE;
|
12818 | for (var i = 0, l = layers.length; i < l; i++) {
|
12819 | var layer = layers[i];
|
12820 | if (isString(layers[i])) {
|
12821 | layer = this.getLayer(layer);
|
12822 | }
|
12823 | if (!(layer instanceof Layer) || !layer.getMap() || layer.getMap() !== this) {
|
12824 | throw new Error('It must be a layer added to this map to order.');
|
12825 | }
|
12826 | if (layer.getZIndex() < minZ) {
|
12827 | minZ = layer.getZIndex();
|
12828 | }
|
12829 | layersToOrder.push(layer);
|
12830 | }
|
12831 | for (var _i = 0, _l = layersToOrder.length; _i < _l; _i++) {
|
12832 | layersToOrder[_i].setZIndex(minZ + _i);
|
12833 | }
|
12834 |
|
12835 | return this;
|
12836 | };
|
12837 |
|
12838 | Map.prototype.toDataURL = function toDataURL(options) {
|
12839 | if (!options) {
|
12840 | options = {};
|
12841 | }
|
12842 | var mimeType = options['mimeType'];
|
12843 | if (!mimeType) {
|
12844 | mimeType = 'image/png';
|
12845 | }
|
12846 | var save = options['save'];
|
12847 | var renderer = this._getRenderer();
|
12848 | if (renderer && renderer.toDataURL) {
|
12849 | var file = options['fileName'];
|
12850 | if (!file) {
|
12851 | file = 'export';
|
12852 | }
|
12853 | var dataURL = renderer.toDataURL(mimeType);
|
12854 | if (save && dataURL) {
|
12855 | var imgURL = void 0;
|
12856 | if (typeof Blob !== 'undefined' && typeof atob !== 'undefined') {
|
12857 | var blob = b64toBlob(dataURL.replace(/^data:image\/(png|jpeg|jpg);base64,/, ''), mimeType);
|
12858 | imgURL = URL.createObjectURL(blob);
|
12859 | } else {
|
12860 | imgURL = dataURL;
|
12861 | }
|
12862 | var dlLink = document.createElement('a');
|
12863 | dlLink.download = file;
|
12864 | dlLink.href = imgURL;
|
12865 |
|
12866 | document.body.appendChild(dlLink);
|
12867 | dlLink.click();
|
12868 | document.body.removeChild(dlLink);
|
12869 | }
|
12870 | return dataURL;
|
12871 | }
|
12872 | return null;
|
12873 | };
|
12874 |
|
12875 | Map.prototype.coordinateToPoint = function coordinateToPoint(coordinate, zoom) {
|
12876 | var prjCoord = this.getProjection().project(coordinate);
|
12877 | return this._prjToPoint(prjCoord, zoom);
|
12878 | };
|
12879 |
|
12880 | Map.prototype.coordToPoint = function coordToPoint(coordinate, zoom) {
|
12881 | return this.coordinateToPoint(coordinate, zoom);
|
12882 | };
|
12883 |
|
12884 | Map.prototype.pointToCoordinate = function pointToCoordinate(point, zoom) {
|
12885 | var prjCoord = this._pointToPrj(point, zoom);
|
12886 | return this.getProjection().unproject(prjCoord);
|
12887 | };
|
12888 |
|
12889 | Map.prototype.pointToCoord = function pointToCoord(point, zoom) {
|
12890 | return this.pointToCoordinate(point, zoom);
|
12891 | };
|
12892 |
|
12893 | Map.prototype.coordinateToViewPoint = function coordinateToViewPoint(coordinate) {
|
12894 | return this._prjToViewPoint(this.getProjection().project(coordinate));
|
12895 | };
|
12896 |
|
12897 | Map.prototype.coordToViewPoint = function coordToViewPoint(coordinate) {
|
12898 | return this.coordinateToViewPoint(coordinate);
|
12899 | };
|
12900 |
|
12901 | Map.prototype.viewPointToCoordinate = function viewPointToCoordinate(viewPoint) {
|
12902 | return this.getProjection().unproject(this._viewPointToPrj(viewPoint));
|
12903 | };
|
12904 |
|
12905 | Map.prototype.viewPointToCoord = function viewPointToCoord(viewPoint) {
|
12906 | return this.viewPointToCoordinate(viewPoint);
|
12907 | };
|
12908 |
|
12909 | Map.prototype.coordinateToContainerPoint = function coordinateToContainerPoint(coordinate, zoom) {
|
12910 | var pCoordinate = this.getProjection().project(coordinate);
|
12911 | return this._prjToContainerPoint(pCoordinate, zoom);
|
12912 | };
|
12913 |
|
12914 | Map.prototype.coordToContainerPoint = function coordToContainerPoint(coordinate, zoom) {
|
12915 | return this.coordinateToContainerPoint(coordinate, zoom);
|
12916 | };
|
12917 |
|
12918 | Map.prototype.containerPointToCoordinate = function containerPointToCoordinate(containerPoint) {
|
12919 | var pCoordinate = this._containerPointToPrj(containerPoint);
|
12920 | return this.getProjection().unproject(pCoordinate);
|
12921 | };
|
12922 |
|
12923 | Map.prototype.containerPointToCoord = function containerPointToCoord(containerPoint) {
|
12924 | return this.containerPointToCoordinate(containerPoint);
|
12925 | };
|
12926 |
|
12927 | Map.prototype.containerPointToViewPoint = function containerPointToViewPoint(containerPoint) {
|
12928 | return containerPoint.sub(this.getViewPoint());
|
12929 | };
|
12930 |
|
12931 | Map.prototype.viewPointToContainerPoint = function viewPointToContainerPoint(viewPoint) {
|
12932 | return viewPoint.add(this.getViewPoint());
|
12933 | };
|
12934 |
|
12935 | Map.prototype.containerToExtent = function containerToExtent(containerExtent) {
|
12936 | var extent2D = new PointExtent(this._containerPointToPoint(containerExtent.getMin()), this._containerPointToPoint(containerExtent.getMax()));
|
12937 | return this._pointToExtent(extent2D);
|
12938 | };
|
12939 |
|
12940 | Map.prototype.checkSize = function checkSize() {
|
12941 | var justStart = now() - this._initTime < 1500 && this.width === 0 || this.height === 0;
|
12942 |
|
12943 | var watched = this._getContainerDomSize(),
|
12944 | oldHeight = this.height,
|
12945 | oldWidth = this.width;
|
12946 | if (watched['width'] === oldWidth && watched['height'] === oldHeight) {
|
12947 | return this;
|
12948 | }
|
12949 | var center = this.getCenter();
|
12950 | this._updateMapSize(watched);
|
12951 | var resizeOffset = new Point((oldWidth - watched.width) / 2, (oldHeight - watched.height) / 2);
|
12952 | this._offsetCenterByPixel(resizeOffset);
|
12953 |
|
12954 | this._mapViewCoord = this._getPrjCenter();
|
12955 | var hided = watched['width'] === 0 || watched['height'] === 0 || oldWidth === 0 || oldHeight === 0;
|
12956 |
|
12957 | if (justStart || hided) {
|
12958 | this._noEvent = true;
|
12959 | this.setCenter(center);
|
12960 | delete this._noEvent;
|
12961 | }
|
12962 |
|
12963 | this._fireEvent('resize');
|
12964 |
|
12965 | return this;
|
12966 | };
|
12967 |
|
12968 | Map.prototype.distanceToPixel = function distanceToPixel(xDist, yDist, zoom) {
|
12969 | var projection = this.getProjection();
|
12970 | if (!projection) {
|
12971 | return null;
|
12972 | }
|
12973 | var scale = this.getScale() / this.getScale(zoom);
|
12974 | var center = this.getCenter(),
|
12975 | target = projection.locate(center, xDist, yDist);
|
12976 | var p0 = this.coordToContainerPoint(center),
|
12977 | p1 = this.coordToContainerPoint(target);
|
12978 | p1._sub(p0)._multi(scale)._abs();
|
12979 | return new Size(p1.x, p1.y);
|
12980 | };
|
12981 |
|
12982 | Map.prototype.distanceToPoint = function distanceToPoint(xDist, yDist, zoom) {
|
12983 | var projection = this.getProjection();
|
12984 | if (!projection) {
|
12985 | return null;
|
12986 | }
|
12987 | var center = this.getCenter(),
|
12988 | target = projection.locate(center, xDist, yDist);
|
12989 | var p0 = this.coordToPoint(center, zoom),
|
12990 | p1 = this.coordToPoint(target, zoom);
|
12991 | p1._sub(p0)._abs();
|
12992 | return p1;
|
12993 | };
|
12994 |
|
12995 | Map.prototype.pixelToDistance = function pixelToDistance(width, height) {
|
12996 | var projection = this.getProjection();
|
12997 | if (!projection) {
|
12998 | return null;
|
12999 | }
|
13000 | var fullExt = this.getFullExtent();
|
13001 | var d = fullExt['top'] > fullExt['bottom'] ? -1 : 1;
|
13002 | var target = new Point(this.width / 2 + width, this.height / 2 + d * height);
|
13003 | var coord = this.containerPointToCoord(target);
|
13004 | return projection.measureLength(this.getCenter(), coord);
|
13005 | };
|
13006 |
|
13007 | Map.prototype.pointToDistance = function pointToDistance(dx, dy, zoom) {
|
13008 | var projection = this.getProjection();
|
13009 | if (!projection) {
|
13010 | return null;
|
13011 | }
|
13012 | var c = this._prjToPoint(this._getPrjCenter(), zoom);
|
13013 | c._add(dx, dy);
|
13014 | var target = this.pointToCoord(c, zoom);
|
13015 | return projection.measureLength(this.getCenter(), target);
|
13016 | };
|
13017 |
|
13018 | Map.prototype.locate = function locate(coordinate, dx, dy) {
|
13019 | return this.getProjection()._locate(new Coordinate(coordinate), dx, dy);
|
13020 | };
|
13021 |
|
13022 | Map.prototype.locateByPoint = function locateByPoint(coordinate, px, py) {
|
13023 | var point = this.coordToContainerPoint(coordinate);
|
13024 | return this.containerPointToCoord(point._add(px, py));
|
13025 | };
|
13026 |
|
13027 | Map.prototype.getMainPanel = function getMainPanel() {
|
13028 | return this._getRenderer().getMainPanel();
|
13029 | };
|
13030 |
|
13031 | Map.prototype.getPanels = function getPanels() {
|
13032 | return this._panels;
|
13033 | };
|
13034 |
|
13035 | Map.prototype.remove = function remove() {
|
13036 | if (this.isRemoved()) {
|
13037 | return this;
|
13038 | }
|
13039 | this._fireEvent('removestart');
|
13040 | this._removeDomEvents();
|
13041 | this._clearHandlers();
|
13042 | this.removeBaseLayer();
|
13043 | var layers = this.getLayers();
|
13044 | for (var i = 0; i < layers.length; i++) {
|
13045 | layers[i].remove();
|
13046 | }
|
13047 | if (this._getRenderer()) {
|
13048 | this._getRenderer().remove();
|
13049 | }
|
13050 | if (this._containerDOM.innerHTML) {
|
13051 | this._containerDOM.innerHTML = '';
|
13052 | }
|
13053 | delete this._panels;
|
13054 | delete this._containerDOM;
|
13055 | delete this.renderer;
|
13056 | this._fireEvent('removeend');
|
13057 | this._clearAllListeners();
|
13058 | return this;
|
13059 | };
|
13060 |
|
13061 | Map.prototype.isRemoved = function isRemoved() {
|
13062 | return !this._containerDOM;
|
13063 | };
|
13064 |
|
13065 | Map.prototype.isMoving = function isMoving() {
|
13066 | return !!this._moving;
|
13067 | };
|
13068 |
|
13069 | Map.prototype.onMoveStart = function onMoveStart(param) {
|
13070 | this._originCenter = this.getCenter();
|
13071 | this._moving = true;
|
13072 | this._trySetCursor('move');
|
13073 |
|
13074 | this._fireEvent('movestart', this._parseEvent(param ? param['domEvent'] : null, 'movestart'));
|
13075 | };
|
13076 |
|
13077 | Map.prototype.onMoving = function onMoving(param) {
|
13078 | this._fireEvent('moving', this._parseEvent(param ? param['domEvent'] : null, 'moving'));
|
13079 | };
|
13080 |
|
13081 | Map.prototype.onMoveEnd = function onMoveEnd(param) {
|
13082 | this._moving = false;
|
13083 | this._trySetCursor('default');
|
13084 |
|
13085 | this._fireEvent('moveend', param && param['domEvent'] ? this._parseEvent(param['domEvent'], 'moveend') : param);
|
13086 | if (!this._verifyExtent(this.getCenter())) {
|
13087 | var moveTo = this._originCenter;
|
13088 | if (!this._verifyExtent(moveTo)) {
|
13089 | moveTo = this.getMaxExtent().getCenter();
|
13090 | }
|
13091 | this.panTo(moveTo);
|
13092 | }
|
13093 | };
|
13094 |
|
13095 | Map.prototype.onDragRotateStart = function onDragRotateStart(param) {
|
13096 | this._dragRotating = true;
|
13097 |
|
13098 | this._fireEvent('dragrotatestart', this._parseEvent(param ? param['domEvent'] : null, 'dragrotatestart'));
|
13099 | };
|
13100 |
|
13101 | Map.prototype.onDragRotating = function onDragRotating(param) {
|
13102 | this._fireEvent('dragrotating', this._parseEvent(param ? param['domEvent'] : null, 'dragrotating'));
|
13103 | };
|
13104 |
|
13105 | Map.prototype.onDragRotateEnd = function onDragRotateEnd(param) {
|
13106 | this._dragRotating = false;
|
13107 |
|
13108 | this._fireEvent('dragrotateend', this._parseEvent(param ? param['domEvent'] : null, 'dragrotateend'));
|
13109 | };
|
13110 |
|
13111 | Map.prototype.isDragRotating = function isDragRotating() {
|
13112 | return !!this._dragRotating;
|
13113 | };
|
13114 |
|
13115 | Map.prototype.getRenderer = function getRenderer() {
|
13116 | return this._getRenderer();
|
13117 | };
|
13118 |
|
13119 | Map.prototype._initContainer = function _initContainer(container) {
|
13120 | if (isString(container)) {
|
13121 | this._containerDOM = document.getElementById(container);
|
13122 | if (!this._containerDOM) {
|
13123 | throw new Error('Invalid container when creating map: \'' + container + '\'');
|
13124 | }
|
13125 | } else {
|
13126 | this._containerDOM = container;
|
13127 | if (IS_NODE) {
|
13128 | this.CanvasClass = this._containerDOM.constructor;
|
13129 | }
|
13130 | }
|
13131 |
|
13132 | if (this._containerDOM.childNodes && this._containerDOM.childNodes.length > 0) {
|
13133 | if (this._containerDOM.childNodes[0].className === 'maptalks-wrapper') {
|
13134 | throw new Error('Container is already loaded with another map instance, use map.remove() to clear it.');
|
13135 | }
|
13136 | }
|
13137 | };
|
13138 |
|
13139 | Map.prototype._trySetCursor = function _trySetCursor(cursor) {
|
13140 | if (!this._cursor && !this._priorityCursor) {
|
13141 | if (!cursor) {
|
13142 | cursor = 'default';
|
13143 | }
|
13144 | this._setCursorToPanel(cursor);
|
13145 | }
|
13146 | return this;
|
13147 | };
|
13148 |
|
13149 | Map.prototype._setPriorityCursor = function _setPriorityCursor(cursor) {
|
13150 | if (!cursor) {
|
13151 | var hasCursor = false;
|
13152 | if (this._priorityCursor) {
|
13153 | hasCursor = true;
|
13154 | }
|
13155 | delete this._priorityCursor;
|
13156 | if (hasCursor) {
|
13157 | this.setCursor(this._cursor);
|
13158 | }
|
13159 | } else {
|
13160 | this._priorityCursor = cursor;
|
13161 | this._setCursorToPanel(cursor);
|
13162 | }
|
13163 | return this;
|
13164 | };
|
13165 |
|
13166 | Map.prototype._setCursorToPanel = function _setCursorToPanel(cursor) {
|
13167 | var panel = this.getMainPanel();
|
13168 | if (panel && panel.style && panel.style.cursor !== cursor) {
|
13169 | panel.style.cursor = cursor;
|
13170 | }
|
13171 | };
|
13172 |
|
13173 | Map.prototype._get2DExtent = function _get2DExtent(zoom) {
|
13174 | var _this3 = this;
|
13175 |
|
13176 | var cExtent = this.getContainerExtent();
|
13177 | return cExtent.convertTo(function (c) {
|
13178 | return _this3._containerPointToPoint(c, zoom);
|
13179 | });
|
13180 | };
|
13181 |
|
13182 | Map.prototype._pointToExtent = function _pointToExtent(extent2D) {
|
13183 | var min2d = extent2D.getMin(),
|
13184 | max2d = extent2D.getMax();
|
13185 | var fullExtent = this.getFullExtent();
|
13186 |
|
13187 | var _ref = !fullExtent || fullExtent.left <= fullExtent.right ? [min2d.x, max2d.x] : [max2d.x, min2d.x],
|
13188 | minx = _ref[0],
|
13189 | maxx = _ref[1];
|
13190 |
|
13191 | var _ref2 = !fullExtent || fullExtent.top > fullExtent.bottom ? [max2d.y, min2d.y] : [min2d.y, max2d.y],
|
13192 | miny = _ref2[0],
|
13193 | maxy = _ref2[1];
|
13194 |
|
13195 | var min = new Coordinate(minx, miny),
|
13196 | max = new Coordinate(maxx, maxy);
|
13197 | return new Extent(this.pointToCoord(min), this.pointToCoord(max), this.getProjection());
|
13198 | };
|
13199 |
|
13200 | Map.prototype._removeLayer = function _removeLayer(layer, layerList) {
|
13201 | if (!layer || !layerList) {
|
13202 | return;
|
13203 | }
|
13204 | var index = layerList.indexOf(layer);
|
13205 | if (index > -1) {
|
13206 | layerList.splice(index, 1);
|
13207 | }
|
13208 | };
|
13209 |
|
13210 | Map.prototype._sortLayersByZIndex = function _sortLayersByZIndex() {
|
13211 | if (!this._layers) {
|
13212 | return;
|
13213 | }
|
13214 | for (var i = 0, l = this._layers.length; i < l; i++) {
|
13215 | this._layers[i]._order = i;
|
13216 | }
|
13217 | this._layers.sort(function (a, b) {
|
13218 | var c = a.getZIndex() - b.getZIndex();
|
13219 | if (c === 0) {
|
13220 | return a._order - b._order;
|
13221 | }
|
13222 | return c;
|
13223 | });
|
13224 | };
|
13225 |
|
13226 | Map.prototype._fireEvent = function _fireEvent(eventName, param) {
|
13227 | if (this._noEvent) {
|
13228 | return;
|
13229 | }
|
13230 |
|
13231 | this.fire('_' + eventName, param);
|
13232 | this.fire(eventName, param);
|
13233 | };
|
13234 |
|
13235 | Map.prototype._Load = function _Load() {
|
13236 | this._resetMapStatus();
|
13237 | if (this.options['pitch']) {
|
13238 | this.setPitch(this.options['pitch']);
|
13239 | delete this.options['pitch'];
|
13240 | }
|
13241 | if (this.options['bearing']) {
|
13242 | this.setBearing(this.options['bearing']);
|
13243 | delete this.options['bearing'];
|
13244 | }
|
13245 | this._loadAllLayers();
|
13246 | this._getRenderer().onLoad();
|
13247 | this._loaded = true;
|
13248 | this._callOnLoadHooks();
|
13249 | this._initTime = now();
|
13250 | };
|
13251 |
|
13252 | Map.prototype._initRenderer = function _initRenderer() {
|
13253 | var renderer = this.options['renderer'];
|
13254 | var clazz = Map.getRendererClass(renderer);
|
13255 | this._renderer = new clazz(this);
|
13256 | this._renderer.load();
|
13257 | };
|
13258 |
|
13259 | Map.prototype._getRenderer = function _getRenderer() {
|
13260 | return this._renderer;
|
13261 | };
|
13262 |
|
13263 | Map.prototype._loadAllLayers = function _loadAllLayers() {
|
13264 | function loadLayer(layer) {
|
13265 | if (layer) {
|
13266 | layer.load();
|
13267 | }
|
13268 | }
|
13269 | if (this._baseLayer) {
|
13270 | this._baseLayer.load();
|
13271 | }
|
13272 | this._eachLayer(loadLayer, this.getLayers());
|
13273 | };
|
13274 |
|
13275 | Map.prototype._getLayers = function _getLayers(filter) {
|
13276 | var layers = this._baseLayer ? [this._baseLayer].concat(this._layers) : this._layers;
|
13277 | var result = [];
|
13278 | for (var i = 0; i < layers.length; i++) {
|
13279 | if (!filter || filter.call(this, layers[i])) {
|
13280 | result.push(layers[i]);
|
13281 | }
|
13282 | }
|
13283 | return result;
|
13284 | };
|
13285 |
|
13286 | Map.prototype._eachLayer = function _eachLayer(fn) {
|
13287 | if (arguments.length < 2) {
|
13288 | return;
|
13289 | }
|
13290 | var layerLists = Array.prototype.slice.call(arguments, 1);
|
13291 | if (layerLists && !Array.isArray(layerLists)) {
|
13292 | layerLists = [layerLists];
|
13293 | }
|
13294 | var layers = [];
|
13295 | for (var i = 0, len = layerLists.length; i < len; i++) {
|
13296 | layers = layers.concat(layerLists[i]);
|
13297 | }
|
13298 | for (var j = 0, jlen = layers.length; j < jlen; j++) {
|
13299 | fn.call(fn, layers[j]);
|
13300 | }
|
13301 | };
|
13302 |
|
13303 | Map.prototype._onLayerEvent = function _onLayerEvent(param) {
|
13304 | if (!param) {
|
13305 | return;
|
13306 | }
|
13307 | if (param['type'] === 'idchange') {
|
13308 | delete this._layerCache[param['old']];
|
13309 | this._layerCache[param['new']] = param['target'];
|
13310 | }
|
13311 | };
|
13312 |
|
13313 | Map.prototype._resetMapStatus = function _resetMapStatus() {
|
13314 | var maxZoom = this.getMaxZoom(),
|
13315 | minZoom = this.getMinZoom();
|
13316 | var viewMaxZoom = this._spatialReference.getMaxZoom(),
|
13317 | viewMinZoom = this._spatialReference.getMinZoom();
|
13318 | if (isNil(maxZoom) || maxZoom === -1 || maxZoom > viewMaxZoom) {
|
13319 | this.setMaxZoom(viewMaxZoom);
|
13320 | }
|
13321 | if (isNil(minZoom) || minZoom === -1 || minZoom < viewMinZoom) {
|
13322 | this.setMinZoom(viewMinZoom);
|
13323 | }
|
13324 | maxZoom = this.getMaxZoom();
|
13325 | minZoom = this.getMinZoom();
|
13326 | if (maxZoom < minZoom) {
|
13327 | this.setMaxZoom(minZoom);
|
13328 | }
|
13329 | if (isNil(this._zoomLevel) || this._zoomLevel > maxZoom) {
|
13330 | this._zoomLevel = maxZoom;
|
13331 | }
|
13332 | if (this._zoomLevel < minZoom) {
|
13333 | this._zoomLevel = minZoom;
|
13334 | }
|
13335 | delete this._prjCenter;
|
13336 | var projection = this.getProjection();
|
13337 | this._prjCenter = projection.project(this._center);
|
13338 | this._calcMatrices();
|
13339 | var renderer = this._getRenderer();
|
13340 | if (renderer) {
|
13341 | renderer.resetContainer();
|
13342 | }
|
13343 | };
|
13344 |
|
13345 | Map.prototype._getContainerDomSize = function _getContainerDomSize() {
|
13346 | if (!this._containerDOM) {
|
13347 | return null;
|
13348 | }
|
13349 | var containerDOM = this._containerDOM;
|
13350 | var width = void 0,
|
13351 | height = void 0;
|
13352 | if (!isNil(containerDOM.width) && !isNil(containerDOM.height)) {
|
13353 | width = containerDOM.width;
|
13354 | height = containerDOM.height;
|
13355 | if (Browser$1.retina && containerDOM['layer']) {
|
13356 | width /= 2;
|
13357 | height /= 2;
|
13358 | }
|
13359 | } else if (!isNil(containerDOM.clientWidth) && !isNil(containerDOM.clientHeight)) {
|
13360 | width = parseInt(containerDOM.clientWidth, 0);
|
13361 | height = parseInt(containerDOM.clientHeight, 0);
|
13362 | } else {
|
13363 | throw new Error('can not get size of container');
|
13364 | }
|
13365 | return new Size(width, height);
|
13366 | };
|
13367 |
|
13368 | Map.prototype._updateMapSize = function _updateMapSize(mSize) {
|
13369 | this.width = mSize['width'];
|
13370 | this.height = mSize['height'];
|
13371 | this._getRenderer().updateMapSize(mSize);
|
13372 | this._calcMatrices();
|
13373 | return this;
|
13374 | };
|
13375 |
|
13376 | Map.prototype._getPrjCenter = function _getPrjCenter() {
|
13377 | return this._prjCenter;
|
13378 | };
|
13379 |
|
13380 | Map.prototype._setPrjCenter = function _setPrjCenter(pcenter) {
|
13381 | this._prjCenter = pcenter;
|
13382 | if (this.isInteracting() && !this.isMoving()) {
|
13383 | this._mapViewCoord = pcenter;
|
13384 | }
|
13385 | this._calcMatrices();
|
13386 | };
|
13387 |
|
13388 | Map.prototype._setPrjCoordAtContainerPoint = function _setPrjCoordAtContainerPoint(coordinate, point) {
|
13389 | if (point.x === this.width / 2 && point.y === this.height / 2) {
|
13390 | return this;
|
13391 | }
|
13392 | var t = this._containerPointToPoint(point)._sub(this._prjToPoint(this._getPrjCenter()));
|
13393 | var pcenter = this._pointToPrj(this._prjToPoint(coordinate).sub(t));
|
13394 | this._setPrjCenter(pcenter);
|
13395 | return this;
|
13396 | };
|
13397 |
|
13398 | Map.prototype._verifyExtent = function _verifyExtent(center) {
|
13399 | if (!center) {
|
13400 | return false;
|
13401 | }
|
13402 | var maxExt = this.getMaxExtent();
|
13403 | if (!maxExt) {
|
13404 | return true;
|
13405 | }
|
13406 | return maxExt.contains(center);
|
13407 | };
|
13408 |
|
13409 | Map.prototype._offsetCenterByPixel = function _offsetCenterByPixel(pixel) {
|
13410 | var pos = new Point(this.width / 2 - pixel.x, this.height / 2 - pixel.y);
|
13411 | var pCenter = this._containerPointToPrj(pos);
|
13412 | this._setPrjCenter(pCenter);
|
13413 | return pCenter;
|
13414 | };
|
13415 |
|
13416 | Map.prototype.offsetPlatform = function offsetPlatform(offset) {
|
13417 | if (!offset) {
|
13418 | return this._mapViewPoint;
|
13419 | } else {
|
13420 | this._getRenderer().offsetPlatform(offset);
|
13421 | this._mapViewCoord = this._getPrjCenter();
|
13422 | this._mapViewPoint = this._mapViewPoint.add(offset);
|
13423 | return this;
|
13424 | }
|
13425 | };
|
13426 |
|
13427 | Map.prototype.getViewPoint = function getViewPoint() {
|
13428 | var offset = this._getViewPointFrameOffset();
|
13429 | var panelOffset = this.offsetPlatform();
|
13430 | if (offset) {
|
13431 | panelOffset = panelOffset.add(offset);
|
13432 | }
|
13433 | return panelOffset;
|
13434 | };
|
13435 |
|
13436 | Map.prototype._getViewPointFrameOffset = function _getViewPointFrameOffset() {
|
13437 | if (this.isZooming()) {
|
13438 | return null;
|
13439 | }
|
13440 | var pcenter = this._getPrjCenter();
|
13441 | if (this._mapViewCoord && !this._mapViewCoord.equals(pcenter)) {
|
13442 | return this._prjToContainerPoint(this._mapViewCoord).sub(this._prjToContainerPoint(pcenter));
|
13443 | }
|
13444 | return null;
|
13445 | };
|
13446 |
|
13447 | Map.prototype._resetMapViewPoint = function _resetMapViewPoint() {
|
13448 | this._mapViewPoint = new Point(0, 0);
|
13449 |
|
13450 | this._mapViewCoord = this._getPrjCenter();
|
13451 | };
|
13452 |
|
13453 | Map.prototype._getResolution = function _getResolution(zoom) {
|
13454 | if (isNil(zoom)) {
|
13455 | zoom = this.getZoom();
|
13456 | }
|
13457 | return this._spatialReference.getResolution(zoom);
|
13458 | };
|
13459 |
|
13460 | Map.prototype._getResolutions = function _getResolutions() {
|
13461 | return this._spatialReference.getResolutions();
|
13462 | };
|
13463 |
|
13464 | Map.prototype._prjToPoint = function _prjToPoint(pCoord, zoom) {
|
13465 | zoom = isNil(zoom) ? this.getZoom() : zoom;
|
13466 | return this._spatialReference.getTransformation().transform(pCoord, this._getResolution(zoom));
|
13467 | };
|
13468 |
|
13469 | Map.prototype._pointToPrj = function _pointToPrj(point, zoom) {
|
13470 | zoom = isNil(zoom) ? this.getZoom() : zoom;
|
13471 | return this._spatialReference.getTransformation().untransform(point, this._getResolution(zoom));
|
13472 | };
|
13473 |
|
13474 | Map.prototype._pointToPoint = function _pointToPoint(point, zoom) {
|
13475 | if (!isNil(zoom)) {
|
13476 | return point.multi(this._getResolution(zoom) / this._getResolution());
|
13477 | }
|
13478 | return point.copy();
|
13479 | };
|
13480 |
|
13481 | Map.prototype._pointToPointAtZoom = function _pointToPointAtZoom(point, zoom) {
|
13482 | if (!isNil(zoom)) {
|
13483 | return point.multi(this._getResolution() / this._getResolution(zoom));
|
13484 | }
|
13485 | return point.copy();
|
13486 | };
|
13487 |
|
13488 | Map.prototype._containerPointToPrj = function _containerPointToPrj(containerPoint) {
|
13489 | return this._pointToPrj(this._containerPointToPoint(containerPoint));
|
13490 | };
|
13491 |
|
13492 | Map.prototype._viewPointToPrj = function _viewPointToPrj(viewPoint) {
|
13493 | return this._containerPointToPrj(this.viewPointToContainerPoint(viewPoint));
|
13494 | };
|
13495 |
|
13496 | Map.prototype._prjToContainerPoint = function _prjToContainerPoint(pCoordinate, zoom) {
|
13497 | return this._pointToContainerPoint(this._prjToPoint(pCoordinate, zoom), zoom);
|
13498 | };
|
13499 |
|
13500 | Map.prototype._prjToViewPoint = function _prjToViewPoint(pCoordinate) {
|
13501 | var containerPoint = this._prjToContainerPoint(pCoordinate);
|
13502 | return this._containerPointToViewPoint(containerPoint);
|
13503 | };
|
13504 |
|
13505 | Map.prototype._containerPointToViewPoint = function _containerPointToViewPoint(containerPoint) {
|
13506 | if (!containerPoint) {
|
13507 | return null;
|
13508 | }
|
13509 | return containerPoint._sub(this.getViewPoint());
|
13510 | };
|
13511 |
|
13512 | Map.prototype._viewPointToPoint = function _viewPointToPoint(viewPoint, zoom) {
|
13513 | return this._containerPointToPoint(this.viewPointToContainerPoint(viewPoint), zoom);
|
13514 | };
|
13515 |
|
13516 | Map.prototype._pointToViewPoint = function _pointToViewPoint(point, zoom) {
|
13517 | return this._prjToViewPoint(this._pointToPrj(point, zoom));
|
13518 | };
|
13519 |
|
13520 | Map.prototype._callOnLoadHooks = function _callOnLoadHooks() {
|
13521 | var proto = Map.prototype;
|
13522 | if (!proto._onLoadHooks) {
|
13523 | return;
|
13524 | }
|
13525 | for (var i = 0, l = proto._onLoadHooks.length; i < l; i++) {
|
13526 | proto._onLoadHooks[i].call(this);
|
13527 | }
|
13528 | };
|
13529 |
|
13530 | return Map;
|
13531 | }(Handlerable(Eventable(Renderable(Class))));
|
13532 |
|
13533 | Map.mergeOptions(options);
|
13534 |
|
13535 | var MapDoubleClickZoomHandler = function (_Handler) {
|
13536 | inherits(MapDoubleClickZoomHandler, _Handler);
|
13537 |
|
13538 | function MapDoubleClickZoomHandler() {
|
13539 | classCallCheck(this, MapDoubleClickZoomHandler);
|
13540 | return possibleConstructorReturn(this, _Handler.apply(this, arguments));
|
13541 | }
|
13542 |
|
13543 | MapDoubleClickZoomHandler.prototype.addHooks = function addHooks() {
|
13544 | if (!this.target) {
|
13545 | return;
|
13546 | }
|
13547 | this.target.on('_dblclick', this._onDoubleClick, this);
|
13548 | };
|
13549 |
|
13550 | MapDoubleClickZoomHandler.prototype.removeHooks = function removeHooks() {
|
13551 | if (!this.target) {
|
13552 | return;
|
13553 | }
|
13554 | this.target.off('_dblclick', this._onDoubleClick, this);
|
13555 | };
|
13556 |
|
13557 | MapDoubleClickZoomHandler.prototype._onDoubleClick = function _onDoubleClick(param) {
|
13558 | var map = this.target;
|
13559 | if (map.options['doubleClickZoom']) {
|
13560 | var oldZoom = map.getZoom(),
|
13561 | zoom = param['domEvent']['shiftKey'] ? Math.ceil(oldZoom) - 1 : Math.floor(oldZoom) + 1;
|
13562 | map._zoomAnimation(zoom, param['containerPoint']);
|
13563 | }
|
13564 | };
|
13565 |
|
13566 | return MapDoubleClickZoomHandler;
|
13567 | }(Handler$1);
|
13568 |
|
13569 | Map.mergeOptions({
|
13570 | 'doubleClickZoom': true
|
13571 | });
|
13572 |
|
13573 | Map.addOnLoadHook('addHandler', 'doubleClickZoom', MapDoubleClickZoomHandler);
|
13574 |
|
13575 | var MapDragHandler = function (_Handler) {
|
13576 | inherits(MapDragHandler, _Handler);
|
13577 |
|
13578 | function MapDragHandler() {
|
13579 | classCallCheck(this, MapDragHandler);
|
13580 | return possibleConstructorReturn(this, _Handler.apply(this, arguments));
|
13581 | }
|
13582 |
|
13583 | MapDragHandler.prototype.addHooks = function addHooks() {
|
13584 | var map = this.target;
|
13585 | if (!map) {
|
13586 | return;
|
13587 | }
|
13588 | var dom = map._panels.mapWrapper || map._containerDOM;
|
13589 | this._dragHandler = new DragHandler(dom, {
|
13590 | 'cancelOn': this._cancelOn.bind(this),
|
13591 | 'rightclick': true
|
13592 | });
|
13593 | this._dragHandler.on('mousedown', this._onMouseDown, this).on('dragstart', this._onDragStart, this).on('dragging', this._onDragging, this).on('dragend', this._onDragEnd, this).enable();
|
13594 | };
|
13595 |
|
13596 | MapDragHandler.prototype.removeHooks = function removeHooks() {
|
13597 | this._dragHandler.off('mousedown', this._onMouseDown, this).off('dragstart', this._onDragStart, this).off('dragging', this._onDragging, this).off('dragend', this._onDragEnd, this);
|
13598 | this._dragHandler.remove();
|
13599 | delete this._dragHandler;
|
13600 | };
|
13601 |
|
13602 | MapDragHandler.prototype._cancelOn = function _cancelOn(domEvent) {
|
13603 | if (this.target.isZooming() || this._ignore(domEvent)) {
|
13604 | return true;
|
13605 | }
|
13606 | return false;
|
13607 | };
|
13608 |
|
13609 | MapDragHandler.prototype._ignore = function _ignore(param) {
|
13610 | if (!param) {
|
13611 | return false;
|
13612 | }
|
13613 | if (param.domEvent) {
|
13614 | param = param.domEvent;
|
13615 | }
|
13616 | return this.target._ignoreEvent(param);
|
13617 | };
|
13618 |
|
13619 | MapDragHandler.prototype._onMouseDown = function _onMouseDown(param) {
|
13620 | delete this.startDragTime;
|
13621 | delete this._mode;
|
13622 | if (param.domEvent.button === 2 || param.domEvent.ctrlKey) {
|
13623 | if (this.target.options['dragRotate'] || this.target.options['dragPitch']) {
|
13624 | this._mode = 'rotatePitch';
|
13625 | }
|
13626 | } else if (this.target.options['dragPan']) {
|
13627 | this._mode = 'move';
|
13628 | }
|
13629 | this.target._stopAnim(this.target._animPlayer);
|
13630 | preventDefault(param['domEvent']);
|
13631 | };
|
13632 |
|
13633 | MapDragHandler.prototype._onDragStart = function _onDragStart(param) {
|
13634 | this.startDragTime = now();
|
13635 | if (this._mode === 'move') {
|
13636 | this._moveStart(param);
|
13637 | } else if (this._mode === 'rotatePitch') {
|
13638 | this._rotateStart(param);
|
13639 | }
|
13640 | };
|
13641 |
|
13642 | MapDragHandler.prototype._onDragging = function _onDragging(param) {
|
13643 | var map = this.target;
|
13644 | if (map._isEventOutMap(param['domEvent'])) {
|
13645 | return;
|
13646 | }
|
13647 | if (this._mode === 'move') {
|
13648 | this._moving(param);
|
13649 | } else if (this._mode === 'rotatePitch') {
|
13650 | this._rotating(param);
|
13651 | }
|
13652 | };
|
13653 |
|
13654 | MapDragHandler.prototype._onDragEnd = function _onDragEnd(param) {
|
13655 | if (this._mode === 'move') {
|
13656 | this._moveEnd(param);
|
13657 | } else if (this._mode === 'rotatePitch') {
|
13658 | this._rotateEnd(param);
|
13659 | }
|
13660 | delete this.startDragTime;
|
13661 | delete this.startBearing;
|
13662 | };
|
13663 |
|
13664 | MapDragHandler.prototype._start = function _start(param) {
|
13665 | this.preX = param['mousePos'].x;
|
13666 | this.preY = param['mousePos'].y;
|
13667 | this.startX = this.preX;
|
13668 | this.startY = this.preY;
|
13669 | };
|
13670 |
|
13671 | MapDragHandler.prototype._moveStart = function _moveStart(param) {
|
13672 | this._start(param);
|
13673 | var map = this.target;
|
13674 | map.onMoveStart(param);
|
13675 | var p = getEventContainerPoint(map._getActualEvent(param.domEvent), map.getContainer());
|
13676 | this.startPrjCoord = map._containerPointToPrj(p);
|
13677 | };
|
13678 |
|
13679 | MapDragHandler.prototype._moving = function _moving(param) {
|
13680 | if (!this.startDragTime) {
|
13681 | return;
|
13682 | }
|
13683 | var map = this.target;
|
13684 | var p = getEventContainerPoint(map._getActualEvent(param.domEvent), map.getContainer());
|
13685 | map._setPrjCoordAtContainerPoint(this.startPrjCoord, p);
|
13686 | map.onMoving(param);
|
13687 | };
|
13688 |
|
13689 | MapDragHandler.prototype._moveEnd = function _moveEnd(param) {
|
13690 | if (!this.startDragTime) {
|
13691 | return;
|
13692 | }
|
13693 | var map = this.target;
|
13694 | var t = now() - this.startDragTime;
|
13695 | var mx = param['mousePos'].x,
|
13696 | my = param['mousePos'].y;
|
13697 | var dx = mx - this.startX;
|
13698 | var dy = my - this.startY;
|
13699 |
|
13700 | this._clear();
|
13701 |
|
13702 | if (map.options['panAnimation'] && !param.interupted && map._verifyExtent(map.getCenter()) && t < 280 && Math.abs(dy) + Math.abs(dx) > 5) {
|
13703 | t = 5 * t * (Math.abs(dx) + Math.abs(dy)) / 500;
|
13704 | map.panBy(new Point(dx, dy), { 'duration': t });
|
13705 | } else {
|
13706 | map.onMoveEnd(param);
|
13707 | }
|
13708 | };
|
13709 |
|
13710 | MapDragHandler.prototype._rotateStart = function _rotateStart(param) {
|
13711 | this._start(param);
|
13712 | delete this._rotateMode;
|
13713 | this.startBearing = this.target.getBearing();
|
13714 | this.target.onDragRotateStart(param);
|
13715 | this._db = 0;
|
13716 | };
|
13717 |
|
13718 | MapDragHandler.prototype._rotating = function _rotating(param) {
|
13719 | var map = this.target;
|
13720 | var mx = param['mousePos'].x,
|
13721 | my = param['mousePos'].y;
|
13722 | var prePitch = map.getPitch(),
|
13723 | preBearing = map.getBearing();
|
13724 | var dx = Math.abs(mx - this.preX),
|
13725 | dy = Math.abs(my - this.preY);
|
13726 |
|
13727 | if (!this._rotateMode) {
|
13728 | if (map.options['dragRotatePitch']) {
|
13729 | this._rotateMode = 'rotate_pitch';
|
13730 | } else if (dx > dy) {
|
13731 | this._rotateMode = 'rotate';
|
13732 | } else if (dx < dy) {
|
13733 | this._rotateMode = 'pitch';
|
13734 | } else {
|
13735 | this._rotateMode = 'rotate';
|
13736 | }
|
13737 | }
|
13738 |
|
13739 | if (this._rotateMode === 'pitch' && prePitch === 0 && dy < 10) {
|
13740 | return;
|
13741 | }
|
13742 |
|
13743 | if (this._rotateMode.indexOf('rotate') >= 0 && map.options['dragRotate']) {
|
13744 |
|
13745 | var db = 0;
|
13746 | if (map.options['dragPitch'] || dx > dy) {
|
13747 | db = -0.6 * (this.preX - mx);
|
13748 | } else if (mx > map.width / 2) {
|
13749 | db = 0.6 * (this.preY - my);
|
13750 | } else {
|
13751 | db = -0.6 * (this.preY - my);
|
13752 | }
|
13753 | var bearing = map.getBearing() + db;
|
13754 | this._db = this._db || 0;
|
13755 | this._db += db;
|
13756 |
|
13757 | map.setBearing(bearing);
|
13758 | }
|
13759 | if (this._rotateMode.indexOf('pitch') >= 0 && map.options['dragPitch']) {
|
13760 | map.setPitch(map.getPitch() + (this.preY - my) * 0.4);
|
13761 | }
|
13762 | this.preX = mx;
|
13763 | this.preY = my;
|
13764 | if (map.getBearing() !== preBearing || map.getPitch() !== prePitch) {
|
13765 | map.onDragRotating(param);
|
13766 | }
|
13767 | };
|
13768 |
|
13769 | MapDragHandler.prototype._rotateEnd = function _rotateEnd(param) {
|
13770 | var map = this.target;
|
13771 | var bearing = map.getBearing();
|
13772 | this._clear();
|
13773 | var t = now() - this.startDragTime;
|
13774 | map.onDragRotateEnd(param);
|
13775 | if (Math.abs(bearing - this.startBearing) > 20 && (this._rotateMode === 'rotate' || this._rotateMode === 'rotate_pitch') && !param.interupted && t < 400) {
|
13776 | var _bearing = map.getBearing();
|
13777 | map.animateTo({
|
13778 | 'bearing': _bearing + this._db / 2
|
13779 | }, {
|
13780 | 'easing': 'out',
|
13781 | 'duration': 800
|
13782 | });
|
13783 | }
|
13784 | };
|
13785 |
|
13786 | MapDragHandler.prototype._clear = function _clear() {
|
13787 | delete this.startPrjCoord;
|
13788 | delete this.preX;
|
13789 | delete this.preY;
|
13790 | delete this.startX;
|
13791 | delete this.startY;
|
13792 | };
|
13793 |
|
13794 | return MapDragHandler;
|
13795 | }(Handler$1);
|
13796 |
|
13797 | Map.mergeOptions({
|
13798 | 'draggable': true,
|
13799 | 'dragPan': true,
|
13800 | 'dragRotatePitch': true,
|
13801 | 'dragRotate': true,
|
13802 | 'dragPitch': true
|
13803 | });
|
13804 |
|
13805 | Map.addOnLoadHook('addHandler', 'draggable', MapDragHandler);
|
13806 |
|
13807 | function clipLine(points, bounds, round, noCut) {
|
13808 | var parts = [];
|
13809 | var k = 0,
|
13810 | segment = void 0;
|
13811 | for (var j = 0, l = points.length; j < l - 1; j++) {
|
13812 | segment = clipSegment(points[j], points[j + 1], bounds, j, round, noCut);
|
13813 |
|
13814 | if (!segment) {
|
13815 | continue;
|
13816 | }
|
13817 |
|
13818 | parts[k] = parts[k] || [];
|
13819 | parts[k].push({
|
13820 | 'point': segment[0],
|
13821 | 'index': j
|
13822 | });
|
13823 |
|
13824 | if (segment[1] !== points[j + 1] || j === l - 2) {
|
13825 | parts[k].push({
|
13826 | 'point': segment[1],
|
13827 | 'index': j + 1
|
13828 | });
|
13829 | k++;
|
13830 | }
|
13831 | }
|
13832 | return parts;
|
13833 | }
|
13834 |
|
13835 | var _lastCode = void 0;
|
13836 |
|
13837 | function clipSegment(a, b, bounds, useLastCode, round, noCut) {
|
13838 | var codeA = useLastCode ? _lastCode : _getBitCode(a, bounds),
|
13839 | codeB = _getBitCode(b, bounds),
|
13840 | codeOut = void 0,
|
13841 | p = void 0,
|
13842 | newCode = void 0;
|
13843 |
|
13844 | _lastCode = codeB;
|
13845 |
|
13846 | while (true) {
|
13847 | if (!(codeA | codeB)) {
|
13848 | return [a, b];
|
13849 | }
|
13850 |
|
13851 | if (codeA & codeB) {
|
13852 | return false;
|
13853 | }
|
13854 |
|
13855 | if (noCut) {
|
13856 | return [a, b];
|
13857 | }
|
13858 |
|
13859 | codeOut = codeA || codeB;
|
13860 | p = _getEdgeIntersection(a, b, codeOut, bounds, round);
|
13861 | newCode = _getBitCode(p, bounds);
|
13862 |
|
13863 | if (codeOut === codeA) {
|
13864 | a = p;
|
13865 | codeA = newCode;
|
13866 | } else {
|
13867 | b = p;
|
13868 | codeB = newCode;
|
13869 | }
|
13870 | }
|
13871 | }
|
13872 |
|
13873 | function clipPolygon(points, bounds, round) {
|
13874 | var edges = [1, 4, 2, 8];
|
13875 | var clippedPoints = void 0,
|
13876 | i = void 0,
|
13877 | j = void 0,
|
13878 | k = void 0,
|
13879 | a = void 0,
|
13880 | b = void 0,
|
13881 | len = void 0,
|
13882 | edge = void 0,
|
13883 | p = void 0;
|
13884 |
|
13885 | for (i = 0, len = points.length; i < len; i++) {
|
13886 | points[i]._code = _getBitCode(points[i], bounds);
|
13887 | }
|
13888 |
|
13889 | for (k = 0; k < 4; k++) {
|
13890 | edge = edges[k];
|
13891 | clippedPoints = [];
|
13892 |
|
13893 | for (i = 0, len = points.length, j = len - 1; i < len; j = i++) {
|
13894 | a = points[i];
|
13895 | b = points[j];
|
13896 |
|
13897 | if (!(a._code & edge)) {
|
13898 | if (b._code & edge) {
|
13899 | p = _getEdgeIntersection(b, a, edge, bounds, round);
|
13900 | p._code = _getBitCode(p, bounds);
|
13901 | clippedPoints.push(p);
|
13902 | }
|
13903 | clippedPoints.push(a);
|
13904 | } else if (!(b._code & edge)) {
|
13905 | p = _getEdgeIntersection(b, a, edge, bounds, round);
|
13906 | p._code = _getBitCode(p, bounds);
|
13907 | clippedPoints.push(p);
|
13908 | }
|
13909 | }
|
13910 | points = clippedPoints;
|
13911 | }
|
13912 |
|
13913 | return points;
|
13914 | }
|
13915 |
|
13916 |
|
13917 |
|
13918 |
|
13919 |
|
13920 | function _getEdgeIntersection(a, b, code, bounds, round) {
|
13921 | var dx = b.x - a.x,
|
13922 | dy = b.y - a.y,
|
13923 | min = bounds.getMin(),
|
13924 | max = bounds.getMax();
|
13925 | var x = void 0,
|
13926 | y = void 0;
|
13927 |
|
13928 | if (code & 8) {
|
13929 | x = a.x + dx * (max.y - a.y) / dy;
|
13930 | y = max.y;
|
13931 | } else if (code & 4) {
|
13932 | x = a.x + dx * (min.y - a.y) / dy;
|
13933 | y = min.y;
|
13934 | } else if (code & 2) {
|
13935 | x = max.x;
|
13936 | y = a.y + dy * (max.x - a.x) / dx;
|
13937 | } else if (code & 1) {
|
13938 | x = min.x;
|
13939 | y = a.y + dy * (min.x - a.x) / dx;
|
13940 | }
|
13941 |
|
13942 | var p = new Point(x, y);
|
13943 | if (round) {
|
13944 | p._round();
|
13945 | }
|
13946 | return p;
|
13947 | }
|
13948 |
|
13949 | function _getBitCode(p, bounds) {
|
13950 | var code = 0;
|
13951 |
|
13952 | if (p.x < bounds.getMin().x) {
|
13953 | code |= 1;
|
13954 | } else if (p.x > bounds.getMax().x) {
|
13955 | code |= 2;
|
13956 | }
|
13957 |
|
13958 | if (p.y < bounds.getMin().y) {
|
13959 | code |= 4;
|
13960 | } else if (p.y > bounds.getMax().y) {
|
13961 | code |= 8;
|
13962 | }
|
13963 |
|
13964 | return code;
|
13965 | }
|
13966 |
|
13967 | function withInEllipse(point, center, southeast, tolerance) {
|
13968 | point = new Point(point);
|
13969 | var a = Math.abs(southeast.x - center.x),
|
13970 | b = Math.abs(southeast.y - center.y),
|
13971 | c = Math.sqrt(Math.abs(a * a - b * b)),
|
13972 | xfocus = a >= b;
|
13973 | var f1 = void 0,
|
13974 | f2 = void 0,
|
13975 | d = void 0;
|
13976 | if (xfocus) {
|
13977 | f1 = new Point(center.x - c, center.y);
|
13978 | f2 = new Point(center.x + c, center.y);
|
13979 | d = a * 2;
|
13980 | } else {
|
13981 | f1 = new Point(center.x, center.y - c);
|
13982 | f2 = new Point(center.x, center.y + c);
|
13983 | d = b * 2;
|
13984 | }
|
13985 |
|
13986 | return point.distanceTo(f1) + point.distanceTo(f2) <= d + 2 * tolerance;
|
13987 | }
|
13988 |
|
13989 | var Symbolizer = function () {
|
13990 | function Symbolizer() {
|
13991 | classCallCheck(this, Symbolizer);
|
13992 | }
|
13993 |
|
13994 | Symbolizer.prototype.getMap = function getMap() {
|
13995 | return this.geometry.getMap();
|
13996 | };
|
13997 |
|
13998 | Symbolizer.prototype.getPainter = function getPainter() {
|
13999 | return this.painter;
|
14000 | };
|
14001 |
|
14002 | Symbolizer.testColor = function testColor(prop) {
|
14003 | if (!prop || !isString(prop)) {
|
14004 | return false;
|
14005 | }
|
14006 | if (COLOR_PROPERTIES.indexOf(prop) >= 0) {
|
14007 | return true;
|
14008 | }
|
14009 | return false;
|
14010 | };
|
14011 |
|
14012 | return Symbolizer;
|
14013 | }();
|
14014 |
|
14015 | var CanvasSymbolizer = function (_Symbolizer) {
|
14016 | inherits(CanvasSymbolizer, _Symbolizer);
|
14017 |
|
14018 | function CanvasSymbolizer() {
|
14019 | classCallCheck(this, CanvasSymbolizer);
|
14020 | return possibleConstructorReturn(this, _Symbolizer.apply(this, arguments));
|
14021 | }
|
14022 |
|
14023 | CanvasSymbolizer.prototype._prepareContext = function _prepareContext(ctx) {
|
14024 | if (isNumber(this.symbol['opacity'])) {
|
14025 | if (ctx.globalAlpha !== this.symbol['opacity']) {
|
14026 | ctx.globalAlpha = this.symbol['opacity'];
|
14027 | }
|
14028 | } else if (ctx.globalAlpha !== 1) {
|
14029 | ctx.globalAlpha = 1;
|
14030 | }
|
14031 | };
|
14032 |
|
14033 | CanvasSymbolizer.prototype.prepareCanvas = function prepareCanvas(ctx, style, resources) {
|
14034 | Canvas.prepareCanvas(ctx, style, resources, this.getPainter().isHitTesting());
|
14035 | };
|
14036 |
|
14037 | CanvasSymbolizer.prototype.remove = function remove() {};
|
14038 |
|
14039 | CanvasSymbolizer.prototype.setZIndex = function setZIndex() {};
|
14040 |
|
14041 | CanvasSymbolizer.prototype.show = function show() {};
|
14042 |
|
14043 | CanvasSymbolizer.prototype.hide = function hide() {};
|
14044 |
|
14045 | CanvasSymbolizer.prototype._defineStyle = function _defineStyle(style) {
|
14046 | return function () {
|
14047 | var _this2 = this;
|
14048 |
|
14049 | var arr = [],
|
14050 | prop = {};
|
14051 | return loadFunctionTypes(style, function () {
|
14052 | var map = _this2.getMap();
|
14053 | return set$1(arr, map.getZoom(), extend({}, _this2.geometry.getProperties(), setProp(prop, map.getBearing(), map.getPitch(), map.getZoom())));
|
14054 | });
|
14055 | }.bind(this)();
|
14056 | };
|
14057 |
|
14058 | return CanvasSymbolizer;
|
14059 | }(Symbolizer);
|
14060 |
|
14061 | function set$1(arr, a0, a1) {
|
14062 | arr[0] = a0;
|
14063 | arr[1] = a1;
|
14064 | return arr;
|
14065 | }
|
14066 |
|
14067 | function setProp(prop, b, p, z) {
|
14068 | prop['{bearing}'] = b;
|
14069 | prop['{pitch}'] = p;
|
14070 | prop['{zoom}'] = z;
|
14071 | return prop;
|
14072 | }
|
14073 |
|
14074 | var PointSymbolizer = function (_CanvasSymbolizer) {
|
14075 | inherits(PointSymbolizer, _CanvasSymbolizer);
|
14076 |
|
14077 | function PointSymbolizer(symbol, geometry, painter) {
|
14078 | classCallCheck(this, PointSymbolizer);
|
14079 |
|
14080 | var _this = possibleConstructorReturn(this, _CanvasSymbolizer.call(this));
|
14081 |
|
14082 | _this.symbol = symbol;
|
14083 | _this.geometry = geometry;
|
14084 | _this.painter = painter;
|
14085 | return _this;
|
14086 | }
|
14087 |
|
14088 | PointSymbolizer.prototype.get2DExtent = function get2DExtent() {
|
14089 | var map = this.getMap();
|
14090 | var glZoom = map.getGLZoom();
|
14091 | var extent = new PointExtent();
|
14092 | var renderPoints = this._getRenderPoints()[0];
|
14093 | for (var i = renderPoints.length - 1; i >= 0; i--) {
|
14094 | if (renderPoints[i]) {
|
14095 | extent._combine(map._pointToPoint(renderPoints[i], glZoom));
|
14096 | }
|
14097 | }
|
14098 | return extent;
|
14099 | };
|
14100 |
|
14101 | PointSymbolizer.prototype._rotateExtent = function _rotateExtent(fixedExtent, angle) {
|
14102 | return fixedExtent.convertTo(function (p) {
|
14103 | return p._rotate(angle);
|
14104 | });
|
14105 | };
|
14106 |
|
14107 | PointSymbolizer.prototype._getRenderPoints = function _getRenderPoints() {
|
14108 | return this.getPainter().getRenderPoints(this.getPlacement());
|
14109 | };
|
14110 |
|
14111 | PointSymbolizer.prototype._getRenderContainerPoints = function _getRenderContainerPoints(ignoreAltitude) {
|
14112 | var painter = this.getPainter(),
|
14113 | points = this._getRenderPoints()[0];
|
14114 | if (painter.isSpriting()) {
|
14115 | return points;
|
14116 | }
|
14117 | var dxdy = this.getDxDy();
|
14118 | var cpoints = this.painter._pointContainerPoints(points, dxdy.x, dxdy.y, ignoreAltitude, true, this.getPlacement());
|
14119 | if (!cpoints || !Array.isArray(cpoints[0])) {
|
14120 | return cpoints;
|
14121 | }
|
14122 | var flat = [];
|
14123 | for (var i = 0, l = cpoints.length; i < l; i++) {
|
14124 | for (var ii = 0, ll = cpoints[i].length; ii < ll; ii++) {
|
14125 | flat.push(cpoints[i][ii]);
|
14126 | }
|
14127 | }
|
14128 | return flat;
|
14129 | };
|
14130 |
|
14131 | PointSymbolizer.prototype._getRotationAt = function _getRotationAt(i) {
|
14132 | var r = this.getRotation();
|
14133 | if (!r) {
|
14134 | r = 0;
|
14135 | }
|
14136 | var rotations = this._getRenderPoints()[1];
|
14137 | if (!rotations || !rotations[i]) {
|
14138 | return r;
|
14139 | }
|
14140 |
|
14141 | var map = this.getMap();
|
14142 | var p0 = rotations[i][0],
|
14143 | p1 = rotations[i][1];
|
14144 | if (map.isTransforming()) {
|
14145 | var maxZoom = map.getGLZoom();
|
14146 | p0 = map._pointToContainerPoint(rotations[i][0], maxZoom);
|
14147 | p1 = map._pointToContainerPoint(rotations[i][1], maxZoom);
|
14148 | }
|
14149 | return r + computeDegree(p0.x, p0.y, p1.x, p1.y);
|
14150 | };
|
14151 |
|
14152 | PointSymbolizer.prototype._rotate = function _rotate(ctx, origin, rotation) {
|
14153 | if (rotation) {
|
14154 | var dxdy = this.getDxDy();
|
14155 | var p = origin.sub(dxdy);
|
14156 | ctx.save();
|
14157 | ctx.translate(p.x, p.y);
|
14158 | ctx.rotate(rotation);
|
14159 | return this.getDxDy();
|
14160 | }
|
14161 | return null;
|
14162 | };
|
14163 |
|
14164 | return PointSymbolizer;
|
14165 | }(CanvasSymbolizer);
|
14166 |
|
14167 | var VectorMarkerSymbolizer = function (_PointSymbolizer) {
|
14168 | inherits(VectorMarkerSymbolizer, _PointSymbolizer);
|
14169 |
|
14170 | VectorMarkerSymbolizer.test = function test(symbol) {
|
14171 | if (!symbol) {
|
14172 | return false;
|
14173 | }
|
14174 | if (isNil(symbol['markerFile']) && !isNil(symbol['markerType']) && symbol['markerType'] !== 'path') {
|
14175 | return true;
|
14176 | }
|
14177 | return false;
|
14178 | };
|
14179 |
|
14180 | function VectorMarkerSymbolizer(symbol, geometry, painter) {
|
14181 | classCallCheck(this, VectorMarkerSymbolizer);
|
14182 |
|
14183 | var _this = possibleConstructorReturn(this, _PointSymbolizer.call(this, symbol, geometry, painter));
|
14184 |
|
14185 | _this._dynamic = hasFunctionDefinition(symbol);
|
14186 | _this.style = _this._defineStyle(_this.translate());
|
14187 | _this.strokeAndFill = _this._defineStyle(VectorMarkerSymbolizer.translateLineAndFill(_this.style));
|
14188 | var lineWidth = _this.strokeAndFill['lineWidth'];
|
14189 | if (lineWidth % 2 === 0) {
|
14190 | _this.padding = 2;
|
14191 | } else {
|
14192 | _this.padding = 1.5;
|
14193 | }
|
14194 | return _this;
|
14195 | }
|
14196 |
|
14197 | VectorMarkerSymbolizer.prototype.symbolize = function symbolize(ctx, resources) {
|
14198 | var style = this.style;
|
14199 | if (!this.painter.isHitTesting() && (style['markerWidth'] === 0 || style['markerHeight'] === 0 || style['polygonOpacity'] === 0 && style['lineOpacity'] === 0)) {
|
14200 | return;
|
14201 | }
|
14202 | var cookedPoints = this._getRenderContainerPoints();
|
14203 | if (!isArrayHasData(cookedPoints)) {
|
14204 | return;
|
14205 | }
|
14206 | this._prepareContext(ctx);
|
14207 | if (this.getPainter().isSpriting() || this.geometry.getLayer().getMask() === this.geometry || this._dynamic || this.geometry.getLayer().options['cacheVectorOnCanvas'] === false) {
|
14208 | this._drawMarkers(ctx, cookedPoints, resources);
|
14209 | } else {
|
14210 | this._drawMarkersWithCache(ctx, cookedPoints, resources);
|
14211 | }
|
14212 | };
|
14213 |
|
14214 | VectorMarkerSymbolizer.prototype.getDxDy = function getDxDy() {
|
14215 | var s = this.style;
|
14216 | var dx = s['markerDx'],
|
14217 | dy = s['markerDy'];
|
14218 | return new Point(dx, dy);
|
14219 | };
|
14220 |
|
14221 | VectorMarkerSymbolizer.prototype._drawMarkers = function _drawMarkers(ctx, cookedPoints, resources) {
|
14222 | var strokeAndFill = this.strokeAndFill;
|
14223 | var gradient = isGradient(strokeAndFill['lineColor']) || isGradient(strokeAndFill['polygonFill']);
|
14224 | if (!gradient) {
|
14225 | this.prepareCanvas(ctx, strokeAndFill, resources);
|
14226 | }
|
14227 | for (var i = cookedPoints.length - 1; i >= 0; i--) {
|
14228 | var point = cookedPoints[i];
|
14229 | var origin = this._rotate(ctx, point, this._getRotationAt(i));
|
14230 | if (origin) {
|
14231 | point = origin;
|
14232 | }
|
14233 |
|
14234 | this._drawVectorMarker(ctx, point, resources);
|
14235 | if (origin) {
|
14236 | ctx.restore();
|
14237 | }
|
14238 | }
|
14239 | };
|
14240 |
|
14241 | VectorMarkerSymbolizer.prototype._drawMarkersWithCache = function _drawMarkersWithCache(ctx, cookedPoints, resources) {
|
14242 | var stamp = this._stampSymbol();
|
14243 | var image = resources.getImage(stamp);
|
14244 | if (!image) {
|
14245 | image = this._createMarkerImage(ctx, resources);
|
14246 | resources.addResource([stamp, image.width, image.height], image);
|
14247 | }
|
14248 | var anchor = this._getAnchor(image.width, image.height);
|
14249 | for (var i = cookedPoints.length - 1; i >= 0; i--) {
|
14250 | var point = cookedPoints[i];
|
14251 | var origin = this._rotate(ctx, point, this._getRotationAt(i));
|
14252 | if (origin) {
|
14253 | point = origin;
|
14254 | }
|
14255 | Canvas.image(ctx, image, point.x + anchor.x, point.y + anchor.y);
|
14256 | if (origin) {
|
14257 | ctx.restore();
|
14258 | }
|
14259 | }
|
14260 | };
|
14261 |
|
14262 | VectorMarkerSymbolizer.prototype._calMarkerSize = function _calMarkerSize() {
|
14263 | if (!this._size) {
|
14264 | var lineWidth = this.strokeAndFill['lineWidth'],
|
14265 | shadow = 2 * (this.symbol['shadowBlur'] || 0),
|
14266 | w = Math.round(this.style['markerWidth'] + lineWidth + 2 * shadow + this.padding * 2),
|
14267 | h = Math.round(this.style['markerHeight'] + lineWidth + 2 * shadow + this.padding * 2);
|
14268 | this._size = [w, h];
|
14269 | }
|
14270 | return this._size;
|
14271 | };
|
14272 |
|
14273 | VectorMarkerSymbolizer.prototype._createMarkerImage = function _createMarkerImage(ctx, resources) {
|
14274 | var canvasClass = ctx.canvas.constructor,
|
14275 | size = this._calMarkerSize(),
|
14276 | canvas = Canvas.createCanvas(size[0], size[1], canvasClass),
|
14277 | point = this._getCacheImageAnchor(size[0], size[1]);
|
14278 | var context = canvas.getContext('2d');
|
14279 | var gradient = isGradient(this.strokeAndFill['lineColor']) || isGradient(this.strokeAndFill['polygonFill']);
|
14280 | if (!gradient) {
|
14281 | this.prepareCanvas(context, this.strokeAndFill, resources);
|
14282 | }
|
14283 | this._drawVectorMarker(context, point, resources);
|
14284 | return canvas;
|
14285 | };
|
14286 |
|
14287 | VectorMarkerSymbolizer.prototype._stampSymbol = function _stampSymbol() {
|
14288 | if (!this._stamp) {
|
14289 | this._stamp = [this.style['markerType'], isGradient(this.style['markerFill']) ? getGradientStamp(this.style['markerFill']) : this.style['markerFill'], this.style['markerFillOpacity'], this.style['markerFillPatternFile'], isGradient(this.style['markerLineColor']) ? getGradientStamp(this.style['markerLineColor']) : this.style['markerLineColor'], this.style['markerLineWidth'], this.style['markerLineOpacity'], this.style['markerLineDasharray'] ? this.style['markerLineDasharray'].join(',') : '', this.style['markerLinePatternFile'], this.style['markerWidth'], this.style['markerHeight'], this.style['markerHorizontalAlignment'], this.style['markerVerticalAlignment']].join('_');
|
14290 | }
|
14291 | return this._stamp;
|
14292 | };
|
14293 |
|
14294 | VectorMarkerSymbolizer.prototype._getAnchor = function _getAnchor(w, h) {
|
14295 | var shadow = 2 * (this.symbol['shadowBlur'] || 0),
|
14296 | margin = shadow + this.padding;
|
14297 | var p = getAlignPoint(new Size(w, h), this.style['markerHorizontalAlignment'], this.style['markerVerticalAlignment']);
|
14298 | if (p.x !== -w / 2) {
|
14299 | p.x -= sign(p.x + w / 2) * margin;
|
14300 | }
|
14301 | if (p.y !== -h / 2) {
|
14302 | p.y -= sign(p.y + h / 2) * margin;
|
14303 | }
|
14304 | return p;
|
14305 | };
|
14306 |
|
14307 | VectorMarkerSymbolizer.prototype._getCacheImageAnchor = function _getCacheImageAnchor(w, h) {
|
14308 | var shadow = 2 * (this.symbol['shadowBlur'] || 0),
|
14309 | margin = shadow + this.padding;
|
14310 | var markerType = this.style['markerType'];
|
14311 | if (markerType === 'bar' || markerType === 'pie' || markerType === 'pin') {
|
14312 | return new Point(w / 2, h - margin);
|
14313 | } else if (markerType === 'rectangle') {
|
14314 | return new Point(margin, margin);
|
14315 | } else {
|
14316 | return new Point(w / 2, h / 2);
|
14317 | }
|
14318 | };
|
14319 |
|
14320 | VectorMarkerSymbolizer.prototype._getGraidentExtent = function _getGraidentExtent(points) {
|
14321 | var e = new PointExtent(),
|
14322 | dxdy = this.getDxDy(),
|
14323 | m = this.getFixedExtent();
|
14324 | if (Array.isArray(points)) {
|
14325 | for (var i = points.length - 1; i >= 0; i--) {
|
14326 | e._combine(points[i]);
|
14327 | }
|
14328 | } else {
|
14329 | e._combine(points);
|
14330 | }
|
14331 | e['xmin'] += m['xmin'] - dxdy.x;
|
14332 | e['ymin'] += m['ymin'] - dxdy.y;
|
14333 | e['xmax'] += m['xmax'] - dxdy.x;
|
14334 | e['ymax'] += m['ymax'] - dxdy.y;
|
14335 | return e;
|
14336 | };
|
14337 |
|
14338 | VectorMarkerSymbolizer.prototype._drawVectorMarker = function _drawVectorMarker(ctx, point, resources) {
|
14339 | var style = this.style,
|
14340 | strokeAndFill = this.strokeAndFill,
|
14341 | markerType = style['markerType'].toLowerCase(),
|
14342 | vectorArray = VectorMarkerSymbolizer._getVectorPoints(markerType, style['markerWidth'], style['markerHeight']),
|
14343 | lineOpacity = strokeAndFill['lineOpacity'],
|
14344 | fillOpacity = strokeAndFill['polygonOpacity'];
|
14345 | var gradient = isGradient(strokeAndFill['lineColor']) || isGradient(strokeAndFill['polygonFill']);
|
14346 | if (gradient) {
|
14347 | var gradientExtent = void 0;
|
14348 | if (isGradient(strokeAndFill['lineColor'])) {
|
14349 | gradientExtent = this._getGraidentExtent(point);
|
14350 | strokeAndFill['lineGradientExtent'] = gradientExtent.expand(strokeAndFill['lineWidth']);
|
14351 | }
|
14352 | if (isGradient(strokeAndFill['polygonFill'])) {
|
14353 | if (!gradientExtent) {
|
14354 | gradientExtent = this._getGraidentExtent(point);
|
14355 | }
|
14356 | strokeAndFill['polygonGradientExtent'] = gradientExtent;
|
14357 | }
|
14358 | this.prepareCanvas(ctx, strokeAndFill, resources);
|
14359 | }
|
14360 |
|
14361 | var width = style['markerWidth'],
|
14362 | height = style['markerHeight'],
|
14363 | hLineWidth = style['markerLineWidth'] / 2;
|
14364 | if (markerType === 'ellipse') {
|
14365 | Canvas.ellipse(ctx, point, width / 2, height / 2, lineOpacity, fillOpacity);
|
14366 | } else if (markerType === 'cross' || markerType === 'x') {
|
14367 | for (var j = vectorArray.length - 1; j >= 0; j--) {
|
14368 | vectorArray[j]._add(point);
|
14369 | }
|
14370 |
|
14371 | Canvas.path(ctx, vectorArray.slice(0, 2), lineOpacity);
|
14372 | Canvas.path(ctx, vectorArray.slice(2, 4), lineOpacity);
|
14373 | } else if (markerType === 'diamond' || markerType === 'bar' || markerType === 'square' || markerType === 'rectangle' || markerType === 'triangle') {
|
14374 | if (markerType === 'bar') {
|
14375 | point = point.add(0, -hLineWidth);
|
14376 | } else if (markerType === 'rectangle') {
|
14377 | point = point.add(hLineWidth, hLineWidth);
|
14378 | }
|
14379 | for (var _j = vectorArray.length - 1; _j >= 0; _j--) {
|
14380 | vectorArray[_j]._add(point);
|
14381 | }
|
14382 |
|
14383 | Canvas.polygon(ctx, vectorArray, lineOpacity, fillOpacity);
|
14384 | } else if (markerType === 'pin') {
|
14385 | point = point.add(0, -hLineWidth);
|
14386 | for (var _j2 = vectorArray.length - 1; _j2 >= 0; _j2--) {
|
14387 | vectorArray[_j2]._add(point);
|
14388 | }
|
14389 | var lineCap = ctx.lineCap;
|
14390 | ctx.lineCap = 'round';
|
14391 | Canvas.bezierCurveAndFill(ctx, vectorArray, lineOpacity, fillOpacity);
|
14392 | ctx.lineCap = lineCap;
|
14393 | } else if (markerType === 'pie') {
|
14394 | point = point.add(0, -hLineWidth);
|
14395 | var angle = Math.atan(width / 2 / height) * 180 / Math.PI;
|
14396 | var _lineCap = ctx.lineCap;
|
14397 | ctx.lineCap = 'round';
|
14398 | Canvas.sector(ctx, point, height, [90 - angle, 90 + angle], lineOpacity, fillOpacity);
|
14399 | ctx.lineCap = _lineCap;
|
14400 | } else {
|
14401 | throw new Error('unsupported markerType: ' + markerType);
|
14402 | }
|
14403 | };
|
14404 |
|
14405 | VectorMarkerSymbolizer.prototype.getPlacement = function getPlacement() {
|
14406 | return this.symbol['markerPlacement'];
|
14407 | };
|
14408 |
|
14409 | VectorMarkerSymbolizer.prototype.getRotation = function getRotation() {
|
14410 | var r = this.style['markerRotation'];
|
14411 | if (!isNumber(r)) {
|
14412 | return null;
|
14413 | }
|
14414 |
|
14415 | return -r * Math.PI / 180;
|
14416 | };
|
14417 |
|
14418 | VectorMarkerSymbolizer.prototype.getFixedExtent = function getFixedExtent() {
|
14419 | var dxdy = this.getDxDy(),
|
14420 | padding = this.padding * 2;
|
14421 | var size = this._calMarkerSize().map(function (d) {
|
14422 | return d - padding;
|
14423 | });
|
14424 | var alignPoint = this._getAnchor(size[0], size[1]);
|
14425 | var result = new PointExtent(dxdy.add(0, 0), dxdy.add(size[0], size[1]));
|
14426 | result._add(alignPoint);
|
14427 | var rotation = this.getRotation();
|
14428 | if (rotation) {
|
14429 | result = this._rotateExtent(result, rotation);
|
14430 | }
|
14431 |
|
14432 | return result;
|
14433 | };
|
14434 |
|
14435 | VectorMarkerSymbolizer.prototype.translate = function translate() {
|
14436 | var s = this.symbol;
|
14437 | var result = {
|
14438 | 'markerType': getValueOrDefault(s['markerType'], 'ellipse'),
|
14439 | 'markerFill': getValueOrDefault(s['markerFill'], '#00f'),
|
14440 | 'markerFillOpacity': getValueOrDefault(s['markerFillOpacity'], 1),
|
14441 | 'markerFillPatternFile': getValueOrDefault(s['markerFillPatternFile'], null),
|
14442 | 'markerLineColor': getValueOrDefault(s['markerLineColor'], '#000'),
|
14443 | 'markerLineWidth': getValueOrDefault(s['markerLineWidth'], 1),
|
14444 | 'markerLineOpacity': getValueOrDefault(s['markerLineOpacity'], 1),
|
14445 | 'markerLineDasharray': getValueOrDefault(s['markerLineDasharray'], []),
|
14446 | 'markerLinePatternFile': getValueOrDefault(s['markerLinePatternFile'], null),
|
14447 |
|
14448 | 'markerDx': getValueOrDefault(s['markerDx'], 0),
|
14449 | 'markerDy': getValueOrDefault(s['markerDy'], 0),
|
14450 |
|
14451 | 'markerWidth': getValueOrDefault(s['markerWidth'], 10),
|
14452 | 'markerHeight': getValueOrDefault(s['markerHeight'], 10),
|
14453 |
|
14454 | 'markerRotation': getValueOrDefault(s['markerRotation'], 0)
|
14455 | };
|
14456 | var markerType = result['markerType'];
|
14457 | var ha = void 0,
|
14458 | va = void 0;
|
14459 | if (markerType === 'bar' || markerType === 'pie' || markerType === 'pin') {
|
14460 | ha = 'middle';
|
14461 | va = 'top';
|
14462 | } else if (markerType === 'rectangle') {
|
14463 | ha = 'right';
|
14464 | va = 'bottom';
|
14465 | } else {
|
14466 | ha = 'middle';
|
14467 | va = 'middle';
|
14468 | }
|
14469 |
|
14470 | result['markerHorizontalAlignment'] = getValueOrDefault(s['markerHorizontalAlignment'], ha);
|
14471 | result['markerVerticalAlignment'] = getValueOrDefault(s['markerVerticalAlignment'], va);
|
14472 | if (isNumber(s['markerOpacity'])) {
|
14473 | if (isNumber(s['markerFillOpacity'])) {
|
14474 | result['markerFillOpacity'] *= s['markerOpacity'];
|
14475 | }
|
14476 | if (isNumber(s['markerLineOpacity'])) {
|
14477 | result['markerLineOpacity'] *= s['markerOpacity'];
|
14478 | }
|
14479 | }
|
14480 | return result;
|
14481 | };
|
14482 |
|
14483 | VectorMarkerSymbolizer.translateLineAndFill = function translateLineAndFill(s) {
|
14484 | var result = {
|
14485 | 'lineColor': s['markerLineColor'],
|
14486 | 'linePatternFile': s['markerLinePatternFile'],
|
14487 | 'lineWidth': s['markerLineWidth'],
|
14488 | 'lineOpacity': s['markerLineOpacity'],
|
14489 | 'lineDasharray': s['markerLineDasharray'],
|
14490 | 'lineCap': 'butt',
|
14491 | 'lineJoin': 'round',
|
14492 | 'polygonFill': s['markerFill'],
|
14493 | 'polygonPatternFile': s['markerFillPatternFile'],
|
14494 | 'polygonOpacity': s['markerFillOpacity']
|
14495 | };
|
14496 | if (result['lineWidth'] === 0) {
|
14497 | result['lineOpacity'] = 0;
|
14498 | }
|
14499 | return result;
|
14500 | };
|
14501 |
|
14502 | VectorMarkerSymbolizer._getVectorPoints = function _getVectorPoints(markerType, width, height) {
|
14503 | var hh = height / 2,
|
14504 | hw = width / 2;
|
14505 | var left = 0,
|
14506 | top = 0;
|
14507 | var v0 = void 0,
|
14508 | v1 = void 0,
|
14509 | v2 = void 0,
|
14510 | v3 = void 0;
|
14511 | if (markerType === 'triangle') {
|
14512 | v0 = new Point(left, top - hh);
|
14513 | v1 = new Point(left - hw, top + hh);
|
14514 | v2 = new Point(left + hw, top + hh);
|
14515 | return [v0, v1, v2];
|
14516 | } else if (markerType === 'cross') {
|
14517 | v0 = new Point(left - hw, top);
|
14518 | v1 = new Point(left + hw, top);
|
14519 | v2 = new Point(left, top - hh);
|
14520 | v3 = new Point(left, top + hh);
|
14521 | return [v0, v1, v2, v3];
|
14522 | } else if (markerType === 'diamond') {
|
14523 | v0 = new Point(left - hw, top);
|
14524 | v1 = new Point(left, top - hh);
|
14525 | v2 = new Point(left + hw, top);
|
14526 | v3 = new Point(left, top + hh);
|
14527 | return [v0, v1, v2, v3];
|
14528 | } else if (markerType === 'square') {
|
14529 | v0 = new Point(left - hw, top + hh);
|
14530 | v1 = new Point(left + hw, top + hh);
|
14531 | v2 = new Point(left + hw, top - hh);
|
14532 | v3 = new Point(left - hw, top - hh);
|
14533 | return [v0, v1, v2, v3];
|
14534 | } else if (markerType === 'rectangle') {
|
14535 | v0 = new Point(left, top);
|
14536 | v1 = v0.add(width, 0);
|
14537 | v2 = v0.add(width, height);
|
14538 | v3 = v0.add(0, height);
|
14539 | return [v0, v1, v2, v3];
|
14540 | } else if (markerType === 'x') {
|
14541 | v0 = new Point(left - hw, top + hh);
|
14542 | v1 = new Point(left + hw, top - hh);
|
14543 | v2 = new Point(left + hw, top + hh);
|
14544 | v3 = new Point(left - hw, top - hh);
|
14545 | return [v0, v1, v2, v3];
|
14546 | } else if (markerType === 'bar') {
|
14547 | v0 = new Point(left - hw, top - height);
|
14548 | v1 = new Point(left + hw, top - height);
|
14549 | v2 = new Point(left + hw, top);
|
14550 | v3 = new Point(left - hw, top);
|
14551 | return [v0, v1, v2, v3];
|
14552 | } else if (markerType === 'pin') {
|
14553 | var extWidth = height * Math.atan(hw / hh);
|
14554 | v0 = new Point(left, top);
|
14555 | v1 = new Point(left - extWidth, top - height);
|
14556 | v2 = new Point(left + extWidth, top - height);
|
14557 | v3 = new Point(left, top);
|
14558 | return [v0, v1, v2, v3];
|
14559 | }
|
14560 | return [];
|
14561 | };
|
14562 |
|
14563 | return VectorMarkerSymbolizer;
|
14564 | }(PointSymbolizer);
|
14565 |
|
14566 | var DebugSymbolizer = function (_PointSymbolizer) {
|
14567 | inherits(DebugSymbolizer, _PointSymbolizer);
|
14568 |
|
14569 | function DebugSymbolizer() {
|
14570 | classCallCheck(this, DebugSymbolizer);
|
14571 | return possibleConstructorReturn(this, _PointSymbolizer.apply(this, arguments));
|
14572 | }
|
14573 |
|
14574 | DebugSymbolizer.prototype.getPlacement = function getPlacement() {
|
14575 | return 'point';
|
14576 | };
|
14577 |
|
14578 | DebugSymbolizer.prototype.getDxDy = function getDxDy() {
|
14579 | return new Point(0, 0);
|
14580 | };
|
14581 |
|
14582 | DebugSymbolizer.prototype.symbolize = function symbolize(ctx) {
|
14583 | var geometry = this.geometry,
|
14584 | layer = geometry.getLayer();
|
14585 | if (!geometry.options['debug'] && layer && !layer.options['debug']) {
|
14586 | return;
|
14587 | }
|
14588 | var map = this.getMap();
|
14589 | if (!map || map.isZooming()) {
|
14590 | return;
|
14591 | }
|
14592 | var color = layer.options['debugOutline'],
|
14593 | op = 1;
|
14594 | ctx.strokeStyle = color;
|
14595 | ctx.fillStyle = color;
|
14596 |
|
14597 | var outline = this.getPainter().getContainerExtent().toArray();
|
14598 | Canvas.polygon(ctx, [outline], op, 0);
|
14599 |
|
14600 | var points = this._getRenderContainerPoints(),
|
14601 | id = this.geometry.getId(),
|
14602 | cross = VectorMarkerSymbolizer._getVectorPoints('cross', 10, 10);
|
14603 | for (var i = 0; i < points.length; i++) {
|
14604 | var p = points[i];
|
14605 | if (!isNil(id)) {
|
14606 | Canvas.fillText(ctx, id, p.add(8, -4), color);
|
14607 | }
|
14608 | var c = [];
|
14609 | for (var ii = 0; ii < cross.length; ii++) {
|
14610 | c.push(cross[ii].add(p));
|
14611 | }
|
14612 | Canvas.path(ctx, c.slice(0, 2), op);
|
14613 | Canvas.path(ctx, c.slice(2, 4), op);
|
14614 | }
|
14615 | };
|
14616 |
|
14617 | return DebugSymbolizer;
|
14618 | }(PointSymbolizer);
|
14619 |
|
14620 | var ImageMarkerSymbolizer = function (_PointSymbolizer) {
|
14621 | inherits(ImageMarkerSymbolizer, _PointSymbolizer);
|
14622 |
|
14623 | ImageMarkerSymbolizer.test = function test(symbol) {
|
14624 | if (!symbol) {
|
14625 | return false;
|
14626 | }
|
14627 | if (!isNil(symbol['markerFile'])) {
|
14628 | return true;
|
14629 | }
|
14630 | return false;
|
14631 | };
|
14632 |
|
14633 | function ImageMarkerSymbolizer(symbol, geometry, painter) {
|
14634 | classCallCheck(this, ImageMarkerSymbolizer);
|
14635 |
|
14636 | var _this = possibleConstructorReturn(this, _PointSymbolizer.call(this, symbol, geometry, painter));
|
14637 |
|
14638 | _this.style = _this._defineStyle(_this.translate());
|
14639 | return _this;
|
14640 | }
|
14641 |
|
14642 | ImageMarkerSymbolizer.prototype.symbolize = function symbolize(ctx, resources) {
|
14643 | var style = this.style;
|
14644 | if (!this.painter.isHitTesting() && (style['markerWidth'] === 0 || style['markerHeight'] === 0 || style['markerOpacity'] === 0)) {
|
14645 | return;
|
14646 | }
|
14647 | var cookedPoints = this._getRenderContainerPoints();
|
14648 | if (!isArrayHasData(cookedPoints)) {
|
14649 | return;
|
14650 | }
|
14651 |
|
14652 | var img = this._getImage(resources);
|
14653 | if (!img) {
|
14654 | if (typeof console !== 'undefined') {
|
14655 | console.warn('no img found for ' + (this.style['markerFile'] || this._url[0]));
|
14656 | }
|
14657 | return;
|
14658 | }
|
14659 | this._prepareContext(ctx);
|
14660 | var width = style['markerWidth'];
|
14661 | var height = style['markerHeight'];
|
14662 | if (!isNumber(width) || !isNumber(height)) {
|
14663 | width = img.width;
|
14664 | height = img.height;
|
14665 | style['markerWidth'] = width;
|
14666 | style['markerHeight'] = height;
|
14667 | var imgURL = [style['markerFile'], style['markerWidth'], style['markerHeight']];
|
14668 | if (!resources.isResourceLoaded(imgURL)) {
|
14669 | resources.addResource(imgURL, img);
|
14670 | }
|
14671 | var painter = this.getPainter();
|
14672 | if (!painter.isSpriting()) {
|
14673 | painter.removeCache();
|
14674 | }
|
14675 | }
|
14676 | var alpha = void 0;
|
14677 |
|
14678 | if (this.symbol['markerType'] !== 'path' && isNumber(style['markerOpacity']) && style['markerOpacity'] < 1) {
|
14679 | alpha = ctx.globalAlpha;
|
14680 | ctx.globalAlpha *= style['markerOpacity'];
|
14681 | }
|
14682 | var alignPoint = getAlignPoint(new Size(width, height), style['markerHorizontalAlignment'], style['markerVerticalAlignment']);
|
14683 | for (var i = 0, len = cookedPoints.length; i < len; i++) {
|
14684 | var p = cookedPoints[i];
|
14685 | var origin = this._rotate(ctx, p, this._getRotationAt(i));
|
14686 | if (origin) {
|
14687 | p = origin;
|
14688 | }
|
14689 | Canvas.image(ctx, img, p.x + alignPoint.x, p.y + alignPoint.y, width, height);
|
14690 | if (origin) {
|
14691 | ctx.restore();
|
14692 | }
|
14693 | }
|
14694 | if (alpha !== undefined) {
|
14695 | ctx.globalAlpha = alpha;
|
14696 | }
|
14697 | };
|
14698 |
|
14699 | ImageMarkerSymbolizer.prototype._getImage = function _getImage(resources) {
|
14700 | var img = !resources ? null : resources.getImage([this.style['markerFile'], this.style['markerWidth'], this.style['markerHeight']]);
|
14701 | return img;
|
14702 | };
|
14703 |
|
14704 | ImageMarkerSymbolizer.prototype.getPlacement = function getPlacement() {
|
14705 | return this.symbol['markerPlacement'];
|
14706 | };
|
14707 |
|
14708 | ImageMarkerSymbolizer.prototype.getRotation = function getRotation() {
|
14709 | var r = this.style['markerRotation'];
|
14710 | if (!isNumber(r)) {
|
14711 | return null;
|
14712 | }
|
14713 |
|
14714 | return -r * Math.PI / 180;
|
14715 | };
|
14716 |
|
14717 | ImageMarkerSymbolizer.prototype.getDxDy = function getDxDy() {
|
14718 | var s = this.style;
|
14719 | var dx = s['markerDx'],
|
14720 | dy = s['markerDy'];
|
14721 | return new Point(dx, dy);
|
14722 | };
|
14723 |
|
14724 | ImageMarkerSymbolizer.prototype.getFixedExtent = function getFixedExtent(resources) {
|
14725 | var style = this.style;
|
14726 | var url = style['markerFile'],
|
14727 | img = resources ? resources.getImage(url) : null;
|
14728 | var width = style['markerWidth'] || (img ? img.width : 0),
|
14729 | height = style['markerHeight'] || (img ? img.height : 0);
|
14730 | var dxdy = this.getDxDy();
|
14731 | var alignPoint = getAlignPoint(new Size(width, height), style['markerHorizontalAlignment'], style['markerVerticalAlignment']);
|
14732 | var result = new PointExtent(dxdy.add(0, 0), dxdy.add(width, height));
|
14733 | result._add(alignPoint);
|
14734 | var rotation = this.getRotation();
|
14735 | if (rotation) {
|
14736 | result = this._rotateExtent(result, rotation);
|
14737 | }
|
14738 | return result;
|
14739 | };
|
14740 |
|
14741 | ImageMarkerSymbolizer.prototype.translate = function translate() {
|
14742 | var s = this.symbol;
|
14743 | return {
|
14744 | 'markerFile': s['markerFile'],
|
14745 | 'markerOpacity': getValueOrDefault(s['markerOpacity'], 1),
|
14746 | 'markerWidth': getValueOrDefault(s['markerWidth'], null),
|
14747 | 'markerHeight': getValueOrDefault(s['markerHeight'], null),
|
14748 | 'markerRotation': getValueOrDefault(s['markerRotation'], 0),
|
14749 |
|
14750 | 'markerDx': getValueOrDefault(s['markerDx'], 0),
|
14751 | 'markerDy': getValueOrDefault(s['markerDy'], 0),
|
14752 |
|
14753 | 'markerHorizontalAlignment': getValueOrDefault(s['markerHorizontalAlignment'], 'middle'),
|
14754 | 'markerVerticalAlignment': getValueOrDefault(s['markerVerticalAlignment'], 'top') };
|
14755 | };
|
14756 |
|
14757 | return ImageMarkerSymbolizer;
|
14758 | }(PointSymbolizer);
|
14759 |
|
14760 | var StrokeAndFillSymbolizer = function (_CanvasSymbolizer) {
|
14761 | inherits(StrokeAndFillSymbolizer, _CanvasSymbolizer);
|
14762 |
|
14763 | StrokeAndFillSymbolizer.test = function test(symbol, geometry) {
|
14764 | if (!symbol) {
|
14765 | return false;
|
14766 | }
|
14767 | if (geometry && geometry.type === 'Point') {
|
14768 | return false;
|
14769 | }
|
14770 | for (var p in symbol) {
|
14771 | var f = p.slice(0, 4);
|
14772 | if (f === 'line' || f === 'poly') {
|
14773 | return true;
|
14774 | }
|
14775 | }
|
14776 | return false;
|
14777 | };
|
14778 |
|
14779 | function StrokeAndFillSymbolizer(symbol, geometry, painter) {
|
14780 | classCallCheck(this, StrokeAndFillSymbolizer);
|
14781 |
|
14782 | var _this = possibleConstructorReturn(this, _CanvasSymbolizer.call(this));
|
14783 |
|
14784 | _this.symbol = symbol;
|
14785 | _this.geometry = geometry;
|
14786 | _this.painter = painter;
|
14787 | if (geometry.type === 'Point') {
|
14788 | return possibleConstructorReturn(_this);
|
14789 | }
|
14790 | _this.style = _this._defineStyle(_this.translate());
|
14791 | return _this;
|
14792 | }
|
14793 |
|
14794 | StrokeAndFillSymbolizer.prototype.symbolize = function symbolize(ctx, resources) {
|
14795 | var style = this.style;
|
14796 | if (style['polygonOpacity'] === 0 && style['lineOpacity'] === 0 && !this.painter.isHitTesting()) {
|
14797 | return;
|
14798 | }
|
14799 | var paintParams = this._getPaintParams();
|
14800 | if (!paintParams) {
|
14801 | return;
|
14802 | }
|
14803 | this._prepareContext(ctx);
|
14804 | var isGradient$$1 = isGradient(style['lineColor']),
|
14805 | isPath = this.geometry.getJSONType() === 'Polygon' || this.geometry.type === 'LineString';
|
14806 | if (isGradient$$1 && (style['lineColor']['places'] || !isPath)) {
|
14807 | style['lineGradientExtent'] = this.getPainter().getContainerExtent()._expand(style['lineWidth']);
|
14808 | }
|
14809 | if (isGradient(style['polygonFill'])) {
|
14810 | style['polygonGradientExtent'] = this.getPainter().getContainerExtent();
|
14811 | }
|
14812 |
|
14813 | var points = paintParams[0],
|
14814 | isSplitted = this.geometry.getJSONType() === 'Polygon' && points.length > 0 && Array.isArray(points[0][0]) || this.geometry.type === 'LineString' && points.length > 0 && Array.isArray(points[0]);
|
14815 |
|
14816 | if (isSplitted) {
|
14817 | for (var i = 0; i < points.length; i++) {
|
14818 | this.prepareCanvas(ctx, style, resources);
|
14819 | if (isGradient$$1 && isPath && !style['lineColor']['places']) {
|
14820 | this._createGradient(ctx, points[i], style['lineColor']);
|
14821 | }
|
14822 | var params = [ctx, points[i]];
|
14823 | if (paintParams.length > 1) {
|
14824 | params.push.apply(params, paintParams.slice(1));
|
14825 | }
|
14826 | params.push(style['lineOpacity'], style['polygonOpacity'], style['lineDasharray']);
|
14827 | this.geometry._paintOn.apply(this.geometry, params);
|
14828 | }
|
14829 | } else {
|
14830 | this.prepareCanvas(ctx, style, resources);
|
14831 | if (isGradient$$1 && isPath && !style['lineColor']['places']) {
|
14832 | this._createGradient(ctx, points, style['lineColor']);
|
14833 | }
|
14834 | var _params = [ctx];
|
14835 | _params.push.apply(_params, paintParams);
|
14836 | _params.push(style['lineOpacity'], style['polygonOpacity'], style['lineDasharray']);
|
14837 | this.geometry._paintOn.apply(this.geometry, _params);
|
14838 | }
|
14839 |
|
14840 | if (ctx.setLineDash && Array.isArray(style['lineDasharray'])) {
|
14841 | ctx.setLineDash([]);
|
14842 | }
|
14843 | };
|
14844 |
|
14845 | StrokeAndFillSymbolizer.prototype.get2DExtent = function get2DExtent() {
|
14846 | var map = this.getMap();
|
14847 | var extent = this.geometry._getPrjExtent();
|
14848 | if (!extent) {
|
14849 | return null;
|
14850 | }
|
14851 |
|
14852 | if (!this._extMin || !this._extMax) {
|
14853 | this._extMin = new Coordinate(0, 0);
|
14854 | this._extMax = new Coordinate(0, 0);
|
14855 | }
|
14856 | this._extMin.x = extent['xmin'];
|
14857 | this._extMin.y = extent['ymin'];
|
14858 | this._extMax.x = extent['xmax'];
|
14859 | this._extMax.y = extent['ymax'];
|
14860 | var min = map._prjToPoint(this._extMin),
|
14861 | max = map._prjToPoint(this._extMax);
|
14862 | if (!this._pxExtent) {
|
14863 | this._pxExtent = new PointExtent(min, max);
|
14864 | } else {
|
14865 | this._pxExtent['xmin'] = Math.min(min.x, max.x);
|
14866 | this._pxExtent['xmax'] = Math.max(min.x, max.x);
|
14867 | this._pxExtent['ymin'] = Math.min(min.y, max.y);
|
14868 | this._pxExtent['ymax'] = Math.max(min.y, max.y);
|
14869 | }
|
14870 | return this._pxExtent;
|
14871 | };
|
14872 |
|
14873 | StrokeAndFillSymbolizer.prototype.getFixedExtent = function getFixedExtent() {
|
14874 | var t = this.style['lineWidth'] / 2;
|
14875 | return new PointExtent(-t, -t, t, t);
|
14876 | };
|
14877 |
|
14878 | StrokeAndFillSymbolizer.prototype._getPaintParams = function _getPaintParams() {
|
14879 | return this.getPainter().getPaintParams(this.style['lineDx'], this.style['lineDy']);
|
14880 | };
|
14881 |
|
14882 | StrokeAndFillSymbolizer.prototype.translate = function translate() {
|
14883 | var s = this.symbol;
|
14884 | var result = {
|
14885 | 'lineColor': getValueOrDefault(s['lineColor'], '#000'),
|
14886 | 'lineWidth': getValueOrDefault(s['lineWidth'], 2),
|
14887 | 'lineOpacity': getValueOrDefault(s['lineOpacity'], 1),
|
14888 | 'lineDasharray': getValueOrDefault(s['lineDasharray'], []),
|
14889 | 'lineCap': getValueOrDefault(s['lineCap'], 'butt'),
|
14890 | 'lineJoin': getValueOrDefault(s['lineJoin'], 'miter'),
|
14891 | 'linePatternFile': getValueOrDefault(s['linePatternFile'], null),
|
14892 | 'lineDx': getValueOrDefault(s['lineDx'], 0),
|
14893 | 'lineDy': getValueOrDefault(s['lineDy'], 0),
|
14894 | 'polygonFill': getValueOrDefault(s['polygonFill'], null),
|
14895 | 'polygonOpacity': getValueOrDefault(s['polygonOpacity'], 1),
|
14896 | 'polygonPatternFile': getValueOrDefault(s['polygonPatternFile'], null),
|
14897 | 'polygonPatternDx': getValueOrDefault(s['polygonPatternDx'], 0),
|
14898 | 'polygonPatternDy': getValueOrDefault(s['polygonPatternDy'], 0),
|
14899 | 'linePatternDx': getValueOrDefault(s['linePatternDx'], 0),
|
14900 | 'linePatternDy': getValueOrDefault(s['linePatternDy'], 0)
|
14901 | };
|
14902 | if (result['lineWidth'] === 0) {
|
14903 | result['lineOpacity'] = 0;
|
14904 | }
|
14905 |
|
14906 | if (this.geometry.type === 'LineString' && !result['polygonFill']) {
|
14907 | result['polygonFill'] = result['lineColor'];
|
14908 | }
|
14909 | return result;
|
14910 | };
|
14911 |
|
14912 | StrokeAndFillSymbolizer.prototype._createGradient = function _createGradient(ctx, points, lineColor) {
|
14913 | if (!Array.isArray(points)) {
|
14914 | return;
|
14915 | }
|
14916 | var len = points.length;
|
14917 | var grad = ctx.createLinearGradient(points[0].x, points[0].y, points[len - 1].x, points[len - 1].y);
|
14918 | lineColor['colorStops'].forEach(function (stop) {
|
14919 | grad.addColorStop.apply(grad, stop);
|
14920 | });
|
14921 | ctx.strokeStyle = grad;
|
14922 | };
|
14923 |
|
14924 | return StrokeAndFillSymbolizer;
|
14925 | }(CanvasSymbolizer);
|
14926 |
|
14927 | var CACHE_KEY = '___text_symbol_cache';
|
14928 |
|
14929 | var TextMarkerSymbolizer = function (_PointSymbolizer) {
|
14930 | inherits(TextMarkerSymbolizer, _PointSymbolizer);
|
14931 |
|
14932 | TextMarkerSymbolizer.test = function test(symbol) {
|
14933 | if (!symbol) {
|
14934 | return false;
|
14935 | }
|
14936 | if (!isNil(symbol['textName'])) {
|
14937 | return true;
|
14938 | }
|
14939 | return false;
|
14940 | };
|
14941 |
|
14942 | function TextMarkerSymbolizer(symbol, geometry, painter) {
|
14943 | classCallCheck(this, TextMarkerSymbolizer);
|
14944 |
|
14945 | var _this = possibleConstructorReturn(this, _PointSymbolizer.call(this, symbol, geometry, painter));
|
14946 |
|
14947 | _this._dynamic = hasFunctionDefinition(symbol);
|
14948 | _this.style = _this._defineStyle(_this.translate());
|
14949 | if (_this.style['textWrapWidth'] === 0) {
|
14950 | return possibleConstructorReturn(_this);
|
14951 | }
|
14952 | _this.strokeAndFill = _this._defineStyle(_this.translateLineAndFill(_this.style));
|
14953 | var textContent = replaceVariable(_this.style['textName'], _this.geometry.getProperties());
|
14954 | if (!_this._dynamic) {
|
14955 | _this._cacheKey = genCacheKey(textContent, _this.style);
|
14956 | }
|
14957 | _this._descText(textContent);
|
14958 | return _this;
|
14959 | }
|
14960 |
|
14961 | TextMarkerSymbolizer.prototype.symbolize = function symbolize(ctx, resources) {
|
14962 | if (!this.painter.isHitTesting() && (this.style['textSize'] === 0 || !this.style['textOpacity'] && (!this.style['textHaloRadius'] || !this.style['textHaloOpacity']) || this.style['textWrapWidth'] === 0)) {
|
14963 | return;
|
14964 | }
|
14965 | var cookedPoints = this._getRenderContainerPoints();
|
14966 | if (!isArrayHasData(cookedPoints)) {
|
14967 | return;
|
14968 | }
|
14969 | var style = this.style,
|
14970 | strokeAndFill = this.strokeAndFill;
|
14971 | var textContent = replaceVariable(this.style['textName'], this.geometry.getProperties());
|
14972 | this._descText(textContent);
|
14973 | this._prepareContext(ctx);
|
14974 | this.prepareCanvas(ctx, strokeAndFill, resources);
|
14975 | Canvas.prepareCanvasFont(ctx, style);
|
14976 | for (var i = 0, len = cookedPoints.length; i < len; i++) {
|
14977 | var p = cookedPoints[i];
|
14978 | var origin = this._rotate(ctx, p, this._getRotationAt(i));
|
14979 | if (origin) {
|
14980 | p = origin;
|
14981 | }
|
14982 | Canvas.text(ctx, textContent, p, style, this.textDesc);
|
14983 | if (origin) {
|
14984 | ctx.restore();
|
14985 | }
|
14986 | }
|
14987 | };
|
14988 |
|
14989 | TextMarkerSymbolizer.prototype.getPlacement = function getPlacement() {
|
14990 | return this.symbol['textPlacement'];
|
14991 | };
|
14992 |
|
14993 | TextMarkerSymbolizer.prototype.getRotation = function getRotation() {
|
14994 | var r = this.style['textRotation'];
|
14995 | if (!isNumber(r)) {
|
14996 | return null;
|
14997 | }
|
14998 |
|
14999 | return -r * Math.PI / 180;
|
15000 | };
|
15001 |
|
15002 | TextMarkerSymbolizer.prototype.getDxDy = function getDxDy() {
|
15003 | var s = this.style;
|
15004 | return new Point(s['textDx'], s['textDy']);
|
15005 | };
|
15006 |
|
15007 | TextMarkerSymbolizer.prototype.getFixedExtent = function getFixedExtent() {
|
15008 | var dxdy = this.getDxDy(),
|
15009 | style = this.style;
|
15010 | var size = this.textDesc['size'];
|
15011 | var alignPoint = getAlignPoint(size, style['textHorizontalAlignment'], style['textVerticalAlignment']);
|
15012 | var alignW = alignPoint.x,
|
15013 | alignH = alignPoint.y;
|
15014 | if (style['textHaloRadius']) {
|
15015 | var r = style['textHaloRadius'];
|
15016 | size = size.add(r * 2, r * 2);
|
15017 | }
|
15018 | var result = new PointExtent(dxdy.add(alignW, alignH), dxdy.add(alignW + size['width'], alignH + size['height']));
|
15019 | var rotation = this.getRotation();
|
15020 | if (rotation) {
|
15021 | result = this._rotateExtent(result, rotation);
|
15022 | }
|
15023 | return result;
|
15024 | };
|
15025 |
|
15026 | TextMarkerSymbolizer.prototype.translate = function translate() {
|
15027 | var s = this.symbol;
|
15028 | var result = {
|
15029 | 'textName': s['textName'],
|
15030 | 'textFaceName': getValueOrDefault(s['textFaceName'], 'monospace'),
|
15031 | 'textWeight': getValueOrDefault(s['textWeight'], 'normal'),
|
15032 | 'textStyle': getValueOrDefault(s['textStyle'], 'normal'),
|
15033 | 'textSize': getValueOrDefault(s['textSize'], 10),
|
15034 | 'textFont': getValueOrDefault(s['textFont'], null),
|
15035 | 'textFill': getValueOrDefault(s['textFill'], '#000'),
|
15036 | 'textOpacity': getValueOrDefault(s['textOpacity'], 1),
|
15037 |
|
15038 | 'textHaloFill': getValueOrDefault(s['textHaloFill'], '#ffffff'),
|
15039 | 'textHaloRadius': getValueOrDefault(s['textHaloRadius'], 0),
|
15040 | 'textHaloOpacity': getValueOrDefault(s['textHaloOpacity'], 1),
|
15041 |
|
15042 | 'textWrapWidth': getValueOrDefault(s['textWrapWidth'], null),
|
15043 | 'textWrapCharacter': getValueOrDefault(s['textWrapCharacter'], '\n'),
|
15044 | 'textLineSpacing': getValueOrDefault(s['textLineSpacing'], 0),
|
15045 |
|
15046 | 'textDx': getValueOrDefault(s['textDx'], 0),
|
15047 | 'textDy': getValueOrDefault(s['textDy'], 0),
|
15048 |
|
15049 | 'textHorizontalAlignment': getValueOrDefault(s['textHorizontalAlignment'], 'middle'),
|
15050 | 'textVerticalAlignment': getValueOrDefault(s['textVerticalAlignment'], 'middle'),
|
15051 | 'textAlign': getValueOrDefault(s['textAlign'], 'center'),
|
15052 |
|
15053 | 'textRotation': getValueOrDefault(s['textRotation'], 0),
|
15054 |
|
15055 | 'textMaxWidth': getValueOrDefault(s['textMaxWidth'], 0),
|
15056 | 'textMaxHeight': getValueOrDefault(s['textMaxHeight'], 0)
|
15057 | };
|
15058 |
|
15059 | if (result['textMaxWidth'] > 0 && (!result['textWrapWidth'] || result['textWrapWidth'] > result['textMaxWidth'])) {
|
15060 | if (!result['textWrapWidth']) {
|
15061 | result['textMaxHeight'] = 1;
|
15062 | }
|
15063 | result['textWrapWidth'] = result['textMaxWidth'];
|
15064 | }
|
15065 | return result;
|
15066 | };
|
15067 |
|
15068 | TextMarkerSymbolizer.prototype.translateLineAndFill = function translateLineAndFill(s) {
|
15069 | return {
|
15070 | 'lineColor': s['textHaloRadius'] ? s['textHaloFill'] : s['textFill'],
|
15071 | 'lineWidth': s['textHaloRadius'],
|
15072 | 'lineOpacity': s['textOpacity'],
|
15073 | 'lineDasharray': null,
|
15074 | 'lineCap': 'butt',
|
15075 | 'lineJoin': 'round',
|
15076 | 'polygonFill': s['textFill'],
|
15077 | 'polygonOpacity': s['textOpacity']
|
15078 | };
|
15079 | };
|
15080 |
|
15081 | TextMarkerSymbolizer.prototype._descText = function _descText(textContent) {
|
15082 | if (this._dynamic) {
|
15083 | this.textDesc = this._measureText(textContent);
|
15084 | return;
|
15085 | }
|
15086 | this.textDesc = this._loadFromCache();
|
15087 | if (!this.textDesc) {
|
15088 | this.textDesc = this._measureText(textContent);
|
15089 | this._storeToCache(this.textDesc);
|
15090 | }
|
15091 | };
|
15092 |
|
15093 | TextMarkerSymbolizer.prototype._measureText = function _measureText(textContent) {
|
15094 | var maxHeight = this.style['textMaxHeight'];
|
15095 | var textDesc = splitTextToRow(textContent, this.style);
|
15096 | if (maxHeight && maxHeight < textDesc.size.height) {
|
15097 | textDesc.size.height = maxHeight;
|
15098 | }
|
15099 | return textDesc;
|
15100 | };
|
15101 |
|
15102 | TextMarkerSymbolizer.prototype._storeToCache = function _storeToCache(textDesc) {
|
15103 | if (IS_NODE) {
|
15104 | return;
|
15105 | }
|
15106 | if (!this.geometry[CACHE_KEY]) {
|
15107 | this.geometry[CACHE_KEY] = {};
|
15108 | }
|
15109 | this.geometry[CACHE_KEY][this._cacheKey] = { 'desc': textDesc, 'active': true };
|
15110 | };
|
15111 |
|
15112 | TextMarkerSymbolizer.prototype._loadFromCache = function _loadFromCache() {
|
15113 | if (!this.geometry[CACHE_KEY]) {
|
15114 | return null;
|
15115 | }
|
15116 | var cache = this.geometry[CACHE_KEY][this._cacheKey];
|
15117 | if (!cache) {
|
15118 | return null;
|
15119 | }
|
15120 | cache.active = true;
|
15121 | return cache.desc;
|
15122 | };
|
15123 |
|
15124 | return TextMarkerSymbolizer;
|
15125 | }(PointSymbolizer);
|
15126 |
|
15127 | TextMarkerSymbolizer.CACHE_KEY = CACHE_KEY;
|
15128 |
|
15129 | function genCacheKey(textContent, style) {
|
15130 | var key = [textContent];
|
15131 | for (var p in style) {
|
15132 | if (style.hasOwnProperty(p) && p.length > 4 && p.substring(0, 4) === 'text') {
|
15133 | key.push(p + '=' + style[p]);
|
15134 | }
|
15135 | }
|
15136 | return key.join('-');
|
15137 | }
|
15138 |
|
15139 | var VectorPathMarkerSymbolizer = function (_ImageMarkerSymbolize) {
|
15140 | inherits(VectorPathMarkerSymbolizer, _ImageMarkerSymbolize);
|
15141 |
|
15142 | VectorPathMarkerSymbolizer.test = function test(symbol) {
|
15143 | if (!symbol) {
|
15144 | return false;
|
15145 | }
|
15146 | if (isNil(symbol['markerFile']) && symbol['markerType'] === 'path') {
|
15147 | return true;
|
15148 | }
|
15149 | return false;
|
15150 | };
|
15151 |
|
15152 | function VectorPathMarkerSymbolizer(symbol, geometry, painter) {
|
15153 | classCallCheck(this, VectorPathMarkerSymbolizer);
|
15154 |
|
15155 | var _this = possibleConstructorReturn(this, _ImageMarkerSymbolize.call(this, symbol, geometry, painter));
|
15156 |
|
15157 | _this.style = _this._defineStyle(_this.translate());
|
15158 |
|
15159 | if (isNil(_this.style['markerWidth'])) {
|
15160 | _this.style['markerWidth'] = 80;
|
15161 | }
|
15162 | if (isNil(_this.style['markerHeight'])) {
|
15163 | _this.style['markerHeight'] = 80;
|
15164 | }
|
15165 | if (Browser$1.gecko) {
|
15166 | _this._url = [getMarkerPathBase64(symbol, _this.style['markerWidth'], _this.style['markerHeight']), _this.style['markerWidth'], _this.style['markerHeight']];
|
15167 | } else {
|
15168 | _this._url = [getMarkerPathBase64(symbol), symbol['markerWidth'], symbol['markerHeight']];
|
15169 | }
|
15170 | return _this;
|
15171 | }
|
15172 |
|
15173 | VectorPathMarkerSymbolizer.prototype._prepareContext = function _prepareContext() {};
|
15174 |
|
15175 | VectorPathMarkerSymbolizer.prototype._getImage = function _getImage(resources) {
|
15176 | if (resources && resources.isResourceLoaded(this._url)) {
|
15177 | return resources.getImage(this._url);
|
15178 | }
|
15179 | var image = new Image();
|
15180 | image.src = this._url[0];
|
15181 | if (resources) {
|
15182 | resources.addResource(this._url, image);
|
15183 | }
|
15184 | return image;
|
15185 | };
|
15186 |
|
15187 | return VectorPathMarkerSymbolizer;
|
15188 | }(ImageMarkerSymbolizer);
|
15189 |
|
15190 | var defaultSymbol = {
|
15191 | lineWidth: 1,
|
15192 | polygonFill: '#fff',
|
15193 | polygonOpacity: 0.5
|
15194 | };
|
15195 |
|
15196 | var DrawAltitudeSymbolizer = function (_PointSymbolizer) {
|
15197 | inherits(DrawAltitudeSymbolizer, _PointSymbolizer);
|
15198 |
|
15199 | DrawAltitudeSymbolizer.test = function test(symbol, geometry) {
|
15200 | var layer = geometry.getLayer();
|
15201 | if (!layer) {
|
15202 | return false;
|
15203 | }
|
15204 | var type = geometry.getJSONType();
|
15205 |
|
15206 | return type === 'Marker' || type === 'LineString';
|
15207 | };
|
15208 |
|
15209 | function DrawAltitudeSymbolizer(symbol, geometry, painter) {
|
15210 | classCallCheck(this, DrawAltitudeSymbolizer);
|
15211 |
|
15212 | var _this = possibleConstructorReturn(this, _PointSymbolizer.call(this, symbol, geometry, painter));
|
15213 |
|
15214 | _this.style = geometry.getLayer().options['drawAltitude'];
|
15215 | if (!_this.style || !isObject(_this.style)) {
|
15216 | _this.style = {
|
15217 | 'lineWidth': 2
|
15218 | };
|
15219 | }
|
15220 | if (!_this.style['lineWidth']) {
|
15221 | _this.style['lineWidth'] = 0;
|
15222 | }
|
15223 | _this.dxdy = _this._defineStyle({
|
15224 | 'dx': symbol['textDx'] || symbol['markerDx'],
|
15225 | 'dy': symbol['textDy'] || symbol['markerDy']
|
15226 | });
|
15227 | return _this;
|
15228 | }
|
15229 |
|
15230 | DrawAltitudeSymbolizer.prototype.symbolize = function symbolize(ctx) {
|
15231 | var layer = this.geometry.getLayer();
|
15232 | if (!layer.options['drawAltitude']) {
|
15233 | return;
|
15234 | }
|
15235 | var properties = this.geometry.getProperties();
|
15236 | if (!properties || !properties[layer.options['altitudeProperty']]) {
|
15237 | return;
|
15238 | }
|
15239 | var style = this._getStyle();
|
15240 | this._prepareContext(ctx);
|
15241 | if (this.geometry.type === 'LineString') {
|
15242 | var paintParams = this._getPaintParams(style['lineDx'], style['lineDy']);
|
15243 | if (!paintParams) {
|
15244 | return;
|
15245 | }
|
15246 |
|
15247 | var groundPoints = this.getPainter().getPaintParams(style['lineDx'], style['lineDy'], true)[0];
|
15248 | this._drawLineAltitude(ctx, paintParams[0], groundPoints);
|
15249 | } else {
|
15250 | var point = this._getRenderContainerPoints(),
|
15251 | groundPoint = this._getRenderContainerPoints(true);
|
15252 | if (!point || point.length === 0) {
|
15253 | return;
|
15254 | }
|
15255 | this._drawMarkerAltitude(ctx, point[0], groundPoint[0]);
|
15256 | }
|
15257 | };
|
15258 |
|
15259 | DrawAltitudeSymbolizer.prototype.getDxDy = function getDxDy() {
|
15260 | var s = this.dxdy;
|
15261 | return new Point(s['dx'] || 0, s['dy'] || 0);
|
15262 | };
|
15263 |
|
15264 | DrawAltitudeSymbolizer.prototype.get2DExtent = function get2DExtent() {
|
15265 | if (this.geometry.type === 'LineString') {
|
15266 | return StrokeAndFillSymbolizer.prototype.get2DExtent.apply(this);
|
15267 | } else {
|
15268 | return _PointSymbolizer.prototype.get2DExtent.call(this);
|
15269 | }
|
15270 | };
|
15271 |
|
15272 | DrawAltitudeSymbolizer.prototype.getPlacement = function getPlacement() {
|
15273 | return 'point';
|
15274 | };
|
15275 |
|
15276 | DrawAltitudeSymbolizer.prototype._getPaintParams = function _getPaintParams(dx, dy) {
|
15277 | return this.getPainter().getPaintParams(dx || 0, dy || 0);
|
15278 | };
|
15279 |
|
15280 | DrawAltitudeSymbolizer.prototype._drawMarkerAltitude = function _drawMarkerAltitude(ctx, point, groundPoint) {
|
15281 | var style = this._getStyle();
|
15282 | this.prepareCanvas(ctx, style);
|
15283 | Canvas.path(ctx, [point, groundPoint], style['lineOpacity'], null, style['lineDasharray']);
|
15284 | };
|
15285 |
|
15286 | DrawAltitudeSymbolizer.prototype._drawLineAltitude = function _drawLineAltitude(ctx, points, groundPoints) {
|
15287 | var style = this._getStyle();
|
15288 | var isSplitted = points.length > 0 && Array.isArray(points[0]);
|
15289 |
|
15290 | if (isSplitted) {
|
15291 | for (var i = 0; i < points.length; i++) {
|
15292 | this._drawLine(ctx, points[i], groundPoints[i]);
|
15293 | }
|
15294 | } else {
|
15295 | this._drawLine(ctx, points, groundPoints);
|
15296 | }
|
15297 |
|
15298 | if (ctx.setLineDash && Array.isArray(style['lineDasharray'])) {
|
15299 | ctx.setLineDash([]);
|
15300 | }
|
15301 | };
|
15302 |
|
15303 | DrawAltitudeSymbolizer.prototype._drawLine = function _drawLine(ctx, points, groundPoints) {
|
15304 | var style = this._getStyle();
|
15305 | this.prepareCanvas(ctx, style);
|
15306 | for (var i = 0, l = points.length - 1; i < l; i++) {
|
15307 | Canvas.polygon(ctx, [points[i], points[i + 1], groundPoints[i + 1], groundPoints[i]], style['lineOpacity'], style['polygonOpacity'], style['lineDasharray']);
|
15308 | }
|
15309 | };
|
15310 |
|
15311 | DrawAltitudeSymbolizer.prototype._getStyle = function _getStyle() {
|
15312 | var style = this.geometry.getLayer().options['drawAltitude'];
|
15313 | if (!isObject(style)) {
|
15314 | style = defaultSymbol;
|
15315 | }
|
15316 | if (!style['lineWidth']) {
|
15317 | style['lineWidth'] = 0;
|
15318 | style['lineOpacity'] = 0;
|
15319 | }
|
15320 | return style;
|
15321 | };
|
15322 |
|
15323 | return DrawAltitudeSymbolizer;
|
15324 | }(PointSymbolizer);
|
15325 |
|
15326 |
|
15327 |
|
15328 | var index$3 = Object.freeze({
|
15329 | Symbolizer: Symbolizer,
|
15330 | CanvasSymbolizer: CanvasSymbolizer,
|
15331 | DebugSymbolizer: DebugSymbolizer,
|
15332 | ImageMarkerSymbolizer: ImageMarkerSymbolizer,
|
15333 | PointSymbolizer: PointSymbolizer,
|
15334 | StrokeAndFillSymbolizer: StrokeAndFillSymbolizer,
|
15335 | TextMarkerSymbolizer: TextMarkerSymbolizer,
|
15336 | VectorMarkerSymbolizer: VectorMarkerSymbolizer,
|
15337 | VectorPathMarkerSymbolizer: VectorPathMarkerSymbolizer,
|
15338 | DrawAltitudeSymbolizer: DrawAltitudeSymbolizer
|
15339 | });
|
15340 |
|
15341 | var registerSymbolizers = [DrawAltitudeSymbolizer, StrokeAndFillSymbolizer, ImageMarkerSymbolizer, VectorPathMarkerSymbolizer, VectorMarkerSymbolizer, TextMarkerSymbolizer];
|
15342 |
|
15343 | var testCanvas = void 0;
|
15344 |
|
15345 | var Painter = function (_Class) {
|
15346 | inherits(Painter, _Class);
|
15347 |
|
15348 | function Painter(geometry) {
|
15349 | classCallCheck(this, Painter);
|
15350 |
|
15351 | var _this = possibleConstructorReturn(this, _Class.call(this));
|
15352 |
|
15353 | _this.geometry = geometry;
|
15354 | _this.symbolizers = _this._createSymbolizers();
|
15355 | _this._altAtGLZoom = _this._getGeometryAltitude();
|
15356 | return _this;
|
15357 | }
|
15358 |
|
15359 | Painter.prototype.getMap = function getMap() {
|
15360 | return this.geometry.getMap();
|
15361 | };
|
15362 |
|
15363 | Painter.prototype.getLayer = function getLayer() {
|
15364 | return this.geometry.getLayer();
|
15365 | };
|
15366 |
|
15367 | Painter.prototype._createSymbolizers = function _createSymbolizers() {
|
15368 | var geoSymbol = this.getSymbol(),
|
15369 | symbolizers = [],
|
15370 | regSymbolizers = registerSymbolizers;
|
15371 | var symbols = geoSymbol;
|
15372 | if (!Array.isArray(geoSymbol)) {
|
15373 | symbols = [geoSymbol];
|
15374 | }
|
15375 | for (var ii = symbols.length - 1; ii >= 0; ii--) {
|
15376 | var symbol = symbols[ii];
|
15377 | for (var i = regSymbolizers.length - 1; i >= 0; i--) {
|
15378 | if (regSymbolizers[i].test(symbol, this.geometry)) {
|
15379 | var symbolizer = new regSymbolizers[i](symbol, this.geometry, this);
|
15380 | symbolizers.push(symbolizer);
|
15381 | if (symbolizer instanceof PointSymbolizer) {
|
15382 | this._hasPoint = true;
|
15383 | }
|
15384 | }
|
15385 | }
|
15386 | }
|
15387 | if (!symbolizers.length) {
|
15388 | if (console) {
|
15389 | var id = this.geometry.getId();
|
15390 | console.warn('invalid symbol for geometry(' + (this.geometry ? this.geometry.getType() + (id ? ':' + id : '') : '') + ') to draw : ' + JSON.stringify(geoSymbol));
|
15391 | }
|
15392 | }
|
15393 | this._debugSymbolizer = new DebugSymbolizer(geoSymbol, this.geometry, this);
|
15394 | return symbolizers;
|
15395 | };
|
15396 |
|
15397 | Painter.prototype.hasPoint = function hasPoint() {
|
15398 | return !!this._hasPoint;
|
15399 | };
|
15400 |
|
15401 | Painter.prototype.getRenderPoints = function getRenderPoints(placement) {
|
15402 | if (!this._renderPoints) {
|
15403 | this._renderPoints = {};
|
15404 | }
|
15405 | if (!placement) {
|
15406 | placement = 'center';
|
15407 | }
|
15408 | if (!this._renderPoints[placement]) {
|
15409 | this._renderPoints[placement] = this.geometry._getRenderPoints(placement);
|
15410 | }
|
15411 | return this._renderPoints[placement];
|
15412 | };
|
15413 |
|
15414 | Painter.prototype.getPaintParams = function getPaintParams(dx, dy, ignoreAltitude) {
|
15415 | var map = this.getMap(),
|
15416 | geometry = this.geometry,
|
15417 | res = map.getResolution(),
|
15418 | pitched = map.getPitch() !== 0,
|
15419 | rotated = map.getBearing() !== 0;
|
15420 | var params = this._cachedParams;
|
15421 |
|
15422 | var paintAsPath = geometry._paintAsPath && geometry._paintAsPath();
|
15423 | if (paintAsPath && this._unsimpledParams && res <= this._unsimpledParams._res) {
|
15424 | params = this._unsimpledParams;
|
15425 | } else if (!params || params._res !== map.getResolution() || this._pitched !== pitched && geometry._redrawWhenPitch() || this._rotated !== rotated && geometry._redrawWhenRotate()) {
|
15426 | params = geometry._getPaintParams();
|
15427 | if (!params) {
|
15428 | return null;
|
15429 | }
|
15430 | params._res = res;
|
15431 |
|
15432 | if (!geometry._simplified && paintAsPath) {
|
15433 | if (!this._unsimpledParams) {
|
15434 | this._unsimpledParams = params;
|
15435 | }
|
15436 | if (res > this._unsimpledParams._res) {
|
15437 | this._unsimpledParams._res = res;
|
15438 | }
|
15439 | }
|
15440 | this._cachedParams = params;
|
15441 | }
|
15442 | if (!params) {
|
15443 | return null;
|
15444 | }
|
15445 | this._pitched = pitched;
|
15446 | this._rotated = rotated;
|
15447 | var zoomScale = map.getGLScale(),
|
15448 | tr = [],
|
15449 | points = params[0];
|
15450 |
|
15451 | var mapExtent = map.getContainerExtent();
|
15452 | var cPoints = this._pointContainerPoints(points, dx, dy, ignoreAltitude, !mapExtent.contains(this._hitPoint));
|
15453 | if (!cPoints) {
|
15454 | return null;
|
15455 | }
|
15456 | tr.push(cPoints);
|
15457 | for (var i = 1, l = params.length; i < l; i++) {
|
15458 | if (isNumber(params[i]) || params[i] instanceof Size) {
|
15459 | if (isNumber(params[i])) {
|
15460 | tr.push(params[i] / zoomScale);
|
15461 | } else {
|
15462 | tr.push(params[i].multi(1 / zoomScale));
|
15463 | }
|
15464 | } else {
|
15465 | tr.push(params[i]);
|
15466 | }
|
15467 | }
|
15468 | return tr;
|
15469 | };
|
15470 |
|
15471 | Painter.prototype._pointContainerPoints = function _pointContainerPoints(points, dx, dy, ignoreAltitude, noClip, pointPlacement) {
|
15472 | var cExtent = this.getContainerExtent();
|
15473 | if (!cExtent) {
|
15474 | return null;
|
15475 | }
|
15476 | var map = this.getMap(),
|
15477 | glZoom = map.getGLZoom(),
|
15478 | containerOffset = this.containerOffset;
|
15479 | var cPoints = void 0;
|
15480 | function pointContainerPoint(point, alt) {
|
15481 | var p = map._pointToContainerPoint(point, glZoom, alt)._sub(containerOffset);
|
15482 | if (dx || dy) {
|
15483 | p._add(dx || 0, dy || 0);
|
15484 | }
|
15485 | return p;
|
15486 | }
|
15487 |
|
15488 | var altitude = this.getAltitude();
|
15489 |
|
15490 | if (Array.isArray(points)) {
|
15491 | var geometry = this.geometry;
|
15492 | var clipped = void 0;
|
15493 | if (!noClip && geometry.options['enableClip']) {
|
15494 | clipped = this._clip(points, altitude);
|
15495 | } else {
|
15496 | clipped = {
|
15497 | points: points,
|
15498 | altitude: altitude
|
15499 | };
|
15500 | }
|
15501 | var clipPoints = clipped.points;
|
15502 | altitude = clipped.altitude;
|
15503 | if (ignoreAltitude) {
|
15504 | altitude = 0;
|
15505 | }
|
15506 | var alt = altitude;
|
15507 | cPoints = [];
|
15508 | for (var i = 0, l = clipPoints.length; i < l; i++) {
|
15509 | var c = clipPoints[i];
|
15510 | if (Array.isArray(c)) {
|
15511 | var cring = [];
|
15512 |
|
15513 | for (var ii = 0, ll = c.length; ii < ll; ii++) {
|
15514 | var cc = c[ii];
|
15515 | if (Array.isArray(altitude)) {
|
15516 | if (altitude[i]) {
|
15517 | alt = altitude[i][ii];
|
15518 | } else {
|
15519 | alt = 0;
|
15520 | }
|
15521 | }
|
15522 | cring.push(pointContainerPoint(cc, alt));
|
15523 | }
|
15524 | cPoints.push(cring);
|
15525 | } else {
|
15526 | if (Array.isArray(altitude)) {
|
15527 | if (pointPlacement === 'vertex-last') {
|
15528 | alt = altitude[altitude.length - 1 - i];
|
15529 | } else if (pointPlacement === 'line') {
|
15530 | alt = (altitude[i] + altitude[i + 1]) / 2;
|
15531 | } else {
|
15532 | alt = altitude[i];
|
15533 | }
|
15534 | }
|
15535 | cPoints.push(pointContainerPoint(c, alt));
|
15536 | }
|
15537 | }
|
15538 | } else if (points instanceof Point) {
|
15539 | if (ignoreAltitude) {
|
15540 | altitude = 0;
|
15541 | }
|
15542 | cPoints = map._pointToContainerPoint(points, glZoom, altitude)._sub(containerOffset);
|
15543 | if (dx || dy) {
|
15544 | cPoints._add(dx, dy);
|
15545 | }
|
15546 | }
|
15547 | return cPoints;
|
15548 | };
|
15549 |
|
15550 | Painter.prototype._clip = function _clip(points, altitude) {
|
15551 | var map = this.getMap(),
|
15552 | geometry = this.geometry,
|
15553 | glZoom = map.getGLZoom();
|
15554 | var lineWidth = this.getSymbol()['lineWidth'];
|
15555 | if (!isNumber(lineWidth)) {
|
15556 | lineWidth = 4;
|
15557 | }
|
15558 | var containerExtent = map.getContainerExtent();
|
15559 | var extent2D = containerExtent.expand(lineWidth).convertTo(function (p) {
|
15560 | return map._containerPointToPoint(p, glZoom);
|
15561 | });
|
15562 | if (map.getPitch() > 0 && altitude) {
|
15563 | var c = map.cameraLookAt;
|
15564 | var pos = map.cameraPosition;
|
15565 |
|
15566 | extent2D = extent2D.combine(new Point(pos)._add(sign(c[0] - pos[0]), sign(c[1] - pos[1])));
|
15567 | }
|
15568 | var e = this.get2DExtent();
|
15569 | var clipPoints = points;
|
15570 | if (e.within(extent2D)) {
|
15571 | return {
|
15572 | points: clipPoints,
|
15573 | altitude: altitude
|
15574 | };
|
15575 | }
|
15576 | var smoothness = geometry.options['smoothness'];
|
15577 |
|
15578 | if (geometry.getShell && this.geometry.getHoles && !smoothness) {
|
15579 | if (!Array.isArray(points[0])) {
|
15580 | clipPoints = clipPolygon(points, extent2D);
|
15581 | } else {
|
15582 | clipPoints = [];
|
15583 | for (var i = 0; i < points.length; i++) {
|
15584 | var part = clipPolygon(points[i], extent2D);
|
15585 | if (part.length) {
|
15586 | clipPoints.push(part);
|
15587 | }
|
15588 | }
|
15589 | }
|
15590 | } else if (geometry.getJSONType() === 'LineString') {
|
15591 | if (!Array.isArray(points[0])) {
|
15592 | clipPoints = clipLine(points, extent2D, false, !!smoothness);
|
15593 | } else {
|
15594 | clipPoints = [];
|
15595 | for (var _i = 0; _i < points.length; _i++) {
|
15596 | pushIn(clipPoints, clipLine(points[_i], extent2D, false, !!smoothness));
|
15597 | }
|
15598 | }
|
15599 |
|
15600 | return this._interpolateSegAlt(clipPoints, points, altitude);
|
15601 | }
|
15602 |
|
15603 | return {
|
15604 | points: clipPoints,
|
15605 | altitude: altitude
|
15606 | };
|
15607 | };
|
15608 |
|
15609 | Painter.prototype._interpolateSegAlt = function _interpolateSegAlt(clipSegs, orig, altitude) {
|
15610 | if (!Array.isArray(altitude)) {
|
15611 | var fn = function fn(cc) {
|
15612 | return cc.point;
|
15613 | };
|
15614 | return {
|
15615 | points: clipSegs.map(function (c) {
|
15616 | if (Array.isArray(c)) {
|
15617 | return c.map(fn);
|
15618 | }
|
15619 | return c.point;
|
15620 | }),
|
15621 | altitude: altitude
|
15622 | };
|
15623 | }
|
15624 | var segsWithAlt = interpolateAlt(clipSegs, orig, altitude);
|
15625 | altitude = [];
|
15626 | var points = segsWithAlt.map(function (p) {
|
15627 | if (Array.isArray(p)) {
|
15628 | var alt = [];
|
15629 | var cp = p.map(function (pp) {
|
15630 | alt.push(pp.altitude);
|
15631 | return pp.point;
|
15632 | });
|
15633 | altitude.push(alt);
|
15634 | return cp;
|
15635 | }
|
15636 | altitude.push(p.altitude);
|
15637 | return p.point;
|
15638 | });
|
15639 | return {
|
15640 | points: points,
|
15641 | altitude: altitude
|
15642 | };
|
15643 | };
|
15644 |
|
15645 | Painter.prototype.getSymbol = function getSymbol() {
|
15646 | return this.geometry._getInternalSymbol();
|
15647 | };
|
15648 |
|
15649 | Painter.prototype.paint = function paint(extent, context, offset) {
|
15650 | if (!this.symbolizers) {
|
15651 | return;
|
15652 | }
|
15653 | var renderer = this.getLayer()._getRenderer();
|
15654 | if (!renderer || !renderer.context) {
|
15655 | return;
|
15656 | }
|
15657 |
|
15658 | if (extent && !extent.intersects(this.get2DExtent(renderer.resources))) {
|
15659 | return;
|
15660 | }
|
15661 | var map = this.getMap();
|
15662 | var minAltitude = this.getMinAltitude();
|
15663 | var frustumAlt = map.getFrustumAltitude();
|
15664 | if (minAltitude && frustumAlt && frustumAlt < minAltitude) {
|
15665 | return;
|
15666 | }
|
15667 | this.containerOffset = offset || map._pointToContainerPoint(renderer.southWest)._add(0, -map.height);
|
15668 | this._beforePaint();
|
15669 | var ctx = context || renderer.context;
|
15670 | var contexts = [ctx, renderer.resources];
|
15671 | for (var i = this.symbolizers.length - 1; i >= 0; i--) {
|
15672 | this._prepareShadow(ctx, this.symbolizers[i].symbol);
|
15673 | this.symbolizers[i].symbolize.apply(this.symbolizers[i], contexts);
|
15674 | }
|
15675 | this._afterPaint();
|
15676 | this._painted = true;
|
15677 | this._debugSymbolizer.symbolize.apply(this._debugSymbolizer, contexts);
|
15678 | };
|
15679 |
|
15680 | Painter.prototype.getSprite = function getSprite(resources, canvasClass) {
|
15681 | if (this.geometry.type !== 'Point') {
|
15682 | return null;
|
15683 | }
|
15684 | this._spriting = true;
|
15685 | if (!this._sprite && this.symbolizers.length > 0) {
|
15686 | var extent = new PointExtent();
|
15687 | this.symbolizers.forEach(function (s) {
|
15688 | var markerExtent = s.getFixedExtent(resources);
|
15689 | extent._combine(markerExtent);
|
15690 | });
|
15691 | var origin = extent.getMin().multi(-1);
|
15692 | var clazz = canvasClass || (this.getMap() ? this.getMap().CanvasClass : null);
|
15693 | var canvas = Canvas.createCanvas(extent.getWidth(), extent.getHeight(), clazz);
|
15694 | var bak = void 0;
|
15695 | if (this._renderPoints) {
|
15696 | bak = this._renderPoints;
|
15697 | }
|
15698 | var ctx = canvas.getContext('2d');
|
15699 | var contexts = [ctx, resources];
|
15700 | for (var i = this.symbolizers.length - 1; i >= 0; i--) {
|
15701 | var dxdy = this.symbolizers[i].getDxDy();
|
15702 | this._renderPoints = {
|
15703 | 'center': [[origin.add(dxdy)]]
|
15704 | };
|
15705 | this._prepareShadow(ctx, this.symbolizers[i].symbol);
|
15706 | this.symbolizers[i].symbolize.apply(this.symbolizers[i], contexts);
|
15707 | }
|
15708 | if (bak) {
|
15709 | this._renderPoints = bak;
|
15710 | }
|
15711 | this._sprite = {
|
15712 | 'canvas': canvas,
|
15713 | 'offset': extent.getCenter()
|
15714 | };
|
15715 | }
|
15716 | this._spriting = false;
|
15717 | return this._sprite;
|
15718 | };
|
15719 |
|
15720 | Painter.prototype.isSpriting = function isSpriting() {
|
15721 | return !!this._spriting;
|
15722 | };
|
15723 |
|
15724 | Painter.prototype.hitTest = function hitTest(cp, tolerance) {
|
15725 | if (!tolerance || tolerance < 0.5) {
|
15726 | tolerance = 0.5;
|
15727 | }
|
15728 | if (!testCanvas) {
|
15729 | testCanvas = Canvas.createCanvas(1, 1);
|
15730 | }
|
15731 | Canvas.setHitTesting(true);
|
15732 | testCanvas.width = testCanvas.height = 2 * tolerance;
|
15733 | var ctx = testCanvas.getContext('2d');
|
15734 | this._hitPoint = cp.sub(tolerance, tolerance);
|
15735 | try {
|
15736 | this.paint(null, ctx, this._hitPoint);
|
15737 | } catch (e) {
|
15738 | throw e;
|
15739 | } finally {
|
15740 | Canvas.setHitTesting(false);
|
15741 | }
|
15742 | delete this._hitPoint;
|
15743 | var imgData = ctx.getImageData(0, 0, testCanvas.width, testCanvas.height).data;
|
15744 | for (var i = 3, l = imgData.length; i < l; i += 4) {
|
15745 | if (imgData[i] > 0) {
|
15746 | return true;
|
15747 | }
|
15748 | }
|
15749 | return false;
|
15750 | };
|
15751 |
|
15752 | Painter.prototype.isHitTesting = function isHitTesting() {
|
15753 | return !!this._hitPoint;
|
15754 | };
|
15755 |
|
15756 | Painter.prototype._prepareShadow = function _prepareShadow(ctx, symbol) {
|
15757 | if (symbol['shadowBlur']) {
|
15758 | ctx.shadowBlur = symbol['shadowBlur'];
|
15759 | ctx.shadowColor = symbol['shadowColor'] || '#000';
|
15760 | ctx.shadowOffsetX = symbol['shadowOffsetX'] || 0;
|
15761 | ctx.shadowOffsetY = symbol['shadowOffsetY'] || 0;
|
15762 | } else if (ctx.shadowBlur) {
|
15763 | ctx.shadowBlur = null;
|
15764 | ctx.shadowColor = null;
|
15765 | ctx.shadowOffsetX = null;
|
15766 | ctx.shadowOffsetY = null;
|
15767 | }
|
15768 | };
|
15769 |
|
15770 | Painter.prototype._eachSymbolizer = function _eachSymbolizer(fn, context) {
|
15771 | if (!this.symbolizers) {
|
15772 | return;
|
15773 | }
|
15774 | if (!context) {
|
15775 | context = this;
|
15776 | }
|
15777 | for (var i = this.symbolizers.length - 1; i >= 0; i--) {
|
15778 | fn.apply(context, [this.symbolizers[i]]);
|
15779 | }
|
15780 | };
|
15781 |
|
15782 | Painter.prototype.get2DExtent = function get2DExtent(resources) {
|
15783 | this._verifyProjection();
|
15784 | var map = this.getMap();
|
15785 | resources = resources || this.getLayer()._getRenderer().resources;
|
15786 | var zoom = map.getZoom();
|
15787 | if (!this._extent2D || this._extent2D._zoom !== zoom) {
|
15788 | delete this._extent2D;
|
15789 | delete this._fixedExtent;
|
15790 | if (this.symbolizers) {
|
15791 | var extent = this._extent2D = new PointExtent();
|
15792 | var fixedExt = this._fixedExtent = new PointExtent();
|
15793 | for (var i = this.symbolizers.length - 1; i >= 0; i--) {
|
15794 | var symbolizer = this.symbolizers[i];
|
15795 | extent._combine(symbolizer.get2DExtent());
|
15796 | if (symbolizer.getFixedExtent) {
|
15797 | fixedExt._combine(symbolizer.getFixedExtent(resources));
|
15798 | }
|
15799 | }
|
15800 | extent._zoom = zoom;
|
15801 | }
|
15802 | }
|
15803 | return this._extent2D.add(this._fixedExtent);
|
15804 | };
|
15805 |
|
15806 | Painter.prototype.getContainerExtent = function getContainerExtent() {
|
15807 | this._verifyProjection();
|
15808 | var map = this.getMap();
|
15809 | var zoom = map.getZoom();
|
15810 | var glScale = map.getGLScale();
|
15811 | if (!this._extent2D || this._extent2D._zoom !== zoom) {
|
15812 | this.get2DExtent();
|
15813 | }
|
15814 | var altitude = this.getMinAltitude();
|
15815 | var frustumAlt = map.getFrustumAltitude();
|
15816 | if (altitude && frustumAlt && frustumAlt < altitude) {
|
15817 | return null;
|
15818 | }
|
15819 | var extent = this._extent2D.convertTo(function (c) {
|
15820 | return map._pointToContainerPoint(c, zoom, altitude / glScale);
|
15821 | });
|
15822 | var maxAltitude = this.getMaxAltitude();
|
15823 | if (maxAltitude !== altitude) {
|
15824 | var extent2 = this._extent2D.convertTo(function (c) {
|
15825 | return map._pointToContainerPoint(c, zoom, maxAltitude / glScale);
|
15826 | });
|
15827 | extent._combine(extent2);
|
15828 | }
|
15829 | if (extent) {
|
15830 | extent._add(this._fixedExtent);
|
15831 | }
|
15832 | var smoothness = this.geometry.options['smoothness'];
|
15833 | if (smoothness) {
|
15834 | extent._expand(extent.getWidth() * 0.15);
|
15835 | }
|
15836 | return extent;
|
15837 | };
|
15838 |
|
15839 | Painter.prototype.getFixedExtent = function getFixedExtent() {
|
15840 | var map = this.getMap();
|
15841 | var zoom = map.getZoom();
|
15842 | if (!this._extent2D || this._extent2D._zoom !== zoom) {
|
15843 | this.get2DExtent();
|
15844 | }
|
15845 | return this._fixedExtent;
|
15846 | };
|
15847 |
|
15848 | Painter.prototype.setZIndex = function setZIndex(change) {
|
15849 | this._eachSymbolizer(function (symbolizer) {
|
15850 | symbolizer.setZIndex(change);
|
15851 | });
|
15852 | };
|
15853 |
|
15854 | Painter.prototype.show = function show() {
|
15855 | if (!this._painted) {
|
15856 | var layer = this.getLayer();
|
15857 | if (!layer.isCanvasRender()) {
|
15858 | this.paint();
|
15859 | }
|
15860 | } else {
|
15861 | this.removeCache();
|
15862 | this._eachSymbolizer(function (symbolizer) {
|
15863 | symbolizer.show();
|
15864 | });
|
15865 | }
|
15866 | };
|
15867 |
|
15868 | Painter.prototype.hide = function hide() {
|
15869 | this._eachSymbolizer(function (symbolizer) {
|
15870 | symbolizer.hide();
|
15871 | });
|
15872 | };
|
15873 |
|
15874 | Painter.prototype.repaint = function repaint() {
|
15875 | this._altAtGLZoom = this._getGeometryAltitude();
|
15876 | this.removeCache();
|
15877 | var layer = this.getLayer();
|
15878 | if (!layer) {
|
15879 | return;
|
15880 | }
|
15881 | var renderer = layer.getRenderer();
|
15882 | if (!renderer || !renderer.setToRedraw()) {
|
15883 | return;
|
15884 | }
|
15885 | renderer.setToRedraw();
|
15886 | };
|
15887 |
|
15888 | Painter.prototype.refreshSymbol = function refreshSymbol() {
|
15889 | this.removeCache();
|
15890 | this._removeSymbolizers();
|
15891 | this.symbolizers = this._createSymbolizers();
|
15892 | };
|
15893 |
|
15894 | Painter.prototype.remove = function remove() {
|
15895 | this.removeCache();
|
15896 | this._removeSymbolizers();
|
15897 | };
|
15898 |
|
15899 | Painter.prototype._removeSymbolizers = function _removeSymbolizers() {
|
15900 | this._eachSymbolizer(function (symbolizer) {
|
15901 | delete symbolizer.painter;
|
15902 | symbolizer.remove();
|
15903 | });
|
15904 | delete this.symbolizers;
|
15905 | };
|
15906 |
|
15907 | Painter.prototype.removeCache = function removeCache() {
|
15908 | delete this._renderPoints;
|
15909 | delete this._paintParams;
|
15910 | delete this._sprite;
|
15911 | delete this._extent2D;
|
15912 | delete this._fixedExtent;
|
15913 | delete this._cachedParams;
|
15914 | delete this._unsimpledParams;
|
15915 | if (this.geometry) {
|
15916 | delete this.geometry[TextMarkerSymbolizer.CACHE_KEY];
|
15917 | }
|
15918 | };
|
15919 |
|
15920 | Painter.prototype.getAltitude = function getAltitude() {
|
15921 | var propAlt = this._getAltitudeProperty();
|
15922 | if (propAlt !== this._propAlt) {
|
15923 | this._altAtGLZoom = this._getGeometryAltitude();
|
15924 | }
|
15925 | if (!this._altAtGLZoom) {
|
15926 | return 0;
|
15927 | }
|
15928 | return this._altAtGLZoom;
|
15929 | };
|
15930 |
|
15931 | Painter.prototype.getMinAltitude = function getMinAltitude() {
|
15932 | if (!this.minAltitude) {
|
15933 | return 0;
|
15934 | }
|
15935 | return this.minAltitude;
|
15936 | };
|
15937 |
|
15938 | Painter.prototype.getMaxAltitude = function getMaxAltitude() {
|
15939 | if (!this.maxAltitude) {
|
15940 | return 0;
|
15941 | }
|
15942 | return this.maxAltitude;
|
15943 | };
|
15944 |
|
15945 | Painter.prototype._getGeometryAltitude = function _getGeometryAltitude() {
|
15946 | var _this2 = this;
|
15947 |
|
15948 | var map = this.getMap();
|
15949 | if (!map) {
|
15950 | return 0;
|
15951 | }
|
15952 | var altitude = this._getAltitudeProperty();
|
15953 | this._propAlt = altitude;
|
15954 | if (!altitude) {
|
15955 | this.minAltitude = this.maxAltitude = 0;
|
15956 | return 0;
|
15957 | }
|
15958 | var center = this.geometry.getCenter();
|
15959 | if (Array.isArray(altitude)) {
|
15960 | this.minAltitude = Number.MAX_VALUE;
|
15961 | this.maxAltitude = Number.MIN_VALUE;
|
15962 | return altitude.map(function (alt) {
|
15963 | var a = _this2._meterToPoint(center, alt);
|
15964 | if (a < _this2.minAltitude) {
|
15965 | _this2.minAltitude = a;
|
15966 | }
|
15967 | if (a > _this2.maxAltitude) {
|
15968 | _this2.maxAltitude = a;
|
15969 | }
|
15970 | return a;
|
15971 | });
|
15972 | } else {
|
15973 | this.minAltitude = this.maxAltitude = this._meterToPoint(center, altitude);
|
15974 | return this.minAltitude;
|
15975 | }
|
15976 | };
|
15977 |
|
15978 | Painter.prototype._meterToPoint = function _meterToPoint(center, altitude) {
|
15979 | var map = this.getMap();
|
15980 | var z = map.getGLZoom();
|
15981 | var target = map.locate(center, altitude, 0);
|
15982 | var p0 = map.coordToPoint(center, z),
|
15983 | p1 = map.coordToPoint(target, z);
|
15984 | return Math.abs(p1.x - p0.x) * sign(altitude);
|
15985 | };
|
15986 |
|
15987 | Painter.prototype._getAltitudeProperty = function _getAltitudeProperty() {
|
15988 | var geometry = this.geometry,
|
15989 | layerOpts = geometry.getLayer().options,
|
15990 | properties = geometry.getProperties();
|
15991 | var altitude = layerOpts['enableAltitude'] ? properties ? properties[layerOpts['altitudeProperty']] : 0 : 0;
|
15992 | return altitude;
|
15993 | };
|
15994 |
|
15995 | Painter.prototype._verifyProjection = function _verifyProjection() {
|
15996 | var projection = this.geometry._getProjection();
|
15997 | if (this._projCode && this._projCode !== projection.code) {
|
15998 | this.removeCache();
|
15999 | }
|
16000 | this._projCode = projection.code;
|
16001 | };
|
16002 |
|
16003 | Painter.prototype._beforePaint = function _beforePaint() {
|
16004 | var textcache = this.geometry[TextMarkerSymbolizer.CACHE_KEY];
|
16005 | if (!textcache) {
|
16006 | return;
|
16007 | }
|
16008 | for (var p in textcache) {
|
16009 | if (hasOwn(textcache, p)) {
|
16010 | textcache[p].active = false;
|
16011 | }
|
16012 | }
|
16013 | };
|
16014 |
|
16015 | Painter.prototype._afterPaint = function _afterPaint() {
|
16016 | var textcache = this.geometry[TextMarkerSymbolizer.CACHE_KEY];
|
16017 | if (!textcache) {
|
16018 | return;
|
16019 | }
|
16020 | for (var p in textcache) {
|
16021 | if (hasOwn(textcache, p)) {
|
16022 | if (!textcache[p].active) {
|
16023 | delete textcache[p];
|
16024 | }
|
16025 | }
|
16026 | }
|
16027 | };
|
16028 |
|
16029 | return Painter;
|
16030 | }(Class);
|
16031 |
|
16032 | function interpolateAlt(points, orig, altitude) {
|
16033 | if (!Array.isArray(altitude)) {
|
16034 | return points;
|
16035 | }
|
16036 | var parts = [];
|
16037 | for (var i = 0, l = points.length; i < l; i++) {
|
16038 | if (Array.isArray(points[i])) {
|
16039 | parts.push(interpolateAlt(points[i], orig, altitude));
|
16040 | } else {
|
16041 | var p = points[i];
|
16042 | if (!p.point.equals(orig[p.index])) {
|
16043 | var w0 = void 0,
|
16044 | w1 = void 0;
|
16045 | if (p.index === 0) {
|
16046 | w0 = p.index;
|
16047 | w1 = p.index + 1;
|
16048 | } else {
|
16049 | w0 = p.index - 1;
|
16050 | w1 = p.index;
|
16051 | }
|
16052 |
|
16053 | var t0 = p.point.distanceTo(orig[w1]);
|
16054 | var t = t0 / (t0 + orig[w0].distanceTo(p.point));
|
16055 | var alt = interpolate(altitude[w0], altitude[w1], 1 - t);
|
16056 | p.altitude = alt;
|
16057 | parts.push(p);
|
16058 | } else {
|
16059 | p.altitude = altitude[p.index];
|
16060 | parts.push(p);
|
16061 | }
|
16062 | }
|
16063 | }
|
16064 | return parts;
|
16065 | }
|
16066 |
|
16067 | var CollectionPainter = function (_Class) {
|
16068 | inherits(CollectionPainter, _Class);
|
16069 |
|
16070 | function CollectionPainter(geometry) {
|
16071 | classCallCheck(this, CollectionPainter);
|
16072 |
|
16073 | var _this = possibleConstructorReturn(this, _Class.call(this));
|
16074 |
|
16075 | _this.geometry = geometry;
|
16076 | return _this;
|
16077 | }
|
16078 |
|
16079 | CollectionPainter.prototype._eachPainter = function _eachPainter(fn) {
|
16080 | var geometries = this.geometry.getGeometries();
|
16081 | var painter = void 0;
|
16082 | for (var i = 0, len = geometries.length; i < len; i++) {
|
16083 | painter = geometries[i]._getPainter();
|
16084 | if (!painter) {
|
16085 | continue;
|
16086 | }
|
16087 | if (painter) {
|
16088 | if (fn.call(this, painter) === false) {
|
16089 | break;
|
16090 | }
|
16091 | }
|
16092 | }
|
16093 | };
|
16094 |
|
16095 | CollectionPainter.prototype.paint = function paint(extent) {
|
16096 | if (!this.geometry) {
|
16097 | return;
|
16098 | }
|
16099 | this._eachPainter(function (painter) {
|
16100 | painter.paint(extent);
|
16101 | });
|
16102 | };
|
16103 |
|
16104 | CollectionPainter.prototype.get2DExtent = function get2DExtent(resources) {
|
16105 | var extent = new PointExtent();
|
16106 | this._eachPainter(function (painter) {
|
16107 | extent = extent.combine(painter.get2DExtent(resources));
|
16108 | });
|
16109 | return extent;
|
16110 | };
|
16111 |
|
16112 | CollectionPainter.prototype.getContainerExtent = function getContainerExtent() {
|
16113 | var extent = new PointExtent();
|
16114 | this._eachPainter(function (painter) {
|
16115 | extent = extent.combine(painter.getContainerExtent());
|
16116 | });
|
16117 | return extent;
|
16118 | };
|
16119 |
|
16120 | CollectionPainter.prototype.remove = function remove() {
|
16121 | var args = arguments;
|
16122 | this._eachPainter(function (painter) {
|
16123 | painter.remove.apply(painter, args);
|
16124 | });
|
16125 | };
|
16126 |
|
16127 | CollectionPainter.prototype.setZIndex = function setZIndex() {
|
16128 | var args = arguments;
|
16129 | this._eachPainter(function (painter) {
|
16130 | painter.setZIndex.apply(painter, args);
|
16131 | });
|
16132 | };
|
16133 |
|
16134 | CollectionPainter.prototype.show = function show() {
|
16135 | var args = arguments;
|
16136 | this._eachPainter(function (painter) {
|
16137 | painter.show.apply(painter, args);
|
16138 | });
|
16139 | };
|
16140 |
|
16141 | CollectionPainter.prototype.hide = function hide() {
|
16142 | var args = arguments;
|
16143 | this._eachPainter(function (painter) {
|
16144 | painter.hide.apply(painter, args);
|
16145 | });
|
16146 | };
|
16147 |
|
16148 | CollectionPainter.prototype.repaint = function repaint() {
|
16149 | var args = arguments;
|
16150 | this._eachPainter(function (painter) {
|
16151 | painter.repaint.apply(painter, args);
|
16152 | });
|
16153 | };
|
16154 |
|
16155 | CollectionPainter.prototype.refreshSymbol = function refreshSymbol() {
|
16156 | var args = arguments;
|
16157 | this._eachPainter(function (painter) {
|
16158 | painter.refreshSymbol.apply(painter, args);
|
16159 | });
|
16160 | };
|
16161 |
|
16162 | CollectionPainter.prototype.hasPoint = function hasPoint() {
|
16163 | var result = false;
|
16164 | this._eachPainter(function (painter) {
|
16165 | if (painter.hasPoint()) {
|
16166 | result = true;
|
16167 | return false;
|
16168 | }
|
16169 | return true;
|
16170 | });
|
16171 | return result;
|
16172 | };
|
16173 |
|
16174 | CollectionPainter.prototype.getMinAltitude = function getMinAltitude() {
|
16175 | var first = true;
|
16176 | var result = 0;
|
16177 | this._eachPainter(function (painter) {
|
16178 | var alt = painter.getMinAltitude();
|
16179 | if (first || alt < result) {
|
16180 | first = false;
|
16181 | result = alt;
|
16182 | }
|
16183 | });
|
16184 | return result;
|
16185 | };
|
16186 |
|
16187 | CollectionPainter.prototype.getMaxAltitude = function getMaxAltitude() {
|
16188 | var result = 0;
|
16189 | this._eachPainter(function (painter) {
|
16190 | var alt = painter.getMaxAltitude();
|
16191 | if (alt > result) {
|
16192 | result = alt;
|
16193 | }
|
16194 | });
|
16195 | return result;
|
16196 | };
|
16197 |
|
16198 | return CollectionPainter;
|
16199 | }(Class);
|
16200 |
|
16201 | var options$2 = {
|
16202 | 'id': null,
|
16203 | 'visible': true,
|
16204 | 'editable': true,
|
16205 | 'cursor': null,
|
16206 | 'defaultProjection': 'EPSG:4326' };
|
16207 |
|
16208 | var Geometry = function (_JSONAble) {
|
16209 | inherits(Geometry, _JSONAble);
|
16210 |
|
16211 | function Geometry(options) {
|
16212 | classCallCheck(this, Geometry);
|
16213 |
|
16214 | var opts = extend({}, options);
|
16215 | var symbol = opts['symbol'];
|
16216 | var properties = opts['properties'];
|
16217 | var id = opts['id'];
|
16218 | delete opts['symbol'];
|
16219 | delete opts['id'];
|
16220 | delete opts['properties'];
|
16221 |
|
16222 | var _this = possibleConstructorReturn(this, _JSONAble.call(this, opts));
|
16223 |
|
16224 | if (symbol) {
|
16225 | _this.setSymbol(symbol);
|
16226 | }
|
16227 | if (properties) {
|
16228 | _this.setProperties(properties);
|
16229 | }
|
16230 | if (!isNil(id)) {
|
16231 | _this.setId(id);
|
16232 | }
|
16233 | return _this;
|
16234 | }
|
16235 |
|
16236 | Geometry.prototype.getFirstCoordinate = function getFirstCoordinate() {
|
16237 | if (this.type === 'GeometryCollection') {
|
16238 | var geometries = this.getGeometries();
|
16239 | if (!geometries.length) {
|
16240 | return null;
|
16241 | }
|
16242 | return geometries[0].getFirstCoordinate();
|
16243 | }
|
16244 | var coordinates = this.getCoordinates();
|
16245 | if (!Array.isArray(coordinates)) {
|
16246 | return coordinates;
|
16247 | }
|
16248 | do {
|
16249 | coordinates = coordinates[0];
|
16250 | } while (Array.isArray(coordinates) && coordinates.length > 0);
|
16251 | return coordinates;
|
16252 | };
|
16253 |
|
16254 | Geometry.prototype.getLastCoordinate = function getLastCoordinate() {
|
16255 | if (this.type === 'GeometryCollection') {
|
16256 | var geometries = this.getGeometries();
|
16257 | if (!geometries.length) {
|
16258 | return null;
|
16259 | }
|
16260 | return geometries[geometries.length - 1].getLastCoordinate();
|
16261 | }
|
16262 | var coordinates = this.getCoordinates();
|
16263 | if (!Array.isArray(coordinates)) {
|
16264 | return coordinates;
|
16265 | }
|
16266 | do {
|
16267 | coordinates = coordinates[coordinates.length - 1];
|
16268 | } while (Array.isArray(coordinates) && coordinates.length > 0);
|
16269 | return coordinates;
|
16270 | };
|
16271 |
|
16272 | Geometry.prototype.addTo = function addTo(layer, fitview) {
|
16273 | layer.addGeometry(this, fitview);
|
16274 | return this;
|
16275 | };
|
16276 |
|
16277 | Geometry.prototype.getLayer = function getLayer() {
|
16278 | if (!this._layer) {
|
16279 | return null;
|
16280 | }
|
16281 | return this._layer;
|
16282 | };
|
16283 |
|
16284 | Geometry.prototype.getMap = function getMap() {
|
16285 | if (!this._layer) {
|
16286 | return null;
|
16287 | }
|
16288 | return this._layer.getMap();
|
16289 | };
|
16290 |
|
16291 | Geometry.prototype.getId = function getId() {
|
16292 | return this._id;
|
16293 | };
|
16294 |
|
16295 | Geometry.prototype.setId = function setId(id) {
|
16296 | var oldId = this.getId();
|
16297 | this._id = id;
|
16298 |
|
16299 | this._fireEvent('idchange', {
|
16300 | 'old': oldId,
|
16301 | 'new': id
|
16302 | });
|
16303 |
|
16304 | return this;
|
16305 | };
|
16306 |
|
16307 | Geometry.prototype.getProperties = function getProperties() {
|
16308 | if (!this.properties) {
|
16309 | if (this._getParent()) {
|
16310 | return this._getParent().getProperties();
|
16311 | }
|
16312 | return null;
|
16313 | }
|
16314 | return this.properties;
|
16315 | };
|
16316 |
|
16317 | Geometry.prototype.setProperties = function setProperties(properties) {
|
16318 | var old = this.properties;
|
16319 | this.properties = isObject(properties) ? extend({}, properties) : properties;
|
16320 | this._repaint();
|
16321 |
|
16322 | this._fireEvent('propertieschange', {
|
16323 | 'old': old,
|
16324 | 'new': properties
|
16325 | });
|
16326 |
|
16327 | return this;
|
16328 | };
|
16329 |
|
16330 | Geometry.prototype.getType = function getType() {
|
16331 | return this.type;
|
16332 | };
|
16333 |
|
16334 | Geometry.prototype.getSymbol = function getSymbol() {
|
16335 | var s = this._symbol;
|
16336 | if (s) {
|
16337 | if (!Array.isArray(s)) {
|
16338 | return extend({}, s);
|
16339 | } else {
|
16340 | return extendSymbol(s);
|
16341 | }
|
16342 | }
|
16343 | return null;
|
16344 | };
|
16345 |
|
16346 | Geometry.prototype.setSymbol = function setSymbol(symbol) {
|
16347 | this._symbol = this._prepareSymbol(symbol);
|
16348 | this.onSymbolChanged();
|
16349 | return this;
|
16350 | };
|
16351 |
|
16352 | Geometry.prototype.updateSymbol = function updateSymbol(props) {
|
16353 | if (!props) {
|
16354 | return this;
|
16355 | }
|
16356 | var s = this._getSymbol();
|
16357 | if (s) {
|
16358 | s = extendSymbol(s, props);
|
16359 | } else {
|
16360 | s = extendSymbol(this._getInternalSymbol(), props);
|
16361 | }
|
16362 | return this.setSymbol(s);
|
16363 | };
|
16364 |
|
16365 | Geometry.prototype.getCenter = function getCenter() {
|
16366 | return this._computeCenter(this._getMeasurer());
|
16367 | };
|
16368 |
|
16369 | Geometry.prototype.getExtent = function getExtent() {
|
16370 | var prjExt = this._getPrjExtent();
|
16371 | if (prjExt) {
|
16372 | var p = this._getProjection();
|
16373 | var min = p.unproject(new Coordinate(prjExt['xmin'], prjExt['ymin'])),
|
16374 | max = p.unproject(new Coordinate(prjExt['xmax'], prjExt['ymax']));
|
16375 | return new Extent(min, max, this._getProjection());
|
16376 | } else {
|
16377 | return this._computeExtent(this._getMeasurer());
|
16378 | }
|
16379 | };
|
16380 |
|
16381 | Geometry.prototype.getContainerExtent = function getContainerExtent() {
|
16382 | var painter = this._getPainter();
|
16383 | return painter ? painter.getContainerExtent() : null;
|
16384 | };
|
16385 |
|
16386 | Geometry.prototype.getSize = function getSize() {
|
16387 | var extent = this.getContainerExtent();
|
16388 | return extent ? extent.getSize() : null;
|
16389 | };
|
16390 |
|
16391 | Geometry.prototype.containsPoint = function containsPoint(containerPoint, t) {
|
16392 | if (!this.getMap()) {
|
16393 | throw new Error('The geometry is required to be added on a map to perform "containsPoint".');
|
16394 | }
|
16395 | if (containerPoint instanceof Coordinate) {
|
16396 | containerPoint = this.getMap().coordToContainerPoint(containerPoint);
|
16397 | }
|
16398 | return this._containsPoint(containerPoint, t);
|
16399 | };
|
16400 |
|
16401 | Geometry.prototype._containsPoint = function _containsPoint(containerPoint, t) {
|
16402 | var painter = this._getPainter();
|
16403 | if (!painter) {
|
16404 | return false;
|
16405 | }
|
16406 | if (isNil(t) && this._hitTestTolerance) {
|
16407 | t = this._hitTestTolerance();
|
16408 | }
|
16409 | return painter.hitTest(containerPoint, t);
|
16410 | };
|
16411 |
|
16412 | Geometry.prototype.show = function show() {
|
16413 | this.options['visible'] = true;
|
16414 | if (this.getMap()) {
|
16415 | var painter = this._getPainter();
|
16416 | if (painter) {
|
16417 | painter.show();
|
16418 | }
|
16419 |
|
16420 | this._fireEvent('show');
|
16421 | }
|
16422 | return this;
|
16423 | };
|
16424 |
|
16425 | Geometry.prototype.hide = function hide() {
|
16426 | this.options['visible'] = false;
|
16427 | if (this.getMap()) {
|
16428 | this.onHide();
|
16429 | var painter = this._getPainter();
|
16430 | if (painter) {
|
16431 | painter.hide();
|
16432 | }
|
16433 |
|
16434 | this._fireEvent('hide');
|
16435 | }
|
16436 | return this;
|
16437 | };
|
16438 |
|
16439 | Geometry.prototype.isVisible = function isVisible() {
|
16440 | if (!this.options['visible']) {
|
16441 | return false;
|
16442 | }
|
16443 | var symbol = this._getInternalSymbol();
|
16444 | if (!symbol) {
|
16445 | return true;
|
16446 | }
|
16447 | if (Array.isArray(symbol)) {
|
16448 | if (!symbol.length) {
|
16449 | return true;
|
16450 | }
|
16451 | for (var i = 0, l = symbol.length; i < l; i++) {
|
16452 | if (isNil(symbol[i]['opacity']) || symbol[i]['opacity'] > 0) {
|
16453 | return true;
|
16454 | }
|
16455 | }
|
16456 | return false;
|
16457 | } else {
|
16458 | return isNil(symbol['opacity']) || isNumber(symbol['opacity']) && symbol['opacity'] > 0;
|
16459 | }
|
16460 | };
|
16461 |
|
16462 | Geometry.prototype.getZIndex = function getZIndex() {
|
16463 | return this.options['zIndex'] || 0;
|
16464 | };
|
16465 |
|
16466 | Geometry.prototype.setZIndex = function setZIndex(zIndex) {
|
16467 | var old = this.options['zIndex'];
|
16468 | this.options['zIndex'] = zIndex;
|
16469 |
|
16470 | this._fireEvent('zindexchange', {
|
16471 | 'old': old,
|
16472 | 'new': zIndex
|
16473 | });
|
16474 |
|
16475 | return this;
|
16476 | };
|
16477 |
|
16478 | Geometry.prototype.setZIndexSilently = function setZIndexSilently(zIndex) {
|
16479 | this.options['zIndex'] = zIndex;
|
16480 | return this;
|
16481 | };
|
16482 |
|
16483 | Geometry.prototype.bringToFront = function bringToFront() {
|
16484 | var layer = this.getLayer();
|
16485 | if (!layer || !layer.getGeoMaxZIndex) {
|
16486 | return this;
|
16487 | }
|
16488 | var topZ = layer.getGeoMaxZIndex();
|
16489 | this.setZIndex(topZ + 1);
|
16490 | return this;
|
16491 | };
|
16492 |
|
16493 | Geometry.prototype.bringToBack = function bringToBack() {
|
16494 | var layer = this.getLayer();
|
16495 | if (!layer || !layer.getGeoMinZIndex) {
|
16496 | return this;
|
16497 | }
|
16498 | var bottomZ = layer.getGeoMinZIndex();
|
16499 | this.setZIndex(bottomZ - 1);
|
16500 | return this;
|
16501 | };
|
16502 |
|
16503 | Geometry.prototype.translate = function translate(x, y) {
|
16504 | if (isNil(x)) {
|
16505 | return this;
|
16506 | }
|
16507 | var offset = new Coordinate(x, y);
|
16508 | if (offset.x === 0 && offset.y === 0) {
|
16509 | return this;
|
16510 | }
|
16511 | var coordinates = this.getCoordinates();
|
16512 | if (coordinates) {
|
16513 | if (Array.isArray(coordinates)) {
|
16514 | var translated = forEachCoord(coordinates, function (coord) {
|
16515 | return coord.add(offset);
|
16516 | });
|
16517 | this.setCoordinates(translated);
|
16518 | } else {
|
16519 | this.setCoordinates(coordinates.add(offset));
|
16520 | }
|
16521 | }
|
16522 | return this;
|
16523 | };
|
16524 |
|
16525 | Geometry.prototype.flash = function flash$$1(interval, count, cb, context) {
|
16526 | return flash.call(this, interval, count, cb, context);
|
16527 | };
|
16528 |
|
16529 | Geometry.prototype.copy = function copy() {
|
16530 | var json = this.toJSON();
|
16531 | var ret = Geometry.fromJSON(json);
|
16532 |
|
16533 | ret.options['visible'] = true;
|
16534 | return ret;
|
16535 | };
|
16536 |
|
16537 | Geometry.prototype.remove = function remove() {
|
16538 | var layer = this.getLayer();
|
16539 | if (!layer) {
|
16540 | return this;
|
16541 | }
|
16542 |
|
16543 | this._fireEvent('removestart');
|
16544 |
|
16545 | this._unbind();
|
16546 |
|
16547 | this._fireEvent('removeend');
|
16548 |
|
16549 | this._fireEvent('remove');
|
16550 | return this;
|
16551 | };
|
16552 |
|
16553 | Geometry.prototype.toGeoJSONGeometry = function toGeoJSONGeometry() {
|
16554 | var gJson = this._exportGeoJSONGeometry();
|
16555 | return gJson;
|
16556 | };
|
16557 |
|
16558 | Geometry.prototype.toGeoJSON = function toGeoJSON(opts) {
|
16559 | if (!opts) {
|
16560 | opts = {};
|
16561 | }
|
16562 | var feature = {
|
16563 | 'type': 'Feature',
|
16564 | 'geometry': null
|
16565 | };
|
16566 | if (isNil(opts['geometry']) || opts['geometry']) {
|
16567 | var geoJSON = this._exportGeoJSONGeometry();
|
16568 | feature['geometry'] = geoJSON;
|
16569 | }
|
16570 | var id = this.getId();
|
16571 | if (!isNil(id)) {
|
16572 | feature['id'] = id;
|
16573 | }
|
16574 | var properties = void 0;
|
16575 | if (isNil(opts['properties']) || opts['properties']) {
|
16576 | properties = this._exportProperties();
|
16577 | }
|
16578 | feature['properties'] = properties;
|
16579 | return feature;
|
16580 | };
|
16581 |
|
16582 | Geometry.prototype.toJSON = function toJSON(options) {
|
16583 | if (!options) {
|
16584 | options = {};
|
16585 | }
|
16586 | var json = this._toJSON(options);
|
16587 | var other = this._exportGraphicOptions(options);
|
16588 | extend(json, other);
|
16589 | return json;
|
16590 | };
|
16591 |
|
16592 | Geometry.prototype.getLength = function getLength() {
|
16593 | return this._computeGeodesicLength(this._getMeasurer());
|
16594 | };
|
16595 |
|
16596 | Geometry.prototype.getArea = function getArea() {
|
16597 | return this._computeGeodesicArea(this._getMeasurer());
|
16598 | };
|
16599 |
|
16600 | Geometry.prototype.rotate = function rotate(angle, pivot) {
|
16601 | if (this.type === 'GeometryCollection') {
|
16602 | var geometries = this.getGeometries();
|
16603 | geometries.forEach(function (g) {
|
16604 | return g.rotate(angle, pivot);
|
16605 | });
|
16606 | return this;
|
16607 | }
|
16608 | if (!pivot) {
|
16609 | pivot = this.getCenter();
|
16610 | } else {
|
16611 | pivot = new Coordinate(pivot);
|
16612 | }
|
16613 | var measurer = this._getMeasurer();
|
16614 | var coordinates = this.getCoordinates();
|
16615 | if (!Array.isArray(coordinates)) {
|
16616 | if (pivot.x !== coordinates.x || pivot.y !== coordinates.y) {
|
16617 | var c = measurer._rotate(coordinates, pivot, angle);
|
16618 | this.setCoordinates(c);
|
16619 | }
|
16620 | return this;
|
16621 | }
|
16622 | forEachCoord(coordinates, function (c) {
|
16623 | return measurer._rotate(c, pivot, angle);
|
16624 | });
|
16625 | this.setCoordinates(coordinates);
|
16626 | return this;
|
16627 | };
|
16628 |
|
16629 | Geometry.prototype._getConnectPoints = function _getConnectPoints() {
|
16630 | return [this.getCenter()];
|
16631 | };
|
16632 |
|
16633 | Geometry.prototype._initOptions = function _initOptions(options) {
|
16634 | var opts = extend({}, options);
|
16635 | var symbol = opts['symbol'];
|
16636 | var properties = opts['properties'];
|
16637 | var id = opts['id'];
|
16638 | delete opts['symbol'];
|
16639 | delete opts['id'];
|
16640 | delete opts['properties'];
|
16641 | this.setOptions(opts);
|
16642 | if (symbol) {
|
16643 | this.setSymbol(symbol);
|
16644 | }
|
16645 | if (properties) {
|
16646 | this.setProperties(properties);
|
16647 | }
|
16648 | if (!isNil(id)) {
|
16649 | this.setId(id);
|
16650 | }
|
16651 | };
|
16652 |
|
16653 | Geometry.prototype._bindLayer = function _bindLayer(layer) {
|
16654 | if (this.getLayer()) {
|
16655 | throw new Error('Geometry cannot be added to two or more layers at the same time.');
|
16656 | }
|
16657 | this._layer = layer;
|
16658 | this._clearCache();
|
16659 | this._clearProjection();
|
16660 | };
|
16661 |
|
16662 | Geometry.prototype._prepareSymbol = function _prepareSymbol(symbol) {
|
16663 | if (Array.isArray(symbol)) {
|
16664 | var cookedSymbols = [];
|
16665 | for (var i = 0; i < symbol.length; i++) {
|
16666 | cookedSymbols.push(convertResourceUrl(this._checkAndCopySymbol(symbol[i])));
|
16667 | }
|
16668 | return cookedSymbols;
|
16669 | } else if (symbol) {
|
16670 | symbol = this._checkAndCopySymbol(symbol);
|
16671 | return convertResourceUrl(symbol);
|
16672 | }
|
16673 | return null;
|
16674 | };
|
16675 |
|
16676 | Geometry.prototype._checkAndCopySymbol = function _checkAndCopySymbol(symbol) {
|
16677 | var s = {};
|
16678 | for (var i in symbol) {
|
16679 | if (NUMERICAL_PROPERTIES[i] && isString(symbol[i])) {
|
16680 | s[i] = +symbol[i];
|
16681 | } else {
|
16682 | s[i] = symbol[i];
|
16683 | }
|
16684 | }
|
16685 | return s;
|
16686 | };
|
16687 |
|
16688 | Geometry.prototype._getSymbol = function _getSymbol() {
|
16689 | return this._symbol;
|
16690 | };
|
16691 |
|
16692 | Geometry.prototype._setExternSymbol = function _setExternSymbol(symbol) {
|
16693 | this._externSymbol = this._prepareSymbol(symbol);
|
16694 | this.onSymbolChanged();
|
16695 | return this;
|
16696 | };
|
16697 |
|
16698 | Geometry.prototype._getInternalSymbol = function _getInternalSymbol() {
|
16699 | if (this._symbol) {
|
16700 | return this._symbol;
|
16701 | } else if (this._externSymbol) {
|
16702 | return this._externSymbol;
|
16703 | } else if (this.options['symbol']) {
|
16704 | return this.options['symbol'];
|
16705 | }
|
16706 | return null;
|
16707 | };
|
16708 |
|
16709 | Geometry.prototype._getPrjExtent = function _getPrjExtent() {
|
16710 | var p = this._getProjection();
|
16711 | this._verifyProjection();
|
16712 | if (!this._extent && p) {
|
16713 | this._extent = this._computePrjExtent(p);
|
16714 | }
|
16715 | return this._extent;
|
16716 | };
|
16717 |
|
16718 | Geometry.prototype._unbind = function _unbind() {
|
16719 | var layer = this.getLayer();
|
16720 | if (!layer) {
|
16721 | return;
|
16722 | }
|
16723 |
|
16724 | if (this._animPlayer) {
|
16725 | this._animPlayer.finish();
|
16726 | }
|
16727 | this._clearHandlers();
|
16728 |
|
16729 | this._unbindMenu();
|
16730 |
|
16731 | this._unbindInfoWindow();
|
16732 |
|
16733 | if (this.isEditing()) {
|
16734 | this.endEdit();
|
16735 | }
|
16736 | this._removePainter();
|
16737 | if (this.onRemove) {
|
16738 | this.onRemove();
|
16739 | }
|
16740 | if (layer.onRemoveGeometry) {
|
16741 | layer.onRemoveGeometry(this);
|
16742 | }
|
16743 | delete this._layer;
|
16744 | delete this._internalId;
|
16745 | delete this._extent;
|
16746 | };
|
16747 |
|
16748 | Geometry.prototype._getInternalId = function _getInternalId() {
|
16749 | return this._internalId;
|
16750 | };
|
16751 |
|
16752 | Geometry.prototype._setInternalId = function _setInternalId(id) {
|
16753 | this._internalId = id;
|
16754 | };
|
16755 |
|
16756 | Geometry.prototype._getMeasurer = function _getMeasurer() {
|
16757 | if (this._getProjection()) {
|
16758 | return this._getProjection();
|
16759 | }
|
16760 | return SpatialReference.getProjectionInstance(this.options['defaultProjection']);
|
16761 | };
|
16762 |
|
16763 | Geometry.prototype._getProjection = function _getProjection() {
|
16764 | var map = this.getMap();
|
16765 | if (map) {
|
16766 | return map.getProjection();
|
16767 | }
|
16768 | return null;
|
16769 | };
|
16770 |
|
16771 | Geometry.prototype._verifyProjection = function _verifyProjection() {
|
16772 | var projection = this._getProjection();
|
16773 | if (this._projCode && (!projection || this._projCode !== projection.code)) {
|
16774 | this._clearProjection();
|
16775 | }
|
16776 | this._projCode = projection ? projection.code : null;
|
16777 | };
|
16778 |
|
16779 | Geometry.prototype._getExternalResources = function _getExternalResources() {
|
16780 | var symbol = this._getInternalSymbol();
|
16781 | return getExternalResources(symbol);
|
16782 | };
|
16783 |
|
16784 | Geometry.prototype._getPainter = function _getPainter() {
|
16785 | if (!this._painter && this.getMap()) {
|
16786 | if (GEOMETRY_COLLECTION_TYPES.indexOf(this.type) !== -1) {
|
16787 | this._painter = new CollectionPainter(this);
|
16788 | } else {
|
16789 | this._painter = new Painter(this);
|
16790 | }
|
16791 | }
|
16792 | return this._painter;
|
16793 | };
|
16794 |
|
16795 | Geometry.prototype._removePainter = function _removePainter() {
|
16796 | if (this._painter) {
|
16797 | this._painter.remove();
|
16798 | }
|
16799 | delete this._painter;
|
16800 | };
|
16801 |
|
16802 | Geometry.prototype._paint = function _paint(extent) {
|
16803 | if (this._painter) {
|
16804 | this._painter.paint(extent);
|
16805 | }
|
16806 | };
|
16807 |
|
16808 | Geometry.prototype._clearCache = function _clearCache() {
|
16809 | delete this._extent;
|
16810 | };
|
16811 |
|
16812 | Geometry.prototype._clearProjection = function _clearProjection() {
|
16813 | delete this._extent;
|
16814 | };
|
16815 |
|
16816 | Geometry.prototype._repaint = function _repaint() {
|
16817 | if (this._painter) {
|
16818 | this._painter.repaint();
|
16819 | }
|
16820 | };
|
16821 |
|
16822 | Geometry.prototype.onHide = function onHide() {
|
16823 | this.closeMenu();
|
16824 | this.closeInfoWindow();
|
16825 | };
|
16826 |
|
16827 | Geometry.prototype.onShapeChanged = function onShapeChanged() {
|
16828 | this._clearCache();
|
16829 | this._repaint();
|
16830 |
|
16831 | this._fireEvent('shapechange');
|
16832 | };
|
16833 |
|
16834 | Geometry.prototype.onPositionChanged = function onPositionChanged() {
|
16835 | this._clearCache();
|
16836 | this._repaint();
|
16837 |
|
16838 | this._fireEvent('positionchange');
|
16839 | };
|
16840 |
|
16841 | Geometry.prototype.onSymbolChanged = function onSymbolChanged() {
|
16842 | if (this._painter) {
|
16843 | this._painter.refreshSymbol();
|
16844 | }
|
16845 |
|
16846 | this._fireEvent('symbolchange');
|
16847 | };
|
16848 |
|
16849 | Geometry.prototype.onConfig = function onConfig(conf) {
|
16850 | var properties = void 0;
|
16851 | if (conf['properties']) {
|
16852 | properties = conf['properties'];
|
16853 | delete conf['properties'];
|
16854 | }
|
16855 | var needRepaint = false;
|
16856 | for (var p in conf) {
|
16857 | if (conf.hasOwnProperty(p)) {
|
16858 | var prefix = p.slice(0, 5);
|
16859 | if (prefix === 'arrow' || prefix === 'smoot') {
|
16860 | needRepaint = true;
|
16861 | break;
|
16862 | }
|
16863 | }
|
16864 | }
|
16865 | if (properties) {
|
16866 | this.setProperties(properties);
|
16867 | this._repaint();
|
16868 | } else if (needRepaint) {
|
16869 | this._repaint();
|
16870 | }
|
16871 | };
|
16872 |
|
16873 | Geometry.prototype._setParent = function _setParent(geometry) {
|
16874 | if (geometry) {
|
16875 | this._parent = geometry;
|
16876 | }
|
16877 | };
|
16878 |
|
16879 | Geometry.prototype._getParent = function _getParent() {
|
16880 | return this._parent;
|
16881 | };
|
16882 |
|
16883 | Geometry.prototype._fireEvent = function _fireEvent(eventName, param) {
|
16884 | if (this.getLayer() && this.getLayer()._onGeometryEvent) {
|
16885 | if (!param) {
|
16886 | param = {};
|
16887 | }
|
16888 | param['type'] = eventName;
|
16889 | param['target'] = this;
|
16890 | this.getLayer()._onGeometryEvent(param);
|
16891 | }
|
16892 | this.fire(eventName, param);
|
16893 | };
|
16894 |
|
16895 | Geometry.prototype._toJSON = function _toJSON(options) {
|
16896 | return {
|
16897 | 'feature': this.toGeoJSON(options)
|
16898 | };
|
16899 | };
|
16900 |
|
16901 | Geometry.prototype._exportGraphicOptions = function _exportGraphicOptions(options) {
|
16902 | var json = {};
|
16903 | if (isNil(options['options']) || options['options']) {
|
16904 | json['options'] = this.config();
|
16905 | }
|
16906 | if (isNil(options['symbol']) || options['symbol']) {
|
16907 | json['symbol'] = this.getSymbol();
|
16908 | }
|
16909 | if (isNil(options['infoWindow']) || options['infoWindow']) {
|
16910 | if (this._infoWinOptions) {
|
16911 | json['infoWindow'] = this._infoWinOptions;
|
16912 | }
|
16913 | }
|
16914 | return json;
|
16915 | };
|
16916 |
|
16917 | Geometry.prototype._exportGeoJSONGeometry = function _exportGeoJSONGeometry() {
|
16918 | var points = this.getCoordinates();
|
16919 | var coordinates = Coordinate.toNumberArrays(points);
|
16920 | return {
|
16921 | 'type': this.getType(),
|
16922 | 'coordinates': coordinates
|
16923 | };
|
16924 | };
|
16925 |
|
16926 | Geometry.prototype._exportProperties = function _exportProperties() {
|
16927 | var properties = null;
|
16928 | var geoProperties = this.getProperties();
|
16929 | if (!isNil(geoProperties)) {
|
16930 | if (isObject(geoProperties)) {
|
16931 | properties = extend({}, geoProperties);
|
16932 | } else {
|
16933 | properties = geoProperties;
|
16934 | }
|
16935 | }
|
16936 | return properties;
|
16937 | };
|
16938 |
|
16939 | return Geometry;
|
16940 | }(JSONAble(Eventable(Handlerable(Class))));
|
16941 |
|
16942 | Geometry.mergeOptions(options$2);
|
16943 |
|
16944 | var EVENTS = 'mousedown ' + 'mouseup ' + 'mousemove ' + 'click ' + 'dblclick ' + 'contextmenu ' + 'touchstart ' + 'touchmove ' + 'touchend';
|
16945 |
|
16946 | var MapGeometryEventsHandler = function (_Handler) {
|
16947 | inherits(MapGeometryEventsHandler, _Handler);
|
16948 |
|
16949 | function MapGeometryEventsHandler() {
|
16950 | classCallCheck(this, MapGeometryEventsHandler);
|
16951 | return possibleConstructorReturn(this, _Handler.apply(this, arguments));
|
16952 | }
|
16953 |
|
16954 | MapGeometryEventsHandler.prototype.addHooks = function addHooks() {
|
16955 | var map = this.target;
|
16956 | var dom = map._panels.allLayers || map._containerDOM;
|
16957 | on(dom, EVENTS, this._identifyGeometryEvents, this);
|
16958 | };
|
16959 |
|
16960 | MapGeometryEventsHandler.prototype.removeHooks = function removeHooks() {
|
16961 | var map = this.target;
|
16962 | var dom = map._panels.allLayers || map._containerDOM;
|
16963 | off(dom, EVENTS, this._identifyGeometryEvents, this);
|
16964 | };
|
16965 |
|
16966 | MapGeometryEventsHandler.prototype._identifyGeometryEvents = function _identifyGeometryEvents(domEvent, type) {
|
16967 | var map = this.target;
|
16968 | if (map.isInteracting() || map._ignoreEvent(domEvent)) {
|
16969 | return;
|
16970 | }
|
16971 | var layers = map._getLayers(function (layer) {
|
16972 | if (layer.identify && layer.options['geometryEvents']) {
|
16973 | return true;
|
16974 | }
|
16975 | return false;
|
16976 | });
|
16977 | if (!layers.length) {
|
16978 | return;
|
16979 | }
|
16980 | var oneMoreEvent = null;
|
16981 | var eventType = type || domEvent.type;
|
16982 |
|
16983 | if (eventType === 'mousedown' || eventType === 'touchstart' && domEvent.touches.length === 1) {
|
16984 | this._mouseDownTime = now();
|
16985 | } else if ((eventType === 'click' || eventType === 'touchend') && this._mouseDownTime) {
|
16986 | var downTime = this._mouseDownTime;
|
16987 | delete this._mouseDownTime;
|
16988 | var time = now();
|
16989 | if (time - downTime > 300) {
|
16990 | if (eventType === 'click') {
|
16991 | return;
|
16992 | }
|
16993 | } else if (eventType === 'touchend') {
|
16994 | oneMoreEvent = 'click';
|
16995 | }
|
16996 | }
|
16997 |
|
16998 | var actual = domEvent.touches && domEvent.touches.length > 0 ? domEvent.touches[0] : domEvent.changedTouches && domEvent.changedTouches.length > 0 ? domEvent.changedTouches[0] : domEvent;
|
16999 | if (!actual) {
|
17000 | return;
|
17001 | }
|
17002 | var containerPoint = getEventContainerPoint(actual, map._containerDOM),
|
17003 | coordinate = map.containerPointToCoordinate(containerPoint);
|
17004 | if (eventType === 'touchstart') {
|
17005 | preventDefault(domEvent);
|
17006 | }
|
17007 | var geometryCursorStyle = null;
|
17008 | var identifyOptions = {
|
17009 | 'includeInternals': true,
|
17010 |
|
17011 | 'filter': function filter(geometry) {
|
17012 | if (!(geometry instanceof Geometry)) {
|
17013 | return false;
|
17014 | }
|
17015 | var eventToFire = geometry._getEventTypeToFire(domEvent);
|
17016 | if (eventType === 'mousemove') {
|
17017 | if (!geometryCursorStyle && geometry.options['cursor']) {
|
17018 | geometryCursorStyle = geometry.options['cursor'];
|
17019 | }
|
17020 | if (!geometry.listens('mousemove') && !geometry.listens('mouseover') && !geometry.listens('mouseenter')) {
|
17021 | return false;
|
17022 | }
|
17023 | } else if (!geometry.listens(eventToFire) && !geometry.listens(oneMoreEvent)) {
|
17024 | return false;
|
17025 | }
|
17026 |
|
17027 | return true;
|
17028 | },
|
17029 | 'count': 1,
|
17030 | 'coordinate': coordinate,
|
17031 | 'onlyVisible': map.options['onlyVisibleGeometryEvents'],
|
17032 | 'layers': layers
|
17033 | };
|
17034 | var callback = fireGeometryEvent.bind(this);
|
17035 |
|
17036 | if (this._queryIdentifyTimeout) {
|
17037 | cancelAnimFrame(this._queryIdentifyTimeout);
|
17038 | }
|
17039 | if (eventType === 'mousemove' || eventType === 'touchmove') {
|
17040 | this._queryIdentifyTimeout = requestAnimFrame(function () {
|
17041 | if (map.isInteracting()) {
|
17042 | return;
|
17043 | }
|
17044 | map.identify(identifyOptions, callback);
|
17045 | });
|
17046 | } else {
|
17047 | map.identify(identifyOptions, callback);
|
17048 | }
|
17049 |
|
17050 | function fireGeometryEvent(geometries) {
|
17051 | var propagation = true;
|
17052 | if (eventType === 'mousemove') {
|
17053 | var geoMap = {};
|
17054 | if (geometries.length > 0) {
|
17055 | for (var i = geometries.length - 1; i >= 0; i--) {
|
17056 | var geo = geometries[i];
|
17057 | if (!(geo instanceof Geometry)) {
|
17058 | continue;
|
17059 | }
|
17060 | var iid = geo._getInternalId();
|
17061 | geoMap[iid] = geo;
|
17062 | geo._onEvent(domEvent);
|
17063 | if (!this._prevOverGeos || !this._prevOverGeos.geomap[iid]) {
|
17064 | geo._onEvent(domEvent, 'mouseenter');
|
17065 | }
|
17066 | propagation = geo._onEvent(domEvent, 'mouseover');
|
17067 | }
|
17068 | }
|
17069 |
|
17070 | map._setPriorityCursor(geometryCursorStyle);
|
17071 |
|
17072 | var oldTargets = this._prevOverGeos && this._prevOverGeos.geos;
|
17073 | this._prevOverGeos = {
|
17074 | 'geos': geometries,
|
17075 | 'geomap': geoMap
|
17076 | };
|
17077 | if (oldTargets && oldTargets.length > 0) {
|
17078 | for (var _i = oldTargets.length - 1; _i >= 0; _i--) {
|
17079 | var oldTarget = oldTargets[_i];
|
17080 | if (!(oldTarget instanceof Geometry)) {
|
17081 | continue;
|
17082 | }
|
17083 | var oldTargetId = oldTargets[_i]._getInternalId();
|
17084 |
|
17085 | if (!geoMap[oldTargetId]) {
|
17086 | propagation = oldTarget._onEvent(domEvent, 'mouseout');
|
17087 | }
|
17088 | }
|
17089 | }
|
17090 | } else {
|
17091 | if (!geometries || !geometries.length) {
|
17092 | return;
|
17093 | }
|
17094 | for (var _i2 = geometries.length - 1; _i2 >= 0; _i2--) {
|
17095 | if (!(geometries[_i2] instanceof Geometry)) {
|
17096 | continue;
|
17097 | }
|
17098 | propagation = geometries[_i2]._onEvent(domEvent);
|
17099 | if (oneMoreEvent) {
|
17100 | geometries[_i2]._onEvent(domEvent, oneMoreEvent);
|
17101 | }
|
17102 | break;
|
17103 | }
|
17104 | }
|
17105 | if (propagation === false) {
|
17106 | stopPropagation(domEvent);
|
17107 | }
|
17108 | }
|
17109 | };
|
17110 |
|
17111 | return MapGeometryEventsHandler;
|
17112 | }(Handler$1);
|
17113 |
|
17114 | Map.mergeOptions({
|
17115 | 'geometryEvents': true,
|
17116 | 'onlyVisibleGeometryEvents': true
|
17117 | });
|
17118 |
|
17119 | Map.addOnLoadHook('addHandler', 'geometryEvents', MapGeometryEventsHandler);
|
17120 |
|
17121 | var MapScrollWheelZoomHandler = function (_Handler) {
|
17122 | inherits(MapScrollWheelZoomHandler, _Handler);
|
17123 |
|
17124 | function MapScrollWheelZoomHandler() {
|
17125 | classCallCheck(this, MapScrollWheelZoomHandler);
|
17126 | return possibleConstructorReturn(this, _Handler.apply(this, arguments));
|
17127 | }
|
17128 |
|
17129 | MapScrollWheelZoomHandler.prototype.addHooks = function addHooks() {
|
17130 | addDomEvent(this.target._containerDOM, 'mousewheel', this._onWheelScroll, this);
|
17131 | };
|
17132 |
|
17133 | MapScrollWheelZoomHandler.prototype.removeHooks = function removeHooks() {
|
17134 | removeDomEvent(this.target._containerDOM, 'mousewheel', this._onWheelScroll);
|
17135 | };
|
17136 |
|
17137 | MapScrollWheelZoomHandler.prototype._onWheelScroll = function _onWheelScroll(evt) {
|
17138 | var _this2 = this;
|
17139 |
|
17140 | var map = this.target;
|
17141 | if (map._ignoreEvent(evt) || !map.options['zoomable']) {
|
17142 | return false;
|
17143 | }
|
17144 | preventDefault(evt);
|
17145 | stopPropagation(evt);
|
17146 | if (this._zooming) {
|
17147 | this._requesting++;
|
17148 | return false;
|
17149 | }
|
17150 | this._requesting = 0;
|
17151 | var container = map._containerDOM;
|
17152 | var levelValue = (evt.wheelDelta ? evt.wheelDelta : evt.detail) > 0 ? 1 : -1;
|
17153 | if (evt.detail) {
|
17154 | levelValue *= -1;
|
17155 | }
|
17156 | var zoom = map.getZoom();
|
17157 | var nextZoom = zoom + levelValue;
|
17158 | nextZoom = map._checkZoom(levelValue > 0 ? Math.ceil(nextZoom) : Math.floor(nextZoom));
|
17159 | if (nextZoom === zoom) {
|
17160 | return false;
|
17161 | }
|
17162 | this._zooming = true;
|
17163 | var origin = map._checkZoomOrigin(getEventContainerPoint(evt, container));
|
17164 | if (!this._delta) {
|
17165 | map.onZoomStart(null, origin);
|
17166 | this._origin = origin;
|
17167 | this._delta = levelValue;
|
17168 | this._startZoom = map.getZoom();
|
17169 | }
|
17170 | var duration = 90;
|
17171 | map.animateTo({
|
17172 | 'zoom': nextZoom - this._delta * 1 / 2,
|
17173 | 'around': this._origin
|
17174 | }, {
|
17175 | 'continueOnViewChanged': true,
|
17176 | 'easing': 'linear',
|
17177 | 'duration': duration,
|
17178 | 'wheelZoom': true
|
17179 | }, function (frame) {
|
17180 | if (frame.state.playState !== 'finished') {
|
17181 | return;
|
17182 | }
|
17183 | if (_this2._requesting < 1 || Math.abs(nextZoom - _this2._startZoom) > 2 || nextZoom === map.getMaxZoom() || nextZoom === map.getMinZoom()) {
|
17184 |
|
17185 | map.animateTo({
|
17186 | 'zoom': nextZoom,
|
17187 | 'around': _this2._origin
|
17188 | }, {
|
17189 | 'continueOnViewChanged': true,
|
17190 | 'duration': 100
|
17191 | }, function (frame) {
|
17192 | if (frame.state.playState === 'finished') {
|
17193 | setTimeout(function () {
|
17194 | delete _this2._zooming;
|
17195 | delete _this2._requesting;
|
17196 | }, 200);
|
17197 | }
|
17198 | });
|
17199 | delete _this2._startZoom;
|
17200 | delete _this2._origin;
|
17201 | delete _this2._delta;
|
17202 | _this2._requesting = 0;
|
17203 | } else if (!isNil(_this2._requesting)) {
|
17204 | delete _this2._zooming;
|
17205 | _this2._onWheelScroll(evt);
|
17206 | }
|
17207 | });
|
17208 | return false;
|
17209 | };
|
17210 |
|
17211 | return MapScrollWheelZoomHandler;
|
17212 | }(Handler$1);
|
17213 |
|
17214 | Map.mergeOptions({
|
17215 | 'scrollWheelZoom': true
|
17216 | });
|
17217 |
|
17218 | Map.addOnLoadHook('addHandler', 'scrollWheelZoom', MapScrollWheelZoomHandler);
|
17219 |
|
17220 | var MapTouchZoomHandler = function (_Handler) {
|
17221 | inherits(MapTouchZoomHandler, _Handler);
|
17222 |
|
17223 | function MapTouchZoomHandler() {
|
17224 | classCallCheck(this, MapTouchZoomHandler);
|
17225 | return possibleConstructorReturn(this, _Handler.apply(this, arguments));
|
17226 | }
|
17227 |
|
17228 | MapTouchZoomHandler.prototype.addHooks = function addHooks() {
|
17229 | addDomEvent(this.target.getContainer(), 'touchstart', this._onTouchStart, this);
|
17230 | };
|
17231 |
|
17232 | MapTouchZoomHandler.prototype.removeHooks = function removeHooks() {
|
17233 | removeDomEvent(this.target.getContainer(), 'touchstart', this._onTouchStart);
|
17234 | };
|
17235 |
|
17236 | MapTouchZoomHandler.prototype._onTouchStart = function _onTouchStart(event) {
|
17237 | var map = this.target;
|
17238 | if (!event.touches || event.touches.length !== 2 || map.isInteracting()) {
|
17239 | return;
|
17240 | }
|
17241 | var container = map.getContainer();
|
17242 | var p1 = getEventContainerPoint(event.touches[0], container),
|
17243 | p2 = getEventContainerPoint(event.touches[1], container);
|
17244 |
|
17245 | this.preY = p1.y;
|
17246 | this._startP1 = p1;
|
17247 | this._startP2 = p2;
|
17248 | this._startDist = p1.distanceTo(p2);
|
17249 | this._startVector = p1.sub(p2);
|
17250 | this._startZoom = map.getZoom();
|
17251 | this._startBearing = map.getBearing();
|
17252 |
|
17253 | addDomEvent(document, 'touchmove', this._onTouchMove, this);
|
17254 | addDomEvent(document, 'touchend', this._onTouchEnd, this);
|
17255 | preventDefault(event);
|
17256 |
|
17257 | map._fireEvent('touchactstart');
|
17258 | };
|
17259 |
|
17260 | MapTouchZoomHandler.prototype._onTouchMove = function _onTouchMove(event) {
|
17261 | var map = this.target;
|
17262 | if (!event.touches || event.touches.length !== 2) {
|
17263 | return;
|
17264 | }
|
17265 | var container = map.getContainer(),
|
17266 | p1 = getEventContainerPoint(event.touches[0], container),
|
17267 | p2 = getEventContainerPoint(event.touches[1], container),
|
17268 | d1 = p1.sub(this._startP1),
|
17269 | d2 = p2.sub(this._startP2),
|
17270 | vector = p1.sub(p2),
|
17271 | scale = p1.distanceTo(p2) / this._startDist,
|
17272 | bearing = vector.angleWith(this._startVector) * 180 / Math.PI,
|
17273 | preY = this.preY || p1.y,
|
17274 | pitch = (preY - p1.y) * 0.4;
|
17275 |
|
17276 | this.preY = p1.y;
|
17277 | var param = {
|
17278 | 'domEvent': event,
|
17279 | 'mousePos': [p1, p2]
|
17280 | };
|
17281 | if (!this.mode) {
|
17282 | if (map.options['touchRotate'] && Math.abs(bearing) > 8) {
|
17283 | this.mode = map.options['touchZoomRotate'] ? 'rotate_zoom' : 'rotate';
|
17284 | } else if (map.options['touchPitch'] && d1.y * d2.y > 0 && Math.abs(d1.y) > 10 && Math.abs(d2.y) > 10) {
|
17285 | this.mode = 'pitch';
|
17286 | } else if (map.options['zoomable'] && map.options['touchZoom'] && Math.abs(1 - scale) > 0.15) {
|
17287 | this.mode = map.options['touchZoomRotate'] && map.options['touchRotate'] ? 'rotate_zoom' : 'zoom';
|
17288 | }
|
17289 | this._startTouching(param);
|
17290 | }
|
17291 | if (this.mode === 'zoom' || this.mode === 'rotate_zoom') {
|
17292 | this._scale = scale;
|
17293 | var res = map._getResolution(this._startZoom) / scale;
|
17294 | var zoom = map.getZoomFromRes(res);
|
17295 | map.onZooming(zoom, this._Origin);
|
17296 | }
|
17297 | if (this.mode === 'rotate' || this.mode === 'rotate_zoom') {
|
17298 | map.setBearing(this._startBearing + bearing);
|
17299 | map.onDragRotating(param);
|
17300 | } else if (this.mode === 'pitch') {
|
17301 | map.setPitch(map.getPitch() + pitch);
|
17302 | map.onDragRotating(param);
|
17303 | }
|
17304 |
|
17305 | map._fireEvent('touchactinging');
|
17306 | };
|
17307 |
|
17308 | MapTouchZoomHandler.prototype._startTouching = function _startTouching(param) {
|
17309 | var map = this.target;
|
17310 | if (this.mode === 'zoom' || this.mode === 'rotate_zoom') {
|
17311 | var size = map.getSize();
|
17312 | this._Origin = new Point(size['width'] / 2, size['height'] / 2);
|
17313 | map.onZoomStart(null, this._Origin);
|
17314 | }
|
17315 | if (this.mode === 'rotate' || this.mode === 'pitch' || this.mode === 'rotate_zoom') {
|
17316 | map.onDragRotateStart(param);
|
17317 | }
|
17318 | };
|
17319 |
|
17320 | MapTouchZoomHandler.prototype._onTouchEnd = function _onTouchEnd(event) {
|
17321 | delete this.preY;
|
17322 | var map = this.target;
|
17323 |
|
17324 | off(document, 'touchmove', this._onTouchMove, this);
|
17325 | off(document, 'touchend', this._onTouchEnd, this);
|
17326 |
|
17327 | if (this.mode === 'zoom' || this.mode === 'rotate_zoom') {
|
17328 | var scale = this._scale;
|
17329 | var res = map._getResolution(this._startZoom) / scale;
|
17330 | var zoom = map.getZoomFromRes(res);
|
17331 | map.onZoomEnd(zoom, this._Origin);
|
17332 | }
|
17333 | if (this.mode === 'pitch' || this.mode === 'rotate' || this.mode === 'rotate_zoom') {
|
17334 | map.onDragRotateEnd({
|
17335 | 'domEvent': event
|
17336 | });
|
17337 | }
|
17338 | delete this.mode;
|
17339 |
|
17340 | map._fireEvent('touchactend');
|
17341 | };
|
17342 |
|
17343 | return MapTouchZoomHandler;
|
17344 | }(Handler$1);
|
17345 |
|
17346 | Map.mergeOptions({
|
17347 | 'touchGesture': true,
|
17348 | 'touchZoom': true,
|
17349 | 'touchPitch': true,
|
17350 | 'touchRotate': true,
|
17351 | 'touchZoomRotate': false
|
17352 | });
|
17353 |
|
17354 | Map.addOnLoadHook('addHandler', 'touchGesture', MapTouchZoomHandler);
|
17355 |
|
17356 | var Easing = {
|
17357 | in: function _in(t) {
|
17358 | return Math.pow(t, 2);
|
17359 | },
|
17360 | out: function out(t) {
|
17361 | return 1 - Easing.in(1 - t);
|
17362 | },
|
17363 | inAndOut: function inAndOut(t) {
|
17364 | return 3 * t * t - 2 * t * t * t;
|
17365 | },
|
17366 | linear: function linear(t) {
|
17367 | return t;
|
17368 | },
|
17369 | upAndDown: function upAndDown(t) {
|
17370 | if (t < 0.5) {
|
17371 | return Easing.inAndOut(2 * t);
|
17372 | } else {
|
17373 | return 1 - Easing.inAndOut(2 * (t - 0.5));
|
17374 | }
|
17375 | }
|
17376 | };
|
17377 |
|
17378 | var Frame = function Frame(state, styles) {
|
17379 | classCallCheck(this, Frame);
|
17380 |
|
17381 | this.state = state;
|
17382 | this.styles = styles;
|
17383 | };
|
17384 |
|
17385 | var Player = function Player(animation, options, onFrame) {
|
17386 | classCallCheck(this, Player);
|
17387 |
|
17388 | this._animation = animation;
|
17389 | this.options = options;
|
17390 | this._onFrame = onFrame;
|
17391 | this.playState = 'idle';
|
17392 | this.ready = true;
|
17393 | this.finished = false;
|
17394 | };
|
17395 |
|
17396 | var Animation = {
|
17397 | speed: {
|
17398 | 'slow': 2000,
|
17399 | 'normal': 1000,
|
17400 | 'fast': 500
|
17401 | },
|
17402 |
|
17403 | _resolveStyles: function _resolveStyles(styles) {
|
17404 | if (!styles) {
|
17405 | return null;
|
17406 | }
|
17407 |
|
17408 | function resolveChild(child) {
|
17409 | if (!Array.isArray(child)) {
|
17410 | return Animation._resolveStyles(child);
|
17411 | }
|
17412 | var start = [],
|
17413 | d = [],
|
17414 | dest = [];
|
17415 | for (var i = 0; i < child.length; i++) {
|
17416 | var _styles = Animation._resolveStyles(child[i]);
|
17417 | if (_styles) {
|
17418 | start.push(_styles[0]);
|
17419 | d.push(_styles[1]);
|
17420 | dest.push(_styles[2]);
|
17421 | }
|
17422 | }
|
17423 | if (!start.length) {
|
17424 | return null;
|
17425 | } else {
|
17426 | return [start, d, dest];
|
17427 | }
|
17428 | }
|
17429 |
|
17430 | function resolveVal(val) {
|
17431 | var values = val;
|
17432 | var clazz = void 0;
|
17433 |
|
17434 | if (!Array.isArray(val)) {
|
17435 | if (isNumber(val)) {
|
17436 | values = [0, val];
|
17437 | } else if (val instanceof Point || val instanceof Coordinate) {
|
17438 | clazz = val.constructor;
|
17439 | values = [new clazz(0, 0), val];
|
17440 | } else {
|
17441 | values = [val, val];
|
17442 | }
|
17443 | }
|
17444 |
|
17445 | var v1 = values[0],
|
17446 | v2 = values[1];
|
17447 | if (isNumber(v1) && isNumber(v2)) {
|
17448 | if (v1 === v2) {
|
17449 | return null;
|
17450 | }
|
17451 | return [v1, v2 - v1, v2];
|
17452 | } else if (Array.isArray(v1) || v1 instanceof Coordinate || v1 instanceof Point) {
|
17453 | if (Array.isArray(v1)) {
|
17454 | v1 = new Coordinate(v1);
|
17455 | v2 = new Coordinate(v2);
|
17456 | } else {
|
17457 | clazz = v1.constructor;
|
17458 | v1 = new clazz(v1);
|
17459 | v2 = new clazz(v2);
|
17460 | }
|
17461 | if (v1.equals(v2)) {
|
17462 | return null;
|
17463 | }
|
17464 | return [v1, v2.sub(v1), v2];
|
17465 | } else {
|
17466 | return [v1, 0, v2];
|
17467 | }
|
17468 | }
|
17469 |
|
17470 | function isChild(val) {
|
17471 | if (!Array.isArray(val) && val.constructor === Object) {
|
17472 | return true;
|
17473 | } else if (Array.isArray(val) && val[0].constructor === Object) {
|
17474 | return true;
|
17475 | }
|
17476 | return false;
|
17477 | }
|
17478 |
|
17479 | var d = {},
|
17480 | start = {},
|
17481 | dest = {};
|
17482 | for (var p in styles) {
|
17483 | if (styles.hasOwnProperty(p)) {
|
17484 | var values = styles[p];
|
17485 |
|
17486 | if (!values) {
|
17487 | continue;
|
17488 | } else if (Array.isArray(values)) {
|
17489 | if (isNil(values[0]) || isNil(values[1])) {
|
17490 | continue;
|
17491 | }
|
17492 | }
|
17493 | var childStyles = void 0;
|
17494 | if (isChild(values)) {
|
17495 | childStyles = resolveChild(values);
|
17496 | } else {
|
17497 | childStyles = resolveVal(values);
|
17498 | }
|
17499 | if (childStyles) {
|
17500 | start[p] = childStyles[0];
|
17501 | d[p] = childStyles[1];
|
17502 | dest[p] = childStyles[2];
|
17503 | }
|
17504 | }
|
17505 | }
|
17506 | return [start, d, dest];
|
17507 | },
|
17508 | framing: function framing(styles, options) {
|
17509 | if (!options) {
|
17510 | options = {};
|
17511 | }
|
17512 | var easing = options['easing'] ? Easing[options['easing']] : Easing.linear;
|
17513 | if (!easing) {
|
17514 | easing = Easing.linear;
|
17515 | }
|
17516 | var dStyles = void 0,
|
17517 | startStyles = void 0,
|
17518 | destStyles = void 0;
|
17519 | styles = Animation._resolveStyles(styles);
|
17520 | if (styles) {
|
17521 | startStyles = styles[0];
|
17522 | dStyles = styles[1];
|
17523 | destStyles = styles[2];
|
17524 | }
|
17525 | var deltaStyles = function deltaStyles(delta, _startStyles, _dStyles) {
|
17526 | if (!_startStyles || !_dStyles) {
|
17527 | return null;
|
17528 | }
|
17529 | var result = {};
|
17530 | for (var p in _dStyles) {
|
17531 | if (_dStyles.hasOwnProperty(p)) {
|
17532 | if (_startStyles[p] === destStyles[p]) {
|
17533 | result[p] = _startStyles[p];
|
17534 | continue;
|
17535 | }
|
17536 | var s = _startStyles[p],
|
17537 | d = _dStyles[p];
|
17538 | if (isNumber(d)) {
|
17539 | result[p] = s + delta * d;
|
17540 | } else if (Array.isArray(d)) {
|
17541 | var children = [];
|
17542 | for (var i = 0; i < d.length; i++) {
|
17543 | children.push(deltaStyles(delta, s[i], d[i]));
|
17544 | }
|
17545 | result[p] = children;
|
17546 | } else {
|
17547 | var clazz = d.constructor;
|
17548 | if (clazz === Object) {
|
17549 | result[p] = deltaStyles(delta, s, d);
|
17550 | } else if (s instanceof Point || s instanceof Coordinate) {
|
17551 | result[p] = s.add(d.multi(delta));
|
17552 | }
|
17553 | }
|
17554 | }
|
17555 | }
|
17556 | return result;
|
17557 | };
|
17558 | return function (elapsed, duration) {
|
17559 | var state = void 0,
|
17560 | d = void 0;
|
17561 | if (elapsed < 0) {
|
17562 | state = {
|
17563 | 'playState': 'idle',
|
17564 | 'delta': 0
|
17565 | };
|
17566 | d = startStyles;
|
17567 | } else if (elapsed < duration) {
|
17568 | var delta = easing(elapsed / duration);
|
17569 | state = {
|
17570 | 'playState': 'running',
|
17571 | 'delta': delta
|
17572 | };
|
17573 | d = deltaStyles(delta, startStyles, dStyles);
|
17574 | } else {
|
17575 | state = {
|
17576 | 'playState': 'finished',
|
17577 | 'delta': 1
|
17578 | };
|
17579 | d = destStyles;
|
17580 | }
|
17581 | state['startStyles'] = startStyles;
|
17582 | state['destStyles'] = destStyles;
|
17583 | state['progress'] = elapsed;
|
17584 | state['remainingMs'] = duration - elapsed;
|
17585 | return new Frame(state, d);
|
17586 | };
|
17587 | },
|
17588 | _requestAnimFrame: function _requestAnimFrame(fn) {
|
17589 | if (!this._frameQueue) {
|
17590 | this._frameQueue = [];
|
17591 | }
|
17592 | this._frameQueue.push(fn);
|
17593 | this._a();
|
17594 | },
|
17595 | _a: function _a() {
|
17596 | if (!this._animationFrameId) {
|
17597 | this._animationFrameId = requestAnimFrame(Animation._frameFn);
|
17598 | }
|
17599 | },
|
17600 | _run: function _run() {
|
17601 | if (this._frameQueue.length) {
|
17602 | var running = this._frameQueue;
|
17603 | this._frameQueue = [];
|
17604 | for (var i = 0, len = running.length; i < len; i++) {
|
17605 | running[i]();
|
17606 | }
|
17607 | if (this._frameQueue.length) {
|
17608 | this._animationFrameId = requestAnimFrame(Animation._frameFn);
|
17609 | } else {
|
17610 | delete this._animationFrameId;
|
17611 | }
|
17612 | }
|
17613 | },
|
17614 | animate: function animate(styles, options, step) {
|
17615 | if (!options) {
|
17616 | options = {};
|
17617 | }
|
17618 | var animation = Animation.framing(styles, options);
|
17619 | return new Player(animation, options, step);
|
17620 | }
|
17621 | };
|
17622 |
|
17623 | Animation._frameFn = Animation._run.bind(Animation);
|
17624 |
|
17625 | extend(Player.prototype, {
|
17626 | _prepare: function _prepare() {
|
17627 | var options = this.options;
|
17628 | var duration = options['speed'] || options['duration'];
|
17629 | if (isString(duration)) {
|
17630 | duration = Animation.speed[duration];
|
17631 | if (!duration) {
|
17632 | duration = +duration;
|
17633 | }
|
17634 | }
|
17635 | if (!duration) {
|
17636 | duration = Animation.speed['normal'];
|
17637 | }
|
17638 | this.duration = duration;
|
17639 | this._framer = options['framer'] || Animation._requestAnimFrame.bind(Animation);
|
17640 | },
|
17641 | play: function play() {
|
17642 | if (this.playState !== 'idle' && this.playState !== 'paused') {
|
17643 | return this;
|
17644 | }
|
17645 | if (this.playState === 'idle') {
|
17646 | this.currentTime = 0;
|
17647 | this._prepare();
|
17648 | }
|
17649 | var t = now();
|
17650 | if (!this.startTime) {
|
17651 | var options = this.options;
|
17652 | this.startTime = options['startTime'] ? options['startTime'] : t;
|
17653 | }
|
17654 | this._playStartTime = Math.max(t, this.startTime);
|
17655 | if (this.playState === 'paused') {
|
17656 | this._playStartTime -= this.currentTime;
|
17657 | }
|
17658 | this.playState = 'running';
|
17659 | this._run();
|
17660 | return this;
|
17661 | },
|
17662 | pause: function pause() {
|
17663 | if (this.playState === 'paused') {
|
17664 | return this;
|
17665 | }
|
17666 | this.playState = 'paused';
|
17667 | this._run();
|
17668 |
|
17669 | return this;
|
17670 | },
|
17671 | cancel: function cancel() {
|
17672 | if (this.playState === 'idle') {
|
17673 | return this;
|
17674 | }
|
17675 | this.playState = 'idle';
|
17676 | this.finished = false;
|
17677 | this._run();
|
17678 | return this;
|
17679 | },
|
17680 | finish: function finish() {
|
17681 | if (this.playState === 'finished') {
|
17682 | return this;
|
17683 | }
|
17684 | this.playState = 'finished';
|
17685 | this.finished = true;
|
17686 | this._run();
|
17687 | return this;
|
17688 | },
|
17689 | reverse: function reverse() {},
|
17690 | _run: function _run() {
|
17691 | var _this = this;
|
17692 |
|
17693 | var onFrame = this._onFrame;
|
17694 | var t = now();
|
17695 | var elapsed = t - this._playStartTime;
|
17696 | if (this.options['repeat'] && elapsed >= this.duration) {
|
17697 | this._playStartTime = t;
|
17698 | elapsed = 0;
|
17699 | }
|
17700 | if (this.playState !== 'running') {
|
17701 | if (onFrame) {
|
17702 | if (this.playState === 'finished') {
|
17703 | elapsed = this.duration;
|
17704 | } else if (this.playState === 'idle') {
|
17705 | elapsed = 0;
|
17706 | }
|
17707 | var _frame = this._animation(elapsed, this.duration);
|
17708 | _frame.state.playState = this.playState;
|
17709 | onFrame(_frame);
|
17710 | }
|
17711 | return;
|
17712 | }
|
17713 |
|
17714 | var frame = this._animation(elapsed, this.duration);
|
17715 | this.playState = frame.state['playState'];
|
17716 |
|
17717 | if (this.playState === 'idle') {
|
17718 | if (this.startTime > t) {
|
17719 | setTimeout(this._run.bind(this), this.startTime - t);
|
17720 | }
|
17721 | } else if (this.playState === 'running') {
|
17722 | this._framer(function () {
|
17723 | if (_this.playState !== 'running') {
|
17724 | return;
|
17725 | }
|
17726 | _this.currentTime = elapsed;
|
17727 | if (onFrame) {
|
17728 | onFrame(frame);
|
17729 | }
|
17730 | _this._run();
|
17731 | });
|
17732 | } else if (this.playState === 'finished') {
|
17733 | this.finished = true;
|
17734 |
|
17735 | if (onFrame) {
|
17736 | onFrame(frame);
|
17737 | }
|
17738 | }
|
17739 | }
|
17740 | });
|
17741 |
|
17742 |
|
17743 |
|
17744 | var Animation$1 = Object.freeze({
|
17745 | Animation: Animation,
|
17746 | Easing: Easing,
|
17747 | Player: Player,
|
17748 | Frame: Frame
|
17749 | });
|
17750 |
|
17751 | var simplify = createCommonjsModule(function (module) {
|
17752 |
|
17753 | (function () {
|
17754 | 'use strict';
|
17755 |
|
17756 | function getSqDist(p1, p2) {
|
17757 |
|
17758 | var dx = p1.x - p2.x,
|
17759 | dy = p1.y - p2.y;
|
17760 |
|
17761 | return dx * dx + dy * dy;
|
17762 | }
|
17763 |
|
17764 | function getSqSegDist(p, p1, p2) {
|
17765 |
|
17766 | var x = p1.x,
|
17767 | y = p1.y,
|
17768 | dx = p2.x - x,
|
17769 | dy = p2.y - y;
|
17770 |
|
17771 | if (dx !== 0 || dy !== 0) {
|
17772 |
|
17773 | var t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy);
|
17774 |
|
17775 | if (t > 1) {
|
17776 | x = p2.x;
|
17777 | y = p2.y;
|
17778 | } else if (t > 0) {
|
17779 | x += dx * t;
|
17780 | y += dy * t;
|
17781 | }
|
17782 | }
|
17783 |
|
17784 | dx = p.x - x;
|
17785 | dy = p.y - y;
|
17786 |
|
17787 | return dx * dx + dy * dy;
|
17788 | }
|
17789 |
|
17790 | function simplifyRadialDist(points, sqTolerance) {
|
17791 |
|
17792 | var prevPoint = points[0],
|
17793 | newPoints = [prevPoint],
|
17794 | point;
|
17795 |
|
17796 | for (var i = 1, len = points.length; i < len; i++) {
|
17797 | point = points[i];
|
17798 |
|
17799 | if (getSqDist(point, prevPoint) > sqTolerance) {
|
17800 | newPoints.push(point);
|
17801 | prevPoint = point;
|
17802 | }
|
17803 | }
|
17804 |
|
17805 | if (prevPoint !== point) newPoints.push(point);
|
17806 |
|
17807 | return newPoints;
|
17808 | }
|
17809 |
|
17810 | function simplifyDPStep(points, first, last, sqTolerance, simplified) {
|
17811 | var maxSqDist = sqTolerance,
|
17812 | index;
|
17813 |
|
17814 | for (var i = first + 1; i < last; i++) {
|
17815 | var sqDist = getSqSegDist(points[i], points[first], points[last]);
|
17816 |
|
17817 | if (sqDist > maxSqDist) {
|
17818 | index = i;
|
17819 | maxSqDist = sqDist;
|
17820 | }
|
17821 | }
|
17822 |
|
17823 | if (maxSqDist > sqTolerance) {
|
17824 | if (index - first > 1) simplifyDPStep(points, first, index, sqTolerance, simplified);
|
17825 | simplified.push(points[index]);
|
17826 | if (last - index > 1) simplifyDPStep(points, index, last, sqTolerance, simplified);
|
17827 | }
|
17828 | }
|
17829 |
|
17830 | function simplifyDouglasPeucker(points, sqTolerance) {
|
17831 | var last = points.length - 1;
|
17832 |
|
17833 | var simplified = [points[0]];
|
17834 | simplifyDPStep(points, 0, last, sqTolerance, simplified);
|
17835 | simplified.push(points[last]);
|
17836 |
|
17837 | return simplified;
|
17838 | }
|
17839 |
|
17840 | function simplify(points, tolerance, highestQuality) {
|
17841 |
|
17842 | if (points.length <= 2) return points;
|
17843 |
|
17844 | var sqTolerance = tolerance !== undefined ? tolerance * tolerance : 1;
|
17845 |
|
17846 | points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);
|
17847 | points = simplifyDouglasPeucker(points, sqTolerance);
|
17848 |
|
17849 | return points;
|
17850 | }
|
17851 |
|
17852 | if (false) undefined(function () {
|
17853 | return simplify;
|
17854 | });else {
|
17855 | module.exports = simplify;
|
17856 | module.exports.default = simplify;
|
17857 | }
|
17858 | })();
|
17859 | });
|
17860 |
|
17861 | var options$4 = {
|
17862 | 'smoothness': 0,
|
17863 | 'enableClip': true,
|
17864 | 'enableSimplify': true,
|
17865 | 'symbol': {
|
17866 | 'lineColor': '#000',
|
17867 | 'lineWidth': 2,
|
17868 | 'lineOpacity': 1,
|
17869 |
|
17870 | 'polygonFill': '#fff',
|
17871 | 'polygonOpacity': 1,
|
17872 | 'opacity': 1
|
17873 | }
|
17874 | };
|
17875 |
|
17876 | var Path = function (_Geometry) {
|
17877 | inherits(Path, _Geometry);
|
17878 |
|
17879 | function Path() {
|
17880 | classCallCheck(this, Path);
|
17881 | return possibleConstructorReturn(this, _Geometry.apply(this, arguments));
|
17882 | }
|
17883 |
|
17884 | Path.prototype.getOutline = function getOutline() {
|
17885 | var painter = this._getPainter();
|
17886 | if (!painter) {
|
17887 | return null;
|
17888 | }
|
17889 | var map = this.getMap();
|
17890 | var extent = painter.getContainerExtent().convertTo(function (c) {
|
17891 | return map.containerPointToCoord(c);
|
17892 | });
|
17893 | return new Polygon(extent.toArray(), {
|
17894 | symbol: {
|
17895 | 'lineWidth': 1,
|
17896 | 'lineColor': '6b707b'
|
17897 | }
|
17898 | });
|
17899 | };
|
17900 |
|
17901 | Path.prototype.animateShow = function animateShow() {
|
17902 | var _this2 = this;
|
17903 |
|
17904 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
17905 | var cb = arguments[1];
|
17906 |
|
17907 | if (this._showPlayer) {
|
17908 | this._showPlayer.finish();
|
17909 | }
|
17910 | if (isFunction(options)) {
|
17911 | options = {};
|
17912 | cb = options;
|
17913 | }
|
17914 | var coordinates = this.getCoordinates();
|
17915 | if (coordinates.length === 0) {
|
17916 | return this;
|
17917 | }
|
17918 | this._animIdx = 0;
|
17919 | this._animLenSoFar = 0;
|
17920 | this.show();
|
17921 | var isPolygon = !!this.getShell;
|
17922 | var animCoords = isPolygon ? this.getShell().concat(this.getShell()[0]) : this.getCoordinates();
|
17923 | var projection = this._getProjection();
|
17924 | this._aniShowCenter = projection.unproject(this._getPrjExtent().getCenter());
|
17925 | var duration = options['duration'] || 1000,
|
17926 | length = this.getLength(),
|
17927 | easing = options['easing'] || 'out';
|
17928 | this.setCoordinates([]);
|
17929 | var player = this._showPlayer = Animation.animate({
|
17930 | 't': duration
|
17931 | }, {
|
17932 | 'duration': duration,
|
17933 | 'easing': easing
|
17934 | }, function (frame) {
|
17935 | if (!_this2.getMap()) {
|
17936 | if (player.playState !== 'finished') {
|
17937 | player.finish();
|
17938 | if (cb) {
|
17939 | var _coordinates = _this2.getCoordinates();
|
17940 | cb(frame, _coordinates[_coordinates.length - 1]);
|
17941 | }
|
17942 | }
|
17943 | return;
|
17944 | }
|
17945 | var currentCoord = _this2._drawAnimShowFrame(frame.styles.t, duration, length, animCoords);
|
17946 | if (frame.state.playState === 'finished') {
|
17947 | delete _this2._showPlayer;
|
17948 | delete _this2._aniShowCenter;
|
17949 | delete _this2._animIdx;
|
17950 | delete _this2._animLenSoFar;
|
17951 | delete _this2._animTailRatio;
|
17952 | _this2.setCoordinates(coordinates);
|
17953 | }
|
17954 | if (cb) {
|
17955 | cb(frame, currentCoord);
|
17956 | }
|
17957 | });
|
17958 | player.play();
|
17959 | return player;
|
17960 | };
|
17961 |
|
17962 | Path.prototype._drawAnimShowFrame = function _drawAnimShowFrame(t, duration, length, coordinates) {
|
17963 | if (t === 0) {
|
17964 | return coordinates[0];
|
17965 | }
|
17966 | var map = this.getMap();
|
17967 | var targetLength = t / duration * length;
|
17968 | var segLen = 0;
|
17969 | var i = void 0,
|
17970 | l = void 0;
|
17971 | for (i = this._animIdx, l = coordinates.length; i < l - 1; i++) {
|
17972 | segLen = map.computeLength(coordinates[i], coordinates[i + 1]);
|
17973 | if (this._animLenSoFar + segLen > targetLength) {
|
17974 | break;
|
17975 | }
|
17976 | this._animLenSoFar += segLen;
|
17977 | }
|
17978 | this._animIdx = i;
|
17979 | if (this._animIdx >= l - 1) {
|
17980 | this.setCoordinates(coordinates);
|
17981 | return coordinates[coordinates.length - 1];
|
17982 | }
|
17983 | var idx = this._animIdx;
|
17984 | var p1 = coordinates[idx],
|
17985 | p2 = coordinates[idx + 1],
|
17986 | span = targetLength - this._animLenSoFar,
|
17987 | r = span / segLen;
|
17988 | this._animTailRatio = r;
|
17989 | var x = p1.x + (p2.x - p1.x) * r,
|
17990 | y = p1.y + (p2.y - p1.y) * r,
|
17991 | targetCoord = new Coordinate(x, y);
|
17992 | var isPolygon = !!this.getShell;
|
17993 | if (!isPolygon && this.options['smoothness'] > 0) {
|
17994 | var animCoords = coordinates.slice(0, this._animIdx + 3);
|
17995 | this.setCoordinates(animCoords);
|
17996 | } else {
|
17997 | var _animCoords = coordinates.slice(0, this._animIdx + 1);
|
17998 | _animCoords.push(targetCoord);
|
17999 | if (isPolygon) {
|
18000 | this.setCoordinates([this._aniShowCenter].concat(_animCoords));
|
18001 | } else {
|
18002 | this.setCoordinates(_animCoords);
|
18003 | }
|
18004 | }
|
18005 | return targetCoord;
|
18006 | };
|
18007 |
|
18008 | Path.prototype._getCenterInExtent = function _getCenterInExtent(extent, coordinates, clipFn) {
|
18009 | var meExtent = this.getExtent();
|
18010 | if (!extent.intersects(meExtent)) {
|
18011 | return null;
|
18012 | }
|
18013 | var clipped = clipFn(coordinates, extent);
|
18014 | if (clipped.length === 0) {
|
18015 | return null;
|
18016 | }
|
18017 | var sumx = 0,
|
18018 | sumy = 0,
|
18019 | counter = 0;
|
18020 |
|
18021 | clipped.forEach(function (part) {
|
18022 | if (Array.isArray(part)) {
|
18023 | part.forEach(function (c) {
|
18024 | if (c.point) {
|
18025 | c = c.point;
|
18026 | }
|
18027 | sumx += c.x;
|
18028 | sumy += c.y;
|
18029 | counter++;
|
18030 | });
|
18031 | } else {
|
18032 | if (part.point) {
|
18033 | part = part.point;
|
18034 | }
|
18035 | sumx += part.x;
|
18036 | sumy += part.y;
|
18037 | counter++;
|
18038 | }
|
18039 | });
|
18040 | var c = new Coordinate(sumx, sumy)._multi(1 / counter);
|
18041 | c.count = counter;
|
18042 | return c;
|
18043 | };
|
18044 |
|
18045 | Path.prototype._getPath2DPoints = function _getPath2DPoints(prjCoords, disableSimplify, zoom) {
|
18046 | if (!isArrayHasData(prjCoords)) {
|
18047 | return [];
|
18048 | }
|
18049 | var map = this.getMap(),
|
18050 | isSimplify = !disableSimplify && this._shouldSimplify(),
|
18051 | tolerance = 2 * map._getResolution(),
|
18052 | isMulti = Array.isArray(prjCoords[0]);
|
18053 | delete this._simplified;
|
18054 | if (isSimplify && !isMulti) {
|
18055 | var count = prjCoords.length;
|
18056 | prjCoords = simplify(prjCoords, tolerance, false);
|
18057 | this._simplified = prjCoords.length < count;
|
18058 | }
|
18059 | if (isNil(zoom)) {
|
18060 | zoom = map.getZoom();
|
18061 | }
|
18062 | return forEachCoord(prjCoords, function (c) {
|
18063 | return map._prjToPoint(c, zoom);
|
18064 | });
|
18065 | };
|
18066 |
|
18067 | Path.prototype._shouldSimplify = function _shouldSimplify() {
|
18068 | var layer = this.getLayer(),
|
18069 | properties = this.getProperties();
|
18070 | var hasAltitude = properties && layer.options['enableAltitude'] && !isNil(properties[layer.options['altitudeProperty']]);
|
18071 | return layer && layer.options['enableSimplify'] && !hasAltitude && this.options['enableSimplify'];
|
18072 | };
|
18073 |
|
18074 | Path.prototype._setPrjCoordinates = function _setPrjCoordinates(prjPoints) {
|
18075 | this._prjCoords = prjPoints;
|
18076 | this.onShapeChanged();
|
18077 | };
|
18078 |
|
18079 | Path.prototype._getPrjCoordinates = function _getPrjCoordinates() {
|
18080 | var projection = this._getProjection();
|
18081 | if (!projection) {
|
18082 | return null;
|
18083 | }
|
18084 | this._verifyProjection();
|
18085 | if (!this._prjCoords) {
|
18086 | this._prjCoords = this._projectCoords(this._coordinates);
|
18087 | }
|
18088 | return this._prjCoords;
|
18089 | };
|
18090 |
|
18091 | Path.prototype._updateCache = function _updateCache() {
|
18092 | this._clearCache();
|
18093 | var projection = this._getProjection();
|
18094 | if (!projection) {
|
18095 | return;
|
18096 | }
|
18097 | if (this._prjCoords) {
|
18098 | this._coordinates = this._unprojectCoords(this._getPrjCoordinates());
|
18099 | }
|
18100 | };
|
18101 |
|
18102 | Path.prototype._clearProjection = function _clearProjection() {
|
18103 | this._prjCoords = null;
|
18104 | _Geometry.prototype._clearProjection.call(this);
|
18105 | };
|
18106 |
|
18107 | Path.prototype._projectCoords = function _projectCoords(points) {
|
18108 | var projection = this._getProjection();
|
18109 | if (projection) {
|
18110 | return projection.projectCoords(points);
|
18111 | }
|
18112 | return [];
|
18113 | };
|
18114 |
|
18115 | Path.prototype._unprojectCoords = function _unprojectCoords(prjPoints) {
|
18116 | var projection = this._getProjection();
|
18117 | if (projection) {
|
18118 | return projection.unprojectCoords(prjPoints);
|
18119 | }
|
18120 | return [];
|
18121 | };
|
18122 |
|
18123 | Path.prototype._computeCenter = function _computeCenter() {
|
18124 | var ring = this._coordinates;
|
18125 | if (!isArrayHasData(ring)) {
|
18126 | return null;
|
18127 | }
|
18128 | var sumx = 0,
|
18129 | sumy = 0,
|
18130 | counter = 0;
|
18131 | var size = ring.length;
|
18132 | for (var i = 0; i < size; i++) {
|
18133 | if (ring[i]) {
|
18134 | if (isNumber(ring[i].x) && isNumber(ring[i].y)) {
|
18135 | sumx += ring[i].x;
|
18136 | sumy += ring[i].y;
|
18137 | counter++;
|
18138 | }
|
18139 | }
|
18140 | }
|
18141 | return new Coordinate(sumx / counter, sumy / counter);
|
18142 | };
|
18143 |
|
18144 | Path.prototype._computeExtent = function _computeExtent() {
|
18145 | var shell = this._coordinates;
|
18146 | if (!isArrayHasData(shell)) {
|
18147 | return null;
|
18148 | }
|
18149 | var rings = [shell];
|
18150 | if (this.hasHoles && this.hasHoles()) {
|
18151 | rings.push.apply(rings, this.getHoles());
|
18152 | }
|
18153 | return this._coords2Extent(rings, this._getProjection());
|
18154 | };
|
18155 |
|
18156 | Path.prototype._computePrjExtent = function _computePrjExtent() {
|
18157 | var coords = [this._getPrjCoordinates()];
|
18158 | if (this.hasHoles && this.hasHoles()) {
|
18159 | coords.push.apply(coords, this._getPrjHoles());
|
18160 | }
|
18161 | return this._coords2Extent(coords);
|
18162 | };
|
18163 |
|
18164 | Path.prototype._get2DLength = function _get2DLength() {
|
18165 | var vertexes = this._getPath2DPoints(this._getPrjCoordinates(), true);
|
18166 | var len = 0;
|
18167 | for (var i = 1, l = vertexes.length; i < l; i++) {
|
18168 | len += vertexes[i].distanceTo(vertexes[i - 1]);
|
18169 | }
|
18170 | return len;
|
18171 | };
|
18172 |
|
18173 | Path.prototype._hitTestTolerance = function _hitTestTolerance() {
|
18174 | var symbol = this._getInternalSymbol();
|
18175 | var w = void 0;
|
18176 | if (Array.isArray(symbol)) {
|
18177 | w = 0;
|
18178 | for (var i = 0; i < symbol.length; i++) {
|
18179 | if (isNumber(symbol[i]['lineWidth'])) {
|
18180 | if (symbol[i]['lineWidth'] > w) {
|
18181 | w = symbol[i]['lineWidth'];
|
18182 | }
|
18183 | }
|
18184 | }
|
18185 | } else {
|
18186 | w = symbol['lineWidth'];
|
18187 | }
|
18188 | return isNumber(w) ? w / 2 : 1.5;
|
18189 | };
|
18190 |
|
18191 | Path.prototype._coords2Extent = function _coords2Extent(coords, proj) {
|
18192 | var result = new Extent(proj);
|
18193 | for (var i = 0, l = coords.length; i < l; i++) {
|
18194 | for (var j = 0, ll = coords[i].length; j < ll; j++) {
|
18195 | result._combine(coords[i][j]);
|
18196 | }
|
18197 | }
|
18198 | return result;
|
18199 | };
|
18200 |
|
18201 | return Path;
|
18202 | }(Geometry);
|
18203 |
|
18204 | Path.mergeOptions(options$4);
|
18205 |
|
18206 | var JSON_TYPE = 'Polygon';
|
18207 |
|
18208 | var Polygon = function (_Path) {
|
18209 | inherits(Polygon, _Path);
|
18210 |
|
18211 | function Polygon(coordinates, opts) {
|
18212 | classCallCheck(this, Polygon);
|
18213 |
|
18214 | var _this = possibleConstructorReturn(this, _Path.call(this, opts));
|
18215 |
|
18216 | _this.type = 'Polygon';
|
18217 | if (coordinates) {
|
18218 | _this.setCoordinates(coordinates);
|
18219 | }
|
18220 | return _this;
|
18221 | }
|
18222 |
|
18223 | Polygon.prototype.setCoordinates = function setCoordinates(coordinates) {
|
18224 | if (!coordinates) {
|
18225 | this._coordinates = null;
|
18226 | this._holes = null;
|
18227 | this._projectRings();
|
18228 | return this;
|
18229 | }
|
18230 | var rings = Coordinate.toCoordinates(coordinates);
|
18231 | var len = rings.length;
|
18232 | if (!Array.isArray(rings[0])) {
|
18233 | this._coordinates = this._trimRing(rings);
|
18234 | } else {
|
18235 | this._coordinates = this._trimRing(rings[0]);
|
18236 | if (len > 1) {
|
18237 | var holes = [];
|
18238 | for (var i = 1; i < len; i++) {
|
18239 | if (!rings[i]) {
|
18240 | continue;
|
18241 | }
|
18242 | holes.push(this._trimRing(rings[i]));
|
18243 | }
|
18244 | this._holes = holes;
|
18245 | }
|
18246 | }
|
18247 |
|
18248 | this._projectRings();
|
18249 | return this;
|
18250 | };
|
18251 |
|
18252 | Polygon.prototype.getCoordinates = function getCoordinates() {
|
18253 | if (!this._coordinates) {
|
18254 | return [];
|
18255 | }
|
18256 | var holes = this.getHoles();
|
18257 | var rings = [this._copyAndCloseRing(this._coordinates)];
|
18258 | for (var i = 0, l = holes.length; i < l; i++) {
|
18259 | rings.push(this._copyAndCloseRing(holes[i]));
|
18260 | }
|
18261 | return rings;
|
18262 | };
|
18263 |
|
18264 | Polygon.prototype.getCenterInExtent = function getCenterInExtent(extent) {
|
18265 | return this._getCenterInExtent(extent, this.getShell(), clipPolygon);
|
18266 | };
|
18267 |
|
18268 | Polygon.prototype.getShell = function getShell() {
|
18269 | return this._coordinates || [];
|
18270 | };
|
18271 |
|
18272 | Polygon.prototype.getHoles = function getHoles() {
|
18273 | return this._holes || [];
|
18274 | };
|
18275 |
|
18276 | Polygon.prototype.hasHoles = function hasHoles() {
|
18277 | return this.getHoles().length > 0;
|
18278 | };
|
18279 |
|
18280 | Polygon.prototype._projectRings = function _projectRings() {
|
18281 | if (!this.getMap()) {
|
18282 | this.onShapeChanged();
|
18283 | return;
|
18284 | }
|
18285 | this._prjCoords = this._projectCoords(this._coordinates);
|
18286 | this._prjHoles = this._projectCoords(this._holes);
|
18287 | this.onShapeChanged();
|
18288 | };
|
18289 |
|
18290 | Polygon.prototype._cleanRing = function _cleanRing(ring) {
|
18291 | for (var i = ring.length - 1; i >= 0; i--) {
|
18292 | if (!ring[i]) {
|
18293 | ring.splice(i, 1);
|
18294 | }
|
18295 | }
|
18296 | };
|
18297 |
|
18298 | Polygon.prototype._checkRing = function _checkRing(ring) {
|
18299 | this._cleanRing(ring);
|
18300 | if (!ring || !isArrayHasData(ring)) {
|
18301 | return false;
|
18302 | }
|
18303 | var lastPoint = ring[ring.length - 1];
|
18304 | var isClose = true;
|
18305 | if (ring[0].x !== lastPoint.x || ring[0].y !== lastPoint.y) {
|
18306 | isClose = false;
|
18307 | }
|
18308 | return isClose;
|
18309 | };
|
18310 |
|
18311 | Polygon.prototype._trimRing = function _trimRing(ring) {
|
18312 | var isClose = this._checkRing(ring);
|
18313 | if (isArrayHasData(ring) && isClose) {
|
18314 | ring.splice(ring.length - 1, 1);
|
18315 | }
|
18316 | return ring;
|
18317 | };
|
18318 |
|
18319 | Polygon.prototype._copyAndCloseRing = function _copyAndCloseRing(ring) {
|
18320 | ring = ring.slice(0);
|
18321 | var isClose = this._checkRing(ring);
|
18322 | if (isArrayHasData(ring) && !isClose) {
|
18323 | ring.push(ring[0].copy());
|
18324 | return ring;
|
18325 | } else {
|
18326 | return ring;
|
18327 | }
|
18328 | };
|
18329 |
|
18330 | Polygon.prototype._getPrjShell = function _getPrjShell() {
|
18331 | if (this.getJSONType() === JSON_TYPE) {
|
18332 | return this._getPrjCoordinates();
|
18333 | }
|
18334 | var projection = this._getProjection();
|
18335 | if (!projection) {
|
18336 | return null;
|
18337 | }
|
18338 | this._verifyProjection();
|
18339 | if (!this._prjShell) {
|
18340 | this._prjShell = this._projectCoords(this.getShell());
|
18341 | }
|
18342 | return this._prjShell;
|
18343 | };
|
18344 |
|
18345 | Polygon.prototype._getPrjHoles = function _getPrjHoles() {
|
18346 | var projection = this._getProjection();
|
18347 | if (!projection) {
|
18348 | return null;
|
18349 | }
|
18350 | this._verifyProjection();
|
18351 | if (!this._prjHoles) {
|
18352 | this._prjHoles = this._projectCoords(this.getHoles());
|
18353 | }
|
18354 | return this._prjHoles;
|
18355 | };
|
18356 |
|
18357 | Polygon.prototype._computeGeodesicLength = function _computeGeodesicLength(measurer) {
|
18358 | var rings = this.getCoordinates();
|
18359 | if (!isArrayHasData(rings)) {
|
18360 | return 0;
|
18361 | }
|
18362 | var result = 0;
|
18363 | for (var i = 0, len = rings.length; i < len; i++) {
|
18364 | result += measurer.measureLength(rings[i]);
|
18365 | }
|
18366 | return result;
|
18367 | };
|
18368 |
|
18369 | Polygon.prototype._computeGeodesicArea = function _computeGeodesicArea(measurer) {
|
18370 | var rings = this.getCoordinates();
|
18371 | if (!isArrayHasData(rings)) {
|
18372 | return 0;
|
18373 | }
|
18374 | var result = measurer.measureArea(rings[0]);
|
18375 |
|
18376 | for (var i = 1, len = rings.length; i < len; i++) {
|
18377 | result -= measurer.measureArea(rings[i]);
|
18378 | }
|
18379 | return result;
|
18380 | };
|
18381 |
|
18382 | Polygon.prototype._updateCache = function _updateCache() {
|
18383 | _Path.prototype._updateCache.call(this);
|
18384 | if (this._prjHoles) {
|
18385 | this._holes = this._unprojectCoords(this._getPrjHoles());
|
18386 | }
|
18387 | };
|
18388 |
|
18389 | Polygon.prototype._clearCache = function _clearCache() {
|
18390 | delete this._prjShell;
|
18391 | return _Path.prototype._clearCache.call(this);
|
18392 | };
|
18393 |
|
18394 | Polygon.prototype._clearProjection = function _clearProjection() {
|
18395 | if (this._prjHoles) {
|
18396 | this._prjHoles = null;
|
18397 | }
|
18398 | if (this._prjShell) {
|
18399 | this._prjShell = null;
|
18400 | }
|
18401 | _Path.prototype._clearProjection.call(this);
|
18402 | };
|
18403 |
|
18404 | return Polygon;
|
18405 | }(Path);
|
18406 |
|
18407 | Polygon.registerJSONType(JSON_TYPE);
|
18408 |
|
18409 | var CenterMixin = function (Base) {
|
18410 | return function (_Base) {
|
18411 | inherits(_class, _Base);
|
18412 |
|
18413 | function _class() {
|
18414 | classCallCheck(this, _class);
|
18415 | return possibleConstructorReturn(this, _Base.apply(this, arguments));
|
18416 | }
|
18417 |
|
18418 | _class.prototype.getCoordinates = function getCoordinates() {
|
18419 | return this._coordinates;
|
18420 | };
|
18421 |
|
18422 | _class.prototype.setCoordinates = function setCoordinates(coordinates) {
|
18423 | var center = coordinates instanceof Coordinate ? coordinates : new Coordinate(coordinates);
|
18424 | if (center.equals(this._coordinates)) {
|
18425 | return this;
|
18426 | }
|
18427 | this._coordinates = center;
|
18428 | if (!this.getMap()) {
|
18429 | this.onPositionChanged();
|
18430 | return this;
|
18431 | }
|
18432 | var projection = this._getProjection();
|
18433 | this._setPrjCoordinates(projection.project(this._coordinates));
|
18434 | return this;
|
18435 | };
|
18436 |
|
18437 | _class.prototype._getCenter2DPoint = function _getCenter2DPoint(zoom) {
|
18438 | var map = this.getMap();
|
18439 | if (!map) {
|
18440 | return null;
|
18441 | }
|
18442 | var z = isNil(zoom) ? map.getZoom() : map.getGLZoom();
|
18443 | var pcenter = this._getPrjCoordinates();
|
18444 | if (!pcenter) {
|
18445 | return null;
|
18446 | }
|
18447 |
|
18448 | return map._prjToPoint(pcenter, z);
|
18449 | };
|
18450 |
|
18451 | _class.prototype._getPrjCoordinates = function _getPrjCoordinates() {
|
18452 | var projection = this._getProjection();
|
18453 | if (!projection) {
|
18454 | return null;
|
18455 | }
|
18456 | this._verifyProjection();
|
18457 | if (!this._pcenter) {
|
18458 | if (this._coordinates) {
|
18459 | this._pcenter = projection.project(this._coordinates);
|
18460 | }
|
18461 | }
|
18462 | return this._pcenter;
|
18463 | };
|
18464 |
|
18465 | _class.prototype._setPrjCoordinates = function _setPrjCoordinates(pcenter) {
|
18466 | this._pcenter = pcenter;
|
18467 | this.onPositionChanged();
|
18468 | };
|
18469 |
|
18470 | _class.prototype._updateCache = function _updateCache() {
|
18471 | this._clearCache();
|
18472 | var projection = this._getProjection();
|
18473 | if (this._pcenter && projection) {
|
18474 | this._coordinates = projection.unproject(this._pcenter);
|
18475 | }
|
18476 | };
|
18477 |
|
18478 | _class.prototype._clearProjection = function _clearProjection() {
|
18479 | this._pcenter = null;
|
18480 | _Base.prototype._clearProjection.call(this);
|
18481 | };
|
18482 |
|
18483 | _class.prototype._computeCenter = function _computeCenter() {
|
18484 | return this._coordinates ? this._coordinates.copy() : null;
|
18485 | };
|
18486 |
|
18487 | return _class;
|
18488 | }(Base);
|
18489 | };
|
18490 |
|
18491 | var options$7 = {
|
18492 | 'symbol': {
|
18493 | 'markerType': 'path',
|
18494 | 'markerPath': [{
|
18495 | 'path': 'M8 23l0 0 0 0 0 0 0 0 0 0c-4,-5 -8,-10 -8,-14 0,-5 4,-9 8,-9l0 0 0 0c4,0 8,4 8,9 0,4 -4,9 -8,14z M3,9 a5,5 0,1,0,0,-0.9Z',
|
18496 | 'fill': '#DE3333'
|
18497 | }],
|
18498 | 'markerPathWidth': 16,
|
18499 | 'markerPathHeight': 23,
|
18500 | 'markerWidth': 24,
|
18501 | 'markerHeight': 34
|
18502 | },
|
18503 | 'hitTestForEvent': false
|
18504 | };
|
18505 |
|
18506 | var Marker = function (_CenterMixin) {
|
18507 | inherits(Marker, _CenterMixin);
|
18508 |
|
18509 | function Marker(coordinates, opts) {
|
18510 | classCallCheck(this, Marker);
|
18511 |
|
18512 | var _this = possibleConstructorReturn(this, _CenterMixin.call(this, opts));
|
18513 |
|
18514 | _this.type = 'Point';
|
18515 | if (coordinates) {
|
18516 | _this.setCoordinates(coordinates);
|
18517 | }
|
18518 | return _this;
|
18519 | }
|
18520 |
|
18521 | Marker.prototype.getOutline = function getOutline() {
|
18522 | var painter = this._getPainter();
|
18523 | if (!painter) {
|
18524 | return null;
|
18525 | }
|
18526 | var coord = this.getCoordinates();
|
18527 | var extent = painter.getContainerExtent();
|
18528 | var anchor = this.getMap().coordToContainerPoint(coord);
|
18529 | return new Marker(coord, {
|
18530 | 'symbol': {
|
18531 | 'markerType': 'square',
|
18532 | 'markerWidth': extent.getWidth(),
|
18533 | 'markerHeight': extent.getHeight(),
|
18534 | 'markerLineWidth': 1,
|
18535 | 'markerLineColor': '6b707b',
|
18536 | 'markerFill': 'rgba(0, 0, 0, 0)',
|
18537 | 'markerDx': extent.xmin - (anchor.x - extent.getWidth() / 2),
|
18538 | 'markerDy': extent.ymin - (anchor.y - extent.getHeight() / 2)
|
18539 | }
|
18540 | });
|
18541 | };
|
18542 |
|
18543 | Marker.prototype._isVectorMarker = function _isVectorMarker() {
|
18544 | var symbol = this._getInternalSymbol();
|
18545 | if (Array.isArray(symbol)) {
|
18546 | return false;
|
18547 | }
|
18548 | return VectorMarkerSymbolizer.test(symbol);
|
18549 | };
|
18550 |
|
18551 | Marker.prototype._canEdit = function _canEdit() {
|
18552 | var symbol = this._getInternalSymbol();
|
18553 | if (Array.isArray(symbol)) {
|
18554 | return false;
|
18555 | }
|
18556 | return VectorMarkerSymbolizer.test(symbol) || VectorPathMarkerSymbolizer.test(symbol) || ImageMarkerSymbolizer.test(symbol);
|
18557 | };
|
18558 |
|
18559 | Marker.prototype._containsPoint = function _containsPoint(point, t) {
|
18560 | var extent = this.getContainerExtent();
|
18561 | if (t) {
|
18562 | extent = extent.expand(t);
|
18563 | }
|
18564 | if (extent.contains(point)) {
|
18565 | if (this.options['hitTestForEvent']) {
|
18566 | return _CenterMixin.prototype._containsPoint.call(this, point, t);
|
18567 | } else {
|
18568 | return true;
|
18569 | }
|
18570 | } else {
|
18571 | return false;
|
18572 | }
|
18573 | };
|
18574 |
|
18575 | Marker.prototype._computeExtent = function _computeExtent() {
|
18576 | return computeExtent.call(this, 'getCenter');
|
18577 | };
|
18578 |
|
18579 | Marker.prototype._computePrjExtent = function _computePrjExtent() {
|
18580 | return computeExtent.call(this, '_getPrjCoordinates');
|
18581 | };
|
18582 |
|
18583 | Marker.prototype._computeGeodesicLength = function _computeGeodesicLength() {
|
18584 | return 0;
|
18585 | };
|
18586 |
|
18587 | Marker.prototype._computeGeodesicArea = function _computeGeodesicArea() {
|
18588 | return 0;
|
18589 | };
|
18590 |
|
18591 | Marker.prototype._getSprite = function _getSprite(resources, canvasClass) {
|
18592 | if (this._getPainter()) {
|
18593 | return this._getPainter().getSprite(resources, canvasClass);
|
18594 | }
|
18595 | return new Painter(this).getSprite(resources, canvasClass);
|
18596 | };
|
18597 |
|
18598 | return Marker;
|
18599 | }(CenterMixin(Geometry));
|
18600 |
|
18601 | Marker.mergeOptions(options$7);
|
18602 |
|
18603 | Marker.registerJSONType('Marker');
|
18604 |
|
18605 | function computeExtent(fn) {
|
18606 | var coordinates = this[fn]();
|
18607 | if (!coordinates) {
|
18608 | return null;
|
18609 | }
|
18610 | return new Extent(coordinates, coordinates, this._getProjection());
|
18611 | }
|
18612 |
|
18613 | var options$8 = {
|
18614 | 'arrowStyle': null,
|
18615 | 'arrowPlacement': 'vertex-last' };
|
18616 |
|
18617 | var LineString = function (_Path) {
|
18618 | inherits(LineString, _Path);
|
18619 |
|
18620 | function LineString(coordinates, options) {
|
18621 | classCallCheck(this, LineString);
|
18622 |
|
18623 | var _this = possibleConstructorReturn(this, _Path.call(this, options));
|
18624 |
|
18625 | _this.type = 'LineString';
|
18626 | if (coordinates) {
|
18627 | _this.setCoordinates(coordinates);
|
18628 | }
|
18629 | return _this;
|
18630 | }
|
18631 |
|
18632 | LineString.prototype.setCoordinates = function setCoordinates(coordinates) {
|
18633 | if (!coordinates) {
|
18634 | this._coordinates = null;
|
18635 | this._setPrjCoordinates(null);
|
18636 | return this;
|
18637 | }
|
18638 | this._coordinates = Coordinate.toCoordinates(coordinates);
|
18639 | if (this.getMap()) {
|
18640 | this._setPrjCoordinates(this._projectCoords(this._coordinates));
|
18641 | } else {
|
18642 | this.onShapeChanged();
|
18643 | }
|
18644 | return this;
|
18645 | };
|
18646 |
|
18647 | LineString.prototype.getCoordinates = function getCoordinates() {
|
18648 | return this._coordinates || [];
|
18649 | };
|
18650 |
|
18651 | LineString.prototype.getCenterInExtent = function getCenterInExtent(extent) {
|
18652 | return this._getCenterInExtent(extent, this.getCoordinates(), clipLine);
|
18653 | };
|
18654 |
|
18655 | LineString.prototype._computeGeodesicLength = function _computeGeodesicLength(measurer) {
|
18656 | return measurer.measureLength(this.getCoordinates());
|
18657 | };
|
18658 |
|
18659 | LineString.prototype._computeGeodesicArea = function _computeGeodesicArea() {
|
18660 | return 0;
|
18661 | };
|
18662 |
|
18663 | return LineString;
|
18664 | }(Path);
|
18665 |
|
18666 | LineString.mergeOptions(options$8);
|
18667 |
|
18668 | LineString.registerJSONType('LineString');
|
18669 |
|
18670 | var GeometryCollection = function (_Geometry) {
|
18671 | inherits(GeometryCollection, _Geometry);
|
18672 |
|
18673 | function GeometryCollection(geometries, opts) {
|
18674 | classCallCheck(this, GeometryCollection);
|
18675 |
|
18676 | var _this = possibleConstructorReturn(this, _Geometry.call(this, opts));
|
18677 |
|
18678 | _this.type = 'GeometryCollection';
|
18679 | _this.setGeometries(geometries);
|
18680 | return _this;
|
18681 | }
|
18682 |
|
18683 | GeometryCollection.prototype.setGeometries = function setGeometries(_geometries) {
|
18684 | var geometries = this._checkGeometries(_geometries || []);
|
18685 | var symbol = this._getSymbol();
|
18686 | var options = this.config();
|
18687 |
|
18688 | for (var i = geometries.length - 1; i >= 0; i--) {
|
18689 | geometries[i]._initOptions(options);
|
18690 | geometries[i]._setParent(this);
|
18691 | geometries[i]._setEventParent(this);
|
18692 | if (symbol) {
|
18693 | geometries[i].setSymbol(symbol);
|
18694 | }
|
18695 | }
|
18696 | this._geometries = geometries;
|
18697 | if (this.getLayer()) {
|
18698 | this._bindGeometriesToLayer();
|
18699 | this.onShapeChanged();
|
18700 | }
|
18701 | return this;
|
18702 | };
|
18703 |
|
18704 | GeometryCollection.prototype.getGeometries = function getGeometries() {
|
18705 | return this._geometries || [];
|
18706 | };
|
18707 |
|
18708 | GeometryCollection.prototype.forEach = function forEach(fn, context) {
|
18709 | var geometries = this.getGeometries();
|
18710 | for (var i = 0, l = geometries.length; i < l; i++) {
|
18711 | if (!geometries[i]) {
|
18712 | continue;
|
18713 | }
|
18714 | if (!context) {
|
18715 | fn(geometries[i], i);
|
18716 | } else {
|
18717 | fn.call(context, geometries[i], i);
|
18718 | }
|
18719 | }
|
18720 | return this;
|
18721 | };
|
18722 |
|
18723 | GeometryCollection.prototype.filter = function filter(fn, context) {
|
18724 | if (!fn) {
|
18725 | return new GeometryCollection();
|
18726 | }
|
18727 | var selected = [];
|
18728 | var isFn = isFunction(fn);
|
18729 | var filter = isFn ? fn : createFilter(fn);
|
18730 |
|
18731 | this.forEach(function (geometry) {
|
18732 | var g = isFn ? geometry : getFilterFeature(geometry);
|
18733 | if (context ? filter.call(context, g) : filter(g)) {
|
18734 | selected.push(geometry);
|
18735 | }
|
18736 | }, this);
|
18737 |
|
18738 | return new GeometryCollection(selected);
|
18739 | };
|
18740 |
|
18741 | GeometryCollection.prototype.translate = function translate(offset) {
|
18742 | if (!offset) {
|
18743 | return this;
|
18744 | }
|
18745 | if (this.isEmpty()) {
|
18746 | return this;
|
18747 | }
|
18748 | var args = arguments;
|
18749 | this.forEach(function (geometry) {
|
18750 | if (geometry && geometry.translate) {
|
18751 | geometry.translate.apply(geometry, args);
|
18752 | }
|
18753 | });
|
18754 | return this;
|
18755 | };
|
18756 |
|
18757 | GeometryCollection.prototype.isEmpty = function isEmpty() {
|
18758 | return !isArrayHasData(this.getGeometries());
|
18759 | };
|
18760 |
|
18761 | GeometryCollection.prototype.remove = function remove() {
|
18762 | this.forEach(function (geometry) {
|
18763 | geometry._unbind();
|
18764 | });
|
18765 | return Geometry.prototype.remove.apply(this, arguments);
|
18766 | };
|
18767 |
|
18768 | GeometryCollection.prototype.show = function show() {
|
18769 | this.options['visible'] = true;
|
18770 | this.forEach(function (geometry) {
|
18771 | geometry.show();
|
18772 | });
|
18773 | return this;
|
18774 | };
|
18775 |
|
18776 | GeometryCollection.prototype.hide = function hide() {
|
18777 | this.options['visible'] = false;
|
18778 | this.forEach(function (geometry) {
|
18779 | geometry.hide();
|
18780 | });
|
18781 | return this;
|
18782 | };
|
18783 |
|
18784 | GeometryCollection.prototype.onConfig = function onConfig(config) {
|
18785 | this.forEach(function (geometry) {
|
18786 | geometry.config(config);
|
18787 | });
|
18788 | };
|
18789 |
|
18790 | GeometryCollection.prototype.getSymbol = function getSymbol() {
|
18791 | var s = _Geometry.prototype.getSymbol.call(this);
|
18792 | if (!s) {
|
18793 | var symbols = [];
|
18794 | var is = false;
|
18795 | this.forEach(function (g) {
|
18796 | var symbol = g.getSymbol();
|
18797 | if (symbol && !is) {
|
18798 | is = true;
|
18799 | }
|
18800 | symbols.push(g.getSymbol());
|
18801 | });
|
18802 | if (is) {
|
18803 | s = {
|
18804 | 'children': symbols
|
18805 | };
|
18806 | }
|
18807 | }
|
18808 | return s;
|
18809 | };
|
18810 |
|
18811 | GeometryCollection.prototype.setSymbol = function setSymbol(s) {
|
18812 | if (s && s['children']) {
|
18813 | this._symbol = null;
|
18814 | this.forEach(function (g, i) {
|
18815 | g.setSymbol(s['children'][i]);
|
18816 | });
|
18817 | } else {
|
18818 | var symbol = this._prepareSymbol(s);
|
18819 | this._symbol = symbol;
|
18820 | this.forEach(function (g) {
|
18821 | g.setSymbol(symbol);
|
18822 | });
|
18823 | }
|
18824 | this.onSymbolChanged();
|
18825 | return this;
|
18826 | };
|
18827 |
|
18828 | GeometryCollection.prototype._setExternSymbol = function _setExternSymbol(symbol) {
|
18829 | symbol = this._prepareSymbol(symbol);
|
18830 | this._externSymbol = symbol;
|
18831 | this.forEach(function (geometry) {
|
18832 | geometry._setExternSymbol(symbol);
|
18833 | });
|
18834 | this.onSymbolChanged();
|
18835 | return this;
|
18836 | };
|
18837 |
|
18838 | GeometryCollection.prototype._bindLayer = function _bindLayer() {
|
18839 | _Geometry.prototype._bindLayer.apply(this, arguments);
|
18840 | this._bindGeometriesToLayer();
|
18841 | };
|
18842 |
|
18843 | GeometryCollection.prototype._bindGeometriesToLayer = function _bindGeometriesToLayer() {
|
18844 | var layer = this.getLayer();
|
18845 | this.forEach(function (geometry) {
|
18846 | geometry._bindLayer(layer);
|
18847 | });
|
18848 | };
|
18849 |
|
18850 | GeometryCollection.prototype._checkGeometries = function _checkGeometries(geometries) {
|
18851 | var invalidGeoError = 'The geometry added to collection is invalid.';
|
18852 | if (geometries && !Array.isArray(geometries)) {
|
18853 | if (geometries instanceof Geometry) {
|
18854 | return [geometries];
|
18855 | } else {
|
18856 | throw new Error(invalidGeoError);
|
18857 | }
|
18858 | } else {
|
18859 | for (var i = 0, l = geometries.length; i < l; i++) {
|
18860 | if (!this._checkGeo(geometries[i])) {
|
18861 | throw new Error(invalidGeoError + ' Index: ' + i);
|
18862 | }
|
18863 | }
|
18864 | return geometries;
|
18865 | }
|
18866 | };
|
18867 |
|
18868 | GeometryCollection.prototype._checkGeo = function _checkGeo(geo) {
|
18869 | return geo instanceof Geometry;
|
18870 | };
|
18871 |
|
18872 | GeometryCollection.prototype._updateCache = function _updateCache() {
|
18873 | this._clearCache();
|
18874 | if (this.isEmpty()) {
|
18875 | return;
|
18876 | }
|
18877 | this.forEach(function (geometry) {
|
18878 | if (geometry && geometry._updateCache) {
|
18879 | geometry._updateCache();
|
18880 | }
|
18881 | });
|
18882 | };
|
18883 |
|
18884 | GeometryCollection.prototype._removePainter = function _removePainter() {
|
18885 | if (this._painter) {
|
18886 | this._painter.remove();
|
18887 | }
|
18888 | delete this._painter;
|
18889 | this.forEach(function (geometry) {
|
18890 | geometry._removePainter();
|
18891 | });
|
18892 | };
|
18893 |
|
18894 | GeometryCollection.prototype._computeCenter = function _computeCenter(projection) {
|
18895 | if (!projection || this.isEmpty()) {
|
18896 | return null;
|
18897 | }
|
18898 | var sumX = 0,
|
18899 | sumY = 0,
|
18900 | counter = 0;
|
18901 | var geometries = this.getGeometries();
|
18902 | for (var i = 0, l = geometries.length; i < l; i++) {
|
18903 | if (!geometries[i]) {
|
18904 | continue;
|
18905 | }
|
18906 | var center = geometries[i]._computeCenter(projection);
|
18907 | if (center) {
|
18908 | sumX += center.x;
|
18909 | sumY += center.y;
|
18910 | counter++;
|
18911 | }
|
18912 | }
|
18913 | if (counter === 0) {
|
18914 | return null;
|
18915 | }
|
18916 | return new Coordinate(sumX / counter, sumY / counter);
|
18917 | };
|
18918 |
|
18919 | GeometryCollection.prototype._containsPoint = function _containsPoint(point, t) {
|
18920 | if (this.isEmpty()) {
|
18921 | return false;
|
18922 | }
|
18923 | var geometries = this.getGeometries();
|
18924 | for (var i = 0, l = geometries.length; i < l; i++) {
|
18925 | if (geometries[i]._containsPoint(point, t)) {
|
18926 | return true;
|
18927 | }
|
18928 | }
|
18929 | return false;
|
18930 | };
|
18931 |
|
18932 | GeometryCollection.prototype._computeExtent = function _computeExtent(projection) {
|
18933 | return computeExtent$1.call(this, projection, '_computeExtent');
|
18934 | };
|
18935 |
|
18936 | GeometryCollection.prototype._computePrjExtent = function _computePrjExtent(projection) {
|
18937 | return computeExtent$1.call(this, projection, '_computePrjExtent');
|
18938 | };
|
18939 |
|
18940 | GeometryCollection.prototype._computeGeodesicLength = function _computeGeodesicLength(projection) {
|
18941 | if (!projection || this.isEmpty()) {
|
18942 | return 0;
|
18943 | }
|
18944 | var geometries = this.getGeometries();
|
18945 | var result = 0;
|
18946 | for (var i = 0, l = geometries.length; i < l; i++) {
|
18947 | if (!geometries[i]) {
|
18948 | continue;
|
18949 | }
|
18950 | result += geometries[i]._computeGeodesicLength(projection);
|
18951 | }
|
18952 | return result;
|
18953 | };
|
18954 |
|
18955 | GeometryCollection.prototype._computeGeodesicArea = function _computeGeodesicArea(projection) {
|
18956 | if (!projection || this.isEmpty()) {
|
18957 | return 0;
|
18958 | }
|
18959 | var geometries = this.getGeometries();
|
18960 | var result = 0;
|
18961 | for (var i = 0, l = geometries.length; i < l; i++) {
|
18962 | if (!geometries[i]) {
|
18963 | continue;
|
18964 | }
|
18965 | result += geometries[i]._computeGeodesicArea(projection);
|
18966 | }
|
18967 | return result;
|
18968 | };
|
18969 |
|
18970 | GeometryCollection.prototype._exportGeoJSONGeometry = function _exportGeoJSONGeometry() {
|
18971 | var children = [];
|
18972 | if (!this.isEmpty()) {
|
18973 | var geometries = this.getGeometries();
|
18974 | for (var i = 0, l = geometries.length; i < l; i++) {
|
18975 | if (!geometries[i]) {
|
18976 | continue;
|
18977 | }
|
18978 | children.push(geometries[i]._exportGeoJSONGeometry());
|
18979 | }
|
18980 | }
|
18981 | return {
|
18982 | 'type': 'GeometryCollection',
|
18983 | 'geometries': children
|
18984 | };
|
18985 | };
|
18986 |
|
18987 | GeometryCollection.prototype._clearProjection = function _clearProjection() {
|
18988 | if (this.isEmpty()) {
|
18989 | return;
|
18990 | }
|
18991 | var geometries = this.getGeometries();
|
18992 | for (var i = 0, l = geometries.length; i < l; i++) {
|
18993 | if (!geometries[i]) {
|
18994 | continue;
|
18995 | }
|
18996 | geometries[i]._clearProjection();
|
18997 | }
|
18998 | };
|
18999 |
|
19000 | GeometryCollection.prototype._getConnectPoints = function _getConnectPoints() {
|
19001 | var extent = this.getExtent();
|
19002 | var anchors = [new Coordinate(extent.xmin, extent.ymax), new Coordinate(extent.xmax, extent.ymin), new Coordinate(extent.xmin, extent.ymin), new Coordinate(extent.xmax, extent.ymax)];
|
19003 | return anchors;
|
19004 | };
|
19005 |
|
19006 | GeometryCollection.prototype._getExternalResources = function _getExternalResources() {
|
19007 | if (this.isEmpty()) {
|
19008 | return [];
|
19009 | }
|
19010 | var geometries = this.getGeometries(),
|
19011 | resources = [];
|
19012 | var cache = {};
|
19013 | var symbol = void 0,
|
19014 | res = void 0,
|
19015 | key = void 0;
|
19016 | for (var i = 0, l = geometries.length; i < l; i++) {
|
19017 | if (!geometries[i]) {
|
19018 | continue;
|
19019 | }
|
19020 | symbol = geometries[i]._getInternalSymbol();
|
19021 | res = getExternalResources(symbol);
|
19022 | for (var ii = 0, ll = res.length; ii < ll; ii++) {
|
19023 | key = res[ii].join();
|
19024 | if (!cache[key]) {
|
19025 | resources.push(res[ii]);
|
19026 | cache[key] = 1;
|
19027 | }
|
19028 | }
|
19029 | }
|
19030 | return resources;
|
19031 | };
|
19032 |
|
19033 | GeometryCollection.prototype.startEdit = function startEdit(opts) {
|
19034 | var _this2 = this;
|
19035 |
|
19036 | if (this.isEmpty()) {
|
19037 | return this;
|
19038 | }
|
19039 | if (!opts) {
|
19040 | opts = {};
|
19041 | }
|
19042 | if (opts['symbol']) {
|
19043 | this._originalSymbol = this.getSymbol();
|
19044 | this.setSymbol(opts['symbol']);
|
19045 | }
|
19046 | this._draggbleBeforeEdit = this.options['draggable'];
|
19047 | this.config('draggable', false);
|
19048 | var geometries = this.getGeometries();
|
19049 | for (var i = 0, l = geometries.length; i < l; i++) {
|
19050 | geometries[i].startEdit(opts);
|
19051 | }
|
19052 | this._editing = true;
|
19053 | this.hide();
|
19054 | setTimeout(function () {
|
19055 | _this2.fire('editstart');
|
19056 | }, 1);
|
19057 | return this;
|
19058 | };
|
19059 |
|
19060 | GeometryCollection.prototype.endEdit = function endEdit() {
|
19061 | if (this.isEmpty()) {
|
19062 | return this;
|
19063 | }
|
19064 | var geometries = this.getGeometries();
|
19065 | for (var i = 0, l = geometries.length; i < l; i++) {
|
19066 | geometries[i].endEdit();
|
19067 | }
|
19068 | if (this._originalSymbol) {
|
19069 | this.setSymbol(this._originalSymbol);
|
19070 | delete this._originalSymbol;
|
19071 | }
|
19072 | this._editing = false;
|
19073 | this.show();
|
19074 | this.config('draggable', this._draggbleBeforeEdit);
|
19075 | this.fire('editend');
|
19076 | return this;
|
19077 | };
|
19078 |
|
19079 | GeometryCollection.prototype.isEditing = function isEditing() {
|
19080 | if (!this._editing) {
|
19081 | return false;
|
19082 | }
|
19083 | return true;
|
19084 | };
|
19085 |
|
19086 | return GeometryCollection;
|
19087 | }(Geometry);
|
19088 |
|
19089 | GeometryCollection.registerJSONType('GeometryCollection');
|
19090 |
|
19091 | function computeExtent$1(projection, fn) {
|
19092 | if (this.isEmpty()) {
|
19093 | return null;
|
19094 | }
|
19095 | var geometries = this.getGeometries();
|
19096 | var result = null;
|
19097 | for (var i = 0, l = geometries.length; i < l; i++) {
|
19098 | var geo = geometries[i];
|
19099 | if (!geo) {
|
19100 | continue;
|
19101 | }
|
19102 | var geoExtent = geo[fn](projection);
|
19103 | if (geoExtent) {
|
19104 | result = geoExtent.combine(result);
|
19105 | }
|
19106 | }
|
19107 | return result;
|
19108 | }
|
19109 |
|
19110 | var MultiGeometry = function (_GeometryCollection) {
|
19111 | inherits(MultiGeometry, _GeometryCollection);
|
19112 |
|
19113 | function MultiGeometry(geoType, type, data, options) {
|
19114 | classCallCheck(this, MultiGeometry);
|
19115 |
|
19116 | var _this = possibleConstructorReturn(this, _GeometryCollection.call(this, null, options));
|
19117 |
|
19118 | _this.GeometryType = geoType;
|
19119 | _this.type = type;
|
19120 | _this._initData(data);
|
19121 | return _this;
|
19122 | }
|
19123 |
|
19124 | MultiGeometry.prototype.getCoordinates = function getCoordinates() {
|
19125 | var coordinates = [];
|
19126 | var geometries = this.getGeometries();
|
19127 | for (var i = 0, l = geometries.length; i < l; i++) {
|
19128 | coordinates.push(geometries[i].getCoordinates());
|
19129 | }
|
19130 | return coordinates;
|
19131 | };
|
19132 |
|
19133 | MultiGeometry.prototype.setCoordinates = function setCoordinates(coordinates) {
|
19134 | coordinates = coordinates || [];
|
19135 | var geometries = [];
|
19136 | for (var i = 0, l = coordinates.length; i < l; i++) {
|
19137 | var g = new this.GeometryType(coordinates[i], this.config());
|
19138 | geometries.push(g);
|
19139 | }
|
19140 | this.setGeometries(geometries);
|
19141 | return this;
|
19142 | };
|
19143 |
|
19144 | MultiGeometry.prototype._initData = function _initData(data) {
|
19145 | data = data || [];
|
19146 | if (data.length) {
|
19147 | if (data[0] instanceof this.GeometryType) {
|
19148 | this.setGeometries(data);
|
19149 | } else {
|
19150 | this.setCoordinates(data);
|
19151 | }
|
19152 | }
|
19153 | };
|
19154 |
|
19155 | MultiGeometry.prototype._checkGeo = function _checkGeo(geo) {
|
19156 | return geo instanceof this.GeometryType;
|
19157 | };
|
19158 |
|
19159 | MultiGeometry.prototype._exportGeoJSONGeometry = function _exportGeoJSONGeometry() {
|
19160 | var points = this.getCoordinates();
|
19161 | var coordinates = Coordinate.toNumberArrays(points);
|
19162 | return {
|
19163 | 'type': this.getType(),
|
19164 | 'coordinates': coordinates
|
19165 | };
|
19166 | };
|
19167 |
|
19168 | return MultiGeometry;
|
19169 | }(GeometryCollection);
|
19170 |
|
19171 | var MultiPoint = function (_MultiGeometry) {
|
19172 | inherits(MultiPoint, _MultiGeometry);
|
19173 |
|
19174 | function MultiPoint(data, opts) {
|
19175 | classCallCheck(this, MultiPoint);
|
19176 | return possibleConstructorReturn(this, _MultiGeometry.call(this, Marker, 'MultiPoint', data, opts));
|
19177 | }
|
19178 |
|
19179 | return MultiPoint;
|
19180 | }(MultiGeometry);
|
19181 |
|
19182 | MultiPoint.registerJSONType('MultiPoint');
|
19183 |
|
19184 | var MultiPath = function (_MultiGeometry) {
|
19185 | inherits(MultiPath, _MultiGeometry);
|
19186 |
|
19187 | function MultiPath() {
|
19188 | classCallCheck(this, MultiPath);
|
19189 | return possibleConstructorReturn(this, _MultiGeometry.apply(this, arguments));
|
19190 | }
|
19191 |
|
19192 | MultiPath.prototype.getCenterInExtent = function getCenterInExtent(extent) {
|
19193 | var children = this.getGeometries();
|
19194 | var sumx = 0,
|
19195 | sumy = 0,
|
19196 | counter = 0;
|
19197 |
|
19198 | children.forEach(function (l) {
|
19199 | var c = l.getCenterInExtent(extent);
|
19200 | if (c) {
|
19201 | sumx += c.x * c.count;
|
19202 | sumy += c.y * c.count;
|
19203 | counter += c.count;
|
19204 | }
|
19205 | });
|
19206 | if (counter === 0) {
|
19207 | return null;
|
19208 | }
|
19209 | return new Coordinate(sumx, sumy)._multi(1 / counter);
|
19210 | };
|
19211 |
|
19212 | return MultiPath;
|
19213 | }(MultiGeometry);
|
19214 |
|
19215 | var MultiLineString = function (_MultiPath) {
|
19216 | inherits(MultiLineString, _MultiPath);
|
19217 |
|
19218 | function MultiLineString(data, options) {
|
19219 | classCallCheck(this, MultiLineString);
|
19220 | return possibleConstructorReturn(this, _MultiPath.call(this, LineString, 'MultiLineString', data, options));
|
19221 | }
|
19222 |
|
19223 | return MultiLineString;
|
19224 | }(MultiPath);
|
19225 |
|
19226 | MultiLineString.registerJSONType('MultiLineString');
|
19227 |
|
19228 | var MultiPolygon = function (_MultiPath) {
|
19229 | inherits(MultiPolygon, _MultiPath);
|
19230 |
|
19231 | function MultiPolygon(data, opts) {
|
19232 | classCallCheck(this, MultiPolygon);
|
19233 | return possibleConstructorReturn(this, _MultiPath.call(this, Polygon, 'MultiPolygon', data, opts));
|
19234 | }
|
19235 |
|
19236 | return MultiPolygon;
|
19237 | }(MultiPath);
|
19238 |
|
19239 | MultiPolygon.registerJSONType('MultiPolygon');
|
19240 |
|
19241 | var types$1 = {
|
19242 | 'Marker': Marker,
|
19243 | 'LineString': LineString,
|
19244 | 'Polygon': Polygon,
|
19245 | 'MultiPoint': MultiPoint,
|
19246 | 'MultiLineString': MultiLineString,
|
19247 | 'MultiPolygon': MultiPolygon
|
19248 | };
|
19249 |
|
19250 | var GeoJSON = {
|
19251 | toGeometry: function toGeometry(geoJSON) {
|
19252 | if (isString(geoJSON)) {
|
19253 | geoJSON = parseJSON(geoJSON);
|
19254 | }
|
19255 | if (Array.isArray(geoJSON)) {
|
19256 | var resultGeos = [];
|
19257 | for (var i = 0, len = geoJSON.length; i < len; i++) {
|
19258 | var geo = GeoJSON._convert(geoJSON[i]);
|
19259 | if (Array.isArray(geo)) {
|
19260 | pushIn(resultGeos, geo);
|
19261 | } else {
|
19262 | resultGeos.push(geo);
|
19263 | }
|
19264 | }
|
19265 | return resultGeos;
|
19266 | } else {
|
19267 | var resultGeo = GeoJSON._convert(geoJSON);
|
19268 | return resultGeo;
|
19269 | }
|
19270 | },
|
19271 |
|
19272 | _convert: function _convert(json) {
|
19273 | if (!json || isNil(json['type'])) {
|
19274 | return null;
|
19275 | }
|
19276 |
|
19277 | var type = json['type'];
|
19278 | if (type === 'Feature') {
|
19279 | var g = json['geometry'];
|
19280 | var geometry = GeoJSON._convert(g);
|
19281 | if (!geometry) {
|
19282 | return null;
|
19283 | }
|
19284 | geometry.setId(json['id']);
|
19285 | geometry.setProperties(json['properties']);
|
19286 | return geometry;
|
19287 | } else if (type === 'FeatureCollection') {
|
19288 | var features = json['features'];
|
19289 | if (!features) {
|
19290 | return null;
|
19291 | }
|
19292 | var result = GeoJSON.toGeometry(features);
|
19293 | return result;
|
19294 | } else if (['Point', 'LineString', 'Polygon', 'MultiPoint', 'MultiLineString', 'MultiPolygon'].indexOf(type) >= 0) {
|
19295 | var clazz = type === 'Point' ? 'Marker' : type;
|
19296 | return new types$1[clazz](json['coordinates']);
|
19297 | } else if (type === 'GeometryCollection') {
|
19298 | var geometries = json['geometries'];
|
19299 | if (!isArrayHasData(geometries)) {
|
19300 | return new GeometryCollection();
|
19301 | }
|
19302 | var mGeos = [];
|
19303 | var size = geometries.length;
|
19304 | for (var i = 0; i < size; i++) {
|
19305 | mGeos.push(GeoJSON._convert(geometries[i]));
|
19306 | }
|
19307 | return new GeometryCollection(mGeos);
|
19308 | }
|
19309 | return null;
|
19310 | }
|
19311 | };
|
19312 |
|
19313 | var options$9 = {
|
19314 | 'numberOfShellPoints': 60
|
19315 | };
|
19316 |
|
19317 | var Circle = function (_CenterMixin) {
|
19318 | inherits(Circle, _CenterMixin);
|
19319 |
|
19320 | Circle.fromJSON = function fromJSON(json) {
|
19321 | var feature = json['feature'];
|
19322 | var circle = new Circle(json['coordinates'], json['radius'], json['options']);
|
19323 | circle.setProperties(feature['properties']);
|
19324 | return circle;
|
19325 | };
|
19326 |
|
19327 | function Circle(coordinates, radius, opts) {
|
19328 | classCallCheck(this, Circle);
|
19329 |
|
19330 | var _this = possibleConstructorReturn(this, _CenterMixin.call(this, null, opts));
|
19331 |
|
19332 | if (coordinates) {
|
19333 | _this.setCoordinates(coordinates);
|
19334 | }
|
19335 | _this._radius = radius;
|
19336 | return _this;
|
19337 | }
|
19338 |
|
19339 | Circle.prototype.getRadius = function getRadius() {
|
19340 | return this._radius;
|
19341 | };
|
19342 |
|
19343 | Circle.prototype.setRadius = function setRadius(radius) {
|
19344 | this._radius = radius;
|
19345 | this.onShapeChanged();
|
19346 | return this;
|
19347 | };
|
19348 |
|
19349 | Circle.prototype.getShell = function getShell() {
|
19350 | var measurer = this._getMeasurer(),
|
19351 | center = this.getCoordinates(),
|
19352 | numberOfPoints = this.options['numberOfShellPoints'],
|
19353 | radius = this.getRadius();
|
19354 | var shell = [];
|
19355 | var rad = void 0,
|
19356 | dx = void 0,
|
19357 | dy = void 0;
|
19358 | for (var i = 0, len = numberOfPoints - 1; i < len; i++) {
|
19359 | rad = 360 * i / len * Math.PI / 180;
|
19360 | dx = radius * Math.cos(rad);
|
19361 | dy = radius * Math.sin(rad);
|
19362 | var vertex = measurer.locate(center, dx, dy);
|
19363 | shell.push(vertex);
|
19364 | }
|
19365 | shell.push(shell[0]);
|
19366 | return shell;
|
19367 | };
|
19368 |
|
19369 | Circle.prototype.getHoles = function getHoles() {
|
19370 | return [];
|
19371 | };
|
19372 |
|
19373 | Circle.prototype.animateShow = function animateShow() {
|
19374 | return this.show();
|
19375 | };
|
19376 |
|
19377 | Circle.prototype._containsPoint = function _containsPoint(point, tolerance) {
|
19378 | var map = this.getMap();
|
19379 | if (map.getPitch()) {
|
19380 | return _CenterMixin.prototype._containsPoint.call(this, point, tolerance);
|
19381 | }
|
19382 | var center = map._pointToContainerPoint(this._getCenter2DPoint()),
|
19383 | size = this.getSize(),
|
19384 | t = isNil(tolerance) ? this._hitTestTolerance() : tolerance,
|
19385 | se = center.add(size.width / 2, size.height / 2);
|
19386 | return withInEllipse(point, center, se, t);
|
19387 | };
|
19388 |
|
19389 | Circle.prototype._computePrjExtent = function _computePrjExtent(projection) {
|
19390 | var minmax = this._getMinMax(projection);
|
19391 | if (!minmax) {
|
19392 | return null;
|
19393 | }
|
19394 | var pcenter = this._getPrjCoordinates();
|
19395 | var pminmax = minmax.map(function (c) {
|
19396 | return projection.project(c);
|
19397 | });
|
19398 | var dx = Math.min(Math.abs(pminmax[0].x - pcenter.x), Math.abs(pminmax[1].x - pcenter.x)),
|
19399 | dy = Math.min(Math.abs(pminmax[2].y - pcenter.y), Math.abs(pminmax[3].y - pcenter.y));
|
19400 | return new Extent(pcenter.sub(dx, dy), pcenter.add(dx, dy));
|
19401 | };
|
19402 |
|
19403 | Circle.prototype._computeExtent = function _computeExtent(measurer) {
|
19404 | var minmax = this._getMinMax(measurer);
|
19405 | if (!minmax) {
|
19406 | return null;
|
19407 | }
|
19408 | return new Extent(minmax[0].x, minmax[2].y, minmax[1].x, minmax[3].y, this._getProjection());
|
19409 | };
|
19410 |
|
19411 | Circle.prototype._getMinMax = function _getMinMax(measurer) {
|
19412 | if (!measurer || !this._coordinates || isNil(this._radius)) {
|
19413 | return null;
|
19414 | }
|
19415 | var radius = this._radius;
|
19416 | var p1 = measurer.locate(this._coordinates, -radius, 0),
|
19417 | p2 = measurer.locate(this._coordinates, radius, 0),
|
19418 | p3 = measurer.locate(this._coordinates, 0, radius),
|
19419 | p4 = measurer.locate(this._coordinates, 0, -radius);
|
19420 | return [p1, p2, p3, p4];
|
19421 | };
|
19422 |
|
19423 | Circle.prototype._computeGeodesicLength = function _computeGeodesicLength() {
|
19424 | if (isNil(this._radius)) {
|
19425 | return 0;
|
19426 | }
|
19427 | return Math.PI * 2 * this._radius;
|
19428 | };
|
19429 |
|
19430 | Circle.prototype._computeGeodesicArea = function _computeGeodesicArea() {
|
19431 | if (isNil(this._radius)) {
|
19432 | return 0;
|
19433 | }
|
19434 | return Math.PI * Math.pow(this._radius, 2);
|
19435 | };
|
19436 |
|
19437 | Circle.prototype._exportGeoJSONGeometry = function _exportGeoJSONGeometry() {
|
19438 | var coordinates = Coordinate.toNumberArrays([this.getShell()]);
|
19439 | return {
|
19440 | 'type': 'Polygon',
|
19441 | 'coordinates': coordinates
|
19442 | };
|
19443 | };
|
19444 |
|
19445 | Circle.prototype._toJSON = function _toJSON(options) {
|
19446 | var center = this.getCenter();
|
19447 | var opts = extend({}, options);
|
19448 | opts.geometry = false;
|
19449 | var feature = this.toGeoJSON(opts);
|
19450 | feature['geometry'] = {
|
19451 | 'type': 'Polygon'
|
19452 | };
|
19453 | return {
|
19454 | 'feature': feature,
|
19455 | 'subType': 'Circle',
|
19456 | 'coordinates': [center.x, center.y],
|
19457 | 'radius': this.getRadius()
|
19458 | };
|
19459 | };
|
19460 |
|
19461 | return Circle;
|
19462 | }(CenterMixin(Polygon));
|
19463 |
|
19464 | Circle.mergeOptions(options$9);
|
19465 |
|
19466 | Circle.registerJSONType('Circle');
|
19467 |
|
19468 | var options$10 = {
|
19469 | 'numberOfShellPoints': 80
|
19470 | };
|
19471 |
|
19472 | var Ellipse = function (_CenterMixin) {
|
19473 | inherits(Ellipse, _CenterMixin);
|
19474 |
|
19475 | Ellipse.fromJSON = function fromJSON(json) {
|
19476 | var feature = json['feature'];
|
19477 | var ellipse = new Ellipse(json['coordinates'], json['width'], json['height'], json['options']);
|
19478 | ellipse.setProperties(feature['properties']);
|
19479 | return ellipse;
|
19480 | };
|
19481 |
|
19482 | function Ellipse(coordinates, width, height, opts) {
|
19483 | classCallCheck(this, Ellipse);
|
19484 |
|
19485 | var _this = possibleConstructorReturn(this, _CenterMixin.call(this, null, opts));
|
19486 |
|
19487 | if (coordinates) {
|
19488 | _this.setCoordinates(coordinates);
|
19489 | }
|
19490 | _this.width = width;
|
19491 | _this.height = height;
|
19492 | return _this;
|
19493 | }
|
19494 |
|
19495 | Ellipse.prototype.getWidth = function getWidth() {
|
19496 | return this.width;
|
19497 | };
|
19498 |
|
19499 | Ellipse.prototype.setWidth = function setWidth(width) {
|
19500 | this.width = width;
|
19501 | this.onShapeChanged();
|
19502 | return this;
|
19503 | };
|
19504 |
|
19505 | Ellipse.prototype.getHeight = function getHeight() {
|
19506 | return this.height;
|
19507 | };
|
19508 |
|
19509 | Ellipse.prototype.setHeight = function setHeight(height) {
|
19510 | this.height = height;
|
19511 | this.onShapeChanged();
|
19512 | return this;
|
19513 | };
|
19514 |
|
19515 | Ellipse.prototype.getShell = function getShell() {
|
19516 | var measurer = this._getMeasurer(),
|
19517 | center = this.getCoordinates(),
|
19518 | numberOfPoints = this.options['numberOfShellPoints'],
|
19519 | width = this.getWidth(),
|
19520 | height = this.getHeight();
|
19521 | var shell = [];
|
19522 | var s = Math.pow(width / 2, 2) * Math.pow(height / 2, 2),
|
19523 | sx = Math.pow(width / 2, 2),
|
19524 | sy = Math.pow(height / 2, 2);
|
19525 | var deg = void 0,
|
19526 | rad = void 0,
|
19527 | dx = void 0,
|
19528 | dy = void 0;
|
19529 | for (var i = 0; i < numberOfPoints; i++) {
|
19530 | deg = 360 * i / numberOfPoints;
|
19531 | rad = deg * Math.PI / 180;
|
19532 | dx = Math.sqrt(s / (sx * Math.pow(Math.tan(rad), 2) + sy));
|
19533 | dy = Math.sqrt(s / (sy * Math.pow(1 / Math.tan(rad), 2) + sx));
|
19534 | if (deg > 90 && deg < 270) {
|
19535 | dx *= -1;
|
19536 | }
|
19537 | if (deg > 180 && deg < 360) {
|
19538 | dy *= -1;
|
19539 | }
|
19540 | var vertex = measurer.locate(center, dx, dy);
|
19541 | shell.push(vertex);
|
19542 | }
|
19543 | return shell;
|
19544 | };
|
19545 |
|
19546 | Ellipse.prototype.getHoles = function getHoles() {
|
19547 | return [];
|
19548 | };
|
19549 |
|
19550 | Ellipse.prototype.animateShow = function animateShow() {
|
19551 | return this.show();
|
19552 | };
|
19553 |
|
19554 | Ellipse.prototype._containsPoint = function _containsPoint(point, tolerance) {
|
19555 | var map = this.getMap();
|
19556 | if (map.isTransforming()) {
|
19557 | return _CenterMixin.prototype._containsPoint.call(this, point, tolerance);
|
19558 | }
|
19559 | var projection = map.getProjection();
|
19560 | var t = isNil(tolerance) ? this._hitTestTolerance() : tolerance,
|
19561 | pps = projection.projectCoords([this._coordinates, map.locate(this._coordinates, this.getWidth() / 2, this.getHeight() / 2)]),
|
19562 | p0 = map._prjToContainerPoint(pps[0]),
|
19563 | p1 = map._prjToContainerPoint(pps[1]);
|
19564 | return withInEllipse(point, p0, p1, t);
|
19565 | };
|
19566 |
|
19567 | Ellipse.prototype._computePrjExtent = function _computePrjExtent() {
|
19568 | return Circle.prototype._computePrjExtent.apply(this, arguments);
|
19569 | };
|
19570 |
|
19571 | Ellipse.prototype._computeExtent = function _computeExtent() {
|
19572 | return Circle.prototype._computeExtent.apply(this, arguments);
|
19573 | };
|
19574 |
|
19575 | Ellipse.prototype._getMinMax = function _getMinMax(measurer) {
|
19576 | if (!measurer || !this._coordinates || isNil(this.width) || isNil(this.height)) {
|
19577 | return null;
|
19578 | }
|
19579 | var width = this.getWidth(),
|
19580 | height = this.getHeight();
|
19581 | var p1 = measurer.locate(this._coordinates, -width / 2, 0),
|
19582 | p2 = measurer.locate(this._coordinates, width / 2, 0),
|
19583 | p3 = measurer.locate(this._coordinates, 0, -height / 2),
|
19584 | p4 = measurer.locate(this._coordinates, 0, height / 2);
|
19585 | return [p1, p2, p3, p4];
|
19586 | };
|
19587 |
|
19588 | Ellipse.prototype._computeGeodesicLength = function _computeGeodesicLength() {
|
19589 | if (isNil(this.width) || isNil(this.height)) {
|
19590 | return 0;
|
19591 | }
|
19592 |
|
19593 | var longer = this.width > this.height ? this.width : this.height;
|
19594 | return 2 * Math.PI * longer / 2 - 4 * Math.abs(this.width - this.height);
|
19595 | };
|
19596 |
|
19597 | Ellipse.prototype._computeGeodesicArea = function _computeGeodesicArea() {
|
19598 | if (isNil(this.width) || isNil(this.height)) {
|
19599 | return 0;
|
19600 | }
|
19601 | return Math.PI * this.width * this.height / 4;
|
19602 | };
|
19603 |
|
19604 | Ellipse.prototype._exportGeoJSONGeometry = function _exportGeoJSONGeometry() {
|
19605 | var coordinates = Coordinate.toNumberArrays([this.getShell()]);
|
19606 | return {
|
19607 | 'type': 'Polygon',
|
19608 | 'coordinates': coordinates
|
19609 | };
|
19610 | };
|
19611 |
|
19612 | Ellipse.prototype._toJSON = function _toJSON(options) {
|
19613 | var opts = extend({}, options);
|
19614 | var center = this.getCenter();
|
19615 | opts.geometry = false;
|
19616 | var feature = this.toGeoJSON(opts);
|
19617 | feature['geometry'] = {
|
19618 | 'type': 'Polygon'
|
19619 | };
|
19620 | return {
|
19621 | 'feature': feature,
|
19622 | 'subType': 'Ellipse',
|
19623 | 'coordinates': [center.x, center.y],
|
19624 | 'width': this.getWidth(),
|
19625 | 'height': this.getHeight()
|
19626 | };
|
19627 | };
|
19628 |
|
19629 | return Ellipse;
|
19630 | }(CenterMixin(Polygon));
|
19631 |
|
19632 | Ellipse.mergeOptions(options$10);
|
19633 |
|
19634 | Ellipse.registerJSONType('Ellipse');
|
19635 |
|
19636 | var Rectangle = function (_Polygon) {
|
19637 | inherits(Rectangle, _Polygon);
|
19638 |
|
19639 | Rectangle.fromJSON = function fromJSON(json) {
|
19640 | var feature = json['feature'];
|
19641 | var rect = new Rectangle(json['coordinates'], json['width'], json['height'], json['options']);
|
19642 | rect.setProperties(feature['properties']);
|
19643 | return rect;
|
19644 | };
|
19645 |
|
19646 | function Rectangle(coordinates, width, height, opts) {
|
19647 | classCallCheck(this, Rectangle);
|
19648 |
|
19649 | var _this = possibleConstructorReturn(this, _Polygon.call(this, null, opts));
|
19650 |
|
19651 | if (coordinates) {
|
19652 | _this.setCoordinates(coordinates);
|
19653 | }
|
19654 | _this._width = width;
|
19655 | _this._height = height;
|
19656 | return _this;
|
19657 | }
|
19658 |
|
19659 | Rectangle.prototype.getCoordinates = function getCoordinates() {
|
19660 | return this._coordinates;
|
19661 | };
|
19662 |
|
19663 | Rectangle.prototype.setCoordinates = function setCoordinates(nw) {
|
19664 | this._coordinates = nw instanceof Coordinate ? nw : new Coordinate(nw);
|
19665 | if (!this._coordinates || !this.getMap()) {
|
19666 | this.onPositionChanged();
|
19667 | return this;
|
19668 | }
|
19669 | var projection = this._getProjection();
|
19670 | this._setPrjCoordinates(projection.project(this._coordinates));
|
19671 | return this;
|
19672 | };
|
19673 |
|
19674 | Rectangle.prototype.getWidth = function getWidth() {
|
19675 | return this._width;
|
19676 | };
|
19677 |
|
19678 | Rectangle.prototype.setWidth = function setWidth(width) {
|
19679 | this._width = width;
|
19680 | this.onShapeChanged();
|
19681 | return this;
|
19682 | };
|
19683 |
|
19684 | Rectangle.prototype.getHeight = function getHeight() {
|
19685 | return this._height;
|
19686 | };
|
19687 |
|
19688 | Rectangle.prototype.setHeight = function setHeight(height) {
|
19689 | this._height = height;
|
19690 | this.onShapeChanged();
|
19691 | return this;
|
19692 | };
|
19693 |
|
19694 | Rectangle.prototype.getShell = function getShell() {
|
19695 | var measurer = this._getMeasurer();
|
19696 | var nw = this._coordinates;
|
19697 | var map = this.getMap();
|
19698 | var sx = 1,
|
19699 | sy = -1;
|
19700 | if (map) {
|
19701 | var fExt = map.getFullExtent();
|
19702 | if (fExt['left'] > fExt['right']) {
|
19703 | sx = -1;
|
19704 | }
|
19705 | if (fExt['bottom'] > fExt['top']) {
|
19706 | sy = 1;
|
19707 | }
|
19708 | }
|
19709 | var points = [];
|
19710 | points.push(nw);
|
19711 | points.push(measurer.locate(nw, sx * this._width, 0));
|
19712 | points.push(measurer.locate(nw, sx * this._width, sy * this._height));
|
19713 | points.push(measurer.locate(nw, 0, sy * this._height));
|
19714 | points.push(nw);
|
19715 | return points;
|
19716 | };
|
19717 |
|
19718 | Rectangle.prototype.getHoles = function getHoles() {
|
19719 | return [];
|
19720 | };
|
19721 |
|
19722 | Rectangle.prototype.animateShow = function animateShow() {
|
19723 | return this.show();
|
19724 | };
|
19725 |
|
19726 | Rectangle.prototype._getPrjCoordinates = function _getPrjCoordinates() {
|
19727 | var projection = this._getProjection();
|
19728 | if (!projection) {
|
19729 | return null;
|
19730 | }
|
19731 | this._verifyProjection();
|
19732 | if (!this._pnw) {
|
19733 | if (this._coordinates) {
|
19734 | this._pnw = projection.project(this._coordinates);
|
19735 | }
|
19736 | }
|
19737 | return this._pnw;
|
19738 | };
|
19739 |
|
19740 | Rectangle.prototype._setPrjCoordinates = function _setPrjCoordinates(pnw) {
|
19741 | this._pnw = pnw;
|
19742 | this.onPositionChanged();
|
19743 | };
|
19744 |
|
19745 | Rectangle.prototype._getPrjShell = function _getPrjShell() {
|
19746 | var shell = _Polygon.prototype._getPrjShell.call(this);
|
19747 | var projection = this._getProjection();
|
19748 | if (!projection.isSphere()) {
|
19749 | return shell;
|
19750 | }
|
19751 | var sphereExtent = projection.getSphereExtent(),
|
19752 | sx = sphereExtent.sx,
|
19753 | sy = sphereExtent.sy;
|
19754 | var circum = this._getProjection().getCircum();
|
19755 | var nw = shell[0];
|
19756 | for (var i = 1, l = shell.length; i < l; i++) {
|
19757 | var p = shell[i];
|
19758 | var dx = 0,
|
19759 | dy = 0;
|
19760 | if (sx * (nw.x - p.x) > 0) {
|
19761 | dx = circum.x * sx;
|
19762 | }
|
19763 | if (sy * (nw.y - p.y) < 0) {
|
19764 | dy = circum.y * sy;
|
19765 | }
|
19766 | shell[i]._add(dx, dy);
|
19767 | }
|
19768 | return shell;
|
19769 | };
|
19770 |
|
19771 | Rectangle.prototype._updateCache = function _updateCache() {
|
19772 | this._clearCache();
|
19773 | var projection = this._getProjection();
|
19774 | if (this._pnw && projection) {
|
19775 | this._coordinates = projection.unproject(this._pnw);
|
19776 | }
|
19777 | };
|
19778 |
|
19779 | Rectangle.prototype._clearProjection = function _clearProjection() {
|
19780 | this._pnw = null;
|
19781 | _Polygon.prototype._clearProjection.call(this);
|
19782 | };
|
19783 |
|
19784 | Rectangle.prototype._computeCenter = function _computeCenter(measurer) {
|
19785 | return measurer.locate(this._coordinates, this._width / 2, -this._height / 2);
|
19786 | };
|
19787 |
|
19788 | Rectangle.prototype._containsPoint = function _containsPoint(point, tolerance) {
|
19789 | var map = this.getMap();
|
19790 | if (map.isTransforming()) {
|
19791 | return _Polygon.prototype._containsPoint.call(this, point, tolerance);
|
19792 | }
|
19793 | var t = isNil(tolerance) ? this._hitTestTolerance() : tolerance,
|
19794 | r = map._getResolution() * t;
|
19795 | var extent = this._getPrjExtent().expand(r);
|
19796 | var p = map._containerPointToPrj(point);
|
19797 | return extent.contains(p);
|
19798 | };
|
19799 |
|
19800 | Rectangle.prototype._computePrjExtent = function _computePrjExtent(projection) {
|
19801 | var se = this._getSouthEast(projection);
|
19802 | if (!se) {
|
19803 | return null;
|
19804 | }
|
19805 | var prjs = projection.projectCoords([new Coordinate(this._coordinates.x, se.y), new Coordinate(se.x, this._coordinates.y)]);
|
19806 | return new Extent(prjs[0], prjs[1]);
|
19807 | };
|
19808 |
|
19809 | Rectangle.prototype._computeExtent = function _computeExtent(measurer) {
|
19810 | var se = this._getSouthEast(measurer);
|
19811 | if (!se) {
|
19812 | return null;
|
19813 | }
|
19814 | return new Extent(this._coordinates, se, this._getProjection());
|
19815 | };
|
19816 |
|
19817 | Rectangle.prototype._getSouthEast = function _getSouthEast(measurer) {
|
19818 | if (!measurer || !this._coordinates || isNil(this._width) || isNil(this._height)) {
|
19819 | return null;
|
19820 | }
|
19821 | var width = this.getWidth(),
|
19822 | height = this.getHeight();
|
19823 | var w = width,
|
19824 | h = -height;
|
19825 | if (measurer.fullExtent) {
|
19826 | var fullExtent = measurer.fullExtent,
|
19827 | sx = fullExtent.right > fullExtent.left ? 1 : -1,
|
19828 | sy = fullExtent.top > fullExtent.bottom ? 1 : -1;
|
19829 | w *= sx;
|
19830 | h *= sy;
|
19831 | }
|
19832 | var se = measurer.locate(this._coordinates, w, h);
|
19833 | return se;
|
19834 | };
|
19835 |
|
19836 | Rectangle.prototype._computeGeodesicLength = function _computeGeodesicLength() {
|
19837 | if (isNil(this._width) || isNil(this._height)) {
|
19838 | return 0;
|
19839 | }
|
19840 | return 2 * (this._width + this._height);
|
19841 | };
|
19842 |
|
19843 | Rectangle.prototype._computeGeodesicArea = function _computeGeodesicArea() {
|
19844 | if (isNil(this._width) || isNil(this._height)) {
|
19845 | return 0;
|
19846 | }
|
19847 | return this._width * this._height;
|
19848 | };
|
19849 |
|
19850 | Rectangle.prototype._exportGeoJSONGeometry = function _exportGeoJSONGeometry() {
|
19851 | var coordinates = Coordinate.toNumberArrays([this.getShell()]);
|
19852 | return {
|
19853 | 'type': 'Polygon',
|
19854 | 'coordinates': coordinates
|
19855 | };
|
19856 | };
|
19857 |
|
19858 | Rectangle.prototype._toJSON = function _toJSON(options) {
|
19859 | var opts = extend({}, options);
|
19860 | var nw = this.getCoordinates();
|
19861 | opts.geometry = false;
|
19862 | var feature = this.toGeoJSON(opts);
|
19863 | feature['geometry'] = {
|
19864 | 'type': 'Polygon'
|
19865 | };
|
19866 | return {
|
19867 | 'feature': feature,
|
19868 | 'subType': 'Rectangle',
|
19869 | 'coordinates': [nw.x, nw.y],
|
19870 | 'width': this.getWidth(),
|
19871 | 'height': this.getHeight()
|
19872 | };
|
19873 | };
|
19874 |
|
19875 | return Rectangle;
|
19876 | }(Polygon);
|
19877 |
|
19878 | Rectangle.registerJSONType('Rectangle');
|
19879 |
|
19880 | var options$11 = {
|
19881 | 'numberOfShellPoints': 60
|
19882 | };
|
19883 |
|
19884 | var Sector = function (_Circle) {
|
19885 | inherits(Sector, _Circle);
|
19886 |
|
19887 | Sector.fromJSON = function fromJSON(json) {
|
19888 | var feature = json['feature'];
|
19889 | var sector = new Sector(json['coordinates'], json['radius'], json['startAngle'], json['endAngle'], json['options']);
|
19890 | sector.setProperties(feature['properties']);
|
19891 | return sector;
|
19892 | };
|
19893 |
|
19894 | function Sector(coordinates, radius, startAngle, endAngle, opts) {
|
19895 | classCallCheck(this, Sector);
|
19896 |
|
19897 | var _this = possibleConstructorReturn(this, _Circle.call(this, coordinates, radius, opts));
|
19898 |
|
19899 | _this.startAngle = startAngle;
|
19900 | _this.endAngle = endAngle;
|
19901 | return _this;
|
19902 | }
|
19903 |
|
19904 | Sector.prototype.getStartAngle = function getStartAngle() {
|
19905 | return this.startAngle;
|
19906 | };
|
19907 |
|
19908 | Sector.prototype.setStartAngle = function setStartAngle(startAngle) {
|
19909 | this.startAngle = startAngle;
|
19910 | this.onShapeChanged();
|
19911 | return this;
|
19912 | };
|
19913 |
|
19914 | Sector.prototype.getEndAngle = function getEndAngle() {
|
19915 | return this.endAngle;
|
19916 | };
|
19917 |
|
19918 | Sector.prototype.setEndAngle = function setEndAngle(endAngle) {
|
19919 | this.endAngle = endAngle;
|
19920 | this.onShapeChanged();
|
19921 | return this;
|
19922 | };
|
19923 |
|
19924 | Sector.prototype.getShell = function getShell() {
|
19925 | var measurer = this._getMeasurer(),
|
19926 | center = this.getCoordinates(),
|
19927 | numberOfPoints = this.options['numberOfShellPoints'] - 2,
|
19928 | radius = this.getRadius(),
|
19929 | shell = [center.copy()],
|
19930 | startAngle = this.getStartAngle(),
|
19931 | angle = this.getEndAngle() - startAngle;
|
19932 | var rad = void 0,
|
19933 | dx = void 0,
|
19934 | dy = void 0;
|
19935 | for (var i = 0; i < numberOfPoints; i++) {
|
19936 | rad = (angle * i / (numberOfPoints - 1) + startAngle) * Math.PI / 180;
|
19937 | dx = radius * Math.cos(rad);
|
19938 | dy = radius * Math.sin(rad);
|
19939 | var vertex = measurer.locate(center, dx, dy);
|
19940 | shell.push(vertex);
|
19941 | }
|
19942 | shell.push(center.copy());
|
19943 | return shell;
|
19944 | };
|
19945 |
|
19946 | Sector.prototype._containsPoint = function _containsPoint(point, tolerance) {
|
19947 | var map = this.getMap();
|
19948 | if (map.isTransforming()) {
|
19949 | return _Circle.prototype._containsPoint.call(this, point, tolerance);
|
19950 | }
|
19951 | var center = map._pointToContainerPoint(this._getCenter2DPoint()),
|
19952 | t = isNil(tolerance) ? this._hitTestTolerance() : tolerance,
|
19953 | size = this.getSize(),
|
19954 | pc = center,
|
19955 | pp = point,
|
19956 | x = pp.x - pc.x,
|
19957 | y = pc.y - pp.y,
|
19958 | atan2 = Math.atan2(y, x),
|
19959 | angle = atan2 < 0 ? (atan2 + 2 * Math.PI) * 360 / (2 * Math.PI) : atan2 * 360 / (2 * Math.PI);
|
19960 | var sAngle = this.startAngle % 360,
|
19961 | eAngle = this.endAngle % 360;
|
19962 | var between = false;
|
19963 | if (sAngle > eAngle) {
|
19964 | between = !(angle > eAngle && angle < sAngle);
|
19965 | } else {
|
19966 | between = angle >= sAngle && angle <= eAngle;
|
19967 | }
|
19968 | return pp.distanceTo(pc) <= size.width / 2 + t && between;
|
19969 | };
|
19970 |
|
19971 | Sector.prototype._computeGeodesicLength = function _computeGeodesicLength() {
|
19972 | if (isNil(this._radius)) {
|
19973 | return 0;
|
19974 | }
|
19975 | return Math.PI * 2 * this._radius * Math.abs(this.startAngle - this.endAngle) / 360 + 2 * this._radius;
|
19976 | };
|
19977 |
|
19978 | Sector.prototype._computeGeodesicArea = function _computeGeodesicArea() {
|
19979 | if (isNil(this._radius)) {
|
19980 | return 0;
|
19981 | }
|
19982 | return Math.PI * Math.pow(this._radius, 2) * Math.abs(this.startAngle - this.endAngle) / 360;
|
19983 | };
|
19984 |
|
19985 | Sector.prototype._toJSON = function _toJSON(options) {
|
19986 | var opts = extend({}, options);
|
19987 | var center = this.getCenter();
|
19988 | opts.geometry = false;
|
19989 | var feature = this.toGeoJSON(opts);
|
19990 | feature['geometry'] = {
|
19991 | 'type': 'Polygon'
|
19992 | };
|
19993 | return {
|
19994 | 'feature': feature,
|
19995 | 'subType': 'Sector',
|
19996 | 'coordinates': [center.x, center.y],
|
19997 | 'radius': this.getRadius(),
|
19998 | 'startAngle': this.getStartAngle(),
|
19999 | 'endAngle': this.getEndAngle()
|
20000 | };
|
20001 | };
|
20002 |
|
20003 | return Sector;
|
20004 | }(Circle);
|
20005 |
|
20006 | Sector.mergeOptions(options$11);
|
20007 |
|
20008 | Sector.registerJSONType('Sector');
|
20009 |
|
20010 | var options$12 = {
|
20011 | 'enableSimplify': false,
|
20012 | 'enableClip': false
|
20013 | };
|
20014 |
|
20015 | var Curve = function (_LineString) {
|
20016 | inherits(Curve, _LineString);
|
20017 |
|
20018 | function Curve() {
|
20019 | classCallCheck(this, Curve);
|
20020 | return possibleConstructorReturn(this, _LineString.apply(this, arguments));
|
20021 | }
|
20022 |
|
20023 | Curve.prototype._arc = function _arc(ctx, points, lineOpacity) {
|
20024 | var degree = this.options['arcDegree'] * Math.PI / 180;
|
20025 | for (var i = 1, l = points.length; i < l; i++) {
|
20026 | var c = Canvas._arcBetween(ctx, points[i - 1], points[i], degree);
|
20027 |
|
20028 | var ctrlPoint = [points[i - 1].x + points[i].x - c[0], points[i - 1].y + points[i].y - c[1]];
|
20029 | points[i - 1].nextCtrlPoint = ctrlPoint;
|
20030 | points[i].prevCtrlPoint = ctrlPoint;
|
20031 | Canvas._stroke(ctx, lineOpacity);
|
20032 | }
|
20033 | };
|
20034 |
|
20035 | Curve.prototype._quadraticCurve = function _quadraticCurve(ctx, points) {
|
20036 | if (points.length <= 2) {
|
20037 | Canvas._path(ctx, points);
|
20038 | return;
|
20039 | }
|
20040 | var i = void 0,
|
20041 | l = void 0;
|
20042 | for (i = 2, l = points.length; i < l; i += 2) {
|
20043 | ctx.quadraticCurveTo(points[i - 1].x, points[i - 1].y, points[i].x, points[i].y);
|
20044 | }
|
20045 | i -= 1;
|
20046 | if (i < l) {
|
20047 | for (; i < l; i++) {
|
20048 | ctx.lineTo(points[i].x, points[i].y);
|
20049 | }
|
20050 | }
|
20051 | };
|
20052 |
|
20053 | Curve.prototype._bezierCurve = function _bezierCurve(ctx, points) {
|
20054 | if (points.length <= 3) {
|
20055 | Canvas._path(ctx, points);
|
20056 | return;
|
20057 | }
|
20058 | var i = void 0,
|
20059 | l = void 0;
|
20060 | for (i = 1, l = points.length; i + 2 < l; i += 3) {
|
20061 | ctx.bezierCurveTo(points[i].x, points[i].y, points[i + 1].x, points[i + 1].y, points[i + 2].x, points[i + 2].y);
|
20062 | }
|
20063 | if (i < l) {
|
20064 | for (; i < l; i++) {
|
20065 | ctx.lineTo(points[i].x, points[i].y);
|
20066 | }
|
20067 | }
|
20068 | };
|
20069 |
|
20070 | Curve.prototype._getCurveArrowPoints = function _getCurveArrowPoints(arrows, segments, lineWidth, arrowStyle, tolerance, step) {
|
20071 | var l = segments.length;
|
20072 | var i = void 0;
|
20073 | for (i = step; i < l; i += step) {
|
20074 | arrows.push(this._getArrowShape(segments[i - 1], segments[i], lineWidth, arrowStyle, tolerance));
|
20075 | }
|
20076 | i -= step;
|
20077 | if (i < l - 1) {
|
20078 | for (i += 1; i < l; i++) {
|
20079 | arrows.push(this._getArrowShape(segments[i - 1], segments[i], lineWidth, arrowStyle, tolerance));
|
20080 | }
|
20081 | }
|
20082 | };
|
20083 |
|
20084 | return Curve;
|
20085 | }(LineString);
|
20086 |
|
20087 | Curve.mergeOptions(options$12);
|
20088 |
|
20089 | var options$13 = {
|
20090 | 'arcDegree': 90
|
20091 | };
|
20092 |
|
20093 | var ArcCurve = function (_Curve) {
|
20094 | inherits(ArcCurve, _Curve);
|
20095 |
|
20096 | function ArcCurve() {
|
20097 | classCallCheck(this, ArcCurve);
|
20098 | return possibleConstructorReturn(this, _Curve.apply(this, arguments));
|
20099 | }
|
20100 |
|
20101 | ArcCurve.prototype._toJSON = function _toJSON(options) {
|
20102 | return {
|
20103 | 'feature': this.toGeoJSON(options),
|
20104 | 'subType': 'ArcCurve'
|
20105 | };
|
20106 | };
|
20107 |
|
20108 | ArcCurve.prototype._paintOn = function _paintOn(ctx, points, lineOpacity) {
|
20109 | ctx.beginPath();
|
20110 | this._arc(ctx, points, lineOpacity);
|
20111 | Canvas._stroke(ctx, lineOpacity);
|
20112 | this._paintArrow(ctx, points, lineOpacity);
|
20113 | };
|
20114 |
|
20115 | ArcCurve.fromJSON = function fromJSON(json) {
|
20116 | var feature = json['feature'];
|
20117 | var arc = new ArcCurve(feature['geometry']['coordinates'], json['options']);
|
20118 | arc.setProperties(feature['properties']);
|
20119 | return arc;
|
20120 | };
|
20121 |
|
20122 | return ArcCurve;
|
20123 | }(Curve);
|
20124 |
|
20125 | ArcCurve.registerJSONType('ArcCurve');
|
20126 |
|
20127 | ArcCurve.mergeOptions(options$13);
|
20128 |
|
20129 | var CubicBezierCurve = function (_Curve) {
|
20130 | inherits(CubicBezierCurve, _Curve);
|
20131 |
|
20132 | function CubicBezierCurve() {
|
20133 | classCallCheck(this, CubicBezierCurve);
|
20134 | return possibleConstructorReturn(this, _Curve.apply(this, arguments));
|
20135 | }
|
20136 |
|
20137 | CubicBezierCurve.fromJSON = function fromJSON(json) {
|
20138 | var feature = json['feature'];
|
20139 | var curve = new CubicBezierCurve(feature['geometry']['coordinates'], json['options']);
|
20140 | curve.setProperties(feature['properties']);
|
20141 | return curve;
|
20142 | };
|
20143 |
|
20144 | CubicBezierCurve.prototype._toJSON = function _toJSON(options) {
|
20145 | return {
|
20146 | 'feature': this.toGeoJSON(options),
|
20147 | 'subType': 'CubicBezierCurve'
|
20148 | };
|
20149 | };
|
20150 |
|
20151 | CubicBezierCurve.prototype._paintOn = function _paintOn(ctx, points, lineOpacity) {
|
20152 | ctx.beginPath();
|
20153 | ctx.moveTo(points[0].x, points[0].y);
|
20154 | this._bezierCurve(ctx, points);
|
20155 | Canvas._stroke(ctx, lineOpacity);
|
20156 | this._paintArrow(ctx, points, lineOpacity);
|
20157 | };
|
20158 |
|
20159 | CubicBezierCurve.prototype._getArrowPoints = function _getArrowPoints(arrows, segments, lineWidth, arrowStyle, tolerance) {
|
20160 | return this._getCurveArrowPoints(arrows, segments, lineWidth, arrowStyle, tolerance, 3);
|
20161 | };
|
20162 |
|
20163 | return CubicBezierCurve;
|
20164 | }(Curve);
|
20165 |
|
20166 | CubicBezierCurve.registerJSONType('CubicBezierCurve');
|
20167 |
|
20168 | var QuadBezierCurve = function (_Curve) {
|
20169 | inherits(QuadBezierCurve, _Curve);
|
20170 |
|
20171 | function QuadBezierCurve() {
|
20172 | classCallCheck(this, QuadBezierCurve);
|
20173 | return possibleConstructorReturn(this, _Curve.apply(this, arguments));
|
20174 | }
|
20175 |
|
20176 | QuadBezierCurve.fromJSON = function fromJSON(json) {
|
20177 | var feature = json['feature'];
|
20178 | var curve = new QuadBezierCurve(feature['geometry']['coordinates'], json['options']);
|
20179 | curve.setProperties(feature['properties']);
|
20180 | return curve;
|
20181 | };
|
20182 |
|
20183 | QuadBezierCurve.prototype._toJSON = function _toJSON(options) {
|
20184 | return {
|
20185 | 'feature': this.toGeoJSON(options),
|
20186 | 'subType': 'QuadBezierCurve'
|
20187 | };
|
20188 | };
|
20189 |
|
20190 | QuadBezierCurve.prototype._paintOn = function _paintOn(ctx, points, lineOpacity) {
|
20191 | ctx.beginPath();
|
20192 | ctx.moveTo(points[0].x, points[0].y);
|
20193 | this._quadraticCurve(ctx, points, lineOpacity);
|
20194 | Canvas._stroke(ctx, lineOpacity);
|
20195 | this._paintArrow(ctx, points, lineOpacity);
|
20196 | };
|
20197 |
|
20198 | QuadBezierCurve.prototype._getArrowPoints = function _getArrowPoints(arrows, segments, lineWidth, arrowStyle, tolerance) {
|
20199 | return this._getCurveArrowPoints(arrows, segments, lineWidth, arrowStyle, tolerance, 2);
|
20200 | };
|
20201 |
|
20202 | return QuadBezierCurve;
|
20203 | }(Curve);
|
20204 |
|
20205 | QuadBezierCurve.registerJSONType('QuadBezierCurve');
|
20206 |
|
20207 | var defaultSymbol$1 = {
|
20208 | 'textFaceName': 'monospace',
|
20209 | 'textSize': 12,
|
20210 | 'textLineSpacing': 8,
|
20211 | 'textWrapCharacter': '\n',
|
20212 | 'textHorizontalAlignment': 'middle',
|
20213 | 'textVerticalAlignment': 'middle' };
|
20214 |
|
20215 | var defaultBoxSymbol = {
|
20216 | 'markerType': 'square',
|
20217 | 'markerLineColor': '#000',
|
20218 | 'markerLineWidth': 2,
|
20219 | 'markerLineOpacity': 1,
|
20220 | 'markerFill': '#fff',
|
20221 | 'markerOpacity': 1
|
20222 | };
|
20223 |
|
20224 | var TextMarker = function (_Marker) {
|
20225 | inherits(TextMarker, _Marker);
|
20226 |
|
20227 | function TextMarker() {
|
20228 | classCallCheck(this, TextMarker);
|
20229 | return possibleConstructorReturn(this, _Marker.apply(this, arguments));
|
20230 | }
|
20231 |
|
20232 | TextMarker.prototype.getContent = function getContent() {
|
20233 | return this._content;
|
20234 | };
|
20235 |
|
20236 | TextMarker.prototype.setContent = function setContent(content) {
|
20237 | var old = this._content;
|
20238 | this._content = escapeSpecialChars(content);
|
20239 | this._refresh();
|
20240 |
|
20241 | this._fireEvent('contentchange', {
|
20242 | 'old': old,
|
20243 | 'new': content
|
20244 | });
|
20245 | return this;
|
20246 | };
|
20247 |
|
20248 | TextMarker.prototype.onAdd = function onAdd() {
|
20249 | this._refresh();
|
20250 | };
|
20251 |
|
20252 | TextMarker.prototype.toJSON = function toJSON() {
|
20253 | var json = _Marker.prototype.toJSON.call(this);
|
20254 | delete json['symbol'];
|
20255 | return json;
|
20256 | };
|
20257 |
|
20258 | TextMarker.prototype.setSymbol = function setSymbol(symbol) {
|
20259 | if (this._refreshing || !symbol) {
|
20260 | return _Marker.prototype.setSymbol.call(this, symbol);
|
20261 | }
|
20262 | var s = this._parseSymbol(symbol);
|
20263 | if (this.setTextStyle) {
|
20264 | var style = this.getTextStyle() || {};
|
20265 | style.symbol = s[0];
|
20266 | this.setTextStyle(style);
|
20267 | } else if (this.setTextSymbol) {
|
20268 | this.setTextSymbol(s[0]);
|
20269 | }
|
20270 | if (this.setBoxStyle) {
|
20271 | var _style = this.getBoxStyle() || {};
|
20272 | _style.symbol = s[1];
|
20273 | this.setBoxStyle(_style);
|
20274 | } else if (this.setBoxSymbol) {
|
20275 | this.setBoxSymbol(s[1]);
|
20276 | }
|
20277 | return this;
|
20278 | };
|
20279 |
|
20280 | TextMarker.prototype._parseSymbol = function _parseSymbol(symbol) {
|
20281 | var t = {};
|
20282 | var b = {};
|
20283 | for (var p in symbol) {
|
20284 | if (hasOwn(symbol, p)) {
|
20285 | if (p.indexOf('text') === 0) {
|
20286 | t[p] = symbol[p];
|
20287 | } else {
|
20288 | b[p] = symbol[p];
|
20289 | }
|
20290 | }
|
20291 | }
|
20292 | return [t, b];
|
20293 | };
|
20294 |
|
20295 | TextMarker.prototype._getTextSize = function _getTextSize(symbol) {
|
20296 | return splitTextToRow(this._content, symbol)['size'];
|
20297 | };
|
20298 |
|
20299 | TextMarker.prototype._getInternalSymbol = function _getInternalSymbol() {
|
20300 | return this._symbol;
|
20301 | };
|
20302 |
|
20303 | TextMarker.prototype._getDefaultTextSymbol = function _getDefaultTextSymbol() {
|
20304 | return extend({}, defaultSymbol$1);
|
20305 | };
|
20306 |
|
20307 | TextMarker.prototype._getDefaultBoxSymbol = function _getDefaultBoxSymbol() {
|
20308 | return extend({}, defaultBoxSymbol);
|
20309 | };
|
20310 |
|
20311 | TextMarker.prototype._getDefaultPadding = function _getDefaultPadding() {
|
20312 | return [12, 8];
|
20313 | };
|
20314 |
|
20315 | return TextMarker;
|
20316 | }(Marker);
|
20317 |
|
20318 | var options$14 = {
|
20319 | 'textStyle': {
|
20320 | 'wrap': true,
|
20321 | 'padding': [12, 8],
|
20322 | 'verticalAlignment': 'middle',
|
20323 | 'horizontalAlignment': 'middle'
|
20324 | },
|
20325 | 'boxSymbol': null
|
20326 | };
|
20327 |
|
20328 | var TextBox = function (_TextMarker) {
|
20329 | inherits(TextBox, _TextMarker);
|
20330 |
|
20331 | function TextBox(content, coordinates, width, height) {
|
20332 | var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
20333 | classCallCheck(this, TextBox);
|
20334 |
|
20335 | var _this = possibleConstructorReturn(this, _TextMarker.call(this, coordinates, options));
|
20336 |
|
20337 | _this._content = escapeSpecialChars(content);
|
20338 | _this._width = isNil(width) ? 100 : width;
|
20339 | _this._height = isNil(height) ? 40 : height;
|
20340 | if (options.boxSymbol) {
|
20341 | _this.setBoxSymbol(options.boxSymbol);
|
20342 | }
|
20343 | if (options.textStyle) {
|
20344 | _this.setTextStyle(options.textStyle);
|
20345 | }
|
20346 | _this._refresh();
|
20347 | return _this;
|
20348 | }
|
20349 |
|
20350 | TextBox.prototype.getWidth = function getWidth() {
|
20351 | return this._width;
|
20352 | };
|
20353 |
|
20354 | TextBox.prototype.setWidth = function setWidth(width) {
|
20355 | this._width = width;
|
20356 | this._refresh();
|
20357 | return this;
|
20358 | };
|
20359 |
|
20360 | TextBox.prototype.getHeight = function getHeight() {
|
20361 | return this._height;
|
20362 | };
|
20363 |
|
20364 | TextBox.prototype.setHeight = function setHeight(height) {
|
20365 | this._height = height;
|
20366 | this._refresh();
|
20367 | return this;
|
20368 | };
|
20369 |
|
20370 | TextBox.prototype.getBoxSymbol = function getBoxSymbol() {
|
20371 | return extend({}, this.options.boxSymbol);
|
20372 | };
|
20373 |
|
20374 | TextBox.prototype.setBoxSymbol = function setBoxSymbol(symbol) {
|
20375 | this.options.boxSymbol = symbol ? extend({}, symbol) : symbol;
|
20376 | if (this.getSymbol()) {
|
20377 | this._refresh();
|
20378 | }
|
20379 | return this;
|
20380 | };
|
20381 |
|
20382 | TextBox.prototype.getTextStyle = function getTextStyle() {
|
20383 | if (!this.options.textStyle) {
|
20384 | return null;
|
20385 | }
|
20386 | return extend({}, this.options.textStyle);
|
20387 | };
|
20388 |
|
20389 | TextBox.prototype.setTextStyle = function setTextStyle(style) {
|
20390 | this.options.textStyle = style ? extend({}, style) : style;
|
20391 | if (this.getSymbol()) {
|
20392 | this._refresh();
|
20393 | }
|
20394 | return this;
|
20395 | };
|
20396 |
|
20397 | TextBox.fromJSON = function fromJSON(json) {
|
20398 | var feature = json['feature'];
|
20399 | var textBox = new TextBox(json['content'], feature['geometry']['coordinates'], json['width'], json['height'], json['options']);
|
20400 | textBox.setProperties(feature['properties']);
|
20401 | textBox.setId(feature['id']);
|
20402 | if (json['symbol']) {
|
20403 | textBox.setSymbol(json['symbol']);
|
20404 | }
|
20405 | return textBox;
|
20406 | };
|
20407 |
|
20408 | TextBox.prototype._toJSON = function _toJSON(options) {
|
20409 | return {
|
20410 | 'feature': this.toGeoJSON(options),
|
20411 | 'width': this.getWidth(),
|
20412 | 'height': this.getHeight(),
|
20413 | 'subType': 'TextBox',
|
20414 | 'content': this._content
|
20415 | };
|
20416 | };
|
20417 |
|
20418 | TextBox.prototype._refresh = function _refresh() {
|
20419 | var textStyle = this.getTextStyle() || {},
|
20420 | padding = textStyle['padding'] || [12, 8],
|
20421 | maxWidth = this._width - 2 * padding[0],
|
20422 | maxHeight = this._height - 2 * padding[1];
|
20423 | var symbol = extend({}, textStyle.symbol || this._getDefaultTextSymbol(), this.options.boxSymbol || this._getDefaultBoxSymbol(), {
|
20424 | 'textName': this._content,
|
20425 | 'markerWidth': this._width,
|
20426 | 'markerHeight': this._height,
|
20427 | 'textHorizontalAlignment': 'middle',
|
20428 | 'textVerticalAlignment': 'middle',
|
20429 | 'textMaxWidth': maxWidth,
|
20430 | 'textMaxHeight': maxHeight
|
20431 | });
|
20432 |
|
20433 | if (textStyle['wrap'] && !symbol['textWrapWidth']) {
|
20434 | symbol['textWrapWidth'] = maxWidth;
|
20435 | }
|
20436 |
|
20437 | var hAlign = textStyle['horizontalAlignment'];
|
20438 | symbol['textDx'] = symbol['markerDx'] || 0;
|
20439 | var offsetX = symbol['markerWidth'] / 2 - padding[0];
|
20440 | if (hAlign === 'left') {
|
20441 | symbol['textHorizontalAlignment'] = 'right';
|
20442 | symbol['textDx'] = symbol['textDx'] - offsetX;
|
20443 | } else if (hAlign === 'right') {
|
20444 | symbol['textHorizontalAlignment'] = 'left';
|
20445 | symbol['textDx'] = symbol['textDx'] + offsetX;
|
20446 | }
|
20447 |
|
20448 | var vAlign = textStyle['verticalAlignment'];
|
20449 | symbol['textDy'] = symbol['markerDy'] || 0;
|
20450 | var offsetY = symbol['markerHeight'] / 2 - padding[1];
|
20451 | if (vAlign === 'top') {
|
20452 | symbol['textVerticalAlignment'] = 'bottom';
|
20453 | symbol['textDy'] -= offsetY;
|
20454 | } else if (vAlign === 'bottom') {
|
20455 | symbol['textVerticalAlignment'] = 'top';
|
20456 | symbol['textDy'] += offsetY;
|
20457 | }
|
20458 | this._refreshing = true;
|
20459 | this.updateSymbol(symbol);
|
20460 | delete this._refreshing;
|
20461 | };
|
20462 |
|
20463 | return TextBox;
|
20464 | }(TextMarker);
|
20465 |
|
20466 | TextBox.mergeOptions(options$14);
|
20467 |
|
20468 | TextBox.registerJSONType('TextBox');
|
20469 |
|
20470 | var options$15 = {
|
20471 | 'boxStyle': null,
|
20472 | textSymbol: null
|
20473 | };
|
20474 |
|
20475 | var Label = function (_TextMarker) {
|
20476 | inherits(Label, _TextMarker);
|
20477 |
|
20478 | function Label(content, coordinates) {
|
20479 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
20480 | classCallCheck(this, Label);
|
20481 |
|
20482 | var _this = possibleConstructorReturn(this, _TextMarker.call(this, coordinates, options));
|
20483 |
|
20484 | if (options.textSymbol) {
|
20485 | _this.setTextSymbol(options.textSymbol);
|
20486 | }
|
20487 | if (options.boxStyle) {
|
20488 | _this.setBoxStyle(options.boxStyle);
|
20489 | }
|
20490 | _this._content = escapeSpecialChars(content);
|
20491 | _this._refresh();
|
20492 | return _this;
|
20493 | }
|
20494 |
|
20495 | Label.prototype.getBoxStyle = function getBoxStyle() {
|
20496 | if (!this.options.boxStyle) {
|
20497 | return null;
|
20498 | }
|
20499 | return extend({}, this.options.boxStyle);
|
20500 | };
|
20501 |
|
20502 | Label.prototype.setBoxStyle = function setBoxStyle(style) {
|
20503 | this.options.boxStyle = style ? extend({}, style) : style;
|
20504 | this._refresh();
|
20505 | return this;
|
20506 | };
|
20507 |
|
20508 | Label.prototype.getTextSymbol = function getTextSymbol() {
|
20509 | return extend({}, this._getDefaultTextSymbol(), this.options.textSymbol);
|
20510 | };
|
20511 |
|
20512 | Label.prototype.setTextSymbol = function setTextSymbol(symbol) {
|
20513 | this.options.textSymbol = symbol ? extend({}, symbol) : symbol;
|
20514 | this._refresh();
|
20515 | return this;
|
20516 | };
|
20517 |
|
20518 | Label.fromJSON = function fromJSON(json) {
|
20519 | var feature = json['feature'];
|
20520 | var label = new Label(json['content'], feature['geometry']['coordinates'], json['options']);
|
20521 | label.setProperties(feature['properties']);
|
20522 | label.setId(feature['id']);
|
20523 | if (json['symbol']) {
|
20524 | label.setSymbol(json['symbol']);
|
20525 | }
|
20526 | return label;
|
20527 | };
|
20528 |
|
20529 | Label.prototype._canEdit = function _canEdit() {
|
20530 | return false;
|
20531 | };
|
20532 |
|
20533 | Label.prototype._toJSON = function _toJSON(options) {
|
20534 | return {
|
20535 | 'feature': this.toGeoJSON(options),
|
20536 | 'subType': 'Label',
|
20537 | 'content': this._content
|
20538 | };
|
20539 | };
|
20540 |
|
20541 | Label.prototype._refresh = function _refresh() {
|
20542 | var symbol = extend({}, this.getTextSymbol(), {
|
20543 | 'textName': this._content
|
20544 | });
|
20545 |
|
20546 | var boxStyle = this.getBoxStyle();
|
20547 | if (boxStyle) {
|
20548 | extend(symbol, boxStyle.symbol);
|
20549 | var sizes = this._getBoxSize(symbol),
|
20550 | textSize = sizes[1],
|
20551 | padding = boxStyle['padding'] || this._getDefaultPadding();
|
20552 | var boxSize = sizes[0];
|
20553 |
|
20554 | symbol['markerWidth'] = boxSize['width'];
|
20555 | symbol['markerHeight'] = boxSize['height'];
|
20556 |
|
20557 | var dx = symbol['textDx'] || 0,
|
20558 | dy = symbol['textDy'] || 0,
|
20559 | textAlignPoint = getAlignPoint(textSize, symbol['textHorizontalAlignment'], symbol['textVerticalAlignment'])._add(dx, dy);
|
20560 |
|
20561 | var hAlign = boxStyle['horizontalAlignment'] || 'middle';
|
20562 | symbol['markerDx'] = textAlignPoint.x;
|
20563 | if (hAlign === 'left') {
|
20564 | symbol['markerDx'] += symbol['markerWidth'] / 2 - padding[0];
|
20565 | } else if (hAlign === 'right') {
|
20566 | symbol['markerDx'] -= symbol['markerWidth'] / 2 - textSize['width'] - padding[0];
|
20567 | } else {
|
20568 | symbol['markerDx'] += textSize['width'] / 2;
|
20569 | }
|
20570 |
|
20571 | var vAlign = boxStyle['verticalAlignment'] || 'middle';
|
20572 | symbol['markerDy'] = textAlignPoint.y;
|
20573 | if (vAlign === 'top') {
|
20574 | symbol['markerDy'] += symbol['markerHeight'] / 2 - padding[1];
|
20575 | } else if (vAlign === 'bottom') {
|
20576 | symbol['markerDy'] -= symbol['markerHeight'] / 2 - textSize['height'] - padding[1];
|
20577 | } else {
|
20578 | symbol['markerDy'] += textSize['height'] / 2;
|
20579 | }
|
20580 | }
|
20581 | this._refreshing = true;
|
20582 | this.updateSymbol(symbol);
|
20583 | delete this._refreshing;
|
20584 | };
|
20585 |
|
20586 | Label.prototype._getBoxSize = function _getBoxSize(symbol) {
|
20587 | if (!symbol['markerType']) {
|
20588 | symbol['markerType'] = 'square';
|
20589 | }
|
20590 | var boxStyle = this.getBoxStyle();
|
20591 | var size = this._getTextSize(symbol);
|
20592 | var width = void 0,
|
20593 | height = void 0;
|
20594 | var padding = boxStyle['padding'] || this._getDefaultPadding();
|
20595 | width = size['width'] + padding[0] * 2;
|
20596 | height = size['height'] + padding[1] * 2;
|
20597 | if (boxStyle['minWidth']) {
|
20598 | if (!width || width < boxStyle['minWidth']) {
|
20599 | width = boxStyle['minWidth'];
|
20600 | }
|
20601 | }
|
20602 | if (boxStyle['minHeight']) {
|
20603 | if (!height || height < boxStyle['minHeight']) {
|
20604 | height = boxStyle['minHeight'];
|
20605 | }
|
20606 | }
|
20607 | return [new Size(width, height), size];
|
20608 | };
|
20609 |
|
20610 | return Label;
|
20611 | }(TextMarker);
|
20612 |
|
20613 | Label.mergeOptions(options$15);
|
20614 |
|
20615 | Label.registerJSONType('Label');
|
20616 |
|
20617 | var Connectable = function Connectable(Base) {
|
20618 | return function (_Base) {
|
20619 | inherits(_class, _Base);
|
20620 |
|
20621 | function _class() {
|
20622 | classCallCheck(this, _class);
|
20623 | return possibleConstructorReturn(this, _Base.apply(this, arguments));
|
20624 | }
|
20625 |
|
20626 | _class._hasConnectors = function _hasConnectors(geometry) {
|
20627 | return !isNil(geometry.__connectors) && geometry.__connectors.length > 0;
|
20628 | };
|
20629 |
|
20630 | _class._getConnectors = function _getConnectors(geometry) {
|
20631 | return geometry.__connectors;
|
20632 | };
|
20633 |
|
20634 | _class.prototype.getConnectSource = function getConnectSource() {
|
20635 | return this._connSource;
|
20636 | };
|
20637 |
|
20638 | _class.prototype.setConnectSource = function setConnectSource(src) {
|
20639 | var target = this._connTarget;
|
20640 | this.onRemove();
|
20641 | this._connSource = src;
|
20642 | this._connTarget = target;
|
20643 | this.onAdd();
|
20644 | return this;
|
20645 | };
|
20646 |
|
20647 | _class.prototype.getConnectTarget = function getConnectTarget() {
|
20648 | return this._connTarget;
|
20649 | };
|
20650 |
|
20651 | _class.prototype.setConnectTarget = function setConnectTarget(target) {
|
20652 | var src = this._connSource;
|
20653 | this.onRemove();
|
20654 | this._connSource = src;
|
20655 | this._connTarget = target;
|
20656 | this._updateCoordinates();
|
20657 | this._registerEvents();
|
20658 | return this;
|
20659 | };
|
20660 |
|
20661 | _class.prototype._updateCoordinates = function _updateCoordinates() {
|
20662 | var map = this.getMap();
|
20663 | if (!map && this._connSource) {
|
20664 | map = this._connSource.getMap();
|
20665 | }
|
20666 | if (!map && this._connTarget) {
|
20667 | map = this._connTarget.getMap();
|
20668 | }
|
20669 | if (!map) {
|
20670 | return;
|
20671 | }
|
20672 | if (!this._connSource || !this._connTarget) {
|
20673 | return;
|
20674 | }
|
20675 | var srcPoints = this._connSource._getConnectPoints();
|
20676 | var targetPoints = this._connTarget._getConnectPoints();
|
20677 | var minDist = 0;
|
20678 | var oldCoordinates = this.getCoordinates();
|
20679 | var c1 = void 0,
|
20680 | c2 = void 0;
|
20681 | for (var i = 0, len = srcPoints.length; i < len; i++) {
|
20682 | var p1 = srcPoints[i];
|
20683 | for (var j = 0, length = targetPoints.length; j < length; j++) {
|
20684 | var p2 = targetPoints[j];
|
20685 | var dist = map.computeLength(p1, p2);
|
20686 | if (i === 0 && j === 0) {
|
20687 | c1 = p1;
|
20688 | c2 = p2;
|
20689 | minDist = dist;
|
20690 | } else if (dist < minDist) {
|
20691 | c1 = p1;
|
20692 | c2 = p2;
|
20693 | }
|
20694 | }
|
20695 | }
|
20696 | if (!isArrayHasData(oldCoordinates) || !oldCoordinates[0].equals(c1) || !oldCoordinates[1].equals(c2)) {
|
20697 | this.setCoordinates([c1, c2]);
|
20698 | }
|
20699 | };
|
20700 |
|
20701 | _class.prototype.onAdd = function onAdd() {
|
20702 | this._registerEvents();
|
20703 | this._updateCoordinates();
|
20704 | };
|
20705 |
|
20706 | _class.prototype.onRemove = function onRemove() {
|
20707 | if (this._connSource) {
|
20708 | if (this._connSource.__connectors) {
|
20709 | removeFromArray(this, this._connSource.__connectors);
|
20710 | }
|
20711 | this._connSource.off('dragging positionchange', this._updateCoordinates, this).off('remove', this.onRemove, this);
|
20712 | this._connSource.off('dragstart mousedown mouseover', this._showConnect, this);
|
20713 | this._connSource.off('dragend mouseup mouseout', this.hide, this);
|
20714 | this._connSource.off('show', this._showConnect, this).off('hide', this.hide, this);
|
20715 | delete this._connSource;
|
20716 | }
|
20717 | if (this._connTarget) {
|
20718 | removeFromArray(this, this._connTarget.__connectors);
|
20719 | this._connTarget.off('dragging positionchange', this._updateCoordinates, this).off('remove', this.onRemove, this);
|
20720 | this._connTarget.off('show', this._showConnect, this).off('hide', this.hide, this);
|
20721 | delete this._connTarget;
|
20722 | }
|
20723 |
|
20724 | if (!(this._connSource instanceof Geometry) || !(this._connTarget instanceof Geometry)) {
|
20725 | var map = this.getMap();
|
20726 | if (map) {
|
20727 | map.off('movestart moving moveend zoomstart zooming zoomend rotate pitch fovchange spatialreferencechange', this._updateCoordinates, this);
|
20728 | }
|
20729 | }
|
20730 | };
|
20731 |
|
20732 | _class.prototype._showConnect = function _showConnect() {
|
20733 | if (!this._connSource || !this._connTarget) {
|
20734 | return;
|
20735 | }
|
20736 | if (this._connSource.isVisible() && this._connTarget.isVisible()) {
|
20737 | this._updateCoordinates();
|
20738 | this.show();
|
20739 | }
|
20740 | };
|
20741 |
|
20742 | _class.prototype._registerEvents = function _registerEvents() {
|
20743 | if (!this._connSource || !this._connTarget) {
|
20744 | return;
|
20745 | }
|
20746 | if (!this._connSource.__connectors) {
|
20747 | this._connSource.__connectors = [];
|
20748 | }
|
20749 | if (!this._connTarget.__connectors) {
|
20750 | this._connTarget.__connectors = [];
|
20751 | }
|
20752 | this._connSource.__connectors.push(this);
|
20753 | this._connTarget.__connectors.push(this);
|
20754 | this._connSource.on('dragging positionchange', this._updateCoordinates, this).on('remove', this.remove, this);
|
20755 | this._connTarget.on('dragging positionchange', this._updateCoordinates, this).on('remove', this.remove, this);
|
20756 | this._connSource.on('show', this._showConnect, this).on('hide', this.hide, this);
|
20757 | this._connTarget.on('show', this._showConnect, this).on('hide', this.hide, this);
|
20758 | var trigger = this.options['showOn'];
|
20759 | this.hide();
|
20760 | if (trigger === 'moving') {
|
20761 | this._connSource.on('dragstart', this._showConnect, this).on('dragend', this.hide, this);
|
20762 | this._connTarget.on('dragstart', this._showConnect, this).on('dragend', this.hide, this);
|
20763 | } else if (trigger === 'click') {
|
20764 | this._connSource.on('mousedown', this._showConnect, this).on('mouseup', this.hide, this);
|
20765 | this._connTarget.on('mousedown', this._showConnect, this).on('mouseup', this.hide, this);
|
20766 | } else if (trigger === 'mouseover') {
|
20767 | this._connSource.on('mouseover', this._showConnect, this).on('mouseout', this.hide, this);
|
20768 | this._connTarget.on('mouseover', this._showConnect, this).on('mouseout', this.hide, this);
|
20769 | } else {
|
20770 | this._showConnect();
|
20771 | }
|
20772 |
|
20773 | if (!(this._connSource instanceof Geometry) || !(this._connTarget instanceof Geometry)) {
|
20774 | var map = this.getMap();
|
20775 | if (map) {
|
20776 | map.on('movestart moving moveend zoomstart zooming zoomend rotate pitch fovchange spatialreferencechange', this._updateCoordinates, this);
|
20777 | }
|
20778 | }
|
20779 | };
|
20780 |
|
20781 | return _class;
|
20782 | }(Base);
|
20783 | };
|
20784 |
|
20785 | var options$16 = {
|
20786 | showOn: 'always'
|
20787 | };
|
20788 |
|
20789 | var ConnectorLine = function (_Connectable) {
|
20790 | inherits(ConnectorLine, _Connectable);
|
20791 |
|
20792 | function ConnectorLine(src, target, options) {
|
20793 | classCallCheck(this, ConnectorLine);
|
20794 |
|
20795 | var _this2 = possibleConstructorReturn(this, _Connectable.call(this, null, options));
|
20796 |
|
20797 | if (arguments.length === 1) {
|
20798 | options = src;
|
20799 | src = null;
|
20800 | target = null;
|
20801 | }
|
20802 | _this2._connSource = src;
|
20803 | _this2._connTarget = target;
|
20804 | return _this2;
|
20805 | }
|
20806 |
|
20807 | return ConnectorLine;
|
20808 | }(Connectable(LineString));
|
20809 |
|
20810 | ConnectorLine.mergeOptions(options$16);
|
20811 |
|
20812 | ConnectorLine.registerJSONType('ConnectorLine');
|
20813 |
|
20814 | var ArcConnectorLine = function (_Connectable2) {
|
20815 | inherits(ArcConnectorLine, _Connectable2);
|
20816 |
|
20817 | function ArcConnectorLine(src, target, options) {
|
20818 | classCallCheck(this, ArcConnectorLine);
|
20819 |
|
20820 | var _this3 = possibleConstructorReturn(this, _Connectable2.call(this, null, options));
|
20821 |
|
20822 | if (arguments.length === 1) {
|
20823 | options = src;
|
20824 | src = null;
|
20825 | target = null;
|
20826 | }
|
20827 | _this3._connSource = src;
|
20828 | _this3._connTarget = target;
|
20829 | return _this3;
|
20830 | }
|
20831 |
|
20832 | return ArcConnectorLine;
|
20833 | }(Connectable(ArcCurve));
|
20834 |
|
20835 | ArcConnectorLine.mergeOptions(options$16);
|
20836 |
|
20837 | ArcConnectorLine.registerJSONType('ArcConnectorLine');
|
20838 |
|
20839 | var options$6 = {
|
20840 | 'drawImmediate': false
|
20841 | };
|
20842 |
|
20843 | var OverlayLayer = function (_Layer) {
|
20844 | inherits(OverlayLayer, _Layer);
|
20845 |
|
20846 | function OverlayLayer(id, geometries, options) {
|
20847 | classCallCheck(this, OverlayLayer);
|
20848 |
|
20849 | if (geometries && !(geometries instanceof Geometry) && !Array.isArray(geometries) && GEOJSON_TYPES.indexOf(geometries.type) < 0) {
|
20850 | options = geometries;
|
20851 | geometries = null;
|
20852 | }
|
20853 |
|
20854 | var _this = possibleConstructorReturn(this, _Layer.call(this, id, options));
|
20855 |
|
20856 | _this._maxZIndex = 0;
|
20857 | _this._minZIndex = 0;
|
20858 | _this._initCache();
|
20859 | if (geometries) {
|
20860 | _this.addGeometry(geometries);
|
20861 | }
|
20862 | return _this;
|
20863 | }
|
20864 |
|
20865 | OverlayLayer.prototype.getGeometryById = function getGeometryById(id) {
|
20866 | if (isNil(id) || id === '') {
|
20867 | return null;
|
20868 | }
|
20869 | if (!this._geoMap[id]) {
|
20870 | return null;
|
20871 | }
|
20872 | return this._geoMap[id];
|
20873 | };
|
20874 |
|
20875 | OverlayLayer.prototype.getGeometries = function getGeometries(filter, context) {
|
20876 | if (!filter) {
|
20877 | return this._geoList.slice(0);
|
20878 | }
|
20879 | var result = [];
|
20880 | var geometry = void 0,
|
20881 | filtered = void 0;
|
20882 | for (var i = 0, l = this._geoList.length; i < l; i++) {
|
20883 | geometry = this._geoList[i];
|
20884 | if (context) {
|
20885 | filtered = filter.call(context, geometry);
|
20886 | } else {
|
20887 | filtered = filter(geometry);
|
20888 | }
|
20889 | if (filtered) {
|
20890 | result.push(geometry);
|
20891 | }
|
20892 | }
|
20893 | return result;
|
20894 | };
|
20895 |
|
20896 | OverlayLayer.prototype.getFirstGeometry = function getFirstGeometry() {
|
20897 | if (!this._geoList.length) {
|
20898 | return null;
|
20899 | }
|
20900 | return this._geoList[0];
|
20901 | };
|
20902 |
|
20903 | OverlayLayer.prototype.getLastGeometry = function getLastGeometry() {
|
20904 | var len = this._geoList.length;
|
20905 | if (len === 0) {
|
20906 | return null;
|
20907 | }
|
20908 | return this._geoList[len - 1];
|
20909 | };
|
20910 |
|
20911 | OverlayLayer.prototype.getCount = function getCount() {
|
20912 | return this._geoList.length;
|
20913 | };
|
20914 |
|
20915 | OverlayLayer.prototype.getExtent = function getExtent() {
|
20916 | if (this.getCount() === 0) {
|
20917 | return null;
|
20918 | }
|
20919 | var extent = new Extent(this.getProjection());
|
20920 | this.forEach(function (g) {
|
20921 | extent._combine(g.getExtent());
|
20922 | });
|
20923 | return extent;
|
20924 | };
|
20925 |
|
20926 | OverlayLayer.prototype.forEach = function forEach(fn, context) {
|
20927 | var copyOnWrite = this._geoList.slice(0);
|
20928 | for (var i = 0, l = copyOnWrite.length; i < l; i++) {
|
20929 | if (!context) {
|
20930 | fn(copyOnWrite[i], i);
|
20931 | } else {
|
20932 | fn.call(context, copyOnWrite[i], i);
|
20933 | }
|
20934 | }
|
20935 | return this;
|
20936 | };
|
20937 |
|
20938 | OverlayLayer.prototype.filter = function filter() {
|
20939 | return GeometryCollection.prototype.filter.apply(this, arguments);
|
20940 | };
|
20941 |
|
20942 | OverlayLayer.prototype.isEmpty = function isEmpty() {
|
20943 | return !this._geoList.length;
|
20944 | };
|
20945 |
|
20946 | OverlayLayer.prototype.addGeometry = function addGeometry(geometries, fitView) {
|
20947 | if (!geometries) {
|
20948 | return this;
|
20949 | }
|
20950 | if (geometries.type === 'FeatureCollection') {
|
20951 | return this.addGeometry(GeoJSON.toGeometry(geometries), fitView);
|
20952 | } else if (!Array.isArray(geometries)) {
|
20953 | var count = arguments.length;
|
20954 | var last = arguments[count - 1];
|
20955 | geometries = Array.prototype.slice.call(arguments, 0, count - 1);
|
20956 | fitView = last;
|
20957 | if (isObject(last)) {
|
20958 | geometries.push(last);
|
20959 | fitView = false;
|
20960 | }
|
20961 | return this.addGeometry(geometries, fitView);
|
20962 | } else if (geometries.length === 0) {
|
20963 | return this;
|
20964 | }
|
20965 | this._initCache();
|
20966 | var extent = void 0;
|
20967 | if (fitView === true) {
|
20968 | extent = new Extent();
|
20969 | }
|
20970 | this._toSort = this._maxZIndex > 0;
|
20971 | var geos = [];
|
20972 | for (var i = 0, l = geometries.length; i < l; i++) {
|
20973 | var geo = geometries[i];
|
20974 | if (!geo) {
|
20975 | throw new Error('Invalid geometry to add to layer(' + this.getId() + ') at index:' + i);
|
20976 | }
|
20977 | if (!(geo instanceof Geometry)) {
|
20978 | geo = Geometry.fromJSON(geo);
|
20979 | if (Array.isArray(geo)) {
|
20980 | for (var ii = 0, ll = geo.length; ii < ll; ii++) {
|
20981 | this._add(geo[ii], extent, i);
|
20982 | geos.push(geo[ii]);
|
20983 | }
|
20984 | }
|
20985 | }
|
20986 | if (!Array.isArray(geo)) {
|
20987 | this._add(geo, extent, i);
|
20988 | geos.push(geo);
|
20989 | }
|
20990 | }
|
20991 | var map = this.getMap();
|
20992 | if (map) {
|
20993 | this._getRenderer().onGeometryAdd(geos);
|
20994 | if (fitView === true && !isNil(extent.xmin)) {
|
20995 | var z = map.getFitZoom(extent);
|
20996 | map.setCenterAndZoom(extent.getCenter(), z);
|
20997 | }
|
20998 | }
|
20999 |
|
21000 | this.fire('addgeo', {
|
21001 | 'geometries': geometries
|
21002 | });
|
21003 | return this;
|
21004 | };
|
21005 |
|
21006 | OverlayLayer.prototype.getGeoMinZIndex = function getGeoMinZIndex() {
|
21007 | return this._minZIndex;
|
21008 | };
|
21009 |
|
21010 | OverlayLayer.prototype.getGeoMaxZIndex = function getGeoMaxZIndex() {
|
21011 | return this._maxZIndex;
|
21012 | };
|
21013 |
|
21014 | OverlayLayer.prototype._add = function _add(geo, extent, i) {
|
21015 | if (!this._toSort) {
|
21016 | this._toSort = geo.getZIndex() !== 0;
|
21017 | }
|
21018 | this._updateZIndex(geo.getZIndex());
|
21019 | var geoId = geo.getId();
|
21020 | if (!isNil(geoId)) {
|
21021 | if (!isNil(this._geoMap[geoId])) {
|
21022 | throw new Error('Duplicate geometry id in layer(' + this.getId() + '):' + geoId + ', at index:' + i);
|
21023 | }
|
21024 | this._geoMap[geoId] = geo;
|
21025 | }
|
21026 | var internalId = UID();
|
21027 | geo._setInternalId(internalId);
|
21028 | this._geoList.push(geo);
|
21029 | if (this.onAddGeometry) {
|
21030 | this.onAddGeometry(geo);
|
21031 | }
|
21032 | geo._bindLayer(this);
|
21033 | if (geo.onAdd) {
|
21034 | geo.onAdd();
|
21035 | }
|
21036 | if (extent) {
|
21037 | extent._combine(geo.getExtent());
|
21038 | }
|
21039 |
|
21040 | geo._fireEvent('add', {
|
21041 | 'layer': this
|
21042 | });
|
21043 | };
|
21044 |
|
21045 | OverlayLayer.prototype.removeGeometry = function removeGeometry(geometries) {
|
21046 | if (!Array.isArray(geometries)) {
|
21047 | return this.removeGeometry([geometries]);
|
21048 | }
|
21049 | for (var i = geometries.length - 1; i >= 0; i--) {
|
21050 | if (!(geometries[i] instanceof Geometry)) {
|
21051 | geometries[i] = this.getGeometryById(geometries[i]);
|
21052 | }
|
21053 | if (!geometries[i] || this !== geometries[i].getLayer()) continue;
|
21054 | geometries[i].remove();
|
21055 | }
|
21056 |
|
21057 | this.fire('removegeo', {
|
21058 | 'geometries': geometries
|
21059 | });
|
21060 | return this;
|
21061 | };
|
21062 |
|
21063 | OverlayLayer.prototype.clear = function clear() {
|
21064 | this._clearing = true;
|
21065 | this.forEach(function (geo) {
|
21066 | geo.remove();
|
21067 | });
|
21068 | this._geoMap = {};
|
21069 | var old = this._geoList;
|
21070 | this._geoList = [];
|
21071 | if (this._getRenderer()) {
|
21072 | this._getRenderer().onGeometryRemove(old);
|
21073 | }
|
21074 | this._clearing = false;
|
21075 |
|
21076 | this.fire('clear');
|
21077 | return this;
|
21078 | };
|
21079 |
|
21080 | OverlayLayer.prototype.onRemoveGeometry = function onRemoveGeometry(geometry) {
|
21081 | if (!geometry || this._clearing) {
|
21082 | return;
|
21083 | }
|
21084 |
|
21085 | if (this !== geometry.getLayer()) {
|
21086 | return;
|
21087 | }
|
21088 | var internalId = geometry._getInternalId();
|
21089 | if (isNil(internalId)) {
|
21090 | return;
|
21091 | }
|
21092 | var geoId = geometry.getId();
|
21093 | if (!isNil(geoId)) {
|
21094 | delete this._geoMap[geoId];
|
21095 | }
|
21096 | var idx = this._findInList(geometry);
|
21097 | if (idx >= 0) {
|
21098 | this._geoList.splice(idx, 1);
|
21099 | }
|
21100 | if (this._getRenderer()) {
|
21101 | this._getRenderer().onGeometryRemove([geometry]);
|
21102 | }
|
21103 | };
|
21104 |
|
21105 | OverlayLayer.prototype.hide = function hide() {
|
21106 | for (var i = 0, l = this._geoList.length; i < l; i++) {
|
21107 | this._geoList[i].onHide();
|
21108 | }
|
21109 | return Layer.prototype.hide.call(this);
|
21110 | };
|
21111 |
|
21112 | OverlayLayer.prototype.identify = function identify(coordinate) {
|
21113 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
21114 |
|
21115 | return this._hitGeos(this._geoList, coordinate, options);
|
21116 | };
|
21117 |
|
21118 | OverlayLayer.prototype._hitGeos = function _hitGeos(geometries, coordinate) {
|
21119 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
21120 |
|
21121 | var filter = options['filter'],
|
21122 | tolerance = options['tolerance'],
|
21123 | hits = [];
|
21124 | var map = this.getMap();
|
21125 | var point = map.coordToPoint(coordinate);
|
21126 | var cp = map._pointToContainerPoint(point);
|
21127 | for (var i = geometries.length - 1; i >= 0; i--) {
|
21128 | var geo = geometries[i];
|
21129 | if (!geo || !geo.isVisible() || !geo._getPainter()) {
|
21130 | continue;
|
21131 | }
|
21132 | if (!(geo instanceof LineString) || !geo._getArrowStyle() && !(geo instanceof Curve)) {
|
21133 | var extent = geo.getContainerExtent();
|
21134 | if (tolerance) {
|
21135 | extent = extent.expand(tolerance);
|
21136 | }
|
21137 | if (!extent || !extent.contains(cp)) {
|
21138 | continue;
|
21139 | }
|
21140 | }
|
21141 | if (geo._containsPoint(cp, tolerance) && (!filter || filter(geo))) {
|
21142 | hits.push(geo);
|
21143 | if (options['count']) {
|
21144 | if (hits.length >= options['count']) {
|
21145 | break;
|
21146 | }
|
21147 | }
|
21148 | }
|
21149 | }
|
21150 | return hits;
|
21151 | };
|
21152 |
|
21153 | OverlayLayer.prototype._initCache = function _initCache() {
|
21154 | if (!this._geoList) {
|
21155 | this._geoList = [];
|
21156 | this._geoMap = {};
|
21157 | }
|
21158 | };
|
21159 |
|
21160 | OverlayLayer.prototype._updateZIndex = function _updateZIndex() {
|
21161 | for (var _len = arguments.length, zIndex = Array(_len), _key = 0; _key < _len; _key++) {
|
21162 | zIndex[_key] = arguments[_key];
|
21163 | }
|
21164 |
|
21165 | this._maxZIndex = Math.max(this._maxZIndex, Math.max.apply(Math, zIndex));
|
21166 | this._minZIndex = Math.min(this._minZIndex, Math.min.apply(Math, zIndex));
|
21167 | };
|
21168 |
|
21169 | OverlayLayer.prototype._sortGeometries = function _sortGeometries() {
|
21170 | var _this2 = this;
|
21171 |
|
21172 | if (!this._toSort) {
|
21173 | return;
|
21174 | }
|
21175 | this._maxZIndex = 0;
|
21176 | this._minZIndex = 0;
|
21177 | this._geoList.sort(function (a, b) {
|
21178 | _this2._updateZIndex(a.getZIndex(), b.getZIndex());
|
21179 | return _this2._compare(a, b);
|
21180 | });
|
21181 | this._toSort = false;
|
21182 | };
|
21183 |
|
21184 | OverlayLayer.prototype._compare = function _compare(a, b) {
|
21185 | if (a.getZIndex() === b.getZIndex()) {
|
21186 | return a._getInternalId() - b._getInternalId();
|
21187 | }
|
21188 | return a.getZIndex() - b.getZIndex();
|
21189 | };
|
21190 |
|
21191 | OverlayLayer.prototype._findInList = function _findInList(geo) {
|
21192 | var len = this._geoList.length;
|
21193 | if (len === 0) {
|
21194 | return -1;
|
21195 | }
|
21196 | var low = 0,
|
21197 | high = len - 1,
|
21198 | middle = void 0;
|
21199 | while (low <= high) {
|
21200 | middle = Math.floor((low + high) / 2);
|
21201 | if (this._geoList[middle] === geo) {
|
21202 | return middle;
|
21203 | } else if (this._compare(this._geoList[middle], geo) > 0) {
|
21204 | high = middle - 1;
|
21205 | } else {
|
21206 | low = middle + 1;
|
21207 | }
|
21208 | }
|
21209 | return -1;
|
21210 | };
|
21211 |
|
21212 | OverlayLayer.prototype._onGeometryEvent = function _onGeometryEvent(param) {
|
21213 | if (!param || !param['target']) {
|
21214 | return;
|
21215 | }
|
21216 | var type = param['type'];
|
21217 | if (type === 'idchange') {
|
21218 | this._onGeometryIdChange(param);
|
21219 | } else if (type === 'zindexchange') {
|
21220 | this._onGeometryZIndexChange(param);
|
21221 | } else if (type === 'positionchange') {
|
21222 | this._onGeometryPositionChange(param);
|
21223 | } else if (type === 'shapechange') {
|
21224 | this._onGeometryShapeChange(param);
|
21225 | } else if (type === 'symbolchange') {
|
21226 | this._onGeometrySymbolChange(param);
|
21227 | } else if (type === 'show') {
|
21228 | this._onGeometryShow(param);
|
21229 | } else if (type === 'hide') {
|
21230 | this._onGeometryHide(param);
|
21231 | } else if (type === 'propertieschange') {
|
21232 | this._onGeometryPropertiesChange(param);
|
21233 | }
|
21234 | };
|
21235 |
|
21236 | OverlayLayer.prototype._onGeometryIdChange = function _onGeometryIdChange(param) {
|
21237 | if (param['new'] === param['old']) {
|
21238 | if (this._geoMap[param['old']] && this._geoMap[param['old']] === param['target']) {
|
21239 | return;
|
21240 | }
|
21241 | }
|
21242 | if (!isNil(param['new'])) {
|
21243 | if (this._geoMap[param['new']]) {
|
21244 | throw new Error('Duplicate geometry id in layer(' + this.getId() + '):' + param['new']);
|
21245 | }
|
21246 | this._geoMap[param['new']] = param['target'];
|
21247 | }
|
21248 | if (!isNil(param['old']) && param['new'] !== param['old']) {
|
21249 | delete this._geoMap[param['old']];
|
21250 | }
|
21251 | };
|
21252 |
|
21253 | OverlayLayer.prototype._onGeometryZIndexChange = function _onGeometryZIndexChange(param) {
|
21254 | if (param['old'] !== param['new']) {
|
21255 | this._updateZIndex(param['new']);
|
21256 | this._toSort = true;
|
21257 | if (this._getRenderer()) {
|
21258 | this._getRenderer().onGeometryZIndexChange(param);
|
21259 | }
|
21260 | }
|
21261 | };
|
21262 |
|
21263 | OverlayLayer.prototype._onGeometryPositionChange = function _onGeometryPositionChange(param) {
|
21264 | if (this._getRenderer()) {
|
21265 | this._getRenderer().onGeometryPositionChange(param);
|
21266 | }
|
21267 | };
|
21268 |
|
21269 | OverlayLayer.prototype._onGeometryShapeChange = function _onGeometryShapeChange(param) {
|
21270 | if (this._getRenderer()) {
|
21271 | this._getRenderer().onGeometryShapeChange(param);
|
21272 | }
|
21273 | };
|
21274 |
|
21275 | OverlayLayer.prototype._onGeometrySymbolChange = function _onGeometrySymbolChange(param) {
|
21276 | if (this._getRenderer()) {
|
21277 | this._getRenderer().onGeometrySymbolChange(param);
|
21278 | }
|
21279 | };
|
21280 |
|
21281 | OverlayLayer.prototype._onGeometryShow = function _onGeometryShow(param) {
|
21282 | if (this._getRenderer()) {
|
21283 | this._getRenderer().onGeometryShow(param);
|
21284 | }
|
21285 | };
|
21286 |
|
21287 | OverlayLayer.prototype._onGeometryHide = function _onGeometryHide(param) {
|
21288 | if (this._getRenderer()) {
|
21289 | this._getRenderer().onGeometryHide(param);
|
21290 | }
|
21291 | };
|
21292 |
|
21293 | OverlayLayer.prototype._onGeometryPropertiesChange = function _onGeometryPropertiesChange(param) {
|
21294 | if (this._getRenderer()) {
|
21295 | this._getRenderer().onGeometryPropertiesChange(param);
|
21296 | }
|
21297 | };
|
21298 |
|
21299 | return OverlayLayer;
|
21300 | }(Layer);
|
21301 |
|
21302 | OverlayLayer.mergeOptions(options$6);
|
21303 |
|
21304 | var options$5 = {
|
21305 | 'debug': false,
|
21306 | 'enableSimplify': true,
|
21307 | 'geometryEvents': true,
|
21308 | 'defaultIconSize': [20, 20],
|
21309 | 'cacheVectorOnCanvas': true,
|
21310 | 'cacheSvgOnCanvas': Browser$1.gecko,
|
21311 | 'enableAltitude': false,
|
21312 | 'altitudeProperty': 'altitude',
|
21313 | 'drawAltitude': false
|
21314 | };
|
21315 |
|
21316 | var VectorLayer = function (_OverlayLayer) {
|
21317 | inherits(VectorLayer, _OverlayLayer);
|
21318 |
|
21319 | function VectorLayer(id, geometries, options) {
|
21320 | classCallCheck(this, VectorLayer);
|
21321 |
|
21322 | var _this = possibleConstructorReturn(this, _OverlayLayer.call(this, id, geometries, options));
|
21323 |
|
21324 | var style = _this.options['style'];
|
21325 | delete _this.options['style'];
|
21326 | if (style) {
|
21327 | _this.setStyle(style);
|
21328 | }
|
21329 | return _this;
|
21330 | }
|
21331 |
|
21332 | VectorLayer.prototype.getStyle = function getStyle() {
|
21333 | if (!this._style) {
|
21334 | return null;
|
21335 | }
|
21336 | return this._style;
|
21337 | };
|
21338 |
|
21339 | VectorLayer.prototype.setStyle = function setStyle(style) {
|
21340 | this._style = style;
|
21341 | this._cookedStyles = compileStyle(style);
|
21342 | this.forEach(function (geometry) {
|
21343 | this._styleGeometry(geometry);
|
21344 | }, this);
|
21345 |
|
21346 | this.fire('setstyle', {
|
21347 | 'style': style
|
21348 | });
|
21349 | return this;
|
21350 | };
|
21351 |
|
21352 | VectorLayer.prototype.removeStyle = function removeStyle() {
|
21353 | if (!this._style) {
|
21354 | return this;
|
21355 | }
|
21356 | delete this._style;
|
21357 | delete this._cookedStyles;
|
21358 | this.forEach(function (geometry) {
|
21359 | geometry._setExternSymbol(null);
|
21360 | }, this);
|
21361 |
|
21362 | this.fire('removestyle');
|
21363 | return this;
|
21364 | };
|
21365 |
|
21366 | VectorLayer.prototype.onAddGeometry = function onAddGeometry(geo) {
|
21367 | var style = this.getStyle();
|
21368 | if (style) {
|
21369 | this._styleGeometry(geo);
|
21370 | }
|
21371 | };
|
21372 |
|
21373 | VectorLayer.prototype.onConfig = function onConfig(conf) {
|
21374 | _OverlayLayer.prototype.onConfig.call(this, conf);
|
21375 | if (conf['enableAltitude'] || conf['drawAltitude'] || conf['altitudeProperty']) {
|
21376 | var renderer = this.getRenderer();
|
21377 | if (renderer && renderer.setToRedraw) {
|
21378 | renderer.setToRedraw();
|
21379 | }
|
21380 | }
|
21381 | };
|
21382 |
|
21383 | VectorLayer.prototype._styleGeometry = function _styleGeometry(geometry) {
|
21384 | if (!this._cookedStyles) {
|
21385 | return false;
|
21386 | }
|
21387 | var g = getFilterFeature(geometry);
|
21388 | for (var i = 0, len = this._cookedStyles.length; i < len; i++) {
|
21389 | if (this._cookedStyles[i]['filter'](g) === true) {
|
21390 | geometry._setExternSymbol(this._cookedStyles[i]['symbol']);
|
21391 | return true;
|
21392 | }
|
21393 | }
|
21394 | return false;
|
21395 | };
|
21396 |
|
21397 | VectorLayer.prototype.identify = function identify(coordinate) {
|
21398 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
21399 |
|
21400 | var renderer = this.getRenderer();
|
21401 |
|
21402 | if (options['onlyVisible'] && renderer && renderer.identify) {
|
21403 | return renderer.identify(coordinate, options);
|
21404 | }
|
21405 | return _OverlayLayer.prototype.identify.call(this, coordinate, options);
|
21406 | };
|
21407 |
|
21408 | VectorLayer.prototype.toJSON = function toJSON(options) {
|
21409 | if (!options) {
|
21410 | options = {};
|
21411 | }
|
21412 | var profile = {
|
21413 | 'type': this.getJSONType(),
|
21414 | 'id': this.getId(),
|
21415 | 'options': this.config()
|
21416 | };
|
21417 | if ((isNil(options['style']) || options['style']) && this.getStyle()) {
|
21418 | profile['style'] = this.getStyle();
|
21419 | }
|
21420 | if (isNil(options['geometries']) || options['geometries']) {
|
21421 | var clipExtent = void 0;
|
21422 | if (options['clipExtent']) {
|
21423 | var map = this.getMap();
|
21424 | var projection = map ? map.getProjection() : null;
|
21425 | clipExtent = new Extent(options['clipExtent'], projection);
|
21426 | }
|
21427 | var geoJSONs = [];
|
21428 | var geometries = this.getGeometries();
|
21429 | for (var i = 0, len = geometries.length; i < len; i++) {
|
21430 | var geo = geometries[i];
|
21431 | var geoExt = geo.getExtent();
|
21432 | if (!geoExt || clipExtent && !clipExtent.intersects(geoExt)) {
|
21433 | continue;
|
21434 | }
|
21435 | var json = geo.toJSON(options['geometries']);
|
21436 | geoJSONs.push(json);
|
21437 | }
|
21438 | profile['geometries'] = geoJSONs;
|
21439 | }
|
21440 | return profile;
|
21441 | };
|
21442 |
|
21443 | VectorLayer.fromJSON = function fromJSON(json) {
|
21444 | if (!json || json['type'] !== 'VectorLayer') {
|
21445 | return null;
|
21446 | }
|
21447 | var layer = new VectorLayer(json['id'], json['options']);
|
21448 | var geoJSONs = json['geometries'];
|
21449 | var geometries = [];
|
21450 | for (var i = 0; i < geoJSONs.length; i++) {
|
21451 | var geo = Geometry.fromJSON(geoJSONs[i]);
|
21452 | if (geo) {
|
21453 | geometries.push(geo);
|
21454 | }
|
21455 | }
|
21456 | layer.addGeometry(geometries);
|
21457 | if (json['style']) {
|
21458 | layer.setStyle(json['style']);
|
21459 | }
|
21460 | return layer;
|
21461 | };
|
21462 |
|
21463 | return VectorLayer;
|
21464 | }(OverlayLayer);
|
21465 |
|
21466 | VectorLayer.mergeOptions(options$5);
|
21467 |
|
21468 | VectorLayer.registerJSONType('VectorLayer');
|
21469 |
|
21470 | var key = '_map_tool';
|
21471 |
|
21472 | var MapTool = function (_Eventable) {
|
21473 | inherits(MapTool, _Eventable);
|
21474 |
|
21475 | function MapTool() {
|
21476 | classCallCheck(this, MapTool);
|
21477 | return possibleConstructorReturn(this, _Eventable.apply(this, arguments));
|
21478 | }
|
21479 |
|
21480 | MapTool.prototype.addTo = function addTo(map) {
|
21481 | if (!map) {
|
21482 | return this;
|
21483 | }
|
21484 | this._map = map;
|
21485 |
|
21486 | if (map[key]) {
|
21487 | map[key].disable();
|
21488 | }
|
21489 | if (this.onAdd) {
|
21490 | this.onAdd();
|
21491 | }
|
21492 | this.enable();
|
21493 | map[key] = this;
|
21494 |
|
21495 | this._fireEvent('add');
|
21496 | return this;
|
21497 | };
|
21498 |
|
21499 | MapTool.prototype.getMap = function getMap() {
|
21500 | return this._map;
|
21501 | };
|
21502 |
|
21503 | MapTool.prototype.enable = function enable() {
|
21504 | var map = this._map;
|
21505 | if (!map || this._enabled) {
|
21506 | return this;
|
21507 | }
|
21508 | this._enabled = true;
|
21509 | this._switchEvents('off');
|
21510 |
|
21511 | this._registerEvents();
|
21512 | if (this.onEnable) {
|
21513 | this.onEnable();
|
21514 | }
|
21515 |
|
21516 | this._fireEvent('enable');
|
21517 | return this;
|
21518 | };
|
21519 |
|
21520 | MapTool.prototype.disable = function disable() {
|
21521 | if (!this._enabled || !this._map) {
|
21522 | return this;
|
21523 | }
|
21524 | this._enabled = false;
|
21525 | this._switchEvents('off');
|
21526 | if (this.onDisable) {
|
21527 | this.onDisable();
|
21528 | }
|
21529 |
|
21530 | this._fireEvent('disable');
|
21531 | return this;
|
21532 | };
|
21533 |
|
21534 | MapTool.prototype.isEnabled = function isEnabled() {
|
21535 | if (!this._enabled) {
|
21536 | return false;
|
21537 | }
|
21538 | return true;
|
21539 | };
|
21540 |
|
21541 | MapTool.prototype.remove = function remove() {
|
21542 | if (!this._map) {
|
21543 | return this;
|
21544 | }
|
21545 | this.disable();
|
21546 | if (this._map) {
|
21547 | delete this._map[key];
|
21548 | delete this._map;
|
21549 | }
|
21550 |
|
21551 | this._fireEvent('remove');
|
21552 | return this;
|
21553 | };
|
21554 |
|
21555 | MapTool.prototype._registerEvents = function _registerEvents() {
|
21556 | this._switchEvents('on');
|
21557 | };
|
21558 |
|
21559 | MapTool.prototype._switchEvents = function _switchEvents(to) {
|
21560 | var events = this.getEvents();
|
21561 | if (events) {
|
21562 | this._map[to](events, this);
|
21563 | }
|
21564 | };
|
21565 |
|
21566 | MapTool.prototype._fireEvent = function _fireEvent(eventName, param) {
|
21567 | if (!param) {
|
21568 | param = {};
|
21569 | }
|
21570 | this.fire(eventName, param);
|
21571 | };
|
21572 |
|
21573 | return MapTool;
|
21574 | }(Eventable(Class));
|
21575 |
|
21576 | var options$3 = {
|
21577 | 'symbol': {
|
21578 | 'lineColor': '#000',
|
21579 | 'lineWidth': 2,
|
21580 | 'lineOpacity': 1,
|
21581 | 'polygonFill': '#fff',
|
21582 | 'polygonOpacity': 0.3
|
21583 | },
|
21584 | 'doubleClickZoom': false,
|
21585 | 'mode': null,
|
21586 | 'once': false,
|
21587 | 'ignoreMouseleave': true
|
21588 | };
|
21589 |
|
21590 | var registeredMode = {};
|
21591 |
|
21592 | var DrawTool = function (_MapTool) {
|
21593 | inherits(DrawTool, _MapTool);
|
21594 |
|
21595 | DrawTool.registerMode = function registerMode(name, modeAction) {
|
21596 | registeredMode[name.toLowerCase()] = modeAction;
|
21597 | };
|
21598 |
|
21599 | DrawTool.getRegisterMode = function getRegisterMode(name) {
|
21600 | return registeredMode[name.toLowerCase()];
|
21601 | };
|
21602 |
|
21603 | function DrawTool(options) {
|
21604 | classCallCheck(this, DrawTool);
|
21605 |
|
21606 | var _this = possibleConstructorReturn(this, _MapTool.call(this, options));
|
21607 |
|
21608 | _this._checkMode();
|
21609 |
|
21610 | _this._events = {
|
21611 | 'click': _this._firstClickHandler,
|
21612 | 'mousemove': _this._mouseMoveHandler,
|
21613 | 'dblclick': _this._doubleClickHandler,
|
21614 | 'mousedown': _this._mouseDownHandler,
|
21615 | 'mouseup': _this._mouseUpHandler
|
21616 | };
|
21617 | return _this;
|
21618 | }
|
21619 |
|
21620 | DrawTool.prototype.getMode = function getMode() {
|
21621 | if (this.options['mode']) {
|
21622 | return this.options['mode'].toLowerCase();
|
21623 | }
|
21624 | return null;
|
21625 | };
|
21626 |
|
21627 | DrawTool.prototype.setMode = function setMode(mode) {
|
21628 | if (this._geometry) {
|
21629 | this._geometry.remove();
|
21630 | delete this._geometry;
|
21631 | }
|
21632 | this._clearStage();
|
21633 | this._switchEvents('off');
|
21634 | this.options['mode'] = mode;
|
21635 | this._checkMode();
|
21636 | if (this.isEnabled()) {
|
21637 | this._switchEvents('on');
|
21638 | this._restoreMapCfg();
|
21639 | this._saveMapCfg();
|
21640 | }
|
21641 | return this;
|
21642 | };
|
21643 |
|
21644 | DrawTool.prototype.getSymbol = function getSymbol() {
|
21645 | var symbol = this.options['symbol'];
|
21646 | if (symbol) {
|
21647 | return extendSymbol(symbol);
|
21648 | } else {
|
21649 | return extendSymbol(this.options['symbol']);
|
21650 | }
|
21651 | };
|
21652 |
|
21653 | DrawTool.prototype.setSymbol = function setSymbol(symbol) {
|
21654 | if (!symbol) {
|
21655 | return this;
|
21656 | }
|
21657 | this.options['symbol'] = symbol;
|
21658 | if (this._geometry) {
|
21659 | this._geometry.setSymbol(symbol);
|
21660 | }
|
21661 | return this;
|
21662 | };
|
21663 |
|
21664 | DrawTool.prototype.getCurrentGeometry = function getCurrentGeometry() {
|
21665 | return this._geometry;
|
21666 | };
|
21667 |
|
21668 | DrawTool.prototype.onAdd = function onAdd() {
|
21669 | this._checkMode();
|
21670 | };
|
21671 |
|
21672 | DrawTool.prototype.onEnable = function onEnable() {
|
21673 | this._saveMapCfg();
|
21674 | this._drawToolLayer = this._getDrawLayer();
|
21675 | this._clearStage();
|
21676 | this._loadResources();
|
21677 | return this;
|
21678 | };
|
21679 |
|
21680 | DrawTool.prototype.onDisable = function onDisable() {
|
21681 | var map = this.getMap();
|
21682 | this._restoreMapCfg();
|
21683 | this.endDraw();
|
21684 | if (this._map) {
|
21685 | map.removeLayer(this._getDrawLayer());
|
21686 | }
|
21687 | return this;
|
21688 | };
|
21689 |
|
21690 | DrawTool.prototype.undo = function undo() {
|
21691 | var registerMode = this._getRegisterMode();
|
21692 | var action = registerMode.action;
|
21693 | if (!this._shouldRecordHistory(action) || !this._historyPointer) {
|
21694 | return this;
|
21695 | }
|
21696 | var coords = this._clickCoords.slice(0, --this._historyPointer);
|
21697 | registerMode.update(coords, this._geometry);
|
21698 | return this;
|
21699 | };
|
21700 |
|
21701 | DrawTool.prototype.redo = function redo() {
|
21702 | var registerMode = this._getRegisterMode();
|
21703 | var action = registerMode.action;
|
21704 | if (!this._shouldRecordHistory(action) || isNil(this._historyPointer) || this._historyPointer === this._clickCoords.length) {
|
21705 | return this;
|
21706 | }
|
21707 | var coords = this._clickCoords.slice(0, ++this._historyPointer);
|
21708 | registerMode.update(coords, this._geometry);
|
21709 | return this;
|
21710 | };
|
21711 |
|
21712 | DrawTool.prototype._shouldRecordHistory = function _shouldRecordHistory(actions) {
|
21713 | return Array.isArray(actions) && actions[0] === 'click' && actions[1] === 'mousemove' && actions[2] === 'dblclick';
|
21714 | };
|
21715 |
|
21716 | DrawTool.prototype._checkMode = function _checkMode() {
|
21717 | this._getRegisterMode();
|
21718 | };
|
21719 |
|
21720 | DrawTool.prototype._saveMapCfg = function _saveMapCfg() {
|
21721 | var map = this.getMap();
|
21722 | this._mapDoubleClickZoom = map.options['doubleClickZoom'];
|
21723 | map.config({
|
21724 | 'doubleClickZoom': this.options['doubleClickZoom']
|
21725 | });
|
21726 | var actions = this._getRegisterMode()['action'];
|
21727 | if (actions.indexOf('mousedown') > -1) {
|
21728 | var _map = this.getMap();
|
21729 | this._mapDraggable = _map.options['draggable'];
|
21730 | _map.config({
|
21731 | 'draggable': false
|
21732 | });
|
21733 | }
|
21734 | };
|
21735 |
|
21736 | DrawTool.prototype._restoreMapCfg = function _restoreMapCfg() {
|
21737 | var map = this.getMap();
|
21738 | map.config({
|
21739 | 'doubleClickZoom': this._mapDoubleClickZoom
|
21740 | });
|
21741 | if (!isNil(this._mapDraggable)) {
|
21742 | map.config('draggable', this._mapDraggable);
|
21743 | }
|
21744 | delete this._mapDraggable;
|
21745 | delete this._mapDoubleClickZoom;
|
21746 | };
|
21747 |
|
21748 | DrawTool.prototype._loadResources = function _loadResources() {
|
21749 | var symbol = this.getSymbol();
|
21750 | var resources = getExternalResources(symbol);
|
21751 | if (resources.length > 0) {
|
21752 | this._drawToolLayer._getRenderer().loadResources(resources);
|
21753 | }
|
21754 | };
|
21755 |
|
21756 | DrawTool.prototype._getProjection = function _getProjection() {
|
21757 | return this._map.getProjection();
|
21758 | };
|
21759 |
|
21760 | DrawTool.prototype._getRegisterMode = function _getRegisterMode() {
|
21761 | var mode = this.getMode();
|
21762 | var registerMode = DrawTool.getRegisterMode(mode);
|
21763 | if (!registerMode) {
|
21764 | throw new Error(mode + ' is not a valid mode of DrawTool.');
|
21765 | }
|
21766 | return registerMode;
|
21767 | };
|
21768 |
|
21769 | DrawTool.prototype.getEvents = function getEvents() {
|
21770 | var action = this._getRegisterMode()['action'];
|
21771 | var _events = {};
|
21772 | if (Array.isArray(action)) {
|
21773 | for (var i = 0; i < action.length; i++) {
|
21774 | _events[action[i]] = this._events[action[i]];
|
21775 | }
|
21776 | return _events;
|
21777 | }
|
21778 | return null;
|
21779 | };
|
21780 |
|
21781 | DrawTool.prototype._mouseDownHandler = function _mouseDownHandler(event) {
|
21782 | this._createGeometry(event);
|
21783 | };
|
21784 |
|
21785 | DrawTool.prototype._mouseUpHandler = function _mouseUpHandler(event) {
|
21786 | this.endDraw(event);
|
21787 | };
|
21788 |
|
21789 | DrawTool.prototype._firstClickHandler = function _firstClickHandler(event) {
|
21790 | var registerMode = this._getRegisterMode();
|
21791 | var coordinate = event['coordinate'];
|
21792 | if (!this._geometry) {
|
21793 | this._createGeometry(event);
|
21794 | } else {
|
21795 | if (!isNil(this._historyPointer)) {
|
21796 | this._clickCoords = this._clickCoords.slice(0, this._historyPointer);
|
21797 | }
|
21798 | this._clickCoords.push(coordinate);
|
21799 | this._historyPointer = this._clickCoords.length;
|
21800 | if (registerMode['clickLimit'] && registerMode['clickLimit'] === this._historyPointer) {
|
21801 | registerMode['update']([coordinate], this._geometry, event);
|
21802 | this.endDraw(event);
|
21803 | } else {
|
21804 | registerMode['update'](this._clickCoords, this._geometry, event);
|
21805 | }
|
21806 |
|
21807 | this._fireEvent('drawvertex', event);
|
21808 | }
|
21809 | };
|
21810 |
|
21811 | DrawTool.prototype._createGeometry = function _createGeometry(event) {
|
21812 | var mode = this.getMode();
|
21813 | var registerMode = this._getRegisterMode();
|
21814 | var coordinate = event['coordinate'];
|
21815 | var symbol = this.getSymbol();
|
21816 | if (!this._geometry) {
|
21817 | this._clickCoords = [coordinate];
|
21818 | this._geometry = registerMode['create'](this._clickCoords, event);
|
21819 | if (symbol && mode !== 'point') {
|
21820 | this._geometry.setSymbol(symbol);
|
21821 | } else if (this.options.hasOwnProperty('symbol')) {
|
21822 | this._geometry.setSymbol(this.options['symbol']);
|
21823 | }
|
21824 | this._addGeometryToStage(this._geometry);
|
21825 |
|
21826 | this._fireEvent('drawstart', event);
|
21827 | }
|
21828 | if (mode === 'point') {
|
21829 | this.endDraw(event);
|
21830 | }
|
21831 | };
|
21832 |
|
21833 | DrawTool.prototype._mouseMoveHandler = function _mouseMoveHandler(event) {
|
21834 | var map = this.getMap();
|
21835 | var coordinate = event['coordinate'];
|
21836 | if (!this._geometry || !map || map.isInteracting()) {
|
21837 | return;
|
21838 | }
|
21839 | var containerPoint = this._getMouseContainerPoint(event);
|
21840 | if (!this._isValidContainerPoint(containerPoint)) {
|
21841 | return;
|
21842 | }
|
21843 | var registerMode = this._getRegisterMode();
|
21844 | if (this._shouldRecordHistory(registerMode.action)) {
|
21845 | var path = this._clickCoords.slice(0, this._historyPointer);
|
21846 | if (path && path.length > 0 && coordinate.equals(path[path.length - 1])) {
|
21847 | return;
|
21848 | }
|
21849 | if (!(this._historyPointer === null)) {
|
21850 | this._clickCoords = this._clickCoords.slice(0, this._historyPointer);
|
21851 | }
|
21852 | this._historyPointer = this._clickCoords.length;
|
21853 | registerMode['update'](path.concat([coordinate]), this._geometry, event);
|
21854 | } else {
|
21855 | registerMode['update']([coordinate], this._geometry, event);
|
21856 | }
|
21857 |
|
21858 | this._fireEvent('mousemove', event);
|
21859 | };
|
21860 |
|
21861 | DrawTool.prototype._doubleClickHandler = function _doubleClickHandler(event) {
|
21862 | if (!this._geometry) {
|
21863 | return;
|
21864 | }
|
21865 | var containerPoint = this._getMouseContainerPoint(event);
|
21866 | if (!this._isValidContainerPoint(containerPoint)) {
|
21867 | return;
|
21868 | }
|
21869 | var registerMode = this._getRegisterMode();
|
21870 | var clickCoords = this._clickCoords;
|
21871 | if (clickCoords.length < 2) {
|
21872 | return;
|
21873 | }
|
21874 |
|
21875 | var path = [clickCoords[0]];
|
21876 | for (var i = 1, len = clickCoords.length; i < len; i++) {
|
21877 | if (clickCoords[i].x !== clickCoords[i - 1].x || clickCoords[i].y !== clickCoords[i - 1].y) {
|
21878 | path.push(clickCoords[i]);
|
21879 | }
|
21880 | }
|
21881 | if (path.length < 2 || this._geometry && this._geometry instanceof Polygon && path.length < 3) {
|
21882 | return;
|
21883 | }
|
21884 | registerMode['update'](path, this._geometry, event);
|
21885 | this.endDraw(event);
|
21886 | };
|
21887 |
|
21888 | DrawTool.prototype._addGeometryToStage = function _addGeometryToStage(geometry) {
|
21889 | var drawLayer = this._getDrawLayer();
|
21890 | drawLayer.addGeometry(geometry);
|
21891 | };
|
21892 |
|
21893 | DrawTool.prototype.endDraw = function endDraw(param) {
|
21894 | if (!this._geometry || this._ending) {
|
21895 | return this;
|
21896 | }
|
21897 | this._ending = true;
|
21898 | var geometry = this._geometry;
|
21899 | this._clearStage();
|
21900 | param = param || {};
|
21901 | this._geometry = geometry;
|
21902 |
|
21903 | this._fireEvent('drawend', param);
|
21904 | delete this._geometry;
|
21905 | if (this.options['once']) {
|
21906 | this.disable();
|
21907 | }
|
21908 | delete this._ending;
|
21909 | return this;
|
21910 | };
|
21911 |
|
21912 | DrawTool.prototype._clearStage = function _clearStage() {
|
21913 | this._getDrawLayer().clear();
|
21914 | delete this._geometry;
|
21915 | delete this._clickCoords;
|
21916 | };
|
21917 |
|
21918 | DrawTool.prototype._getMouseContainerPoint = function _getMouseContainerPoint(event) {
|
21919 | var action = this._getRegisterMode()['action'];
|
21920 | if (action === 'mousedown') {
|
21921 | stopPropagation(event['domEvent']);
|
21922 | }
|
21923 | return event['containerPoint'];
|
21924 | };
|
21925 |
|
21926 | DrawTool.prototype._isValidContainerPoint = function _isValidContainerPoint(containerPoint) {
|
21927 | var mapSize = this._map.getSize();
|
21928 | var w = mapSize['width'],
|
21929 | h = mapSize['height'];
|
21930 | if (containerPoint.x < 0 || containerPoint.y < 0) {
|
21931 | return false;
|
21932 | } else if (containerPoint.x > w || containerPoint.y > h) {
|
21933 | return false;
|
21934 | }
|
21935 | return true;
|
21936 | };
|
21937 |
|
21938 | DrawTool.prototype._getDrawLayer = function _getDrawLayer() {
|
21939 | var drawLayerId = INTERNAL_LAYER_PREFIX + 'drawtool';
|
21940 | var drawToolLayer = this._map.getLayer(drawLayerId);
|
21941 | if (!drawToolLayer) {
|
21942 | drawToolLayer = new VectorLayer(drawLayerId, {
|
21943 | 'enableSimplify': false
|
21944 | });
|
21945 | this._map.addLayer(drawToolLayer);
|
21946 | }
|
21947 | return drawToolLayer;
|
21948 | };
|
21949 |
|
21950 | DrawTool.prototype._fireEvent = function _fireEvent(eventName, param) {
|
21951 | if (!param) {
|
21952 | param = {};
|
21953 | }
|
21954 | if (this._geometry) {
|
21955 | param['geometry'] = this._getRegisterMode()['generate'](this._geometry).copy();
|
21956 | }
|
21957 | MapTool.prototype._fireEvent.call(this, eventName, param);
|
21958 | };
|
21959 |
|
21960 | return DrawTool;
|
21961 | }(MapTool);
|
21962 |
|
21963 | DrawTool.mergeOptions(options$3);
|
21964 |
|
21965 | var MapBoxZoomHander = function (_Handler) {
|
21966 | inherits(MapBoxZoomHander, _Handler);
|
21967 |
|
21968 | function MapBoxZoomHander(target) {
|
21969 | classCallCheck(this, MapBoxZoomHander);
|
21970 |
|
21971 | var _this = possibleConstructorReturn(this, _Handler.call(this, target));
|
21972 |
|
21973 | _this.drawTool = new DrawTool({
|
21974 | 'mode': 'boxZoom',
|
21975 | 'ignoreMouseleave': false
|
21976 | });
|
21977 | return _this;
|
21978 | }
|
21979 |
|
21980 | MapBoxZoomHander.prototype.addHooks = function addHooks() {
|
21981 | this.target.on('_mousedown', this._onMouseDown, this);
|
21982 | };
|
21983 |
|
21984 | MapBoxZoomHander.prototype.removeHooks = function removeHooks() {
|
21985 | this.target.off('_mousedown', this._onMouseDown, this);
|
21986 | if (this.drawTool.isEnabled()) {
|
21987 | this.drawTool.remove();
|
21988 | }
|
21989 | };
|
21990 |
|
21991 | MapBoxZoomHander.prototype._onMouseDown = function _onMouseDown(param) {
|
21992 | if (!this.target.options['boxZoom']) {
|
21993 | return;
|
21994 | }
|
21995 | if (param.domEvent.shiftKey) {
|
21996 | this.drawTool.setSymbol(this.target.options['boxZoomSymbol']).on('drawend', this._boxZoom, this).addTo(this.target);
|
21997 | }
|
21998 | };
|
21999 |
|
22000 | MapBoxZoomHander.prototype._boxZoom = function _boxZoom(param) {
|
22001 | var map = this.target;
|
22002 | this.drawTool.remove();
|
22003 | var geometry = param.geometry,
|
22004 | center = geometry.getCenter(),
|
22005 | symbol = geometry.getSymbol(),
|
22006 | w = symbol.markerWidth,
|
22007 | h = symbol.markerHeight;
|
22008 |
|
22009 | var extent = new Extent(center, map.locateByPoint(center, w, h), map.getProjection());
|
22010 | var zoom = map.getFitZoom(extent);
|
22011 | map.animateTo({
|
22012 | center: extent.getCenter(),
|
22013 | zoom: zoom
|
22014 | });
|
22015 | };
|
22016 |
|
22017 | return MapBoxZoomHander;
|
22018 | }(Handler$1);
|
22019 |
|
22020 | Map.mergeOptions({
|
22021 | 'boxZoom': true,
|
22022 | 'boxZoomSymbol': {
|
22023 | 'markerType': 'rectangle',
|
22024 | 'markerLineWidth': 3,
|
22025 | 'markerLineColor': '#1bbc9b',
|
22026 | 'markerLineDasharray': [10, 5],
|
22027 | 'markerFillOpacity': 0.1,
|
22028 | 'markerFill': '#1bbc9b',
|
22029 | 'markerWidth': 1,
|
22030 | 'markerHeight': 1
|
22031 | }
|
22032 | });
|
22033 |
|
22034 | Map.addOnLoadHook('addHandler', 'boxZoom', MapBoxZoomHander);
|
22035 |
|
22036 | function equalView(view1, view2) {
|
22037 | for (var p in view1) {
|
22038 | if (hasOwn(view1, p)) {
|
22039 | if (p === 'center') {
|
22040 | if (view1[p][0] !== view2[p][0] || view1[p][1] !== view2[p][1]) {
|
22041 | return false;
|
22042 | }
|
22043 | } else if (view1[p] !== view2[p]) {
|
22044 | return false;
|
22045 | }
|
22046 | }
|
22047 | }
|
22048 | return true;
|
22049 | }
|
22050 |
|
22051 | Map.include({
|
22052 | animateTo: function animateTo(view) {
|
22053 | var _this = this;
|
22054 |
|
22055 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
22056 | var step = arguments[2];
|
22057 |
|
22058 | this._stopAnim(this._animPlayer);
|
22059 | if (isFunction(options)) {
|
22060 | step = options;
|
22061 | options = {};
|
22062 | }
|
22063 | var projection = this.getProjection(),
|
22064 | currView = this.getView(),
|
22065 | props = {};
|
22066 | var empty = true;
|
22067 | for (var p in view) {
|
22068 | if (hasOwn(view, p) && !isNil(currView[p])) {
|
22069 | empty = false;
|
22070 | if (p === 'center') {
|
22071 | var from = new Coordinate(currView[p]).toFixed(7),
|
22072 | to = new Coordinate(view[p]).toFixed(7);
|
22073 | if (!from.equals(to)) {
|
22074 | props['center'] = [from, to];
|
22075 | }
|
22076 | } else if (currView[p] !== view[p] && p !== 'around') {
|
22077 | props[p] = [currView[p], view[p]];
|
22078 | }
|
22079 | }
|
22080 | }
|
22081 | if (empty) {
|
22082 | return null;
|
22083 | }
|
22084 | var zoomOrigin = view['around'] || new Point(this.width / 2, this.height / 2);
|
22085 | var preView = this.getView();
|
22086 | var renderer = this._getRenderer(),
|
22087 | framer = function framer(fn) {
|
22088 | renderer.callInNextFrame(fn);
|
22089 | };
|
22090 |
|
22091 | var player = this._animPlayer = Animation.animate(props, {
|
22092 | 'easing': options['easing'] || 'out',
|
22093 | 'duration': options['duration'] || this.options['zoomAnimationDuration'],
|
22094 | 'framer': framer
|
22095 | }, function (frame) {
|
22096 | if (_this.isRemoved()) {
|
22097 | player.finish();
|
22098 | return;
|
22099 | }
|
22100 | if (player.playState === 'running') {
|
22101 | var _view = _this.getView();
|
22102 | if (!options['continueOnViewChanged'] && !equalView(_view, preView)) {
|
22103 | _this._stopAnim(player);
|
22104 | return;
|
22105 | }
|
22106 | if (frame.styles['center']) {
|
22107 | var center = frame.styles['center'];
|
22108 | _this._setPrjCenter(projection.project(center));
|
22109 | _this.onMoving(_this._parseEventFromCoord(_this.getCenter()));
|
22110 | }
|
22111 | if (!isNil(frame.styles['zoom'])) {
|
22112 | _this.onZooming(frame.styles['zoom'], zoomOrigin);
|
22113 | }
|
22114 | if (!isNil(frame.styles['pitch'])) {
|
22115 | _this.setPitch(frame.styles['pitch']);
|
22116 | }
|
22117 | if (!isNil(frame.styles['bearing'])) {
|
22118 | _this.setBearing(frame.styles['bearing']);
|
22119 | }
|
22120 | preView = _this.getView();
|
22121 | _this._fireEvent('animating');
|
22122 | } else if (player.playState === 'finished') {
|
22123 | if (!player._interupted) {
|
22124 | if (props['center']) {
|
22125 | _this._setPrjCenter(projection.project(props['center'][1]));
|
22126 | }
|
22127 | if (!isNil(props['pitch'])) {
|
22128 | _this.setPitch(props['pitch'][1]);
|
22129 | }
|
22130 | if (!isNil(props['bearing'])) {
|
22131 | _this.setBearing(props['bearing'][1]);
|
22132 | }
|
22133 | }
|
22134 | _this._endAnim(player, props, zoomOrigin, options);
|
22135 | preView = _this.getView();
|
22136 | }
|
22137 | if (step) {
|
22138 | step(frame);
|
22139 | }
|
22140 | });
|
22141 |
|
22142 | this._startAnim(props, zoomOrigin);
|
22143 |
|
22144 | return player;
|
22145 | },
|
22146 | isAnimating: function isAnimating() {
|
22147 | return !!this._animPlayer;
|
22148 | },
|
22149 | isRotating: function isRotating() {
|
22150 | return this.isDragRotating() || !!this._animRotating;
|
22151 | },
|
22152 | _endAnim: function _endAnim(player, props, zoomOrigin, options) {
|
22153 | delete this._animRotating;
|
22154 | var evtType = player._interupted ? 'animateinterupted' : 'animateend';
|
22155 | if (player === this._animPlayer) {
|
22156 | delete this._animPlayer;
|
22157 | }
|
22158 | if (props['center']) {
|
22159 | var endCoord = void 0;
|
22160 | if (player._interupted) {
|
22161 | endCoord = this.getCenter();
|
22162 | } else {
|
22163 | endCoord = props['center'][1];
|
22164 | }
|
22165 | this.onMoveEnd(this._parseEventFromCoord(endCoord));
|
22166 | }
|
22167 | if (!isNil(props['zoom'])) {
|
22168 | if (player._interupted) {
|
22169 | this.onZoomEnd(this.getZoom(), zoomOrigin);
|
22170 | } else if (!options['wheelZoom']) {
|
22171 | this.onZoomEnd(props['zoom'][1], zoomOrigin);
|
22172 | } else {
|
22173 | this.onZooming(props['zoom'][1], zoomOrigin);
|
22174 | }
|
22175 | }
|
22176 | if (evtType) {
|
22177 | this._fireEvent(evtType);
|
22178 | }
|
22179 | },
|
22180 | _startAnim: function _startAnim(props, zoomOrigin) {
|
22181 | if (!this._animPlayer) {
|
22182 | return;
|
22183 | }
|
22184 | if (props['center']) {
|
22185 | this.onMoveStart();
|
22186 | }
|
22187 | if (props['zoom'] && !this.isZooming()) {
|
22188 | this.onZoomStart(props['zoom'][1], zoomOrigin);
|
22189 | }
|
22190 | if (props['pitch'] || props['bearing']) {
|
22191 | this._animRotating = true;
|
22192 | }
|
22193 | this._fireEvent('animatestart');
|
22194 | this._animPlayer.play();
|
22195 | },
|
22196 | _stopAnim: function _stopAnim(player) {
|
22197 | if (player && player.playState !== 'finished') {
|
22198 | player._interupted = true;
|
22199 | player.finish();
|
22200 | }
|
22201 | }
|
22202 | });
|
22203 |
|
22204 | var events = 'mousedown ' + 'mouseup ' + 'mouseover ' + 'mouseout ' + 'mouseenter ' + 'mouseleave ' + 'mousemove ' + 'click ' + 'dblclick ' + 'contextmenu ' + 'keypress ' + 'touchstart ' + 'touchmove ' + 'touchend ';
|
22205 |
|
22206 | Map.include({
|
22207 | _registerDomEvents: function _registerDomEvents() {
|
22208 | var dom = this._panels.mapWrapper || this._containerDOM;
|
22209 | addDomEvent(dom, events, this._handleDOMEvent, this);
|
22210 | },
|
22211 | _removeDomEvents: function _removeDomEvents() {
|
22212 | var dom = this._panels.mapWrapper || this._containerDOM;
|
22213 | removeDomEvent(dom, events, this._handleDOMEvent, this);
|
22214 | },
|
22215 | _handleDOMEvent: function _handleDOMEvent(e) {
|
22216 | var type = e.type;
|
22217 |
|
22218 | if (type === 'contextmenu') {
|
22219 | preventDefault(e);
|
22220 | }
|
22221 | if (this._ignoreEvent(e)) {
|
22222 | return;
|
22223 | }
|
22224 | var mimicClick = false;
|
22225 |
|
22226 | if (type === 'mousedown' || type === 'touchstart' && e.touches.length === 1) {
|
22227 | this._mouseDownTime = now();
|
22228 | } else if (type === 'click' || type === 'touchend' || type === 'contextmenu') {
|
22229 | if (!this._mouseDownTime) {
|
22230 | return;
|
22231 | } else {
|
22232 | var downTime = this._mouseDownTime;
|
22233 | delete this._mouseDownTime;
|
22234 | var time = now();
|
22235 | if (time - downTime > 300) {
|
22236 | if (type === 'click' || type === 'contextmenu') {
|
22237 | return;
|
22238 | }
|
22239 | } else if (type === 'touchend') {
|
22240 | mimicClick = true;
|
22241 | }
|
22242 | }
|
22243 | }
|
22244 | this._fireDOMEvent(this, e, type);
|
22245 | if (mimicClick) {
|
22246 | if (this._clickTime && now() - this._clickTime <= 300) {
|
22247 | delete this._clickTime;
|
22248 | this._fireDOMEvent(this, e, 'dblclick');
|
22249 | } else {
|
22250 | this._clickTime = now();
|
22251 | this._fireDOMEvent(this, e, 'click');
|
22252 | }
|
22253 | }
|
22254 | },
|
22255 | _ignoreEvent: function _ignoreEvent(domEvent) {
|
22256 | if (!domEvent || !this._panels.control) {
|
22257 | return false;
|
22258 | }
|
22259 | if (this._isEventOutMap(domEvent)) {
|
22260 | return true;
|
22261 | }
|
22262 | var target = domEvent.srcElement || domEvent.target;
|
22263 | var preTarget = void 0;
|
22264 | if (target) {
|
22265 | while (target && target !== this._containerDOM) {
|
22266 | if (target.className && target.className.indexOf && (target.className.indexOf('maptalks-control') >= 0 || target.className.indexOf('maptalks-ui') >= 0 && !preTarget['eventsPropagation'])) {
|
22267 | return true;
|
22268 | }
|
22269 | preTarget = target;
|
22270 | target = target.parentNode;
|
22271 | }
|
22272 | }
|
22273 | return false;
|
22274 | },
|
22275 | _isEventOutMap: function _isEventOutMap(domEvent) {
|
22276 | if (this.getPitch() > this.options['maxVisualPitch']) {
|
22277 | var actualEvent = this._getActualEvent(domEvent);
|
22278 | var eventPos = getEventContainerPoint(actualEvent, this._containerDOM);
|
22279 | if (!this.getContainerExtent().contains(eventPos)) {
|
22280 | return true;
|
22281 | }
|
22282 | }
|
22283 | return false;
|
22284 | },
|
22285 | _parseEvent: function _parseEvent(e, type) {
|
22286 | if (!e) {
|
22287 | return null;
|
22288 | }
|
22289 | var eventParam = {
|
22290 | 'domEvent': e
|
22291 | };
|
22292 | if (type !== 'keypress') {
|
22293 | var actual = this._getActualEvent(e);
|
22294 | if (actual) {
|
22295 | var containerPoint = getEventContainerPoint(actual, this._containerDOM);
|
22296 | eventParam = extend(eventParam, {
|
22297 | 'coordinate': this.containerPointToCoord(containerPoint),
|
22298 | 'containerPoint': containerPoint,
|
22299 | 'viewPoint': this.containerPointToViewPoint(containerPoint),
|
22300 | 'point2d': this._containerPointToPoint(containerPoint)
|
22301 | });
|
22302 | }
|
22303 | }
|
22304 | return eventParam;
|
22305 | },
|
22306 | _parseEventFromCoord: function _parseEventFromCoord(coord) {
|
22307 | var containerPoint = this.coordToContainerPoint(coord),
|
22308 | viewPoint = this.containerPointToViewPoint(containerPoint);
|
22309 | var e = {
|
22310 | 'coordinate': coord,
|
22311 | 'containerPoint': containerPoint,
|
22312 | 'viewPoint': viewPoint,
|
22313 | 'point2d': this.coordToPoint(coord)
|
22314 | };
|
22315 | return e;
|
22316 | },
|
22317 | _getActualEvent: function _getActualEvent(e) {
|
22318 | return e.touches && e.touches.length > 0 ? e.touches[0] : e.changedTouches && e.changedTouches.length > 0 ? e.changedTouches[0] : e;
|
22319 | },
|
22320 | _fireDOMEvent: function _fireDOMEvent(target, e, type) {
|
22321 | if (this.isRemoved()) {
|
22322 | return;
|
22323 | }
|
22324 | var eventParam = this._parseEvent(e, type);
|
22325 | this._fireEvent(type, eventParam);
|
22326 | }
|
22327 | });
|
22328 |
|
22329 | Map.addOnLoadHook('_registerDomEvents');
|
22330 |
|
22331 | Map.include({
|
22332 | isFullScreen: function isFullScreen() {
|
22333 | return !!(document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement || document.fullscreenElement);
|
22334 | },
|
22335 | requestFullScreen: function requestFullScreen(dom) {
|
22336 | this._fireEvent('fullscreenstart');
|
22337 | this._requestFullScreen(dom || this._containerDOM);
|
22338 |
|
22339 | this._fireEvent('fullscreenend');
|
22340 | return this;
|
22341 | },
|
22342 | cancelFullScreen: function cancelFullScreen() {
|
22343 | this._cancelFullScreen();
|
22344 |
|
22345 | this._fireEvent('cancelfullscreen');
|
22346 | return this;
|
22347 | },
|
22348 | _requestFullScreen: function _requestFullScreen(dom) {
|
22349 | if (dom.requestFullScreen) {
|
22350 | dom.requestFullScreen();
|
22351 | } else if (dom.mozRequestFullScreen) {
|
22352 | dom.mozRequestFullScreen();
|
22353 | } else if (dom.webkitRequestFullScreen) {
|
22354 | dom.webkitRequestFullScreen();
|
22355 | } else if (dom.msRequestFullScreen) {
|
22356 | dom.msRequestFullScreen();
|
22357 | } else {
|
22358 | var features = 'fullscreen=1,status=no,resizable=yes,top=0,left=0,scrollbars=no,' + 'titlebar=no,menubar=no,location=no,toolbar=no,z-look=yes,' + 'width=' + (screen.availWidth - 8) + ',height=' + (screen.availHeight - 45);
|
22359 | var newWin = window.open(location.href, '_blank', features);
|
22360 | if (newWin !== null) {
|
22361 | window.opener = null;
|
22362 |
|
22363 | window.close();
|
22364 | }
|
22365 | }
|
22366 | },
|
22367 | _cancelFullScreen: function _cancelFullScreen() {
|
22368 | if (document.cancelFullScreen) {
|
22369 | document.cancelFullScreen();
|
22370 | } else if (document.mozCancelFullScreen) {
|
22371 | document.mozCancelFullScreen();
|
22372 | } else if (document.webkitCancelFullScreen) {
|
22373 | document.webkitCancelFullScreen();
|
22374 | } else {
|
22375 | var features = 'fullscreen=no,status=yes,resizable=yes,scrollbars=no,' + 'titlebar=no,menubar=yes,location=yes,toolbar=yes,z-look=yes';
|
22376 | var newWin = window.open(location.href, '_blank', features);
|
22377 | if (newWin !== null) {
|
22378 | window.opener = null;
|
22379 |
|
22380 | window.close();
|
22381 | }
|
22382 | }
|
22383 | }
|
22384 | });
|
22385 |
|
22386 | Map.include({
|
22387 | panTo: function panTo(coordinate) {
|
22388 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
22389 | var step = arguments[2];
|
22390 |
|
22391 | if (!coordinate) {
|
22392 | return this;
|
22393 | }
|
22394 | if (isFunction(options)) {
|
22395 | step = options;
|
22396 | options = {};
|
22397 | }
|
22398 | coordinate = new Coordinate(coordinate);
|
22399 | if (typeof options['animation'] === 'undefined' || options['animation']) {
|
22400 | return this._panAnimation(coordinate, options['duration'], step);
|
22401 | } else {
|
22402 | this.setCenter(coordinate);
|
22403 | return this;
|
22404 | }
|
22405 | },
|
22406 |
|
22407 | panBy: function panBy(offset) {
|
22408 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
22409 | var step = arguments[2];
|
22410 |
|
22411 | if (!offset) {
|
22412 | return this;
|
22413 | }
|
22414 | if (isFunction(options)) {
|
22415 | step = options;
|
22416 | options = {};
|
22417 | }
|
22418 | offset = new Point(offset).multi(-1);
|
22419 | this.onMoveStart();
|
22420 | if (typeof options['animation'] === 'undefined' || options['animation']) {
|
22421 | var target = this.locateByPoint(this.getCenter(), offset.x, offset.y);
|
22422 | this._panAnimation(target, options['duration'], step);
|
22423 | } else {
|
22424 | this._offsetCenterByPixel(offset);
|
22425 | this.onMoveEnd(this._parseEventFromCoord(this.getCenter()));
|
22426 | }
|
22427 | return this;
|
22428 | },
|
22429 |
|
22430 | _panAnimation: function _panAnimation(target, t, cb) {
|
22431 | return this.animateTo({
|
22432 | 'center': target
|
22433 | }, {
|
22434 | 'duration': t || this.options['panAnimationDuration']
|
22435 | }, cb);
|
22436 | }
|
22437 | });
|
22438 |
|
22439 | Geometry.fromJSON = function (json) {
|
22440 | if (Array.isArray(json)) {
|
22441 | var result = [];
|
22442 | for (var i = 0, len = json.length; i < len; i++) {
|
22443 | var c = Geometry.fromJSON(json[i]);
|
22444 | if (Array.isArray(json)) {
|
22445 | result = result.concat(c);
|
22446 | } else {
|
22447 | result.push(c);
|
22448 | }
|
22449 | }
|
22450 | return result;
|
22451 | }
|
22452 |
|
22453 | if (json && !json['feature']) {
|
22454 | return GeoJSON.toGeometry(json);
|
22455 | }
|
22456 | var geometry = void 0;
|
22457 | if (json['subType']) {
|
22458 | geometry = Geometry.getJSONClass(json['subType']).fromJSON(json);
|
22459 | if (!isNil(json['feature']['id'])) {
|
22460 | geometry.setId(json['feature']['id']);
|
22461 | }
|
22462 | } else {
|
22463 | geometry = GeoJSON.toGeometry(json['feature']);
|
22464 | if (json['options']) {
|
22465 | geometry.config(json['options']);
|
22466 | }
|
22467 | }
|
22468 | if (json['symbol']) {
|
22469 | geometry.setSymbol(json['symbol']);
|
22470 | }
|
22471 | if (json['infoWindow']) {
|
22472 | geometry.setInfoWindow(json['infoWindow']);
|
22473 | }
|
22474 | return geometry;
|
22475 | };
|
22476 |
|
22477 | Layer.fromJSON = function (layerJSON) {
|
22478 | if (!layerJSON) {
|
22479 | return null;
|
22480 | }
|
22481 | var layerType = layerJSON['type'];
|
22482 | var clazz = Layer.getJSONClass(layerType);
|
22483 | if (!clazz || !clazz.fromJSON) {
|
22484 | throw new Error('unsupported layer type:' + layerType);
|
22485 | }
|
22486 | return clazz.fromJSON(layerJSON);
|
22487 | };
|
22488 |
|
22489 | Map.include({
|
22490 | 'JSON_VERSION': '1.0',
|
22491 |
|
22492 | toJSON: function toJSON(options) {
|
22493 | if (!options) {
|
22494 | options = {};
|
22495 | }
|
22496 | var json = {
|
22497 | 'version': this['JSON_VERSION'],
|
22498 | 'extent': this.getExtent().toJSON()
|
22499 | };
|
22500 | json['options'] = this.config();
|
22501 | json['options']['center'] = this.getCenter();
|
22502 | json['options']['zoom'] = this.getZoom();
|
22503 |
|
22504 | var baseLayer = this.getBaseLayer();
|
22505 | if ((isNil(options['baseLayer']) || options['baseLayer']) && baseLayer) {
|
22506 | json['baseLayer'] = baseLayer.toJSON(options['baseLayer']);
|
22507 | }
|
22508 | var extraLayerOptions = {};
|
22509 | if (options['clipExtent']) {
|
22510 | if (options['clipExtent'] === true) {
|
22511 | extraLayerOptions['clipExtent'] = this.getExtent();
|
22512 | } else {
|
22513 | extraLayerOptions['clipExtent'] = options['clipExtent'];
|
22514 | }
|
22515 | }
|
22516 | var layersJSON = [];
|
22517 | if (isNil(options['layers']) || options['layers'] && !Array.isArray(options['layers'])) {
|
22518 | var layers = this.getLayers();
|
22519 | for (var i = 0, len = layers.length; i < len; i++) {
|
22520 | if (!layers[i].toJSON) {
|
22521 | continue;
|
22522 | }
|
22523 | var opts = extend({}, isObject(options['layers']) ? options['layers'] : {}, extraLayerOptions);
|
22524 | layersJSON.push(layers[i].toJSON(opts));
|
22525 | }
|
22526 | json['layers'] = layersJSON;
|
22527 | } else if (isArrayHasData(options['layers'])) {
|
22528 | var _layers = options['layers'];
|
22529 | for (var _i = 0; _i < _layers.length; _i++) {
|
22530 | var exportOption = _layers[_i];
|
22531 | var layer = this.getLayer(exportOption['id']);
|
22532 | if (!layer.toJSON) {
|
22533 | continue;
|
22534 | }
|
22535 | var _opts = extend({}, exportOption['options'], extraLayerOptions);
|
22536 | layersJSON.push(layer.toJSON(_opts));
|
22537 | }
|
22538 | json['layers'] = layersJSON;
|
22539 | } else {
|
22540 | json['layers'] = [];
|
22541 | }
|
22542 | return json;
|
22543 | }
|
22544 | });
|
22545 |
|
22546 | Map.fromJSON = function (container, profile, options) {
|
22547 | if (!container || !profile) {
|
22548 | return null;
|
22549 | }
|
22550 | if (!options) {
|
22551 | options = {};
|
22552 | }
|
22553 | var map = new Map(container, profile['options']);
|
22554 | if (isNil(options['baseLayer']) || options['baseLayer']) {
|
22555 | var baseLayer = Layer.fromJSON(profile['baseLayer']);
|
22556 | if (baseLayer) {
|
22557 | map.setBaseLayer(baseLayer);
|
22558 | }
|
22559 | }
|
22560 | if (isNil(options['layers']) || options['layers']) {
|
22561 | var layers = [];
|
22562 | var layerJSONs = profile['layers'];
|
22563 | for (var i = 0; i < layerJSONs.length; i++) {
|
22564 | var layer = Layer.fromJSON(layerJSONs[i]);
|
22565 | layers.push(layer);
|
22566 | }
|
22567 | map.addLayer(layers);
|
22568 | }
|
22569 |
|
22570 | return map;
|
22571 | };
|
22572 |
|
22573 | Map.include({
|
22574 | computeLength: function computeLength(coord1, coord2) {
|
22575 | if (!this.getProjection()) {
|
22576 | return null;
|
22577 | }
|
22578 | var p1 = new Coordinate(coord1),
|
22579 | p2 = new Coordinate(coord2);
|
22580 | if (p1.equals(p2)) {
|
22581 | return 0;
|
22582 | }
|
22583 | return this.getProjection().measureLength(p1, p2);
|
22584 | },
|
22585 |
|
22586 | computeGeometryLength: function computeGeometryLength(geometry) {
|
22587 | return geometry._computeGeodesicLength(this.getProjection());
|
22588 | },
|
22589 |
|
22590 | computeGeometryArea: function computeGeometryArea(geometry) {
|
22591 | return geometry._computeGeodesicArea(this.getProjection());
|
22592 | },
|
22593 |
|
22594 | identify: function identify(opts, callback) {
|
22595 | if (!opts) {
|
22596 | return this;
|
22597 | }
|
22598 | var reqLayers = opts['layers'];
|
22599 | if (!isArrayHasData(reqLayers)) {
|
22600 | return this;
|
22601 | }
|
22602 | var layers = [];
|
22603 | for (var i = 0, len = reqLayers.length; i < len; i++) {
|
22604 | if (isString(reqLayers[i])) {
|
22605 | layers.push(this.getLayer(reqLayers[i]));
|
22606 | } else {
|
22607 | layers.push(reqLayers[i]);
|
22608 | }
|
22609 | }
|
22610 | var coordinate = new Coordinate(opts['coordinate']);
|
22611 | var options = extend({}, opts);
|
22612 | var hits = [];
|
22613 | for (var _i = layers.length - 1; _i >= 0; _i--) {
|
22614 | if (opts['count'] && hits.length >= opts['count']) {
|
22615 | break;
|
22616 | }
|
22617 | var layer = layers[_i];
|
22618 | if (!layer || !layer.getMap() || !opts['includeInvisible'] && !layer.isVisible() || !opts['includeInternals'] && layer.getId().indexOf(INTERNAL_LAYER_PREFIX) >= 0) {
|
22619 | continue;
|
22620 | }
|
22621 | var layerHits = layer.identify(coordinate, options);
|
22622 | if (layerHits) {
|
22623 | if (Array.isArray(layerHits)) {
|
22624 | pushIn(hits, layerHits);
|
22625 | } else {
|
22626 | hits.push(layerHits);
|
22627 | }
|
22628 | }
|
22629 | }
|
22630 | callback.call(this, hits);
|
22631 | return this;
|
22632 | }
|
22633 |
|
22634 | });
|
22635 |
|
22636 | Map.include({
|
22637 | _zoom: function _zoom(nextZoom, origin) {
|
22638 | if (!this.options['zoomable'] || this.isZooming()) {
|
22639 | return;
|
22640 | }
|
22641 | origin = this._checkZoomOrigin(origin);
|
22642 | nextZoom = this._checkZoom(nextZoom);
|
22643 | this.onZoomStart(nextZoom, origin);
|
22644 | this._frameZoom = this.getZoom();
|
22645 | this.onZoomEnd(nextZoom, origin);
|
22646 | },
|
22647 | _zoomAnimation: function _zoomAnimation(nextZoom, origin, startScale) {
|
22648 | if (!this.options['zoomable'] || this.isZooming()) {
|
22649 | return;
|
22650 | }
|
22651 |
|
22652 | nextZoom = this._checkZoom(nextZoom);
|
22653 | if (this.getZoom() === nextZoom) {
|
22654 | return;
|
22655 | }
|
22656 | origin = this._checkZoomOrigin(origin);
|
22657 | this._startZoomAnim(nextZoom, origin, startScale);
|
22658 | },
|
22659 | _checkZoomOrigin: function _checkZoomOrigin(origin) {
|
22660 | if (!origin || this.options['zoomInCenter']) {
|
22661 | origin = new Point(this.width / 2, this.height / 2);
|
22662 | }
|
22663 | return origin;
|
22664 | },
|
22665 | _startZoomAnim: function _startZoomAnim(nextZoom, origin, startScale) {
|
22666 | if (isNil(startScale)) {
|
22667 | startScale = 1;
|
22668 | }
|
22669 | var endScale = this._getResolution(this._startZoomVal) / this._getResolution(nextZoom);
|
22670 | var duration = this.options['zoomAnimationDuration'] * Math.abs(endScale - startScale) / Math.abs(endScale - 1);
|
22671 | this._frameZoom = this._startZoomVal;
|
22672 | this.animateTo({
|
22673 | 'zoom': nextZoom,
|
22674 | 'around': origin
|
22675 | }, {
|
22676 | 'continueOnViewChanged': true,
|
22677 | 'duration': duration
|
22678 | });
|
22679 | },
|
22680 | onZoomStart: function onZoomStart(nextZoom, origin) {
|
22681 | if (!this.options['zoomable'] || this.isZooming()) {
|
22682 | return;
|
22683 | }
|
22684 | this._zooming = true;
|
22685 | this._startZoomVal = this.getZoom();
|
22686 | this._startZoomCoord = this._containerPointToPrj(origin);
|
22687 |
|
22688 | this._fireEvent('zoomstart', { 'from': this._startZoomVal, 'to': nextZoom });
|
22689 | },
|
22690 | onZooming: function onZooming(nextZoom, origin, startScale) {
|
22691 | if (!this.options['zoomable']) {
|
22692 | return;
|
22693 | }
|
22694 | var frameZoom = this._frameZoom;
|
22695 | if (frameZoom === nextZoom) {
|
22696 | return;
|
22697 | }
|
22698 | if (isNil(startScale)) {
|
22699 | startScale = 1;
|
22700 | }
|
22701 | this._zoomTo(nextZoom, origin);
|
22702 | var res = this.getResolution(nextZoom),
|
22703 | fromRes = this.getResolution(this._startZoomVal),
|
22704 | scale = fromRes / res / startScale,
|
22705 | startPoint = this._prjToContainerPoint(this._startZoomCoord, this._startZoomVal);
|
22706 | var offset = this.getViewPoint();
|
22707 | if (!this.isRotating() && !startPoint.equals(origin) && scale !== 1) {
|
22708 | var pitch = this.getPitch();
|
22709 |
|
22710 | var originOffset = startPoint._sub(origin)._multi(1 / (1 - scale));
|
22711 | if (pitch) {
|
22712 | originOffset.y /= Math.cos(pitch * Math.PI / 180);
|
22713 | }
|
22714 | origin = origin.add(originOffset);
|
22715 | }
|
22716 | var matrix = {
|
22717 | 'view': [scale, 0, 0, scale, (origin.x - offset.x) * (1 - scale), (origin.y - offset.y) * (1 - scale)]
|
22718 | };
|
22719 | if (Browser$1.retina) {
|
22720 | origin = origin.multi(2);
|
22721 | }
|
22722 | matrix['container'] = [scale, 0, 0, scale, origin.x * (1 - scale), origin.y * (1 - scale)];
|
22723 |
|
22724 | this._fireEvent('zooming', { 'from': this._startZoomVal, 'to': nextZoom, 'origin': origin, 'matrix': matrix });
|
22725 | this._frameZoom = nextZoom;
|
22726 | },
|
22727 | onZoomEnd: function onZoomEnd(nextZoom, origin) {
|
22728 | if (!this.options['zoomable']) {
|
22729 | return;
|
22730 | }
|
22731 | var startZoomVal = this._startZoomVal;
|
22732 | this._zoomTo(nextZoom, origin);
|
22733 | this._zooming = false;
|
22734 | this._getRenderer().onZoomEnd();
|
22735 |
|
22736 | this._fireEvent('zoomend', { 'from': startZoomVal, 'to': nextZoom });
|
22737 | if (!this._verifyExtent(this.getCenter())) {
|
22738 | this.panTo(this.getMaxExtent().getCenter());
|
22739 | }
|
22740 | },
|
22741 | _zoomTo: function _zoomTo(nextZoom, origin) {
|
22742 | this._zoomLevel = nextZoom;
|
22743 | this._calcMatrices();
|
22744 | if (origin) {
|
22745 | this._setPrjCoordAtContainerPoint(this._startZoomCoord, origin);
|
22746 | }
|
22747 | },
|
22748 | _checkZoom: function _checkZoom(nextZoom) {
|
22749 | var maxZoom = this.getMaxZoom(),
|
22750 | minZoom = this.getMinZoom();
|
22751 | if (nextZoom < minZoom) {
|
22752 | nextZoom = minZoom;
|
22753 | }
|
22754 | if (nextZoom > maxZoom) {
|
22755 | nextZoom = maxZoom;
|
22756 | }
|
22757 | return nextZoom;
|
22758 | }
|
22759 | });
|
22760 |
|
22761 | function perspective(out, fovy, aspect, near, far) {
|
22762 | var f = 1.0 / Math.tan(fovy / 2),
|
22763 | nf = 1 / (near - far);
|
22764 | out[0] = f / aspect;
|
22765 | out[1] = 0;
|
22766 | out[2] = 0;
|
22767 | out[3] = 0;
|
22768 | out[4] = 0;
|
22769 | out[5] = f;
|
22770 | out[6] = 0;
|
22771 | out[7] = 0;
|
22772 | out[8] = 0;
|
22773 | out[9] = 0;
|
22774 | out[10] = (far + near) * nf;
|
22775 | out[11] = -1;
|
22776 | out[12] = 0;
|
22777 | out[13] = 0;
|
22778 | out[14] = 2 * far * near * nf;
|
22779 | out[15] = 0;
|
22780 | return out;
|
22781 | }
|
22782 |
|
22783 | function translate(out, a, v) {
|
22784 | var x = v[0],
|
22785 | y = v[1],
|
22786 | z = v[2],
|
22787 | a00,
|
22788 | a01,
|
22789 | a02,
|
22790 | a03,
|
22791 | a10,
|
22792 | a11,
|
22793 | a12,
|
22794 | a13,
|
22795 | a20,
|
22796 | a21,
|
22797 | a22,
|
22798 | a23;
|
22799 |
|
22800 | if (a === out) {
|
22801 | out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
|
22802 | out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
|
22803 | out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
|
22804 | out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
|
22805 | } else {
|
22806 | a00 = a[0];a01 = a[1];a02 = a[2];a03 = a[3];
|
22807 | a10 = a[4];a11 = a[5];a12 = a[6];a13 = a[7];
|
22808 | a20 = a[8];a21 = a[9];a22 = a[10];a23 = a[11];
|
22809 |
|
22810 | out[0] = a00;out[1] = a01;out[2] = a02;out[3] = a03;
|
22811 | out[4] = a10;out[5] = a11;out[6] = a12;out[7] = a13;
|
22812 | out[8] = a20;out[9] = a21;out[10] = a22;out[11] = a23;
|
22813 |
|
22814 | out[12] = a00 * x + a10 * y + a20 * z + a[12];
|
22815 | out[13] = a01 * x + a11 * y + a21 * z + a[13];
|
22816 | out[14] = a02 * x + a12 * y + a22 * z + a[14];
|
22817 | out[15] = a03 * x + a13 * y + a23 * z + a[15];
|
22818 | }
|
22819 |
|
22820 | return out;
|
22821 | }
|
22822 |
|
22823 | function scale(out, a, v) {
|
22824 | var x = v[0],
|
22825 | y = v[1],
|
22826 | z = v[2];
|
22827 |
|
22828 | out[0] = a[0] * x;
|
22829 | out[1] = a[1] * x;
|
22830 | out[2] = a[2] * x;
|
22831 | out[3] = a[3] * x;
|
22832 | out[4] = a[4] * y;
|
22833 | out[5] = a[5] * y;
|
22834 | out[6] = a[6] * y;
|
22835 | out[7] = a[7] * y;
|
22836 | out[8] = a[8] * z;
|
22837 | out[9] = a[9] * z;
|
22838 | out[10] = a[10] * z;
|
22839 | out[11] = a[11] * z;
|
22840 | out[12] = a[12];
|
22841 | out[13] = a[13];
|
22842 | out[14] = a[14];
|
22843 | out[15] = a[15];
|
22844 | return out;
|
22845 | }
|
22846 |
|
22847 | function rotateX(out, a, rad) {
|
22848 | var s = Math.sin(rad),
|
22849 | c = Math.cos(rad),
|
22850 | a10 = a[4],
|
22851 | a11 = a[5],
|
22852 | a12 = a[6],
|
22853 | a13 = a[7],
|
22854 | a20 = a[8],
|
22855 | a21 = a[9],
|
22856 | a22 = a[10],
|
22857 | a23 = a[11];
|
22858 |
|
22859 | if (a !== out) {
|
22860 | out[0] = a[0];
|
22861 | out[1] = a[1];
|
22862 | out[2] = a[2];
|
22863 | out[3] = a[3];
|
22864 | out[12] = a[12];
|
22865 | out[13] = a[13];
|
22866 | out[14] = a[14];
|
22867 | out[15] = a[15];
|
22868 | }
|
22869 |
|
22870 | out[4] = a10 * c + a20 * s;
|
22871 | out[5] = a11 * c + a21 * s;
|
22872 | out[6] = a12 * c + a22 * s;
|
22873 | out[7] = a13 * c + a23 * s;
|
22874 | out[8] = a20 * c - a10 * s;
|
22875 | out[9] = a21 * c - a11 * s;
|
22876 | out[10] = a22 * c - a12 * s;
|
22877 | out[11] = a23 * c - a13 * s;
|
22878 | return out;
|
22879 | }
|
22880 |
|
22881 | function rotateZ(out, a, rad) {
|
22882 | var s = Math.sin(rad),
|
22883 | c = Math.cos(rad),
|
22884 | a00 = a[0],
|
22885 | a01 = a[1],
|
22886 | a02 = a[2],
|
22887 | a03 = a[3],
|
22888 | a10 = a[4],
|
22889 | a11 = a[5],
|
22890 | a12 = a[6],
|
22891 | a13 = a[7];
|
22892 |
|
22893 | if (a !== out) {
|
22894 | out[8] = a[8];
|
22895 | out[9] = a[9];
|
22896 | out[10] = a[10];
|
22897 | out[11] = a[11];
|
22898 | out[12] = a[12];
|
22899 | out[13] = a[13];
|
22900 | out[14] = a[14];
|
22901 | out[15] = a[15];
|
22902 | }
|
22903 |
|
22904 | out[0] = a00 * c + a10 * s;
|
22905 | out[1] = a01 * c + a11 * s;
|
22906 | out[2] = a02 * c + a12 * s;
|
22907 | out[3] = a03 * c + a13 * s;
|
22908 | out[4] = a10 * c - a00 * s;
|
22909 | out[5] = a11 * c - a01 * s;
|
22910 | out[6] = a12 * c - a02 * s;
|
22911 | out[7] = a13 * c - a03 * s;
|
22912 | return out;
|
22913 | }
|
22914 |
|
22915 | function multiply(out, a, b) {
|
22916 | var a00 = a[0],
|
22917 | a01 = a[1],
|
22918 | a02 = a[2],
|
22919 | a03 = a[3],
|
22920 | a10 = a[4],
|
22921 | a11 = a[5],
|
22922 | a12 = a[6],
|
22923 | a13 = a[7],
|
22924 | a20 = a[8],
|
22925 | a21 = a[9],
|
22926 | a22 = a[10],
|
22927 | a23 = a[11],
|
22928 | a30 = a[12],
|
22929 | a31 = a[13],
|
22930 | a32 = a[14],
|
22931 | a33 = a[15];
|
22932 |
|
22933 | var b0 = b[0],
|
22934 | b1 = b[1],
|
22935 | b2 = b[2],
|
22936 | b3 = b[3];
|
22937 | out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
22938 | out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
22939 | out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
22940 | out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
22941 |
|
22942 | b0 = b[4];b1 = b[5];b2 = b[6];b3 = b[7];
|
22943 | out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
22944 | out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
22945 | out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
22946 | out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
22947 |
|
22948 | b0 = b[8];b1 = b[9];b2 = b[10];b3 = b[11];
|
22949 | out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
22950 | out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
22951 | out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
22952 | out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
22953 |
|
22954 | b0 = b[12];b1 = b[13];b2 = b[14];b3 = b[15];
|
22955 | out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
22956 | out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
22957 | out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
22958 | out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
22959 | return out;
|
22960 | }
|
22961 |
|
22962 | function invert(out, a) {
|
22963 | var a00 = a[0],
|
22964 | a01 = a[1],
|
22965 | a02 = a[2],
|
22966 | a03 = a[3],
|
22967 | a10 = a[4],
|
22968 | a11 = a[5],
|
22969 | a12 = a[6],
|
22970 | a13 = a[7],
|
22971 | a20 = a[8],
|
22972 | a21 = a[9],
|
22973 | a22 = a[10],
|
22974 | a23 = a[11],
|
22975 | a30 = a[12],
|
22976 | a31 = a[13],
|
22977 | a32 = a[14],
|
22978 | a33 = a[15],
|
22979 | b00 = a00 * a11 - a01 * a10,
|
22980 | b01 = a00 * a12 - a02 * a10,
|
22981 | b02 = a00 * a13 - a03 * a10,
|
22982 | b03 = a01 * a12 - a02 * a11,
|
22983 | b04 = a01 * a13 - a03 * a11,
|
22984 | b05 = a02 * a13 - a03 * a12,
|
22985 | b06 = a20 * a31 - a21 * a30,
|
22986 | b07 = a20 * a32 - a22 * a30,
|
22987 | b08 = a20 * a33 - a23 * a30,
|
22988 | b09 = a21 * a32 - a22 * a31,
|
22989 | b10 = a21 * a33 - a23 * a31,
|
22990 | b11 = a22 * a33 - a23 * a32,
|
22991 | det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
22992 |
|
22993 | if (!det) {
|
22994 | return null;
|
22995 | }
|
22996 | det = 1.0 / det;
|
22997 |
|
22998 | out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
|
22999 | out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
|
23000 | out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
|
23001 | out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
|
23002 | out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
|
23003 | out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
|
23004 | out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
23005 | out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
|
23006 | out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
|
23007 | out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
|
23008 | out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
23009 | out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
|
23010 | out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
|
23011 | out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
|
23012 | out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
|
23013 | out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
|
23014 |
|
23015 | return out;
|
23016 | }
|
23017 |
|
23018 | function identity(out) {
|
23019 | out[0] = 1;
|
23020 | out[1] = 0;
|
23021 | out[2] = 0;
|
23022 | out[3] = 0;
|
23023 | out[4] = 0;
|
23024 | out[5] = 1;
|
23025 | out[6] = 0;
|
23026 | out[7] = 0;
|
23027 | out[8] = 0;
|
23028 | out[9] = 0;
|
23029 | out[10] = 1;
|
23030 | out[11] = 0;
|
23031 | out[12] = 0;
|
23032 | out[13] = 0;
|
23033 | out[14] = 0;
|
23034 | out[15] = 1;
|
23035 | return out;
|
23036 | }
|
23037 |
|
23038 | function set$2(out, x, y, z) {
|
23039 | out[0] = x;
|
23040 | out[1] = y;
|
23041 | out[2] = z;
|
23042 | return out;
|
23043 | }
|
23044 |
|
23045 | function add(out, a, b) {
|
23046 | out[0] = a[0] + b[0];
|
23047 | out[1] = a[1] + b[1];
|
23048 | out[2] = a[2] + b[2];
|
23049 | return out;
|
23050 | }
|
23051 |
|
23052 | function subtract(out, a, b) {
|
23053 | out[0] = a[0] - b[0];
|
23054 | out[1] = a[1] - b[1];
|
23055 | out[2] = a[2] - b[2];
|
23056 | return out;
|
23057 | }
|
23058 |
|
23059 | function length(a) {
|
23060 | var x = a[0],
|
23061 | y = a[1],
|
23062 | z = a[2];
|
23063 | return Math.sqrt(x * x + y * y + z * z);
|
23064 | }
|
23065 |
|
23066 | function normalize(out, a) {
|
23067 | var x = a[0],
|
23068 | y = a[1],
|
23069 | z = a[2];
|
23070 | var len = x * x + y * y + z * z;
|
23071 | if (len > 0) {
|
23072 | len = 1 / Math.sqrt(len);
|
23073 | out[0] = a[0] * len;
|
23074 | out[1] = a[1] * len;
|
23075 | out[2] = a[2] * len;
|
23076 | }
|
23077 | return out;
|
23078 | }
|
23079 |
|
23080 | function dot(a, b) {
|
23081 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
23082 | }
|
23083 |
|
23084 | function scale$1(out, a, b) {
|
23085 | out[0] = a[0] * b;
|
23086 | out[1] = a[1] * b;
|
23087 | out[2] = a[2] * b;
|
23088 | return out;
|
23089 | }
|
23090 |
|
23091 | function cross(out, a, b) {
|
23092 | var ax = a[0],
|
23093 | ay = a[1],
|
23094 | az = a[2],
|
23095 | bx = b[0],
|
23096 | by = b[1],
|
23097 | bz = b[2];
|
23098 |
|
23099 | out[0] = ay * bz - az * by;
|
23100 | out[1] = az * bx - ax * bz;
|
23101 | out[2] = ax * by - ay * bx;
|
23102 | return out;
|
23103 | }
|
23104 |
|
23105 | function applyMatrix(out, v, e) {
|
23106 | var x = v[0],
|
23107 | y = v[1],
|
23108 | z = v[2];
|
23109 |
|
23110 |
|
23111 | var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
|
23112 |
|
23113 | out[0] = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
|
23114 | out[1] = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
|
23115 | out[2] = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
|
23116 |
|
23117 | return out;
|
23118 | }
|
23119 |
|
23120 |
|
23121 |
|
23122 | function matrixToQuaternion(out, te) {
|
23123 |
|
23124 | var m11 = te[0],
|
23125 | m12 = te[4],
|
23126 | m13 = te[8],
|
23127 | m21 = te[1],
|
23128 | m22 = te[5],
|
23129 | m23 = te[9],
|
23130 | m31 = te[2],
|
23131 | m32 = te[6],
|
23132 | m33 = te[10],
|
23133 | trace = m11 + m22 + m33;
|
23134 | var s = void 0;
|
23135 |
|
23136 | if (trace > 0) {
|
23137 |
|
23138 | s = 0.5 / Math.sqrt(trace + 1.0);
|
23139 |
|
23140 | out.w = 0.25 / s;
|
23141 | out.x = (m32 - m23) * s;
|
23142 | out.y = (m13 - m31) * s;
|
23143 | out.z = (m21 - m12) * s;
|
23144 | } else if (m11 > m22 && m11 > m33) {
|
23145 |
|
23146 | s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
|
23147 |
|
23148 | out.w = (m32 - m23) / s;
|
23149 | out.x = 0.25 * s;
|
23150 | out.y = (m12 + m21) / s;
|
23151 | out.z = (m13 + m31) / s;
|
23152 | } else if (m22 > m33) {
|
23153 |
|
23154 | s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
|
23155 |
|
23156 | out.w = (m13 - m31) / s;
|
23157 | out.x = (m12 + m21) / s;
|
23158 | out.y = 0.25 * s;
|
23159 | out.z = (m23 + m32) / s;
|
23160 | } else {
|
23161 |
|
23162 | s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
|
23163 |
|
23164 | out.w = (m21 - m12) / s;
|
23165 | out.x = (m13 + m31) / s;
|
23166 | out.y = (m23 + m32) / s;
|
23167 | out.z = 0.25 * s;
|
23168 | }
|
23169 |
|
23170 | return this;
|
23171 | }
|
23172 |
|
23173 | function quaternionToMatrix(out, q) {
|
23174 | var te = out;
|
23175 |
|
23176 | var x = q.x,
|
23177 | y = q.y,
|
23178 | z = q.z,
|
23179 | w = q.w;
|
23180 | var x2 = x + x,
|
23181 | y2 = y + y,
|
23182 | z2 = z + z;
|
23183 | var xx = x * x2,
|
23184 | xy = x * y2,
|
23185 | xz = x * z2;
|
23186 | var yy = y * y2,
|
23187 | yz = y * z2,
|
23188 | zz = z * z2;
|
23189 | var wx = w * x2,
|
23190 | wy = w * y2,
|
23191 | wz = w * z2;
|
23192 |
|
23193 | te[0] = 1 - (yy + zz);
|
23194 | te[4] = xy - wz;
|
23195 | te[8] = xz + wy;
|
23196 |
|
23197 | te[1] = xy + wz;
|
23198 | te[5] = 1 - (xx + zz);
|
23199 | te[9] = yz - wx;
|
23200 |
|
23201 | te[2] = xz - wy;
|
23202 | te[6] = yz + wx;
|
23203 | te[10] = 1 - (xx + yy);
|
23204 |
|
23205 | te[3] = 0;
|
23206 | te[7] = 0;
|
23207 | te[11] = 0;
|
23208 |
|
23209 | te[12] = 0;
|
23210 | te[13] = 0;
|
23211 | te[14] = 0;
|
23212 | te[15] = 1;
|
23213 |
|
23214 | return te;
|
23215 | }
|
23216 |
|
23217 | function setPosition(out, v) {
|
23218 | var te = out;
|
23219 |
|
23220 | te[12] = v[0];
|
23221 | te[13] = v[1];
|
23222 | te[14] = v[2];
|
23223 |
|
23224 | return out;
|
23225 | }
|
23226 |
|
23227 | function lookAt(te, eye, target, up) {
|
23228 | var x = [0, 0, 0];
|
23229 | var y = [0, 0, 0];
|
23230 | var z = [0, 0, 0];
|
23231 | subtract(z, eye, target);
|
23232 |
|
23233 | if (length(z) === 0) {
|
23234 |
|
23235 | z[2] = 1;
|
23236 | }
|
23237 |
|
23238 | normalize(z, z);
|
23239 | cross(x, up, z);
|
23240 |
|
23241 | if (length(z) === 0) {
|
23242 |
|
23243 | if (Math.abs(up[2]) === 1) {
|
23244 |
|
23245 | z[0] += 0.0001;
|
23246 | } else {
|
23247 |
|
23248 | z[2] += 0.0001;
|
23249 | }
|
23250 |
|
23251 | normalize(z, z);
|
23252 | cross(x, up, z);
|
23253 | }
|
23254 |
|
23255 | normalize(x, x);
|
23256 | cross(y, z, x);
|
23257 |
|
23258 | te[0] = x[0];te[4] = y[0];te[8] = z[0];
|
23259 | te[1] = x[1];te[5] = y[1];te[9] = z[1];
|
23260 | te[2] = x[2];te[6] = y[2];te[10] = z[2];
|
23261 |
|
23262 | return te;
|
23263 | }
|
23264 |
|
23265 | var RADIAN = Math.PI / 180;
|
23266 | var DEFAULT_FOV = 0.6435011087932844;
|
23267 |
|
23268 | Map.include({
|
23269 | getFov: function getFov() {
|
23270 | if (!this._fov) {
|
23271 | this._fov = DEFAULT_FOV;
|
23272 | }
|
23273 | return this._fov / RADIAN;
|
23274 | },
|
23275 | setFov: function setFov(fov) {
|
23276 | if (this.isZooming()) {
|
23277 | return this;
|
23278 | }
|
23279 | fov = Math.max(0.01, Math.min(60, fov));
|
23280 | if (this._fov === fov) return this;
|
23281 | var from = this.getFov();
|
23282 | this._fov = fov * RADIAN;
|
23283 | this._calcMatrices();
|
23284 | this._renderLayers();
|
23285 |
|
23286 | this._fireEvent('fovchange', { 'from': from, 'to': this.getFov() });
|
23287 | return this;
|
23288 | },
|
23289 | getBearing: function getBearing() {
|
23290 | if (!this._angle) {
|
23291 | return 0;
|
23292 | }
|
23293 | return -this._angle / RADIAN;
|
23294 | },
|
23295 | setBearing: function setBearing(bearing) {
|
23296 | if (Browser$1.ie9) {
|
23297 | throw new Error('map can\'t rotate in IE9.');
|
23298 | }
|
23299 | var b = -wrap(bearing, -180, 180) * RADIAN;
|
23300 | if (this._angle === b) return this;
|
23301 | var from = this.getBearing();
|
23302 |
|
23303 | this._fireEvent('rotatestart', { 'from': from, 'to': b });
|
23304 | this._angle = b;
|
23305 | this._calcMatrices();
|
23306 | this._renderLayers();
|
23307 |
|
23308 | this._fireEvent('rotate', { 'from': from, 'to': b });
|
23309 |
|
23310 | this._fireEvent('rotateend', { 'from': from, 'to': b });
|
23311 | return this;
|
23312 | },
|
23313 | getPitch: function getPitch() {
|
23314 | if (!this._pitch) {
|
23315 | return 0;
|
23316 | }
|
23317 | return this._pitch / Math.PI * 180;
|
23318 | },
|
23319 | setPitch: function setPitch(pitch) {
|
23320 | if (Browser$1.ie9) {
|
23321 | throw new Error('map can\'t tilt in IE9.');
|
23322 | }
|
23323 | var p = clamp(pitch, 0, this.options['maxPitch']) * RADIAN;
|
23324 | if (this._pitch === p) return this;
|
23325 | var from = this.getPitch();
|
23326 |
|
23327 | this._fireEvent('pitchstart', { 'from': from, 'to': p });
|
23328 | this._pitch = p;
|
23329 | this._calcMatrices();
|
23330 | this._renderLayers();
|
23331 |
|
23332 | this._fireEvent('pitch', { 'from': from, 'to': p });
|
23333 |
|
23334 | this._fireEvent('pitchend', { 'from': from, 'to': p });
|
23335 | return this;
|
23336 | },
|
23337 | isTransforming: function isTransforming() {
|
23338 | return !!(this._pitch || this._angle);
|
23339 | },
|
23340 | getFrustumAltitude: function getFrustumAltitude() {
|
23341 | var pitch = 90 - this.getPitch();
|
23342 | var fov = this.getFov() / 2;
|
23343 | var cameraAlt = this.cameraPosition ? this.cameraPosition[2] : 0;
|
23344 | if (fov <= pitch) {
|
23345 | return cameraAlt;
|
23346 | }
|
23347 | fov = Math.PI * fov / 180;
|
23348 | var d1 = new Point(this.cameraPosition).distanceTo(new Point(this.cameraLookAt)),
|
23349 | d2 = cameraAlt * Math.tan(fov * 2);
|
23350 | var d = Math.tan(fov) * (d1 + d2);
|
23351 | return cameraAlt + d;
|
23352 | },
|
23353 |
|
23354 | _pointToContainerPoint: function () {
|
23355 | var a = [0, 0, 0];
|
23356 | return function (point, zoom) {
|
23357 | var altitude = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
23358 |
|
23359 | point = this._pointToPoint(point, zoom);
|
23360 | if (this.isTransforming() || altitude) {
|
23361 | altitude *= this.getResolution(zoom) / this.getResolution();
|
23362 | var _scale = this._glScale;
|
23363 | set$2(a, point.x * _scale, point.y * _scale, altitude * _scale);
|
23364 |
|
23365 |
|
23366 | var t = this._projIfBehindCamera(a, this.cameraPosition, this.cameraForward);
|
23367 |
|
23368 | applyMatrix(t, t, this.projViewMatrix);
|
23369 |
|
23370 | var w2 = this.width / 2,
|
23371 | h2 = this.height / 2;
|
23372 | t[0] = t[0] * w2 + w2;
|
23373 | t[1] = -(t[1] * h2) + h2;
|
23374 | return new Point(t[0], t[1]);
|
23375 | } else {
|
23376 | var centerPoint = this._prjToPoint(this._getPrjCenter());
|
23377 | return point._sub(centerPoint)._add(this.width / 2, this.height / 2);
|
23378 | }
|
23379 | };
|
23380 | }(),
|
23381 |
|
23382 | _projIfBehindCamera: function () {
|
23383 | var vectorFromCam = new Array(3);
|
23384 | var nVectorFromCam = new Array(3);
|
23385 | var proj = new Array(3);
|
23386 | var sub = new Array(3);
|
23387 | return function (position, cameraPos, camForward) {
|
23388 | subtract(vectorFromCam, position, cameraPos);
|
23389 | var cameraDot = dot(camForward, normalize(nVectorFromCam, vectorFromCam));
|
23390 |
|
23391 | if (cameraDot <= 0) {
|
23392 | var camDot = dot(camForward, vectorFromCam);
|
23393 | scale$1(proj, camForward, camDot * 1.01);
|
23394 | add(position, cameraPos, subtract(sub, vectorFromCam, proj));
|
23395 | }
|
23396 |
|
23397 | return position;
|
23398 | };
|
23399 | }(),
|
23400 |
|
23401 | _containerPointToPoint: function () {
|
23402 | var cp = [0, 0, 0],
|
23403 | coord0 = [0, 0, 0, 1],
|
23404 | coord1 = [0, 0, 0, 1];
|
23405 | return function (p, zoom) {
|
23406 | if (this.isTransforming()) {
|
23407 | var w2 = this.width / 2 || 1,
|
23408 | h2 = this.height / 2 || 1;
|
23409 | set$2(cp, (p.x - w2) / w2, (h2 - p.y) / h2, 0);
|
23410 |
|
23411 | set$2(coord0, cp[0], cp[1], 0);
|
23412 | set$2(coord1, cp[0], cp[1], 1);
|
23413 | coord0[3] = coord1[3] = 1;
|
23414 |
|
23415 | applyMatrix(coord0, coord0, this.projViewMatrixInverse);
|
23416 | applyMatrix(coord1, coord1, this.projViewMatrixInverse);
|
23417 | var x0 = coord0[0];
|
23418 | var x1 = coord1[0];
|
23419 | var y0 = coord0[1];
|
23420 | var y1 = coord1[1];
|
23421 | var z0 = coord0[2];
|
23422 | var z1 = coord1[2];
|
23423 |
|
23424 | var t = z0 === z1 ? 0 : (0 - z0) / (z1 - z0);
|
23425 |
|
23426 | var point = new Point(interpolate(x0, x1, t), interpolate(y0, y1, t))._multi(1 / this._glScale);
|
23427 | return zoom === undefined || this.getZoom() === zoom ? point : this._pointToPointAtZoom(point, zoom);
|
23428 | }
|
23429 | var centerPoint = this._prjToPoint(this._getPrjCenter(), zoom),
|
23430 | scale$$1 = zoom !== undefined ? this._getResolution() / this._getResolution(zoom) : 1;
|
23431 | var x = scale$$1 * (p.x - this.width / 2),
|
23432 | y = scale$$1 * (p.y - this.height / 2);
|
23433 | return centerPoint._add(x, y);
|
23434 | };
|
23435 | }(),
|
23436 |
|
23437 | _calcMatrices: function () {
|
23438 | var m0 = Browser$1.ie9 ? null : createMat4(),
|
23439 | m1 = Browser$1.ie9 ? null : createMat4();
|
23440 | return function () {
|
23441 | if (Browser$1.ie9) {
|
23442 | return;
|
23443 | }
|
23444 | var size = this.getSize();
|
23445 | var w = size.width || 1,
|
23446 | h = size.height || 1;
|
23447 |
|
23448 | this._glScale = this.getGLScale();
|
23449 |
|
23450 | var fov = this.getFov() * Math.PI / 180;
|
23451 | var maxScale = this.getScale(this.getMinZoom()) / this.getScale(this.getMaxNativeZoom());
|
23452 | var farZ = maxScale * h / 2 / this._getFovRatio() * 1.4;
|
23453 |
|
23454 | var projMatrix = this.projMatrix || createMat4();
|
23455 | perspective(projMatrix, fov, w / h, 0.1, farZ);
|
23456 | this.projMatrix = projMatrix;
|
23457 |
|
23458 | var worldMatrix = this._getCameraWorldMatrix();
|
23459 |
|
23460 | this.viewMatrix = invert(m0, worldMatrix);
|
23461 |
|
23462 | this.projViewMatrix = multiply(this.projViewMatrix || createMat4(), projMatrix, this.viewMatrix);
|
23463 |
|
23464 | this.projViewMatrixInverse = multiply(this.projViewMatrixInverse || createMat4(), worldMatrix, invert(m1, projMatrix));
|
23465 | this.domCssMatrix = this._calcDomMatrix();
|
23466 | };
|
23467 | }(),
|
23468 |
|
23469 | _calcDomMatrix: function () {
|
23470 | var m = Browser$1.ie9 ? null : createMat4(),
|
23471 | minusY = [1, -1, 1],
|
23472 | arr = [0, 0, 0];
|
23473 | return function () {
|
23474 | var cameraToCenterDistance = 0.5 / Math.tan(this._fov / 2) * this.height;
|
23475 | scale(m, this.projMatrix, minusY);
|
23476 | translate(m, m, set$2(arr, 0, 0, -cameraToCenterDistance));
|
23477 | if (this._pitch) {
|
23478 | rotateX(m, m, this._pitch);
|
23479 | }
|
23480 | if (this._angle) {
|
23481 | rotateZ(m, m, this._angle);
|
23482 | }
|
23483 | var m1 = createMat4();
|
23484 | scale(m1, m1, set$2(arr, this.width / 2, -this.height / 2, 1));
|
23485 | return multiply(this.domCssMatrix || createMat4(), m1, m);
|
23486 | };
|
23487 | }(),
|
23488 |
|
23489 | _getCameraWorldMatrix: function () {
|
23490 | var q = {},
|
23491 | minusY = [1, -1, 1];
|
23492 | return function () {
|
23493 | var targetZ = this.getGLZoom();
|
23494 |
|
23495 | var size = this.getSize(),
|
23496 | scale$$1 = this.getGLScale();
|
23497 | var center2D = this._prjToPoint(this._prjCenter, targetZ);
|
23498 | this.cameraLookAt = set$2(this.cameraLookAt || [0, 0, 0], center2D.x, center2D.y, 0);
|
23499 |
|
23500 | var pitch = this.getPitch() * RADIAN;
|
23501 | var bearing = -this.getBearing() * RADIAN;
|
23502 |
|
23503 | var ratio = this._getFovRatio();
|
23504 | var z = scale$$1 * (size.height || 1) / 2 / ratio;
|
23505 | var cz = z * Math.cos(pitch);
|
23506 |
|
23507 | var dist = Math.sin(pitch) * z;
|
23508 |
|
23509 | var cx = center2D.x + dist * Math.sin(bearing);
|
23510 | var cy = center2D.y + dist * Math.cos(bearing);
|
23511 | this.cameraPosition = set$2(this.cameraPosition || [0, 0, 0], cx, cy, cz);
|
23512 |
|
23513 | var d = dist || 1;
|
23514 | var up = this.cameraUp = set$2(this.cameraUp || [0, 0, 0], Math.sin(bearing) * d, Math.cos(bearing) * d, 0);
|
23515 | var m = this.cameraWorldMatrix = this.cameraWorldMatrix || createMat4();
|
23516 | lookAt(m, this.cameraPosition, this.cameraLookAt, up);
|
23517 |
|
23518 | var cameraForward = this.cameraForward || [0, 0, 0];
|
23519 | subtract(cameraForward, this.cameraLookAt, this.cameraPosition);
|
23520 |
|
23521 | this.cameraForward = normalize(cameraForward, cameraForward);
|
23522 |
|
23523 | matrixToQuaternion(q, m);
|
23524 | quaternionToMatrix(m, q);
|
23525 | setPosition(m, this.cameraPosition);
|
23526 | scale(m, m, minusY);
|
23527 | return m;
|
23528 | };
|
23529 | }(),
|
23530 |
|
23531 | _getFovRatio: function _getFovRatio() {
|
23532 | var fov = this.getFov();
|
23533 | return Math.tan(fov / 2 * RADIAN);
|
23534 | },
|
23535 | _renderLayers: function _renderLayers() {
|
23536 | if (this.isInteracting()) {
|
23537 | return;
|
23538 | }
|
23539 | var layers = this._getLayers();
|
23540 |
|
23541 | layers.forEach(function (layer) {
|
23542 | if (!layer) {
|
23543 | return;
|
23544 | }
|
23545 | var renderer = layer._getRenderer();
|
23546 | if (renderer && renderer.setToRedraw) {
|
23547 | renderer.setToRedraw();
|
23548 | }
|
23549 | });
|
23550 | }
|
23551 | });
|
23552 |
|
23553 | function createMat4() {
|
23554 | return identity(new Array(16));
|
23555 | }
|
23556 |
|
23557 | Map.include({
|
23558 | _onViewChange: function _onViewChange(view) {
|
23559 | if (!this._viewHistory) {
|
23560 | this._viewHistory = [];
|
23561 | this._viewHistoryPointer = 0;
|
23562 | }
|
23563 | var old = this._getCurrentView();
|
23564 | for (var i = this._viewHistory.length - 1; i >= 0; i--) {
|
23565 | if (equalMapView(view, this._viewHistory[i])) {
|
23566 | this._viewHistoryPointer = i;
|
23567 | this._fireViewChange(old, view);
|
23568 | return;
|
23569 | }
|
23570 | }
|
23571 |
|
23572 | if (this._viewHistoryPointer < this._viewHistory.length - 1) {
|
23573 | this._viewHistory.splice(this._viewHistoryPointer + 1);
|
23574 | }
|
23575 | this._viewHistory.push(view);
|
23576 | var count = this.options['viewHistoryCount'];
|
23577 | if (count > 0 && this._viewHistory.length > count) {
|
23578 | this._viewHistory.splice(0, this._viewHistory.length - count);
|
23579 | }
|
23580 | this._viewHistoryPointer = this._viewHistory.length - 1;
|
23581 |
|
23582 | this._fireViewChange(old, view);
|
23583 | },
|
23584 | zoomToPreviousView: function zoomToPreviousView() {
|
23585 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
23586 |
|
23587 | if (!this.hasPreviousView()) {
|
23588 | return null;
|
23589 | }
|
23590 | var view = this._viewHistory[--this._viewHistoryPointer];
|
23591 | this._zoomToView(view, options);
|
23592 | return view;
|
23593 | },
|
23594 | hasPreviousView: function hasPreviousView() {
|
23595 | if (!this._viewHistory || this._viewHistoryPointer === 0) {
|
23596 | return false;
|
23597 | }
|
23598 | return true;
|
23599 | },
|
23600 | zoomToNextView: function zoomToNextView() {
|
23601 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
23602 |
|
23603 | if (!this.hasNextView()) {
|
23604 | return null;
|
23605 | }
|
23606 | var view = this._viewHistory[++this._viewHistoryPointer];
|
23607 | this._zoomToView(view, options);
|
23608 | return view;
|
23609 | },
|
23610 | hasNextView: function hasNextView() {
|
23611 | if (!this._viewHistory || this._viewHistoryPointer === this._viewHistory.length - 1) {
|
23612 | return false;
|
23613 | }
|
23614 | return true;
|
23615 | },
|
23616 | _zoomToView: function _zoomToView(view, options) {
|
23617 | var _this = this;
|
23618 |
|
23619 | var old = this.getView();
|
23620 | if (options['animation']) {
|
23621 | this.animateTo(view, {
|
23622 | 'duration': options['duration']
|
23623 | }, function (frame) {
|
23624 | if (frame.state.playState === 'finished') {
|
23625 | _this._fireViewChange(old, view);
|
23626 | }
|
23627 | });
|
23628 | } else {
|
23629 | this.setView(view);
|
23630 | this._fireViewChange(old, view);
|
23631 | }
|
23632 | },
|
23633 | getViewHistory: function getViewHistory() {
|
23634 | return this._viewHistory;
|
23635 | },
|
23636 | _fireViewChange: function _fireViewChange(old, view) {
|
23637 | this._fireEvent('viewchange', {
|
23638 | 'old': old,
|
23639 | 'new': view
|
23640 | });
|
23641 | },
|
23642 | _getCurrentView: function _getCurrentView() {
|
23643 | if (!this._viewHistory) {
|
23644 | return null;
|
23645 | }
|
23646 | return this._viewHistory[this._viewHistoryPointer];
|
23647 | }
|
23648 | });
|
23649 |
|
23650 | Map.mergeOptions({
|
23651 | 'viewHistory': true,
|
23652 | 'viewHistoryCount': 10
|
23653 | });
|
23654 |
|
23655 | var options$17 = {
|
23656 | 'mode': 'LineString',
|
23657 | 'language': 'zh-CN',
|
23658 | 'metric': true,
|
23659 | 'imperial': false,
|
23660 | 'symbol': {
|
23661 | 'lineColor': '#000',
|
23662 | 'lineWidth': 3,
|
23663 | 'lineOpacity': 1
|
23664 | },
|
23665 | 'vertexSymbol': {
|
23666 | 'markerType': 'ellipse',
|
23667 | 'markerFill': '#fff',
|
23668 | 'markerLineColor': '#000',
|
23669 | 'markerLineWidth': 3,
|
23670 | 'markerWidth': 11,
|
23671 | 'markerHeight': 11
|
23672 | },
|
23673 | 'labelOptions': {
|
23674 | 'textSymbol': {
|
23675 | 'textFaceName': 'monospace',
|
23676 | 'textLineSpacing': 1,
|
23677 | 'textHorizontalAlignment': 'right',
|
23678 | 'textDx': 15
|
23679 | },
|
23680 | 'boxStyle': {
|
23681 | 'padding': [6, 2],
|
23682 | 'symbol': {
|
23683 | 'markerType': 'square',
|
23684 | 'markerFill': '#fff',
|
23685 | 'markerFillOpacity': 0.9,
|
23686 | 'markerLineColor': '#b4b3b3'
|
23687 | }
|
23688 | }
|
23689 | },
|
23690 | 'clearButtonSymbol': [{
|
23691 | 'markerType': 'square',
|
23692 | 'markerFill': '#fff',
|
23693 | 'markerLineColor': '#b4b3b3',
|
23694 | 'markerLineWidth': 2,
|
23695 | 'markerWidth': 15,
|
23696 | 'markerHeight': 15,
|
23697 | 'markerDx': 20
|
23698 | }, {
|
23699 | 'markerType': 'x',
|
23700 | 'markerWidth': 10,
|
23701 | 'markerHeight': 10,
|
23702 | 'markerDx': 20
|
23703 | }]
|
23704 | };
|
23705 |
|
23706 | var DistanceTool = function (_DrawTool) {
|
23707 | inherits(DistanceTool, _DrawTool);
|
23708 |
|
23709 | function DistanceTool(options) {
|
23710 | classCallCheck(this, DistanceTool);
|
23711 |
|
23712 | var _this = possibleConstructorReturn(this, _DrawTool.call(this, options));
|
23713 |
|
23714 | _this.on('enable', _this._afterEnable, _this).on('disable', _this._afterDisable, _this);
|
23715 | _this._measureLayers = [];
|
23716 | return _this;
|
23717 | }
|
23718 |
|
23719 | DistanceTool.prototype.clear = function clear() {
|
23720 | if (isArrayHasData(this._measureLayers)) {
|
23721 | for (var i = 0; i < this._measureLayers.length; i++) {
|
23722 | this._measureLayers[i].remove();
|
23723 | }
|
23724 | }
|
23725 | delete this._lastMeasure;
|
23726 | delete this._lastVertex;
|
23727 | this._measureLayers = [];
|
23728 | return this;
|
23729 | };
|
23730 |
|
23731 | DistanceTool.prototype.getMeasureLayers = function getMeasureLayers() {
|
23732 | return this._measureLayers;
|
23733 | };
|
23734 |
|
23735 | DistanceTool.prototype.getLastMeasure = function getLastMeasure() {
|
23736 | if (!this._lastMeasure) {
|
23737 | return 0;
|
23738 | }
|
23739 | return this._lastMeasure;
|
23740 | };
|
23741 |
|
23742 | DistanceTool.prototype._measure = function _measure(toMeasure) {
|
23743 | var map = this.getMap();
|
23744 | var length = void 0;
|
23745 | if (toMeasure instanceof Geometry) {
|
23746 | length = map.computeGeometryLength(toMeasure);
|
23747 | } else if (Array.isArray(toMeasure)) {
|
23748 | length = map.getProjection().measureLength(toMeasure);
|
23749 | }
|
23750 | this._lastMeasure = length;
|
23751 | var units = void 0;
|
23752 | if (this.options['language'] === 'zh-CN') {
|
23753 | units = [' 米', ' 公里', ' 英尺', ' 英里'];
|
23754 | } else {
|
23755 | units = [' m', ' km', ' feet', ' mile'];
|
23756 | }
|
23757 | var content = '';
|
23758 | if (this.options['metric']) {
|
23759 | content += length < 1000 ? length.toFixed(0) + units[0] : (length / 1000).toFixed(2) + units[1];
|
23760 | }
|
23761 | if (this.options['imperial']) {
|
23762 | length *= 3.2808399;
|
23763 | if (content.length > 0) {
|
23764 | content += '\n';
|
23765 | }
|
23766 | content += length < 5280 ? length.toFixed(0) + units[2] : (length / 5280).toFixed(2) + units[3];
|
23767 | }
|
23768 | return content;
|
23769 | };
|
23770 |
|
23771 | DistanceTool.prototype._registerMeasureEvents = function _registerMeasureEvents() {
|
23772 | this.on('drawstart', this._msOnDrawStart, this).on('drawvertex', this._msOnDrawVertex, this).on('mousemove', this._msOnMouseMove, this).on('drawend', this._msOnDrawEnd, this);
|
23773 | };
|
23774 |
|
23775 | DistanceTool.prototype._afterEnable = function _afterEnable() {
|
23776 | this._registerMeasureEvents();
|
23777 | };
|
23778 |
|
23779 | DistanceTool.prototype._afterDisable = function _afterDisable() {
|
23780 | this.off('drawstart', this._msOnDrawStart, this).off('drawvertex', this._msOnDrawVertex, this).off('mousemove', this._msOnMouseMove, this).off('drawend', this._msOnDrawEnd, this);
|
23781 | };
|
23782 |
|
23783 | DistanceTool.prototype._msOnDrawStart = function _msOnDrawStart(param) {
|
23784 | var map = this.getMap();
|
23785 | var uid = UID();
|
23786 | var layerId = 'distancetool_' + uid;
|
23787 | var markerLayerId = 'distancetool_markers_' + uid;
|
23788 | if (!map.getLayer(layerId)) {
|
23789 | this._measureLineLayer = new VectorLayer(layerId).addTo(map);
|
23790 | this._measureMarkerLayer = new VectorLayer(markerLayerId).addTo(map);
|
23791 | } else {
|
23792 | this._measureLineLayer = map.getLayer(layerId);
|
23793 | this._measureMarkerLayer = map.getLayer(markerLayerId);
|
23794 | }
|
23795 | this._measureLayers.push(this._measureLineLayer);
|
23796 | this._measureLayers.push(this._measureMarkerLayer);
|
23797 |
|
23798 | new Marker(param['coordinate'], {
|
23799 | 'symbol': this.options['vertexSymbol']
|
23800 | }).addTo(this._measureMarkerLayer);
|
23801 | var content = this.options['language'] === 'zh-CN' ? '起点' : 'start';
|
23802 | var startLabel = new Label(content, param['coordinate'], this.options['labelOptions']);
|
23803 | this._measureMarkerLayer.addGeometry(startLabel);
|
23804 | };
|
23805 |
|
23806 | DistanceTool.prototype._msOnMouseMove = function _msOnMouseMove(param) {
|
23807 | var ms = this._measure(this._msGetCoordsToMeasure(param));
|
23808 | if (!this._tailMarker) {
|
23809 | var symbol = extendSymbol(this.options['vertexSymbol']);
|
23810 | symbol['markerWidth'] /= 2;
|
23811 | symbol['markerHeight'] /= 2;
|
23812 | this._tailMarker = new Marker(param['coordinate'], {
|
23813 | 'symbol': symbol
|
23814 | }).addTo(this._measureMarkerLayer);
|
23815 | this._tailLabel = new Label(ms, param['coordinate'], this.options['labelOptions']).addTo(this._measureMarkerLayer);
|
23816 | }
|
23817 | this._tailMarker.setCoordinates(param['coordinate']);
|
23818 | this._tailLabel.setContent(ms);
|
23819 | this._tailLabel.setCoordinates(param['coordinate']);
|
23820 | };
|
23821 |
|
23822 | DistanceTool.prototype._msGetCoordsToMeasure = function _msGetCoordsToMeasure(param) {
|
23823 | return param['geometry'].getCoordinates().concat([param['coordinate']]);
|
23824 | };
|
23825 |
|
23826 | DistanceTool.prototype._msOnDrawVertex = function _msOnDrawVertex(param) {
|
23827 | var geometry = param['geometry'];
|
23828 |
|
23829 | new Marker(param['coordinate'], {
|
23830 | 'symbol': this.options['vertexSymbol']
|
23831 | }).addTo(this._measureMarkerLayer);
|
23832 | var length = this._measure(geometry);
|
23833 | var vertexLabel = new Label(length, param['coordinate'], this.options['labelOptions']);
|
23834 | this._measureMarkerLayer.addGeometry(vertexLabel);
|
23835 | this._lastVertex = vertexLabel;
|
23836 | };
|
23837 |
|
23838 | DistanceTool.prototype._msOnDrawEnd = function _msOnDrawEnd(param) {
|
23839 | this._clearTailMarker();
|
23840 | var size = this._lastVertex.getSize();
|
23841 | if (!size) {
|
23842 | size = new Size(10, 10);
|
23843 | }
|
23844 | this._addClearMarker(this._lastVertex.getCoordinates(), size['width']);
|
23845 | var geo = param['geometry'].copy();
|
23846 | geo.addTo(this._measureLineLayer);
|
23847 | this._lastMeasure = geo.getLength();
|
23848 | };
|
23849 |
|
23850 | DistanceTool.prototype._addClearMarker = function _addClearMarker(coordinates, dx) {
|
23851 | var symbol = this.options['clearButtonSymbol'];
|
23852 | var dxSymbol = {
|
23853 | 'markerDx': (symbol['markerDx'] || 0) + dx,
|
23854 | 'textDx': (symbol['textDx'] || 0) + dx
|
23855 | };
|
23856 | if (Array.isArray(symbol)) {
|
23857 | dxSymbol = symbol.map(function (s) {
|
23858 | if (s) {
|
23859 | return {
|
23860 | 'markerDx': (s['markerDx'] || 0) + dx,
|
23861 | 'textDx': (s['textDx'] || 0) + dx
|
23862 | };
|
23863 | }
|
23864 | return null;
|
23865 | });
|
23866 | }
|
23867 | symbol = extendSymbol(symbol, dxSymbol);
|
23868 | var endMarker = new Marker(coordinates, {
|
23869 | 'symbol': symbol
|
23870 | });
|
23871 | var measureLineLayer = this._measureLineLayer,
|
23872 | measureMarkerLayer = this._measureMarkerLayer;
|
23873 | endMarker.on('click', function () {
|
23874 | measureLineLayer.remove();
|
23875 | measureMarkerLayer.remove();
|
23876 |
|
23877 | return false;
|
23878 | }, this);
|
23879 | endMarker.addTo(this._measureMarkerLayer);
|
23880 | };
|
23881 |
|
23882 | DistanceTool.prototype._clearTailMarker = function _clearTailMarker() {
|
23883 | if (this._tailMarker) {
|
23884 | this._tailMarker.remove();
|
23885 | delete this._tailMarker;
|
23886 | }
|
23887 | if (this._tailLabel) {
|
23888 | this._tailLabel.remove();
|
23889 | delete this._tailLabel;
|
23890 | }
|
23891 | };
|
23892 |
|
23893 | return DistanceTool;
|
23894 | }(DrawTool);
|
23895 |
|
23896 | DistanceTool.mergeOptions(options$17);
|
23897 |
|
23898 | var options$18 = {
|
23899 | 'mode': 'Polygon',
|
23900 | 'symbol': {
|
23901 | 'lineColor': '#000000',
|
23902 | 'lineWidth': 2,
|
23903 | 'lineOpacity': 1,
|
23904 | 'lineDasharray': '',
|
23905 | 'polygonFill': '#ffffff',
|
23906 | 'polygonOpacity': 0.5
|
23907 | }
|
23908 | };
|
23909 |
|
23910 | var AreaTool = function (_DistanceTool) {
|
23911 | inherits(AreaTool, _DistanceTool);
|
23912 |
|
23913 | function AreaTool(options) {
|
23914 | classCallCheck(this, AreaTool);
|
23915 |
|
23916 | var _this = possibleConstructorReturn(this, _DistanceTool.call(this, options));
|
23917 |
|
23918 | _this.on('enable', _this._afterEnable, _this).on('disable', _this._afterDisable, _this);
|
23919 | _this._measureLayers = [];
|
23920 | return _this;
|
23921 | }
|
23922 |
|
23923 | AreaTool.prototype._measure = function _measure(toMeasure) {
|
23924 | var map = this.getMap();
|
23925 | var area = void 0;
|
23926 | if (toMeasure instanceof Geometry) {
|
23927 | area = map.computeGeometryArea(toMeasure);
|
23928 | } else if (Array.isArray(toMeasure)) {
|
23929 | area = map.getProjection().measureArea(toMeasure);
|
23930 | }
|
23931 | this._lastMeasure = area;
|
23932 | var units = void 0;
|
23933 | if (this.options['language'] === 'zh-CN') {
|
23934 | units = [' 平方米', ' 平方公里', ' 平方英尺', ' 平方英里'];
|
23935 | } else {
|
23936 | units = [' sq.m', ' sq.km', ' sq.ft', ' sq.mi'];
|
23937 | }
|
23938 | var content = '';
|
23939 | if (this.options['metric']) {
|
23940 | content += area < 1E6 ? area.toFixed(0) + units[0] : (area / 1E6).toFixed(2) + units[1];
|
23941 | }
|
23942 | if (this.options['imperial']) {
|
23943 | area *= 3.2808399;
|
23944 | if (content.length > 0) {
|
23945 | content += '\n';
|
23946 | }
|
23947 | var sqmi = 5280 * 5280;
|
23948 | content += area < sqmi ? area.toFixed(0) + units[2] : (area / sqmi).toFixed(2) + units[3];
|
23949 | }
|
23950 | return content;
|
23951 | };
|
23952 |
|
23953 | AreaTool.prototype._msGetCoordsToMeasure = function _msGetCoordsToMeasure(param) {
|
23954 | return param['geometry'].getShell().concat([param['coordinate']]);
|
23955 | };
|
23956 |
|
23957 | AreaTool.prototype._msOnDrawVertex = function _msOnDrawVertex(param) {
|
23958 | var vertexMarker = new Marker(param['coordinate'], {
|
23959 | 'symbol': this.options['vertexSymbol']
|
23960 | }).addTo(this._measureMarkerLayer);
|
23961 | this._measure(param['geometry']);
|
23962 | this._lastVertex = vertexMarker;
|
23963 | };
|
23964 |
|
23965 | AreaTool.prototype._msOnDrawEnd = function _msOnDrawEnd(param) {
|
23966 | this._clearTailMarker();
|
23967 |
|
23968 | var ms = this._measure(param['geometry']);
|
23969 | var endLabel = new Label(ms, param['coordinate'], this.options['labelOptions']).addTo(this._measureMarkerLayer);
|
23970 | var size = endLabel.getSize();
|
23971 | if (!size) {
|
23972 | size = new Size(10, 10);
|
23973 | }
|
23974 | this._addClearMarker(param['coordinate'], size['width']);
|
23975 | var geo = param['geometry'].copy();
|
23976 | geo.addTo(this._measureLineLayer);
|
23977 | this._lastMeasure = geo.getArea();
|
23978 | };
|
23979 |
|
23980 | return AreaTool;
|
23981 | }(DistanceTool);
|
23982 |
|
23983 | AreaTool.mergeOptions(options$18);
|
23984 |
|
23985 | DrawTool.registerMode('circle', {
|
23986 | 'clickLimit': 2,
|
23987 | 'action': ['click', 'mousemove', 'click'],
|
23988 | 'create': function create(coordinate) {
|
23989 | return new Circle(coordinate[0], 0);
|
23990 | },
|
23991 | 'update': function update(path, geometry) {
|
23992 | var map = geometry.getMap();
|
23993 | var radius = map.computeLength(geometry.getCenter(), path[path.length - 1]);
|
23994 | geometry.setRadius(radius);
|
23995 | },
|
23996 | 'generate': function generate(geometry) {
|
23997 | return geometry;
|
23998 | }
|
23999 | });
|
24000 |
|
24001 | DrawTool.registerMode('freeHandCircle', {
|
24002 | 'action': ['mousedown', 'mousemove', 'mouseup'],
|
24003 | 'create': function create(coordinate) {
|
24004 | return new Circle(coordinate[0], 0);
|
24005 | },
|
24006 | 'update': function update(path, geometry) {
|
24007 | var map = geometry.getMap();
|
24008 | var radius = map.computeLength(geometry.getCenter(), path[path.length - 1]);
|
24009 | geometry.setRadius(radius);
|
24010 | },
|
24011 | 'generate': function generate(geometry) {
|
24012 | return geometry;
|
24013 | }
|
24014 | });
|
24015 |
|
24016 | DrawTool.registerMode('ellipse', {
|
24017 | 'clickLimit': 2,
|
24018 | 'action': ['click', 'mousemove', 'click'],
|
24019 | 'create': function create(coordinates) {
|
24020 | return new Ellipse(coordinates[0], 0, 0);
|
24021 | },
|
24022 | 'update': function update(path, geometry) {
|
24023 | var map = geometry.getMap();
|
24024 | var center = geometry.getCenter();
|
24025 | var rx = map.computeLength(center, new Coordinate({
|
24026 | x: path[path.length - 1].x,
|
24027 | y: center.y
|
24028 | }));
|
24029 | var ry = map.computeLength(center, new Coordinate({
|
24030 | x: center.x,
|
24031 | y: path[path.length - 1].y
|
24032 | }));
|
24033 | geometry.setWidth(rx * 2);
|
24034 | geometry.setHeight(ry * 2);
|
24035 | },
|
24036 | 'generate': function generate(geometry) {
|
24037 | return geometry;
|
24038 | }
|
24039 | });
|
24040 |
|
24041 | DrawTool.registerMode('freeHandEllipse', {
|
24042 | 'action': ['mousedown', 'mousemove', 'mouseup'],
|
24043 | 'create': function create(coordinates) {
|
24044 | return new Ellipse(coordinates[0], 0, 0);
|
24045 | },
|
24046 | 'update': function update(path, geometry) {
|
24047 | var map = geometry.getMap();
|
24048 | var center = geometry.getCenter();
|
24049 | var rx = map.computeLength(center, new Coordinate({
|
24050 | x: path[path.length - 1].x,
|
24051 | y: center.y
|
24052 | }));
|
24053 | var ry = map.computeLength(center, new Coordinate({
|
24054 | x: center.x,
|
24055 | y: path[path.length - 1].y
|
24056 | }));
|
24057 | geometry.setWidth(rx * 2);
|
24058 | geometry.setHeight(ry * 2);
|
24059 | },
|
24060 | 'generate': function generate(geometry) {
|
24061 | return geometry;
|
24062 | }
|
24063 | });
|
24064 |
|
24065 | DrawTool.registerMode('rectangle', {
|
24066 | 'clickLimit': 2,
|
24067 | 'action': ['click', 'mousemove', 'click'],
|
24068 | 'create': function create(coordinates) {
|
24069 | var rect = new Polygon([]);
|
24070 | rect._firstClick = coordinates[0];
|
24071 | return rect;
|
24072 | },
|
24073 | 'update': function update(coordinates, geometry, param) {
|
24074 | var map = geometry.getMap();
|
24075 | var containerPoint = param['containerPoint'];
|
24076 | var firstClick = map.coordToContainerPoint(geometry._firstClick);
|
24077 | var ring = [[firstClick.x, firstClick.y], [containerPoint.x, firstClick.y], [containerPoint.x, containerPoint.y], [firstClick.x, containerPoint.y]];
|
24078 | geometry.setCoordinates(ring.map(function (c) {
|
24079 | return map.containerPointToCoord(new Point(c));
|
24080 | }));
|
24081 | },
|
24082 | 'generate': function generate(geometry) {
|
24083 | return geometry;
|
24084 | }
|
24085 | });
|
24086 |
|
24087 | DrawTool.registerMode('freeHandRectangle', {
|
24088 | 'action': ['mousedown', 'mousemove', 'mouseup'],
|
24089 | 'create': function create(coordinates) {
|
24090 | var rect = new Polygon([]);
|
24091 | rect._firstClick = coordinates[0];
|
24092 | return rect;
|
24093 | },
|
24094 | 'update': function update(coordinates, geometry) {
|
24095 | var firstClick = geometry._firstClick;
|
24096 | var ring = [[firstClick.x, firstClick.y], [coordinates[0].x, firstClick.y], [coordinates[0].x, coordinates[0].y], [firstClick.x, coordinates[0].y]];
|
24097 | geometry.setCoordinates(ring);
|
24098 | },
|
24099 | 'generate': function generate(geometry) {
|
24100 | return geometry;
|
24101 | }
|
24102 | });
|
24103 |
|
24104 | DrawTool.registerMode('point', {
|
24105 | 'clickLimit': 1,
|
24106 | 'action': ['click'],
|
24107 | 'create': function create(coordinate) {
|
24108 | return new Marker(coordinate[0]);
|
24109 | },
|
24110 | 'generate': function generate(geometry) {
|
24111 | return geometry;
|
24112 | }
|
24113 | });
|
24114 |
|
24115 | DrawTool.registerMode('polygon', {
|
24116 | 'action': ['click', 'mousemove', 'dblclick'],
|
24117 | 'create': function create(path) {
|
24118 | return new LineString(path);
|
24119 | },
|
24120 | 'update': function update(path, geometry) {
|
24121 | var symbol = geometry.getSymbol();
|
24122 | geometry.setCoordinates(path);
|
24123 |
|
24124 | var layer = geometry.getLayer();
|
24125 | if (layer) {
|
24126 | var polygon = layer.getGeometryById('polygon');
|
24127 | if (!polygon && path.length >= 3) {
|
24128 | polygon = new Polygon([path], {
|
24129 | 'id': 'polygon'
|
24130 | });
|
24131 | if (symbol) {
|
24132 | var pSymbol = extendSymbol(symbol, {
|
24133 | 'lineOpacity': 0
|
24134 | });
|
24135 | polygon.setSymbol(pSymbol);
|
24136 | }
|
24137 | polygon.addTo(layer);
|
24138 | }
|
24139 | if (polygon) {
|
24140 | polygon.setCoordinates(path);
|
24141 | }
|
24142 | }
|
24143 | },
|
24144 | 'generate': function generate(geometry) {
|
24145 | return new Polygon(geometry.getCoordinates(), {
|
24146 | 'symbol': geometry.getSymbol()
|
24147 | });
|
24148 | }
|
24149 | });
|
24150 |
|
24151 | DrawTool.registerMode('freeHandPolygon', {
|
24152 | 'action': ['mousedown', 'mousemove', 'mouseup'],
|
24153 | 'create': function create(path) {
|
24154 | return new LineString(path);
|
24155 | },
|
24156 | 'update': function update(path, geometry) {
|
24157 | var coordinates = geometry.getCoordinates();
|
24158 | var symbol = geometry.getSymbol();
|
24159 | geometry.setCoordinates(coordinates.concat(path));
|
24160 |
|
24161 | var layer = geometry.getLayer();
|
24162 | if (layer) {
|
24163 | var polygon = layer.getGeometryById('polygon');
|
24164 | if (!polygon && path.length >= 3) {
|
24165 | polygon = new Polygon([path], {
|
24166 | 'id': 'polygon'
|
24167 | });
|
24168 | if (symbol) {
|
24169 | var pSymbol = extendSymbol(symbol, {
|
24170 | 'lineOpacity': 0
|
24171 | });
|
24172 | polygon.setSymbol(pSymbol);
|
24173 | }
|
24174 | polygon.addTo(layer);
|
24175 | }
|
24176 | if (polygon) {
|
24177 | polygon.setCoordinates(path);
|
24178 | }
|
24179 | }
|
24180 | },
|
24181 | 'generate': function generate(geometry) {
|
24182 | return new Polygon(geometry.getCoordinates(), {
|
24183 | 'symbol': geometry.getSymbol()
|
24184 | });
|
24185 | }
|
24186 | });
|
24187 |
|
24188 | DrawTool.registerMode('linestring', {
|
24189 | 'action': ['click', 'mousemove', 'dblclick'],
|
24190 | 'create': function create(path) {
|
24191 | return new LineString(path);
|
24192 | },
|
24193 | 'update': function update(path, geometry) {
|
24194 | geometry.setCoordinates(path);
|
24195 | },
|
24196 | 'generate': function generate(geometry) {
|
24197 | return geometry;
|
24198 | }
|
24199 | });
|
24200 |
|
24201 | DrawTool.registerMode('freeHandLinestring', {
|
24202 | 'action': ['mousedown', 'mousemove', 'mouseup'],
|
24203 | 'create': function create(path) {
|
24204 | return new LineString(path);
|
24205 | },
|
24206 | 'update': function update(path, geometry) {
|
24207 | var coordinates = geometry.getCoordinates();
|
24208 | geometry.setCoordinates(coordinates.concat(path));
|
24209 | },
|
24210 | 'generate': function generate(geometry) {
|
24211 | return geometry;
|
24212 | }
|
24213 | });
|
24214 |
|
24215 | DrawTool.registerMode('arccurve', {
|
24216 | 'action': ['click', 'mousemove', 'dblclick'],
|
24217 | 'create': function create(path) {
|
24218 | return new ArcCurve(path);
|
24219 | },
|
24220 | 'update': function update(path, geometry) {
|
24221 | geometry.setCoordinates(path);
|
24222 | },
|
24223 | 'generate': function generate(geometry) {
|
24224 | return geometry;
|
24225 | }
|
24226 | });
|
24227 |
|
24228 | DrawTool.registerMode('quadbeziercurve', {
|
24229 | 'action': ['click', 'mousemove', 'dblclick'],
|
24230 | 'create': function create(path) {
|
24231 | return new QuadBezierCurve(path);
|
24232 | },
|
24233 | 'update': function update(path, geometry) {
|
24234 | geometry.setCoordinates(path);
|
24235 | },
|
24236 | 'generate': function generate(geometry) {
|
24237 | return geometry;
|
24238 | }
|
24239 | });
|
24240 |
|
24241 | DrawTool.registerMode('cubicbeziercurve', {
|
24242 | 'action': ['click', 'mousemove', 'dblclick'],
|
24243 | 'create': function create(path) {
|
24244 | return new CubicBezierCurve(path);
|
24245 | },
|
24246 | 'update': function update(path, geometry) {
|
24247 | geometry.setCoordinates(path);
|
24248 | },
|
24249 | 'generate': function generate(geometry) {
|
24250 | return geometry;
|
24251 | }
|
24252 | });
|
24253 |
|
24254 | DrawTool.registerMode('boxZoom', {
|
24255 | 'action': ['mousedown', 'mousemove', 'mouseup'],
|
24256 | 'create': function create(coordinates) {
|
24257 | var marker = new Marker(coordinates[0]);
|
24258 | marker._firstClick = coordinates[0];
|
24259 | return marker;
|
24260 | },
|
24261 | 'update': function update(path, geometry, param) {
|
24262 | var map = geometry.getMap();
|
24263 | var p1 = map.coordToContainerPoint(geometry._firstClick),
|
24264 | p2 = param['containerPoint'];
|
24265 | var coords = map.containerPointToCoordinate(new Coordinate(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y)));
|
24266 | geometry.setCoordinates(coords).updateSymbol({
|
24267 | markerWidth: Math.abs(p1.x - p2.x),
|
24268 | markerHeight: Math.abs(p1.y - p2.y)
|
24269 | });
|
24270 | },
|
24271 | 'generate': function generate(geometry) {
|
24272 | return geometry;
|
24273 | }
|
24274 | });
|
24275 |
|
24276 | function parse(arcConf) {
|
24277 | var tileInfo = arcConf['tileInfo'],
|
24278 | tileSize = [tileInfo['cols'], tileInfo['rows']],
|
24279 | resolutions = [],
|
24280 | lods = tileInfo['lods'];
|
24281 | for (var i = 0, len = lods.length; i < len; i++) {
|
24282 | resolutions.push(lods[i]['resolution']);
|
24283 | }
|
24284 | var fullExtent = arcConf['fullExtent'],
|
24285 | origin = tileInfo['origin'],
|
24286 | tileSystem = [1, -1, origin['x'], origin['y']];
|
24287 | delete fullExtent['spatialReference'];
|
24288 | return {
|
24289 | 'spatialReference': {
|
24290 | 'resolutions': resolutions,
|
24291 | 'fullExtent': fullExtent
|
24292 | },
|
24293 | 'tileSystem': tileSystem,
|
24294 | 'tileSize': tileSize
|
24295 | };
|
24296 | }
|
24297 |
|
24298 | SpatialReference.loadArcgis = function (url, cb) {
|
24299 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { 'jsonp': true };
|
24300 |
|
24301 | if (isString(url) && url.substring(0, 1) !== '{') {
|
24302 | Ajax.getJSON(url, function (err, json) {
|
24303 | if (err) {
|
24304 | cb(err);
|
24305 | return;
|
24306 | }
|
24307 | var spatialRef = parse(json);
|
24308 | cb(null, spatialRef);
|
24309 | }, options);
|
24310 | } else {
|
24311 | if (isString(url)) {
|
24312 | url = parseJSON(url);
|
24313 | }
|
24314 | var spatialRef = parse(url);
|
24315 | cb(null, spatialRef);
|
24316 | }
|
24317 | return this;
|
24318 | };
|
24319 |
|
24320 | var options$19 = {
|
24321 | 'eventsPropagation': false,
|
24322 | 'eventsToStop': null,
|
24323 | 'dx': 0,
|
24324 | 'dy': 0,
|
24325 | 'autoPan': false,
|
24326 | 'autoPanDuration': 600,
|
24327 | 'single': true,
|
24328 | 'animation': 'scale',
|
24329 | 'animationOnHide': true,
|
24330 | 'animationDuration': 500
|
24331 | };
|
24332 |
|
24333 | var UIComponent = function (_Eventable) {
|
24334 | inherits(UIComponent, _Eventable);
|
24335 |
|
24336 | function UIComponent(options) {
|
24337 | classCallCheck(this, UIComponent);
|
24338 | return possibleConstructorReturn(this, _Eventable.call(this, options));
|
24339 | }
|
24340 |
|
24341 | UIComponent.prototype.addTo = function addTo(owner) {
|
24342 | this._owner = owner;
|
24343 |
|
24344 | this._switchEvents('on');
|
24345 | if (this.onAdd) {
|
24346 | this.onAdd();
|
24347 | }
|
24348 |
|
24349 | this.fire('add');
|
24350 | return this;
|
24351 | };
|
24352 |
|
24353 | UIComponent.prototype.getMap = function getMap() {
|
24354 | if (!this._owner) {
|
24355 | return null;
|
24356 | }
|
24357 |
|
24358 | if (this._owner.getBaseLayer) {
|
24359 | return this._owner;
|
24360 | }
|
24361 | return this._owner.getMap();
|
24362 | };
|
24363 |
|
24364 | UIComponent.prototype.show = function show(coordinate) {
|
24365 | var map = this.getMap();
|
24366 | if (!map) {
|
24367 | return this;
|
24368 | }
|
24369 |
|
24370 | if (!this._mapEventsOn) {
|
24371 | this._switchMapEvents('on');
|
24372 | }
|
24373 |
|
24374 | coordinate = coordinate || this._coordinate || this._owner.getCenter();
|
24375 |
|
24376 | var visible = this.isVisible();
|
24377 |
|
24378 | this.fire('showstart');
|
24379 | var container = this._getUIContainer();
|
24380 | this._coordinate = coordinate;
|
24381 | this._removePrevDOM();
|
24382 | var dom = this.__uiDOM = this.buildOn(map);
|
24383 | dom['eventsPropagation'] = this.options['eventsPropagation'];
|
24384 |
|
24385 | if (!dom) {
|
24386 | this.fire('showend');
|
24387 | return this;
|
24388 | }
|
24389 |
|
24390 | this._measureSize(dom);
|
24391 |
|
24392 | if (this._singleton()) {
|
24393 | map[this._uiDomKey()] = dom;
|
24394 | }
|
24395 |
|
24396 | this._setPosition();
|
24397 |
|
24398 | dom.style[TRANSITION] = null;
|
24399 |
|
24400 | container.appendChild(dom);
|
24401 |
|
24402 | var anim = this._getAnimation();
|
24403 |
|
24404 | if (visible) {
|
24405 | anim.ok = false;
|
24406 | }
|
24407 |
|
24408 | if (anim.ok) {
|
24409 | if (anim.fade) {
|
24410 | dom.style.opacity = 0;
|
24411 | }
|
24412 | if (anim.scale) {
|
24413 | if (this.getTransformOrigin) {
|
24414 | var origin = this.getTransformOrigin();
|
24415 | dom.style[TRANSFORMORIGIN] = origin;
|
24416 | }
|
24417 | dom.style[TRANSFORM] = toCSSTranslate(this._pos) + ' scale(0)';
|
24418 | }
|
24419 | }
|
24420 |
|
24421 | dom.style.display = '';
|
24422 |
|
24423 | if (this.options['eventsToStop']) {
|
24424 | on(dom, this.options['eventsToStop'], stopPropagation);
|
24425 | }
|
24426 |
|
24427 | if (this.options['autoPan']) {
|
24428 | this._autoPan();
|
24429 | }
|
24430 |
|
24431 | var transition = anim.transition;
|
24432 | if (anim.ok && transition) {
|
24433 | dom.offsetHeight;
|
24434 |
|
24435 | if (transition) {
|
24436 | dom.style[TRANSITION] = transition;
|
24437 | }
|
24438 | if (anim.fade) {
|
24439 | dom.style.opacity = 1;
|
24440 | }
|
24441 | if (anim.scale) {
|
24442 | dom.style[TRANSFORM] = toCSSTranslate(this._pos) + ' scale(1)';
|
24443 | }
|
24444 | }
|
24445 |
|
24446 | this.fire('showend');
|
24447 | return this;
|
24448 | };
|
24449 |
|
24450 | UIComponent.prototype.hide = function hide() {
|
24451 | if (!this.getDOM() || !this.getMap()) {
|
24452 | return this;
|
24453 | }
|
24454 |
|
24455 | var anim = this._getAnimation(),
|
24456 | dom = this.getDOM();
|
24457 | if (!this.options['animationOnHide']) {
|
24458 | anim.ok = false;
|
24459 | }
|
24460 | if (!anim.ok) {
|
24461 | dom.style.display = 'none';
|
24462 | } else {
|
24463 | dom.offsetHeight;
|
24464 |
|
24465 | dom.style[TRANSITION] = anim.transition;
|
24466 | setTimeout(function () {
|
24467 | dom.style.display = 'none';
|
24468 | }, this.options['animationDuration']);
|
24469 | }
|
24470 | if (anim.fade) {
|
24471 | dom.style.opacity = 0;
|
24472 | }
|
24473 | if (anim.scale) {
|
24474 | dom.style[TRANSFORM] = toCSSTranslate(this._pos) + ' scale(0)';
|
24475 | }
|
24476 |
|
24477 | this.fire('hide');
|
24478 | return this;
|
24479 | };
|
24480 |
|
24481 | UIComponent.prototype.isVisible = function isVisible() {
|
24482 | var dom = this.getDOM();
|
24483 | return this.getMap() && dom && dom.parentNode && dom.style.display !== 'none';
|
24484 | };
|
24485 |
|
24486 | UIComponent.prototype.remove = function remove() {
|
24487 | delete this._mapEventsOn;
|
24488 | if (!this._owner) {
|
24489 | return this;
|
24490 | }
|
24491 | this.hide();
|
24492 | this._switchEvents('off');
|
24493 | if (this.onRemove) {
|
24494 | this.onRemove();
|
24495 | }
|
24496 | if (!this._singleton() && this.__uiDOM) {
|
24497 | this._removePrevDOM();
|
24498 | }
|
24499 | delete this._owner;
|
24500 |
|
24501 | this.fire('remove');
|
24502 | return this;
|
24503 | };
|
24504 |
|
24505 | UIComponent.prototype.getSize = function getSize() {
|
24506 | if (this._size) {
|
24507 | return this._size.copy();
|
24508 | } else {
|
24509 | return null;
|
24510 | }
|
24511 | };
|
24512 |
|
24513 | UIComponent.prototype.getOwner = function getOwner() {
|
24514 | return this._owner;
|
24515 | };
|
24516 |
|
24517 | UIComponent.prototype.getDOM = function getDOM() {
|
24518 | return this.__uiDOM;
|
24519 | };
|
24520 |
|
24521 | UIComponent.prototype.getPosition = function getPosition() {
|
24522 | if (!this.getMap()) {
|
24523 | return null;
|
24524 | }
|
24525 | var p = this._getViewPoint()._round();
|
24526 | if (this.getOffset) {
|
24527 | var o = this.getOffset()._round();
|
24528 | if (o) {
|
24529 | p._add(o);
|
24530 | }
|
24531 | }
|
24532 | return p;
|
24533 | };
|
24534 |
|
24535 | UIComponent.prototype._getAnimation = function _getAnimation() {
|
24536 | var anim = {
|
24537 | 'fade': false,
|
24538 | 'scale': false
|
24539 | };
|
24540 | var animations = this.options['animation'] ? this.options['animation'].split(',') : [];
|
24541 | for (var i = 0; i < animations.length; i++) {
|
24542 | var trimed = trim(animations[i]);
|
24543 | if (trimed === 'fade') {
|
24544 | anim.fade = true;
|
24545 | } else if (trimed === 'scale') {
|
24546 | anim.scale = true;
|
24547 | }
|
24548 | }
|
24549 | var transition = null;
|
24550 | if (anim.fade) {
|
24551 | transition = 'opacity ' + this.options['animationDuration'] + 'ms';
|
24552 | }
|
24553 | if (anim.scale) {
|
24554 | transition = transition ? transition + ',' : '';
|
24555 | transition += TRANSFORM + ' ' + this.options['animationDuration'] + 'ms';
|
24556 | }
|
24557 | anim.transition = transition;
|
24558 | anim.ok = transition !== null;
|
24559 | return anim;
|
24560 | };
|
24561 |
|
24562 | UIComponent.prototype._getViewPoint = function _getViewPoint() {
|
24563 | return this.getMap().coordToViewPoint(this._coordinate)._add(this.options['dx'], this.options['dy']);
|
24564 | };
|
24565 |
|
24566 | UIComponent.prototype._autoPan = function _autoPan() {
|
24567 | var map = this.getMap(),
|
24568 | dom = this.getDOM();
|
24569 | if (map.isMoving()) {
|
24570 | return;
|
24571 | }
|
24572 | var point = this._pos;
|
24573 | var mapSize = map.getSize(),
|
24574 | mapWidth = mapSize['width'],
|
24575 | mapHeight = mapSize['height'];
|
24576 |
|
24577 | var containerPoint = map.viewPointToContainerPoint(point);
|
24578 | var clientWidth = parseInt(dom.clientWidth),
|
24579 | clientHeight = parseInt(dom.clientHeight);
|
24580 | var left = 0,
|
24581 | top = 0;
|
24582 | if (containerPoint.x < 0) {
|
24583 | left = -(containerPoint.x - clientWidth / 2);
|
24584 | } else if (containerPoint.x + clientWidth - 35 > mapWidth) {
|
24585 | left = mapWidth - (containerPoint.x + clientWidth * 3 / 2);
|
24586 | }
|
24587 | if (containerPoint.y < 0) {
|
24588 | top = -containerPoint.y + 50;
|
24589 | } else if (containerPoint.y > mapHeight) {
|
24590 | top = mapHeight - containerPoint.y - clientHeight - 30;
|
24591 | }
|
24592 | if (top !== 0 || left !== 0) {
|
24593 | map.panBy(new Point(left, top), { 'duration': this.options['autoPanDuration'] });
|
24594 | }
|
24595 | };
|
24596 |
|
24597 | UIComponent.prototype._measureSize = function _measureSize(dom) {
|
24598 | var container = this._getUIContainer();
|
24599 | dom.style.position = 'absolute';
|
24600 | dom.style.left = -99999 + 'px';
|
24601 | var anchor = dom.style.bottom ? 'bottom' : 'top';
|
24602 | dom.style[anchor] = -99999 + 'px';
|
24603 | dom.style.display = '';
|
24604 | container.appendChild(dom);
|
24605 | this._size = new Size(dom.clientWidth, dom.clientHeight);
|
24606 | dom.style.display = 'none';
|
24607 | dom.style.left = '0px';
|
24608 | dom.style[anchor] = '0px';
|
24609 | return this._size;
|
24610 | };
|
24611 |
|
24612 | UIComponent.prototype._removePrevDOM = function _removePrevDOM() {
|
24613 | if (this.onDomRemove) {
|
24614 | this.onDomRemove();
|
24615 | }
|
24616 | var eventsToStop = this.options['eventsToStop'];
|
24617 | if (this._singleton()) {
|
24618 | var map = this.getMap(),
|
24619 | key = this._uiDomKey();
|
24620 | if (map[key]) {
|
24621 | if (eventsToStop) {
|
24622 | off(map[key], eventsToStop, stopPropagation);
|
24623 | }
|
24624 | removeDomNode(map[key]);
|
24625 | delete map[key];
|
24626 | }
|
24627 | delete this.__uiDOM;
|
24628 | } else if (this.__uiDOM) {
|
24629 | if (eventsToStop) {
|
24630 | off(this.__uiDOM, eventsToStop, stopPropagation);
|
24631 | }
|
24632 | removeDomNode(this.__uiDOM);
|
24633 | delete this.__uiDOM;
|
24634 | }
|
24635 | };
|
24636 |
|
24637 | UIComponent.prototype._uiDomKey = function _uiDomKey() {
|
24638 | return '__ui_' + this._getClassName();
|
24639 | };
|
24640 |
|
24641 | UIComponent.prototype._singleton = function _singleton() {
|
24642 | return this.options['single'];
|
24643 | };
|
24644 |
|
24645 | UIComponent.prototype._getUIContainer = function _getUIContainer() {
|
24646 | return this.getMap()._panels['ui'];
|
24647 | };
|
24648 |
|
24649 | UIComponent.prototype._getClassName = function _getClassName() {
|
24650 | return 'UIComponent';
|
24651 | };
|
24652 |
|
24653 | UIComponent.prototype._switchMapEvents = function _switchMapEvents(to) {
|
24654 | var map = this.getMap();
|
24655 | if (!map) {
|
24656 | return;
|
24657 | }
|
24658 | this._mapEventsOn = to === 'on';
|
24659 | var events = this._getDefaultEvents();
|
24660 | if (this.getEvents) {
|
24661 | extend(events, this.getEvents());
|
24662 | }
|
24663 | if (events) {
|
24664 | for (var p in events) {
|
24665 | if (events.hasOwnProperty(p)) {
|
24666 | map[to](p, events[p], this);
|
24667 | }
|
24668 | }
|
24669 | }
|
24670 | };
|
24671 |
|
24672 | UIComponent.prototype._switchEvents = function _switchEvents(to) {
|
24673 | this._switchMapEvents(to);
|
24674 | var ownerEvents = this._getOwnerEvents();
|
24675 | if (this._owner) {
|
24676 | for (var p in ownerEvents) {
|
24677 | if (ownerEvents.hasOwnProperty(p)) {
|
24678 | this._owner[to](p, ownerEvents[p], this);
|
24679 | }
|
24680 | }
|
24681 | }
|
24682 | };
|
24683 |
|
24684 | UIComponent.prototype._getDefaultEvents = function _getDefaultEvents() {
|
24685 | return {
|
24686 | 'zooming rotate pitch': this.onEvent,
|
24687 | 'zoomend': this.onZoomEnd,
|
24688 | 'moving': this.onMoving
|
24689 | };
|
24690 | };
|
24691 |
|
24692 | UIComponent.prototype._getOwnerEvents = function _getOwnerEvents() {
|
24693 | var events = {};
|
24694 | if (this._owner && this._owner instanceof Geometry) {
|
24695 | events.positionchange = this.onGeometryPositionChange;
|
24696 | }
|
24697 | if (this.getOwnerEvents) {
|
24698 | extend(events, this.getOwnerEvents());
|
24699 | }
|
24700 | return events;
|
24701 | };
|
24702 |
|
24703 | UIComponent.prototype.onGeometryPositionChange = function onGeometryPositionChange(param) {
|
24704 | if (this._owner && this.isVisible()) {
|
24705 | this.show(param['target'].getCenter());
|
24706 | }
|
24707 | };
|
24708 |
|
24709 | UIComponent.prototype.onMoving = function onMoving() {
|
24710 | if (this.isVisible() && this.getMap().isTransforming()) {
|
24711 | this._updatePosition();
|
24712 | }
|
24713 | };
|
24714 |
|
24715 | UIComponent.prototype.onEvent = function onEvent() {
|
24716 | if (this.isVisible()) {
|
24717 | this._updatePosition();
|
24718 | }
|
24719 | };
|
24720 |
|
24721 | UIComponent.prototype.onZoomEnd = function onZoomEnd() {
|
24722 | if (this.isVisible()) {
|
24723 | this._setPosition();
|
24724 | }
|
24725 | };
|
24726 |
|
24727 | UIComponent.prototype._updatePosition = function _updatePosition() {
|
24728 | var renderer = this.getMap()._getRenderer();
|
24729 | renderer.callInNextFrame(this._setPosition.bind(this));
|
24730 | };
|
24731 |
|
24732 | UIComponent.prototype._setPosition = function _setPosition() {
|
24733 | var dom = this.getDOM(),
|
24734 | p = this.getPosition();
|
24735 | this._pos = p;
|
24736 | dom.style[TRANSITION] = null;
|
24737 | dom.style[TRANSFORM] = toCSSTranslate(p) + ' scale(1)';
|
24738 | };
|
24739 |
|
24740 | return UIComponent;
|
24741 | }(Eventable(Class));
|
24742 |
|
24743 | UIComponent.mergeOptions(options$19);
|
24744 |
|
24745 | function toCSSTranslate(p) {
|
24746 | if (!p) {
|
24747 | return '';
|
24748 | }
|
24749 | if (Browser$1.any3d) {
|
24750 | return 'translate3d(' + p.x + 'px,' + p.y + 'px, 0px)';
|
24751 | } else {
|
24752 | return 'translate(' + p.x + 'px,' + p.y + 'px)';
|
24753 | }
|
24754 | }
|
24755 |
|
24756 | var options$20 = {
|
24757 | 'eventsPropagation': true,
|
24758 | 'draggable': false,
|
24759 | 'single': false,
|
24760 | 'content': null
|
24761 | };
|
24762 |
|
24763 | var domEvents = 'mousedown ' + 'mouseup ' + 'mouseenter ' + 'mouseover ' + 'mouseout ' + 'mousemove ' + 'click ' + 'dblclick ' + 'contextmenu ' + 'keypress ' + 'touchstart ' + 'touchmove ' + 'touchend';
|
24764 |
|
24765 | var UIMarker = function (_Handlerable) {
|
24766 | inherits(UIMarker, _Handlerable);
|
24767 |
|
24768 | function UIMarker(coordinate, options) {
|
24769 | classCallCheck(this, UIMarker);
|
24770 |
|
24771 | var _this = possibleConstructorReturn(this, _Handlerable.call(this, options));
|
24772 |
|
24773 | _this._markerCoord = new Coordinate(coordinate);
|
24774 | return _this;
|
24775 | }
|
24776 |
|
24777 | UIMarker.prototype._getClassName = function _getClassName() {
|
24778 | return 'UIMarker';
|
24779 | };
|
24780 |
|
24781 | UIMarker.prototype.setCoordinates = function setCoordinates(coordinates) {
|
24782 | this._markerCoord = coordinates;
|
24783 |
|
24784 | this.fire('positionchange');
|
24785 | if (this.isVisible()) {
|
24786 | this._coordinate = this._markerCoord;
|
24787 | this._setPosition();
|
24788 | }
|
24789 | return this;
|
24790 | };
|
24791 |
|
24792 | UIMarker.prototype.getCoordinates = function getCoordinates() {
|
24793 | return this._markerCoord;
|
24794 | };
|
24795 |
|
24796 | UIMarker.prototype.setContent = function setContent(content) {
|
24797 | var old = this.options['content'];
|
24798 | this.options['content'] = content;
|
24799 |
|
24800 | this.fire('contentchange', {
|
24801 | 'old': old,
|
24802 | 'new': content
|
24803 | });
|
24804 | if (this.isVisible()) {
|
24805 | this.show();
|
24806 | }
|
24807 | return this;
|
24808 | };
|
24809 |
|
24810 | UIMarker.prototype.getContent = function getContent() {
|
24811 | return this.options['content'];
|
24812 | };
|
24813 |
|
24814 | UIMarker.prototype.onAdd = function onAdd() {
|
24815 | this.show();
|
24816 | };
|
24817 |
|
24818 | UIMarker.prototype.show = function show() {
|
24819 | return _Handlerable.prototype.show.call(this, this._markerCoord);
|
24820 | };
|
24821 |
|
24822 | UIMarker.prototype.flash = function flash$$1(interval, count, cb, context) {
|
24823 | return flash.call(this, interval, count, cb, context);
|
24824 | };
|
24825 |
|
24826 | UIMarker.prototype.buildOn = function buildOn() {
|
24827 | var dom = void 0;
|
24828 | if (isString(this.options['content'])) {
|
24829 | dom = createEl('div');
|
24830 | dom.innerHTML = this.options['content'];
|
24831 | } else {
|
24832 | dom = this.options['content'];
|
24833 | }
|
24834 | this._registerDOMEvents(dom);
|
24835 | return dom;
|
24836 | };
|
24837 |
|
24838 | UIMarker.prototype.getOffset = function getOffset() {
|
24839 | var size = this.getSize();
|
24840 | return new Point(-size.width / 2, -size.height / 2);
|
24841 | };
|
24842 |
|
24843 | UIMarker.prototype.getTransformOrigin = function getTransformOrigin() {
|
24844 | return 'center center';
|
24845 | };
|
24846 |
|
24847 | UIMarker.prototype.onDomRemove = function onDomRemove() {
|
24848 | var dom = this.getDOM();
|
24849 | this._removeDOMEvents(dom);
|
24850 | };
|
24851 |
|
24852 | UIMarker.prototype.isDragging = function isDragging() {
|
24853 | if (this['draggable']) {
|
24854 | return this['draggable'].isDragging();
|
24855 | }
|
24856 | return false;
|
24857 | };
|
24858 |
|
24859 | UIMarker.prototype._registerDOMEvents = function _registerDOMEvents(dom) {
|
24860 | on(dom, domEvents, this._onDomEvents, this);
|
24861 | };
|
24862 |
|
24863 | UIMarker.prototype._onDomEvents = function _onDomEvents(e) {
|
24864 | var event = this.getMap()._parseEvent(e, e.type);
|
24865 | this.fire(e.type, event);
|
24866 | };
|
24867 |
|
24868 | UIMarker.prototype._removeDOMEvents = function _removeDOMEvents(dom) {
|
24869 | off(dom, domEvents, this._onDomEvents, this);
|
24870 | };
|
24871 |
|
24872 | UIMarker.prototype._getConnectPoints = function _getConnectPoints() {
|
24873 | var map = this.getMap();
|
24874 | var containerPoint = map.coordToContainerPoint(this.getCoordinates());
|
24875 | var size = this.getSize(),
|
24876 | width = size.width,
|
24877 | height = size.height;
|
24878 | var anchors = [map.containerPointToCoordinate(containerPoint.add(-width / 2, 0)), map.containerPointToCoordinate(containerPoint.add(width / 2, 0)), map.containerPointToCoordinate(containerPoint.add(0, height / 2)), map.containerPointToCoordinate(containerPoint.add(0, -height / 2))];
|
24879 | return anchors;
|
24880 | };
|
24881 |
|
24882 | return UIMarker;
|
24883 | }(Handlerable(UIComponent));
|
24884 |
|
24885 | UIMarker.mergeOptions(options$20);
|
24886 |
|
24887 | var EVENTS$1 = Browser$1.touch ? 'touchstart mousedown' : 'mousedown';
|
24888 |
|
24889 | var UIMarkerDragHandler = function (_Handler) {
|
24890 | inherits(UIMarkerDragHandler, _Handler);
|
24891 |
|
24892 | function UIMarkerDragHandler(target) {
|
24893 | classCallCheck(this, UIMarkerDragHandler);
|
24894 | return possibleConstructorReturn(this, _Handler.call(this, target));
|
24895 | }
|
24896 |
|
24897 | UIMarkerDragHandler.prototype.addHooks = function addHooks() {
|
24898 | this.target.on(EVENTS$1, this._startDrag, this);
|
24899 | };
|
24900 |
|
24901 | UIMarkerDragHandler.prototype.removeHooks = function removeHooks() {
|
24902 | this.target.off(EVENTS$1, this._startDrag, this);
|
24903 | };
|
24904 |
|
24905 | UIMarkerDragHandler.prototype._startDrag = function _startDrag(param) {
|
24906 | var domEvent = param['domEvent'];
|
24907 | if (domEvent.touches && domEvent.touches.length > 1 || domEvent.button === 2) {
|
24908 | return;
|
24909 | }
|
24910 | if (this.isDragging()) {
|
24911 | return;
|
24912 | }
|
24913 | this.target.on('click', this._endDrag, this);
|
24914 | this._lastCoord = param['coordinate'];
|
24915 | this._lastPoint = param['containerPoint'];
|
24916 |
|
24917 | this._prepareDragHandler();
|
24918 | this._dragHandler.onMouseDown(param['domEvent']);
|
24919 |
|
24920 | this.target.fire('dragstart', param);
|
24921 | };
|
24922 |
|
24923 | UIMarkerDragHandler.prototype._prepareDragHandler = function _prepareDragHandler() {
|
24924 | this._dragHandler = new DragHandler(this.target.getDOM(), {
|
24925 | 'cancelOn': this._cancelOn.bind(this),
|
24926 | 'ignoreMouseleave': true
|
24927 | });
|
24928 | this._dragHandler.on('mousedown', this._onMouseDown, this);
|
24929 | this._dragHandler.on('dragging', this._dragging, this);
|
24930 | this._dragHandler.on('mouseup', this._endDrag, this);
|
24931 | this._dragHandler.enable();
|
24932 | };
|
24933 |
|
24934 | UIMarkerDragHandler.prototype._cancelOn = function _cancelOn(domEvent) {
|
24935 | var target = domEvent.srcElement || domEvent.target,
|
24936 | tagName = target.tagName.toLowerCase();
|
24937 | if (tagName === 'button' || tagName === 'input' || tagName === 'select' || tagName === 'option' || tagName === 'textarea') {
|
24938 | return true;
|
24939 | }
|
24940 | return false;
|
24941 | };
|
24942 |
|
24943 | UIMarkerDragHandler.prototype._onMouseDown = function _onMouseDown(param) {
|
24944 | stopPropagation(param['domEvent']);
|
24945 | };
|
24946 |
|
24947 | UIMarkerDragHandler.prototype._dragging = function _dragging(param) {
|
24948 | var target = this.target,
|
24949 | map = target.getMap(),
|
24950 | eventParam = map._parseEvent(param['domEvent']),
|
24951 | domEvent = eventParam['domEvent'];
|
24952 | if (domEvent.touches && domEvent.touches.length > 1) {
|
24953 | return;
|
24954 | }
|
24955 | if (!this._isDragging) {
|
24956 | this._isDragging = true;
|
24957 | return;
|
24958 | }
|
24959 |
|
24960 | var coord = eventParam['coordinate'],
|
24961 | point = eventParam['containerPoint'];
|
24962 | if (!this._lastCoord) {
|
24963 | this._lastCoord = coord;
|
24964 | }
|
24965 | if (!this._lastPoint) {
|
24966 | this._lastPoint = point;
|
24967 | }
|
24968 | var coordOffset = coord.sub(this._lastCoord),
|
24969 | pointOffset = point.sub(this._lastPoint);
|
24970 | this._lastCoord = coord;
|
24971 | this._lastPoint = point;
|
24972 | this.target.setCoordinates(this.target.getCoordinates().add(coordOffset));
|
24973 | eventParam['coordOffset'] = coordOffset;
|
24974 | eventParam['pointOffset'] = pointOffset;
|
24975 |
|
24976 | target.fire('dragging', eventParam);
|
24977 | };
|
24978 |
|
24979 | UIMarkerDragHandler.prototype._endDrag = function _endDrag(param) {
|
24980 | var target = this.target,
|
24981 | map = target.getMap();
|
24982 | if (this._dragHandler) {
|
24983 | target.off('click', this._endDrag, this);
|
24984 | this._dragHandler.disable();
|
24985 | delete this._dragHandler;
|
24986 | }
|
24987 | delete this._lastCoord;
|
24988 | delete this._lastPoint;
|
24989 | this._isDragging = false;
|
24990 | if (!map) {
|
24991 | return;
|
24992 | }
|
24993 | var eventParam = map._parseEvent(param['domEvent']);
|
24994 |
|
24995 | target.fire('dragend', eventParam);
|
24996 | };
|
24997 |
|
24998 | UIMarkerDragHandler.prototype.isDragging = function isDragging() {
|
24999 | if (!this._isDragging) {
|
25000 | return false;
|
25001 | }
|
25002 | return true;
|
25003 | };
|
25004 |
|
25005 | return UIMarkerDragHandler;
|
25006 | }(Handler$1);
|
25007 |
|
25008 | UIMarker.addInitHook('addHandler', 'draggable', UIMarkerDragHandler);
|
25009 |
|
25010 | var options$21 = {
|
25011 | 'autoPan': true,
|
25012 | 'autoCloseOn': null,
|
25013 | 'autoOpenOn': 'click',
|
25014 | 'width': 300,
|
25015 | 'minHeight': 120,
|
25016 | 'custom': false,
|
25017 | 'title': null,
|
25018 | 'content': null
|
25019 | };
|
25020 |
|
25021 | var InfoWindow = function (_UIComponent) {
|
25022 | inherits(InfoWindow, _UIComponent);
|
25023 |
|
25024 | function InfoWindow() {
|
25025 | classCallCheck(this, InfoWindow);
|
25026 | return possibleConstructorReturn(this, _UIComponent.apply(this, arguments));
|
25027 | }
|
25028 |
|
25029 | InfoWindow.prototype._getClassName = function _getClassName() {
|
25030 | return 'InfoWindow';
|
25031 | };
|
25032 |
|
25033 | InfoWindow.prototype.addTo = function addTo(owner) {
|
25034 | if (owner instanceof Geometry) {
|
25035 | if (owner.getInfoWindow() && owner.getInfoWindow() !== this) {
|
25036 | owner.removeInfoWindow();
|
25037 | }
|
25038 | owner._infoWindow = this;
|
25039 | }
|
25040 | return _UIComponent.prototype.addTo.call(this, owner);
|
25041 | };
|
25042 |
|
25043 | InfoWindow.prototype.setContent = function setContent(content) {
|
25044 | var old = this.options['content'];
|
25045 | this.options['content'] = content;
|
25046 |
|
25047 | this.fire('contentchange', {
|
25048 | 'old': old,
|
25049 | 'new': content
|
25050 | });
|
25051 | if (this.isVisible()) {
|
25052 | this.show(this._coordinate);
|
25053 | }
|
25054 | return this;
|
25055 | };
|
25056 |
|
25057 | InfoWindow.prototype.getContent = function getContent() {
|
25058 | return this.options['content'];
|
25059 | };
|
25060 |
|
25061 | InfoWindow.prototype.setTitle = function setTitle(title) {
|
25062 | var old = title;
|
25063 | this.options['title'] = title;
|
25064 |
|
25065 | this.fire('contentchange', {
|
25066 | 'old': old,
|
25067 | 'new': title
|
25068 | });
|
25069 | if (this.isVisible()) {
|
25070 | this.show(this._coordinate);
|
25071 | }
|
25072 | return this;
|
25073 | };
|
25074 |
|
25075 | InfoWindow.prototype.getTitle = function getTitle() {
|
25076 | return this.options['title'];
|
25077 | };
|
25078 |
|
25079 | InfoWindow.prototype.buildOn = function buildOn() {
|
25080 | if (this.options['custom']) {
|
25081 | if (isString(this.options['content'])) {
|
25082 | var _dom = createEl('div');
|
25083 | _dom.innerHTML = this.options['content'];
|
25084 | return _dom;
|
25085 | } else {
|
25086 | return this.options['content'];
|
25087 | }
|
25088 | }
|
25089 | var dom = createEl('div');
|
25090 | dom.className = 'maptalks-msgBox';
|
25091 | dom.style.width = this._getWindowWidth() + 'px';
|
25092 | dom.style.bottom = '0px';
|
25093 | var content = '<em class="maptalks-ico"></em>';
|
25094 | if (this.options['title']) {
|
25095 | content += '<h2>' + this.options['title'] + '</h2>';
|
25096 | }
|
25097 | var onClose = '"this.parentNode.style.display=\'none\';return false;"';
|
25098 | content += '<a href="javascript:void(0);" onclick=' + onClose + ' ontouchend=' + onClose + ' class="maptalks-close"></a><div class="maptalks-msgContent">' + this.options['content'] + '</div>';
|
25099 | dom.innerHTML = content;
|
25100 | return dom;
|
25101 | };
|
25102 |
|
25103 | InfoWindow.prototype.getTransformOrigin = function getTransformOrigin() {
|
25104 | var size = this.getSize();
|
25105 | return size.width / 2 + 'px bottom';
|
25106 | };
|
25107 |
|
25108 | InfoWindow.prototype.getOffset = function getOffset() {
|
25109 | var size = this.getSize();
|
25110 | var o = new Point(-size['width'] / 2, 0);
|
25111 | if (!this.options['custom']) {
|
25112 | o._sub(4, 12);
|
25113 | }
|
25114 | var owner = this.getOwner();
|
25115 | if (owner instanceof Marker) {
|
25116 | var painter = owner._getPainter();
|
25117 | if (painter) {
|
25118 | var markerSize = owner.getSize();
|
25119 | var fixExtent = painter.getFixedExtent();
|
25120 | o._add(fixExtent.xmax - markerSize.width / 2, fixExtent.ymin);
|
25121 | }
|
25122 | }
|
25123 | return o;
|
25124 | };
|
25125 |
|
25126 | InfoWindow.prototype.show = function show(coordinate) {
|
25127 | if (!this.getMap()) {
|
25128 | return this;
|
25129 | }
|
25130 | if (!this.getMap().options['enableInfoWindow']) {
|
25131 | return this;
|
25132 | }
|
25133 | return _UIComponent.prototype.show.call(this, coordinate);
|
25134 | };
|
25135 |
|
25136 | InfoWindow.prototype.getEvents = function getEvents() {
|
25137 | if (!this.options['autoCloseOn']) {
|
25138 | return null;
|
25139 | }
|
25140 | var events = {};
|
25141 | events[this.options['autoCloseOn']] = this.hide;
|
25142 | return events;
|
25143 | };
|
25144 |
|
25145 | InfoWindow.prototype.getOwnerEvents = function getOwnerEvents() {
|
25146 | var owner = this.getOwner();
|
25147 | if (!this.options['autoOpenOn'] || !owner) {
|
25148 | return null;
|
25149 | }
|
25150 | var events = {};
|
25151 | events[this.options['autoOpenOn']] = this._onAutoOpen;
|
25152 | return events;
|
25153 | };
|
25154 |
|
25155 | InfoWindow.prototype._onAutoOpen = function _onAutoOpen(e) {
|
25156 | var _this2 = this;
|
25157 |
|
25158 | var owner = this.getOwner();
|
25159 | setTimeout(function () {
|
25160 | if (owner instanceof Marker) {
|
25161 | _this2.show(owner.getCoordinates());
|
25162 | } else {
|
25163 | _this2.show(e.coordinate);
|
25164 | }
|
25165 | }, 1);
|
25166 | };
|
25167 |
|
25168 | InfoWindow.prototype._getWindowWidth = function _getWindowWidth() {
|
25169 | var defaultWidth = 300;
|
25170 | var width = this.options['width'];
|
25171 | if (!width) {
|
25172 | width = defaultWidth;
|
25173 | }
|
25174 | return width;
|
25175 | };
|
25176 |
|
25177 | return InfoWindow;
|
25178 | }(UIComponent);
|
25179 |
|
25180 | InfoWindow.mergeOptions(options$21);
|
25181 |
|
25182 | var options$22 = {
|
25183 | 'width': 0,
|
25184 | 'height': 0,
|
25185 | 'animation': 'fade',
|
25186 | 'cssName': 'maptalks-tooltip',
|
25187 | 'showTimeout': 400
|
25188 | };
|
25189 |
|
25190 | var ToolTip = function (_UIComponent) {
|
25191 | inherits(ToolTip, _UIComponent);
|
25192 |
|
25193 | ToolTip.prototype._getClassName = function _getClassName() {
|
25194 | return 'ToolTip';
|
25195 | };
|
25196 |
|
25197 | function ToolTip(content) {
|
25198 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
25199 | classCallCheck(this, ToolTip);
|
25200 |
|
25201 | var _this = possibleConstructorReturn(this, _UIComponent.call(this, options));
|
25202 |
|
25203 | _this._content = content;
|
25204 | return _this;
|
25205 | }
|
25206 |
|
25207 | ToolTip.prototype.addTo = function addTo(owner) {
|
25208 | if (owner instanceof Geometry) {
|
25209 | owner.on('mousemove', this.onMouseMove, this);
|
25210 | owner.on('mouseout', this.onMouseOut, this);
|
25211 | return _UIComponent.prototype.addTo.call(this, owner);
|
25212 | } else {
|
25213 | throw new Error('Invalid geometry the tooltip is added to.');
|
25214 | }
|
25215 | };
|
25216 |
|
25217 | ToolTip.prototype.setStyle = function setStyle$$1(cssName) {
|
25218 | this.options.cssName = cssName;
|
25219 | return this;
|
25220 | };
|
25221 |
|
25222 | ToolTip.prototype.getStyle = function getStyle() {
|
25223 | return this.options.cssName;
|
25224 | };
|
25225 |
|
25226 | ToolTip.prototype.getContent = function getContent() {
|
25227 | return this._content;
|
25228 | };
|
25229 |
|
25230 | ToolTip.prototype.buildOn = function buildOn() {
|
25231 | var dom = createEl('div');
|
25232 | if (options$22.height) {
|
25233 | dom.style.height = options$22.height + 'px';
|
25234 | }
|
25235 | if (options$22.width) {
|
25236 | dom.style.width = options$22.width + 'px';
|
25237 | }
|
25238 | var cssName = this.options.cssName;
|
25239 | if (!cssName && options$22.height) {
|
25240 | dom.style.lineHeight = options$22.height + 'px';
|
25241 | }
|
25242 | dom.innerHTML = '<div class="' + cssName + '">' + this._content + '</div>';
|
25243 | return dom;
|
25244 | };
|
25245 |
|
25246 | ToolTip.prototype.onMouseOut = function onMouseOut() {
|
25247 | clearTimeout(this._timeout);
|
25248 | if (this.isVisible()) {
|
25249 | this._removePrevDOM();
|
25250 | }
|
25251 | };
|
25252 |
|
25253 | ToolTip.prototype.onMouseMove = function onMouseMove(e) {
|
25254 | var _this2 = this;
|
25255 |
|
25256 | clearTimeout(this._timeout);
|
25257 | var map = this.getMap();
|
25258 | if (!map) {
|
25259 | return;
|
25260 | }
|
25261 | var coord = map.locateByPoint(e.coordinate, -5, 25);
|
25262 | if (this.options['showTimeout'] === 0) {
|
25263 | this.show(coord);
|
25264 | } else {
|
25265 | this._timeout = setTimeout(function () {
|
25266 | if (map) {
|
25267 | _this2.show(coord);
|
25268 | }
|
25269 | }, this.options['showTimeout']);
|
25270 | }
|
25271 | };
|
25272 |
|
25273 | ToolTip.prototype.onRemove = function onRemove() {
|
25274 | clearTimeout(this._timeout);
|
25275 | if (this._owner) {
|
25276 | this._owner.off('mouseover', this.onMouseOver, this);
|
25277 | this._owner.off('mouseout', this.onMouseOut, this);
|
25278 | }
|
25279 | };
|
25280 |
|
25281 | return ToolTip;
|
25282 | }(UIComponent);
|
25283 |
|
25284 | ToolTip.mergeOptions(options$22);
|
25285 |
|
25286 | var defaultOptions = {
|
25287 | 'animation': null,
|
25288 | 'animationDelay': 10,
|
25289 | 'animationOnHide': false,
|
25290 | 'autoPan': false,
|
25291 | 'width': 160,
|
25292 | 'maxHeight': 0,
|
25293 | 'custom': false,
|
25294 | 'items': []
|
25295 | };
|
25296 |
|
25297 | var Menu = function (_UIComponent) {
|
25298 | inherits(Menu, _UIComponent);
|
25299 |
|
25300 | function Menu(options) {
|
25301 | classCallCheck(this, Menu);
|
25302 | return possibleConstructorReturn(this, _UIComponent.call(this, options));
|
25303 | }
|
25304 |
|
25305 | Menu.prototype._getClassName = function _getClassName() {
|
25306 | return 'Menu';
|
25307 | };
|
25308 |
|
25309 | Menu.prototype.addTo = function addTo(owner) {
|
25310 | if (owner._menu && owner._menu !== this) {
|
25311 | owner.removeMenu();
|
25312 | }
|
25313 | owner._menu = this;
|
25314 | return UIComponent.prototype.addTo.apply(this, arguments);
|
25315 | };
|
25316 |
|
25317 | Menu.prototype.setItems = function setItems(items) {
|
25318 | this.options['items'] = items;
|
25319 | return this;
|
25320 | };
|
25321 |
|
25322 | Menu.prototype.getItems = function getItems() {
|
25323 | return this.options['items'] || [];
|
25324 | };
|
25325 |
|
25326 | Menu.prototype.buildOn = function buildOn() {
|
25327 | if (this.options['custom']) {
|
25328 | if (isString(this.options['items'])) {
|
25329 | var container = createEl('div');
|
25330 | container.innerHTML = this.options['items'];
|
25331 | return container;
|
25332 | } else {
|
25333 | return this.options['items'];
|
25334 | }
|
25335 | } else {
|
25336 | var dom = createEl('div');
|
25337 | addClass(dom, 'maptalks-menu');
|
25338 | dom.style.width = this._getMenuWidth() + 'px';
|
25339 |
|
25340 | var menuItems = this._createMenuItemDom();
|
25341 |
|
25342 | dom.appendChild(menuItems);
|
25343 | on(dom, 'contextmenu', preventDefault);
|
25344 | return dom;
|
25345 | }
|
25346 | };
|
25347 |
|
25348 | Menu.prototype.getOffset = function getOffset() {
|
25349 | if (!this.getMap()) {
|
25350 | return null;
|
25351 | }
|
25352 | var mapSize = this.getMap().getSize(),
|
25353 | p = this.getMap().viewPointToContainerPoint(this._getViewPoint()),
|
25354 | size = this.getSize();
|
25355 | var dx = 0,
|
25356 | dy = 0;
|
25357 | if (p.x + size['width'] > mapSize['width']) {
|
25358 | dx = -size['width'];
|
25359 | }
|
25360 | if (p.y + size['height'] > mapSize['height']) {
|
25361 | dy = -size['height'];
|
25362 | }
|
25363 | return new Point(dx, dy);
|
25364 | };
|
25365 |
|
25366 | Menu.prototype.getTransformOrigin = function getTransformOrigin() {
|
25367 | var p = this.getOffset()._multi(-1);
|
25368 | return p.x + 'px ' + p.y + 'px';
|
25369 | };
|
25370 |
|
25371 | Menu.prototype.getEvents = function getEvents() {
|
25372 | return {
|
25373 | '_zoomstart _zoomend _movestart _dblclick _click': this._removePrevDOM
|
25374 | };
|
25375 | };
|
25376 |
|
25377 | Menu.prototype._createMenuItemDom = function _createMenuItemDom() {
|
25378 | var me = this;
|
25379 | var map = this.getMap();
|
25380 | var ul = createEl('ul');
|
25381 | addClass(ul, 'maptalks-menu-items');
|
25382 | var items = this.getItems();
|
25383 |
|
25384 | function onMenuClick(index) {
|
25385 | return function (e) {
|
25386 | var param = map._parseEvent(e, 'click');
|
25387 | param['target'] = me;
|
25388 | param['owner'] = me._owner;
|
25389 | param['index'] = index;
|
25390 | var result = this._callback(param);
|
25391 | if (result === false) {
|
25392 | return;
|
25393 | }
|
25394 | me.hide();
|
25395 | };
|
25396 | }
|
25397 | var item = void 0,
|
25398 | itemDOM = void 0;
|
25399 | for (var i = 0, len = items.length; i < len; i++) {
|
25400 | item = items[i];
|
25401 | if (item === '-' || item === '_') {
|
25402 | itemDOM = createEl('li');
|
25403 | addClass(itemDOM, 'maptalks-menu-splitter');
|
25404 | } else {
|
25405 | itemDOM = createEl('li');
|
25406 | var itemTitle = item['item'];
|
25407 | if (isFunction(itemTitle)) {
|
25408 | itemTitle = itemTitle({
|
25409 | 'owner': this._owner,
|
25410 | 'index': i
|
25411 | });
|
25412 | }
|
25413 | itemDOM.innerHTML = itemTitle;
|
25414 | itemDOM._callback = item['click'];
|
25415 | on(itemDOM, 'click', onMenuClick(i));
|
25416 | }
|
25417 | ul.appendChild(itemDOM);
|
25418 | }
|
25419 | var maxHeight = this.options['maxHeight'] || 0;
|
25420 | if (maxHeight > 0) {
|
25421 | setStyle(ul, 'max-height: ' + maxHeight + 'px; overflow-y: auto;');
|
25422 | }
|
25423 | return ul;
|
25424 | };
|
25425 |
|
25426 | Menu.prototype._getMenuWidth = function _getMenuWidth() {
|
25427 | var defaultWidth = 160;
|
25428 | var width = this.options['width'] || defaultWidth;
|
25429 | return width;
|
25430 | };
|
25431 |
|
25432 | return Menu;
|
25433 | }(UIComponent);
|
25434 |
|
25435 | Menu.mergeOptions(defaultOptions);
|
25436 |
|
25437 | var Menuable = {
|
25438 | setMenu: function setMenu(options) {
|
25439 | this._menuOptions = options;
|
25440 |
|
25441 | if (this._menu) {
|
25442 | this._menu.setOptions(options);
|
25443 | } else {
|
25444 | this.on('contextmenu', this._defaultOpenMenu, this);
|
25445 | }
|
25446 | return this;
|
25447 | },
|
25448 | openMenu: function openMenu(coordinate) {
|
25449 | var map = this instanceof Map ? this : this.getMap();
|
25450 | if (!coordinate) {
|
25451 | coordinate = this.getCenter();
|
25452 | }
|
25453 | if (!this._menu) {
|
25454 | if (this._menuOptions && map) {
|
25455 | this._bindMenu(this._menuOptions);
|
25456 | this._menu.show(coordinate);
|
25457 | }
|
25458 | } else {
|
25459 | this._menu.show(coordinate);
|
25460 | }
|
25461 | return this;
|
25462 | },
|
25463 | setMenuItems: function setMenuItems(items) {
|
25464 | if (!this._menuOptions) {
|
25465 | this._menuOptions = {};
|
25466 | }
|
25467 | if (Array.isArray(items)) {
|
25468 | this._menuOptions['custom'] = false;
|
25469 | }
|
25470 | this._menuOptions['items'] = items;
|
25471 | this.setMenu(this._menuOptions);
|
25472 | return this;
|
25473 | },
|
25474 | getMenuItems: function getMenuItems() {
|
25475 | if (this._menu) {
|
25476 | return this._menu.getItems();
|
25477 | } else if (this._menuOptions) {
|
25478 | return this._menuOptions['items'] || [];
|
25479 | }
|
25480 | return [];
|
25481 | },
|
25482 | closeMenu: function closeMenu() {
|
25483 | if (this._menu) {
|
25484 | this._menu.hide();
|
25485 | }
|
25486 | return this;
|
25487 | },
|
25488 | removeMenu: function removeMenu() {
|
25489 | this.off('contextmenu', this._defaultOpenMenu, this);
|
25490 | this._unbindMenu();
|
25491 | delete this._menuOptions;
|
25492 | return this;
|
25493 | },
|
25494 | _bindMenu: function _bindMenu(options) {
|
25495 | this._menu = new Menu(options);
|
25496 | this._menu.addTo(this);
|
25497 |
|
25498 | return this;
|
25499 | },
|
25500 | _unbindMenu: function _unbindMenu() {
|
25501 | if (this._menu) {
|
25502 | this.closeMenu();
|
25503 | this._menu.remove();
|
25504 | delete this._menu;
|
25505 | }
|
25506 | return this;
|
25507 | },
|
25508 | _defaultOpenMenu: function _defaultOpenMenu(param) {
|
25509 | if (this.listens('contextmenu') > 1) {
|
25510 | return true;
|
25511 | } else {
|
25512 | this.openMenu(param['coordinate']);
|
25513 | return false;
|
25514 | }
|
25515 | }
|
25516 | };
|
25517 |
|
25518 | Map.include(Menuable);
|
25519 | Geometry.include(Menuable);
|
25520 |
|
25521 |
|
25522 |
|
25523 | var index$4 = Object.freeze({
|
25524 | UIComponent: UIComponent,
|
25525 | UIMarker: UIMarker,
|
25526 | InfoWindow: InfoWindow,
|
25527 | ToolTip: ToolTip,
|
25528 | Menuable: Menuable,
|
25529 | Menu: Menu
|
25530 | });
|
25531 |
|
25532 | var Control = function (_Eventable) {
|
25533 | inherits(Control, _Eventable);
|
25534 |
|
25535 | function Control(options) {
|
25536 | classCallCheck(this, Control);
|
25537 |
|
25538 | if (options && options['position'] && !isString(options['position'])) {
|
25539 | options['position'] = extend({}, options['position']);
|
25540 | }
|
25541 | return possibleConstructorReturn(this, _Eventable.call(this, options));
|
25542 | }
|
25543 |
|
25544 | Control.prototype.addTo = function addTo(map) {
|
25545 | this.remove();
|
25546 | if (!map.options['control']) {
|
25547 | return this;
|
25548 | }
|
25549 | this._map = map;
|
25550 | var controlContainer = map._panels.control;
|
25551 | this.__ctrlContainer = createEl('div');
|
25552 | setStyle(this.__ctrlContainer, 'position:absolute;overflow:visible;');
|
25553 |
|
25554 | this.update();
|
25555 | controlContainer.appendChild(this.__ctrlContainer);
|
25556 | if (this.onAdd) {
|
25557 | this.onAdd();
|
25558 | }
|
25559 |
|
25560 | this.fire('add', {
|
25561 | 'dom': controlContainer
|
25562 | });
|
25563 | return this;
|
25564 | };
|
25565 |
|
25566 | Control.prototype.update = function update() {
|
25567 | this.__ctrlContainer.innerHTML = '';
|
25568 | this._controlDom = this.buildOn(this.getMap());
|
25569 | if (this._controlDom) {
|
25570 | this._updatePosition();
|
25571 | this.__ctrlContainer.appendChild(this._controlDom);
|
25572 | }
|
25573 | return this;
|
25574 | };
|
25575 |
|
25576 | Control.prototype.getMap = function getMap() {
|
25577 | return this._map;
|
25578 | };
|
25579 |
|
25580 | Control.prototype.getPosition = function getPosition() {
|
25581 | return extend({}, this._parse(this.options['position']));
|
25582 | };
|
25583 |
|
25584 | Control.prototype.setPosition = function setPosition(position) {
|
25585 | if (isString(position)) {
|
25586 | this.options['position'] = position;
|
25587 | } else {
|
25588 | this.options['position'] = extend({}, position);
|
25589 | }
|
25590 | this._updatePosition();
|
25591 | return this;
|
25592 | };
|
25593 |
|
25594 | Control.prototype.getContainerPoint = function getContainerPoint() {
|
25595 | var position = this.getPosition();
|
25596 |
|
25597 | var size = this.getMap().getSize();
|
25598 | var x = void 0,
|
25599 | y = void 0;
|
25600 | if (!isNil(position['left'])) {
|
25601 | x = parseInt(position['left']);
|
25602 | } else if (!isNil(position['right'])) {
|
25603 | x = size['width'] - parseInt(position['right']);
|
25604 | }
|
25605 | if (!isNil(position['top'])) {
|
25606 | y = parseInt(position['top']);
|
25607 | } else if (!isNil(position['bottom'])) {
|
25608 | y = size['height'] - parseInt(position['bottom']);
|
25609 | }
|
25610 | return new Point(x, y);
|
25611 | };
|
25612 |
|
25613 | Control.prototype.getContainer = function getContainer() {
|
25614 | return this.__ctrlContainer;
|
25615 | };
|
25616 |
|
25617 | Control.prototype.getDOM = function getDOM() {
|
25618 | return this._controlDom;
|
25619 | };
|
25620 |
|
25621 | Control.prototype.show = function show() {
|
25622 | this.__ctrlContainer.style.display = '';
|
25623 | return this;
|
25624 | };
|
25625 |
|
25626 | Control.prototype.hide = function hide() {
|
25627 | this.__ctrlContainer.style.display = 'none';
|
25628 | return this;
|
25629 | };
|
25630 |
|
25631 | Control.prototype.isVisible = function isVisible() {
|
25632 | return this.__ctrlContainer && this.__ctrlContainer.style.display === '';
|
25633 | };
|
25634 |
|
25635 | Control.prototype.remove = function remove() {
|
25636 | if (!this._map) {
|
25637 | return this;
|
25638 | }
|
25639 | removeDomNode(this.__ctrlContainer);
|
25640 | if (this.onRemove) {
|
25641 | this.onRemove();
|
25642 | }
|
25643 | delete this._map;
|
25644 | delete this.__ctrlContainer;
|
25645 | delete this._controlDom;
|
25646 |
|
25647 | this.fire('remove');
|
25648 | return this;
|
25649 | };
|
25650 |
|
25651 | Control.prototype._parse = function _parse(position) {
|
25652 | var p = position;
|
25653 | if (isString(position)) {
|
25654 | p = Control['positions'][p];
|
25655 | }
|
25656 | return p;
|
25657 | };
|
25658 |
|
25659 | Control.prototype._updatePosition = function _updatePosition() {
|
25660 | var position = this.getPosition();
|
25661 | if (!position) {
|
25662 | position = {
|
25663 | 'top': 20,
|
25664 | 'left': 20
|
25665 | };
|
25666 | }
|
25667 | for (var p in position) {
|
25668 | if (position.hasOwnProperty(p)) {
|
25669 | position[p] = parseInt(position[p]);
|
25670 | this.__ctrlContainer.style[p] = position[p] + 'px';
|
25671 | }
|
25672 | }
|
25673 |
|
25674 | this.fire('positionchange', {
|
25675 | 'position': extend({}, position)
|
25676 | });
|
25677 | };
|
25678 |
|
25679 | return Control;
|
25680 | }(Eventable(Class));
|
25681 |
|
25682 | Control.positions = {
|
25683 | 'top-left': {
|
25684 | 'top': 20,
|
25685 | 'left': 20
|
25686 | },
|
25687 | 'top-right': {
|
25688 | 'top': 20,
|
25689 | 'right': 20
|
25690 | },
|
25691 | 'bottom-left': {
|
25692 | 'bottom': 20,
|
25693 | 'left': 20
|
25694 | },
|
25695 | 'bottom-right': {
|
25696 | 'bottom': 20,
|
25697 | 'right': 20
|
25698 | }
|
25699 | };
|
25700 |
|
25701 | Map.mergeOptions({
|
25702 | 'control': true
|
25703 | });
|
25704 |
|
25705 | Map.include({
|
25706 | addControl: function addControl(control) {
|
25707 | if (this._containerDOM.getContext) {
|
25708 | return this;
|
25709 | }
|
25710 | control.addTo(this);
|
25711 | return this;
|
25712 | },
|
25713 |
|
25714 | removeControl: function removeControl(control) {
|
25715 | if (!control || control.getMap() !== this) {
|
25716 | return this;
|
25717 | }
|
25718 | control.remove();
|
25719 | return this;
|
25720 | }
|
25721 |
|
25722 | });
|
25723 |
|
25724 | var options$23 = {
|
25725 | 'position': {
|
25726 | 'bottom': 0,
|
25727 | 'left': 0
|
25728 | },
|
25729 | 'content': '<a href="http://maptalks.org" target="_blank">maptalks</a>'
|
25730 | };
|
25731 |
|
25732 | var layerEvents = 'addlayer removelayer setbaselayer baselayerremove';
|
25733 |
|
25734 | var Attribution = function (_Control) {
|
25735 | inherits(Attribution, _Control);
|
25736 |
|
25737 | function Attribution() {
|
25738 | classCallCheck(this, Attribution);
|
25739 | return possibleConstructorReturn(this, _Control.apply(this, arguments));
|
25740 | }
|
25741 |
|
25742 | Attribution.prototype.buildOn = function buildOn() {
|
25743 | this._attributionContainer = createEl('div');
|
25744 | this._attributionContainer.className = 'maptalks-attribution';
|
25745 | this._update();
|
25746 | return this._attributionContainer;
|
25747 | };
|
25748 |
|
25749 | Attribution.prototype.onAdd = function onAdd() {
|
25750 | this.getMap().on(layerEvents, this._update, this);
|
25751 | };
|
25752 |
|
25753 | Attribution.prototype.onRemove = function onRemove() {
|
25754 | this.getMap().off(layerEvents, this._update, this);
|
25755 | };
|
25756 |
|
25757 | Attribution.prototype._update = function _update() {
|
25758 | var map = this.getMap();
|
25759 | if (!map) {
|
25760 | return;
|
25761 | }
|
25762 |
|
25763 | var attributions = map._getLayers(function (layer) {
|
25764 | return layer.options['attribution'];
|
25765 | }).reverse().map(function (layer) {
|
25766 | return layer.options['attribution'];
|
25767 | });
|
25768 | var content = this.options['content'] + (attributions.length > 0 ? ' - ' + attributions.join(', ') : '');
|
25769 | this._attributionContainer.innerHTML = '<span style="padding:0px 4px">' + content + '</span>';
|
25770 | };
|
25771 |
|
25772 | return Attribution;
|
25773 | }(Control);
|
25774 |
|
25775 | Attribution.mergeOptions(options$23);
|
25776 |
|
25777 | Map.mergeOptions({
|
25778 | 'attribution': true
|
25779 | });
|
25780 |
|
25781 | Map.addOnLoadHook(function () {
|
25782 | var a = this.options['attribution'] || this.options['attributionControl'];
|
25783 | if (a) {
|
25784 | this.attributionControl = new Attribution(a);
|
25785 | this.addControl(this.attributionControl);
|
25786 | }
|
25787 | });
|
25788 |
|
25789 | var options$24 = {
|
25790 | 'position': 'top-right',
|
25791 | 'baseTitle': 'Base Layers',
|
25792 | 'overlayTitle': 'Layers',
|
25793 | 'excludeLayers': [],
|
25794 | 'containerClass': 'maptalks-layer-switcher'
|
25795 | };
|
25796 |
|
25797 | var LayerSwitcher = function (_Control) {
|
25798 | inherits(LayerSwitcher, _Control);
|
25799 |
|
25800 | function LayerSwitcher() {
|
25801 | classCallCheck(this, LayerSwitcher);
|
25802 | return possibleConstructorReturn(this, _Control.apply(this, arguments));
|
25803 | }
|
25804 |
|
25805 | LayerSwitcher.prototype.buildOn = function buildOn() {
|
25806 | var container = this.container = createEl('div', this.options['containerClass']),
|
25807 | panel = this.panel = createEl('div', 'panel'),
|
25808 | button = this.button = createEl('button');
|
25809 | container.appendChild(button);
|
25810 | container.appendChild(panel);
|
25811 | return container;
|
25812 | };
|
25813 |
|
25814 | LayerSwitcher.prototype.onAdd = function onAdd() {
|
25815 | on(this.button, 'mouseover', this._show, this);
|
25816 | on(this.panel, 'mouseleave', this._hide, this);
|
25817 | on(this.getMap(), 'click', this._hide, this);
|
25818 | };
|
25819 |
|
25820 | LayerSwitcher.prototype.onRemove = function onRemove() {
|
25821 | if (this.panel) {
|
25822 | off(this.button, 'mouseover', this._show, this);
|
25823 | off(this.panel, 'mouseleave', this._hide, this);
|
25824 | off(this.getMap(), 'click', this._hide, this);
|
25825 | removeDomNode(this.panel);
|
25826 | removeDomNode(this.button);
|
25827 | delete this.panel;
|
25828 | delete this.button;
|
25829 | delete this.container;
|
25830 | }
|
25831 | };
|
25832 |
|
25833 | LayerSwitcher.prototype._show = function _show() {
|
25834 | if (!hasClass(this.container, 'shown')) {
|
25835 | addClass(this.container, 'shown');
|
25836 | this._createPanel();
|
25837 | }
|
25838 | };
|
25839 |
|
25840 | LayerSwitcher.prototype._hide = function _hide(e) {
|
25841 | if (!this.panel.contains(e.toElement || e.relatedTarget)) {
|
25842 | setClass(this.container, this.options['containerClass']);
|
25843 | }
|
25844 | };
|
25845 |
|
25846 | LayerSwitcher.prototype._createPanel = function _createPanel() {
|
25847 | this.panel.innerHTML = '';
|
25848 | var ul = createEl('ul');
|
25849 | this.panel.appendChild(ul);
|
25850 | this._renderLayers(this.getMap(), ul);
|
25851 | };
|
25852 |
|
25853 | LayerSwitcher.prototype._renderLayers = function _renderLayers(map, elm) {
|
25854 | var base = map.getBaseLayer(),
|
25855 | layers = map.getLayers(),
|
25856 | len = layers.length;
|
25857 | if (base) {
|
25858 | var baseLayers = base.layers || [base],
|
25859 | li = createEl('li', 'group'),
|
25860 | ul = createEl('ul'),
|
25861 | label = createEl('label');
|
25862 | label.innerHTML = this.options['baseTitle'];
|
25863 | li.appendChild(label);
|
25864 | for (var i = 0, _len = baseLayers.length; i < _len; i++) {
|
25865 | var layer = baseLayers[i];
|
25866 | if (this._isExcluded(layer)) {
|
25867 | ul.appendChild(this._renderLayer(baseLayers[i], true));
|
25868 | li.appendChild(ul);
|
25869 | elm.appendChild(li);
|
25870 | }
|
25871 | }
|
25872 | }
|
25873 |
|
25874 | if (len) {
|
25875 | var _li = createEl('li', 'group'),
|
25876 | _ul = createEl('ul'),
|
25877 | _label = createEl('label');
|
25878 | _label.innerHTML = this.options['overlayTitle'];
|
25879 | _li.appendChild(_label);
|
25880 | for (var _i = 0; _i < len; _i++) {
|
25881 | var _layer = layers[_i];
|
25882 | if (this._isExcluded(_layer)) {
|
25883 | _ul.appendChild(this._renderLayer(_layer));
|
25884 | }
|
25885 | }
|
25886 | _li.appendChild(_ul);
|
25887 | elm.appendChild(_li);
|
25888 | }
|
25889 | };
|
25890 |
|
25891 | LayerSwitcher.prototype._isExcluded = function _isExcluded(layer) {
|
25892 | var id = layer.getId(),
|
25893 | excludeLayers = this.options['excludeLayers'];
|
25894 | return !(excludeLayers.length && excludeLayers.indexOf(id) >= 0);
|
25895 | };
|
25896 |
|
25897 | LayerSwitcher.prototype._renderLayer = function _renderLayer(layer, isBase) {
|
25898 | var _this2 = this;
|
25899 |
|
25900 | var li = createEl('li', 'layer'),
|
25901 | label = createEl('label'),
|
25902 | input = createEl('input'),
|
25903 | map = this.getMap();
|
25904 | var visible = layer.options['visible'];
|
25905 | layer.options['visible'] = true;
|
25906 | var enabled = layer.isVisible();
|
25907 | layer.options['visible'] = visible;
|
25908 | li.className = 'layer';
|
25909 | if (isBase) {
|
25910 | input.type = 'radio';
|
25911 | input.name = 'base';
|
25912 | } else {
|
25913 | input.type = 'checkbox';
|
25914 | }
|
25915 |
|
25916 | input.checked = visible && enabled;
|
25917 | if (!enabled) {
|
25918 | input.setAttribute('disabled', 'disabled');
|
25919 | }
|
25920 |
|
25921 | input.onchange = function (e) {
|
25922 | if (e.target.type === 'radio') {
|
25923 | var baseLayer = map.getBaseLayer(),
|
25924 | baseLayers = baseLayer.layers;
|
25925 | if (baseLayers) {
|
25926 | for (var i = 0, len = baseLayers.length; i < len; i++) {
|
25927 | var _baseLayer = baseLayers[i];
|
25928 | _baseLayer[_baseLayer === layer ? 'show' : 'hide']();
|
25929 | }
|
25930 | } else if (!baseLayer.isVisible()) {
|
25931 | baseLayer.show();
|
25932 | }
|
25933 | map._fireEvent('setbaselayer');
|
25934 | } else {
|
25935 | layer[e.target.checked ? 'show' : 'hide']();
|
25936 | }
|
25937 | _this2.fire('layerchange', { target: layer });
|
25938 | };
|
25939 | li.appendChild(input);
|
25940 | label.innerHTML = layer.getId();
|
25941 | li.appendChild(label);
|
25942 | return li;
|
25943 | };
|
25944 |
|
25945 | return LayerSwitcher;
|
25946 | }(Control);
|
25947 |
|
25948 | LayerSwitcher.mergeOptions(options$24);
|
25949 |
|
25950 | Map.mergeOptions({
|
25951 | 'layerSwitcherControl': false
|
25952 | });
|
25953 |
|
25954 | Map.addOnLoadHook(function () {
|
25955 | if (this.options['layerSwitcherControl']) {
|
25956 | this.layerSwitcherControl = new LayerSwitcher(this.options['layerSwitcherControl']);
|
25957 | this.addControl(this.layerSwitcherControl);
|
25958 | }
|
25959 | });
|
25960 |
|
25961 | var options$25 = {
|
25962 | 'level': 4,
|
25963 | 'position': {
|
25964 | 'right': 1,
|
25965 | 'bottom': 1
|
25966 | },
|
25967 | 'size': [300, 200],
|
25968 | 'maximize': true,
|
25969 | 'symbol': {
|
25970 | 'lineWidth': 3,
|
25971 | 'lineColor': '#1bbc9b',
|
25972 | 'polygonFill': '#1bbc9b',
|
25973 | 'polygonOpacity': 0.4
|
25974 | },
|
25975 | 'containerClass': 'maptalks-overview',
|
25976 | 'buttonClass': 'maptalks-overview-button'
|
25977 | };
|
25978 |
|
25979 | var Overview = function (_Control) {
|
25980 | inherits(Overview, _Control);
|
25981 |
|
25982 | function Overview() {
|
25983 | classCallCheck(this, Overview);
|
25984 | return possibleConstructorReturn(this, _Control.apply(this, arguments));
|
25985 | }
|
25986 |
|
25987 | Overview.prototype.buildOn = function buildOn() {
|
25988 | var size = this.options['size'];
|
25989 | if (!this.options['maximize']) {
|
25990 | size = [0, 0];
|
25991 | }
|
25992 | var container = createEl('div');
|
25993 |
|
25994 | var mapContainer = this.mapContainer = createEl('div');
|
25995 | mapContainer.style.width = size[0] + 'px';
|
25996 | mapContainer.style.height = size[1] + 'px';
|
25997 | mapContainer.className = this.options['containerClass'];
|
25998 | var button = this.button = createEl('div');
|
25999 | button.className = this.options['buttonClass'];
|
26000 | container.appendChild(mapContainer);
|
26001 | container.appendChild(button);
|
26002 | return container;
|
26003 | };
|
26004 |
|
26005 | Overview.prototype.onAdd = function onAdd() {
|
26006 | if (this.options['maximize']) {
|
26007 | this._createOverview();
|
26008 | }
|
26009 | this.getMap().on('resize moving zooming rotate dragrotating viewchange', this._update, this).on('setbaselayer', this._updateBaseLayer, this).on('spatialreferencechange', this._updateSpatialReference, this);
|
26010 | on(this.button, 'click', this._onButtonClick, this);
|
26011 | this._updateButtonText();
|
26012 | };
|
26013 |
|
26014 | Overview.prototype.onRemove = function onRemove() {
|
26015 | this.getMap().off('resize moving zooming rotate dragrotating viewchange', this._update, this).off('setbaselayer', this._updateBaseLayer, this).off('spatialreferencechange', this._updateSpatialReference, this);
|
26016 | if (this._overview) {
|
26017 | this._overview.remove();
|
26018 | delete this._overview;
|
26019 | delete this._perspective;
|
26020 | }
|
26021 | off(this.button, 'click', this._onButtonClick, this);
|
26022 | };
|
26023 |
|
26024 | Overview.prototype.maxmize = function maxmize() {
|
26025 | var size = this.options['size'];
|
26026 | var dom = this.mapContainer;
|
26027 | dom.style.width = size[0] + 'px';
|
26028 | dom.style.height = size[1] + 'px';
|
26029 | this._createOverview();
|
26030 | };
|
26031 |
|
26032 | Overview.prototype.minimize = function minimize() {
|
26033 | if (this._overview) {
|
26034 | this._overview.remove();
|
26035 | }
|
26036 | delete this._overview;
|
26037 | delete this._perspective;
|
26038 | var dom = this.mapContainer;
|
26039 | dom.style.width = 0 + 'px';
|
26040 | dom.style.height = 0 + 'px';
|
26041 | };
|
26042 |
|
26043 | Overview.prototype._onButtonClick = function _onButtonClick() {
|
26044 | if (!this._overview) {
|
26045 | this.maxmize();
|
26046 | } else {
|
26047 | this.minimize();
|
26048 | }
|
26049 | this._updateButtonText();
|
26050 | };
|
26051 |
|
26052 | Overview.prototype._updateButtonText = function _updateButtonText() {
|
26053 | if (this._overview) {
|
26054 | this.button.innerHTML = '-';
|
26055 | } else {
|
26056 | this.button.innerHTML = '+';
|
26057 | }
|
26058 | };
|
26059 |
|
26060 | Overview.prototype._createOverview = function _createOverview() {
|
26061 | var map = this.getMap(),
|
26062 | dom = this.mapContainer;
|
26063 | var options = map.config();
|
26064 | extend(options, {
|
26065 | 'center': map.getCenter(),
|
26066 | 'zoom': this._getOverviewZoom(),
|
26067 | 'zoomAnimationDuration': 150,
|
26068 | 'pitch': 0,
|
26069 | 'bearing': 0,
|
26070 | 'scrollWheelZoom': false,
|
26071 | 'checkSize': false,
|
26072 | 'doubleClickZoom': false,
|
26073 | 'touchZoom': false,
|
26074 | 'control': false,
|
26075 | 'draggable': false,
|
26076 | 'maxExtent': null
|
26077 | });
|
26078 | this._overview = new Map(dom, options);
|
26079 | this._updateBaseLayer();
|
26080 | this._perspective = new Polygon(this._getPerspectiveCoords(), {
|
26081 | 'draggable': true,
|
26082 | 'cursor': 'move',
|
26083 | 'symbol': this.options['symbol']
|
26084 | }).on('dragend', this._onDragEnd, this);
|
26085 | new VectorLayer('perspective_layer', this._perspective).addTo(this._overview);
|
26086 | this.fire('load');
|
26087 | };
|
26088 |
|
26089 | Overview.prototype._getOverviewZoom = function _getOverviewZoom() {
|
26090 | var map = this.getMap(),
|
26091 | zoom = map.getZoom(),
|
26092 | minZoom = map.getMinZoom(),
|
26093 | level = this.options['level'];
|
26094 | if (level > 0) {
|
26095 | for (var i = level; i > 0; i--) {
|
26096 | if (zoom - i >= minZoom) {
|
26097 | return zoom - i;
|
26098 | }
|
26099 | }
|
26100 | } else {
|
26101 | for (var _i = level; _i < 0; _i++) {
|
26102 | if (zoom - _i >= minZoom) {
|
26103 | return zoom - _i;
|
26104 | }
|
26105 | }
|
26106 | }
|
26107 |
|
26108 | return zoom;
|
26109 | };
|
26110 |
|
26111 | Overview.prototype._onDragEnd = function _onDragEnd() {
|
26112 | var center = this._perspective.getCenter();
|
26113 | this._overview.setCenter(center);
|
26114 | this.getMap().panTo(center);
|
26115 | };
|
26116 |
|
26117 | Overview.prototype._getPerspectiveCoords = function _getPerspectiveCoords() {
|
26118 | var map = this.getMap();
|
26119 | return map.getContainerExtent().toArray().map(function (c) {
|
26120 | return map.containerPointToCoordinate(c);
|
26121 | });
|
26122 | };
|
26123 |
|
26124 | Overview.prototype._update = function _update() {
|
26125 | if (!this._overview) {
|
26126 | return;
|
26127 | }
|
26128 | var coords = this._getPerspectiveCoords();
|
26129 | this._perspective.setCoordinates(coords);
|
26130 | this._overview.setCenterAndZoom(this.getMap().getCenter(), this._getOverviewZoom());
|
26131 | };
|
26132 |
|
26133 | Overview.prototype._updateSpatialReference = function _updateSpatialReference() {
|
26134 | if (!this._overview) {
|
26135 | return;
|
26136 | }
|
26137 | var map = this.getMap();
|
26138 | var spatialRef = map.options['spatialReference'];
|
26139 | this._overview.setSpatialReference(spatialRef);
|
26140 | };
|
26141 |
|
26142 | Overview.prototype._updateBaseLayer = function _updateBaseLayer() {
|
26143 | if (!this._overview) {
|
26144 | return;
|
26145 | }
|
26146 | var map = this.getMap(),
|
26147 | baseLayer = map.getBaseLayer();
|
26148 | if (!baseLayer) {
|
26149 | this._overview.setBaseLayer(null);
|
26150 | return;
|
26151 | }
|
26152 | var layers = baseLayer.layers;
|
26153 | var showIndex = 0;
|
26154 | if (layers) {
|
26155 | for (var i = 0, l = layers.length; i < l; i++) {
|
26156 | var _layer = layers[i];
|
26157 | if (_layer.isVisible()) {
|
26158 | showIndex = i;
|
26159 | break;
|
26160 | }
|
26161 | }
|
26162 | }
|
26163 |
|
26164 | var json = baseLayer.toJSON();
|
26165 | var options = null;
|
26166 | if (layers) {
|
26167 | options = json.layers[showIndex].options;
|
26168 | options.visible = true;
|
26169 | } else {
|
26170 | options = json.options;
|
26171 | }
|
26172 | this._overview.setMinZoom(options.minZoom || null).setMaxZoom(options.maxZoom || null);
|
26173 | delete options.minZoom;
|
26174 | delete options.maxZoom;
|
26175 | delete json.options.canvas;
|
26176 | json.options.visible = true;
|
26177 | json.options.renderer = 'canvas';
|
26178 | var layer = Layer.fromJSON(json);
|
26179 | for (var p in baseLayer) {
|
26180 | if (isFunction(baseLayer[p]) && baseLayer.hasOwnProperty(p) && baseLayer[p] !== baseLayer.constructor.prototype[p]) {
|
26181 | layer[p] = baseLayer[p];
|
26182 | }
|
26183 | }
|
26184 | this._overview.setBaseLayer(layer);
|
26185 | };
|
26186 |
|
26187 | return Overview;
|
26188 | }(Control);
|
26189 |
|
26190 | Overview.mergeOptions(options$25);
|
26191 |
|
26192 | Map.mergeOptions({
|
26193 | 'overviewControl': false
|
26194 | });
|
26195 |
|
26196 | Map.addOnLoadHook(function () {
|
26197 | if (this.options['overviewControl']) {
|
26198 | this.overviewControl = new Overview(this.options['overviewControl']);
|
26199 | this.addControl(this.overviewControl);
|
26200 | }
|
26201 | });
|
26202 |
|
26203 | var options$26 = {
|
26204 | 'position': 'top-right',
|
26205 | 'draggable': true,
|
26206 | 'custom': false,
|
26207 | 'content': '',
|
26208 | 'closeButton': true
|
26209 | };
|
26210 |
|
26211 | var Panel = function (_Control) {
|
26212 | inherits(Panel, _Control);
|
26213 |
|
26214 | function Panel() {
|
26215 | classCallCheck(this, Panel);
|
26216 | return possibleConstructorReturn(this, _Control.apply(this, arguments));
|
26217 | }
|
26218 |
|
26219 | Panel.prototype.buildOn = function buildOn() {
|
26220 | var dom = void 0;
|
26221 | if (this.options['custom']) {
|
26222 | if (isString(this.options['content'])) {
|
26223 | dom = createEl('div');
|
26224 | dom.innerHTML = this.options['content'];
|
26225 | } else {
|
26226 | dom = this.options['content'];
|
26227 | }
|
26228 | } else {
|
26229 | dom = createEl('div', 'maptalks-panel');
|
26230 | if (this.options['closeButton']) {
|
26231 | var closeButton = createEl('a', 'maptalks-close');
|
26232 | closeButton.href = 'javascript:;';
|
26233 | closeButton.onclick = function () {
|
26234 | dom.style.display = 'none';
|
26235 | };
|
26236 | dom.appendChild(closeButton);
|
26237 | }
|
26238 |
|
26239 | var panelContent = createEl('div', 'maptalks-panel-content');
|
26240 | panelContent.innerHTML = this.options['content'];
|
26241 | dom.appendChild(panelContent);
|
26242 | }
|
26243 |
|
26244 | this.draggable = new DragHandler(dom, {
|
26245 | 'cancelOn': this._cancelOn.bind(this),
|
26246 | 'ignoreMouseleave': true
|
26247 | });
|
26248 |
|
26249 | this.draggable.on('dragstart', this._onDragStart, this).on('dragging', this._onDragging, this).on('dragend', this._onDragEnd, this);
|
26250 |
|
26251 | if (this.options['draggable']) {
|
26252 | this.draggable.enable();
|
26253 | }
|
26254 |
|
26255 | return dom;
|
26256 | };
|
26257 |
|
26258 | Panel.prototype.update = function update() {
|
26259 | if (this.draggable) {
|
26260 | this.draggable.disable();
|
26261 | delete this.draggable;
|
26262 | }
|
26263 | return Control.prototype.update.call(this);
|
26264 | };
|
26265 |
|
26266 | Panel.prototype.setContent = function setContent(content) {
|
26267 | var old = this.options['content'];
|
26268 | this.options['content'] = content;
|
26269 |
|
26270 | this.fire('contentchange', {
|
26271 | 'old': old,
|
26272 | 'new': content
|
26273 | });
|
26274 | if (this.isVisible()) {
|
26275 | this.update();
|
26276 | }
|
26277 | return this;
|
26278 | };
|
26279 |
|
26280 | Panel.prototype.getContent = function getContent() {
|
26281 | return this.options['content'];
|
26282 | };
|
26283 |
|
26284 | Panel.prototype._cancelOn = function _cancelOn(domEvent) {
|
26285 | var target = domEvent.srcElement || domEvent.target,
|
26286 | tagName = target.tagName.toLowerCase();
|
26287 | if (tagName === 'button' || tagName === 'input' || tagName === 'select' || tagName === 'option' || tagName === 'textarea') {
|
26288 | return true;
|
26289 | }
|
26290 | return false;
|
26291 | };
|
26292 |
|
26293 | Panel.prototype._onDragStart = function _onDragStart(param) {
|
26294 | this._startPos = param['mousePos'];
|
26295 | this._startPosition = extend({}, this.getPosition());
|
26296 |
|
26297 | this.fire('dragstart', param);
|
26298 | };
|
26299 |
|
26300 | Panel.prototype._onDragging = function _onDragging(param) {
|
26301 | var pos = param['mousePos'];
|
26302 | var offset = pos.sub(this._startPos);
|
26303 |
|
26304 | var startPosition = this._startPosition;
|
26305 | var position = this.getPosition();
|
26306 | if (!isNil(position['top'])) {
|
26307 | position['top'] = parseInt(startPosition['top']) + offset.y;
|
26308 | }
|
26309 | if (!isNil(position['bottom'])) {
|
26310 | position['bottom'] = parseInt(startPosition['bottom']) - offset.y;
|
26311 | }
|
26312 | if (!isNil(position['left'])) {
|
26313 | position['left'] = parseInt(startPosition['left']) + offset.x;
|
26314 | }
|
26315 | if (!isNil(position['right'])) {
|
26316 | position['right'] = parseInt(startPosition['right']) - offset.x;
|
26317 | }
|
26318 | this.setPosition(position);
|
26319 |
|
26320 | this.fire('dragging', param);
|
26321 | };
|
26322 |
|
26323 | Panel.prototype._onDragEnd = function _onDragEnd(param) {
|
26324 | delete this._startPos;
|
26325 | delete this._startPosition;
|
26326 |
|
26327 | this.fire('dragend', param);
|
26328 | };
|
26329 |
|
26330 | Panel.prototype._getConnectPoints = function _getConnectPoints() {
|
26331 | var map = this.getMap();
|
26332 | var containerPoint = this.getContainerPoint();
|
26333 | var dom = this.getDOM(),
|
26334 | width = parseInt(dom.clientWidth),
|
26335 | height = parseInt(dom.clientHeight);
|
26336 | var anchors = [map.containerPointToCoordinate(containerPoint.add(width / 2, 0)), map.containerPointToCoordinate(containerPoint.add(width, height / 2)), map.containerPointToCoordinate(containerPoint.add(width / 2, height)), map.containerPointToCoordinate(containerPoint.add(0, height / 2))];
|
26337 | return anchors;
|
26338 | };
|
26339 |
|
26340 | return Panel;
|
26341 | }(Control);
|
26342 |
|
26343 | Panel.mergeOptions(options$26);
|
26344 |
|
26345 | var options$27 = {
|
26346 | 'position': 'bottom-left',
|
26347 | 'maxWidth': 100,
|
26348 | 'metric': true,
|
26349 | 'imperial': false
|
26350 | };
|
26351 |
|
26352 | var Scale = function (_Control) {
|
26353 | inherits(Scale, _Control);
|
26354 |
|
26355 | function Scale() {
|
26356 | classCallCheck(this, Scale);
|
26357 | return possibleConstructorReturn(this, _Control.apply(this, arguments));
|
26358 | }
|
26359 |
|
26360 | Scale.prototype.buildOn = function buildOn(map) {
|
26361 | this._map = map;
|
26362 | this._scaleContainer = createEl('div');
|
26363 | this._addScales();
|
26364 | map.on('zoomend', this._update, this);
|
26365 | if (this._map._loaded) {
|
26366 | this._update();
|
26367 | }
|
26368 | return this._scaleContainer;
|
26369 | };
|
26370 |
|
26371 | Scale.prototype.onRemove = function onRemove() {
|
26372 | this.getMap().off('zoomend', this._update, this);
|
26373 | };
|
26374 |
|
26375 | Scale.prototype._addScales = function _addScales() {
|
26376 | var css = 'border: 2px solid #000000;border-top: none;line-height: 1.1;padding: 2px 5px 1px;' + 'color: #000000;font-size: 11px;text-align:center;white-space: nowrap;overflow: hidden' + ';-moz-box-sizing: content-box;box-sizing: content-box;background: #fff; background: rgba(255, 255, 255, 0);';
|
26377 | if (this.options['metric']) {
|
26378 | this._mScale = createElOn('div', css, this._scaleContainer);
|
26379 | }
|
26380 | if (this.options['imperial']) {
|
26381 | this._iScale = createElOn('div', css, this._scaleContainer);
|
26382 | }
|
26383 | };
|
26384 |
|
26385 | Scale.prototype._update = function _update() {
|
26386 | var map = this._map;
|
26387 | var maxMeters = map.pixelToDistance(this.options['maxWidth'], 0);
|
26388 | this._updateScales(maxMeters);
|
26389 | };
|
26390 |
|
26391 | Scale.prototype._updateScales = function _updateScales(maxMeters) {
|
26392 | if (this.options['metric'] && maxMeters) {
|
26393 | this._updateMetric(maxMeters);
|
26394 | }
|
26395 | if (this.options['imperial'] && maxMeters) {
|
26396 | this._updateImperial(maxMeters);
|
26397 | }
|
26398 | };
|
26399 |
|
26400 | Scale.prototype._updateMetric = function _updateMetric(maxMeters) {
|
26401 | var meters = this._getRoundNum(maxMeters),
|
26402 | label = meters < 1000 ? meters + ' m' : meters / 1000 + ' km';
|
26403 |
|
26404 | this._updateScale(this._mScale, label, meters / maxMeters);
|
26405 | };
|
26406 |
|
26407 | Scale.prototype._updateImperial = function _updateImperial(maxMeters) {
|
26408 | var maxFeet = maxMeters * 3.2808399;
|
26409 | var maxMiles = void 0,
|
26410 | miles = void 0,
|
26411 | feet = void 0;
|
26412 |
|
26413 | if (maxFeet > 5280) {
|
26414 | maxMiles = maxFeet / 5280;
|
26415 | miles = this._getRoundNum(maxMiles);
|
26416 | this._updateScale(this._iScale, miles + ' mile', miles / maxMiles);
|
26417 | } else {
|
26418 | feet = this._getRoundNum(maxFeet);
|
26419 | this._updateScale(this._iScale, feet + ' feet', feet / maxFeet);
|
26420 | }
|
26421 | };
|
26422 |
|
26423 | Scale.prototype._updateScale = function _updateScale(scale, text, ratio) {
|
26424 | scale['style']['width'] = Math.round(this.options['maxWidth'] * ratio) + 'px';
|
26425 | scale['innerHTML'] = text;
|
26426 | };
|
26427 |
|
26428 | Scale.prototype._getRoundNum = function _getRoundNum(num) {
|
26429 | var pow10 = Math.pow(10, (Math.floor(num) + '').length - 1);
|
26430 | var d = num / pow10;
|
26431 |
|
26432 | d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1;
|
26433 |
|
26434 | return pow10 * d;
|
26435 | };
|
26436 |
|
26437 | return Scale;
|
26438 | }(Control);
|
26439 |
|
26440 | Scale.mergeOptions(options$27);
|
26441 |
|
26442 | Map.mergeOptions({
|
26443 | 'scaleControl': false
|
26444 | });
|
26445 |
|
26446 | Map.addOnLoadHook(function () {
|
26447 | if (this.options['scaleControl']) {
|
26448 | this.scaleControl = new Scale(this.options['scaleControl']);
|
26449 | this.addControl(this.scaleControl);
|
26450 | }
|
26451 | });
|
26452 |
|
26453 | var options$28 = {
|
26454 | 'height': 28,
|
26455 | 'vertical': false,
|
26456 | 'position': 'top-right',
|
26457 | 'reverseMenu': false,
|
26458 | 'items': {}
|
26459 | };
|
26460 |
|
26461 | var Toolbar = function (_Control) {
|
26462 | inherits(Toolbar, _Control);
|
26463 |
|
26464 | function Toolbar() {
|
26465 | classCallCheck(this, Toolbar);
|
26466 | return possibleConstructorReturn(this, _Control.apply(this, arguments));
|
26467 | }
|
26468 |
|
26469 | Toolbar.prototype.buildOn = function buildOn(map) {
|
26470 | this._map = map;
|
26471 | var dom = createEl('div');
|
26472 | var ul = createEl('ul', 'maptalks-toolbar-hx');
|
26473 | dom.appendChild(ul);
|
26474 |
|
26475 | if (this.options['vertical']) {
|
26476 | addClass(dom, 'maptalks-toolbar-vertical');
|
26477 | } else {
|
26478 | addClass(dom, 'maptalks-toolbar-horizonal');
|
26479 | }
|
26480 | var me = this;
|
26481 |
|
26482 | function onButtonClick(fn, index, childIndex, targetDom) {
|
26483 | var item = me._getItems()[index];
|
26484 | return function (e) {
|
26485 | stopPropagation(e);
|
26486 | return fn({
|
26487 | 'target': item,
|
26488 | 'index': index,
|
26489 | 'childIndex': childIndex,
|
26490 | 'dom': targetDom
|
26491 | });
|
26492 | };
|
26493 | }
|
26494 |
|
26495 | var items = this.options['items'];
|
26496 | if (isArrayHasData(items)) {
|
26497 | for (var i = 0, len = items.length; i < len; i++) {
|
26498 | var item = items[i];
|
26499 | var li = createEl('li');
|
26500 | if (this.options['height'] !== 28) {
|
26501 | li.style.lineHeight = this.options['height'] + 'px';
|
26502 | }
|
26503 | li.style.height = this.options['height'] + 'px';
|
26504 | li.style.cursor = 'pointer';
|
26505 | if (isHTML(item['item'])) {
|
26506 | li.style.textAlign = 'center';
|
26507 | var itemSize = measureDom('div', item['item']);
|
26508 |
|
26509 | li.innerHTML = '<div style="margin-top:' + (this.options['height'] - itemSize['height']) / 2 + 'px;">' + item['item'] + '</div>';
|
26510 | } else {
|
26511 | li.innerHTML = item['item'];
|
26512 | }
|
26513 | if (item['click']) {
|
26514 | on(li, 'click', onButtonClick(item['click'], i, null, li));
|
26515 | }
|
26516 | if (isArrayHasData(item['children'])) {
|
26517 | var dropMenu = this._createDropMenu(i);
|
26518 | li.appendChild(dropMenu);
|
26519 | li._menu = dropMenu;
|
26520 | on(li, 'mouseover', function () {
|
26521 | this._menu.style.display = '';
|
26522 | });
|
26523 | on(li, 'mouseout', function () {
|
26524 | this._menu.style.display = 'none';
|
26525 | });
|
26526 | }
|
26527 | ul.appendChild(li);
|
26528 | }
|
26529 | }
|
26530 | return dom;
|
26531 | };
|
26532 |
|
26533 | Toolbar.prototype._createDropMenu = function _createDropMenu(index) {
|
26534 | var me = this;
|
26535 |
|
26536 | function onButtonClick(fn, index, childIndex) {
|
26537 | var item = me._getItems()[index]['children'][childIndex];
|
26538 | return function (e) {
|
26539 | stopPropagation(e);
|
26540 | return fn({
|
26541 | 'target': item,
|
26542 | 'index': index,
|
26543 | 'childIndex': childIndex
|
26544 | });
|
26545 | };
|
26546 | }
|
26547 | var menuDom = createEl('div', 'maptalks-dropMenu'),
|
26548 | items = this._getItems(),
|
26549 | len = items.length,
|
26550 | menuUL = createEl('ul'),
|
26551 | children = items[index]['children'];
|
26552 | if (index === len - 1 && children) {
|
26553 | menuDom.style.cssText = 'right: 0px;';
|
26554 | menuUL.style.cssText = 'right: 0px;position: absolute;';
|
26555 | if (this.options['reverseMenu']) {
|
26556 | menuUL.style.bottom = 0;
|
26557 | }
|
26558 | }
|
26559 | menuDom.appendChild(createEl('em', 'maptalks-ico'));
|
26560 |
|
26561 | var liWidth = 0;
|
26562 | for (var i = 0, l = children.length; i < l; i++) {
|
26563 | var size = stringLength(children[i]['item'], '12px');
|
26564 | if (size.width > liWidth) {
|
26565 | liWidth = size.width;
|
26566 | }
|
26567 | }
|
26568 | for (var _i = 0, _l = children.length; _i < _l; _i++) {
|
26569 | var child = children[_i];
|
26570 | var li = createEl('li');
|
26571 | li.innerHTML = '<a href="javascript:;">' + child['item'] + '</a>';
|
26572 | li.style.cursor = 'pointer';
|
26573 | li.style.width = liWidth + 24 + 'px';
|
26574 | on(li.childNodes[0], 'click', onButtonClick(child['click'], index, _i));
|
26575 | menuUL.appendChild(li);
|
26576 | }
|
26577 | if (this.options['vertical']) {
|
26578 | var width = liWidth < 95 ? 95 : liWidth;
|
26579 | if (this.options['reverseMenu']) {
|
26580 | menuDom.style.right = -(width + 10 * 2) + 'px';
|
26581 | } else {
|
26582 | menuDom.style.left = -(width + 10 * 2) + 'px';
|
26583 | }
|
26584 | } else if (this.options['reverseMenu']) {
|
26585 | menuDom.style.bottom = '28px';
|
26586 | } else {
|
26587 | menuDom.style.top = '28px';
|
26588 | }
|
26589 | menuDom.appendChild(menuUL);
|
26590 | menuDom.style.display = 'none';
|
26591 | return menuDom;
|
26592 | };
|
26593 |
|
26594 | Toolbar.prototype._getItems = function _getItems() {
|
26595 | return this.options['items'] || [];
|
26596 | };
|
26597 |
|
26598 | return Toolbar;
|
26599 | }(Control);
|
26600 |
|
26601 | Toolbar.mergeOptions(options$28);
|
26602 |
|
26603 | var options$29 = {
|
26604 | 'position': 'top-left',
|
26605 | 'slider': true,
|
26606 | 'zoomLevel': true,
|
26607 | 'seamless': false
|
26608 | };
|
26609 |
|
26610 | var UNIT = 10;
|
26611 |
|
26612 | var Zoom = function (_Control) {
|
26613 | inherits(Zoom, _Control);
|
26614 |
|
26615 | function Zoom() {
|
26616 | classCallCheck(this, Zoom);
|
26617 | return possibleConstructorReturn(this, _Control.apply(this, arguments));
|
26618 | }
|
26619 |
|
26620 | Zoom.prototype.buildOn = function buildOn(map) {
|
26621 | var options = this.options;
|
26622 |
|
26623 | var dom = createEl('div', 'maptalks-zoom');
|
26624 |
|
26625 | if (options['zoomLevel']) {
|
26626 | var levelDOM = createEl('span', 'maptalks-zoom-zoomlevel');
|
26627 | dom.appendChild(levelDOM);
|
26628 | this._levelDOM = levelDOM;
|
26629 | }
|
26630 |
|
26631 | var zoomDOM = createEl('div', 'maptalks-zoom-slider');
|
26632 |
|
26633 | var zoomInButton = createEl('a', 'maptalks-zoom-zoomin');
|
26634 | zoomInButton.href = 'javascript:;';
|
26635 | zoomInButton.innerHTML = '+';
|
26636 | zoomDOM.appendChild(zoomInButton);
|
26637 | this._zoomInButton = zoomInButton;
|
26638 |
|
26639 | if (options['slider']) {
|
26640 | var box = createEl('div', 'maptalks-zoom-slider-box');
|
26641 | var ruler = createEl('div', 'maptalks-zoom-slider-ruler');
|
26642 | var reading = createEl('span', 'maptalks-zoom-slider-reading');
|
26643 | var dot = createEl('span', 'maptalks-zoom-slider-dot');
|
26644 | ruler.appendChild(reading);
|
26645 | box.appendChild(ruler);
|
26646 | box.appendChild(dot);
|
26647 | zoomDOM.appendChild(box);
|
26648 | this._sliderBox = box;
|
26649 | this._sliderRuler = ruler;
|
26650 | this._sliderReading = reading;
|
26651 | this._sliderDot = dot;
|
26652 | }
|
26653 |
|
26654 | var zoomOutButton = createEl('a', 'maptalks-zoom-zoomout');
|
26655 | zoomOutButton.href = 'javascript:;';
|
26656 | zoomOutButton.innerHTML = '-';
|
26657 | zoomDOM.appendChild(zoomOutButton);
|
26658 | this._zoomOutButton = zoomOutButton;
|
26659 |
|
26660 | dom.appendChild(zoomDOM);
|
26661 |
|
26662 | map.on('_zoomend _zoomstart _spatialreferencechange', this._update, this);
|
26663 |
|
26664 | this._update();
|
26665 | this._registerDomEvents();
|
26666 |
|
26667 | return dom;
|
26668 | };
|
26669 |
|
26670 | Zoom.prototype.onRemove = function onRemove() {
|
26671 | this.getMap().off('_zoomend _zoomstart _spatialreferencechange', this._update, this);
|
26672 | if (this._zoomInButton) {
|
26673 | off(this._zoomInButton, 'click', this._onZoomInClick, this);
|
26674 | }
|
26675 | if (this._zoomOutButton) {
|
26676 | off(this._zoomOutButton, 'click', this._onZoomOutClick, this);
|
26677 | }
|
26678 | if (this._sliderRuler) {
|
26679 | off(this._sliderRuler, 'click', this._onClickRuler, this);
|
26680 | this.dotDragger.disable();
|
26681 | delete this.dotDragger;
|
26682 | }
|
26683 | };
|
26684 |
|
26685 | Zoom.prototype._update = function _update() {
|
26686 | var map = this.getMap();
|
26687 | if (this._sliderBox) {
|
26688 | var totalRange = (map.getMaxZoom() - map.getMinZoom()) * UNIT;
|
26689 | this._sliderBox.style.height = totalRange + 16 + 'px';
|
26690 | this._sliderRuler.style.height = totalRange + 8 + 'px';
|
26691 | this._sliderRuler.style.cursor = 'pointer';
|
26692 | var zoomRange = (map.getMaxZoom() - map.getZoom()) * UNIT;
|
26693 |
|
26694 | this._sliderReading.style.height = (map.getZoom() - map.getMinZoom() + 1) * UNIT + 'px';
|
26695 | this._sliderDot.style.top = zoomRange + 'px';
|
26696 | }
|
26697 | this._updateText();
|
26698 | };
|
26699 |
|
26700 | Zoom.prototype._updateText = function _updateText() {
|
26701 | if (this._levelDOM) {
|
26702 | var map = this.getMap();
|
26703 | var zoom = map.getZoom();
|
26704 | if (!isInteger(zoom)) {
|
26705 | zoom = zoom.toFixed(1);
|
26706 | }
|
26707 | this._levelDOM.innerHTML = zoom;
|
26708 | }
|
26709 | };
|
26710 |
|
26711 | Zoom.prototype._registerDomEvents = function _registerDomEvents() {
|
26712 | if (this._zoomInButton) {
|
26713 | on(this._zoomInButton, 'click', this._onZoomInClick, this);
|
26714 | }
|
26715 | if (this._zoomOutButton) {
|
26716 | on(this._zoomOutButton, 'click', this._onZoomOutClick, this);
|
26717 | }
|
26718 | if (this._sliderRuler) {
|
26719 | on(this._sliderRuler, 'click', this._onClickRuler, this);
|
26720 | this.dotDragger = new DragHandler(this._sliderDot, {
|
26721 | 'ignoreMouseleave': true
|
26722 | });
|
26723 | this.dotDragger.on('dragstart', this._onDotDragstart, this).on('dragging dragend', this._onDotDrag, this).enable();
|
26724 | }
|
26725 | };
|
26726 |
|
26727 | Zoom.prototype._onZoomInClick = function _onZoomInClick(e) {
|
26728 | preventDefault(e);
|
26729 | this.getMap().zoomIn();
|
26730 | };
|
26731 |
|
26732 | Zoom.prototype._onZoomOutClick = function _onZoomOutClick(e) {
|
26733 | preventDefault(e);
|
26734 | this.getMap().zoomOut();
|
26735 | };
|
26736 |
|
26737 | Zoom.prototype._onClickRuler = function _onClickRuler(e) {
|
26738 | preventDefault(e);
|
26739 | var map = this.getMap(),
|
26740 | point = getEventContainerPoint(e, this._sliderRuler),
|
26741 | h = point.y;
|
26742 | var maxZoom = map.getMaxZoom(),
|
26743 | zoom = Math.floor(maxZoom - h / UNIT);
|
26744 | map.setZoom(zoom);
|
26745 | };
|
26746 |
|
26747 | Zoom.prototype._onDotDragstart = function _onDotDragstart(e) {
|
26748 | preventDefault(e.domEvent);
|
26749 | var map = this.getMap(),
|
26750 | origin = map.getSize().toPoint()._multi(1 / 2);
|
26751 | map.onZoomStart(map.getZoom(), origin);
|
26752 | };
|
26753 |
|
26754 | Zoom.prototype._onDotDrag = function _onDotDrag(e) {
|
26755 | preventDefault(e.domEvent);
|
26756 | var map = this.getMap(),
|
26757 | origin = map.getSize().toPoint()._multi(1 / 2),
|
26758 | point = getEventContainerPoint(e.domEvent, this._sliderRuler),
|
26759 | maxZoom = map.getMaxZoom(),
|
26760 | minZoom = map.getMinZoom();
|
26761 | var top = point.y,
|
26762 | z = maxZoom - top / UNIT;
|
26763 |
|
26764 | if (maxZoom < z) {
|
26765 | z = maxZoom;
|
26766 | top = 0;
|
26767 | } else if (minZoom > z) {
|
26768 | z = minZoom;
|
26769 | top = (maxZoom - minZoom) * UNIT;
|
26770 | }
|
26771 |
|
26772 | if (e.type === 'dragging') {
|
26773 | map.onZooming(z, origin, 1);
|
26774 | } else if (e.type === 'dragend') {
|
26775 | if (this.options['seamless']) {
|
26776 | map.onZoomEnd(z, origin);
|
26777 | } else {
|
26778 | map.onZoomEnd(Math.round(z), origin);
|
26779 | }
|
26780 | }
|
26781 | this._sliderDot.style.top = top + 'px';
|
26782 |
|
26783 | this._sliderReading.style.height = (map.getZoom() - minZoom + 1) * UNIT + 'px';
|
26784 | this._updateText();
|
26785 | };
|
26786 |
|
26787 | return Zoom;
|
26788 | }(Control);
|
26789 |
|
26790 | Zoom.mergeOptions(options$29);
|
26791 |
|
26792 | Map.mergeOptions({
|
26793 | 'zoomControl': false
|
26794 | });
|
26795 |
|
26796 | Map.addOnLoadHook(function () {
|
26797 | if (this.options['zoomControl']) {
|
26798 | this.zoomControl = new Zoom(this.options['zoomControl']);
|
26799 | this.addControl(this.zoomControl);
|
26800 | }
|
26801 | });
|
26802 |
|
26803 |
|
26804 |
|
26805 | var index$5 = Object.freeze({
|
26806 | Control: Control,
|
26807 | Attribution: Attribution,
|
26808 | LayerSwitcher: LayerSwitcher,
|
26809 | Overview: Overview,
|
26810 | Panel: Panel,
|
26811 | Scale: Scale,
|
26812 | Toolbar: Toolbar,
|
26813 | Zoom: Zoom
|
26814 | });
|
26815 |
|
26816 | var TileSystem = function () {
|
26817 | function TileSystem(sx, sy, ox, oy) {
|
26818 | classCallCheck(this, TileSystem);
|
26819 |
|
26820 | if (Array.isArray(sx)) {
|
26821 | this.scale = {
|
26822 | x: sx[0],
|
26823 | y: sx[1]
|
26824 | };
|
26825 | this.origin = {
|
26826 | x: sx[2],
|
26827 | y: sx[3]
|
26828 | };
|
26829 | } else {
|
26830 | this.scale = {
|
26831 | x: sx,
|
26832 | y: sy
|
26833 | };
|
26834 | this.origin = {
|
26835 | x: ox,
|
26836 | y: oy
|
26837 | };
|
26838 | }
|
26839 | }
|
26840 |
|
26841 | TileSystem.getDefault = function getDefault(projection) {
|
26842 | if (projection['code'].toLowerCase() === 'baidu') {
|
26843 | return 'baidu';
|
26844 | } else if (projection['code'].toLowerCase() === 'EPSG:4326'.toLowerCase()) {
|
26845 | return 'tms-global-geodetic';
|
26846 | } else if (projection['code'].toLowerCase() === 'identity') {
|
26847 | return [1, -1, 0, 0];
|
26848 | } else {
|
26849 | return 'web-mercator';
|
26850 | }
|
26851 | };
|
26852 |
|
26853 | return TileSystem;
|
26854 | }();
|
26855 |
|
26856 | var semiCircum = 6378137 * Math.PI;
|
26857 |
|
26858 | extend(TileSystem, {
|
26859 | 'web-mercator': new TileSystem([1, -1, -semiCircum, semiCircum]),
|
26860 |
|
26861 | 'tms-global-mercator': new TileSystem([1, 1, -semiCircum, -semiCircum]),
|
26862 |
|
26863 | 'tms-global-geodetic': new TileSystem([1, 1, -180, -90]),
|
26864 |
|
26865 | 'baidu': new TileSystem([1, 1, 0, 0])
|
26866 | });
|
26867 |
|
26868 | var TileConfig = function () {
|
26869 | function TileConfig(tileSystem, fullExtent, tileSize) {
|
26870 | classCallCheck(this, TileConfig);
|
26871 |
|
26872 | this.tileSize = tileSize;
|
26873 | this.fullExtent = fullExtent;
|
26874 | this.prepareTileInfo(tileSystem, fullExtent);
|
26875 | }
|
26876 |
|
26877 | TileConfig.prototype.prepareTileInfo = function prepareTileInfo(tileSystem, fullExtent) {
|
26878 | if (isString(tileSystem)) {
|
26879 | tileSystem = TileSystem[tileSystem.toLowerCase()];
|
26880 | } else if (Array.isArray(tileSystem)) {
|
26881 | tileSystem = new TileSystem(tileSystem);
|
26882 | }
|
26883 |
|
26884 | if (!tileSystem) {
|
26885 | throw new Error('Invalid TileSystem');
|
26886 | }
|
26887 | this.tileSystem = tileSystem;
|
26888 |
|
26889 | var a = fullExtent['right'] > fullExtent['left'] ? 1 : -1,
|
26890 | b = fullExtent['top'] > fullExtent['bottom'] ? -1 : 1,
|
26891 | c = tileSystem['origin']['x'],
|
26892 | d = tileSystem['origin']['y'];
|
26893 | this.transformation = new Transformation([a, b, c, d]);
|
26894 | };
|
26895 |
|
26896 | TileConfig.prototype._getTileNum = function _getTileNum(point, res) {
|
26897 | var tileSystem = this.tileSystem,
|
26898 | tileSize = this['tileSize'],
|
26899 | delta = 1E-7;
|
26900 | var tileX = Math.floor(delta + point.x / (tileSize['width'] * res));
|
26901 | var tileY = -Math.floor(delta + point.y / (tileSize['height'] * res));
|
26902 |
|
26903 | return {
|
26904 | 'x': tileSystem['scale']['x'] * tileX,
|
26905 | 'y': tileSystem['scale']['y'] * tileY
|
26906 | };
|
26907 | };
|
26908 |
|
26909 | TileConfig.prototype.getTileIndex = function getTileIndex(pCoord, res) {
|
26910 | var tileSystem = this.tileSystem;
|
26911 |
|
26912 | var point = this.transformation.transform(pCoord, 1);
|
26913 | var tileIndex = this._getTileNum(point, res);
|
26914 |
|
26915 | if (tileSystem['scale']['x'] < 0) {
|
26916 | tileIndex['x'] -= 1;
|
26917 | }
|
26918 |
|
26919 | if (tileSystem['scale']['y'] > 0) {
|
26920 | tileIndex['y'] -= 1;
|
26921 | }
|
26922 |
|
26923 | return this.getNeighorTileIndex(tileIndex['x'], tileIndex['y'], 0, 0, true);
|
26924 | };
|
26925 |
|
26926 | TileConfig.prototype.getNeighorTileIndex = function getNeighorTileIndex(tileX, tileY, offsetX, offsetY, res, isRepeatWorld) {
|
26927 | var tileSystem = this.tileSystem;
|
26928 | var x = tileX + tileSystem['scale']['x'] * offsetX;
|
26929 | var y = tileY - tileSystem['scale']['y'] * offsetY;
|
26930 | var idx = x;
|
26931 | var idy = y;
|
26932 | if (isRepeatWorld) {
|
26933 | var ext = this._getTileFullIndex(res);
|
26934 | if (x < ext['xmin']) {
|
26935 | x = ext['xmax'] - (ext['xmin'] - x) % (ext['xmax'] - ext['xmin']);
|
26936 | if (x === ext['xmax']) {
|
26937 | x = ext['xmin'];
|
26938 | }
|
26939 | } else if (x >= ext['xmax']) {
|
26940 | x = ext['xmin'] + (x - ext['xmin']) % (ext['xmax'] - ext['xmin']);
|
26941 | }
|
26942 |
|
26943 | if (y >= ext['ymax']) {
|
26944 | y = ext['ymin'] + (y - ext['ymin']) % (ext['ymax'] - ext['ymin']);
|
26945 | } else if (y < ext['ymin']) {
|
26946 | y = ext['ymax'] - (ext['ymin'] - y) % (ext['ymax'] - ext['ymin']);
|
26947 | if (y === ext['ymax']) {
|
26948 | y = ext['ymin'];
|
26949 | }
|
26950 | }
|
26951 | }
|
26952 | return {
|
26953 | 'x': x,
|
26954 | 'y': y,
|
26955 |
|
26956 | 'idx': idx,
|
26957 | 'idy': idy
|
26958 | };
|
26959 | };
|
26960 |
|
26961 | TileConfig.prototype._getTileFullIndex = function _getTileFullIndex(res) {
|
26962 | var ext = this.fullExtent;
|
26963 | var transformation = this.transformation;
|
26964 | var nwIndex = this._getTileNum(transformation.transform(new Coordinate(ext['left'], ext['top']), 1), res);
|
26965 | var seIndex = this._getTileNum(transformation.transform(new Coordinate(ext['right'], ext['bottom']), 1), res);
|
26966 | return new Extent(nwIndex, seIndex);
|
26967 | };
|
26968 |
|
26969 | TileConfig.prototype.getTilePrjNW = function getTilePrjNW(tileX, tileY, res) {
|
26970 | var tileSystem = this.tileSystem;
|
26971 | var tileSize = this['tileSize'];
|
26972 | var y = tileSystem['origin']['y'] + tileSystem['scale']['y'] * (tileY + (tileSystem['scale']['y'] === 1 ? 1 : 0)) * (res * tileSize['height']);
|
26973 | var x = tileSystem['scale']['x'] * (tileX + (tileSystem['scale']['x'] === 1 ? 0 : 1)) * res * tileSize['width'] + tileSystem['origin']['x'];
|
26974 | return new Coordinate(x, y);
|
26975 | };
|
26976 |
|
26977 | TileConfig.prototype.getTilePrjSE = function getTilePrjSE(tileX, tileY, res) {
|
26978 | var tileSystem = this.tileSystem;
|
26979 | var tileSize = this['tileSize'];
|
26980 | var y = tileSystem['origin']['y'] + tileSystem['scale']['y'] * (tileY + (tileSystem['scale']['y'] === 1 ? 0 : 1)) * (res * tileSize['height']);
|
26981 | var x = tileSystem['scale']['x'] * (tileX + (tileSystem['scale']['x'] === 1 ? 1 : 0)) * res * tileSize['width'] + tileSystem['origin']['x'];
|
26982 | return new Coordinate(x, y);
|
26983 | };
|
26984 |
|
26985 | TileConfig.prototype.getTilePrjExtent = function getTilePrjExtent(tileX, tileY, res) {
|
26986 | var nw = this.getTilePrjNW(tileX, tileY, res),
|
26987 | se = this.getTilePrjSE(tileX, tileY, res);
|
26988 | return new Extent(nw, se);
|
26989 | };
|
26990 |
|
26991 | return TileConfig;
|
26992 | }();
|
26993 |
|
26994 | var options$30 = {
|
26995 |
|
26996 | 'urlTemplate': null,
|
26997 | 'subdomains': null,
|
26998 |
|
26999 | 'repeatWorld': true,
|
27000 |
|
27001 | 'background': true,
|
27002 | 'backgroundZoomDiff': 6,
|
27003 |
|
27004 | 'loadingLimitOnInteracting': 3,
|
27005 |
|
27006 | 'placeholder': false,
|
27007 |
|
27008 | 'crossOrigin': null,
|
27009 |
|
27010 | 'tileSize': [256, 256],
|
27011 |
|
27012 | 'offset': [0, 0],
|
27013 |
|
27014 | 'tileSystem': null,
|
27015 |
|
27016 | 'fadeAnimation': !IS_NODE,
|
27017 |
|
27018 | 'debug': false,
|
27019 |
|
27020 | 'spatialReference': null,
|
27021 |
|
27022 | 'maxCacheSize': 256,
|
27023 |
|
27024 | 'renderer': function () {
|
27025 | return Browser$1.webgl ? 'gl' : 'canvas';
|
27026 | }(),
|
27027 |
|
27028 | 'clipByPitch': true,
|
27029 |
|
27030 | 'maxAvailableZoom': null,
|
27031 |
|
27032 | 'cascadeTiles': true,
|
27033 | 'minPitchToCascade': 35
|
27034 | };
|
27035 |
|
27036 | var urlPattern = /\{ *([\w_]+) *\}/g;
|
27037 |
|
27038 | var MAX_VISIBLE_SIZE = 5;
|
27039 |
|
27040 | var TileLayer = function (_Layer) {
|
27041 | inherits(TileLayer, _Layer);
|
27042 |
|
27043 | function TileLayer() {
|
27044 | classCallCheck(this, TileLayer);
|
27045 | return possibleConstructorReturn(this, _Layer.apply(this, arguments));
|
27046 | }
|
27047 |
|
27048 | TileLayer.fromJSON = function fromJSON(layerJSON) {
|
27049 | if (!layerJSON || layerJSON['type'] !== 'TileLayer') {
|
27050 | return null;
|
27051 | }
|
27052 | return new TileLayer(layerJSON['id'], layerJSON['options']);
|
27053 | };
|
27054 |
|
27055 | TileLayer.prototype.getTileSize = function getTileSize() {
|
27056 | return new Size(this.options['tileSize']);
|
27057 | };
|
27058 |
|
27059 | TileLayer.prototype.getTiles = function getTiles(z) {
|
27060 | var map = this.getMap();
|
27061 | var mapExtent = map.getContainerExtent();
|
27062 | var tileGrids = [];
|
27063 | var count = 0;
|
27064 | var minZoom = this.getMinZoom();
|
27065 | var minPitchToCascade = this.options['minPitchToCascade'];
|
27066 | var tileZoom = isNil(z) ? this._getTileZoom(map.getZoom()) : z;
|
27067 | if (!isNil(z) || !this.options['cascadeTiles'] || map.getPitch() <= minPitchToCascade || !isNil(minZoom) && tileZoom <= minZoom) {
|
27068 | var _currentTiles = this._getTiles(tileZoom, mapExtent);
|
27069 | if (_currentTiles) {
|
27070 | count += _currentTiles.tiles.length;
|
27071 | tileGrids.push(_currentTiles);
|
27072 | }
|
27073 | return {
|
27074 | tileGrids: tileGrids, count: count
|
27075 | };
|
27076 | }
|
27077 |
|
27078 | var visualHeight = Math.floor(map._getVisualHeight(minPitchToCascade));
|
27079 | var extent0 = new PointExtent(0, map.height - visualHeight, map.width, map.height);
|
27080 | var currentTiles = this._getTiles(tileZoom, extent0, 0);
|
27081 | count += currentTiles ? currentTiles.tiles.length : 0;
|
27082 |
|
27083 | var extent1 = new PointExtent(0, mapExtent.ymin, map.width, extent0.ymin);
|
27084 | var d = map.getSpatialReference().getZoomDirection();
|
27085 | var parentTiles = this._getTiles(tileZoom - d, extent1, 1);
|
27086 | count += parentTiles ? parentTiles.tiles.length : 0;
|
27087 |
|
27088 | tileGrids.push(currentTiles, parentTiles);
|
27089 | return {
|
27090 | tileGrids: tileGrids, count: count
|
27091 | };
|
27092 | };
|
27093 |
|
27094 | TileLayer.prototype.getTileUrl = function getTileUrl(x, y, z) {
|
27095 | var urlTemplate = this.options['urlTemplate'];
|
27096 | var domain = '';
|
27097 | if (this.options['subdomains']) {
|
27098 | var subdomains = this.options['subdomains'];
|
27099 | if (isArrayHasData(subdomains)) {
|
27100 | var length = subdomains.length;
|
27101 | var s = (x + y) % length;
|
27102 | if (s < 0) {
|
27103 | s = 0;
|
27104 | }
|
27105 | domain = subdomains[s];
|
27106 | }
|
27107 | }
|
27108 | if (isFunction(urlTemplate)) {
|
27109 | return urlTemplate(x, y, z, domain);
|
27110 | }
|
27111 | var data = {
|
27112 | 'x': x,
|
27113 | 'y': y,
|
27114 | 'z': z,
|
27115 | 's': domain
|
27116 | };
|
27117 | return urlTemplate.replace(urlPattern, function (str, key) {
|
27118 | var value = data[key];
|
27119 |
|
27120 | if (value === undefined) {
|
27121 | throw new Error('No value provided for variable ' + str);
|
27122 | } else if (typeof value === 'function') {
|
27123 | value = value(data);
|
27124 | }
|
27125 | return value;
|
27126 | });
|
27127 | };
|
27128 |
|
27129 | TileLayer.prototype.clear = function clear() {
|
27130 | if (this._renderer) {
|
27131 | this._renderer.clear();
|
27132 | }
|
27133 |
|
27134 | this.fire('clear');
|
27135 | return this;
|
27136 | };
|
27137 |
|
27138 | TileLayer.prototype.toJSON = function toJSON() {
|
27139 | var profile = {
|
27140 | 'type': this.getJSONType(),
|
27141 | 'id': this.getId(),
|
27142 | 'options': this.config()
|
27143 | };
|
27144 | return profile;
|
27145 | };
|
27146 |
|
27147 | TileLayer.prototype.getSpatialReference = function getSpatialReference() {
|
27148 | var map = this.getMap();
|
27149 | if (map && (!this.options['spatialReference'] || SpatialReference.equals(this.options['spatialReference'], map.options['spatialReference']))) {
|
27150 | return map.getSpatialReference();
|
27151 | }
|
27152 | this._sr = this._sr || new SpatialReference(this.options['spatialReference']);
|
27153 | return this._sr;
|
27154 | };
|
27155 |
|
27156 | TileLayer.prototype._getTileZoom = function _getTileZoom(zoom) {
|
27157 | var map = this.getMap();
|
27158 | if (!isInteger(zoom)) {
|
27159 | if (map.isZooming()) {
|
27160 | zoom = zoom > map._frameZoom ? Math.floor(zoom) : Math.ceil(zoom);
|
27161 | } else {
|
27162 | zoom = Math.round(zoom);
|
27163 | }
|
27164 | }
|
27165 | var maxZoom = this.options['maxAvailableZoom'];
|
27166 | if (!isNil(maxZoom) && zoom > maxZoom) {
|
27167 | zoom = maxZoom;
|
27168 | }
|
27169 | return zoom;
|
27170 | };
|
27171 |
|
27172 | TileLayer.prototype._getTiles = function _getTiles(z, containerExtent, maskID) {
|
27173 | var map = this.getMap();
|
27174 | if (!map || !this.isVisible() || !map.width || !map.height) {
|
27175 | return null;
|
27176 | }
|
27177 | var minZoom = this.getMinZoom(),
|
27178 | maxZoom = this.getMaxZoom();
|
27179 | if (!isNil(minZoom) && z < minZoom || !isNil(maxZoom) && z > maxZoom) {
|
27180 | return null;
|
27181 | }
|
27182 | var tileConfig = this._getTileConfig();
|
27183 | if (!tileConfig) {
|
27184 | return null;
|
27185 | }
|
27186 |
|
27187 | var zoom = z,
|
27188 | sr = this.getSpatialReference(),
|
27189 | mapSR = map.getSpatialReference(),
|
27190 | res = sr.getResolution(zoom);
|
27191 | var emptyGrid = {
|
27192 | 'zoom': zoom,
|
27193 | 'extent': null,
|
27194 | 'tiles': []
|
27195 | };
|
27196 |
|
27197 | var offset = this._getTileOffset(zoom),
|
27198 | hasOffset = offset[0] || offset[1];
|
27199 |
|
27200 | var extent2d = containerExtent.convertTo(function (c) {
|
27201 | return map._containerPointToPoint(c);
|
27202 | })._add(offset),
|
27203 | innerExtent2D = this._getInnerExtent(zoom, containerExtent, extent2d);
|
27204 |
|
27205 | var maskExtent = this._getMask2DExtent();
|
27206 | if (maskExtent) {
|
27207 | var intersection = maskExtent.intersection(extent2d);
|
27208 | if (!intersection) {
|
27209 | return emptyGrid;
|
27210 | }
|
27211 | containerExtent = intersection.convertTo(function (c) {
|
27212 | return map._pointToContainerPoint(c);
|
27213 | });
|
27214 | }
|
27215 |
|
27216 | var prjCenter = map._containerPointToPrj(containerExtent.getCenter());
|
27217 | var c = void 0;
|
27218 | if (hasOffset) {
|
27219 | c = this._project(map._pointToPrj(map._prjToPoint(prjCenter)._add(offset)));
|
27220 | } else {
|
27221 | c = this._project(prjCenter);
|
27222 | }
|
27223 | var pmin = this._project(map._pointToPrj(extent2d.getMin())),
|
27224 | pmax = this._project(map._pointToPrj(extent2d.getMax()));
|
27225 |
|
27226 | var centerTile = tileConfig.getTileIndex(c, res),
|
27227 | ltTile = tileConfig.getTileIndex(pmin, res),
|
27228 | rbTile = tileConfig.getTileIndex(pmax, res);
|
27229 |
|
27230 | var top = Math.ceil(Math.abs(centerTile.y - ltTile.y)),
|
27231 | left = Math.ceil(Math.abs(centerTile.x - ltTile.x)),
|
27232 | bottom = Math.ceil(Math.abs(centerTile.y - rbTile.y)),
|
27233 | right = Math.ceil(Math.abs(centerTile.x - rbTile.x));
|
27234 | var layerId = this.getId(),
|
27235 | renderer = this.getRenderer(),
|
27236 | tileSize = this.getTileSize(),
|
27237 | scale = this._getTileConfig().tileSystem.scale;
|
27238 | var tiles = [],
|
27239 | extent = new PointExtent();
|
27240 | for (var i = -left; i <= right; i++) {
|
27241 | for (var j = -top; j <= bottom; j++) {
|
27242 | var idx = tileConfig.getNeighorTileIndex(centerTile['x'], centerTile['y'], i, j, res, this.options['repeatWorld']),
|
27243 | pnw = tileConfig.getTilePrjNW(idx.x, idx.y, res),
|
27244 | p = map._prjToPoint(this._unproject(pnw), zoom);
|
27245 | var width = void 0,
|
27246 | height = void 0;
|
27247 | if (sr === mapSR) {
|
27248 | width = tileSize.width;
|
27249 | height = tileSize.height;
|
27250 | } else {
|
27251 | var pse = tileConfig.getTilePrjSE(idx.x, idx.y, res),
|
27252 | pp = map._prjToPoint(this._unproject(pse), zoom);
|
27253 | width = Math.abs(Math.round(pp.x - p.x));
|
27254 | height = Math.abs(Math.round(pp.y - p.y));
|
27255 | }
|
27256 | var dx = scale.x * (idx.idx - idx.x) * width,
|
27257 | dy = -scale.y * (idx.idy - idx.y) * height;
|
27258 | if (dx || dy) {
|
27259 | p._add(dx, dy);
|
27260 | }
|
27261 | if (sr !== mapSR) {
|
27262 | width++;
|
27263 | height++;
|
27264 | }
|
27265 | if (hasOffset) {
|
27266 | p._sub(offset);
|
27267 | }
|
27268 | var tileExtent = new PointExtent(p, p.add(width, height)),
|
27269 | tileInfo = {
|
27270 | 'point': p,
|
27271 | 'z': zoom,
|
27272 | 'x': idx.x,
|
27273 | 'y': idx.y,
|
27274 | 'extent2d': tileExtent,
|
27275 | 'mask': maskID
|
27276 | };
|
27277 | if (innerExtent2D.intersects(tileExtent) || !innerExtent2D.equals(extent2d) && this._isTileInExtent(tileInfo, containerExtent)) {
|
27278 | if (hasOffset) {
|
27279 | tileInfo.point._add(offset);
|
27280 | tileInfo.extent2d._add(offset);
|
27281 | }
|
27282 | tileInfo['size'] = [width, height];
|
27283 | tileInfo['dupKey'] = p.round().toArray().join() + ',' + width + ',' + height + ',' + layerId;
|
27284 | tileInfo['id'] = this._getTileId(idx, zoom);
|
27285 | tileInfo['layer'] = layerId;
|
27286 | if (!renderer || !renderer.isTileCachedOrLoading(tileInfo.id)) {
|
27287 | tileInfo['url'] = this.getTileUrl(idx.x, idx.y, zoom);
|
27288 | }
|
27289 | tiles.push(tileInfo);
|
27290 | extent._combine(tileExtent);
|
27291 | }
|
27292 | }
|
27293 | }
|
27294 |
|
27295 | var center = map._containerPointToPoint(containerExtent.getCenter(), zoom)._add(offset);
|
27296 | tiles.sort(function (a, b) {
|
27297 | return a.point.distanceTo(center) - b.point.distanceTo(center);
|
27298 | });
|
27299 |
|
27300 | return {
|
27301 | 'offset': offset,
|
27302 | 'zoom': zoom,
|
27303 | 'extent': extent,
|
27304 | 'tiles': tiles
|
27305 | };
|
27306 | };
|
27307 |
|
27308 | TileLayer.prototype._getInnerExtent = function _getInnerExtent(zoom, containerExtent, extent2d) {
|
27309 | var map = this.getMap(),
|
27310 | res = map.getResolution(zoom),
|
27311 | scale = map.getResolution() / res,
|
27312 | center = extent2d.getCenter()._multi(scale),
|
27313 | bearing = map.getBearing() * Math.PI / 180,
|
27314 | ch = containerExtent.getHeight() / 2 * scale,
|
27315 | cw = containerExtent.getWidth() / 2 * scale,
|
27316 | h = Math.abs(Math.cos(bearing) * ch) || ch,
|
27317 | w = Math.abs(Math.sin(bearing) * ch) || cw;
|
27318 | return new PointExtent(center.sub(w, h), center.add(w, h));
|
27319 | };
|
27320 |
|
27321 | TileLayer.prototype._getTileOffset = function _getTileOffset(z) {
|
27322 | var map = this.getMap();
|
27323 | var scale = map._getResolution() / map._getResolution(z);
|
27324 | var offset = this.options['offset'];
|
27325 | if (isFunction(offset)) {
|
27326 | offset = offset(this);
|
27327 | }
|
27328 | offset[0] *= scale;
|
27329 | offset[1] *= scale;
|
27330 | return offset;
|
27331 | };
|
27332 |
|
27333 | TileLayer.prototype._getTileId = function _getTileId(idx, zoom, id) {
|
27334 | return [id || this.getId(), idx.idy, idx.idx, zoom].join('__');
|
27335 | };
|
27336 |
|
27337 | TileLayer.prototype._project = function _project(pcoord) {
|
27338 | var map = this.getMap();
|
27339 | var sr = this.getSpatialReference();
|
27340 | if (sr !== map.getSpatialReference()) {
|
27341 | return sr.getProjection().project(map.getProjection().unproject(pcoord));
|
27342 | } else {
|
27343 | return pcoord;
|
27344 | }
|
27345 | };
|
27346 |
|
27347 | TileLayer.prototype._unproject = function _unproject(pcoord) {
|
27348 | var map = this.getMap();
|
27349 | var sr = this.getSpatialReference();
|
27350 | if (sr !== map.getSpatialReference()) {
|
27351 | return map.getProjection().project(sr.getProjection().unproject(pcoord));
|
27352 | } else {
|
27353 | return pcoord;
|
27354 | }
|
27355 | };
|
27356 |
|
27357 | TileLayer.prototype._initTileConfig = function _initTileConfig() {
|
27358 | var map = this.getMap(),
|
27359 | tileSize = this.getTileSize();
|
27360 | var sr = this.getSpatialReference();
|
27361 | var projection = sr.getProjection(),
|
27362 | fullExtent = sr.getFullExtent();
|
27363 | this._defaultTileConfig = new TileConfig(TileSystem.getDefault(projection), fullExtent, tileSize);
|
27364 | if (this.options['tileSystem']) {
|
27365 | this._tileConfig = new TileConfig(this.options['tileSystem'], fullExtent, tileSize);
|
27366 | }
|
27367 |
|
27368 | if (map && !this._tileConfig && map.getSpatialReference() === sr && map.getBaseLayer() && map.getBaseLayer() !== this && map.getBaseLayer()._getTileConfig) {
|
27369 | var base = map.getBaseLayer()._getTileConfig();
|
27370 | this._tileConfig = new TileConfig(base.tileSystem, base.fullExtent, tileSize);
|
27371 | }
|
27372 | };
|
27373 |
|
27374 | TileLayer.prototype._getTileConfig = function _getTileConfig() {
|
27375 | if (!this._defaultTileConfig) {
|
27376 | this._initTileConfig();
|
27377 | }
|
27378 | return this._tileConfig || this._defaultTileConfig;
|
27379 | };
|
27380 |
|
27381 | TileLayer.prototype._bindMap = function _bindMap(map) {
|
27382 | var baseLayer = map.getBaseLayer();
|
27383 | if (baseLayer === this) {
|
27384 | if (!baseLayer.options.hasOwnProperty('forceRenderOnMoving')) {
|
27385 | this.config({
|
27386 | 'forceRenderOnMoving': true
|
27387 | });
|
27388 | }
|
27389 | }
|
27390 | return _Layer.prototype._bindMap.apply(this, arguments);
|
27391 | };
|
27392 |
|
27393 | TileLayer.prototype._isTileInExtent = function _isTileInExtent(tileInfo, extent) {
|
27394 | var map = this.getMap();
|
27395 | if (!map) {
|
27396 | return false;
|
27397 | }
|
27398 | var tileZoom = tileInfo.z;
|
27399 | var tileExtent = tileInfo.extent2d.convertTo(function (c) {
|
27400 | return map._pointToContainerPoint(c, tileZoom);
|
27401 | });
|
27402 | if (tileExtent.getWidth() < MAX_VISIBLE_SIZE || tileExtent.getHeight() < MAX_VISIBLE_SIZE) {
|
27403 | return false;
|
27404 | }
|
27405 | return extent.intersects(tileExtent);
|
27406 | };
|
27407 |
|
27408 | TileLayer.prototype.getEvents = function getEvents() {
|
27409 | return {
|
27410 | 'spatialreferencechange': this._onSpatialReferenceChange
|
27411 | };
|
27412 | };
|
27413 |
|
27414 | TileLayer.prototype._onSpatialReferenceChange = function _onSpatialReferenceChange() {
|
27415 | delete this._tileConfig;
|
27416 | delete this._defaultTileConfig;
|
27417 | delete this._sr;
|
27418 | };
|
27419 |
|
27420 | return TileLayer;
|
27421 | }(Layer);
|
27422 |
|
27423 | TileLayer.registerJSONType('TileLayer');
|
27424 |
|
27425 | TileLayer.mergeOptions(options$30);
|
27426 |
|
27427 | var GroupTileLayer = function (_TileLayer) {
|
27428 | inherits(GroupTileLayer, _TileLayer);
|
27429 |
|
27430 | GroupTileLayer.fromJSON = function fromJSON(layerJSON) {
|
27431 | if (!layerJSON || layerJSON['type'] !== 'GroupTileLayer') {
|
27432 | return null;
|
27433 | }
|
27434 | var layers = layerJSON['layers'].map(function (json) {
|
27435 | return Layer.fromJSON(json);
|
27436 | });
|
27437 | return new GroupTileLayer(layerJSON['id'], layers, layerJSON['options']);
|
27438 | };
|
27439 |
|
27440 | function GroupTileLayer(id, layers, options) {
|
27441 | classCallCheck(this, GroupTileLayer);
|
27442 |
|
27443 | var _this = possibleConstructorReturn(this, _TileLayer.call(this, id, options));
|
27444 |
|
27445 | _this.layers = layers || [];
|
27446 | _this._checkChildren();
|
27447 | _this.layerMap = {};
|
27448 | _this._groupChildren = [];
|
27449 | return _this;
|
27450 | }
|
27451 |
|
27452 | GroupTileLayer.prototype.getLayers = function getLayers() {
|
27453 | return this.layers;
|
27454 | };
|
27455 |
|
27456 | GroupTileLayer.prototype.toJSON = function toJSON() {
|
27457 | var profile = {
|
27458 | 'type': this.getJSONType(),
|
27459 | 'id': this.getId(),
|
27460 | 'layers': this.layers.map(function (layer) {
|
27461 | return layer.toJSON();
|
27462 | }),
|
27463 | 'options': this.config()
|
27464 | };
|
27465 | return profile;
|
27466 | };
|
27467 |
|
27468 | GroupTileLayer.prototype.getTiles = function getTiles(z) {
|
27469 | var layers = this.layers;
|
27470 | var tiles = [];
|
27471 | var count = 0;
|
27472 | for (var i = 0, l = layers.length; i < l; i++) {
|
27473 | var layer = layers[i];
|
27474 | if (!layer.options['visible']) {
|
27475 | continue;
|
27476 | }
|
27477 | var childGrid = layer.getTiles(z);
|
27478 | if (!childGrid || childGrid.count === 0) {
|
27479 | continue;
|
27480 | }
|
27481 | count += childGrid.count;
|
27482 | pushIn(tiles, childGrid.tileGrids);
|
27483 | }
|
27484 |
|
27485 | return {
|
27486 | count: count,
|
27487 | tileGrids: tiles
|
27488 | };
|
27489 | };
|
27490 |
|
27491 | GroupTileLayer.prototype.onAdd = function onAdd() {
|
27492 | var _this2 = this;
|
27493 |
|
27494 | var map = this.getMap();
|
27495 | this.layers.forEach(function (layer) {
|
27496 | _this2.layerMap[layer.getId()] = layer;
|
27497 | if (layer.getChildLayer) {
|
27498 | _this2._groupChildren.push(layer);
|
27499 | }
|
27500 | layer._bindMap(map);
|
27501 | layer.on('show hide', _this2._onLayerShowHide, _this2);
|
27502 | });
|
27503 | _TileLayer.prototype.onAdd.call(this);
|
27504 | };
|
27505 |
|
27506 | GroupTileLayer.prototype.onRemove = function onRemove() {
|
27507 | var _this3 = this;
|
27508 |
|
27509 | this.layers.forEach(function (layer) {
|
27510 | layer._doRemove();
|
27511 | layer.off('show hide', _this3._onLayerShowHide, _this3);
|
27512 | });
|
27513 | delete this.layerMap;
|
27514 | delete this._groupChildren;
|
27515 | _TileLayer.prototype.onRemove.call(this);
|
27516 | };
|
27517 |
|
27518 | GroupTileLayer.prototype.getChildLayer = function getChildLayer(id) {
|
27519 | var layer = this.layerMap[id];
|
27520 | if (layer) {
|
27521 | return layer;
|
27522 | }
|
27523 | for (var i = 0; i < this._groupChildren.length; i++) {
|
27524 | var child = this._groupChildren[i].getChildLayer(id);
|
27525 | if (child) {
|
27526 | return child;
|
27527 | }
|
27528 | }
|
27529 | return null;
|
27530 | };
|
27531 |
|
27532 | GroupTileLayer.prototype._onLayerShowHide = function _onLayerShowHide() {
|
27533 | var renderer = this.getRenderer();
|
27534 | if (renderer) {
|
27535 | renderer.setToRedraw();
|
27536 | }
|
27537 | };
|
27538 |
|
27539 | GroupTileLayer.prototype.isVisible = function isVisible() {
|
27540 | if (!_TileLayer.prototype.isVisible.call(this)) {
|
27541 | return false;
|
27542 | }
|
27543 | var children = this.layers;
|
27544 | for (var i = 0, l = children.length; i < l; i++) {
|
27545 | if (children[i].isVisible()) {
|
27546 | return true;
|
27547 | }
|
27548 | }
|
27549 | return false;
|
27550 | };
|
27551 |
|
27552 | GroupTileLayer.prototype._checkChildren = function _checkChildren() {
|
27553 | var _this4 = this;
|
27554 |
|
27555 | var ids = {};
|
27556 | this.layers.forEach(function (layer) {
|
27557 | var layerId = layer.getId();
|
27558 | if (ids[layerId]) {
|
27559 | throw new Error('Duplicate child layer id (' + layerId + ') in the GroupTileLayer (' + _this4.getId() + ')');
|
27560 | } else {
|
27561 | ids[layerId] = 1;
|
27562 | }
|
27563 | });
|
27564 | };
|
27565 |
|
27566 | return GroupTileLayer;
|
27567 | }(TileLayer);
|
27568 |
|
27569 | GroupTileLayer.registerJSONType('GroupTileLayer');
|
27570 |
|
27571 | var options$31 = {
|
27572 | crs: null,
|
27573 | uppercase: false,
|
27574 | detectRetina: false
|
27575 | };
|
27576 |
|
27577 | var defaultWmsParams = {
|
27578 | service: 'WMS',
|
27579 | request: 'GetMap',
|
27580 | layers: '',
|
27581 | styles: '',
|
27582 | format: 'image/jpeg',
|
27583 | transparent: false,
|
27584 | version: '1.1.1'
|
27585 | };
|
27586 |
|
27587 | var WMSTileLayer = function (_TileLayer) {
|
27588 | inherits(WMSTileLayer, _TileLayer);
|
27589 |
|
27590 | function WMSTileLayer(id, options) {
|
27591 | classCallCheck(this, WMSTileLayer);
|
27592 |
|
27593 | var _this = possibleConstructorReturn(this, _TileLayer.call(this, id));
|
27594 |
|
27595 | var wmsParams = extend({}, defaultWmsParams);
|
27596 | for (var p in options) {
|
27597 | if (!(p in _this.options)) {
|
27598 | wmsParams[p] = options[p];
|
27599 | }
|
27600 | }
|
27601 | _this.setOptions(options);
|
27602 | var r = options.detectRetina && Browser$1.retina ? 2 : 1,
|
27603 | tileSize = _this.getTileSize();
|
27604 | wmsParams.width = tileSize.width * r;
|
27605 | wmsParams.height = tileSize.height * r;
|
27606 | _this.wmsParams = wmsParams;
|
27607 | _this._wmsVersion = parseFloat(wmsParams.version);
|
27608 | return _this;
|
27609 | }
|
27610 |
|
27611 | WMSTileLayer.prototype.onAdd = function onAdd() {
|
27612 | var crs = this.options.crs || this.getMap().getProjection().code;
|
27613 | var projectionKey = this._wmsVersion >= 1.3 ? 'crs' : 'srs';
|
27614 | this.wmsParams[projectionKey] = crs;
|
27615 | _TileLayer.prototype.onAdd.call(this);
|
27616 | };
|
27617 |
|
27618 | WMSTileLayer.prototype.getTileUrl = function getTileUrl(x, y, z) {
|
27619 | var map = this.getMap(),
|
27620 | res = map._getResolution(z),
|
27621 | tileConfig = this._getTileConfig(),
|
27622 | tileExtent = tileConfig.getTilePrjExtent(x, y, res);
|
27623 | var max = tileExtent.getMax(),
|
27624 | min = tileExtent.getMin();
|
27625 |
|
27626 | var bbox = (this._wmsVersion >= 1.3 && this.wmsParams.crs === 'EPSG:4326' ? [min.y, min.x, max.y, max.x] : [min.x, min.y, max.x, max.y]).join(',');
|
27627 |
|
27628 | var url = _TileLayer.prototype.getTileUrl.call(this, x, y, z);
|
27629 |
|
27630 | return url + getParamString(this.wmsParams, url, this.options.uppercase) + (this.options.uppercase ? '&BBOX=' : '&bbox=') + bbox;
|
27631 | };
|
27632 |
|
27633 | WMSTileLayer.prototype.toJSON = function toJSON() {
|
27634 | return {
|
27635 | 'type': 'WMSTileLayer',
|
27636 | 'id': this.getId(),
|
27637 | 'options': this.config()
|
27638 | };
|
27639 | };
|
27640 |
|
27641 | WMSTileLayer.fromJSON = function fromJSON(layerJSON) {
|
27642 | if (!layerJSON || layerJSON['type'] !== 'WMSTileLayer') {
|
27643 | return null;
|
27644 | }
|
27645 | return new WMSTileLayer(layerJSON['id'], layerJSON['options']);
|
27646 | };
|
27647 |
|
27648 | return WMSTileLayer;
|
27649 | }(TileLayer);
|
27650 |
|
27651 | WMSTileLayer.registerJSONType('WMSTileLayer');
|
27652 |
|
27653 | WMSTileLayer.mergeOptions(options$31);
|
27654 |
|
27655 | function getParamString(obj, existingUrl, uppercase) {
|
27656 | var params = [];
|
27657 | for (var i in obj) {
|
27658 | params.push(encodeURIComponent(uppercase ? i.toUpperCase() : i) + '=' + encodeURIComponent(obj[i]));
|
27659 | }
|
27660 | return (!existingUrl || existingUrl.indexOf('?') === -1 ? '?' : '&') + params.join('&');
|
27661 | }
|
27662 |
|
27663 | var CanvasTileLayer = function (_TileLayer) {
|
27664 | inherits(CanvasTileLayer, _TileLayer);
|
27665 |
|
27666 | function CanvasTileLayer(id, options) {
|
27667 | classCallCheck(this, CanvasTileLayer);
|
27668 |
|
27669 | var _this = possibleConstructorReturn(this, _TileLayer.call(this, id, options));
|
27670 |
|
27671 | if (!_this.options.hasOwnProperty('forceRenderOnMoving')) {
|
27672 | _this.options['forceRenderOnMoving'] = false;
|
27673 | }
|
27674 | return _this;
|
27675 | }
|
27676 |
|
27677 | CanvasTileLayer.prototype.drawTile = function drawTile() {};
|
27678 |
|
27679 | CanvasTileLayer.prototype.toJSON = function toJSON() {
|
27680 | return {
|
27681 | 'type': 'CanvasTileLayer',
|
27682 | 'id': this.getId(),
|
27683 | 'options': this.config()
|
27684 | };
|
27685 | };
|
27686 |
|
27687 | CanvasTileLayer.fromJSON = function fromJSON(layerJSON) {
|
27688 | if (!layerJSON || layerJSON['type'] !== 'CanvasTileLayer') {
|
27689 | return null;
|
27690 | }
|
27691 | return new CanvasTileLayer(layerJSON['id'], layerJSON['options']);
|
27692 | };
|
27693 |
|
27694 | return CanvasTileLayer;
|
27695 | }(TileLayer);
|
27696 |
|
27697 | CanvasTileLayer.registerJSONType('CanvasTileLayer');
|
27698 |
|
27699 | function createGLContext(canvas, options) {
|
27700 | var attributes = {
|
27701 | 'alpha': true,
|
27702 | 'stencil': true,
|
27703 | 'preserveDrawingBuffer': true,
|
27704 | 'antialias': false
|
27705 | };
|
27706 | var names = ['webgl', 'experimental-webgl'];
|
27707 | var context = null;
|
27708 |
|
27709 | for (var i = 0; i < names.length; ++i) {
|
27710 | try {
|
27711 | context = canvas.getContext(names[i], options || attributes);
|
27712 | } catch (e) {}
|
27713 | if (context) {
|
27714 | break;
|
27715 | }
|
27716 | }
|
27717 | return context;
|
27718 | }
|
27719 |
|
27720 | function compileShader(gl, type, source) {
|
27721 | var shader = gl.createShader(type);
|
27722 |
|
27723 | gl.shaderSource(shader, source);
|
27724 | gl.compileShader(shader);
|
27725 |
|
27726 | var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
27727 | if (!compiled) {
|
27728 | var error = gl.getShaderInfoLog(shader);
|
27729 | gl.deleteShader(shader);
|
27730 | throw new Error('Failed to compile shader: ' + error);
|
27731 | }
|
27732 | return shader;
|
27733 | }
|
27734 |
|
27735 | function createProgram(gl, vert, frag) {
|
27736 | var vertexShader = compileShader(gl, gl.VERTEX_SHADER, vert);
|
27737 | var fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, frag);
|
27738 | if (!vertexShader || !fragmentShader) {
|
27739 | return null;
|
27740 | }
|
27741 |
|
27742 | var program = gl.createProgram();
|
27743 | if (!program) {
|
27744 | return null;
|
27745 | }
|
27746 |
|
27747 | gl.attachShader(program, vertexShader);
|
27748 | gl.attachShader(program, fragmentShader);
|
27749 |
|
27750 | gl.linkProgram(program);
|
27751 | return { program: program, vertexShader: vertexShader, fragmentShader: fragmentShader };
|
27752 | }
|
27753 |
|
27754 | function enableVertexAttrib(gl, program, attributes) {
|
27755 | if (Array.isArray(attributes[0])) {
|
27756 | var FSIZE = Float32Array.BYTES_PER_ELEMENT;
|
27757 | var STRIDE = 0;
|
27758 | for (var i = 0; i < attributes.length; i++) {
|
27759 | STRIDE += attributes[i][1] || 0;
|
27760 | }
|
27761 | var offset = 0;
|
27762 | for (var _i = 0; _i < attributes.length; _i++) {
|
27763 | var attr = gl.getAttribLocation(program, attributes[_i][0]);
|
27764 | if (attr < 0) {
|
27765 | throw new Error('Failed to get the storage location of ' + attributes[_i][0]);
|
27766 | }
|
27767 | gl.vertexAttribPointer(attr, attributes[_i][1], gl[attributes[_i][2] || 'FLOAT'], false, FSIZE * STRIDE, FSIZE * offset);
|
27768 | offset += attributes[_i][1] || 0;
|
27769 | gl.enableVertexAttribArray(attr);
|
27770 | }
|
27771 | } else {
|
27772 | var _attr = gl.getAttribLocation(program, attributes[0]);
|
27773 | gl.vertexAttribPointer(_attr, attributes[1], gl[attributes[2] || 'FLOAT'], false, 0, 0);
|
27774 | gl.enableVertexAttribArray(_attr);
|
27775 | }
|
27776 | }
|
27777 |
|
27778 | var shaders = {
|
27779 | 'vertexShader': '\n attribute vec3 a_position;\n\n attribute vec2 a_texCoord;\n\n uniform mat4 u_matrix;\n\n varying vec2 v_texCoord;\n\n void main() {\n gl_Position = u_matrix * vec4(a_position, 1.0);\n\n v_texCoord = a_texCoord;\n }\n ',
|
27780 |
|
27781 | 'fragmentShader': '\n precision mediump float;\n\n uniform sampler2D u_image;\n\n uniform float u_opacity;\n\n varying vec2 v_texCoord;\n\n void main() {\n\n gl_FragColor = texture2D(u_image, v_texCoord) * u_opacity;\n\n }\n '
|
27782 | };
|
27783 |
|
27784 | var v2 = [0, 0];
|
27785 | var v3 = [0, 0, 0];
|
27786 | var arr16 = new Array(16);
|
27787 |
|
27788 | var ImageGLRenderable = function ImageGLRenderable(Base) {
|
27789 | var renderable = function (_Base) {
|
27790 | inherits(renderable, _Base);
|
27791 |
|
27792 | function renderable() {
|
27793 | classCallCheck(this, renderable);
|
27794 | return possibleConstructorReturn(this, _Base.apply(this, arguments));
|
27795 | }
|
27796 |
|
27797 | renderable.prototype.drawGLImage = function drawGLImage(image, x, y, w, h, opacity) {
|
27798 | var gl = this.gl;
|
27799 | this.loadTexture(image);
|
27800 |
|
27801 | v3[0] = x || 0;
|
27802 | v3[1] = y || 0;
|
27803 | var uMatrix = identity(arr16);
|
27804 | translate(uMatrix, uMatrix, v3);
|
27805 | multiply(uMatrix, this.getMap().projViewMatrix, uMatrix);
|
27806 | gl.uniformMatrix4fv(this.program['u_matrix'], false, uMatrix);
|
27807 | gl.uniform1f(this.program['u_opacity'], opacity);
|
27808 | if (!image.glBuffer) {
|
27809 | image.glBuffer = this.bufferTileData(0, 0, w, h);
|
27810 | } else {
|
27811 | gl.bindBuffer(gl.ARRAY_BUFFER, image.glBuffer);
|
27812 | }
|
27813 |
|
27814 | v2[0] = 'a_position';
|
27815 | v2[1] = 3;
|
27816 | this.enableVertexAttrib(v2);
|
27817 | gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
27818 | };
|
27819 |
|
27820 | renderable.prototype.bufferTileData = function bufferTileData(x, y, w, h, buffer) {
|
27821 | var x1 = x;
|
27822 | var x2 = x + w;
|
27823 | var y1 = y;
|
27824 | var y2 = y + h;
|
27825 | return this.loadImageBuffer(this.set12(x1, y1, 0, x1, y2, 0, x2, y1, 0, x2, y2, 0), buffer);
|
27826 | };
|
27827 |
|
27828 | renderable.prototype.drawTinImage = function drawTinImage(image, vertices, texCoords, indices, opacity) {
|
27829 | var gl = this.gl;
|
27830 | this.loadTexture(image);
|
27831 | gl.uniformMatrix4fv(this.program['u_matrix'], false, this.getMap().projViewMatrix);
|
27832 | gl.uniform1f(this.program['u_opacity'], opacity);
|
27833 |
|
27834 | gl.bindBuffer(gl.ARRAY_BUFFER, this.posBuffer);
|
27835 | this.enableVertexAttrib(['a_position', 3]);
|
27836 |
|
27837 | gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.DYNAMIC_DRAW);
|
27838 |
|
27839 | gl.bindBuffer(gl.ARRAY_BUFFER, this.texBuffer);
|
27840 | this.enableVertexAttrib(['a_texCoord', 2]);
|
27841 | gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(texCoords), gl.DYNAMIC_DRAW);
|
27842 |
|
27843 | gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.DYNAMIC_DRAW);
|
27844 |
|
27845 | gl.drawElements(gl.TRIANGLES, indices.length, gl.UNSIGNED_SHORT, 0);
|
27846 | };
|
27847 |
|
27848 | renderable.prototype.createCanvas2 = function createCanvas2() {
|
27849 | this.canvas2 = Canvas.createCanvas(this.canvas.width, this.canvas.height);
|
27850 | };
|
27851 |
|
27852 | renderable.prototype.createGLContext = function createGLContext$$1() {
|
27853 | var gl = this.gl = createGLContext(this.canvas2 || this.canvas, this.layer.options['glOptions']);
|
27854 | gl.clearColor(0.0, 0.0, 0.0, 0.0);
|
27855 |
|
27856 | gl.disable(gl.DEPTH_TEST);
|
27857 | gl.enable(gl.STENCIL_TEST);
|
27858 |
|
27859 | gl.enable(gl.BLEND);
|
27860 | gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
27861 |
|
27862 | this.program = this.createProgram(shaders['vertexShader'], this.layer.options['fragmentShader'] || shaders['fragmentShader'], ['u_matrix', 'u_image', 'u_opacity']);
|
27863 | this.useProgram(this.program);
|
27864 |
|
27865 | this.texBuffer = this.createBuffer();
|
27866 | gl.bindBuffer(gl.ARRAY_BUFFER, this.texBuffer);
|
27867 | this.enableVertexAttrib(['a_texCoord', 2]);
|
27868 | gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]), gl.STATIC_DRAW);
|
27869 |
|
27870 | this.enableSampler('u_image');
|
27871 |
|
27872 | gl.activeTexture(gl['TEXTURE0']);
|
27873 |
|
27874 | gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
27875 |
|
27876 | this.posBuffer = this.createBuffer();
|
27877 | gl.bindBuffer(gl.ARRAY_BUFFER, this.posBuffer);
|
27878 | this.enableVertexAttrib(['a_position', 3]);
|
27879 |
|
27880 | this.indicesBuffer = this.createBuffer();
|
27881 | gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
|
27882 | };
|
27883 |
|
27884 | renderable.prototype.resizeGLCanvas = function resizeGLCanvas() {
|
27885 | if (this.gl) {
|
27886 | this.gl.viewport(0, 0, this.canvas.width, this.canvas.height);
|
27887 | }
|
27888 | if (!this.canvas2) {
|
27889 | return;
|
27890 | }
|
27891 | if (this.canvas2.width !== this.canvas.width || this.canvas2.height !== this.canvas.height) {
|
27892 | this.canvas2.width = this.canvas.width;
|
27893 | this.canvas2.height = this.canvas.height;
|
27894 | }
|
27895 | };
|
27896 |
|
27897 | renderable.prototype.clearGLCanvas = function clearGLCanvas() {
|
27898 | if (this.gl) {
|
27899 | this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.STENCIL_BUFFER_BIT);
|
27900 | }
|
27901 | };
|
27902 |
|
27903 | renderable.prototype.disposeImage = function disposeImage(image) {
|
27904 | if (!image) {
|
27905 | return;
|
27906 | }
|
27907 | if (image.texture) {
|
27908 | this.saveTexture(image.texture);
|
27909 | }
|
27910 | if (image.glBuffer) {
|
27911 | this.saveImageBuffer(image.glBuffer);
|
27912 | }
|
27913 | delete image.texture;
|
27914 | delete image.glBuffer;
|
27915 | };
|
27916 |
|
27917 | renderable.prototype._createTexture = function _createTexture(image) {
|
27918 | var gl = this.gl;
|
27919 | var texture = this.getTexture() || gl.createTexture();
|
27920 | gl.bindTexture(gl.TEXTURE_2D, texture);
|
27921 |
|
27922 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
27923 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
27924 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
27925 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
27926 |
|
27927 | gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
27928 |
|
27929 | if (isInteger(log2(image.width)) && isInteger(log2(image.width))) {
|
27930 | gl.generateMipmap(gl.TEXTURE_2D);
|
27931 | }
|
27932 |
|
27933 | return texture;
|
27934 | };
|
27935 |
|
27936 | renderable.prototype.getTexture = function getTexture() {
|
27937 | if (!this._textures) {
|
27938 | this._textures = [];
|
27939 | }
|
27940 | var textures = this._textures;
|
27941 | return textures && textures.length > 0 ? textures.pop() : null;
|
27942 | };
|
27943 |
|
27944 | renderable.prototype.saveTexture = function saveTexture(texture) {
|
27945 | this._textures.push(texture);
|
27946 | };
|
27947 |
|
27948 | renderable.prototype.loadTexture = function loadTexture(image) {
|
27949 | var gl = this.gl;
|
27950 | var texture = image.texture;
|
27951 | if (!texture) {
|
27952 | texture = this._createTexture(image);
|
27953 | image.texture = texture;
|
27954 | }
|
27955 | gl.bindTexture(gl.TEXTURE_2D, texture);
|
27956 | return texture;
|
27957 | };
|
27958 |
|
27959 | renderable.prototype.getImageBuffer = function getImageBuffer() {
|
27960 | if (!this._imageBuffers) {
|
27961 | this._imageBuffers = [];
|
27962 | }
|
27963 | var imageBuffers = this._imageBuffers;
|
27964 | return imageBuffers && imageBuffers.length > 0 ? imageBuffers.pop() : null;
|
27965 | };
|
27966 |
|
27967 | renderable.prototype.saveImageBuffer = function saveImageBuffer(buffer) {
|
27968 | this._imageBuffers.push(buffer);
|
27969 | };
|
27970 |
|
27971 | renderable.prototype.loadImageBuffer = function loadImageBuffer(data, glBuffer) {
|
27972 | var gl = this.gl;
|
27973 |
|
27974 | var buffer = glBuffer || this.createImageBuffer();
|
27975 | gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
27976 | gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
|
27977 | return buffer;
|
27978 | };
|
27979 |
|
27980 | renderable.prototype.createImageBuffer = function createImageBuffer() {
|
27981 | return this.getImageBuffer() || this.createBuffer();
|
27982 | };
|
27983 |
|
27984 | renderable.prototype.removeGLCanvas = function removeGLCanvas() {
|
27985 | var gl = this.gl;
|
27986 | if (!gl) {
|
27987 | return;
|
27988 | }
|
27989 | if (this._buffers) {
|
27990 | this._buffers.forEach(function (b) {
|
27991 | gl.deleteBuffer(b);
|
27992 | });
|
27993 | delete this._buffers;
|
27994 | }
|
27995 | if (this._textures) {
|
27996 | this._textures.forEach(function (t) {
|
27997 | return gl.deleteTexture(t);
|
27998 | });
|
27999 | delete this._textures;
|
28000 | }
|
28001 | delete this.posBuffer;
|
28002 | var program = gl.program;
|
28003 | gl.deleteShader(program.fragmentShader);
|
28004 | gl.deleteShader(program.vertexShader);
|
28005 | gl.deleteProgram(program);
|
28006 | delete this.gl;
|
28007 | delete this.canvas2;
|
28008 | };
|
28009 |
|
28010 | renderable.prototype.createBuffer = function createBuffer() {
|
28011 | var gl = this.gl;
|
28012 |
|
28013 | var buffer = gl.createBuffer();
|
28014 | if (!buffer) {
|
28015 | throw new Error('Failed to create the buffer object');
|
28016 | }
|
28017 | if (!this._buffers) {
|
28018 | this._buffers = [];
|
28019 | }
|
28020 | this._buffers.push(buffer);
|
28021 | return buffer;
|
28022 | };
|
28023 |
|
28024 | renderable.prototype.enableVertexAttrib = function enableVertexAttrib$$1(attributes) {
|
28025 | enableVertexAttrib(this.gl, this.gl.program, attributes);
|
28026 | };
|
28027 |
|
28028 | renderable.prototype.createProgram = function createProgram$$1(vert, frag, uniforms) {
|
28029 | var gl = this.gl;
|
28030 |
|
28031 | var _createProgram2 = createProgram(gl, vert, frag),
|
28032 | program = _createProgram2.program,
|
28033 | vertexShader = _createProgram2.vertexShader,
|
28034 | fragmentShader = _createProgram2.fragmentShader;
|
28035 |
|
28036 | program.vertexShader = vertexShader;
|
28037 | program.fragmentShader = fragmentShader;
|
28038 |
|
28039 | this._initUniforms(program, uniforms);
|
28040 | return program;
|
28041 | };
|
28042 |
|
28043 | renderable.prototype.useProgram = function useProgram(program) {
|
28044 | var gl = this.gl;
|
28045 | gl.useProgram(program);
|
28046 | gl.program = program;
|
28047 | return this;
|
28048 | };
|
28049 |
|
28050 | renderable.prototype.enableSampler = function enableSampler(sampler, texIdx) {
|
28051 | var gl = this.gl;
|
28052 | var uSampler = this._getUniform(gl.program, sampler);
|
28053 | if (!texIdx) {
|
28054 | texIdx = 0;
|
28055 | }
|
28056 |
|
28057 | gl.uniform1i(uSampler, texIdx);
|
28058 | return uSampler;
|
28059 | };
|
28060 |
|
28061 | renderable.prototype._initUniforms = function _initUniforms(program, uniforms) {
|
28062 | for (var i = 0; i < uniforms.length; i++) {
|
28063 | var name = uniforms[i];
|
28064 | var uniform = uniforms[i];
|
28065 | var b = name.indexOf('[');
|
28066 | if (b >= 0) {
|
28067 | name = name.substring(0, b);
|
28068 | if (!IS_NODE) {
|
28069 | uniform = uniform.substring(0, b);
|
28070 | }
|
28071 | }
|
28072 | program[name] = this._getUniform(program, uniform);
|
28073 | }
|
28074 | };
|
28075 |
|
28076 | renderable.prototype._getUniform = function _getUniform(program, uniformName) {
|
28077 | var gl = this.gl;
|
28078 | var uniform = gl.getUniformLocation(program, uniformName);
|
28079 | if (!uniform) {
|
28080 | throw new Error('Failed to get the storage location of ' + uniformName);
|
28081 | }
|
28082 | return uniform;
|
28083 | };
|
28084 |
|
28085 | return renderable;
|
28086 | }(Base);
|
28087 |
|
28088 | extend(renderable.prototype, {
|
28089 | set12: function () {
|
28090 | var out = Browser$1.ie9 ? null : new Float32Array(12);
|
28091 | return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) {
|
28092 | out[0] = a0;
|
28093 | out[1] = a1;
|
28094 | out[2] = a2;
|
28095 | out[3] = a3;
|
28096 | out[4] = a4;
|
28097 | out[5] = a5;
|
28098 | out[6] = a6;
|
28099 | out[7] = a7;
|
28100 | out[8] = a8;
|
28101 | out[9] = a9;
|
28102 | out[10] = a10;
|
28103 | out[11] = a11;
|
28104 | return out;
|
28105 | };
|
28106 | }()
|
28107 | });
|
28108 |
|
28109 | return renderable;
|
28110 | };
|
28111 |
|
28112 | var options$32 = {
|
28113 | renderer: Browser$1.webgl ? 'gl' : 'canvas',
|
28114 | crossOrigin: null
|
28115 | };
|
28116 |
|
28117 | var ImageLayer = function (_Layer) {
|
28118 | inherits(ImageLayer, _Layer);
|
28119 |
|
28120 | function ImageLayer(id, images, options) {
|
28121 | classCallCheck(this, ImageLayer);
|
28122 |
|
28123 | if (!Array.isArray(images) && !images.url) {
|
28124 | options = images;
|
28125 | images = null;
|
28126 | }
|
28127 |
|
28128 | var _this = possibleConstructorReturn(this, _Layer.call(this, id, options));
|
28129 |
|
28130 | _this._prepareImages(images);
|
28131 | return _this;
|
28132 | }
|
28133 |
|
28134 | ImageLayer.prototype.setImages = function setImages(images) {
|
28135 | this._images = images;
|
28136 | this._prepareImages(images);
|
28137 | return this;
|
28138 | };
|
28139 |
|
28140 | ImageLayer.prototype.getImages = function getImages() {
|
28141 | return this._images;
|
28142 | };
|
28143 |
|
28144 | ImageLayer.prototype._prepareImages = function _prepareImages(images) {
|
28145 | images = images || [];
|
28146 | if (!Array.isArray(images)) {
|
28147 | images = [images];
|
28148 | }
|
28149 | this._imageData = images.map(function (img) {
|
28150 | return extend({}, img, {
|
28151 | extent: new Extent(img.extent)
|
28152 | });
|
28153 | });
|
28154 | this._images = images;
|
28155 | var renderer = this.getRenderer();
|
28156 | if (renderer) {
|
28157 | renderer.refreshImages();
|
28158 | }
|
28159 | };
|
28160 |
|
28161 | return ImageLayer;
|
28162 | }(Layer);
|
28163 |
|
28164 | ImageLayer.mergeOptions(options$32);
|
28165 |
|
28166 | var EMPTY_ARRAY = [];
|
28167 |
|
28168 | var ImageLayerCanvasRenderer = function (_CanvasRenderer) {
|
28169 | inherits(ImageLayerCanvasRenderer, _CanvasRenderer);
|
28170 |
|
28171 | function ImageLayerCanvasRenderer() {
|
28172 | classCallCheck(this, ImageLayerCanvasRenderer);
|
28173 | return possibleConstructorReturn(this, _CanvasRenderer.apply(this, arguments));
|
28174 | }
|
28175 |
|
28176 | ImageLayerCanvasRenderer.prototype.isDrawable = function isDrawable() {
|
28177 | if (this.getMap().getPitch()) {
|
28178 | if (console) {
|
28179 | console.warn('ImageLayer with canvas renderer can\'t be pitched, use gl renderer (\'renderer\' : \'gl\') instead.');
|
28180 | }
|
28181 | return false;
|
28182 | }
|
28183 | return true;
|
28184 | };
|
28185 |
|
28186 | ImageLayerCanvasRenderer.prototype.checkResources = function checkResources() {
|
28187 | var _this3 = this;
|
28188 |
|
28189 | if (this._imageLoaded) {
|
28190 | return EMPTY_ARRAY;
|
28191 | }
|
28192 | var layer = this.layer;
|
28193 | var urls = layer._imageData.map(function (img) {
|
28194 | return [img.url, null, null];
|
28195 | });
|
28196 | if (this.resources) {
|
28197 | var unloaded = [];
|
28198 | var resources = new ResourceCache();
|
28199 | urls.forEach(function (url) {
|
28200 | if (_this3.resources.isResourceLoaded(url)) {
|
28201 | var img = _this3.resources.getImage(url);
|
28202 | resources.addResource(url, img);
|
28203 | } else {
|
28204 | unloaded.push(url);
|
28205 | }
|
28206 | });
|
28207 | this.resources.forEach(function (url, res) {
|
28208 | if (!resources.isResourceLoaded(url)) {
|
28209 | _this3.retireImage(res.image);
|
28210 | }
|
28211 | });
|
28212 | this.resources = resources;
|
28213 | urls = unloaded;
|
28214 | }
|
28215 | this._imageLoaded = true;
|
28216 | return urls;
|
28217 | };
|
28218 |
|
28219 | ImageLayerCanvasRenderer.prototype.retireImage = function retireImage() {};
|
28220 |
|
28221 | ImageLayerCanvasRenderer.prototype.refreshImages = function refreshImages() {
|
28222 | this._imageLoaded = false;
|
28223 | this.setToRedraw();
|
28224 | };
|
28225 |
|
28226 | ImageLayerCanvasRenderer.prototype.needToRedraw = function needToRedraw() {
|
28227 | var map = this.getMap();
|
28228 |
|
28229 | if (map.isZooming() && !map.getPitch()) {
|
28230 | return false;
|
28231 | }
|
28232 | return _CanvasRenderer.prototype.needToRedraw.call(this);
|
28233 | };
|
28234 |
|
28235 | ImageLayerCanvasRenderer.prototype.draw = function draw() {
|
28236 | if (!this.isDrawable()) {
|
28237 | return;
|
28238 | }
|
28239 | this.prepareCanvas();
|
28240 | this._painted = false;
|
28241 | this._drawImages();
|
28242 | this.completeRender();
|
28243 | };
|
28244 |
|
28245 | ImageLayerCanvasRenderer.prototype._drawImages = function _drawImages() {
|
28246 | var imgData = this.layer._imageData;
|
28247 | var map = this.getMap();
|
28248 | var mapExtent = map.getExtent();
|
28249 | if (imgData && imgData.length) {
|
28250 | for (var i = 0; i < imgData.length; i++) {
|
28251 | var extent = imgData[i].extent;
|
28252 | var image = this.resources && this.resources.getImage(imgData[i].url);
|
28253 | if (image && mapExtent.intersects(extent)) {
|
28254 | this._painted = true;
|
28255 | this._drawImage(image, extent, imgData[i].opacity || 1);
|
28256 | }
|
28257 | }
|
28258 | }
|
28259 | };
|
28260 |
|
28261 | ImageLayerCanvasRenderer.prototype._drawImage = function _drawImage(image, extent, opacity) {
|
28262 | var globalAlpha = 0;
|
28263 | var ctx = this.context;
|
28264 | if (opacity < 1) {
|
28265 | globalAlpha = ctx.globalAlpha;
|
28266 | ctx.globalAlpha = opacity;
|
28267 | }
|
28268 | var map = this.getMap();
|
28269 | var min = map.coordToPoint(extent.getMin()),
|
28270 | max = map.coordToPoint(extent.getMax());
|
28271 | var point = map._pointToContainerPoint(min);
|
28272 | var x = point.x,
|
28273 | y = point.y;
|
28274 | var bearing = map.getBearing();
|
28275 | if (bearing) {
|
28276 | ctx.save();
|
28277 | ctx.translate(x, y);
|
28278 | if (bearing) {
|
28279 | ctx.rotate(-bearing * Math.PI / 180);
|
28280 | }
|
28281 | x = y = 0;
|
28282 | }
|
28283 | ctx.drawImage(image, x, y, max.x - min.x, max.y - min.y);
|
28284 | if (bearing) {
|
28285 | ctx.restore();
|
28286 | }
|
28287 | if (globalAlpha) {
|
28288 | ctx.globalAlpha = globalAlpha;
|
28289 | }
|
28290 | };
|
28291 |
|
28292 | ImageLayerCanvasRenderer.prototype.drawOnInteracting = function drawOnInteracting() {
|
28293 | this.draw();
|
28294 | };
|
28295 |
|
28296 | return ImageLayerCanvasRenderer;
|
28297 | }(CanvasRenderer);
|
28298 |
|
28299 | var ImageLayerGLRenderer = function (_ImageGLRenderable) {
|
28300 | inherits(ImageLayerGLRenderer, _ImageGLRenderable);
|
28301 |
|
28302 | function ImageLayerGLRenderer() {
|
28303 | classCallCheck(this, ImageLayerGLRenderer);
|
28304 | return possibleConstructorReturn(this, _ImageGLRenderable.apply(this, arguments));
|
28305 | }
|
28306 |
|
28307 | ImageLayerGLRenderer.prototype.isDrawable = function isDrawable() {
|
28308 | return true;
|
28309 | };
|
28310 |
|
28311 | ImageLayerGLRenderer.prototype._drawImage = function _drawImage(image, extent, opacity) {
|
28312 | var map = this.getMap();
|
28313 | var extent2d = extent.__imagelayerposition;
|
28314 | if (!extent2d) {
|
28315 | extent2d = extent.__imagelayerposition = extent.convertTo(function (c) {
|
28316 | return map.coordToPoint(c, map.getGLZoom());
|
28317 | });
|
28318 | }
|
28319 | this.drawGLImage(image, extent2d.xmin, extent2d.ymin, extent2d.getWidth(), extent2d.getHeight(), opacity);
|
28320 | };
|
28321 |
|
28322 | ImageLayerGLRenderer.prototype.createContext = function createContext() {
|
28323 | this.createGLContext();
|
28324 | };
|
28325 |
|
28326 | ImageLayerGLRenderer.prototype.resizeCanvas = function resizeCanvas(canvasSize) {
|
28327 | if (!this.canvas) {
|
28328 | return;
|
28329 | }
|
28330 | _ImageGLRenderable.prototype.resizeCanvas.call(this, canvasSize);
|
28331 | this.resizeGLCanvas();
|
28332 | };
|
28333 |
|
28334 | ImageLayerGLRenderer.prototype.clearCanvas = function clearCanvas() {
|
28335 | if (!this.canvas) {
|
28336 | return;
|
28337 | }
|
28338 | _ImageGLRenderable.prototype.clearCanvas.call(this);
|
28339 | this.clearGLCanvas();
|
28340 | };
|
28341 |
|
28342 | ImageLayerGLRenderer.prototype.retireImage = function retireImage(image) {
|
28343 | this.disposeImage(image);
|
28344 | };
|
28345 |
|
28346 | ImageLayerGLRenderer.prototype.onRemove = function onRemove() {
|
28347 | this.removeGLCanvas();
|
28348 | _ImageGLRenderable.prototype.onRemove.call(this);
|
28349 | };
|
28350 |
|
28351 | return ImageLayerGLRenderer;
|
28352 | }(ImageGLRenderable(ImageLayerCanvasRenderer));
|
28353 |
|
28354 | ImageLayer.registerRenderer('canvas', ImageLayerCanvasRenderer);
|
28355 | ImageLayer.registerRenderer('gl', ImageLayerGLRenderer);
|
28356 |
|
28357 | var CanvasLayerRenderer = function (_CanvasRenderer) {
|
28358 | inherits(CanvasLayerRenderer, _CanvasRenderer);
|
28359 |
|
28360 | function CanvasLayerRenderer() {
|
28361 | classCallCheck(this, CanvasLayerRenderer);
|
28362 | return possibleConstructorReturn(this, _CanvasRenderer.apply(this, arguments));
|
28363 | }
|
28364 |
|
28365 | CanvasLayerRenderer.prototype.getPrepareParams = function getPrepareParams() {
|
28366 | return [];
|
28367 | };
|
28368 |
|
28369 | CanvasLayerRenderer.prototype.getDrawParams = function getDrawParams() {
|
28370 | return [];
|
28371 | };
|
28372 |
|
28373 | CanvasLayerRenderer.prototype.onCanvasCreate = function onCanvasCreate() {
|
28374 | if (this.canvas && this.layer.options['doubleBuffer']) {
|
28375 | this.buffer = Canvas.createCanvas(this.canvas.width, this.canvas.height, this.getMap().CanvasClass);
|
28376 | }
|
28377 | };
|
28378 |
|
28379 | CanvasLayerRenderer.prototype.needToRedraw = function needToRedraw() {
|
28380 | if (this.layer.options['animation']) {
|
28381 | return true;
|
28382 | }
|
28383 | var map = this.getMap();
|
28384 | if (map.isInteracting() && !this.layer.drawOnInteracting) {
|
28385 | return false;
|
28386 | }
|
28387 | return _CanvasRenderer.prototype.needToRedraw.call(this);
|
28388 | };
|
28389 |
|
28390 | CanvasLayerRenderer.prototype.draw = function draw() {
|
28391 | this.prepareCanvas();
|
28392 | this.prepareDrawContext();
|
28393 | this._drawLayer();
|
28394 | };
|
28395 |
|
28396 | CanvasLayerRenderer.prototype.drawOnInteracting = function drawOnInteracting() {
|
28397 | this._drawLayerOnInteracting();
|
28398 | };
|
28399 |
|
28400 | CanvasLayerRenderer.prototype.getCanvasImage = function getCanvasImage() {
|
28401 | var canvasImg = _CanvasRenderer.prototype.getCanvasImage.call(this);
|
28402 | if (canvasImg && canvasImg.image && this.layer.options['doubleBuffer']) {
|
28403 | var canvas = canvasImg.image;
|
28404 | if (this.buffer.width !== canvas.width || this.buffer.height !== canvas.height) {
|
28405 | this.buffer.width = canvas.width;
|
28406 | this.buffer.height = canvas.height;
|
28407 | }
|
28408 | var bufferContext = this.buffer.getContext('2d');
|
28409 | var prevent = this.layer.doubleBuffer(bufferContext, this.context);
|
28410 | if (prevent === undefined || prevent) {
|
28411 | Canvas.image(bufferContext, canvas, 0, 0);
|
28412 | canvasImg.image = this.buffer;
|
28413 | }
|
28414 | }
|
28415 | return canvasImg;
|
28416 | };
|
28417 |
|
28418 | CanvasLayerRenderer.prototype.remove = function remove() {
|
28419 | delete this._drawContext;
|
28420 | return _CanvasRenderer.prototype.remove.call(this);
|
28421 | };
|
28422 |
|
28423 | CanvasLayerRenderer.prototype.onZoomStart = function onZoomStart(param) {
|
28424 | this.layer.onZoomStart(param);
|
28425 | _CanvasRenderer.prototype.onZoomStart.call(this, param);
|
28426 | };
|
28427 |
|
28428 | CanvasLayerRenderer.prototype.onZooming = function onZooming(param) {
|
28429 | this.layer.onZooming(param);
|
28430 | _CanvasRenderer.prototype.onZooming.call(this, param);
|
28431 | };
|
28432 |
|
28433 | CanvasLayerRenderer.prototype.onZoomEnd = function onZoomEnd(param) {
|
28434 | this.layer.onZoomEnd(param);
|
28435 | _CanvasRenderer.prototype.onZoomEnd.call(this, param);
|
28436 | };
|
28437 |
|
28438 | CanvasLayerRenderer.prototype.onMoveStart = function onMoveStart(param) {
|
28439 | this.layer.onMoveStart(param);
|
28440 | _CanvasRenderer.prototype.onMoveStart.call(this, param);
|
28441 | };
|
28442 |
|
28443 | CanvasLayerRenderer.prototype.onMoving = function onMoving(param) {
|
28444 | this.layer.onMoving(param);
|
28445 | _CanvasRenderer.prototype.onMoving.call(this, param);
|
28446 | };
|
28447 |
|
28448 | CanvasLayerRenderer.prototype.onMoveEnd = function onMoveEnd(param) {
|
28449 | this.layer.onMoveEnd(param);
|
28450 | _CanvasRenderer.prototype.onMoveEnd.call(this, param);
|
28451 | };
|
28452 |
|
28453 | CanvasLayerRenderer.prototype.onResize = function onResize(param) {
|
28454 | this.layer.onResize(param);
|
28455 | _CanvasRenderer.prototype.onResize.call(this, param);
|
28456 | };
|
28457 |
|
28458 | CanvasLayerRenderer.prototype.prepareDrawContext = function prepareDrawContext() {
|
28459 | if (!this._predrawed) {
|
28460 | var params = ensureParams(this.getPrepareParams());
|
28461 | this._drawContext = this.layer.prepareToDraw.apply(this.layer, [this.context].concat(params));
|
28462 | if (!this._drawContext) {
|
28463 | this._drawContext = [];
|
28464 | }
|
28465 | if (!Array.isArray(this._drawContext)) {
|
28466 | this._drawContext = [this._drawContext];
|
28467 | }
|
28468 | this._predrawed = true;
|
28469 | }
|
28470 | };
|
28471 |
|
28472 | CanvasLayerRenderer.prototype._prepareDrawParams = function _prepareDrawParams() {
|
28473 | if (!this.getMap()) {
|
28474 | return null;
|
28475 | }
|
28476 | var view = this.getViewExtent();
|
28477 | if (view['maskExtent'] && !view['extent'].intersects(view['maskExtent'])) {
|
28478 | this.completeRender();
|
28479 | return null;
|
28480 | }
|
28481 | var args = [this.context, view];
|
28482 | var params = ensureParams(this.getDrawParams());
|
28483 | args.push.apply(args, params);
|
28484 | args.push.apply(args, this._drawContext);
|
28485 | return args;
|
28486 | };
|
28487 |
|
28488 | CanvasLayerRenderer.prototype._drawLayer = function _drawLayer() {
|
28489 | var args = this._prepareDrawParams();
|
28490 | if (!args) {
|
28491 | return;
|
28492 | }
|
28493 | this.layer.draw.apply(this.layer, args);
|
28494 | this.completeRender();
|
28495 | };
|
28496 |
|
28497 | CanvasLayerRenderer.prototype._drawLayerOnInteracting = function _drawLayerOnInteracting() {
|
28498 | if (!this.layer.drawOnInteracting) {
|
28499 | return;
|
28500 | }
|
28501 | var args = this._prepareDrawParams();
|
28502 | if (!args) {
|
28503 | return;
|
28504 | }
|
28505 | this.layer.drawOnInteracting.apply(this.layer, args);
|
28506 | this.completeRender();
|
28507 | };
|
28508 |
|
28509 | return CanvasLayerRenderer;
|
28510 | }(CanvasRenderer);
|
28511 |
|
28512 | function ensureParams(params) {
|
28513 | if (!params) {
|
28514 | params = [];
|
28515 | }
|
28516 | if (!Array.isArray(params)) {
|
28517 | params = [params];
|
28518 | }
|
28519 | return params;
|
28520 | }
|
28521 |
|
28522 | var options$33 = {
|
28523 | 'doubleBuffer': false,
|
28524 | 'animation': false
|
28525 | };
|
28526 |
|
28527 | var CanvasLayer = function (_Layer) {
|
28528 | inherits(CanvasLayer, _Layer);
|
28529 |
|
28530 | function CanvasLayer() {
|
28531 | classCallCheck(this, CanvasLayer);
|
28532 | return possibleConstructorReturn(this, _Layer.apply(this, arguments));
|
28533 | }
|
28534 |
|
28535 | CanvasLayer.prototype.isCanvasRender = function isCanvasRender() {
|
28536 | return true;
|
28537 | };
|
28538 |
|
28539 | CanvasLayer.prototype.prepareToDraw = function prepareToDraw() {};
|
28540 |
|
28541 | CanvasLayer.prototype.draw = function draw() {};
|
28542 |
|
28543 | CanvasLayer.prototype.redraw = function redraw() {
|
28544 | if (this._getRenderer()) {
|
28545 | this._getRenderer().setToRedraw();
|
28546 | }
|
28547 | return this;
|
28548 | };
|
28549 |
|
28550 | CanvasLayer.prototype.play = function play() {
|
28551 | this.config('animation', true);
|
28552 | return this;
|
28553 | };
|
28554 |
|
28555 | CanvasLayer.prototype.pause = function pause() {
|
28556 | this.config('animation', false);
|
28557 | return this;
|
28558 | };
|
28559 |
|
28560 | CanvasLayer.prototype.isPlaying = function isPlaying() {
|
28561 | return this.options['animation'];
|
28562 | };
|
28563 |
|
28564 | CanvasLayer.prototype.clearCanvas = function clearCanvas() {
|
28565 | if (this._getRenderer()) {
|
28566 | this._getRenderer().clearCanvas();
|
28567 | }
|
28568 | return this;
|
28569 | };
|
28570 |
|
28571 | CanvasLayer.prototype.requestMapToRender = function requestMapToRender() {
|
28572 | if (this._getRenderer()) {
|
28573 | this._getRenderer().requestMapToRender();
|
28574 | }
|
28575 | return this;
|
28576 | };
|
28577 |
|
28578 | CanvasLayer.prototype.completeRender = function completeRender() {
|
28579 | if (this._getRenderer()) {
|
28580 | this._getRenderer().completeRender();
|
28581 | }
|
28582 | return this;
|
28583 | };
|
28584 |
|
28585 | CanvasLayer.prototype.onCanvasCreate = function onCanvasCreate() {
|
28586 | return this;
|
28587 | };
|
28588 |
|
28589 | CanvasLayer.prototype.onZoomStart = function onZoomStart() {};
|
28590 |
|
28591 | CanvasLayer.prototype.onZooming = function onZooming() {};
|
28592 |
|
28593 | CanvasLayer.prototype.onZoomEnd = function onZoomEnd() {};
|
28594 |
|
28595 | CanvasLayer.prototype.onMoveStart = function onMoveStart() {};
|
28596 |
|
28597 | CanvasLayer.prototype.onMoving = function onMoving() {};
|
28598 |
|
28599 | CanvasLayer.prototype.onMoveEnd = function onMoveEnd() {};
|
28600 |
|
28601 | CanvasLayer.prototype.onResize = function onResize() {};
|
28602 |
|
28603 | CanvasLayer.prototype.doubleBuffer = function doubleBuffer(bufferContext) {
|
28604 | bufferContext.clearRect(0, 0, bufferContext.canvas.width, bufferContext.canvas.height);
|
28605 | return this;
|
28606 | };
|
28607 |
|
28608 | return CanvasLayer;
|
28609 | }(Layer);
|
28610 |
|
28611 | CanvasLayer.mergeOptions(options$33);
|
28612 |
|
28613 | CanvasLayer.registerRenderer('canvas', CanvasLayerRenderer);
|
28614 |
|
28615 | var options$34 = {
|
28616 | 'animation': true
|
28617 | };
|
28618 |
|
28619 | var ParticleLayer = function (_CanvasLayer) {
|
28620 | inherits(ParticleLayer, _CanvasLayer);
|
28621 |
|
28622 | function ParticleLayer() {
|
28623 | classCallCheck(this, ParticleLayer);
|
28624 | return possibleConstructorReturn(this, _CanvasLayer.apply(this, arguments));
|
28625 | }
|
28626 |
|
28627 | ParticleLayer.prototype.getParticles = function getParticles() {};
|
28628 |
|
28629 | ParticleLayer.prototype.draw = function draw(context, view) {
|
28630 | var points = this.getParticles(now());
|
28631 | if (!points || points.length === 0) {
|
28632 | var renderer = this._getRenderer();
|
28633 | if (renderer) {
|
28634 | this._getRenderer()._shouldClear = true;
|
28635 | }
|
28636 | return;
|
28637 | }
|
28638 | var map = this.getMap();
|
28639 | var extent = view.extent;
|
28640 | if (view.maskExtent) {
|
28641 | extent = view.extent.intersection(view.maskExtent);
|
28642 | }
|
28643 | extent = extent.convertTo(function (c) {
|
28644 | return map._pointToContainerPoint(c);
|
28645 | });
|
28646 | var e = 2 * Math.PI;
|
28647 | for (var i = 0, l = points.length; i < l; i++) {
|
28648 | var pos = points[i].point;
|
28649 | if (extent.contains(pos)) {
|
28650 | var color = points[i].color || this.options['lineColor'] || '#fff',
|
28651 | r = points[i].r;
|
28652 | if (context.fillStyle !== color) {
|
28653 | context.fillStyle = color;
|
28654 | }
|
28655 | if (r <= 2) {
|
28656 | context.fillRect(pos.x - r / 2, pos.y - r / 2, r, r);
|
28657 | } else {
|
28658 | context.beginPath();
|
28659 | context.arc(pos.x, pos.y, r / 2, 0, e);
|
28660 | context.fill();
|
28661 | }
|
28662 | }
|
28663 | }
|
28664 | this._fillCanvas(context);
|
28665 | };
|
28666 |
|
28667 | ParticleLayer.prototype._fillCanvas = function _fillCanvas(context) {
|
28668 | var g = context.globalCompositeOperation;
|
28669 | context.globalCompositeOperation = 'destination-out';
|
28670 | var trail = this.options['trail'] || 30;
|
28671 | context.fillStyle = 'rgba(0, 0, 0, ' + 1 / trail + ')';
|
28672 | context.fillRect(0, 0, context.canvas.width, context.canvas.height);
|
28673 | context.globalCompositeOperation = g;
|
28674 | };
|
28675 |
|
28676 | return ParticleLayer;
|
28677 | }(CanvasLayer);
|
28678 |
|
28679 | ParticleLayer.mergeOptions(options$34);
|
28680 |
|
28681 | ParticleLayer.registerRenderer('canvas', function (_CanvasLayerRenderer) {
|
28682 | inherits(_class, _CanvasLayerRenderer);
|
28683 |
|
28684 | function _class() {
|
28685 | classCallCheck(this, _class);
|
28686 | return possibleConstructorReturn(this, _CanvasLayerRenderer.apply(this, arguments));
|
28687 | }
|
28688 |
|
28689 | _class.prototype.draw = function draw() {
|
28690 | if (!this.canvas || !this.layer.options['animation'] || this._shouldClear) {
|
28691 | this.prepareCanvas();
|
28692 | this._shouldClear = false;
|
28693 | }
|
28694 | this.prepareDrawContext();
|
28695 | this._drawLayer();
|
28696 | };
|
28697 |
|
28698 | _class.prototype.drawOnInteracting = function drawOnInteracting() {
|
28699 | this.draw();
|
28700 | this._shouldClear = false;
|
28701 | };
|
28702 |
|
28703 | _class.prototype.onSkipDrawOnInteracting = function onSkipDrawOnInteracting() {
|
28704 | this._shouldClear = true;
|
28705 | };
|
28706 |
|
28707 | return _class;
|
28708 | }(CanvasLayerRenderer));
|
28709 |
|
28710 | var EDIT_STAGE_LAYER_PREFIX = INTERNAL_LAYER_PREFIX + '_edit_stage_';
|
28711 |
|
28712 | function createHandleSymbol(markerType, opacity) {
|
28713 | return {
|
28714 | 'markerType': markerType,
|
28715 | 'markerFill': '#fff',
|
28716 | 'markerLineColor': '#000',
|
28717 | 'markerLineWidth': 2,
|
28718 | 'markerWidth': 10,
|
28719 | 'markerHeight': 10,
|
28720 | 'opacity': opacity
|
28721 | };
|
28722 | }
|
28723 |
|
28724 | var options$35 = {
|
28725 | 'fixAspectRatio': false,
|
28726 |
|
28727 | 'symbol': null,
|
28728 | 'removeVertexOn': 'contextmenu',
|
28729 |
|
28730 | 'centerHandleSymbol': createHandleSymbol('ellipse', 1),
|
28731 | 'vertexHandleSymbol': createHandleSymbol('square', 1),
|
28732 | 'newVertexHandleSymbol': createHandleSymbol('square', 0.4)
|
28733 | };
|
28734 |
|
28735 | var GeometryEditor = function (_Eventable) {
|
28736 | inherits(GeometryEditor, _Eventable);
|
28737 |
|
28738 | function GeometryEditor(geometry, opts) {
|
28739 | classCallCheck(this, GeometryEditor);
|
28740 |
|
28741 | var _this = possibleConstructorReturn(this, _Eventable.call(this, opts));
|
28742 |
|
28743 | _this._geometry = geometry;
|
28744 | if (!_this._geometry) {
|
28745 | return possibleConstructorReturn(_this);
|
28746 | }
|
28747 | return _this;
|
28748 | }
|
28749 |
|
28750 | GeometryEditor.prototype.getMap = function getMap() {
|
28751 | return this._geometry.getMap();
|
28752 | };
|
28753 |
|
28754 | GeometryEditor.prototype.prepare = function prepare() {
|
28755 | var map = this.getMap();
|
28756 | if (!map) {
|
28757 | return;
|
28758 | }
|
28759 |
|
28760 | if (this.options['symbol']) {
|
28761 | this._originalSymbol = this._geometry.getSymbol();
|
28762 | this._geometry.setSymbol(this.options['symbol']);
|
28763 | }
|
28764 |
|
28765 | this._prepareEditStageLayer();
|
28766 | };
|
28767 |
|
28768 | GeometryEditor.prototype._prepareEditStageLayer = function _prepareEditStageLayer() {
|
28769 | var map = this.getMap();
|
28770 | var uid = UID();
|
28771 | var stageId = EDIT_STAGE_LAYER_PREFIX + uid,
|
28772 | shadowId = EDIT_STAGE_LAYER_PREFIX + uid + '_shadow';
|
28773 | this._editStageLayer = map.getLayer(stageId);
|
28774 | this._shadowLayer = map.getLayer(shadowId);
|
28775 | if (!this._editStageLayer) {
|
28776 | this._editStageLayer = new VectorLayer(stageId);
|
28777 | map.addLayer(this._editStageLayer);
|
28778 | }
|
28779 | if (!this._shadowLayer) {
|
28780 | this._shadowLayer = new VectorLayer(shadowId);
|
28781 | map.addLayer(this._shadowLayer);
|
28782 | }
|
28783 | };
|
28784 |
|
28785 | GeometryEditor.prototype.start = function start() {
|
28786 | var _this2 = this;
|
28787 |
|
28788 | if (!this._geometry || !this._geometry.getMap() || this._geometry.editing) {
|
28789 | return;
|
28790 | }
|
28791 | var map = this.getMap();
|
28792 | this.editing = true;
|
28793 | var geometry = this._geometry;
|
28794 | this._geometryDraggble = geometry.options['draggable'];
|
28795 | geometry.config('draggable', false);
|
28796 | this.prepare();
|
28797 |
|
28798 | var shadow = geometry.copy();
|
28799 | shadow.setSymbol(geometry._getInternalSymbol());
|
28800 |
|
28801 | shadow.copyEventListeners(geometry);
|
28802 | if (geometry._getParent()) {
|
28803 | shadow.copyEventListeners(geometry._getParent());
|
28804 | }
|
28805 |
|
28806 | shadow.setId(null).config({
|
28807 | 'draggable': false
|
28808 | });
|
28809 |
|
28810 | this._shadow = shadow;
|
28811 |
|
28812 | this._switchGeometryEvents('on');
|
28813 |
|
28814 | geometry.hide();
|
28815 | if (geometry instanceof Marker || geometry instanceof Circle || geometry instanceof Rectangle || geometry instanceof Ellipse) {
|
28816 | this._createOrRefreshOutline();
|
28817 | }
|
28818 | this._shadowLayer.bringToFront().addGeometry(shadow);
|
28819 | this._editStageLayer.bringToFront();
|
28820 | this._addListener([map, 'zoomstart', function () {
|
28821 | _this2._editStageLayer.hide();
|
28822 | }]);
|
28823 | this._addListener([map, 'zoomend', function () {
|
28824 | _this2._editStageLayer.show();
|
28825 | }]);
|
28826 | if (!(geometry instanceof Marker)) {
|
28827 | this._createCenterHandle();
|
28828 | } else {
|
28829 | shadow.config('draggable', true);
|
28830 | shadow.on('dragend', this._onMarkerDragEnd, this);
|
28831 | }
|
28832 | if (geometry instanceof Marker) {
|
28833 | this.createMarkerEditor();
|
28834 | } else if (geometry instanceof Circle) {
|
28835 | this.createCircleEditor();
|
28836 | } else if (geometry instanceof Rectangle) {
|
28837 | this.createEllipseOrRectEditor();
|
28838 | } else if (geometry instanceof Ellipse) {
|
28839 | this.createEllipseOrRectEditor();
|
28840 | } else if (geometry instanceof Sector) {} else if (geometry instanceof Polygon || geometry instanceof LineString) {
|
28841 | this.createPolygonEditor();
|
28842 | }
|
28843 | };
|
28844 |
|
28845 | GeometryEditor.prototype.stop = function stop() {
|
28846 | delete this._history;
|
28847 | delete this._historyPointer;
|
28848 | delete this._editOutline;
|
28849 | this._switchGeometryEvents('off');
|
28850 | var map = this.getMap();
|
28851 | if (!map) {
|
28852 | return;
|
28853 | }
|
28854 | delete this._shadow;
|
28855 | this._geometry.config('draggable', this._geometryDraggble);
|
28856 | delete this._geometryDraggble;
|
28857 | this._geometry.show();
|
28858 |
|
28859 | this._editStageLayer.remove();
|
28860 | this._shadowLayer.remove();
|
28861 | this._clearAllListeners();
|
28862 | this._refreshHooks = [];
|
28863 | if (this.options['symbol']) {
|
28864 | this._geometry.setSymbol(this._originalSymbol);
|
28865 | delete this._originalSymbol;
|
28866 | }
|
28867 | this.editing = false;
|
28868 | };
|
28869 |
|
28870 | GeometryEditor.prototype.isEditing = function isEditing() {
|
28871 | if (isNil(this.editing)) {
|
28872 | return false;
|
28873 | }
|
28874 | return this.editing;
|
28875 | };
|
28876 |
|
28877 | GeometryEditor.prototype._getGeometryEvents = function _getGeometryEvents() {
|
28878 | return {
|
28879 | 'symbolchange': this._onGeoSymbolChange,
|
28880 | 'positionchange shapechange': this._exeAndReset
|
28881 | };
|
28882 | };
|
28883 |
|
28884 | GeometryEditor.prototype._switchGeometryEvents = function _switchGeometryEvents(oper) {
|
28885 | if (this._geometry) {
|
28886 | var events = this._getGeometryEvents();
|
28887 | for (var p in events) {
|
28888 | this._geometry[oper](p, events[p], this);
|
28889 | }
|
28890 | }
|
28891 | };
|
28892 |
|
28893 | GeometryEditor.prototype._onGeoSymbolChange = function _onGeoSymbolChange(param) {
|
28894 | if (this._shadow) {
|
28895 | this._shadow.setSymbol(param.target._getInternalSymbol());
|
28896 | }
|
28897 | };
|
28898 |
|
28899 | GeometryEditor.prototype._onMarkerDragEnd = function _onMarkerDragEnd() {
|
28900 | this._update('setCoordinates', this._shadow.getCoordinates().toArray());
|
28901 | this._refresh();
|
28902 | };
|
28903 |
|
28904 | GeometryEditor.prototype._createOrRefreshOutline = function _createOrRefreshOutline() {
|
28905 | var geometry = this._geometry;
|
28906 | var outline = this._editOutline;
|
28907 | if (!outline) {
|
28908 | outline = geometry.getOutline();
|
28909 | this._editStageLayer.addGeometry(outline);
|
28910 | this._editOutline = outline;
|
28911 | this._addRefreshHook(this._createOrRefreshOutline);
|
28912 | } else {
|
28913 | outline.remove();
|
28914 | this._editOutline = outline = geometry.getOutline();
|
28915 | this._editStageLayer.addGeometry(outline);
|
28916 | }
|
28917 |
|
28918 | return outline;
|
28919 | };
|
28920 |
|
28921 | GeometryEditor.prototype._createCenterHandle = function _createCenterHandle() {
|
28922 | var _this3 = this;
|
28923 |
|
28924 | var center = this._shadow.getCenter();
|
28925 | var symbol = this.options['centerHandleSymbol'];
|
28926 | var shadow = void 0;
|
28927 | var handle = this.createHandle(center, {
|
28928 | 'symbol': symbol,
|
28929 | 'cursor': 'move',
|
28930 | onDown: function onDown() {
|
28931 | shadow = _this3._shadow.copy();
|
28932 | var symbol = lowerSymbolOpacity(shadow._getInternalSymbol(), 0.5);
|
28933 | shadow.setSymbol(symbol).addTo(_this3._editStageLayer);
|
28934 | },
|
28935 | onMove: function onMove(v, param) {
|
28936 | var offset = param['coordOffset'];
|
28937 | shadow.translate(offset);
|
28938 | },
|
28939 | onUp: function onUp() {
|
28940 | _this3._update('setCoordinates', Coordinate.toNumberArrays(shadow.getCoordinates()));
|
28941 | shadow.remove();
|
28942 | _this3._refresh();
|
28943 | }
|
28944 | });
|
28945 | this._addRefreshHook(function () {
|
28946 | var center = _this3._shadow.getCenter();
|
28947 | handle.setCoordinates(center);
|
28948 | });
|
28949 | };
|
28950 |
|
28951 | GeometryEditor.prototype._createHandleInstance = function _createHandleInstance(coordinate, opts) {
|
28952 | var symbol = opts['symbol'];
|
28953 | var handle = new Marker(coordinate, {
|
28954 | 'draggable': true,
|
28955 | 'dragShadow': false,
|
28956 | 'dragOnAxis': opts['axis'],
|
28957 | 'cursor': opts['cursor'],
|
28958 | 'symbol': symbol
|
28959 | });
|
28960 | return handle;
|
28961 | };
|
28962 |
|
28963 | GeometryEditor.prototype.createHandle = function createHandle(coordinate, opts) {
|
28964 | if (!opts) {
|
28965 | opts = {};
|
28966 | }
|
28967 | var map = this.getMap();
|
28968 | var handle = this._createHandleInstance(coordinate, opts);
|
28969 | var me = this;
|
28970 |
|
28971 | function onHandleDragstart(param) {
|
28972 | if (opts.onDown) {
|
28973 | opts.onDown.call(me, param['viewPoint'], param);
|
28974 | }
|
28975 | return false;
|
28976 | }
|
28977 |
|
28978 | function onHandleDragging(param) {
|
28979 | me._hideContext();
|
28980 | var viewPoint = map._prjToViewPoint(handle._getPrjCoordinates());
|
28981 | if (opts.onMove) {
|
28982 | opts.onMove.call(me, viewPoint, param);
|
28983 | }
|
28984 | return false;
|
28985 | }
|
28986 |
|
28987 | function onHandleDragEnd(ev) {
|
28988 | if (opts.onUp) {
|
28989 | opts.onUp.call(me, ev);
|
28990 | }
|
28991 | return false;
|
28992 | }
|
28993 |
|
28994 | function onHandleRemove() {
|
28995 | handle.config('draggable', false);
|
28996 | handle.off('dragstart', onHandleDragstart, me);
|
28997 | handle.off('dragging', onHandleDragging, me);
|
28998 | handle.off('dragend', onHandleDragEnd, me);
|
28999 | handle.off('removestart', onHandleRemove, me);
|
29000 | delete handle['maptalks--editor-refresh-fn'];
|
29001 | }
|
29002 |
|
29003 | handle.on('dragstart', onHandleDragstart, this);
|
29004 | handle.on('dragging', onHandleDragging, this);
|
29005 | handle.on('dragend', onHandleDragEnd, this);
|
29006 | handle.on('removestart', onHandleRemove, this);
|
29007 |
|
29008 | if (opts.onRefresh) {
|
29009 | handle['maptalks--editor-refresh-fn'] = opts.onRefresh;
|
29010 | }
|
29011 | this._editStageLayer.addGeometry(handle);
|
29012 | return handle;
|
29013 | };
|
29014 |
|
29015 | GeometryEditor.prototype._createResizeHandles = function _createResizeHandles(blackList, onHandleMove, onHandleUp) {
|
29016 | var _this4 = this;
|
29017 |
|
29018 | var cursors = ['nw-resize', 'n-resize', 'ne-resize', 'w-resize', 'e-resize', 'sw-resize', 's-resize', 'se-resize'];
|
29019 |
|
29020 | var axis = [null, 'y', null, 'x', 'x', null, 'y', null];
|
29021 | var geometry = this._geometry;
|
29022 |
|
29023 | function getResizeAnchors(ext) {
|
29024 | return [ext.getMin(), new Point((ext['xmax'] + ext['xmin']) / 2, ext['ymin']), new Point(ext['xmax'], ext['ymin']), new Point(ext['xmin'], (ext['ymax'] + ext['ymin']) / 2), new Point(ext['xmax'], (ext['ymax'] + ext['ymin']) / 2), new Point(ext['xmin'], ext['ymax']), new Point((ext['xmax'] + ext['xmin']) / 2, ext['ymax']), ext.getMax()];
|
29025 | }
|
29026 | if (!blackList) {
|
29027 | blackList = [];
|
29028 | }
|
29029 | var me = this;
|
29030 | var resizeHandles = [],
|
29031 | anchorIndexes = {},
|
29032 | map = this.getMap(),
|
29033 | handleSymbol = this.options['vertexHandleSymbol'];
|
29034 | var fnLocateHandles = function fnLocateHandles() {
|
29035 | var pExt = geometry._getPainter().get2DExtent(),
|
29036 | anchors = getResizeAnchors(pExt);
|
29037 |
|
29038 | var _loop = function _loop(i) {
|
29039 | if (Array.isArray(blackList)) {
|
29040 | var isBlack = blackList.some(function (ele) {
|
29041 | return ele === i;
|
29042 | });
|
29043 | if (isBlack) {
|
29044 | return 'continue';
|
29045 | }
|
29046 | }
|
29047 | var anchor = anchors[i],
|
29048 | coordinate = map.pointToCoordinate(anchor);
|
29049 | if (resizeHandles.length < anchors.length - blackList.length) {
|
29050 | var handle = _this4.createHandle(coordinate, {
|
29051 | 'symbol': handleSymbol,
|
29052 | 'cursor': cursors[i],
|
29053 | 'axis': axis[i],
|
29054 | onMove: function (_index) {
|
29055 | return function (handleViewPoint) {
|
29056 | me._updating = true;
|
29057 | onHandleMove(handleViewPoint, _index);
|
29058 | geometry.fire('resizing');
|
29059 | };
|
29060 | }(i),
|
29061 | onUp: function onUp() {
|
29062 | me._updating = false;
|
29063 | onHandleUp();
|
29064 | _this4._refresh();
|
29065 | }
|
29066 | });
|
29067 | handle.setId(i);
|
29068 | anchorIndexes[i] = resizeHandles.length;
|
29069 | resizeHandles.push(handle);
|
29070 | } else {
|
29071 | resizeHandles[anchorIndexes[i]].setCoordinates(coordinate);
|
29072 | }
|
29073 | };
|
29074 |
|
29075 | for (var i = 0; i < anchors.length; i++) {
|
29076 | var _ret = _loop(i);
|
29077 |
|
29078 | if (_ret === 'continue') continue;
|
29079 | }
|
29080 | };
|
29081 |
|
29082 | fnLocateHandles();
|
29083 |
|
29084 | this._addRefreshHook(fnLocateHandles);
|
29085 | return resizeHandles;
|
29086 | };
|
29087 |
|
29088 | GeometryEditor.prototype.createMarkerEditor = function createMarkerEditor() {
|
29089 | var _this5 = this;
|
29090 |
|
29091 | var geometryToEdit = this._geometry,
|
29092 | shadow = this._shadow,
|
29093 | map = this.getMap();
|
29094 | if (!shadow._canEdit()) {
|
29095 | if (console) {
|
29096 | console.warn('A marker can\'t be resized with symbol:', shadow.getSymbol());
|
29097 | }
|
29098 | return;
|
29099 | }
|
29100 |
|
29101 | if (!this._history) {
|
29102 | this._recordHistory(getUpdates());
|
29103 | }
|
29104 |
|
29105 |
|
29106 | var symbol = shadow._getInternalSymbol();
|
29107 | var dxdy = new Point(0, 0);
|
29108 | if (isNumber(symbol['markerDx'])) {
|
29109 | dxdy.x = symbol['markerDx'];
|
29110 | }
|
29111 | if (isNumber(symbol['markerDy'])) {
|
29112 | dxdy.y = symbol['markerDy'];
|
29113 | }
|
29114 |
|
29115 | var blackList = null;
|
29116 |
|
29117 | if (VectorMarkerSymbolizer.test(symbol)) {
|
29118 | if (symbol['markerType'] === 'pin' || symbol['markerType'] === 'pie' || symbol['markerType'] === 'bar') {
|
29119 | blackList = [5, 6, 7];
|
29120 | }
|
29121 | } else if (ImageMarkerSymbolizer.test(symbol) || VectorPathMarkerSymbolizer.test(symbol)) {
|
29122 | blackList = [5, 6, 7];
|
29123 | }
|
29124 |
|
29125 | var resizeAbilities = [2, 1, 2, 0, 0, 2, 1, 2];
|
29126 |
|
29127 | var aspectRatio = void 0;
|
29128 | if (this.options['fixAspectRatio']) {
|
29129 | var size = shadow.getSize();
|
29130 | aspectRatio = size.width / size.height;
|
29131 | }
|
29132 |
|
29133 | var resizeHandles = this._createResizeHandles(null, function (handleViewPoint, i) {
|
29134 | if (blackList && blackList.indexOf(i) >= 0) {
|
29135 | var newCoordinates = map.viewPointToCoordinate(handleViewPoint.sub(dxdy));
|
29136 | var coordinates = shadow.getCoordinates();
|
29137 | newCoordinates.x = coordinates.x;
|
29138 | shadow.setCoordinates(newCoordinates);
|
29139 | _this5._updateCoordFromShadow(true);
|
29140 |
|
29141 | var mirrorHandle = resizeHandles[resizeHandles.length - 1 - i];
|
29142 | var mirrorViewPoint = map.coordToViewPoint(mirrorHandle.getCoordinates());
|
29143 | handleViewPoint = mirrorViewPoint;
|
29144 | }
|
29145 |
|
29146 | var viewCenter = map._pointToViewPoint(shadow._getCenter2DPoint()).add(dxdy),
|
29147 | symbol = shadow._getInternalSymbol();
|
29148 | var wh = handleViewPoint.sub(viewCenter);
|
29149 | if (blackList && handleViewPoint.y > viewCenter.y) {
|
29150 | wh.y = 0;
|
29151 | }
|
29152 |
|
29153 | var r = blackList ? 1 : 2;
|
29154 | var width = Math.abs(wh.x) * 2,
|
29155 | height = Math.abs(wh.y) * r;
|
29156 | if (aspectRatio) {
|
29157 | width = Math.max(width, height * aspectRatio);
|
29158 | height = width / aspectRatio;
|
29159 | }
|
29160 | var ability = resizeAbilities[i];
|
29161 | if (!(shadow instanceof TextBox)) {
|
29162 | if (aspectRatio || ability === 0 || ability === 2) {
|
29163 | symbol['markerWidth'] = width;
|
29164 | }
|
29165 | if (aspectRatio || ability === 1 || ability === 2) {
|
29166 | symbol['markerHeight'] = height;
|
29167 | }
|
29168 | shadow.setSymbol(symbol);
|
29169 | geometryToEdit.setSymbol(symbol);
|
29170 | } else {
|
29171 | if (aspectRatio || ability === 0 || ability === 2) {
|
29172 | shadow.setWidth(width);
|
29173 | geometryToEdit.setWidth(width);
|
29174 | }
|
29175 | if (aspectRatio || ability === 1 || ability === 2) {
|
29176 | shadow.setHeight(height);
|
29177 | geometryToEdit.setHeight(height);
|
29178 | }
|
29179 | }
|
29180 | }, function () {
|
29181 | _this5._update(getUpdates());
|
29182 | });
|
29183 |
|
29184 | function getUpdates() {
|
29185 | var updates = [['setCoordinates', shadow.getCoordinates().toArray()]];
|
29186 | if (shadow instanceof TextBox) {
|
29187 | updates.push(['setWidth', shadow.getWidth()]);
|
29188 | updates.push(['setHeight', shadow.getHeight()]);
|
29189 | } else {
|
29190 | updates.push(['setSymbol', shadow.getSymbol()]);
|
29191 | }
|
29192 | return updates;
|
29193 | }
|
29194 |
|
29195 | function onZoomEnd() {
|
29196 | this._refresh();
|
29197 | }
|
29198 |
|
29199 | this._addListener([map, 'zoomend', onZoomEnd]);
|
29200 | };
|
29201 |
|
29202 | GeometryEditor.prototype.createCircleEditor = function createCircleEditor() {
|
29203 | var _this6 = this;
|
29204 |
|
29205 | var circle = this._geometry,
|
29206 | shadow = this._shadow;
|
29207 | var map = this.getMap();
|
29208 |
|
29209 | if (!this._history) {
|
29210 | this._recordHistory([['setCoordinates', shadow.getCoordinates().toArray()], ['setRadius', shadow.getRadius()]]);
|
29211 | }
|
29212 |
|
29213 | this._createResizeHandles(null, function (handleViewPoint) {
|
29214 | var viewCenter = map._pointToViewPoint(shadow._getCenter2DPoint());
|
29215 | var wh = handleViewPoint.sub(viewCenter);
|
29216 | var w = Math.abs(wh.x),
|
29217 | h = Math.abs(wh.y);
|
29218 | var r = void 0;
|
29219 | if (w > h) {
|
29220 | r = map.pixelToDistance(w, 0);
|
29221 | } else {
|
29222 | r = map.pixelToDistance(0, h);
|
29223 | }
|
29224 | shadow.setRadius(r);
|
29225 | circle.setRadius(r);
|
29226 | }, function () {
|
29227 | _this6._update('setRadius', shadow.getRadius());
|
29228 | });
|
29229 | };
|
29230 |
|
29231 | GeometryEditor.prototype.createEllipseOrRectEditor = function createEllipseOrRectEditor() {
|
29232 | var _this7 = this;
|
29233 |
|
29234 | var resizeAbilities = [2, 1, 2, 0, 0, 2, 1, 2];
|
29235 | var geometryToEdit = this._geometry,
|
29236 | shadow = this._shadow;
|
29237 |
|
29238 | if (!this._history) {
|
29239 | this._recordHistory(getUpdates());
|
29240 | }
|
29241 |
|
29242 | var map = this.getMap();
|
29243 | var isRect = this._geometry instanceof Rectangle;
|
29244 | var aspectRatio = void 0;
|
29245 | if (this.options['fixAspectRatio']) {
|
29246 | aspectRatio = geometryToEdit.getWidth() / geometryToEdit.getHeight();
|
29247 | }
|
29248 | var resizeHandles = this._createResizeHandles(null, function (mouseViewPoint, i) {
|
29249 | var r = isRect ? 1 : 2;
|
29250 | var pointSub = void 0,
|
29251 | w = void 0,
|
29252 | h = void 0;
|
29253 | var targetPoint = mouseViewPoint;
|
29254 | var ability = resizeAbilities[i];
|
29255 | if (isRect) {
|
29256 | var mirror = resizeHandles[7 - i];
|
29257 | var mirrorViewPoint = map.coordToViewPoint(mirror.getCoordinates());
|
29258 | pointSub = targetPoint.sub(mirrorViewPoint);
|
29259 | var absSub = pointSub.abs();
|
29260 | w = map.pixelToDistance(absSub.x, 0);
|
29261 | h = map.pixelToDistance(0, absSub.y);
|
29262 | var size = geometryToEdit.getSize();
|
29263 | if (ability === 0) {
|
29264 | if (aspectRatio) {
|
29265 | absSub.y = absSub.x / aspectRatio;
|
29266 | size.height = Math.abs(absSub.y);
|
29267 | h = w / aspectRatio;
|
29268 | }
|
29269 | targetPoint.y = mirrorViewPoint.y - size.height / 2;
|
29270 | } else if (ability === 1) {
|
29271 | if (aspectRatio) {
|
29272 | absSub.x = absSub.y * aspectRatio;
|
29273 | size.width = Math.abs(absSub.x);
|
29274 | w = h * aspectRatio;
|
29275 | }
|
29276 | targetPoint.x = mirrorViewPoint.x - size.width / 2;
|
29277 | } else if (aspectRatio) {
|
29278 | if (w > h * aspectRatio) {
|
29279 | h = w / aspectRatio;
|
29280 | targetPoint.y = mirrorViewPoint.y + absSub.x * sign(pointSub.y) / aspectRatio;
|
29281 | } else {
|
29282 | w = h * aspectRatio;
|
29283 | targetPoint.x = mirrorViewPoint.x + absSub.y * sign(pointSub.x) * aspectRatio;
|
29284 | }
|
29285 | }
|
29286 |
|
29287 | var newCoordinates = map.viewPointToCoordinate(new Point(Math.min(targetPoint.x, mirrorViewPoint.x), Math.min(targetPoint.y, mirrorViewPoint.y)));
|
29288 | shadow.setCoordinates(newCoordinates);
|
29289 | _this7._updateCoordFromShadow(true);
|
29290 | } else {
|
29291 | var viewCenter = map.coordToViewPoint(geometryToEdit.getCenter());
|
29292 | pointSub = viewCenter.sub(targetPoint)._abs();
|
29293 | w = map.pixelToDistance(pointSub.x, 0);
|
29294 | h = map.pixelToDistance(0, pointSub.y);
|
29295 | if (aspectRatio) {
|
29296 | w = Math.max(w, h * aspectRatio);
|
29297 | h = w / aspectRatio;
|
29298 | }
|
29299 | }
|
29300 |
|
29301 | if (aspectRatio || ability === 0 || ability === 2) {
|
29302 | shadow.setWidth(w * r);
|
29303 | geometryToEdit.setWidth(w * r);
|
29304 | }
|
29305 | if (aspectRatio || ability === 1 || ability === 2) {
|
29306 | shadow.setHeight(h * r);
|
29307 | geometryToEdit.setHeight(h * r);
|
29308 | }
|
29309 | }, function () {
|
29310 | _this7._update(getUpdates());
|
29311 | });
|
29312 |
|
29313 | function getUpdates() {
|
29314 | return [['setCoordinates', shadow.getCoordinates().toArray()], ['setWidth', shadow.getWidth()], ['setHeight', shadow.getHeight()]];
|
29315 | }
|
29316 | };
|
29317 |
|
29318 | GeometryEditor.prototype.createPolygonEditor = function createPolygonEditor() {
|
29319 |
|
29320 | var map = this.getMap(),
|
29321 | shadow = this._shadow,
|
29322 | me = this,
|
29323 | projection = map.getProjection();
|
29324 | if (!this._history) {
|
29325 | this._recordHistory('setCoordinates', Coordinate.toNumberArrays(shadow.getCoordinates()));
|
29326 | }
|
29327 |
|
29328 | var verticeLimit = shadow instanceof Polygon ? 3 : 2;
|
29329 | var propertyOfVertexRefreshFn = 'maptalks--editor-refresh-fn',
|
29330 | propertyOfVertexIndex = 'maptalks--editor-vertex-index';
|
29331 | var vertexHandles = [],
|
29332 | newVertexHandles = [];
|
29333 |
|
29334 | function getVertexCoordinates() {
|
29335 | if (shadow instanceof Polygon) {
|
29336 | var coordinates = shadow.getCoordinates()[0];
|
29337 | return coordinates.slice(0, coordinates.length - 1);
|
29338 | } else {
|
29339 | return shadow.getCoordinates();
|
29340 | }
|
29341 | }
|
29342 |
|
29343 | function getVertexPrjCoordinates() {
|
29344 | return shadow._getPrjCoordinates();
|
29345 | }
|
29346 |
|
29347 | function onVertexAddOrRemove() {
|
29348 | for (var i = vertexHandles.length - 1; i >= 0; i--) {
|
29349 | vertexHandles[i][propertyOfVertexIndex] = i;
|
29350 | }
|
29351 | for (var _i = newVertexHandles.length - 1; _i >= 0; _i--) {
|
29352 | newVertexHandles[_i][propertyOfVertexIndex] = _i;
|
29353 | }
|
29354 | me._updateCoordFromShadow();
|
29355 | }
|
29356 |
|
29357 | function removeVertex(param) {
|
29358 | var handle = param['target'],
|
29359 | index = handle[propertyOfVertexIndex];
|
29360 | var prjCoordinates = getVertexPrjCoordinates();
|
29361 | if (prjCoordinates.length <= verticeLimit) {
|
29362 | return;
|
29363 | }
|
29364 | prjCoordinates.splice(index, 1);
|
29365 | shadow._setPrjCoordinates(prjCoordinates);
|
29366 | shadow._updateCache();
|
29367 |
|
29368 | vertexHandles.splice(index, 1)[0].remove();
|
29369 |
|
29370 | if (index < newVertexHandles.length) {
|
29371 | newVertexHandles.splice(index, 1)[0].remove();
|
29372 | }
|
29373 | var nextIndex = void 0;
|
29374 | if (index === 0) {
|
29375 | nextIndex = newVertexHandles.length - 1;
|
29376 | } else {
|
29377 | nextIndex = index - 1;
|
29378 | }
|
29379 | newVertexHandles.splice(nextIndex, 1)[0].remove();
|
29380 |
|
29381 | newVertexHandles.splice(nextIndex, 0, createNewVertexHandle.call(me, nextIndex));
|
29382 | onVertexAddOrRemove();
|
29383 | me._refresh();
|
29384 | }
|
29385 |
|
29386 | function moveVertexHandle(handleViewPoint, index) {
|
29387 | var vertice = getVertexPrjCoordinates();
|
29388 | var nVertex = map._viewPointToPrj(handleViewPoint);
|
29389 | var pVertex = vertice[index];
|
29390 | pVertex.x = nVertex.x;
|
29391 | pVertex.y = nVertex.y;
|
29392 | shadow._updateCache();
|
29393 | shadow.onShapeChanged();
|
29394 | me._updateCoordFromShadow(true);
|
29395 | var nextIndex = void 0;
|
29396 | if (index === 0) {
|
29397 | nextIndex = newVertexHandles.length - 1;
|
29398 | } else {
|
29399 | nextIndex = index - 1;
|
29400 | }
|
29401 |
|
29402 | if (newVertexHandles[index]) {
|
29403 | newVertexHandles[index][propertyOfVertexRefreshFn]();
|
29404 | }
|
29405 | if (newVertexHandles[nextIndex]) {
|
29406 | newVertexHandles[nextIndex][propertyOfVertexRefreshFn]();
|
29407 | }
|
29408 | }
|
29409 |
|
29410 | function createVertexHandle(index) {
|
29411 | var vertex = getVertexCoordinates()[index];
|
29412 | var handle = me.createHandle(vertex, {
|
29413 | 'symbol': me.options['vertexHandleSymbol'],
|
29414 | 'cursor': 'pointer',
|
29415 | 'axis': null,
|
29416 | onMove: function onMove(handleViewPoint) {
|
29417 | moveVertexHandle(handleViewPoint, handle[propertyOfVertexIndex]);
|
29418 | },
|
29419 | onRefresh: function onRefresh() {
|
29420 | vertex = getVertexCoordinates()[handle[propertyOfVertexIndex]];
|
29421 | handle.setCoordinates(vertex);
|
29422 | },
|
29423 | onUp: function onUp() {
|
29424 | me._refresh();
|
29425 | me._updateCoordFromShadow();
|
29426 | }
|
29427 | });
|
29428 | handle[propertyOfVertexIndex] = index;
|
29429 | handle.on(me.options['removeVertexOn'], removeVertex);
|
29430 | return handle;
|
29431 | }
|
29432 |
|
29433 | function createNewVertexHandle(index) {
|
29434 | var vertexCoordinates = getVertexCoordinates();
|
29435 | var nextVertex = void 0;
|
29436 | if (index + 1 >= vertexCoordinates.length) {
|
29437 | nextVertex = vertexCoordinates[0];
|
29438 | } else {
|
29439 | nextVertex = vertexCoordinates[index + 1];
|
29440 | }
|
29441 | var vertex = vertexCoordinates[index].add(nextVertex).multi(1 / 2);
|
29442 | var handle = me.createHandle(vertex, {
|
29443 | 'symbol': me.options['newVertexHandleSymbol'],
|
29444 | 'cursor': 'pointer',
|
29445 | 'axis': null,
|
29446 | onDown: function onDown(param, e) {
|
29447 | if (e && e.domEvent && e.domEvent.button === 2) {
|
29448 | return;
|
29449 | }
|
29450 | var prjCoordinates = getVertexPrjCoordinates();
|
29451 | var vertexIndex = handle[propertyOfVertexIndex];
|
29452 |
|
29453 | var pVertex = projection.project(handle.getCoordinates());
|
29454 |
|
29455 | prjCoordinates.splice(vertexIndex + 1, 0, pVertex);
|
29456 | shadow._setPrjCoordinates(prjCoordinates);
|
29457 | shadow._updateCache();
|
29458 |
|
29459 | var symbol = handle.getSymbol();
|
29460 | delete symbol['opacity'];
|
29461 | handle.setSymbol(symbol);
|
29462 |
|
29463 | newVertexHandles.splice(vertexIndex, 0, createNewVertexHandle.call(me, vertexIndex), createNewVertexHandle.call(me, vertexIndex + 1));
|
29464 | },
|
29465 | onMove: function onMove(handleViewPoint) {
|
29466 | moveVertexHandle(handleViewPoint, handle[propertyOfVertexIndex] + 1);
|
29467 | },
|
29468 | onUp: function onUp(e) {
|
29469 | if (e && e.domEvent && e.domEvent.button === 2) {
|
29470 | return;
|
29471 | }
|
29472 | var vertexIndex = handle[propertyOfVertexIndex];
|
29473 |
|
29474 | removeFromArray(handle, newVertexHandles);
|
29475 | handle.remove();
|
29476 |
|
29477 | vertexHandles.splice(vertexIndex + 1, 0, createVertexHandle.call(me, vertexIndex + 1));
|
29478 | onVertexAddOrRemove();
|
29479 | me._updateCoordFromShadow();
|
29480 | me._refresh();
|
29481 | },
|
29482 | onRefresh: function onRefresh() {
|
29483 | vertexCoordinates = getVertexCoordinates();
|
29484 | var vertexIndex = handle[propertyOfVertexIndex];
|
29485 | var nextIndex = void 0;
|
29486 | if (vertexIndex === vertexCoordinates.length - 1) {
|
29487 | nextIndex = 0;
|
29488 | } else {
|
29489 | nextIndex = vertexIndex + 1;
|
29490 | }
|
29491 | var refreshVertex = vertexCoordinates[vertexIndex].add(vertexCoordinates[nextIndex]).multi(1 / 2);
|
29492 | handle.setCoordinates(refreshVertex);
|
29493 | }
|
29494 | });
|
29495 | handle[propertyOfVertexIndex] = index;
|
29496 | return handle;
|
29497 | }
|
29498 | var vertexCoordinates = getVertexCoordinates();
|
29499 | for (var i = 0, len = vertexCoordinates.length; i < len; i++) {
|
29500 | vertexHandles.push(createVertexHandle.call(this, i));
|
29501 | if (i < len - 1) {
|
29502 | newVertexHandles.push(createNewVertexHandle.call(this, i));
|
29503 | }
|
29504 | }
|
29505 | if (shadow instanceof Polygon) {
|
29506 | newVertexHandles.push(createNewVertexHandle.call(this, vertexCoordinates.length - 1));
|
29507 | }
|
29508 | this._addRefreshHook(function () {
|
29509 | for (var _i2 = newVertexHandles.length - 1; _i2 >= 0; _i2--) {
|
29510 | newVertexHandles[_i2][propertyOfVertexRefreshFn]();
|
29511 | }
|
29512 | for (var _i3 = vertexHandles.length - 1; _i3 >= 0; _i3--) {
|
29513 | vertexHandles[_i3][propertyOfVertexRefreshFn]();
|
29514 | }
|
29515 | });
|
29516 | };
|
29517 |
|
29518 | GeometryEditor.prototype._refresh = function _refresh() {
|
29519 | if (this._refreshHooks) {
|
29520 | for (var i = this._refreshHooks.length - 1; i >= 0; i--) {
|
29521 | this._refreshHooks[i].call(this);
|
29522 | }
|
29523 | }
|
29524 | };
|
29525 |
|
29526 | GeometryEditor.prototype._hideContext = function _hideContext() {
|
29527 | if (this._geometry) {
|
29528 | this._geometry.closeMenu();
|
29529 | this._geometry.closeInfoWindow();
|
29530 | }
|
29531 | };
|
29532 |
|
29533 | GeometryEditor.prototype._addListener = function _addListener(listener) {
|
29534 | if (!this._eventListeners) {
|
29535 | this._eventListeners = [];
|
29536 | }
|
29537 | this._eventListeners.push(listener);
|
29538 | listener[0].on(listener[1], listener[2], this);
|
29539 | };
|
29540 |
|
29541 | GeometryEditor.prototype._clearAllListeners = function _clearAllListeners() {
|
29542 | if (this._eventListeners && this._eventListeners.length > 0) {
|
29543 | for (var i = this._eventListeners.length - 1; i >= 0; i--) {
|
29544 | var listener = this._eventListeners[i];
|
29545 | listener[0].off(listener[1], listener[2], this);
|
29546 | }
|
29547 | this._eventListeners = [];
|
29548 | }
|
29549 | };
|
29550 |
|
29551 | GeometryEditor.prototype._addRefreshHook = function _addRefreshHook(fn) {
|
29552 | if (!fn) {
|
29553 | return;
|
29554 | }
|
29555 | if (!this._refreshHooks) {
|
29556 | this._refreshHooks = [];
|
29557 | }
|
29558 | this._refreshHooks.push(fn);
|
29559 | };
|
29560 |
|
29561 | GeometryEditor.prototype._update = function _update(method) {
|
29562 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
29563 | args[_key - 1] = arguments[_key];
|
29564 | }
|
29565 |
|
29566 | this._exeHistory([method, args]);
|
29567 | this._recordHistory.apply(this, [method].concat(args));
|
29568 | };
|
29569 |
|
29570 | GeometryEditor.prototype._updateCoordFromShadow = function _updateCoordFromShadow(ignoreRecord) {
|
29571 | if (!this._shadow) {
|
29572 | return;
|
29573 | }
|
29574 |
|
29575 | var coords = this._shadow.getCoordinates();
|
29576 | var geo = this._geometry;
|
29577 | var updating = this._updating;
|
29578 | this._updating = true;
|
29579 | geo.setCoordinates(coords);
|
29580 | if (!ignoreRecord) {
|
29581 | this._recordHistory('setCoordinates', Coordinate.toNumberArrays(geo.getCoordinates()));
|
29582 | }
|
29583 | this._updating = updating;
|
29584 | };
|
29585 |
|
29586 | GeometryEditor.prototype._recordHistory = function _recordHistory(method) {
|
29587 | if (!this._history) {
|
29588 | this._history = [];
|
29589 | this._historyPointer = 0;
|
29590 | }
|
29591 |
|
29592 | if (this._historyPointer < this._history.length - 1) {
|
29593 | this._history.splice(this._historyPointer + 1);
|
29594 | }
|
29595 |
|
29596 | for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
29597 | args[_key2 - 1] = arguments[_key2];
|
29598 | }
|
29599 |
|
29600 | this._history.push([method, args]);
|
29601 | this._historyPointer = this._history.length - 1;
|
29602 |
|
29603 | this._geometry.fire('editrecord');
|
29604 | };
|
29605 |
|
29606 | GeometryEditor.prototype.undo = function undo() {
|
29607 | if (!this._history || this._historyPointer === 0) {
|
29608 | return this;
|
29609 | }
|
29610 | var record = this._history[--this._historyPointer];
|
29611 | this._exeAndReset(record);
|
29612 | return this;
|
29613 | };
|
29614 |
|
29615 | GeometryEditor.prototype.redo = function redo() {
|
29616 | if (!this._history || this._historyPointer === this._history.length - 1) {
|
29617 | return null;
|
29618 | }
|
29619 | var record = this._history[++this._historyPointer];
|
29620 | this._exeAndReset(record);
|
29621 | return this;
|
29622 | };
|
29623 |
|
29624 | GeometryEditor.prototype._exeAndReset = function _exeAndReset(record) {
|
29625 | if (this._updating) {
|
29626 | return;
|
29627 | }
|
29628 | this._exeHistory(record);
|
29629 | var history = this._history,
|
29630 | pointer = this._historyPointer;
|
29631 | this.stop();
|
29632 | this._history = history;
|
29633 | this._historyPointer = pointer;
|
29634 | this.start();
|
29635 | };
|
29636 |
|
29637 | GeometryEditor.prototype._exeHistory = function _exeHistory(record) {
|
29638 | var _this8 = this;
|
29639 |
|
29640 | if (!Array.isArray(record)) {
|
29641 | return;
|
29642 | }
|
29643 | var updating = this._updating;
|
29644 | this._updating = true;
|
29645 | var geo = this._geometry;
|
29646 | if (Array.isArray(record[0])) {
|
29647 | record[0].forEach(function (o) {
|
29648 | var m = o[0],
|
29649 | args = o.slice(1);
|
29650 | _this8._shadow[m].apply(_this8._shadow, args);
|
29651 | geo[m].apply(geo, args);
|
29652 | });
|
29653 | } else {
|
29654 | this._shadow[record[0]].apply(this._shadow, record[1]);
|
29655 | geo[record[0]].apply(geo, record[1]);
|
29656 | }
|
29657 | this._updating = updating;
|
29658 | };
|
29659 |
|
29660 | return GeometryEditor;
|
29661 | }(Eventable(Class));
|
29662 |
|
29663 | GeometryEditor.mergeOptions(options$35);
|
29664 |
|
29665 | var TextEditable = {
|
29666 | startEditText: function startEditText() {
|
29667 | if (!this.getMap()) {
|
29668 | return this;
|
29669 | }
|
29670 | this.hide();
|
29671 | this.endEditText();
|
29672 | this._prepareEditor();
|
29673 |
|
29674 | this._fireEvent('edittextstart');
|
29675 | return this;
|
29676 | },
|
29677 | endEditText: function endEditText() {
|
29678 | if (this._textEditor) {
|
29679 | var html = this._textEditor.innerHTML;
|
29680 | html = html.replace(/<p>/ig, '').replace(/<\/p>/ig, '<br/>');
|
29681 | this._textEditor.innerHTML = html;
|
29682 |
|
29683 | var content = this._textEditor.innerText.replace(/[\r\n]+$/gi, '');
|
29684 | this.setContent(content);
|
29685 | off(this._textEditor, 'mousedown dblclick', stopPropagation);
|
29686 | this.getMap().off('mousedown', this.endEditText, this);
|
29687 | this._editUIMarker.remove();
|
29688 | delete this._editUIMarker;
|
29689 | this._textEditor.onkeyup = null;
|
29690 | delete this._textEditor;
|
29691 | this.show();
|
29692 |
|
29693 | this._fireEvent('edittextend');
|
29694 | }
|
29695 | return this;
|
29696 | },
|
29697 | isEditingText: function isEditingText() {
|
29698 | if (this._textEditor) {
|
29699 | return true;
|
29700 | }
|
29701 | return false;
|
29702 | },
|
29703 | getTextEditor: function getTextEditor() {
|
29704 | return this._editUIMarker;
|
29705 | },
|
29706 | _prepareEditor: function _prepareEditor() {
|
29707 | var map = this.getMap();
|
29708 | var editContainer = this._createEditor();
|
29709 | this._textEditor = editContainer;
|
29710 | map.on('mousedown', this.endEditText, this);
|
29711 | var offset = this._getEditorOffset();
|
29712 | this._editUIMarker = new UIMarker(this.getCoordinates(), {
|
29713 | 'animation': null,
|
29714 | 'content': editContainer,
|
29715 | 'dx': offset.dx,
|
29716 | 'dy': offset.dy
|
29717 | }).addTo(map);
|
29718 | this._setCursorToLast(this._textEditor);
|
29719 | },
|
29720 | _getEditorOffset: function _getEditorOffset() {
|
29721 | var symbol = this._getInternalSymbol() || {};
|
29722 | var dx = 0,
|
29723 | dy = 0;
|
29724 | var textAlign = symbol['textHorizontalAlignment'];
|
29725 | if (textAlign === 'middle' || isNil(textAlign)) {
|
29726 | dx = (symbol['textDx'] || 0) - 2;
|
29727 | dy = (symbol['textDy'] || 0) - 2;
|
29728 | } else {
|
29729 | dx = (symbol['markerDx'] || 0) - 2;
|
29730 | dy = (symbol['markerDy'] || 0) - 2;
|
29731 | }
|
29732 | return {
|
29733 | 'dx': dx,
|
29734 | 'dy': dy
|
29735 | };
|
29736 | },
|
29737 | _createEditor: function _createEditor() {
|
29738 | var content = this.getContent();
|
29739 | var labelSize = this.getSize(),
|
29740 | symbol = this._getInternalSymbol() || {},
|
29741 | width = labelSize.width,
|
29742 | textColor = symbol['textFill'] || '#000000',
|
29743 | textSize = symbol['textSize'] || 12,
|
29744 | height = labelSize.height,
|
29745 | lineColor = symbol['markerLineColor'] || '#000',
|
29746 | fill = symbol['markerFill'] || '#3398CC',
|
29747 | spacing = symbol['textLineSpacing'] || 0;
|
29748 | var editor = createEl('div');
|
29749 | editor.contentEditable = true;
|
29750 | editor.style.cssText = 'background:' + fill + '; border:1px solid ' + lineColor + ';\n color:' + textColor + ';font-size:' + textSize + 'px;width:' + (width - 2) + 'px;height:' + (height - 2) + 'px;margin: auto;\n line-height:' + (textSize + spacing) + 'px;outline: 0; padding:0; margin:0;word-wrap: break-word;\n overflow: hidden;-webkit-user-modify: read-write-plaintext-only;';
|
29751 |
|
29752 | editor.innerText = content;
|
29753 | on(editor, 'mousedown dblclick', stopPropagation);
|
29754 | editor.onkeyup = function (event) {
|
29755 | var h = editor.style.height || 0;
|
29756 | if (event.keyCode === 13) {
|
29757 | editor.style.height = parseInt(h) + textSize / 2 + 'px';
|
29758 | }
|
29759 | };
|
29760 | return editor;
|
29761 | },
|
29762 | _setCursorToLast: function _setCursorToLast(obj) {
|
29763 | var range = void 0;
|
29764 | if (window.getSelection) {
|
29765 | obj.focus();
|
29766 | range = window.getSelection();
|
29767 | range.selectAllChildren(obj);
|
29768 | range.collapseToEnd();
|
29769 | } else if (document.selection) {
|
29770 | range = document.selection.createRange();
|
29771 | range.moveToElementText(obj);
|
29772 | range.collapse(false);
|
29773 | range.select();
|
29774 | }
|
29775 | }
|
29776 | };
|
29777 |
|
29778 | TextMarker.include(TextEditable);
|
29779 |
|
29780 | Geometry.include({
|
29781 | animate: function animate(styles, options, step) {
|
29782 | var _this = this;
|
29783 |
|
29784 | if (this._animPlayer) {
|
29785 | this._animPlayer.finish();
|
29786 | }
|
29787 | if (isFunction(options)) {
|
29788 | step = options;
|
29789 | }
|
29790 | if (!options) {
|
29791 | options = {};
|
29792 | }
|
29793 | var map = this.getMap(),
|
29794 | projection = this._getProjection(),
|
29795 | symbol = this.getSymbol() || {},
|
29796 | stylesToAnimate = this._prepareAnimationStyles(styles);
|
29797 | var preTranslate = void 0;
|
29798 |
|
29799 | var isFocusing = options['focus'];
|
29800 | delete this._animationStarted;
|
29801 |
|
29802 | if (map) {
|
29803 | var renderer = map._getRenderer();
|
29804 | var framer = function framer(fn) {
|
29805 | renderer.callInNextFrame(fn);
|
29806 | };
|
29807 | options['framer'] = framer;
|
29808 | }
|
29809 |
|
29810 | var player = Animation.animate(stylesToAnimate, options, function (frame) {
|
29811 | if (map && map.isRemoved()) {
|
29812 | player.finish();
|
29813 | return;
|
29814 | }
|
29815 | if (map && !_this._animationStarted && isFocusing) {
|
29816 | map.onMoveStart();
|
29817 | }
|
29818 | var styles = frame.styles;
|
29819 | for (var p in styles) {
|
29820 | if (p !== 'symbol' && p !== 'translate' && styles.hasOwnProperty(p)) {
|
29821 | var fnName = 'set' + p[0].toUpperCase() + p.slice(1);
|
29822 | _this[fnName](styles[p]);
|
29823 | }
|
29824 | }
|
29825 | var translate = styles['translate'];
|
29826 | if (translate) {
|
29827 | var toTranslate = translate;
|
29828 | if (preTranslate) {
|
29829 | toTranslate = translate.sub(preTranslate);
|
29830 | }
|
29831 | preTranslate = translate;
|
29832 | _this.translate(toTranslate);
|
29833 | }
|
29834 | var dSymbol = styles['symbol'];
|
29835 | if (dSymbol) {
|
29836 | _this.setSymbol(extendSymbol(symbol, dSymbol));
|
29837 | }
|
29838 | if (map && isFocusing) {
|
29839 | var pcenter = projection.project(_this.getCenter());
|
29840 | map._setPrjCenter(pcenter);
|
29841 | var e = map._parseEventFromCoord(projection.unproject(pcenter));
|
29842 | if (player.playState !== 'running') {
|
29843 | map.onMoveEnd(e);
|
29844 | } else {
|
29845 | map.onMoving(e);
|
29846 | }
|
29847 | }
|
29848 | _this._fireAnimateEvent(player.playState);
|
29849 | if (step) {
|
29850 | step(frame);
|
29851 | }
|
29852 | });
|
29853 | this._animPlayer = player;
|
29854 | return this._animPlayer.play();
|
29855 | },
|
29856 |
|
29857 | _prepareAnimationStyles: function _prepareAnimationStyles(styles) {
|
29858 | var symbol = this._getInternalSymbol();
|
29859 | var stylesToAnimate = {};
|
29860 | for (var p in styles) {
|
29861 | if (styles.hasOwnProperty(p)) {
|
29862 | var v = styles[p];
|
29863 | if (p !== 'translate' && p !== 'symbol') {
|
29864 | var fnName = 'get' + p[0].toUpperCase() + p.substring(1);
|
29865 | var current = this[fnName]();
|
29866 | stylesToAnimate[p] = [current, v];
|
29867 | } else if (p === 'symbol') {
|
29868 | var symbolToAnimate = void 0;
|
29869 | if (Array.isArray(styles['symbol'])) {
|
29870 | if (!Array.isArray(symbol)) {
|
29871 | throw new Error('geometry\'symbol isn\'t a composite symbol, while the symbol in styles is.');
|
29872 | }
|
29873 | symbolToAnimate = [];
|
29874 | var symbolInStyles = styles['symbol'];
|
29875 | for (var i = 0; i < symbolInStyles.length; i++) {
|
29876 | if (!symbolInStyles[i]) {
|
29877 | symbolToAnimate.push(null);
|
29878 | continue;
|
29879 | }
|
29880 | var a = {};
|
29881 | for (var sp in symbolInStyles[i]) {
|
29882 | if (symbolInStyles[i].hasOwnProperty(sp)) {
|
29883 | a[sp] = [symbol[i][sp], symbolInStyles[i][sp]];
|
29884 | }
|
29885 | }
|
29886 | symbolToAnimate.push(a);
|
29887 | }
|
29888 | } else {
|
29889 | if (Array.isArray(symbol)) {
|
29890 | throw new Error('geometry\'symbol is a composite symbol, while the symbol in styles isn\'t.');
|
29891 | }
|
29892 | symbolToAnimate = {};
|
29893 | for (var _sp in v) {
|
29894 | if (v.hasOwnProperty(_sp)) {
|
29895 | symbolToAnimate[_sp] = [symbol[_sp], v[_sp]];
|
29896 | }
|
29897 | }
|
29898 | }
|
29899 | stylesToAnimate['symbol'] = symbolToAnimate;
|
29900 | } else if (p === 'translate') {
|
29901 | stylesToAnimate['translate'] = new Coordinate(v);
|
29902 | }
|
29903 | }
|
29904 | }
|
29905 | return stylesToAnimate;
|
29906 | },
|
29907 |
|
29908 | _fireAnimateEvent: function _fireAnimateEvent(playState) {
|
29909 | if (playState === 'finished') {
|
29910 | delete this._animationStarted;
|
29911 | this._fireEvent('animateend');
|
29912 | } else if (playState === 'running') {
|
29913 | if (this._animationStarted) {
|
29914 | this._fireEvent('animating');
|
29915 | } else {
|
29916 | this._fireEvent('animatestart');
|
29917 | this._animationStarted = true;
|
29918 | }
|
29919 | }
|
29920 | }
|
29921 | });
|
29922 |
|
29923 | var DRAG_STAGE_LAYER_ID = INTERNAL_LAYER_PREFIX + '_drag_stage';
|
29924 |
|
29925 | var EVENTS$2 = Browser$1.touch ? 'touchstart mousedown' : 'mousedown';
|
29926 |
|
29927 | var GeometryDragHandler = function (_Handler) {
|
29928 | inherits(GeometryDragHandler, _Handler);
|
29929 |
|
29930 | function GeometryDragHandler(target) {
|
29931 | classCallCheck(this, GeometryDragHandler);
|
29932 | return possibleConstructorReturn(this, _Handler.call(this, target));
|
29933 | }
|
29934 |
|
29935 | GeometryDragHandler.prototype.addHooks = function addHooks() {
|
29936 | this.target.on(EVENTS$2, this._startDrag, this);
|
29937 | };
|
29938 |
|
29939 | GeometryDragHandler.prototype.removeHooks = function removeHooks() {
|
29940 | this._endDrag();
|
29941 | this.target.off(EVENTS$2, this._startDrag, this);
|
29942 | delete this.container;
|
29943 | };
|
29944 |
|
29945 | GeometryDragHandler.prototype._prepareDragHandler = function _prepareDragHandler() {
|
29946 | this._dragHandler = new DragHandler(this.container);
|
29947 | this._dragHandler.on('dragging', this._dragging, this).on('mouseup', this._endDrag, this).enable();
|
29948 | };
|
29949 |
|
29950 | GeometryDragHandler.prototype._prepareShadow = function _prepareShadow() {
|
29951 | var target = this.target;
|
29952 | this._prepareDragStageLayer();
|
29953 | if (this._shadow) {
|
29954 | this._shadow.remove();
|
29955 | }
|
29956 |
|
29957 | var shadow = this._shadow = target.copy();
|
29958 | this._shadow.setSymbol(target._getInternalSymbol());
|
29959 | if (target.options['dragShadow']) {
|
29960 | var symbol = lowerSymbolOpacity(shadow._getInternalSymbol(), 0.5);
|
29961 | shadow.setSymbol(symbol);
|
29962 | }
|
29963 | shadow.setId(null);
|
29964 | this._prepareShadowConnectors();
|
29965 | };
|
29966 |
|
29967 | GeometryDragHandler.prototype._prepareShadowConnectors = function _prepareShadowConnectors() {
|
29968 | var target = this.target;
|
29969 | var shadow = this._shadow;
|
29970 | var resources = this._dragStageLayer._getRenderer().resources;
|
29971 |
|
29972 | var shadowConnectors = [];
|
29973 | if (ConnectorLine._hasConnectors(target)) {
|
29974 | var connectors = ConnectorLine._getConnectors(target);
|
29975 |
|
29976 | for (var i = 0, l = connectors.length; i < l; i++) {
|
29977 | var targetConn = connectors[i];
|
29978 | var connOptions = targetConn.config(),
|
29979 | connSymbol = targetConn._getInternalSymbol();
|
29980 | connOptions['symbol'] = lowerSymbolOpacity(connSymbol, 0.5);
|
29981 | var conn = void 0;
|
29982 | if (targetConn.getConnectSource() === target) {
|
29983 | conn = new targetConn.constructor(shadow, targetConn.getConnectTarget(), connOptions);
|
29984 | } else {
|
29985 | conn = new targetConn.constructor(targetConn.getConnectSource(), shadow, connOptions);
|
29986 | }
|
29987 | shadowConnectors.push(conn);
|
29988 | if (targetConn.getLayer() && targetConn.getLayer()._getRenderer()) {
|
29989 | resources.merge(targetConn.getLayer()._getRenderer().resources);
|
29990 | }
|
29991 | }
|
29992 | }
|
29993 | this._shadowConnectors = shadowConnectors;
|
29994 | shadowConnectors.push(shadow);
|
29995 | this._dragStageLayer.bringToFront().addGeometry(shadowConnectors);
|
29996 | };
|
29997 |
|
29998 | GeometryDragHandler.prototype._onTargetUpdated = function _onTargetUpdated() {
|
29999 | if (this._shadow) {
|
30000 | this._shadow.setSymbol(this.target._getSymbol());
|
30001 | }
|
30002 | };
|
30003 |
|
30004 | GeometryDragHandler.prototype._prepareDragStageLayer = function _prepareDragStageLayer() {
|
30005 | var map = this.target.getMap(),
|
30006 | layer = this.target.getLayer();
|
30007 | this._dragStageLayer = map.getLayer(DRAG_STAGE_LAYER_ID);
|
30008 | if (!this._dragStageLayer) {
|
30009 | this._dragStageLayer = new VectorLayer(DRAG_STAGE_LAYER_ID, {
|
30010 | enableAltitude: layer.options['enableAltitude'],
|
30011 | altitudeProperty: layer.options['altitudeProperty']
|
30012 | });
|
30013 | map.addLayer(this._dragStageLayer);
|
30014 | }
|
30015 |
|
30016 | var resources = new ResourceCache();
|
30017 | resources.merge(layer._getRenderer().resources);
|
30018 | this._dragStageLayer._getRenderer().resources = resources;
|
30019 | };
|
30020 |
|
30021 | GeometryDragHandler.prototype._startDrag = function _startDrag(param) {
|
30022 | var map = this.target.getMap();
|
30023 | if (!map) {
|
30024 | return;
|
30025 | }
|
30026 | var parent = this.target._getParent();
|
30027 | if (parent) {
|
30028 | return;
|
30029 | }
|
30030 | if (this.isDragging()) {
|
30031 | return;
|
30032 | }
|
30033 | var domEvent = param['domEvent'];
|
30034 | if (domEvent.touches && domEvent.touches.length > 1 || domEvent.button === 2) {
|
30035 | return;
|
30036 | }
|
30037 | this.container = map._panels.mapWrapper || map._containerDOM;
|
30038 | this.target.on('click', this._endDrag, this);
|
30039 | this._lastCoord = this._correctCoord(param['coordinate']);
|
30040 | this._lastPoint = param['containerPoint'];
|
30041 | this._prepareDragHandler();
|
30042 | this._dragHandler.onMouseDown(param['domEvent']);
|
30043 |
|
30044 | on(this.container, 'mouseleave', this._endDrag, this);
|
30045 | this._startParam = param;
|
30046 | this._moved = false;
|
30047 |
|
30048 | return;
|
30049 | };
|
30050 |
|
30051 | GeometryDragHandler.prototype._dragging = function _dragging(param) {
|
30052 | var target = this.target;
|
30053 | var map = target.getMap(),
|
30054 | e = map._parseEvent(param['domEvent']);
|
30055 |
|
30056 | var domEvent = e['domEvent'];
|
30057 | if (domEvent.touches && domEvent.touches.length > 1) {
|
30058 | return;
|
30059 | }
|
30060 |
|
30061 | if (!this._moved) {
|
30062 | this._moved = true;
|
30063 | target.on('symbolchange', this._onTargetUpdated, this);
|
30064 | this._isDragging = true;
|
30065 | this._prepareShadow();
|
30066 | if (!target.options['dragShadow']) {
|
30067 | target.hide();
|
30068 | }
|
30069 | this._shadow._fireEvent('dragstart', e);
|
30070 |
|
30071 | this.target._fireEvent('dragstart', this._startParam || e);
|
30072 | delete this._startParam;
|
30073 | return;
|
30074 | }
|
30075 | if (!this._shadow) {
|
30076 | return;
|
30077 | }
|
30078 | var axis = this._shadow.options['dragOnAxis'],
|
30079 | coord = this._correctCoord(e['coordinate']),
|
30080 | point = e['containerPoint'];
|
30081 | this._lastPoint = this._lastPoint || point;
|
30082 | this._lastCoord = this._lastCoord || coord;
|
30083 | var pointOffset = point.sub(this._lastPoint);
|
30084 | var coordOffset = coord.sub(this._lastCoord);
|
30085 | if (axis === 'x') {
|
30086 | pointOffset.y = coordOffset.y = 0;
|
30087 | } else if (axis === 'y') {
|
30088 | pointOffset.x = coordOffset.x = 0;
|
30089 | }
|
30090 | this._lastPoint = point;
|
30091 | this._lastCoord = coord;
|
30092 | this._shadow.translate(coordOffset);
|
30093 | if (!target.options['dragShadow']) {
|
30094 | target.translate(coordOffset);
|
30095 | }
|
30096 | e['coordOffset'] = coordOffset;
|
30097 | e['pointOffset'] = pointOffset;
|
30098 | this._shadow._fireEvent('dragging', e);
|
30099 |
|
30100 | target._fireEvent('dragging', e);
|
30101 | };
|
30102 |
|
30103 | GeometryDragHandler.prototype._endDrag = function _endDrag(param) {
|
30104 | if (this._dragHandler) {
|
30105 | this._dragHandler.disable();
|
30106 | delete this._dragHandler;
|
30107 | }
|
30108 | if (this.container) {
|
30109 | off(this.container, 'mouseleave', this._endDrag, this);
|
30110 | }
|
30111 | if (!this.target) {
|
30112 | return;
|
30113 | }
|
30114 | var target = this.target;
|
30115 | target.off('click', this._endDrag, this);
|
30116 |
|
30117 | target.off('symbolchange', this._onTargetUpdated, this);
|
30118 |
|
30119 | delete this._lastCoord;
|
30120 | delete this._lastPoint;
|
30121 |
|
30122 | this._isDragging = false;
|
30123 |
|
30124 | var map = target.getMap();
|
30125 | if (this.enabled() && map) {
|
30126 | var e = map._parseEvent(param ? param['domEvent'] : null);
|
30127 | this._updateTargetAndRemoveShadow(e);
|
30128 | if (this._moved) {
|
30129 | target._fireEvent('dragend', e);
|
30130 | }
|
30131 | }
|
30132 | };
|
30133 |
|
30134 | GeometryDragHandler.prototype.isDragging = function isDragging() {
|
30135 | if (!this._isDragging) {
|
30136 | return false;
|
30137 | }
|
30138 | return true;
|
30139 | };
|
30140 |
|
30141 | GeometryDragHandler.prototype._updateTargetAndRemoveShadow = function _updateTargetAndRemoveShadow(eventParam) {
|
30142 | var target = this.target,
|
30143 | map = target.getMap();
|
30144 | if (!target.options['dragShadow']) {
|
30145 | target.show();
|
30146 | }
|
30147 | var shadow = this._shadow;
|
30148 | if (shadow) {
|
30149 | if (target.options['dragShadow']) {
|
30150 | target.setCoordinates(shadow.getCoordinates());
|
30151 | }
|
30152 | shadow._fireEvent('dragend', eventParam);
|
30153 | shadow.remove();
|
30154 | delete this._shadow;
|
30155 | }
|
30156 | if (this._shadowConnectors) {
|
30157 | map.getLayer(DRAG_STAGE_LAYER_ID).removeGeometry(this._shadowConnectors);
|
30158 | delete this._shadowConnectors;
|
30159 | }
|
30160 | if (this._dragStageLayer) {
|
30161 | this._dragStageLayer.remove();
|
30162 | }
|
30163 | };
|
30164 |
|
30165 | GeometryDragHandler.prototype._correctCoord = function _correctCoord(coord) {
|
30166 | var map = this.target.getMap();
|
30167 | if (!map.getPitch()) {
|
30168 | return coord;
|
30169 | }
|
30170 | var painter = this.target._getPainter();
|
30171 | if (!painter.getMinAltitude()) {
|
30172 | return coord;
|
30173 | }
|
30174 | var alt = (painter.getMinAltitude() + painter.getMaxAltitude()) / 2;
|
30175 | return map.locateByPoint(coord, 0, -alt);
|
30176 | };
|
30177 |
|
30178 | return GeometryDragHandler;
|
30179 | }(Handler$1);
|
30180 |
|
30181 | Geometry.mergeOptions({
|
30182 | 'draggable': false,
|
30183 | 'dragShadow': true,
|
30184 | 'dragOnAxis': null
|
30185 | });
|
30186 |
|
30187 | Geometry.addInitHook('addHandler', 'draggable', GeometryDragHandler);
|
30188 |
|
30189 | Geometry.include({
|
30190 | isDragging: function isDragging() {
|
30191 | if (this._getParent()) {
|
30192 | return this._getParent().isDragging();
|
30193 | }
|
30194 | if (this['draggable']) {
|
30195 | return this['draggable'].isDragging();
|
30196 | }
|
30197 | return false;
|
30198 | }
|
30199 | });
|
30200 |
|
30201 | Geometry.include({
|
30202 | startEdit: function startEdit(opts) {
|
30203 | if (!this.getMap() || !this.options['editable']) {
|
30204 | return this;
|
30205 | }
|
30206 | this.endEdit();
|
30207 | this._editor = new GeometryEditor(this, opts);
|
30208 | this._editor.start();
|
30209 |
|
30210 | this.fire('editstart');
|
30211 | return this;
|
30212 | },
|
30213 | endEdit: function endEdit() {
|
30214 | if (this._editor) {
|
30215 | this._editor.stop();
|
30216 | delete this._editor;
|
30217 |
|
30218 | this.fire('editend');
|
30219 | }
|
30220 | return this;
|
30221 | },
|
30222 | redoEdit: function redoEdit() {
|
30223 | if (!this.isEditing()) {
|
30224 | return this;
|
30225 | }
|
30226 | this._editor.redo();
|
30227 |
|
30228 | this.fire('redoedit');
|
30229 | return this;
|
30230 | },
|
30231 | undoEdit: function undoEdit() {
|
30232 | if (!this.isEditing()) {
|
30233 | return this;
|
30234 | }
|
30235 | this._editor.undo();
|
30236 |
|
30237 | this.fire('undoedit');
|
30238 | return this;
|
30239 | },
|
30240 | isEditing: function isEditing() {
|
30241 | if (this._editor) {
|
30242 | return this._editor.isEditing();
|
30243 | }
|
30244 | return false;
|
30245 | }
|
30246 | });
|
30247 |
|
30248 | Geometry.include({
|
30249 | _onEvent: function _onEvent(event, type) {
|
30250 | if (!this.getMap()) {
|
30251 | return;
|
30252 | }
|
30253 | var eventType = type || this._getEventTypeToFire(event);
|
30254 | if (eventType === 'contextmenu' && this.listens('contextmenu')) {
|
30255 | stopPropagation(event);
|
30256 | preventDefault(event);
|
30257 | }
|
30258 | var params = this._getEventParams(event);
|
30259 | this._fireEvent(eventType, params);
|
30260 | },
|
30261 |
|
30262 | _getEventTypeToFire: function _getEventTypeToFire(domEvent) {
|
30263 | return domEvent.type;
|
30264 | },
|
30265 |
|
30266 | _getEventParams: function _getEventParams(e) {
|
30267 | var map = this.getMap();
|
30268 | var eventParam = {
|
30269 | 'domEvent': e
|
30270 | };
|
30271 | var actual = e.touches && e.touches.length > 0 ? e.touches[0] : e.changedTouches && e.changedTouches.length > 0 ? e.changedTouches[0] : e;
|
30272 | if (actual) {
|
30273 | var containerPoint = getEventContainerPoint(actual, map._containerDOM);
|
30274 | eventParam['coordinate'] = map.containerPointToCoordinate(containerPoint);
|
30275 | eventParam['containerPoint'] = containerPoint;
|
30276 | eventParam['viewPoint'] = map.containerPointToViewPoint(containerPoint);
|
30277 | eventParam['pont2d'] = map._containerPointToPoint(containerPoint);
|
30278 | }
|
30279 | return eventParam;
|
30280 | }
|
30281 | });
|
30282 |
|
30283 | Geometry.include({
|
30284 | setInfoWindow: function setInfoWindow(options) {
|
30285 | this.removeInfoWindow();
|
30286 | if (options instanceof InfoWindow) {
|
30287 | this._infoWindow = options;
|
30288 | this._infoWinOptions = extend({}, this._infoWindow.options);
|
30289 | this._infoWindow.addTo(this);
|
30290 | return this;
|
30291 | }
|
30292 | this._infoWinOptions = extend({}, options);
|
30293 | if (this._infoWindow) {
|
30294 | this._infoWindow.setOptions(options);
|
30295 | } else if (this.getMap()) {
|
30296 | this._bindInfoWindow(this._infoWinOptions);
|
30297 | }
|
30298 |
|
30299 | return this;
|
30300 | },
|
30301 | getInfoWindow: function getInfoWindow() {
|
30302 | if (!this._infoWindow) {
|
30303 | return null;
|
30304 | }
|
30305 | return this._infoWindow;
|
30306 | },
|
30307 | openInfoWindow: function openInfoWindow(coordinate) {
|
30308 | if (!this.getMap()) {
|
30309 | return this;
|
30310 | }
|
30311 | if (!coordinate) {
|
30312 | coordinate = this.getCenter();
|
30313 | }
|
30314 | if (!this._infoWindow) {
|
30315 | if (this._infoWinOptions && this.getMap()) {
|
30316 | this._bindInfoWindow(this._infoWinOptions);
|
30317 | this._infoWindow.show(coordinate);
|
30318 | }
|
30319 | } else {
|
30320 | this._infoWindow.show(coordinate);
|
30321 | }
|
30322 | return this;
|
30323 | },
|
30324 | closeInfoWindow: function closeInfoWindow() {
|
30325 | if (this._infoWindow) {
|
30326 | this._infoWindow.hide();
|
30327 | }
|
30328 | return this;
|
30329 | },
|
30330 | removeInfoWindow: function removeInfoWindow() {
|
30331 | this._unbindInfoWindow();
|
30332 | delete this._infoWinOptions;
|
30333 | delete this._infoWindow;
|
30334 | return this;
|
30335 | },
|
30336 | _bindInfoWindow: function _bindInfoWindow(options) {
|
30337 | this._infoWindow = new InfoWindow(options);
|
30338 | this._infoWindow.addTo(this);
|
30339 |
|
30340 | return this;
|
30341 | },
|
30342 | _unbindInfoWindow: function _unbindInfoWindow() {
|
30343 | if (this._infoWindow) {
|
30344 | this.closeInfoWindow();
|
30345 | this._infoWindow.remove();
|
30346 | delete this._infoWindow;
|
30347 | }
|
30348 | return this;
|
30349 | }
|
30350 | });
|
30351 |
|
30352 | var LRUCache = function () {
|
30353 | function LRUCache(max, onRemove) {
|
30354 | classCallCheck(this, LRUCache);
|
30355 |
|
30356 | this.max = max;
|
30357 | this.onRemove = onRemove;
|
30358 | this.reset();
|
30359 | }
|
30360 |
|
30361 | LRUCache.prototype.reset = function reset() {
|
30362 | for (var key in this.data) {
|
30363 | this.onRemove(this.data[key]);
|
30364 | }
|
30365 |
|
30366 | this.data = {};
|
30367 | this.order = [];
|
30368 |
|
30369 | return this;
|
30370 | };
|
30371 |
|
30372 | LRUCache.prototype.clear = function clear() {
|
30373 | this.reset();
|
30374 | delete this.onRemove;
|
30375 | };
|
30376 |
|
30377 | LRUCache.prototype.add = function add(key, data) {
|
30378 |
|
30379 | if (this.has(key)) {
|
30380 | this.order.splice(this.order.indexOf(key), 1);
|
30381 | this.data[key] = data;
|
30382 | this.order.push(key);
|
30383 | } else {
|
30384 | this.data[key] = data;
|
30385 | this.order.push(key);
|
30386 |
|
30387 | if (this.order.length > this.max) {
|
30388 | var removedData = this.getAndRemove(this.order[0]);
|
30389 | if (removedData) this.onRemove(removedData);
|
30390 | }
|
30391 | }
|
30392 |
|
30393 | return this;
|
30394 | };
|
30395 |
|
30396 | LRUCache.prototype.has = function has(key) {
|
30397 | return key in this.data;
|
30398 | };
|
30399 |
|
30400 | LRUCache.prototype.keys = function keys() {
|
30401 | return this.order;
|
30402 | };
|
30403 |
|
30404 | LRUCache.prototype.getAndRemove = function getAndRemove(key) {
|
30405 | if (!this.has(key)) {
|
30406 | return null;
|
30407 | }
|
30408 |
|
30409 | var data = this.data[key];
|
30410 |
|
30411 | delete this.data[key];
|
30412 | this.order.splice(this.order.indexOf(key), 1);
|
30413 |
|
30414 | return data;
|
30415 | };
|
30416 |
|
30417 | LRUCache.prototype.get = function get$$1(key) {
|
30418 | if (!this.has(key)) {
|
30419 | return null;
|
30420 | }
|
30421 |
|
30422 | var data = this.data[key];
|
30423 | return data;
|
30424 | };
|
30425 |
|
30426 | LRUCache.prototype.remove = function remove(key) {
|
30427 | if (!this.has(key)) {
|
30428 | return this;
|
30429 | }
|
30430 |
|
30431 | var data = this.data[key];
|
30432 | delete this.data[key];
|
30433 | this.onRemove(data);
|
30434 | this.order.splice(this.order.indexOf(key), 1);
|
30435 |
|
30436 | return this;
|
30437 | };
|
30438 |
|
30439 | LRUCache.prototype.setMaxSize = function setMaxSize(max) {
|
30440 | this.max = max;
|
30441 |
|
30442 | while (this.order.length > this.max) {
|
30443 | var removedData = this.getAndRemove(this.order[0]);
|
30444 | if (removedData) this.onRemove(removedData);
|
30445 | }
|
30446 |
|
30447 | return this;
|
30448 | };
|
30449 |
|
30450 | return LRUCache;
|
30451 | }();
|
30452 |
|
30453 | var TileLayerCanvasRenderer = function (_CanvasRenderer) {
|
30454 | inherits(TileLayerCanvasRenderer, _CanvasRenderer);
|
30455 |
|
30456 | function TileLayerCanvasRenderer(layer) {
|
30457 | classCallCheck(this, TileLayerCanvasRenderer);
|
30458 |
|
30459 | var _this = possibleConstructorReturn(this, _CanvasRenderer.call(this, layer));
|
30460 |
|
30461 | _this.tilesInView = {};
|
30462 | _this.tilesLoading = {};
|
30463 | _this._parentTiles = [];
|
30464 | _this._childTiles = [];
|
30465 | _this.tileCache = new LRUCache(layer.options['maxCacheSize'], _this.deleteTile.bind(_this));
|
30466 | return _this;
|
30467 | }
|
30468 |
|
30469 | TileLayerCanvasRenderer.prototype.draw = function draw() {
|
30470 | var map = this.getMap();
|
30471 | if (!this.isDrawable()) {
|
30472 | return;
|
30473 | }
|
30474 | var mask2DExtent = this.prepareCanvas();
|
30475 | if (mask2DExtent) {
|
30476 | if (!mask2DExtent.intersects(this.canvasExtent2D)) {
|
30477 | this.completeRender();
|
30478 | return;
|
30479 | }
|
30480 | }
|
30481 | var layer = this.layer;
|
30482 | var tileGrids = layer.getTiles().tileGrids;
|
30483 | if (!tileGrids || !tileGrids.length) {
|
30484 | this.completeRender();
|
30485 | return;
|
30486 | }
|
30487 |
|
30488 | var loadingCount = 0;
|
30489 | var loading = false;
|
30490 | var checkedTiles = {};
|
30491 | var tiles = [],
|
30492 | parentTiles = [],
|
30493 | parentKeys = {},
|
30494 | childTiles = [],
|
30495 | childKeys = {},
|
30496 | placeholders = [],
|
30497 | placeholderKeys = {};
|
30498 |
|
30499 | var tileQueue = {};
|
30500 | var preLoadingCount = this._markTiles(),
|
30501 | loadingLimit = this._getLoadLimit();
|
30502 |
|
30503 | var l = tileGrids.length;
|
30504 |
|
30505 | this._tileZoom = tileGrids[0]['zoom'];
|
30506 | this._tileOffset = tileGrids[0]['offset'];
|
30507 |
|
30508 | for (var i = 0; i < l; i++) {
|
30509 | var tileGrid = tileGrids[i];
|
30510 | var allTiles = tileGrid['tiles'];
|
30511 |
|
30512 | var placeholder = this._generatePlaceHolder(tileGrid.zoom);
|
30513 |
|
30514 | for (var _i = 0, _l = allTiles.length; _i < _l; _i++) {
|
30515 | var tile = allTiles[_i],
|
30516 | tileId = tile['id'];
|
30517 |
|
30518 | var cached = this._getCachedTile(tileId);
|
30519 | var tileLoading = false;
|
30520 | if (this._isLoadingTile(tileId)) {
|
30521 | tileLoading = loading = true;
|
30522 | this.tilesLoading[tileId].current = true;
|
30523 | } else if (cached) {
|
30524 | if (this.getTileOpacity(cached.image) < 1) {
|
30525 | tileLoading = loading = true;
|
30526 | }
|
30527 | tiles.push(cached);
|
30528 | } else {
|
30529 | tileLoading = loading = true;
|
30530 | var hitLimit = loadingLimit && loadingCount + preLoadingCount[0] > loadingLimit;
|
30531 | if (!hitLimit && (!map.isInteracting() || map.isMoving() || map.isRotating())) {
|
30532 | loadingCount++;
|
30533 | tileQueue[tileId + '@' + tile['point'].toArray().join()] = tile;
|
30534 | }
|
30535 | }
|
30536 | if (!tileLoading) continue;
|
30537 | if (checkedTiles[tile.dupKey]) {
|
30538 | continue;
|
30539 | }
|
30540 |
|
30541 | checkedTiles[tile.dupKey] = 1;
|
30542 | if (placeholder && !placeholderKeys[tile.dupKey]) {
|
30543 | tile.cache = false;
|
30544 | placeholders.push({
|
30545 | image: placeholder,
|
30546 | info: tile
|
30547 | });
|
30548 |
|
30549 | placeholderKeys[tile.dupKey] = 1;
|
30550 | }
|
30551 |
|
30552 | var parentTile = this._findParentTile(tile);
|
30553 | if (parentTile) {
|
30554 | var dupKey = parentTile.info.dupKey;
|
30555 | if (parentKeys[dupKey] === undefined) {
|
30556 | parentKeys[dupKey] = parentTiles.length;
|
30557 | parentTiles.push(parentTile);
|
30558 | }
|
30559 | } else {
|
30560 | var children = this._findChildTiles(tile);
|
30561 | if (children.length) {
|
30562 | children.forEach(function (c) {
|
30563 | if (!childKeys[c.info.dupKey]) {
|
30564 | childTiles.push(c);
|
30565 | childKeys[c.info.dupKey] = 1;
|
30566 | }
|
30567 | });
|
30568 | }
|
30569 | }
|
30570 | }
|
30571 | }
|
30572 |
|
30573 | this._drawTiles(tiles, parentTiles, childTiles, placeholders);
|
30574 | if (!loadingCount) {
|
30575 | if (!loading) {
|
30576 | if (!map.isAnimating() && this._parentTiles.length > 0) {
|
30577 | this._parentTiles = [];
|
30578 | this._childTiles = [];
|
30579 | this.setToRedraw();
|
30580 | }
|
30581 | this.completeRender();
|
30582 | }
|
30583 | } else {
|
30584 | this.loadTileQueue(tileQueue);
|
30585 | }
|
30586 | this._retireTiles();
|
30587 | };
|
30588 |
|
30589 | TileLayerCanvasRenderer.prototype.isTileCachedOrLoading = function isTileCachedOrLoading(tileId) {
|
30590 | return this.tilesLoading[tileId] || this.tilesInView[tileId] || this.tileCache.has(tileId);
|
30591 | };
|
30592 |
|
30593 | TileLayerCanvasRenderer.prototype._drawTiles = function _drawTiles(tiles, parentTiles, childTiles, placeholders) {
|
30594 | var _this2 = this;
|
30595 |
|
30596 | if (parentTiles.length) {
|
30597 | parentTiles.sort(function (t1, t2) {
|
30598 | return Math.abs(t2.info.z - _this2._tileZoom) - Math.abs(t1.info.z - _this2._tileZoom);
|
30599 | });
|
30600 | this._parentTiles = parentTiles;
|
30601 | }
|
30602 | if (childTiles.length) {
|
30603 | this._childTiles = childTiles;
|
30604 | }
|
30605 |
|
30606 | var context = { tiles: tiles, parentTiles: parentTiles, childTiles: childTiles };
|
30607 | this.onDrawTileStart(context);
|
30608 |
|
30609 | this._parentTiles.forEach(function (t) {
|
30610 | return _this2._drawTileAndCache(t);
|
30611 | });
|
30612 | this._childTiles.forEach(function (t) {
|
30613 | return _this2._drawTileOffset(t.info, t.image);
|
30614 | });
|
30615 |
|
30616 | placeholders.forEach(function (t) {
|
30617 | return _this2._drawTileOffset(t.info, t.image);
|
30618 | });
|
30619 |
|
30620 | var layer = this.layer,
|
30621 | map = this.getMap();
|
30622 | if (!layer.options['cascadeTiles'] || map.getPitch() <= layer.options['minPitchToCascade']) {
|
30623 | tiles.forEach(function (t) {
|
30624 | return _this2._drawTileAndCache(t);
|
30625 | });
|
30626 | } else {
|
30627 | this.writeZoomStencil();
|
30628 | var started = false;
|
30629 | for (var i = 0, l = tiles.length; i < l; i++) {
|
30630 | if (tiles[i].info.z !== this._tileZoom) {
|
30631 | if (!started) {
|
30632 | this.startZoomStencilTest();
|
30633 | started = true;
|
30634 | } else {
|
30635 | this.resumeZoomStencilTest();
|
30636 | }
|
30637 | } else if (started) {
|
30638 | this.pauseZoomStencilTest();
|
30639 | }
|
30640 | this._drawTileAndCache(tiles[i]);
|
30641 | }
|
30642 | this.endZoomStencilTest();
|
30643 | }
|
30644 |
|
30645 | this.onDrawTileEnd(context);
|
30646 | };
|
30647 |
|
30648 | TileLayerCanvasRenderer.prototype.writeZoomStencil = function writeZoomStencil() {};
|
30649 |
|
30650 | TileLayerCanvasRenderer.prototype.startZoomStencilTest = function startZoomStencilTest() {};
|
30651 |
|
30652 | TileLayerCanvasRenderer.prototype.endZoomStencilTest = function endZoomStencilTest() {};
|
30653 |
|
30654 | TileLayerCanvasRenderer.prototype.pauseZoomStencilTest = function pauseZoomStencilTest() {};
|
30655 |
|
30656 | TileLayerCanvasRenderer.prototype.resumeZoomStencilTest = function resumeZoomStencilTest() {};
|
30657 |
|
30658 | TileLayerCanvasRenderer.prototype.onDrawTileStart = function onDrawTileStart() {};
|
30659 |
|
30660 | TileLayerCanvasRenderer.prototype.onDrawTileEnd = function onDrawTileEnd() {};
|
30661 |
|
30662 | TileLayerCanvasRenderer.prototype._drawTileOffset = function _drawTileOffset(info, image) {
|
30663 | var offset = this._tileOffset;
|
30664 | if (!offset[0] && !offset[1]) {
|
30665 | this.drawTile(info, image);
|
30666 | return;
|
30667 | }
|
30668 | var map = this.getMap();
|
30669 |
|
30670 | var scale = map._getResolution(this._tileZoom) / map._getResolution(info.z);
|
30671 | offset[0] *= scale;
|
30672 | offset[1] *= scale;
|
30673 | info.point._sub(offset);
|
30674 | info.extent2d._sub(offset);
|
30675 | this.drawTile(info, image);
|
30676 |
|
30677 | info.point._add(offset);
|
30678 | info.extent2d._add(offset);
|
30679 | offset[0] /= scale;
|
30680 | offset[1] /= scale;
|
30681 | };
|
30682 |
|
30683 | TileLayerCanvasRenderer.prototype._drawTileAndCache = function _drawTileAndCache(tile) {
|
30684 | tile.current = true;
|
30685 | this.tilesInView[tile.info.id] = tile;
|
30686 | this._drawTileOffset(tile.info, tile.image);
|
30687 | this.tileCache.add(tile.info.id, tile);
|
30688 | };
|
30689 |
|
30690 | TileLayerCanvasRenderer.prototype.drawOnInteracting = function drawOnInteracting() {
|
30691 | this.draw();
|
30692 | };
|
30693 |
|
30694 | TileLayerCanvasRenderer.prototype.needToRedraw = function needToRedraw() {
|
30695 | var map = this.getMap();
|
30696 | if (map.getPitch()) {
|
30697 | return _CanvasRenderer.prototype.needToRedraw.call(this);
|
30698 | }
|
30699 | if (map.isRotating() || map.isZooming()) {
|
30700 | return true;
|
30701 | }
|
30702 | if (map.isMoving()) {
|
30703 | return !!this.layer.options['forceRenderOnMoving'];
|
30704 | }
|
30705 | return _CanvasRenderer.prototype.needToRedraw.call(this);
|
30706 | };
|
30707 |
|
30708 | TileLayerCanvasRenderer.prototype.hitDetect = function hitDetect() {
|
30709 | return false;
|
30710 | };
|
30711 |
|
30712 | TileLayerCanvasRenderer.prototype._getLoadLimit = function _getLoadLimit() {
|
30713 | if (this.getMap().isInteracting()) {
|
30714 | return this.layer.options['loadingLimitOnInteracting'];
|
30715 | }
|
30716 | return 0;
|
30717 | };
|
30718 |
|
30719 | TileLayerCanvasRenderer.prototype.isDrawable = function isDrawable() {
|
30720 | if (this.getMap().getPitch()) {
|
30721 | if (console) {
|
30722 | console.warn('TileLayer with canvas renderer can\'t be pitched, use gl renderer (\'renderer\' : \'gl\') instead.');
|
30723 | }
|
30724 | this.clear();
|
30725 | return false;
|
30726 | }
|
30727 | return true;
|
30728 | };
|
30729 |
|
30730 | TileLayerCanvasRenderer.prototype.clear = function clear() {
|
30731 | this._retireTiles(true);
|
30732 | this.tileCache.reset();
|
30733 | this.tilesInView = {};
|
30734 | this.tilesLoading = {};
|
30735 | this._parentTiles = [];
|
30736 | this._childTiles = [];
|
30737 | _CanvasRenderer.prototype.clear.call(this);
|
30738 | };
|
30739 |
|
30740 | TileLayerCanvasRenderer.prototype._isLoadingTile = function _isLoadingTile(tileId) {
|
30741 | return !!this.tilesLoading[tileId];
|
30742 | };
|
30743 |
|
30744 | TileLayerCanvasRenderer.prototype.clipCanvas = function clipCanvas(context) {
|
30745 | var mask = this.layer.getMask();
|
30746 | if (!mask) {
|
30747 | return this._clipByPitch(context);
|
30748 | }
|
30749 | return _CanvasRenderer.prototype.clipCanvas.call(this, context);
|
30750 | };
|
30751 |
|
30752 | TileLayerCanvasRenderer.prototype._clipByPitch = function _clipByPitch(ctx) {
|
30753 | var map = this.getMap();
|
30754 | if (map.getPitch() <= map.options['maxVisualPitch']) {
|
30755 | return false;
|
30756 | }
|
30757 | if (!this.layer.options['clipByPitch']) {
|
30758 | return false;
|
30759 | }
|
30760 | var clipExtent = map.getContainerExtent();
|
30761 | var r = Browser$1.retina ? 2 : 1;
|
30762 | ctx.save();
|
30763 | ctx.strokeStyle = 'rgba(0, 0, 0, 0)';
|
30764 | ctx.beginPath();
|
30765 | ctx.rect(0, Math.ceil(clipExtent.ymin) * r, Math.ceil(clipExtent.getWidth()) * r, Math.ceil(clipExtent.getHeight()) * r);
|
30766 | ctx.stroke();
|
30767 | ctx.clip();
|
30768 | return true;
|
30769 | };
|
30770 |
|
30771 | TileLayerCanvasRenderer.prototype.loadTileQueue = function loadTileQueue(tileQueue) {
|
30772 | for (var p in tileQueue) {
|
30773 | if (tileQueue.hasOwnProperty(p)) {
|
30774 | var tile = tileQueue[p];
|
30775 | var tileImage = this.loadTile(tile);
|
30776 | if (tileImage.loadTime === undefined) {
|
30777 | this.tilesLoading[tile['id']] = {
|
30778 | image: tileImage,
|
30779 | current: true,
|
30780 | info: tile
|
30781 | };
|
30782 | }
|
30783 | }
|
30784 | }
|
30785 | };
|
30786 |
|
30787 | TileLayerCanvasRenderer.prototype.loadTile = function loadTile(tile) {
|
30788 | var tileSize = this.layer.getTileSize();
|
30789 | var tileImage = new Image();
|
30790 |
|
30791 | tileImage.width = tileSize['width'];
|
30792 | tileImage.height = tileSize['height'];
|
30793 |
|
30794 | tileImage.onload = this.onTileLoad.bind(this, tileImage, tile);
|
30795 | tileImage.onerror = this.onTileError.bind(this, tileImage, tile);
|
30796 |
|
30797 | var crossOrigin = this.layer.options['crossOrigin'];
|
30798 | if (!isNil(crossOrigin)) {
|
30799 | tileImage.crossOrigin = crossOrigin;
|
30800 | }
|
30801 | this.loadTileImage(tileImage, tile['url']);
|
30802 | return tileImage;
|
30803 | };
|
30804 |
|
30805 | TileLayerCanvasRenderer.prototype.loadTileImage = function loadTileImage(tileImage, url) {
|
30806 | return loadImage(tileImage, [url]);
|
30807 | };
|
30808 |
|
30809 | TileLayerCanvasRenderer.prototype.abortTileLoading = function abortTileLoading(tileImage) {
|
30810 | if (!tileImage) return;
|
30811 | tileImage.onload = falseFn;
|
30812 | tileImage.onerror = falseFn;
|
30813 | tileImage.src = emptyImageUrl;
|
30814 | };
|
30815 |
|
30816 | TileLayerCanvasRenderer.prototype.onTileLoad = function onTileLoad(tileImage, tileInfo) {
|
30817 | if (!this.layer) {
|
30818 | return;
|
30819 | }
|
30820 | var id = tileInfo['id'];
|
30821 | if (!this.tilesInView) {
|
30822 | return;
|
30823 | }
|
30824 | tileImage.loadTime = now();
|
30825 | delete this.tilesLoading[id];
|
30826 | this._addTileToCache(tileInfo, tileImage);
|
30827 | this.setToRedraw();
|
30828 |
|
30829 | this.layer.fire('tileload', { tile: tileInfo, tileImage: tileImage });
|
30830 | };
|
30831 |
|
30832 | TileLayerCanvasRenderer.prototype.onTileError = function onTileError(tileImage, tileInfo) {
|
30833 | if (!this.layer) {
|
30834 | return;
|
30835 | }
|
30836 | if (tileImage instanceof Image) {
|
30837 | this.abortTileLoading(tileImage);
|
30838 | }
|
30839 | tileImage.loadTime = 0;
|
30840 | delete this.tilesLoading[tileInfo['id']];
|
30841 | this._addTileToCache(tileInfo, tileImage);
|
30842 | this.setToRedraw();
|
30843 |
|
30844 | this.layer.fire('tileerror', { tile: tileInfo });
|
30845 | };
|
30846 |
|
30847 | TileLayerCanvasRenderer.prototype.drawTile = function drawTile(tileInfo, tileImage) {
|
30848 | if (!tileImage || !this.getMap()) {
|
30849 | return;
|
30850 | }
|
30851 | var point = tileInfo.point,
|
30852 | tileZoom = tileInfo.z,
|
30853 | tileId = tileInfo.id;
|
30854 | var map = this.getMap(),
|
30855 | tileSize = tileInfo.size,
|
30856 | zoom = map.getZoom(),
|
30857 | ctx = this.context,
|
30858 | cp = map._pointToContainerPoint(point, tileZoom),
|
30859 | bearing = map.getBearing(),
|
30860 | transformed = bearing || zoom !== tileZoom;
|
30861 | var opacity = this.getTileOpacity(tileImage);
|
30862 | var alpha = ctx.globalAlpha;
|
30863 | if (opacity < 1) {
|
30864 | ctx.globalAlpha = opacity;
|
30865 | this.setToRedraw();
|
30866 | }
|
30867 | if (!transformed) {
|
30868 | cp._round();
|
30869 | }
|
30870 | var x = cp.x,
|
30871 | y = cp.y;
|
30872 | var w = tileSize[0],
|
30873 | h = tileSize[1];
|
30874 | if (transformed) {
|
30875 | w++;
|
30876 | h++;
|
30877 | ctx.save();
|
30878 | ctx.translate(x, y);
|
30879 | if (bearing) {
|
30880 | ctx.rotate(-bearing * Math.PI / 180);
|
30881 | }
|
30882 | if (zoom !== tileZoom) {
|
30883 | var scale = map._getResolution(tileZoom) / map._getResolution();
|
30884 | ctx.scale(scale, scale);
|
30885 | }
|
30886 | x = y = 0;
|
30887 | }
|
30888 | Canvas.image(ctx, tileImage, x, y, w, h);
|
30889 | if (this.layer.options['debug']) {
|
30890 | var p = new Point(x, y),
|
30891 | color = this.layer.options['debugOutline'],
|
30892 | xyz = tileId.split('__');
|
30893 | ctx.save();
|
30894 | ctx.strokeStyle = color;
|
30895 | ctx.fillStyle = color;
|
30896 | ctx.strokeWidth = 10;
|
30897 | ctx.font = '15px monospace';
|
30898 | Canvas.rectangle(ctx, p, tileSize, 1, 0);
|
30899 | Canvas.fillText(ctx, 'x:' + xyz[2] + ', y:' + xyz[1] + ', z:' + xyz[3], p.add(10, 20), color);
|
30900 | Canvas.drawCross(ctx, p.add(w / 2, h / 2), 2, color);
|
30901 | ctx.restore();
|
30902 | }
|
30903 | if (transformed) {
|
30904 | ctx.restore();
|
30905 | }
|
30906 | if (ctx.globalAlpha !== alpha) {
|
30907 | ctx.globalAlpha = alpha;
|
30908 | }
|
30909 | this.setCanvasUpdated();
|
30910 | };
|
30911 |
|
30912 | TileLayerCanvasRenderer.prototype._findChildTiles = function _findChildTiles(info) {
|
30913 | var layer = this._getLayerOfTile(info.layer);
|
30914 | if (!layer.options['background']) {
|
30915 | return [];
|
30916 | }
|
30917 | var map = this.getMap();
|
30918 | var children = [];
|
30919 | var min = info.extent2d.getMin(),
|
30920 | max = info.extent2d.getMax(),
|
30921 | pmin = layer._project(map._pointToPrj(min, info.z)),
|
30922 | pmax = layer._project(map._pointToPrj(max, info.z));
|
30923 | var zoomDiff = 3;
|
30924 | for (var i = 1; i < zoomDiff; i++) {
|
30925 | this._findChildTilesAt(children, pmin, pmax, layer, info.z + i);
|
30926 | }
|
30927 |
|
30928 | return children;
|
30929 | };
|
30930 |
|
30931 | TileLayerCanvasRenderer.prototype._findChildTilesAt = function _findChildTilesAt(children, pmin, pmax, layer, childZoom) {
|
30932 | var layerId = layer.getId(),
|
30933 | res = layer.getSpatialReference().getResolution(childZoom);
|
30934 | var dmin = layer._getTileConfig().getTileIndex(pmin, res),
|
30935 | dmax = layer._getTileConfig().getTileIndex(pmax, res);
|
30936 | var sx = Math.min(dmin.idx, dmax.idx),
|
30937 | ex = Math.max(dmin.idx, dmax.idx);
|
30938 | var sy = Math.min(dmin.idy, dmax.idy),
|
30939 | ey = Math.max(dmin.idy, dmax.idy);
|
30940 | var id = void 0,
|
30941 | tile = void 0;
|
30942 | for (var i = sx; i < ex; i++) {
|
30943 | for (var ii = sy; ii < ey; ii++) {
|
30944 | id = layer._getTileId({ idx: i, idy: ii }, childZoom, layerId);
|
30945 | if (this.tileCache.has(id)) {
|
30946 | tile = this.tileCache.getAndRemove(id);
|
30947 | children.push(tile);
|
30948 | this.tileCache.add(id, tile);
|
30949 | }
|
30950 | }
|
30951 | }
|
30952 | };
|
30953 |
|
30954 | TileLayerCanvasRenderer.prototype._findParentTile = function _findParentTile(info) {
|
30955 | var map = this.getMap(),
|
30956 | layer = this._getLayerOfTile(info.layer);
|
30957 | if (!layer.options['background']) {
|
30958 | return null;
|
30959 | }
|
30960 | var sr = layer.getSpatialReference();
|
30961 | var d = sr.getZoomDirection(),
|
30962 | zoomDiff = layer.options['backgroundZoomDiff'];
|
30963 | var center = info.extent2d.getCenter(),
|
30964 | prj = layer._project(map._pointToPrj(center, info.z));
|
30965 | for (var diff = 1; diff <= zoomDiff; diff++) {
|
30966 | var z = info.z - d * diff;
|
30967 | var res = sr.getResolution(z);
|
30968 | var tileIndex = layer._getTileConfig().getTileIndex(prj, res);
|
30969 | var id = layer._getTileId(tileIndex, z, info.layer);
|
30970 | if (this.tileCache.has(id)) {
|
30971 | var tile = this.tileCache.getAndRemove(id);
|
30972 | this.tileCache.add(id, tile);
|
30973 | return tile;
|
30974 | }
|
30975 | }
|
30976 | return null;
|
30977 | };
|
30978 |
|
30979 | TileLayerCanvasRenderer.prototype._getLayerOfTile = function _getLayerOfTile(layerId) {
|
30980 | return this.layer.getChildLayer ? this.layer.getChildLayer(layerId) : this.layer;
|
30981 | };
|
30982 |
|
30983 | TileLayerCanvasRenderer.prototype._getCachedTile = function _getCachedTile(tileId) {
|
30984 | var tilesInView = this.tilesInView;
|
30985 | var cached = this.tileCache.getAndRemove(tileId);
|
30986 | if (cached) {
|
30987 | tilesInView[tileId] = cached;
|
30988 | var tilesLoading = this.tilesLoading;
|
30989 | if (tilesLoading && tilesLoading[tileId]) {
|
30990 | tilesLoading[tileId].current = false;
|
30991 | this.abortTileLoading(tilesLoading[tileId]);
|
30992 | delete tilesLoading[tileId];
|
30993 | }
|
30994 | } else {
|
30995 | cached = tilesInView[tileId];
|
30996 | }
|
30997 | return cached;
|
30998 | };
|
30999 |
|
31000 | TileLayerCanvasRenderer.prototype._addTileToCache = function _addTileToCache(tileInfo, tileImage) {
|
31001 | this.tilesInView[tileInfo.id] = {
|
31002 | image: tileImage,
|
31003 | current: true,
|
31004 | info: tileInfo
|
31005 | };
|
31006 | };
|
31007 |
|
31008 | TileLayerCanvasRenderer.prototype.getTileOpacity = function getTileOpacity(tileImage) {
|
31009 | if (!this.layer.options['fadeAnimation'] || !tileImage.loadTime) {
|
31010 | return 1;
|
31011 | }
|
31012 | return Math.min(1, (now() - tileImage.loadTime) / (1000 / 60 * 10));
|
31013 | };
|
31014 |
|
31015 | TileLayerCanvasRenderer.prototype.onRemove = function onRemove() {
|
31016 | this.clear();
|
31017 | delete this.tileCache;
|
31018 | delete this._tilePlaceHolder;
|
31019 | _CanvasRenderer.prototype.onRemove.call(this);
|
31020 | };
|
31021 |
|
31022 | TileLayerCanvasRenderer.prototype._markTiles = function _markTiles() {
|
31023 | var a = 0,
|
31024 | b = 0;
|
31025 | if (this.tilesLoading) {
|
31026 | for (var p in this.tilesLoading) {
|
31027 | this.tilesLoading[p].current = false;
|
31028 | a++;
|
31029 | }
|
31030 | }
|
31031 | if (this.tilesInView) {
|
31032 | for (var _p in this.tilesInView) {
|
31033 | this.tilesInView[_p].current = false;
|
31034 | b++;
|
31035 | }
|
31036 | }
|
31037 | return [a, b];
|
31038 | };
|
31039 |
|
31040 | TileLayerCanvasRenderer.prototype._retireTiles = function _retireTiles(force) {
|
31041 | for (var i in this.tilesLoading) {
|
31042 | var tile = this.tilesLoading[i];
|
31043 | if (force || !tile.current) {
|
31044 | if (tile.image) {
|
31045 | this.abortTileLoading(tile.image);
|
31046 | }
|
31047 | this.deleteTile(tile);
|
31048 | delete this.tilesLoading[i];
|
31049 | }
|
31050 | }
|
31051 | for (var _i2 in this.tilesInView) {
|
31052 | var _tile = this.tilesInView[_i2];
|
31053 | if (!_tile.current) {
|
31054 | delete this.tilesInView[_i2];
|
31055 | if (!this.tileCache.has(_i2)) {
|
31056 | this.deleteTile(_tile);
|
31057 | }
|
31058 | }
|
31059 | }
|
31060 | };
|
31061 |
|
31062 | TileLayerCanvasRenderer.prototype.deleteTile = function deleteTile(tile) {
|
31063 | if (!tile || !tile.image) {
|
31064 | return;
|
31065 | }
|
31066 | tile.image.onload = null;
|
31067 | tile.image.onerror = null;
|
31068 | };
|
31069 |
|
31070 | TileLayerCanvasRenderer.prototype._generatePlaceHolder = function _generatePlaceHolder(z) {
|
31071 | var map = this.getMap();
|
31072 | var placeholder = this.layer.options['placeholder'];
|
31073 | if (!placeholder || map.getPitch()) {
|
31074 | return null;
|
31075 | }
|
31076 | var tileSize = this.layer.getTileSize(),
|
31077 | scale = map._getResolution(z) / map._getResolution(),
|
31078 | canvas = this._tilePlaceHolder = this._tilePlaceHolder || Canvas.createCanvas(1, 1);
|
31079 | canvas.width = tileSize.width * scale;
|
31080 | canvas.height = tileSize.height * scale;
|
31081 | if (isFunction(placeholder)) {
|
31082 | placeholder(canvas);
|
31083 | } else {
|
31084 | defaultPlaceholder(canvas);
|
31085 | }
|
31086 | return canvas;
|
31087 | };
|
31088 |
|
31089 | return TileLayerCanvasRenderer;
|
31090 | }(CanvasRenderer);
|
31091 |
|
31092 | TileLayer.registerRenderer('canvas', TileLayerCanvasRenderer);
|
31093 |
|
31094 | function falseFn() {
|
31095 | return false;
|
31096 | }
|
31097 |
|
31098 | function defaultPlaceholder(canvas) {
|
31099 | var ctx = canvas.getContext('2d'),
|
31100 | cw = canvas.width,
|
31101 | ch = canvas.height,
|
31102 | w = cw / 16,
|
31103 | h = ch / 16;
|
31104 | ctx.beginPath();
|
31105 | for (var i = 0; i < 16; i++) {
|
31106 | ctx.moveTo(0, i * h);
|
31107 | ctx.lineTo(cw, i * h);
|
31108 | ctx.moveTo(i * w, 0);
|
31109 | ctx.lineTo(i * w, ch);
|
31110 | }
|
31111 | ctx.strokeStyle = 'rgba(180, 180, 180, 0.1)';
|
31112 | ctx.lineWidth = 1;
|
31113 | ctx.stroke();
|
31114 | ctx.beginPath();
|
31115 | var path = [[0, 0], [cw, 0], [0, ch], [cw, ch], [0, 0], [0, ch], [cw, 0], [cw, ch], [0, ch / 2], [cw, ch / 2], [cw / 2, 0], [cw / 2, ch]];
|
31116 | for (var _i3 = 1; _i3 < path.length; _i3 += 2) {
|
31117 | ctx.moveTo(path[_i3 - 1][0], path[_i3 - 1][1]);
|
31118 | ctx.lineTo(path[_i3][0], path[_i3][1]);
|
31119 | }
|
31120 | ctx.lineWidth = 1 * 4;
|
31121 | ctx.stroke();
|
31122 | }
|
31123 |
|
31124 | var TileLayerGLRenderer$1 = function (_ImageGLRenderable) {
|
31125 | inherits(TileLayerGLRenderer, _ImageGLRenderable);
|
31126 |
|
31127 | function TileLayerGLRenderer() {
|
31128 | classCallCheck(this, TileLayerGLRenderer);
|
31129 | return possibleConstructorReturn(this, _ImageGLRenderable.apply(this, arguments));
|
31130 | }
|
31131 |
|
31132 | TileLayerGLRenderer.prototype.isDrawable = function isDrawable() {
|
31133 | return true;
|
31134 | };
|
31135 |
|
31136 | TileLayerGLRenderer.prototype.needToRedraw = function needToRedraw() {
|
31137 | var map = this.getMap();
|
31138 | if (this._gl() && !map.getPitch() && map.isZooming() && !map.isMoving() && !map.isRotating()) {
|
31139 | return true;
|
31140 | }
|
31141 | return _ImageGLRenderable.prototype.needToRedraw.call(this);
|
31142 | };
|
31143 |
|
31144 | TileLayerGLRenderer.prototype.drawTile = function drawTile(tileInfo, tileImage) {
|
31145 | var map = this.getMap();
|
31146 | if (!tileInfo || !map) {
|
31147 | return;
|
31148 | }
|
31149 | if (tileImage.src === emptyImageUrl) {
|
31150 | return;
|
31151 | }
|
31152 |
|
31153 | var scale = map.getGLScale(tileInfo.z),
|
31154 | w = tileInfo.size[0] * scale,
|
31155 | h = tileInfo.size[1] * scale;
|
31156 | if (tileInfo.cache !== false) {
|
31157 | this._bindGLBuffer(tileImage, w, h);
|
31158 | }
|
31159 | if (!this._gl()) {
|
31160 | _ImageGLRenderable.prototype.drawTile.call(this, tileInfo, tileImage);
|
31161 | return;
|
31162 | }
|
31163 | var point = tileInfo.point;
|
31164 | var x = point.x * scale,
|
31165 | y = point.y * scale;
|
31166 | var opacity = this.getTileOpacity(tileImage);
|
31167 | this.drawGLImage(tileImage, x, y, w, h, opacity);
|
31168 |
|
31169 | if (opacity < 1) {
|
31170 | this.setToRedraw();
|
31171 | } else {
|
31172 | this.setCanvasUpdated();
|
31173 | }
|
31174 | };
|
31175 |
|
31176 | TileLayerGLRenderer.prototype.writeZoomStencil = function writeZoomStencil() {
|
31177 | var gl = this.gl;
|
31178 | gl.stencilFunc(gl.ALWAYS, 1, 0xFF);
|
31179 | gl.stencilOp(gl.KEEP, gl.KEEP, gl.REPLACE);
|
31180 | };
|
31181 |
|
31182 | TileLayerGLRenderer.prototype.startZoomStencilTest = function startZoomStencilTest() {
|
31183 | var gl = this.gl;
|
31184 | gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
|
31185 | gl.stencilFunc(gl.EQUAL, 0, 0xFF);
|
31186 | };
|
31187 |
|
31188 | TileLayerGLRenderer.prototype.endZoomStencilTest = function endZoomStencilTest() {
|
31189 | this.pauseZoomStencilTest();
|
31190 | };
|
31191 |
|
31192 | TileLayerGLRenderer.prototype.pauseZoomStencilTest = function pauseZoomStencilTest() {
|
31193 | var gl = this.gl;
|
31194 | gl.stencilFunc(gl.ALWAYS, 1, 0xFF);
|
31195 | };
|
31196 |
|
31197 | TileLayerGLRenderer.prototype.resumeZoomStencilTest = function resumeZoomStencilTest() {
|
31198 | var gl = this.gl;
|
31199 | gl.stencilFunc(gl.EQUAL, 0, 0xFF);
|
31200 | };
|
31201 |
|
31202 | TileLayerGLRenderer.prototype._bindGLBuffer = function _bindGLBuffer(image, w, h) {
|
31203 | if (!image.glBuffer) {
|
31204 | image.glBuffer = this.bufferTileData(0, 0, w, h);
|
31205 | }
|
31206 | };
|
31207 |
|
31208 | TileLayerGLRenderer.prototype.loadTileImage = function loadTileImage(tileImage, url) {
|
31209 | tileImage.crossOrigin = this.layer.options['crossOrigin'] || '';
|
31210 | tileImage.src = url;
|
31211 | return;
|
31212 | };
|
31213 |
|
31214 | TileLayerGLRenderer.prototype.onCanvasCreate = function onCanvasCreate() {
|
31215 | this.createCanvas2();
|
31216 | };
|
31217 |
|
31218 | TileLayerGLRenderer.prototype.createContext = function createContext() {
|
31219 | _ImageGLRenderable.prototype.createContext.call(this);
|
31220 | this.createGLContext();
|
31221 | };
|
31222 |
|
31223 | TileLayerGLRenderer.prototype.resizeCanvas = function resizeCanvas(canvasSize) {
|
31224 | if (!this.canvas) {
|
31225 | return;
|
31226 | }
|
31227 | _ImageGLRenderable.prototype.resizeCanvas.call(this, canvasSize);
|
31228 | this.resizeGLCanvas();
|
31229 | };
|
31230 |
|
31231 | TileLayerGLRenderer.prototype.clearCanvas = function clearCanvas() {
|
31232 | if (!this.canvas) {
|
31233 | return;
|
31234 | }
|
31235 | _ImageGLRenderable.prototype.clearCanvas.call(this);
|
31236 | this.clearGLCanvas();
|
31237 | };
|
31238 |
|
31239 | TileLayerGLRenderer.prototype.getCanvasImage = function getCanvasImage() {
|
31240 | if (!this._gl()) {
|
31241 | return _ImageGLRenderable.prototype.getCanvasImage.call(this);
|
31242 | }
|
31243 | var img = _ImageGLRenderable.prototype.getCanvasImage.call(this);
|
31244 | if (img) {
|
31245 | img.image = this.canvas2;
|
31246 | }
|
31247 | return img;
|
31248 | };
|
31249 |
|
31250 | TileLayerGLRenderer.prototype._gl = function _gl() {
|
31251 | return this.getMap() && !!this.getMap().getPitch() || this.layer && !!this.layer.options['fragmentShader'];
|
31252 | };
|
31253 |
|
31254 | TileLayerGLRenderer.prototype.deleteTile = function deleteTile(tile) {
|
31255 | _ImageGLRenderable.prototype.deleteTile.call(this, tile);
|
31256 | if (tile && tile.image) {
|
31257 | this.disposeImage(tile.image);
|
31258 | }
|
31259 | };
|
31260 |
|
31261 | TileLayerGLRenderer.prototype.onRemove = function onRemove() {
|
31262 | this.removeGLCanvas();
|
31263 | };
|
31264 |
|
31265 | return TileLayerGLRenderer;
|
31266 | }(ImageGLRenderable(TileLayerCanvasRenderer));
|
31267 |
|
31268 | TileLayer.registerRenderer('gl', TileLayerGLRenderer$1);
|
31269 |
|
31270 | function _loadTile(tile) {
|
31271 | var tileSize = this.layer.getTileSize(),
|
31272 | canvasClass = this.canvas.constructor,
|
31273 | map = this.getMap();
|
31274 | var r = Browser$1.retina ? 2 : 1;
|
31275 | var tileCanvas = Canvas.createCanvas(tileSize['width'] * r, tileSize['height'] * r, canvasClass);
|
31276 | tileCanvas['layer'] = this.layer;
|
31277 | var me = this;
|
31278 | var extent = new Extent(map.pointToCoordinate(tile['point']), map.pointToCoordinate(tile['point'].add(tileSize.toPoint())), map.getProjection());
|
31279 | this.layer.drawTile(tileCanvas, {
|
31280 | 'url': tile['url'],
|
31281 | 'point': tile['point'],
|
31282 | 'center': map.pointToCoordinate(tile['point'].add(tileSize['width'] / 2, tileSize['height'] / 2)),
|
31283 | 'extent': extent,
|
31284 | 'z': tile['z'],
|
31285 | 'x': tile['x'],
|
31286 | 'y': tile['y']
|
31287 | }, function (error) {
|
31288 | if (error) {
|
31289 | me.onTileError(tileCanvas, tile);
|
31290 | return;
|
31291 | }
|
31292 | me.onTileLoad(tileCanvas, tile);
|
31293 | });
|
31294 | return tileCanvas;
|
31295 | }
|
31296 |
|
31297 | var CanvasRenderer$2 = function (_TileLayerCanvasRende) {
|
31298 | inherits(CanvasRenderer, _TileLayerCanvasRende);
|
31299 |
|
31300 | function CanvasRenderer() {
|
31301 | classCallCheck(this, CanvasRenderer);
|
31302 | return possibleConstructorReturn(this, _TileLayerCanvasRende.apply(this, arguments));
|
31303 | }
|
31304 |
|
31305 | CanvasRenderer.prototype.loadTile = function loadTile() {
|
31306 | return _loadTile.apply(this, arguments);
|
31307 | };
|
31308 |
|
31309 | return CanvasRenderer;
|
31310 | }(TileLayerCanvasRenderer);
|
31311 |
|
31312 | var GLRenderer = function (_TileLayerGLRenderer) {
|
31313 | inherits(GLRenderer, _TileLayerGLRenderer);
|
31314 |
|
31315 | function GLRenderer() {
|
31316 | classCallCheck(this, GLRenderer);
|
31317 | return possibleConstructorReturn(this, _TileLayerGLRenderer.apply(this, arguments));
|
31318 | }
|
31319 |
|
31320 | GLRenderer.prototype.loadTile = function loadTile() {
|
31321 | return _loadTile.apply(this, arguments);
|
31322 | };
|
31323 |
|
31324 | return GLRenderer;
|
31325 | }(TileLayerCanvasRenderer);
|
31326 |
|
31327 | CanvasTileLayer.registerRenderer('canvas', CanvasRenderer$2);
|
31328 | CanvasTileLayer.registerRenderer('gl', GLRenderer);
|
31329 |
|
31330 | var OverlayLayerRenderer = function (_CanvasRenderer) {
|
31331 | inherits(OverlayLayerRenderer, _CanvasRenderer);
|
31332 |
|
31333 | function OverlayLayerRenderer() {
|
31334 | classCallCheck(this, OverlayLayerRenderer);
|
31335 | return possibleConstructorReturn(this, _CanvasRenderer.apply(this, arguments));
|
31336 | }
|
31337 |
|
31338 | OverlayLayerRenderer.prototype.checkResources = function checkResources() {
|
31339 | var geometries = this._geosToCheck;
|
31340 | if (!this._resourceChecked && !geometries) {
|
31341 | geometries = this.layer._geoList;
|
31342 | }
|
31343 | if (!isArrayHasData(geometries)) {
|
31344 | return [];
|
31345 | }
|
31346 | var resources = [];
|
31347 | var cache = {};
|
31348 |
|
31349 | for (var i = geometries.length - 1; i >= 0; i--) {
|
31350 | var geo = geometries[i];
|
31351 | var res = geo._getExternalResources();
|
31352 | if (!res.length) {
|
31353 | continue;
|
31354 | }
|
31355 | if (!this.resources) {
|
31356 | resources.push.apply(resources, res);
|
31357 | } else {
|
31358 | for (var _i = 0; _i < res.length; _i++) {
|
31359 | var url = res[_i][0];
|
31360 | if (!this.resources.isResourceLoaded(res[_i]) && !cache[url]) {
|
31361 | resources.push(res[_i]);
|
31362 | cache[url] = 1;
|
31363 | }
|
31364 | }
|
31365 | }
|
31366 | }
|
31367 | this._resourceChecked = true;
|
31368 | delete this._geosToCheck;
|
31369 | return resources;
|
31370 | };
|
31371 |
|
31372 | OverlayLayerRenderer.prototype.render = function render() {
|
31373 | this.layer._sortGeometries();
|
31374 | return _CanvasRenderer.prototype.render.apply(this, arguments);
|
31375 | };
|
31376 |
|
31377 | OverlayLayerRenderer.prototype._addGeoToCheckRes = function _addGeoToCheckRes(res) {
|
31378 | if (!res) {
|
31379 | return;
|
31380 | }
|
31381 | if (!Array.isArray(res)) {
|
31382 | res = [res];
|
31383 | }
|
31384 | if (!this._geosToCheck) {
|
31385 | this._geosToCheck = [];
|
31386 | }
|
31387 | pushIn(this._geosToCheck, res);
|
31388 | };
|
31389 |
|
31390 | OverlayLayerRenderer.prototype.onGeometryAdd = function onGeometryAdd(geometries) {
|
31391 | this._addGeoToCheckRes(geometries);
|
31392 | redraw(this);
|
31393 | };
|
31394 |
|
31395 | OverlayLayerRenderer.prototype.onGeometryRemove = function onGeometryRemove() {
|
31396 | redraw(this);
|
31397 | };
|
31398 |
|
31399 | OverlayLayerRenderer.prototype.onGeometrySymbolChange = function onGeometrySymbolChange(e) {
|
31400 | this._addGeoToCheckRes(e.target);
|
31401 | redraw(this);
|
31402 | };
|
31403 |
|
31404 | OverlayLayerRenderer.prototype.onGeometryShapeChange = function onGeometryShapeChange() {
|
31405 | redraw(this);
|
31406 | };
|
31407 |
|
31408 | OverlayLayerRenderer.prototype.onGeometryPositionChange = function onGeometryPositionChange() {
|
31409 | redraw(this);
|
31410 | };
|
31411 |
|
31412 | OverlayLayerRenderer.prototype.onGeometryZIndexChange = function onGeometryZIndexChange() {
|
31413 | redraw(this);
|
31414 | };
|
31415 |
|
31416 | OverlayLayerRenderer.prototype.onGeometryShow = function onGeometryShow() {
|
31417 | redraw(this);
|
31418 | };
|
31419 |
|
31420 | OverlayLayerRenderer.prototype.onGeometryHide = function onGeometryHide() {
|
31421 | redraw(this);
|
31422 | };
|
31423 |
|
31424 | OverlayLayerRenderer.prototype.onGeometryPropertiesChange = function onGeometryPropertiesChange() {
|
31425 | redraw(this);
|
31426 | };
|
31427 |
|
31428 | return OverlayLayerRenderer;
|
31429 | }(CanvasRenderer);
|
31430 |
|
31431 | function redraw(renderer) {
|
31432 | if (renderer.layer.options['drawImmediate']) {
|
31433 | renderer.render();
|
31434 | }
|
31435 | renderer.setToRedraw();
|
31436 | }
|
31437 |
|
31438 | var VectorLayerRenderer = function (_OverlayLayerCanvasRe) {
|
31439 | inherits(VectorLayerRenderer, _OverlayLayerCanvasRe);
|
31440 |
|
31441 | function VectorLayerRenderer() {
|
31442 | classCallCheck(this, VectorLayerRenderer);
|
31443 | return possibleConstructorReturn(this, _OverlayLayerCanvasRe.apply(this, arguments));
|
31444 | }
|
31445 |
|
31446 | VectorLayerRenderer.prototype.checkResources = function checkResources() {
|
31447 | var _this2 = this;
|
31448 |
|
31449 | var resources = _OverlayLayerCanvasRe.prototype.checkResources.apply(this, arguments);
|
31450 | var style = this.layer.getStyle();
|
31451 | if (style) {
|
31452 | if (!Array.isArray(style)) {
|
31453 | style = [style];
|
31454 | }
|
31455 | style.forEach(function (s) {
|
31456 | var res = getExternalResources(s['symbol'], true);
|
31457 | for (var i = 0, l = res.length; i < l; i++) {
|
31458 | if (!_this2.resources.isResourceLoaded(res[i])) {
|
31459 | resources.push(res[i]);
|
31460 | }
|
31461 | }
|
31462 | });
|
31463 | }
|
31464 | return resources;
|
31465 | };
|
31466 |
|
31467 | VectorLayerRenderer.prototype.needToRedraw = function needToRedraw() {
|
31468 | var map = this.getMap();
|
31469 | if (map.isInteracting() && this.layer.options['enableAltitude']) {
|
31470 | return true;
|
31471 | }
|
31472 |
|
31473 | if (map.isZooming() && !map.isRotating() && !map.getPitch() && !this._hasPoint && this.layer.constructor === VectorLayer) {
|
31474 | return false;
|
31475 | }
|
31476 | return _OverlayLayerCanvasRe.prototype.needToRedraw.call(this);
|
31477 | };
|
31478 |
|
31479 | VectorLayerRenderer.prototype.draw = function draw() {
|
31480 | if (!this.getMap()) {
|
31481 | return;
|
31482 | }
|
31483 | if (!this.layer.isVisible() || this.layer.isEmpty()) {
|
31484 | this.clearCanvas();
|
31485 | this.completeRender();
|
31486 | return;
|
31487 | }
|
31488 |
|
31489 | this.prepareCanvas();
|
31490 |
|
31491 | this.drawGeos();
|
31492 |
|
31493 | this.completeRender();
|
31494 | };
|
31495 |
|
31496 | VectorLayerRenderer.prototype.isBlank = function isBlank() {
|
31497 | if (!this.context) {
|
31498 | return false;
|
31499 | }
|
31500 | return !this.context.canvas._drawn;
|
31501 | };
|
31502 |
|
31503 | VectorLayerRenderer.prototype.drawOnInteracting = function drawOnInteracting() {
|
31504 | if (!this._geosToDraw) {
|
31505 | return;
|
31506 | }
|
31507 | this._updateDisplayExtent();
|
31508 | for (var i = 0, l = this._geosToDraw.length; i < l; i++) {
|
31509 | if (!this._geosToDraw[i].isVisible()) {
|
31510 | continue;
|
31511 | }
|
31512 | this._geosToDraw[i]._paint(this._displayExtent);
|
31513 | }
|
31514 | };
|
31515 |
|
31516 | VectorLayerRenderer.prototype.show = function show() {
|
31517 | this.layer.forEach(function (geo) {
|
31518 | geo._repaint();
|
31519 | });
|
31520 | _OverlayLayerCanvasRe.prototype.show.apply(this, arguments);
|
31521 | };
|
31522 |
|
31523 | VectorLayerRenderer.prototype.forEachGeo = function forEachGeo(fn, context) {
|
31524 | this.layer.forEach(fn, context);
|
31525 | };
|
31526 |
|
31527 | VectorLayerRenderer.prototype.drawGeos = function drawGeos() {
|
31528 | this._updateDisplayExtent();
|
31529 | this.prepareToDraw();
|
31530 |
|
31531 | this.forEachGeo(this.checkGeo, this);
|
31532 | for (var i = 0, len = this._geosToDraw.length; i < len; i++) {
|
31533 | this._geosToDraw[i]._paint();
|
31534 | }
|
31535 | };
|
31536 |
|
31537 | VectorLayerRenderer.prototype.prepareToDraw = function prepareToDraw() {
|
31538 | this._hasPoint = false;
|
31539 | this._geosToDraw = [];
|
31540 | };
|
31541 |
|
31542 | VectorLayerRenderer.prototype.checkGeo = function checkGeo(geo) {
|
31543 | if (!geo || !geo.isVisible() || !geo.getMap() || !geo.getLayer() || !geo.getLayer().isCanvasRender()) {
|
31544 | return;
|
31545 | }
|
31546 |
|
31547 | var painter = geo._getPainter(),
|
31548 | extent2D = painter.get2DExtent(this.resources);
|
31549 | if (!extent2D || !extent2D.intersects(this._displayExtent)) {
|
31550 | return;
|
31551 | }
|
31552 | if (painter.hasPoint()) {
|
31553 | this._hasPoint = true;
|
31554 | }
|
31555 | this._geosToDraw.push(geo);
|
31556 | };
|
31557 |
|
31558 | VectorLayerRenderer.prototype.onZoomEnd = function onZoomEnd() {
|
31559 | delete this.canvasExtent2D;
|
31560 | _OverlayLayerCanvasRe.prototype.onZoomEnd.apply(this, arguments);
|
31561 | };
|
31562 |
|
31563 | VectorLayerRenderer.prototype.onRemove = function onRemove() {
|
31564 | this.forEachGeo(function (g) {
|
31565 | g.onHide();
|
31566 | });
|
31567 | delete this._geosToDraw;
|
31568 | };
|
31569 |
|
31570 | VectorLayerRenderer.prototype.onGeometryPropertiesChange = function onGeometryPropertiesChange(param) {
|
31571 | if (param) {
|
31572 | this.layer._styleGeometry(param['target']);
|
31573 | }
|
31574 | _OverlayLayerCanvasRe.prototype.onGeometryPropertiesChange.call(this, param);
|
31575 | };
|
31576 |
|
31577 | VectorLayerRenderer.prototype._updateDisplayExtent = function _updateDisplayExtent() {
|
31578 | var extent2D = this.canvasExtent2D;
|
31579 | if (this._maskExtent) {
|
31580 | if (!this._maskExtent.intersects(extent2D)) {
|
31581 | this.completeRender();
|
31582 | return;
|
31583 | }
|
31584 | extent2D = extent2D.intersection(this._maskExtent);
|
31585 | }
|
31586 | this._displayExtent = extent2D;
|
31587 | };
|
31588 |
|
31589 | VectorLayerRenderer.prototype.identify = function identify(coordinate) {
|
31590 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
31591 |
|
31592 | var geometries = this._geosToDraw;
|
31593 | if (!geometries) {
|
31594 | return [];
|
31595 | }
|
31596 | return this.layer._hitGeos(geometries, coordinate, options);
|
31597 | };
|
31598 |
|
31599 | return VectorLayerRenderer;
|
31600 | }(OverlayLayerRenderer);
|
31601 |
|
31602 | VectorLayer.registerRenderer('canvas', VectorLayerRenderer);
|
31603 |
|
31604 | var MapRenderer = function (_Class) {
|
31605 | inherits(MapRenderer, _Class);
|
31606 |
|
31607 | function MapRenderer(map) {
|
31608 | classCallCheck(this, MapRenderer);
|
31609 |
|
31610 | var _this = possibleConstructorReturn(this, _Class.call(this));
|
31611 |
|
31612 | _this.map = map;
|
31613 | _this._handlerQueue = {};
|
31614 | return _this;
|
31615 | }
|
31616 |
|
31617 | MapRenderer.prototype.callInNextFrame = function callInNextFrame(fn) {
|
31618 | this._handlerQueue.push(fn);
|
31619 | };
|
31620 |
|
31621 | MapRenderer.prototype.executeFrameCallbacks = function executeFrameCallbacks() {
|
31622 | var running = this._handlerQueue;
|
31623 | this._handlerQueue = [];
|
31624 | for (var i = 0, l = running.length; i < l; i++) {
|
31625 | running[i]();
|
31626 | }
|
31627 | };
|
31628 |
|
31629 | MapRenderer.prototype.offsetPlatform = function offsetPlatform(offset) {
|
31630 | if (!this.map._panels.front) {
|
31631 | return this;
|
31632 | }
|
31633 | if (offset.x === 0 && offset.y === 0) {
|
31634 | return this;
|
31635 | }
|
31636 | var pos = this.map.offsetPlatform().add(offset)._round();
|
31637 | var panels = this.map._panels;
|
31638 | offsetDom(panels.back, pos);
|
31639 | offsetDom(panels.front, pos);
|
31640 | return this;
|
31641 | };
|
31642 |
|
31643 | MapRenderer.prototype.resetContainer = function resetContainer() {
|
31644 | if (!this.map) {
|
31645 | return;
|
31646 | }
|
31647 | this.map._resetMapViewPoint();
|
31648 | if (this.map._panels.front) {
|
31649 | var pos = new Point(0, 0);
|
31650 | offsetDom(this.map._panels.back, pos);
|
31651 | offsetDom(this.map._panels.front, pos);
|
31652 | }
|
31653 | };
|
31654 |
|
31655 | MapRenderer.prototype.onZoomEnd = function onZoomEnd() {
|
31656 | this.resetContainer();
|
31657 | };
|
31658 |
|
31659 | MapRenderer.prototype.onLoad = function onLoad() {
|
31660 | this._frameLoop();
|
31661 | };
|
31662 |
|
31663 | return MapRenderer;
|
31664 | }(Class);
|
31665 |
|
31666 | var MapCanvasRenderer = function (_MapRenderer) {
|
31667 | inherits(MapCanvasRenderer, _MapRenderer);
|
31668 |
|
31669 | function MapCanvasRenderer(map) {
|
31670 | classCallCheck(this, MapCanvasRenderer);
|
31671 |
|
31672 | var _this = possibleConstructorReturn(this, _MapRenderer.call(this, map));
|
31673 |
|
31674 | _this._containerIsCanvas = !!map._containerDOM.getContext;
|
31675 | _this._registerEvents();
|
31676 | _this._loopTime = 0;
|
31677 | return _this;
|
31678 | }
|
31679 |
|
31680 | MapCanvasRenderer.prototype.load = function load() {
|
31681 | this.initContainer();
|
31682 | };
|
31683 |
|
31684 | MapCanvasRenderer.prototype.renderFrame = function renderFrame(framestamp) {
|
31685 | if (!this.map) {
|
31686 | return false;
|
31687 | }
|
31688 | var map = this.map;
|
31689 | map._fireEvent('framestart');
|
31690 | this.updateMapDOM();
|
31691 | var layers = this._getAllLayerToRender();
|
31692 | this.drawLayers(layers, framestamp);
|
31693 | this.drawLayerCanvas(layers);
|
31694 |
|
31695 | map._fireEvent('frameend');
|
31696 | this._recordView();
|
31697 |
|
31698 | this._mapview = this._getMapView();
|
31699 | delete this._spatialRefChanged;
|
31700 | this._fireLayerLoadEvents();
|
31701 | this.executeFrameCallbacks();
|
31702 | this._needRedraw = false;
|
31703 | return true;
|
31704 | };
|
31705 |
|
31706 | MapCanvasRenderer.prototype.updateMapDOM = function updateMapDOM() {
|
31707 | var map = this.map;
|
31708 |
|
31709 | if (map.isZooming()) {
|
31710 | return;
|
31711 | }
|
31712 | var offset = map._getViewPointFrameOffset();
|
31713 | if (offset) {
|
31714 | map.offsetPlatform(offset);
|
31715 | }
|
31716 | };
|
31717 |
|
31718 | MapCanvasRenderer.prototype.drawLayers = function drawLayers(layers, framestamp) {
|
31719 | var map = this.map,
|
31720 | isInteracting = map.isInteracting(),
|
31721 | canvasIds = [],
|
31722 | updatedIds = [],
|
31723 | fps = map.options['fpsOnInteracting'] || 0,
|
31724 | timeLimit = fps === 0 ? 0 : 1000 / fps,
|
31725 | layerLimit = this.map.options['layerCanvasLimitOnInteracting'],
|
31726 | l = layers.length;
|
31727 | var baseLayer = map.getBaseLayer();
|
31728 | var t = 0;
|
31729 | for (var i = 0; i < l; i++) {
|
31730 | var layer = layers[i];
|
31731 | if (!layer.isVisible()) {
|
31732 | continue;
|
31733 | }
|
31734 | var isCanvas = layer.isCanvasRender();
|
31735 | if (isCanvas) {
|
31736 | canvasIds.push(layer.getId());
|
31737 | }
|
31738 | var renderer = layer._getRenderer();
|
31739 | if (!renderer) {
|
31740 | continue;
|
31741 | }
|
31742 |
|
31743 | var needsRedraw = this._checkLayerRedraw(layer);
|
31744 | if (isCanvas && renderer.isCanvasUpdated()) {
|
31745 | if (!needsRedraw) {
|
31746 | updatedIds.push(layer.getId());
|
31747 | }
|
31748 | this.setToRedraw();
|
31749 | }
|
31750 | delete renderer.__shouldZoomTransform;
|
31751 | if (!needsRedraw) {
|
31752 | if (isCanvas && isInteracting) {
|
31753 | if (map.isZooming() && !map.getPitch()) {
|
31754 | renderer.prepareRender();
|
31755 | renderer.__shouldZoomTransform = true;
|
31756 | } else if (map.getPitch() || map.isRotating()) {
|
31757 | renderer.clearCanvas();
|
31758 | }
|
31759 | }
|
31760 | continue;
|
31761 | }
|
31762 |
|
31763 | if (isInteracting && isCanvas) {
|
31764 | if (layerLimit > 0 && l - 1 - i > layerLimit && layer !== baseLayer) {
|
31765 | layer._getRenderer().clearCanvas();
|
31766 | continue;
|
31767 | }
|
31768 | t += this._drawCanvasLayerOnInteracting(layer, t, timeLimit, framestamp);
|
31769 | } else if (isInteracting && renderer.drawOnInteracting) {
|
31770 | if (renderer.prepareRender) {
|
31771 | renderer.prepareRender();
|
31772 | }
|
31773 | renderer.drawOnInteracting(this._eventParam, framestamp);
|
31774 | } else {
|
31775 | renderer.render(framestamp);
|
31776 | }
|
31777 |
|
31778 | if (isCanvas) {
|
31779 | updatedIds.push(layer.getId());
|
31780 | this.setToRedraw();
|
31781 | }
|
31782 | }
|
31783 |
|
31784 | var preCanvasIds = this._canvasIds || [];
|
31785 | var preUpdatedIds = this._updatedIds || [];
|
31786 | this._canvasIds = canvasIds;
|
31787 | this._updatedIds = updatedIds;
|
31788 | if (!this._needToRedraw()) {
|
31789 | var sep = '---';
|
31790 | if (preCanvasIds.join(sep) !== canvasIds.join(sep) || preUpdatedIds.join(sep) !== updatedIds.join(sep)) {
|
31791 | this.setToRedraw();
|
31792 | }
|
31793 | }
|
31794 | };
|
31795 |
|
31796 | MapCanvasRenderer.prototype._checkLayerRedraw = function _checkLayerRedraw(layer) {
|
31797 | if (this.isSpatialReferenceChanged()) {
|
31798 | return true;
|
31799 | }
|
31800 | var map = this.map;
|
31801 | var renderer = layer._getRenderer();
|
31802 | if (layer.isCanvasRender()) {
|
31803 | return renderer.testIfNeedRedraw();
|
31804 | } else {
|
31805 | if (renderer.needToRedraw && renderer.needToRedraw()) {
|
31806 | return true;
|
31807 | }
|
31808 |
|
31809 | return map.isInteracting() || this.isViewChanged();
|
31810 | }
|
31811 | };
|
31812 |
|
31813 | MapCanvasRenderer.prototype._drawCanvasLayerOnInteracting = function _drawCanvasLayerOnInteracting(layer, t, timeLimit, framestamp) {
|
31814 | var map = this.map,
|
31815 | renderer = layer._getRenderer(),
|
31816 | drawTime = renderer.getDrawTime(),
|
31817 | inTime = timeLimit === 0 || timeLimit > 0 && t + drawTime <= timeLimit;
|
31818 | if (renderer.mustRenderOnInteracting && renderer.mustRenderOnInteracting()) {
|
31819 | renderer.render(framestamp);
|
31820 | } else if (renderer.drawOnInteracting && (layer === map.getBaseLayer() || inTime || map.isZooming() && layer.options['forceRenderOnZooming'] || map.isMoving() && layer.options['forceRenderOnMoving'] || map.isRotating() && layer.options['forceRenderOnRotating'])) {
|
31821 | renderer.prepareRender();
|
31822 | renderer.prepareCanvas();
|
31823 | renderer.drawOnInteracting(this._eventParam, framestamp);
|
31824 | return drawTime;
|
31825 | } else if (map.isZooming() && !map.getPitch() && !map.isRotating()) {
|
31826 | renderer.prepareRender();
|
31827 | renderer.__shouldZoomTransform = true;
|
31828 | } else if (map.getPitch() || map.isRotating()) {
|
31829 | renderer.clearCanvas();
|
31830 | }
|
31831 | if (renderer.drawOnInteracting && !inTime) {
|
31832 | renderer.onSkipDrawOnInteracting(this._eventParam, framestamp);
|
31833 | }
|
31834 | return 0;
|
31835 | };
|
31836 |
|
31837 | MapCanvasRenderer.prototype._fireLayerLoadEvents = function _fireLayerLoadEvents() {
|
31838 | if (this._updatedIds && this._updatedIds.length > 0) {
|
31839 | var map = this.map;
|
31840 |
|
31841 | this._updatedIds.reverse().forEach(function (id) {
|
31842 | var layer = map.getLayer(id);
|
31843 | if (!layer) {
|
31844 | return;
|
31845 | }
|
31846 | var renderer = layer._getRenderer();
|
31847 | if (!renderer || !renderer.isRenderComplete()) {
|
31848 | return;
|
31849 | }
|
31850 |
|
31851 | layer.fire('layerload');
|
31852 | });
|
31853 | }
|
31854 | };
|
31855 |
|
31856 | MapCanvasRenderer.prototype._needToRedraw = function _needToRedraw() {
|
31857 | return this._needRedraw;
|
31858 | };
|
31859 |
|
31860 | MapCanvasRenderer.prototype.setToRedraw = function setToRedraw() {
|
31861 | this._needRedraw = true;
|
31862 | };
|
31863 |
|
31864 | MapCanvasRenderer.prototype.drawLayerCanvas = function drawLayerCanvas(layers) {
|
31865 | var map = this.map;
|
31866 | if (!map) {
|
31867 | return;
|
31868 | }
|
31869 | if (!this._needToRedraw() && !this.isViewChanged()) {
|
31870 | return;
|
31871 | }
|
31872 | if (!this.canvas) {
|
31873 | this.createCanvas();
|
31874 | }
|
31875 |
|
31876 | map._fireEvent('renderstart', {
|
31877 | 'context': this.context
|
31878 | });
|
31879 |
|
31880 | if (!this._updateCanvasSize()) {
|
31881 | this.clearCanvas();
|
31882 | }
|
31883 |
|
31884 | var interacting = map.isInteracting(),
|
31885 | limit = map.options['layerCanvasLimitOnInteracting'];
|
31886 | var len = layers.length;
|
31887 |
|
31888 | var baseLayerImage = void 0;
|
31889 | var images = [];
|
31890 | for (var i = 0; i < len; i++) {
|
31891 | if (!layers[i].isVisible() || !layers[i].isCanvasRender()) {
|
31892 | continue;
|
31893 | }
|
31894 | var renderer = layers[i]._getRenderer();
|
31895 | if (!renderer) {
|
31896 | continue;
|
31897 | }
|
31898 | var layerImage = this._getLayerImage(layers[i]);
|
31899 | if (layerImage && layerImage['image']) {
|
31900 | if (layers[i] === map.getBaseLayer()) {
|
31901 | baseLayerImage = [layers[i], layerImage];
|
31902 | } else {
|
31903 | images.push([layers[i], layerImage]);
|
31904 | }
|
31905 | }
|
31906 | }
|
31907 |
|
31908 | if (baseLayerImage) {
|
31909 | this._drawLayerCanvasImage(baseLayerImage[0], baseLayerImage[1]);
|
31910 | this._drawFog();
|
31911 | }
|
31912 |
|
31913 | len = images.length;
|
31914 | var start = interacting && limit >= 0 && len > limit ? len - limit : 0;
|
31915 | for (var _i = start; _i < len; _i++) {
|
31916 | this._drawLayerCanvasImage(images[_i][0], images[_i][1]);
|
31917 | }
|
31918 |
|
31919 | this._drawCenterCross();
|
31920 |
|
31921 | map._fireEvent('renderend', {
|
31922 | 'context': this.context
|
31923 | });
|
31924 | };
|
31925 |
|
31926 | MapCanvasRenderer.prototype.updateMapSize = function updateMapSize(size) {
|
31927 | if (!size || this._containerIsCanvas) {
|
31928 | return;
|
31929 | }
|
31930 | var width = size['width'] + 'px',
|
31931 | height = size['height'] + 'px';
|
31932 | var panels = this.map._panels;
|
31933 | panels.mapWrapper.style.width = width;
|
31934 | panels.mapWrapper.style.height = height;
|
31935 | this._updateCanvasSize();
|
31936 | };
|
31937 |
|
31938 | MapCanvasRenderer.prototype.getMainPanel = function getMainPanel() {
|
31939 | if (!this.map) {
|
31940 | return null;
|
31941 | }
|
31942 | if (this._containerIsCanvas) {
|
31943 | return this.map._containerDOM;
|
31944 | }
|
31945 | if (this.map._panels) {
|
31946 | return this.map._panels.mapWrapper;
|
31947 | }
|
31948 | return null;
|
31949 | };
|
31950 |
|
31951 | MapCanvasRenderer.prototype.toDataURL = function toDataURL(mimeType) {
|
31952 | if (!this.canvas) {
|
31953 | return null;
|
31954 | }
|
31955 | return this.canvas.toDataURL(mimeType);
|
31956 | };
|
31957 |
|
31958 | MapCanvasRenderer.prototype.remove = function remove() {
|
31959 | if (Browser$1.webgl && typeof document !== 'undefined') {
|
31960 | removeDomEvent(document, 'visibilitychange', this._onVisibilitychange, this);
|
31961 | }
|
31962 | if (this._resizeInterval) {
|
31963 | clearInterval(this._resizeInterval);
|
31964 | }
|
31965 | delete this.context;
|
31966 | delete this.canvas;
|
31967 | delete this.map;
|
31968 | delete this._spatialRefChanged;
|
31969 | this._cancelFrameLoop();
|
31970 | };
|
31971 |
|
31972 | MapCanvasRenderer.prototype.hitDetect = function hitDetect(point) {
|
31973 | var map = this.map;
|
31974 | if (!map || !map.options['hitDetect'] || map.isInteracting()) {
|
31975 | return;
|
31976 | }
|
31977 | var layers = map._getLayers();
|
31978 | var cursor = 'default';
|
31979 | var limit = map.options['hitDetectLimit'] || 0;
|
31980 | var counter = 0;
|
31981 | for (var i = layers.length - 1; i >= 0; i--) {
|
31982 | var layer = layers[i];
|
31983 | if (layer.isEmpty && layer.isEmpty()) {
|
31984 | continue;
|
31985 | }
|
31986 | var renderer = layer._getRenderer();
|
31987 | if (!renderer || !renderer.hitDetect) {
|
31988 | continue;
|
31989 | }
|
31990 | if (renderer.isBlank && renderer.isBlank()) {
|
31991 | continue;
|
31992 | }
|
31993 | if (layer.options['cursor'] !== 'default' && renderer.hitDetect(point)) {
|
31994 | cursor = layer.options['cursor'] || 'pointer';
|
31995 | break;
|
31996 | }
|
31997 | counter++;
|
31998 | if (limit > 0 && counter > limit) {
|
31999 | break;
|
32000 | }
|
32001 | }
|
32002 |
|
32003 | map._trySetCursor(cursor);
|
32004 | };
|
32005 |
|
32006 | MapCanvasRenderer.prototype._getLayerImage = function _getLayerImage(layer) {
|
32007 | var renderer = layer._getRenderer();
|
32008 | if (renderer.getCanvasImage) {
|
32009 | return renderer.getCanvasImage();
|
32010 | }
|
32011 | return null;
|
32012 | };
|
32013 |
|
32014 | MapCanvasRenderer.prototype.initContainer = function initContainer() {
|
32015 | var panels = this.map._panels;
|
32016 |
|
32017 | function createContainer(name, className, cssText, enableSelect) {
|
32018 | var c = createEl('div', className);
|
32019 | if (cssText) {
|
32020 | c.style.cssText = cssText;
|
32021 | }
|
32022 | panels[name] = c;
|
32023 | if (!enableSelect) {
|
32024 | preventSelection(c);
|
32025 | }
|
32026 | return c;
|
32027 | }
|
32028 | var containerDOM = this.map._containerDOM;
|
32029 |
|
32030 | if (this._containerIsCanvas) {
|
32031 | return;
|
32032 | }
|
32033 |
|
32034 | containerDOM.innerHTML = '';
|
32035 |
|
32036 | var POSITION0 = 'position:absolute;top:0px;left:0px;';
|
32037 |
|
32038 | var mapWrapper = createContainer('mapWrapper', 'maptalks-wrapper', 'position:absolute;overflow:hidden;', true),
|
32039 | mapAllLayers = createContainer('allLayers', 'maptalks-all-layers', POSITION0 + 'padding:0px;margin:0px;z-index:0;overflow:visible;', true),
|
32040 | backStatic = createContainer('backStatic', 'maptalks-back-static', POSITION0 + 'z-index:0;', true),
|
32041 | back = createContainer('back', 'maptalks-back', POSITION0 + 'z-index:1;'),
|
32042 | backLayer = createContainer('backLayer', 'maptalks-back-layer', POSITION0),
|
32043 | canvasContainer = createContainer('canvasContainer', 'maptalks-canvas-layer', POSITION0 + 'border:none;z-index:2;'),
|
32044 | frontStatic = createContainer('frontStatic', 'maptalks-front-static', POSITION0 + 'z-index:3;', true),
|
32045 | front = createContainer('front', 'maptalks-front', POSITION0 + 'z-index:4;', true),
|
32046 | frontLayer = createContainer('frontLayer', 'maptalks-front-layer', POSITION0 + 'z-index:0;'),
|
32047 | ui = createContainer('ui', 'maptalks-ui', POSITION0 + 'border:none;z-index:1;', true),
|
32048 | control = createContainer('control', 'maptalks-control', 'z-index:1', true);
|
32049 |
|
32050 | containerDOM.appendChild(mapWrapper);
|
32051 |
|
32052 | mapAllLayers.appendChild(backStatic);
|
32053 | back.appendChild(backLayer);
|
32054 | mapAllLayers.appendChild(back);
|
32055 | mapAllLayers.appendChild(canvasContainer);
|
32056 | front.appendChild(frontLayer);
|
32057 | mapAllLayers.appendChild(frontStatic);
|
32058 | mapAllLayers.appendChild(front);
|
32059 | front.appendChild(ui);
|
32060 |
|
32061 | mapWrapper.appendChild(mapAllLayers);
|
32062 | mapWrapper.appendChild(control);
|
32063 |
|
32064 | this.createCanvas();
|
32065 |
|
32066 | this.resetContainer();
|
32067 | var mapSize = this.map._getContainerDomSize();
|
32068 | this.updateMapSize(mapSize);
|
32069 | };
|
32070 |
|
32071 | MapCanvasRenderer.prototype.isViewChanged = function isViewChanged() {
|
32072 | var previous = this._mapview;
|
32073 | var view = this._getMapView();
|
32074 | if (!previous || !equalMapView(previous, view)) {
|
32075 | return true;
|
32076 | }
|
32077 | return false;
|
32078 | };
|
32079 |
|
32080 | MapCanvasRenderer.prototype._recordView = function _recordView() {
|
32081 | var map = this.map;
|
32082 | if (!map._onViewChange || map.isInteracting() || map.isAnimating()) {
|
32083 | return;
|
32084 | }
|
32085 | if (!equalMapView(map.getView(), map._getCurrentView())) {
|
32086 | map._onViewChange(map.getView());
|
32087 | }
|
32088 | };
|
32089 |
|
32090 | MapCanvasRenderer.prototype.isSpatialReferenceChanged = function isSpatialReferenceChanged() {
|
32091 | return this._spatialRefChanged;
|
32092 | };
|
32093 |
|
32094 | MapCanvasRenderer.prototype._getMapView = function _getMapView() {
|
32095 | var map = this.map;
|
32096 | var center = map._getPrjCenter();
|
32097 | return {
|
32098 | x: center.x,
|
32099 | y: center.y,
|
32100 | zoom: map.getZoom(),
|
32101 | pitch: map.getPitch(),
|
32102 | bearing: map.getBearing(),
|
32103 | width: map.width,
|
32104 | height: map.height
|
32105 | };
|
32106 | };
|
32107 |
|
32108 | MapCanvasRenderer.prototype._frameLoop = function _frameLoop(framestamp) {
|
32109 | var _this2 = this;
|
32110 |
|
32111 | if (!this.map) {
|
32112 | this._cancelFrameLoop();
|
32113 | return;
|
32114 | }
|
32115 | this.renderFrame(framestamp);
|
32116 |
|
32117 | this._animationFrame = requestAnimFrame(function (framestamp) {
|
32118 | _this2._frameLoop(framestamp);
|
32119 | });
|
32120 | };
|
32121 |
|
32122 | MapCanvasRenderer.prototype._cancelFrameLoop = function _cancelFrameLoop() {
|
32123 | if (this._animationFrame) {
|
32124 | cancelAnimFrame(this._animationFrame);
|
32125 | }
|
32126 | };
|
32127 |
|
32128 | MapCanvasRenderer.prototype._drawLayerCanvasImage = function _drawLayerCanvasImage(layer, layerImage) {
|
32129 | var ctx = this.context;
|
32130 | var point = layerImage['point'].round();
|
32131 | if (Browser$1.retina) {
|
32132 | point._multi(2);
|
32133 | }
|
32134 | var canvasImage = layerImage['image'];
|
32135 | if (point.x + canvasImage.width <= 0 || point.y + canvasImage.height <= 0) {
|
32136 | return;
|
32137 | }
|
32138 |
|
32139 | var op = layer.options['opacity'];
|
32140 | if (!isNumber(op)) {
|
32141 | op = 1;
|
32142 | }
|
32143 | if (op <= 0) {
|
32144 | return;
|
32145 | }
|
32146 | var imgOp = layerImage['opacity'];
|
32147 | if (!isNumber(imgOp)) {
|
32148 | imgOp = 1;
|
32149 | }
|
32150 | if (imgOp <= 0) {
|
32151 | return;
|
32152 | }
|
32153 | var alpha = ctx.globalAlpha;
|
32154 |
|
32155 | if (op < 1) {
|
32156 | ctx.globalAlpha *= op;
|
32157 | }
|
32158 | if (imgOp < 1) {
|
32159 | ctx.globalAlpha *= imgOp;
|
32160 | }
|
32161 | if (layer.options['cssFilter']) {
|
32162 | ctx.filter = layer.options['cssFilter'];
|
32163 | }
|
32164 | var matrix = this._zoomMatrix;
|
32165 | var shouldTransform = !!layer._getRenderer().__shouldZoomTransform;
|
32166 | var renderer = layer.getRenderer();
|
32167 | var clipped = renderer.clipCanvas(this.context);
|
32168 | if (matrix && shouldTransform) {
|
32169 | ctx.save();
|
32170 | ctx.setTransform.apply(ctx, matrix);
|
32171 | }
|
32172 |
|
32173 | ctx.drawImage(canvasImage, point.x, point.y);
|
32174 | if (matrix && shouldTransform) {
|
32175 | ctx.restore();
|
32176 | }
|
32177 | if (clipped) {
|
32178 | ctx.restore();
|
32179 | }
|
32180 | if (ctx.filter !== 'none') {
|
32181 | ctx.filter = 'none';
|
32182 | }
|
32183 | ctx.globalAlpha = alpha;
|
32184 | };
|
32185 |
|
32186 | MapCanvasRenderer.prototype._drawCenterCross = function _drawCenterCross() {
|
32187 | var cross = this.map.options['centerCross'];
|
32188 | if (cross) {
|
32189 | var ctx = this.context;
|
32190 | var p = new Point(this.canvas.width / 2, this.canvas.height / 2);
|
32191 | if (isFunction(cross)) {
|
32192 | cross(ctx, p);
|
32193 | } else {
|
32194 | Canvas.drawCross(this.context, p, 2, '#f00');
|
32195 | }
|
32196 | }
|
32197 | };
|
32198 |
|
32199 | MapCanvasRenderer.prototype._drawFog = function _drawFog() {
|
32200 | var map = this.map;
|
32201 | if (map.getPitch() <= map.options['maxVisualPitch'] || !map.options['fog']) {
|
32202 | return;
|
32203 | }
|
32204 | var fogThickness = 30,
|
32205 | r = Browser$1.retina ? 2 : 1;
|
32206 | var ctx = this.context,
|
32207 | clipExtent = map.getContainerExtent();
|
32208 | var top = (map.height - map._getVisualHeight(75)) * r;
|
32209 | if (top < 0) top = 0;
|
32210 | var bottom = clipExtent.ymin * r,
|
32211 | h = Math.ceil(bottom - top),
|
32212 | color = map.options['fogColor'].join();
|
32213 | var gradient = ctx.createLinearGradient(0, top, 0, bottom + fogThickness);
|
32214 | var landscape = 1 - fogThickness / (h + fogThickness);
|
32215 | gradient.addColorStop(0, 'rgba(' + color + ', 0)');
|
32216 | gradient.addColorStop(0.3, 'rgba(' + color + ', 0.3)');
|
32217 | gradient.addColorStop(landscape, 'rgba(' + color + ', 1)');
|
32218 | gradient.addColorStop(1, 'rgba(' + color + ', 0)');
|
32219 | ctx.beginPath();
|
32220 | ctx.fillStyle = gradient;
|
32221 | ctx.fillRect(0, top, Math.ceil(clipExtent.getWidth()) * r, Math.ceil(h + fogThickness));
|
32222 | };
|
32223 |
|
32224 | MapCanvasRenderer.prototype._getAllLayerToRender = function _getAllLayerToRender() {
|
32225 | return this.map._getLayers();
|
32226 | };
|
32227 |
|
32228 | MapCanvasRenderer.prototype.clearCanvas = function clearCanvas() {
|
32229 | if (!this.canvas) {
|
32230 | return;
|
32231 | }
|
32232 | Canvas.clearRect(this.context, 0, 0, this.canvas.width, this.canvas.height);
|
32233 | };
|
32234 |
|
32235 | MapCanvasRenderer.prototype._updateCanvasSize = function _updateCanvasSize() {
|
32236 | if (!this.canvas || this._containerIsCanvas) {
|
32237 | return false;
|
32238 | }
|
32239 | var map = this.map,
|
32240 | mapSize = map.getSize(),
|
32241 | canvas = this.canvas,
|
32242 | r = Browser$1.retina ? 2 : 1;
|
32243 | if (mapSize['width'] * r === canvas.width && mapSize['height'] * r === canvas.height) {
|
32244 | return false;
|
32245 | }
|
32246 |
|
32247 |
|
32248 | canvas.height = r * mapSize['height'];
|
32249 | canvas.width = r * mapSize['width'];
|
32250 | if (canvas.style) {
|
32251 | canvas.style.width = mapSize['width'] + 'px';
|
32252 | canvas.style.height = mapSize['height'] + 'px';
|
32253 | }
|
32254 |
|
32255 | return true;
|
32256 | };
|
32257 |
|
32258 | MapCanvasRenderer.prototype.createCanvas = function createCanvas() {
|
32259 | if (this._containerIsCanvas) {
|
32260 | this.canvas = this.map._containerDOM;
|
32261 | } else {
|
32262 | this.canvas = createEl('canvas');
|
32263 | this._updateCanvasSize();
|
32264 | this.map._panels.canvasContainer.appendChild(this.canvas);
|
32265 | }
|
32266 | this.context = this.canvas.getContext('2d');
|
32267 | };
|
32268 |
|
32269 | MapCanvasRenderer.prototype._checkSize = function _checkSize() {
|
32270 | if (!this.map || this.map.isInteracting()) {
|
32271 | return;
|
32272 | }
|
32273 |
|
32274 | computeDomPosition(this.map._containerDOM);
|
32275 | this.map.checkSize();
|
32276 | };
|
32277 |
|
32278 | MapCanvasRenderer.prototype._setCheckSizeInterval = function _setCheckSizeInterval(interval) {
|
32279 | var _this3 = this;
|
32280 |
|
32281 | clearInterval(this._resizeInterval);
|
32282 | this._checkSizeInterval = interval;
|
32283 | this._resizeInterval = setInterval(function () {
|
32284 | if (!_this3.map || _this3.map.isRemoved()) {
|
32285 | clearInterval(_this3._resizeInterval);
|
32286 | } else {
|
32287 | _this3._checkSize();
|
32288 | }
|
32289 | }, this._checkSizeInterval);
|
32290 | };
|
32291 |
|
32292 | MapCanvasRenderer.prototype._registerEvents = function _registerEvents() {
|
32293 | var _this4 = this;
|
32294 |
|
32295 | var map = this.map;
|
32296 |
|
32297 | if (map.options['checkSize'] && !IS_NODE && typeof window !== 'undefined') {
|
32298 | this._setCheckSizeInterval(1000);
|
32299 | }
|
32300 | if (!Browser$1.mobile) {
|
32301 | map.on('_mousemove', this._onMapMouseMove, this);
|
32302 | }
|
32303 |
|
32304 | map.on('_dragrotatestart _dragrotating _dragrotateend _movestart _moving _moveend _zoomstart', function (param) {
|
32305 | _this4._eventParam = param;
|
32306 | });
|
32307 |
|
32308 | map.on('_zooming', function (param) {
|
32309 | if (!map.getPitch()) {
|
32310 | _this4._zoomMatrix = param['matrix']['container'];
|
32311 | }
|
32312 | _this4._eventParam = param;
|
32313 | });
|
32314 |
|
32315 | map.on('_zoomend', function (param) {
|
32316 | _this4._eventParam = param;
|
32317 | delete _this4._zoomMatrix;
|
32318 | });
|
32319 |
|
32320 | map.on('_spatialreferencechange', function () {
|
32321 | _this4._spatialRefChanged = true;
|
32322 | });
|
32323 |
|
32324 | if (Browser$1.webgl && typeof document !== 'undefined') {
|
32325 | addDomEvent(document, 'visibilitychange', this._onVisibilitychange, this);
|
32326 | }
|
32327 | };
|
32328 |
|
32329 | MapCanvasRenderer.prototype._onMapMouseMove = function _onMapMouseMove(param) {
|
32330 | var _this5 = this;
|
32331 |
|
32332 | var map = this.map;
|
32333 | if (map.isInteracting() || !map.options['hitDetect']) {
|
32334 | return;
|
32335 | }
|
32336 | if (this._hitDetectFrame) {
|
32337 | cancelAnimFrame(this._hitDetectFrame);
|
32338 | }
|
32339 | this._hitDetectFrame = requestAnimFrame(function () {
|
32340 | _this5.hitDetect(param['containerPoint']);
|
32341 | });
|
32342 | };
|
32343 |
|
32344 | MapCanvasRenderer.prototype._getCanvasLayers = function _getCanvasLayers() {
|
32345 | return this.map._getLayers(function (layer) {
|
32346 | return layer.isCanvasRender();
|
32347 | });
|
32348 | };
|
32349 |
|
32350 | MapCanvasRenderer.prototype._onVisibilitychange = function _onVisibilitychange() {
|
32351 | if (document.visibilityState !== 'visible') {
|
32352 | return;
|
32353 | }
|
32354 | var layers = this._getAllLayerToRender();
|
32355 | for (var i = 0, l = layers.length; i < l; i++) {
|
32356 | var renderer = layers[i].getRenderer();
|
32357 | if (renderer && renderer.canvas && renderer.setToRedraw) {
|
32358 | renderer.setToRedraw();
|
32359 | }
|
32360 | }
|
32361 | };
|
32362 |
|
32363 | return MapCanvasRenderer;
|
32364 | }(MapRenderer);
|
32365 |
|
32366 | Map.registerRenderer('canvas', MapCanvasRenderer);
|
32367 |
|
32368 | Map.mergeOptions({
|
32369 | 'fog': true,
|
32370 | 'fogColor': [233, 233, 233]
|
32371 | });
|
32372 |
|
32373 |
|
32374 |
|
32375 | var index$6 = Object.freeze({
|
32376 | ResourceCache: ResourceCache,
|
32377 | CanvasRenderer: CanvasRenderer,
|
32378 | ImageGLRenderable: ImageGLRenderable,
|
32379 | MapRenderer: MapRenderer,
|
32380 | MapCanvasRenderer: MapCanvasRenderer,
|
32381 | Renderable: Renderable,
|
32382 | ImageLayerCanvasRenderer: ImageLayerCanvasRenderer,
|
32383 | ImageLayerGLRenderer: ImageLayerGLRenderer,
|
32384 | TileLayerCanvasRenderer: TileLayerCanvasRenderer,
|
32385 | TileLayerGLRenderer: TileLayerGLRenderer$1,
|
32386 | CanvasTileLayerCanvasRenderer: CanvasRenderer$2,
|
32387 | CanvasTileLayerGLRenderer: GLRenderer,
|
32388 | OverlayLayerCanvasRenderer: OverlayLayerRenderer,
|
32389 | VectorLayerCanvasRenderer: VectorLayerRenderer,
|
32390 | CanvasLayerRenderer: CanvasLayerRenderer
|
32391 | });
|
32392 |
|
32393 | var CenterPointRenderer = {
|
32394 | _getRenderPoints: function _getRenderPoints() {
|
32395 | return [[this._getCenter2DPoint(this.getMap().getGLZoom())], null];
|
32396 | }
|
32397 | };
|
32398 |
|
32399 | Marker.include(CenterPointRenderer);
|
32400 |
|
32401 | Ellipse.include(CenterPointRenderer);
|
32402 |
|
32403 | Circle.include(CenterPointRenderer);
|
32404 |
|
32405 | Sector.include(CenterPointRenderer);
|
32406 |
|
32407 | Rectangle.include({
|
32408 | _getRenderPoints: function _getRenderPoints(placement) {
|
32409 | var map = this.getMap();
|
32410 | if (placement === 'vertex') {
|
32411 | var shell = this._trimRing(this.getShell());
|
32412 | var points = [];
|
32413 | for (var i = 0, len = shell.length; i < len; i++) {
|
32414 | points.push(map.coordToPoint(shell[i], map.getGLZoom()));
|
32415 | }
|
32416 | return [points, null];
|
32417 | } else {
|
32418 | var c = map.coordToPoint(this.getCenter(), map.getGLZoom());
|
32419 | return [[c], null];
|
32420 | }
|
32421 | }
|
32422 | });
|
32423 |
|
32424 | var PolyRenderer = {
|
32425 | _getRenderPoints: function _getRenderPoints(placement) {
|
32426 | var map = this.getMap();
|
32427 | var glZoom = map.getGLZoom();
|
32428 | var points = void 0,
|
32429 | rotations = null;
|
32430 | if (placement === 'point') {
|
32431 | points = this._getPath2DPoints(this._getPrjCoordinates(), false, glZoom);
|
32432 | if (points && points.length > 0 && Array.isArray(points[0])) {
|
32433 | points = points[0].concat(points[1]);
|
32434 | }
|
32435 | } else if (placement === 'vertex') {
|
32436 | points = this._getPath2DPoints(this._getPrjCoordinates(), false, glZoom);
|
32437 | rotations = [];
|
32438 | if (points && points.length > 0 && Array.isArray(points[0])) {
|
32439 | for (var i = 0, l = points.length; i < l; i++) {
|
32440 | for (var ii = 0, ll = points[i].length; ii < ll; ii++) {
|
32441 | if (ii === 0) {
|
32442 | rotations.push([points[i][ii], points[i][ii + 1]]);
|
32443 | } else {
|
32444 | rotations.push([points[i][ii - 1], points[i][ii]]);
|
32445 | }
|
32446 | }
|
32447 | }
|
32448 | points = points[0].concat(points[1]);
|
32449 | } else {
|
32450 | for (var _i = 0, _l = points.length; _i < _l; _i++) {
|
32451 | if (_i === 0) {
|
32452 | rotations.push([points[_i], points[_i + 1]]);
|
32453 | } else {
|
32454 | rotations.push([points[_i - 1], points[_i]]);
|
32455 | }
|
32456 | }
|
32457 | }
|
32458 | } else if (placement === 'line') {
|
32459 | points = [];
|
32460 | rotations = [];
|
32461 | var vertice = this._getPath2DPoints(this._getPrjCoordinates(), false, glZoom),
|
32462 | isSplitted = vertice.length > 0 && Array.isArray(vertice[0]);
|
32463 | if (isSplitted) {
|
32464 | var ring = void 0;
|
32465 | for (var _i2 = 1, _l2 = vertice.length; _i2 < _l2; _i2++) {
|
32466 | ring = vertice[_i2];
|
32467 | if (this instanceof Polygon && ring.length > 0 && !ring[0].equals(ring[ring.length - 1])) {
|
32468 | ring.push(ring[0]);
|
32469 | }
|
32470 | for (var _ii = 1, _ll = ring.length; _ii < _ll; _ii++) {
|
32471 | points.push(ring[_ii].add(ring[_ii - 1])._multi(0.5));
|
32472 | rotations.push([ring[_ii - 1], ring[_ii]]);
|
32473 | }
|
32474 | }
|
32475 | } else {
|
32476 | if (this instanceof Polygon && vertice.length > 0 && !vertice[0].equals(vertice[vertice.length - 1])) {
|
32477 | vertice.push(vertice[0]);
|
32478 | }
|
32479 | for (var _i3 = 1, _l3 = vertice.length; _i3 < _l3; _i3++) {
|
32480 | points.push(vertice[_i3].add(vertice[_i3 - 1])._multi(0.5));
|
32481 | rotations.push([vertice[_i3 - 1], vertice[_i3]]);
|
32482 | }
|
32483 | }
|
32484 | } else if (placement === 'vertex-first') {
|
32485 | var coords = this._getPrjCoordinates();
|
32486 | points = [map._prjToPoint(coords[0], glZoom)];
|
32487 | rotations = [[map._prjToPoint(coords[0], glZoom), map._prjToPoint(coords[1], glZoom)]];
|
32488 | } else if (placement === 'vertex-last') {
|
32489 | var _coords = this._getPrjCoordinates();
|
32490 | var _l4 = _coords.length;
|
32491 | points = [map._prjToPoint(_coords[_l4 - 1], glZoom)];
|
32492 | rotations = [[map._prjToPoint(_coords[_l4 - 2], glZoom), map._prjToPoint(_coords[_l4 - 1], glZoom)]];
|
32493 | } else {
|
32494 | var pcenter = this._getProjection().project(this.getCenter());
|
32495 | points = [map._prjToPoint(pcenter, glZoom)];
|
32496 | }
|
32497 | return [points, rotations];
|
32498 | }
|
32499 | };
|
32500 |
|
32501 | LineString.include(PolyRenderer);
|
32502 |
|
32503 | Polygon.include(PolyRenderer);
|
32504 |
|
32505 | Geometry.include({
|
32506 | _redrawWhenPitch: function _redrawWhenPitch() {
|
32507 | return false;
|
32508 | },
|
32509 |
|
32510 | _redrawWhenRotate: function _redrawWhenRotate() {
|
32511 | return false;
|
32512 | }
|
32513 | });
|
32514 |
|
32515 | var el = {
|
32516 | _redrawWhenPitch: function _redrawWhenPitch() {
|
32517 | return true;
|
32518 | },
|
32519 |
|
32520 | _redrawWhenRotate: function _redrawWhenRotate() {
|
32521 | return this instanceof Ellipse || this instanceof Sector;
|
32522 | },
|
32523 |
|
32524 | _paintAsPath: function _paintAsPath() {
|
32525 | var map = this.getMap();
|
32526 | var altitude = this._getPainter().getAltitude();
|
32527 |
|
32528 | return altitude > 0 || map.getPitch() || this instanceof Ellipse && map.getBearing();
|
32529 | },
|
32530 |
|
32531 | _getPaintParams: function _getPaintParams() {
|
32532 | var map = this.getMap();
|
32533 | if (this._paintAsPath()) {
|
32534 | return Polygon.prototype._getPaintParams.call(this, true);
|
32535 | }
|
32536 | var pcenter = this._getPrjCoordinates();
|
32537 | var pt = map._prjToPoint(pcenter, map.getGLZoom());
|
32538 | var size = this._getRenderSize();
|
32539 | return [pt, size['width'], size['height']];
|
32540 | },
|
32541 |
|
32542 |
|
32543 | _paintOn: function _paintOn() {
|
32544 | if (this._paintAsPath()) {
|
32545 | return Canvas.polygon.apply(Canvas, arguments);
|
32546 | } else {
|
32547 | return Canvas.ellipse.apply(Canvas, arguments);
|
32548 | }
|
32549 | },
|
32550 |
|
32551 | _getRenderSize: function _getRenderSize() {
|
32552 | var map = this.getMap(),
|
32553 | z = map.getGLZoom();
|
32554 | var prjExtent = this._getPrjExtent();
|
32555 | var pmin = map._prjToPoint(prjExtent.getMin(), z),
|
32556 | pmax = map._prjToPoint(prjExtent.getMax(), z);
|
32557 | return new Size(Math.abs(pmax.x - pmin.x) / 2, Math.abs(pmax.y - pmin.y) / 2);
|
32558 | }
|
32559 | };
|
32560 |
|
32561 | Ellipse.include(el);
|
32562 |
|
32563 | Circle.include(el);
|
32564 |
|
32565 | Rectangle.include({
|
32566 | _getPaintParams: function _getPaintParams() {
|
32567 | var map = this.getMap();
|
32568 | var pointZoom = map.getGLZoom();
|
32569 | var shell = this._getPrjShell();
|
32570 | var points = this._getPath2DPoints(shell, false, pointZoom);
|
32571 | return [points];
|
32572 | },
|
32573 |
|
32574 |
|
32575 | _paintOn: Canvas.polygon
|
32576 | });
|
32577 |
|
32578 | Sector.include(el, {
|
32579 | _redrawWhenPitch: function _redrawWhenPitch() {
|
32580 | return true;
|
32581 | },
|
32582 |
|
32583 | _getPaintParams: function _getPaintParams() {
|
32584 | if (this._paintAsPath()) {
|
32585 | return Polygon.prototype._getPaintParams.call(this, true);
|
32586 | }
|
32587 | var map = this.getMap();
|
32588 | var pt = map._prjToPoint(this._getPrjCoordinates(), map.getGLZoom());
|
32589 | var size = this._getRenderSize();
|
32590 | return [pt, size['width'], [this.getStartAngle(), this.getEndAngle()]];
|
32591 | },
|
32592 |
|
32593 |
|
32594 | _paintOn: function _paintOn() {
|
32595 | if (this._paintAsPath()) {
|
32596 | return Canvas.polygon.apply(Canvas, arguments);
|
32597 | } else {
|
32598 | var r = this.getMap().getBearing();
|
32599 | var args = arguments;
|
32600 | if (r) {
|
32601 | args[3] = args[3].slice(0);
|
32602 | args[3][0] += r;
|
32603 | args[3][1] += r;
|
32604 | }
|
32605 | return Canvas.sector.apply(Canvas, args);
|
32606 | }
|
32607 | }
|
32608 |
|
32609 | });
|
32610 |
|
32611 | Path.include({
|
32612 | _paintAsPath: function _paintAsPath() {
|
32613 | return true;
|
32614 | }
|
32615 | });
|
32616 |
|
32617 | LineString.include({
|
32618 |
|
32619 | arrowStyles: {
|
32620 | 'classic': [3, 4]
|
32621 | },
|
32622 |
|
32623 | _getArrowShape: function _getArrowShape(prePoint, point, lineWidth, arrowStyle, tolerance) {
|
32624 | if (!tolerance) {
|
32625 | tolerance = 0;
|
32626 | }
|
32627 | var width = lineWidth * arrowStyle[0],
|
32628 | height = lineWidth * arrowStyle[1] + tolerance,
|
32629 | hw = width / 2 + tolerance;
|
32630 |
|
32631 | var normal = void 0;
|
32632 | if (point.nextCtrlPoint || point.prevCtrlPoint) {
|
32633 | if (point.prevCtrlPoint) {
|
32634 | normal = point.sub(new Point(point.prevCtrlPoint));
|
32635 | } else {
|
32636 | normal = point.sub(new Point(point.nextCtrlPoint));
|
32637 | }
|
32638 | } else {
|
32639 | normal = point.sub(prePoint);
|
32640 | }
|
32641 | normal._unit();
|
32642 | var p1 = point.sub(normal.multi(height));
|
32643 | normal._perp();
|
32644 | var p0 = p1.add(normal.multi(hw));
|
32645 | normal._multi(-1);
|
32646 | var p2 = p1.add(normal.multi(hw));
|
32647 | return [p0, point, p2, p0];
|
32648 | },
|
32649 | _getPaintParams: function _getPaintParams() {
|
32650 | var prjVertexes = this._getPrjCoordinates();
|
32651 | var points = this._getPath2DPoints(prjVertexes, false, this.getMap().getGLZoom());
|
32652 | return [points];
|
32653 | },
|
32654 | _paintOn: function _paintOn(ctx, points, lineOpacity, fillOpacity, dasharray) {
|
32655 | if (this.options['smoothness']) {
|
32656 | Canvas.paintSmoothLine(ctx, points, lineOpacity, this.options['smoothness'], false, this._animIdx, this._animTailRatio);
|
32657 | } else {
|
32658 | Canvas.path(ctx, points, lineOpacity, null, dasharray);
|
32659 | }
|
32660 | this._paintArrow(ctx, points, lineOpacity);
|
32661 | },
|
32662 | _getArrowPlacement: function _getArrowPlacement() {
|
32663 | return this.options['arrowPlacement'];
|
32664 | },
|
32665 | _getArrowStyle: function _getArrowStyle() {
|
32666 | var arrowStyle = this.options['arrowStyle'];
|
32667 | if (arrowStyle) {
|
32668 | return Array.isArray(arrowStyle) ? arrowStyle : this.arrowStyles[arrowStyle];
|
32669 | }
|
32670 | return null;
|
32671 | },
|
32672 | _getArrows: function _getArrows(points, lineWidth, tolerance) {
|
32673 | var arrowStyle = this._getArrowStyle();
|
32674 | if (!arrowStyle || points.length < 2) {
|
32675 | return [];
|
32676 | }
|
32677 | var isSplitted = points.length > 0 && Array.isArray(points[0]);
|
32678 | var segments = isSplitted ? points : [points];
|
32679 | var placement = this._getArrowPlacement();
|
32680 | var arrows = [];
|
32681 | var map = this.getMap(),
|
32682 | first = map.coordToContainerPoint(this.getFirstCoordinate()),
|
32683 | last = map.coordToContainerPoint(this.getLastCoordinate());
|
32684 | for (var i = segments.length - 1; i >= 0; i--) {
|
32685 | if (placement === 'vertex-first' || placement === 'vertex-firstlast' && segments[i][0].closeTo(first, 0.01)) {
|
32686 | arrows.push(this._getArrowShape(segments[i][1], segments[i][0], lineWidth, arrowStyle, tolerance));
|
32687 | }
|
32688 | if (placement === 'vertex-last' || placement === 'vertex-firstlast' && segments[i][segments[i].length - 1].closeTo(last, 0.01)) {
|
32689 | arrows.push(this._getArrowShape(segments[i][segments[i].length - 2], segments[i][segments[i].length - 1], lineWidth, arrowStyle, tolerance));
|
32690 | } else if (placement === 'point') {
|
32691 | this._getArrowPoints(arrows, segments[i], lineWidth, arrowStyle, tolerance);
|
32692 | }
|
32693 | }
|
32694 | return arrows;
|
32695 | },
|
32696 | _getArrowPoints: function _getArrowPoints(arrows, segments, lineWidth, arrowStyle, tolerance) {
|
32697 | for (var ii = 0, ll = segments.length - 1; ii < ll; ii++) {
|
32698 | arrows.push(this._getArrowShape(segments[ii], segments[ii + 1], lineWidth, arrowStyle, tolerance));
|
32699 | }
|
32700 | },
|
32701 | _paintArrow: function _paintArrow(ctx, points, lineOpacity) {
|
32702 | var lineWidth = this._getInternalSymbol()['lineWidth'];
|
32703 | if (!isNumber(lineWidth) || lineWidth < 3) {
|
32704 | lineWidth = 3;
|
32705 | }
|
32706 | var arrows = this._getArrows(points, lineWidth);
|
32707 | if (!arrows.length) {
|
32708 | return;
|
32709 | }
|
32710 | if (ctx.setLineDash) {
|
32711 | ctx.setLineDash([]);
|
32712 | }
|
32713 | for (var i = arrows.length - 1; i >= 0; i--) {
|
32714 | ctx.fillStyle = ctx.strokeStyle;
|
32715 | Canvas.polygon(ctx, arrows[i], lineOpacity, lineOpacity);
|
32716 | }
|
32717 | }
|
32718 | });
|
32719 |
|
32720 | Polygon.include({
|
32721 | _getPaintParams: function _getPaintParams(disableSimplify) {
|
32722 | var maxZoom = this.getMap().getGLZoom();
|
32723 | var prjVertexes = this._getPrjShell();
|
32724 | var points = this._getPath2DPoints(prjVertexes, disableSimplify, maxZoom);
|
32725 |
|
32726 | var isSplitted = points.length > 0 && Array.isArray(points[0]);
|
32727 | if (isSplitted) {
|
32728 | points = [[points[0]], [points[1]]];
|
32729 | }
|
32730 | var prjHoles = this._getPrjHoles();
|
32731 | var holePoints = [];
|
32732 | if (prjHoles && prjHoles.length > 0) {
|
32733 | for (var i = 0; i < prjHoles.length; i++) {
|
32734 | var hole = this._getPath2DPoints(prjHoles[i], disableSimplify, maxZoom);
|
32735 | if (Array.isArray(hole) && isSplitted) {
|
32736 | if (Array.isArray(hole[0])) {
|
32737 | points[0].push(hole[0]);
|
32738 | points[1].push(hole[1]);
|
32739 | } else {
|
32740 | points[0].push(hole);
|
32741 | }
|
32742 | } else {
|
32743 | holePoints.push(hole);
|
32744 | }
|
32745 | }
|
32746 | }
|
32747 | if (!isSplitted) {
|
32748 | points = [points];
|
32749 | pushIn(points, holePoints);
|
32750 | }
|
32751 | return [points];
|
32752 | },
|
32753 | _paintOn: function _paintOn(ctx, points, lineOpacity, fillOpacity, dasharray) {
|
32754 | Canvas.polygon(ctx, points, lineOpacity, fillOpacity, dasharray, this.options['smoothness']);
|
32755 | }
|
32756 | });
|
32757 |
|
32758 |
|
32759 |
|
32760 | typeof console !== 'undefined' && console.log('maptalks v0.40.5');
|
32761 |
|
32762 | }.call(__webpack_exports__, __webpack_require__(96), __webpack_require__(15)))
|
32763 |
|
32764 | })
|
32765 | ]);
|
32766 |
|
\ | No newline at end of file |