1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.leafletXserver = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | if (typeof module !== 'undefined') {
|
8 | module.exports = Emitter;
|
9 | }
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function Emitter(obj) {
|
18 | if (obj) return mixin(obj);
|
19 | };
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | function mixin(obj) {
|
30 | for (var key in Emitter.prototype) {
|
31 | obj[key] = Emitter.prototype[key];
|
32 | }
|
33 | return obj;
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | Emitter.prototype.on =
|
46 | Emitter.prototype.addEventListener = function(event, fn){
|
47 | this._callbacks = this._callbacks || {};
|
48 | (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
49 | .push(fn);
|
50 | return this;
|
51 | };
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | Emitter.prototype.once = function(event, fn){
|
64 | function on() {
|
65 | this.off(event, on);
|
66 | fn.apply(this, arguments);
|
67 | }
|
68 |
|
69 | on.fn = fn;
|
70 | this.on(event, on);
|
71 | return this;
|
72 | };
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | Emitter.prototype.off =
|
85 | Emitter.prototype.removeListener =
|
86 | Emitter.prototype.removeAllListeners =
|
87 | Emitter.prototype.removeEventListener = function(event, fn){
|
88 | this._callbacks = this._callbacks || {};
|
89 |
|
90 |
|
91 | if (0 == arguments.length) {
|
92 | this._callbacks = {};
|
93 | return this;
|
94 | }
|
95 |
|
96 |
|
97 | var callbacks = this._callbacks['$' + event];
|
98 | if (!callbacks) return this;
|
99 |
|
100 |
|
101 | if (1 == arguments.length) {
|
102 | delete this._callbacks['$' + event];
|
103 | return this;
|
104 | }
|
105 |
|
106 |
|
107 | var cb;
|
108 | for (var i = 0; i < callbacks.length; i++) {
|
109 | cb = callbacks[i];
|
110 | if (cb === fn || cb.fn === fn) {
|
111 | callbacks.splice(i, 1);
|
112 | break;
|
113 | }
|
114 | }
|
115 |
|
116 |
|
117 |
|
118 | if (callbacks.length === 0) {
|
119 | delete this._callbacks['$' + event];
|
120 | }
|
121 |
|
122 | return this;
|
123 | };
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | Emitter.prototype.emit = function(event){
|
134 | this._callbacks = this._callbacks || {};
|
135 |
|
136 | var args = new Array(arguments.length - 1)
|
137 | , callbacks = this._callbacks['$' + event];
|
138 |
|
139 | for (var i = 1; i < arguments.length; i++) {
|
140 | args[i - 1] = arguments[i];
|
141 | }
|
142 |
|
143 | if (callbacks) {
|
144 | callbacks = callbacks.slice(0);
|
145 | for (var i = 0, len = callbacks.length; i < len; ++i) {
|
146 | callbacks[i].apply(this, args);
|
147 | }
|
148 | }
|
149 |
|
150 | return this;
|
151 | };
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | Emitter.prototype.listeners = function(event){
|
162 | this._callbacks = this._callbacks || {};
|
163 | return this._callbacks['$' + event] || [];
|
164 | };
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | Emitter.prototype.hasListeners = function(event){
|
175 | return !! this.listeners(event).length;
|
176 | };
|
177 |
|
178 | },{}],2:[function(require,module,exports){
|
179 | module.exports = stringify
|
180 | stringify.default = stringify
|
181 | stringify.stable = deterministicStringify
|
182 | stringify.stableStringify = deterministicStringify
|
183 |
|
184 | var arr = []
|
185 | var replacerStack = []
|
186 |
|
187 |
|
188 | function stringify (obj, replacer, spacer) {
|
189 | decirc(obj, '', [], undefined)
|
190 | var res
|
191 | if (replacerStack.length === 0) {
|
192 | res = JSON.stringify(obj, replacer, spacer)
|
193 | } else {
|
194 | res = JSON.stringify(obj, replaceGetterValues(replacer), spacer)
|
195 | }
|
196 | while (arr.length !== 0) {
|
197 | var part = arr.pop()
|
198 | if (part.length === 4) {
|
199 | Object.defineProperty(part[0], part[1], part[3])
|
200 | } else {
|
201 | part[0][part[1]] = part[2]
|
202 | }
|
203 | }
|
204 | return res
|
205 | }
|
206 | function decirc (val, k, stack, parent) {
|
207 | var i
|
208 | if (typeof val === 'object' && val !== null) {
|
209 | for (i = 0; i < stack.length; i++) {
|
210 | if (stack[i] === val) {
|
211 | var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k)
|
212 | if (propertyDescriptor.get !== undefined) {
|
213 | if (propertyDescriptor.configurable) {
|
214 | Object.defineProperty(parent, k, { value: '[Circular]' })
|
215 | arr.push([parent, k, val, propertyDescriptor])
|
216 | } else {
|
217 | replacerStack.push([val, k])
|
218 | }
|
219 | } else {
|
220 | parent[k] = '[Circular]'
|
221 | arr.push([parent, k, val])
|
222 | }
|
223 | return
|
224 | }
|
225 | }
|
226 | stack.push(val)
|
227 |
|
228 | if (Array.isArray(val)) {
|
229 | for (i = 0; i < val.length; i++) {
|
230 | decirc(val[i], i, stack, val)
|
231 | }
|
232 | } else {
|
233 | var keys = Object.keys(val)
|
234 | for (i = 0; i < keys.length; i++) {
|
235 | var key = keys[i]
|
236 | decirc(val[key], key, stack, val)
|
237 | }
|
238 | }
|
239 | stack.pop()
|
240 | }
|
241 | }
|
242 |
|
243 |
|
244 | function compareFunction (a, b) {
|
245 | if (a < b) {
|
246 | return -1
|
247 | }
|
248 | if (a > b) {
|
249 | return 1
|
250 | }
|
251 | return 0
|
252 | }
|
253 |
|
254 | function deterministicStringify (obj, replacer, spacer) {
|
255 | var tmp = deterministicDecirc(obj, '', [], undefined) || obj
|
256 | var res
|
257 | if (replacerStack.length === 0) {
|
258 | res = JSON.stringify(tmp, replacer, spacer)
|
259 | } else {
|
260 | res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer)
|
261 | }
|
262 | while (arr.length !== 0) {
|
263 | var part = arr.pop()
|
264 | if (part.length === 4) {
|
265 | Object.defineProperty(part[0], part[1], part[3])
|
266 | } else {
|
267 | part[0][part[1]] = part[2]
|
268 | }
|
269 | }
|
270 | return res
|
271 | }
|
272 |
|
273 | function deterministicDecirc (val, k, stack, parent) {
|
274 | var i
|
275 | if (typeof val === 'object' && val !== null) {
|
276 | for (i = 0; i < stack.length; i++) {
|
277 | if (stack[i] === val) {
|
278 | var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k)
|
279 | if (propertyDescriptor.get !== undefined) {
|
280 | if (propertyDescriptor.configurable) {
|
281 | Object.defineProperty(parent, k, { value: '[Circular]' })
|
282 | arr.push([parent, k, val, propertyDescriptor])
|
283 | } else {
|
284 | replacerStack.push([val, k])
|
285 | }
|
286 | } else {
|
287 | parent[k] = '[Circular]'
|
288 | arr.push([parent, k, val])
|
289 | }
|
290 | return
|
291 | }
|
292 | }
|
293 | if (typeof val.toJSON === 'function') {
|
294 | return
|
295 | }
|
296 | stack.push(val)
|
297 |
|
298 | if (Array.isArray(val)) {
|
299 | for (i = 0; i < val.length; i++) {
|
300 | deterministicDecirc(val[i], i, stack, val)
|
301 | }
|
302 | } else {
|
303 |
|
304 | var tmp = {}
|
305 | var keys = Object.keys(val).sort(compareFunction)
|
306 | for (i = 0; i < keys.length; i++) {
|
307 | var key = keys[i]
|
308 | deterministicDecirc(val[key], key, stack, val)
|
309 | tmp[key] = val[key]
|
310 | }
|
311 | if (parent !== undefined) {
|
312 | arr.push([parent, k, val])
|
313 | parent[k] = tmp
|
314 | } else {
|
315 | return tmp
|
316 | }
|
317 | }
|
318 | stack.pop()
|
319 | }
|
320 | }
|
321 |
|
322 |
|
323 |
|
324 | function replaceGetterValues (replacer) {
|
325 | replacer = replacer !== undefined ? replacer : function (k, v) { return v }
|
326 | return function (key, val) {
|
327 | if (replacerStack.length > 0) {
|
328 | for (var i = 0; i < replacerStack.length; i++) {
|
329 | var part = replacerStack[i]
|
330 | if (part[1] === key && part[0] === val) {
|
331 | val = '[Circular]'
|
332 | replacerStack.splice(i, 1)
|
333 | break
|
334 | }
|
335 | }
|
336 | }
|
337 | return replacer.call(this, key, val)
|
338 | }
|
339 | }
|
340 |
|
341 | },{}],3:[function(require,module,exports){
|
342 | "use strict";
|
343 |
|
344 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
345 |
|
346 | function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
347 |
|
348 | function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
349 |
|
350 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
351 |
|
352 | function Agent() {
|
353 | this._defaults = [];
|
354 | }
|
355 |
|
356 | ['use', 'on', 'once', 'set', 'query', 'type', 'accept', 'auth', 'withCredentials', 'sortQuery', 'retry', 'ok', 'redirects', 'timeout', 'buffer', 'serialize', 'parse', 'ca', 'key', 'pfx', 'cert', 'disableTLSCerts'].forEach(function (fn) {
|
357 |
|
358 | Agent.prototype[fn] = function () {
|
359 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
360 | args[_key] = arguments[_key];
|
361 | }
|
362 |
|
363 | this._defaults.push({
|
364 | fn: fn,
|
365 | args: args
|
366 | });
|
367 |
|
368 | return this;
|
369 | };
|
370 | });
|
371 |
|
372 | Agent.prototype._setDefaults = function (req) {
|
373 | this._defaults.forEach(function (def) {
|
374 | req[def.fn].apply(req, _toConsumableArray(def.args));
|
375 | });
|
376 | };
|
377 |
|
378 | module.exports = Agent;
|
379 |
|
380 | },{}],4:[function(require,module,exports){
|
381 | "use strict";
|
382 |
|
383 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
384 |
|
385 |
|
386 |
|
387 |
|
388 | var root;
|
389 |
|
390 | if (typeof window !== 'undefined') {
|
391 |
|
392 | root = window;
|
393 | } else if (typeof self === 'undefined') {
|
394 |
|
395 | console.warn('Using browser-only version of superagent in non-browser environment');
|
396 | root = void 0;
|
397 | } else {
|
398 |
|
399 | root = self;
|
400 | }
|
401 |
|
402 | var Emitter = require('component-emitter');
|
403 |
|
404 | var safeStringify = require('fast-safe-stringify');
|
405 |
|
406 | var RequestBase = require('./request-base');
|
407 |
|
408 | var isObject = require('./is-object');
|
409 |
|
410 | var ResponseBase = require('./response-base');
|
411 |
|
412 | var Agent = require('./agent-base');
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 | function noop() {}
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 | module.exports = function (method, url) {
|
425 |
|
426 | if (typeof url === 'function') {
|
427 | return new exports.Request('GET', method).end(url);
|
428 | }
|
429 |
|
430 |
|
431 | if (arguments.length === 1) {
|
432 | return new exports.Request('GET', method);
|
433 | }
|
434 |
|
435 | return new exports.Request(method, url);
|
436 | };
|
437 |
|
438 | exports = module.exports;
|
439 | var request = exports;
|
440 | exports.Request = Request;
|
441 |
|
442 |
|
443 |
|
444 |
|
445 | request.getXHR = function () {
|
446 | if (root.XMLHttpRequest && (!root.location || root.location.protocol !== 'file:' || !root.ActiveXObject)) {
|
447 | return new XMLHttpRequest();
|
448 | }
|
449 |
|
450 | try {
|
451 | return new ActiveXObject('Microsoft.XMLHTTP');
|
452 | } catch (_unused) {}
|
453 |
|
454 | try {
|
455 | return new ActiveXObject('Msxml2.XMLHTTP.6.0');
|
456 | } catch (_unused2) {}
|
457 |
|
458 | try {
|
459 | return new ActiveXObject('Msxml2.XMLHTTP.3.0');
|
460 | } catch (_unused3) {}
|
461 |
|
462 | try {
|
463 | return new ActiveXObject('Msxml2.XMLHTTP');
|
464 | } catch (_unused4) {}
|
465 |
|
466 | throw new Error('Browser-only version of superagent could not find XHR');
|
467 | };
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 | var trim = ''.trim ? function (s) {
|
478 | return s.trim();
|
479 | } : function (s) {
|
480 | return s.replace(/(^\s*|\s*$)/g, '');
|
481 | };
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 | function serialize(obj) {
|
491 | if (!isObject(obj)) return obj;
|
492 | var pairs = [];
|
493 |
|
494 | for (var key in obj) {
|
495 | if (Object.prototype.hasOwnProperty.call(obj, key)) pushEncodedKeyValuePair(pairs, key, obj[key]);
|
496 | }
|
497 |
|
498 | return pairs.join('&');
|
499 | }
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 | function pushEncodedKeyValuePair(pairs, key, val) {
|
511 | if (val === undefined) return;
|
512 |
|
513 | if (val === null) {
|
514 | pairs.push(encodeURIComponent(key));
|
515 | return;
|
516 | }
|
517 |
|
518 | if (Array.isArray(val)) {
|
519 | val.forEach(function (v) {
|
520 | pushEncodedKeyValuePair(pairs, key, v);
|
521 | });
|
522 | } else if (isObject(val)) {
|
523 | for (var subkey in val) {
|
524 | if (Object.prototype.hasOwnProperty.call(val, subkey)) pushEncodedKeyValuePair(pairs, "".concat(key, "[").concat(subkey, "]"), val[subkey]);
|
525 | }
|
526 | } else {
|
527 | pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
|
528 | }
|
529 | }
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 | request.serializeObject = serialize;
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 | function parseString(str) {
|
545 | var obj = {};
|
546 | var pairs = str.split('&');
|
547 | var pair;
|
548 | var pos;
|
549 |
|
550 | for (var i = 0, len = pairs.length; i < len; ++i) {
|
551 | pair = pairs[i];
|
552 | pos = pair.indexOf('=');
|
553 |
|
554 | if (pos === -1) {
|
555 | obj[decodeURIComponent(pair)] = '';
|
556 | } else {
|
557 | obj[decodeURIComponent(pair.slice(0, pos))] = decodeURIComponent(pair.slice(pos + 1));
|
558 | }
|
559 | }
|
560 |
|
561 | return obj;
|
562 | }
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 | request.parseString = parseString;
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 | request.types = {
|
577 | html: 'text/html',
|
578 | json: 'application/json',
|
579 | xml: 'text/xml',
|
580 | urlencoded: 'application/x-www-form-urlencoded',
|
581 | form: 'application/x-www-form-urlencoded',
|
582 | 'form-data': 'application/x-www-form-urlencoded'
|
583 | };
|
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 | request.serialize = {
|
594 | 'application/x-www-form-urlencoded': serialize,
|
595 | 'application/json': safeStringify
|
596 | };
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 | request.parse = {
|
607 | 'application/x-www-form-urlencoded': parseString,
|
608 | 'application/json': JSON.parse
|
609 | };
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 | function parseHeader(str) {
|
620 | var lines = str.split(/\r?\n/);
|
621 | var fields = {};
|
622 | var index;
|
623 | var line;
|
624 | var field;
|
625 | var val;
|
626 |
|
627 | for (var i = 0, len = lines.length; i < len; ++i) {
|
628 | line = lines[i];
|
629 | index = line.indexOf(':');
|
630 |
|
631 | if (index === -1) {
|
632 |
|
633 | continue;
|
634 | }
|
635 |
|
636 | field = line.slice(0, index).toLowerCase();
|
637 | val = trim(line.slice(index + 1));
|
638 | fields[field] = val;
|
639 | }
|
640 |
|
641 | return fields;
|
642 | }
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 | function isJSON(mime) {
|
653 |
|
654 |
|
655 | return /[/+]json($|[^-\w])/.test(mime);
|
656 | }
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 | function Response(req) {
|
705 | this.req = req;
|
706 | this.xhr = this.req.xhr;
|
707 |
|
708 | this.text = this.req.method !== 'HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text') || typeof this.xhr.responseType === 'undefined' ? this.xhr.responseText : null;
|
709 | this.statusText = this.req.xhr.statusText;
|
710 | var status = this.xhr.status;
|
711 |
|
712 | if (status === 1223) {
|
713 | status = 204;
|
714 | }
|
715 |
|
716 | this._setStatusProperties(status);
|
717 |
|
718 | this.headers = parseHeader(this.xhr.getAllResponseHeaders());
|
719 | this.header = this.headers;
|
720 |
|
721 |
|
722 |
|
723 | this.header['content-type'] = this.xhr.getResponseHeader('content-type');
|
724 |
|
725 | this._setHeaderProperties(this.header);
|
726 |
|
727 | if (this.text === null && req._responseType) {
|
728 | this.body = this.xhr.response;
|
729 | } else {
|
730 | this.body = this.req.method === 'HEAD' ? null : this._parseBody(this.text ? this.text : this.xhr.response);
|
731 | }
|
732 | }
|
733 |
|
734 |
|
735 | ResponseBase(Response.prototype);
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 | Response.prototype._parseBody = function (str) {
|
748 | var parse = request.parse[this.type];
|
749 |
|
750 | if (this.req._parser) {
|
751 | return this.req._parser(this, str);
|
752 | }
|
753 |
|
754 | if (!parse && isJSON(this.type)) {
|
755 | parse = request.parse['application/json'];
|
756 | }
|
757 |
|
758 | return parse && str && (str.length > 0 || str instanceof Object) ? parse(str) : null;
|
759 | };
|
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 | Response.prototype.toError = function () {
|
769 | var req = this.req;
|
770 | var method = req.method;
|
771 | var url = req.url;
|
772 | var msg = "cannot ".concat(method, " ").concat(url, " (").concat(this.status, ")");
|
773 | var err = new Error(msg);
|
774 | err.status = this.status;
|
775 | err.method = method;
|
776 | err.url = url;
|
777 | return err;
|
778 | };
|
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 | request.Response = Response;
|
785 |
|
786 |
|
787 |
|
788 |
|
789 |
|
790 |
|
791 |
|
792 |
|
793 | function Request(method, url) {
|
794 | var self = this;
|
795 | this._query = this._query || [];
|
796 | this.method = method;
|
797 | this.url = url;
|
798 | this.header = {};
|
799 |
|
800 | this._header = {};
|
801 |
|
802 | this.on('end', function () {
|
803 | var err = null;
|
804 | var res = null;
|
805 |
|
806 | try {
|
807 | res = new Response(self);
|
808 | } catch (err_) {
|
809 | err = new Error('Parser is unable to parse the response');
|
810 | err.parse = true;
|
811 | err.original = err_;
|
812 |
|
813 | if (self.xhr) {
|
814 |
|
815 | err.rawResponse = typeof self.xhr.responseType === 'undefined' ? self.xhr.responseText : self.xhr.response;
|
816 |
|
817 | err.status = self.xhr.status ? self.xhr.status : null;
|
818 | err.statusCode = err.status;
|
819 | } else {
|
820 | err.rawResponse = null;
|
821 | err.status = null;
|
822 | }
|
823 |
|
824 | return self.callback(err);
|
825 | }
|
826 |
|
827 | self.emit('response', res);
|
828 | var new_err;
|
829 |
|
830 | try {
|
831 | if (!self._isResponseOK(res)) {
|
832 | new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
|
833 | }
|
834 | } catch (err_) {
|
835 | new_err = err_;
|
836 | }
|
837 |
|
838 |
|
839 | if (new_err) {
|
840 | new_err.original = err;
|
841 | new_err.response = res;
|
842 | new_err.status = res.status;
|
843 | self.callback(new_err, res);
|
844 | } else {
|
845 | self.callback(null, res);
|
846 | }
|
847 | });
|
848 | }
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 | Emitter(Request.prototype);
|
856 |
|
857 | RequestBase(Request.prototype);
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 |
|
871 |
|
872 |
|
873 |
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 | Request.prototype.type = function (type) {
|
881 | this.set('Content-Type', request.types[type] || type);
|
882 | return this;
|
883 | };
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 | Request.prototype.accept = function (type) {
|
906 | this.set('Accept', request.types[type] || type);
|
907 | return this;
|
908 | };
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 | Request.prototype.auth = function (user, pass, options) {
|
921 | if (arguments.length === 1) pass = '';
|
922 |
|
923 | if (_typeof(pass) === 'object' && pass !== null) {
|
924 |
|
925 | options = pass;
|
926 | pass = '';
|
927 | }
|
928 |
|
929 | if (!options) {
|
930 | options = {
|
931 | type: typeof btoa === 'function' ? 'basic' : 'auto'
|
932 | };
|
933 | }
|
934 |
|
935 | var encoder = function encoder(string) {
|
936 | if (typeof btoa === 'function') {
|
937 | return btoa(string);
|
938 | }
|
939 |
|
940 | throw new Error('Cannot use basic auth, btoa is not a function');
|
941 | };
|
942 |
|
943 | return this._auth(user, pass, options, encoder);
|
944 | };
|
945 |
|
946 |
|
947 |
|
948 |
|
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 |
|
959 |
|
960 | Request.prototype.query = function (val) {
|
961 | if (typeof val !== 'string') val = serialize(val);
|
962 | if (val) this._query.push(val);
|
963 | return this;
|
964 | };
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
|
972 |
|
973 |
|
974 |
|
975 |
|
976 |
|
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 | Request.prototype.attach = function (field, file, options) {
|
984 | if (file) {
|
985 | if (this._data) {
|
986 | throw new Error("superagent can't mix .send() and .attach()");
|
987 | }
|
988 |
|
989 | this._getFormData().append(field, file, options || file.name);
|
990 | }
|
991 |
|
992 | return this;
|
993 | };
|
994 |
|
995 | Request.prototype._getFormData = function () {
|
996 | if (!this._formData) {
|
997 | this._formData = new root.FormData();
|
998 | }
|
999 |
|
1000 | return this._formData;
|
1001 | };
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 | Request.prototype.callback = function (err, res) {
|
1013 | if (this._shouldRetry(err, res)) {
|
1014 | return this._retry();
|
1015 | }
|
1016 |
|
1017 | var fn = this._callback;
|
1018 | this.clearTimeout();
|
1019 |
|
1020 | if (err) {
|
1021 | if (this._maxRetries) err.retries = this._retries - 1;
|
1022 | this.emit('error', err);
|
1023 | }
|
1024 |
|
1025 | fn(err, res);
|
1026 | };
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 | Request.prototype.crossDomainError = function () {
|
1035 | var err = new Error('Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.');
|
1036 | err.crossDomain = true;
|
1037 | err.status = this.status;
|
1038 | err.method = this.method;
|
1039 | err.url = this.url;
|
1040 | this.callback(err);
|
1041 | };
|
1042 |
|
1043 |
|
1044 | Request.prototype.agent = function () {
|
1045 | console.warn('This is not supported in browser version of superagent');
|
1046 | return this;
|
1047 | };
|
1048 |
|
1049 | Request.prototype.buffer = Request.prototype.ca;
|
1050 | Request.prototype.ca = Request.prototype.agent;
|
1051 |
|
1052 | Request.prototype.write = function () {
|
1053 | throw new Error('Streaming is not supported in browser version of superagent');
|
1054 | };
|
1055 |
|
1056 | Request.prototype.pipe = Request.prototype.write;
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 | Request.prototype._isHost = function (obj) {
|
1067 |
|
1068 | return obj && _typeof(obj) === 'object' && !Array.isArray(obj) && Object.prototype.toString.call(obj) !== '[object Object]';
|
1069 | };
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 | Request.prototype.end = function (fn) {
|
1081 | if (this._endCalled) {
|
1082 | console.warn('Warning: .end() was called twice. This is not supported in superagent');
|
1083 | }
|
1084 |
|
1085 | this._endCalled = true;
|
1086 |
|
1087 | this._callback = fn || noop;
|
1088 |
|
1089 | this._finalizeQueryString();
|
1090 |
|
1091 | this._end();
|
1092 | };
|
1093 |
|
1094 | Request.prototype._setUploadTimeout = function () {
|
1095 | var self = this;
|
1096 |
|
1097 | if (this._uploadTimeout && !this._uploadTimeoutTimer) {
|
1098 | this._uploadTimeoutTimer = setTimeout(function () {
|
1099 | self._timeoutError('Upload timeout of ', self._uploadTimeout, 'ETIMEDOUT');
|
1100 | }, this._uploadTimeout);
|
1101 | }
|
1102 | };
|
1103 |
|
1104 |
|
1105 | Request.prototype._end = function () {
|
1106 | if (this._aborted) return this.callback(new Error('The request has been aborted even before .end() was called'));
|
1107 | var self = this;
|
1108 | this.xhr = request.getXHR();
|
1109 | var xhr = this.xhr;
|
1110 | var data = this._formData || this._data;
|
1111 |
|
1112 | this._setTimeouts();
|
1113 |
|
1114 |
|
1115 | xhr.onreadystatechange = function () {
|
1116 | var readyState = xhr.readyState;
|
1117 |
|
1118 | if (readyState >= 2 && self._responseTimeoutTimer) {
|
1119 | clearTimeout(self._responseTimeoutTimer);
|
1120 | }
|
1121 |
|
1122 | if (readyState !== 4) {
|
1123 | return;
|
1124 | }
|
1125 |
|
1126 |
|
1127 |
|
1128 | var status;
|
1129 |
|
1130 | try {
|
1131 | status = xhr.status;
|
1132 | } catch (_unused5) {
|
1133 | status = 0;
|
1134 | }
|
1135 |
|
1136 | if (!status) {
|
1137 | if (self.timedout || self._aborted) return;
|
1138 | return self.crossDomainError();
|
1139 | }
|
1140 |
|
1141 | self.emit('end');
|
1142 | };
|
1143 |
|
1144 |
|
1145 | var handleProgress = function handleProgress(direction, e) {
|
1146 | if (e.total > 0) {
|
1147 | e.percent = e.loaded / e.total * 100;
|
1148 |
|
1149 | if (e.percent === 100) {
|
1150 | clearTimeout(self._uploadTimeoutTimer);
|
1151 | }
|
1152 | }
|
1153 |
|
1154 | e.direction = direction;
|
1155 | self.emit('progress', e);
|
1156 | };
|
1157 |
|
1158 | if (this.hasListeners('progress')) {
|
1159 | try {
|
1160 | xhr.addEventListener('progress', handleProgress.bind(null, 'download'));
|
1161 |
|
1162 | if (xhr.upload) {
|
1163 | xhr.upload.addEventListener('progress', handleProgress.bind(null, 'upload'));
|
1164 | }
|
1165 | } catch (_unused6) {
|
1166 |
|
1167 |
|
1168 | }
|
1169 | }
|
1170 |
|
1171 | if (xhr.upload) {
|
1172 | this._setUploadTimeout();
|
1173 | }
|
1174 |
|
1175 |
|
1176 | try {
|
1177 | if (this.username && this.password) {
|
1178 | xhr.open(this.method, this.url, true, this.username, this.password);
|
1179 | } else {
|
1180 | xhr.open(this.method, this.url, true);
|
1181 | }
|
1182 | } catch (err) {
|
1183 |
|
1184 | return this.callback(err);
|
1185 | }
|
1186 |
|
1187 |
|
1188 | if (this._withCredentials) xhr.withCredentials = true;
|
1189 |
|
1190 | if (!this._formData && this.method !== 'GET' && this.method !== 'HEAD' && typeof data !== 'string' && !this._isHost(data)) {
|
1191 |
|
1192 | var contentType = this._header['content-type'];
|
1193 |
|
1194 | var _serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
|
1195 |
|
1196 | if (!_serialize && isJSON(contentType)) {
|
1197 | _serialize = request.serialize['application/json'];
|
1198 | }
|
1199 |
|
1200 | if (_serialize) data = _serialize(data);
|
1201 | }
|
1202 |
|
1203 |
|
1204 | for (var field in this.header) {
|
1205 | if (this.header[field] === null) continue;
|
1206 | if (Object.prototype.hasOwnProperty.call(this.header, field)) xhr.setRequestHeader(field, this.header[field]);
|
1207 | }
|
1208 |
|
1209 | if (this._responseType) {
|
1210 | xhr.responseType = this._responseType;
|
1211 | }
|
1212 |
|
1213 |
|
1214 | this.emit('request', this);
|
1215 |
|
1216 |
|
1217 | xhr.send(typeof data === 'undefined' ? null : data);
|
1218 | };
|
1219 |
|
1220 | request.agent = function () {
|
1221 | return new Agent();
|
1222 | };
|
1223 |
|
1224 | ['GET', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE'].forEach(function (method) {
|
1225 | Agent.prototype[method.toLowerCase()] = function (url, fn) {
|
1226 | var req = new request.Request(method, url);
|
1227 |
|
1228 | this._setDefaults(req);
|
1229 |
|
1230 | if (fn) {
|
1231 | req.end(fn);
|
1232 | }
|
1233 |
|
1234 | return req;
|
1235 | };
|
1236 | });
|
1237 | Agent.prototype.del = Agent.prototype.delete;
|
1238 |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 |
|
1248 | request.get = function (url, data, fn) {
|
1249 | var req = request('GET', url);
|
1250 |
|
1251 | if (typeof data === 'function') {
|
1252 | fn = data;
|
1253 | data = null;
|
1254 | }
|
1255 |
|
1256 | if (data) req.query(data);
|
1257 | if (fn) req.end(fn);
|
1258 | return req;
|
1259 | };
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 |
|
1268 |
|
1269 |
|
1270 |
|
1271 | request.head = function (url, data, fn) {
|
1272 | var req = request('HEAD', url);
|
1273 |
|
1274 | if (typeof data === 'function') {
|
1275 | fn = data;
|
1276 | data = null;
|
1277 | }
|
1278 |
|
1279 | if (data) req.query(data);
|
1280 | if (fn) req.end(fn);
|
1281 | return req;
|
1282 | };
|
1283 |
|
1284 |
|
1285 |
|
1286 |
|
1287 |
|
1288 |
|
1289 |
|
1290 |
|
1291 |
|
1292 |
|
1293 |
|
1294 | request.options = function (url, data, fn) {
|
1295 | var req = request('OPTIONS', url);
|
1296 |
|
1297 | if (typeof data === 'function') {
|
1298 | fn = data;
|
1299 | data = null;
|
1300 | }
|
1301 |
|
1302 | if (data) req.send(data);
|
1303 | if (fn) req.end(fn);
|
1304 | return req;
|
1305 | };
|
1306 |
|
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 |
|
1312 |
|
1313 |
|
1314 |
|
1315 |
|
1316 |
|
1317 | function del(url, data, fn) {
|
1318 | var req = request('DELETE', url);
|
1319 |
|
1320 | if (typeof data === 'function') {
|
1321 | fn = data;
|
1322 | data = null;
|
1323 | }
|
1324 |
|
1325 | if (data) req.send(data);
|
1326 | if (fn) req.end(fn);
|
1327 | return req;
|
1328 | }
|
1329 |
|
1330 | request.del = del;
|
1331 | request.delete = del;
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 |
|
1341 |
|
1342 | request.patch = function (url, data, fn) {
|
1343 | var req = request('PATCH', url);
|
1344 |
|
1345 | if (typeof data === 'function') {
|
1346 | fn = data;
|
1347 | data = null;
|
1348 | }
|
1349 |
|
1350 | if (data) req.send(data);
|
1351 | if (fn) req.end(fn);
|
1352 | return req;
|
1353 | };
|
1354 |
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 |
|
1360 |
|
1361 |
|
1362 |
|
1363 |
|
1364 |
|
1365 | request.post = function (url, data, fn) {
|
1366 | var req = request('POST', url);
|
1367 |
|
1368 | if (typeof data === 'function') {
|
1369 | fn = data;
|
1370 | data = null;
|
1371 | }
|
1372 |
|
1373 | if (data) req.send(data);
|
1374 | if (fn) req.end(fn);
|
1375 | return req;
|
1376 | };
|
1377 |
|
1378 |
|
1379 |
|
1380 |
|
1381 |
|
1382 |
|
1383 |
|
1384 |
|
1385 |
|
1386 |
|
1387 |
|
1388 | request.put = function (url, data, fn) {
|
1389 | var req = request('PUT', url);
|
1390 |
|
1391 | if (typeof data === 'function') {
|
1392 | fn = data;
|
1393 | data = null;
|
1394 | }
|
1395 |
|
1396 | if (data) req.send(data);
|
1397 | if (fn) req.end(fn);
|
1398 | return req;
|
1399 | };
|
1400 |
|
1401 | },{"./agent-base":3,"./is-object":5,"./request-base":6,"./response-base":7,"component-emitter":1,"fast-safe-stringify":2}],5:[function(require,module,exports){
|
1402 | "use strict";
|
1403 |
|
1404 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 |
|
1412 |
|
1413 | function isObject(obj) {
|
1414 | return obj !== null && _typeof(obj) === 'object';
|
1415 | }
|
1416 |
|
1417 | module.exports = isObject;
|
1418 |
|
1419 | },{}],6:[function(require,module,exports){
|
1420 | "use strict";
|
1421 |
|
1422 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
1423 |
|
1424 |
|
1425 |
|
1426 |
|
1427 | var isObject = require('./is-object');
|
1428 |
|
1429 |
|
1430 |
|
1431 |
|
1432 |
|
1433 | module.exports = RequestBase;
|
1434 |
|
1435 |
|
1436 |
|
1437 |
|
1438 |
|
1439 |
|
1440 | function RequestBase(obj) {
|
1441 | if (obj) return mixin(obj);
|
1442 | }
|
1443 |
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 |
|
1452 | function mixin(obj) {
|
1453 | for (var key in RequestBase.prototype) {
|
1454 | if (Object.prototype.hasOwnProperty.call(RequestBase.prototype, key)) obj[key] = RequestBase.prototype[key];
|
1455 | }
|
1456 |
|
1457 | return obj;
|
1458 | }
|
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 |
|
1464 |
|
1465 |
|
1466 |
|
1467 | RequestBase.prototype.clearTimeout = function () {
|
1468 | clearTimeout(this._timer);
|
1469 | clearTimeout(this._responseTimeoutTimer);
|
1470 | clearTimeout(this._uploadTimeoutTimer);
|
1471 | delete this._timer;
|
1472 | delete this._responseTimeoutTimer;
|
1473 | delete this._uploadTimeoutTimer;
|
1474 | return this;
|
1475 | };
|
1476 |
|
1477 |
|
1478 |
|
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 |
|
1485 |
|
1486 | RequestBase.prototype.parse = function (fn) {
|
1487 | this._parser = fn;
|
1488 | return this;
|
1489 | };
|
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 |
|
1500 |
|
1501 |
|
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 |
|
1507 |
|
1508 |
|
1509 | RequestBase.prototype.responseType = function (val) {
|
1510 | this._responseType = val;
|
1511 | return this;
|
1512 | };
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 | RequestBase.prototype.serialize = function (fn) {
|
1524 | this._serializer = fn;
|
1525 | return this;
|
1526 | };
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 | RequestBase.prototype.timeout = function (options) {
|
1543 | if (!options || _typeof(options) !== 'object') {
|
1544 | this._timeout = options;
|
1545 | this._responseTimeout = 0;
|
1546 | this._uploadTimeout = 0;
|
1547 | return this;
|
1548 | }
|
1549 |
|
1550 | for (var option in options) {
|
1551 | if (Object.prototype.hasOwnProperty.call(options, option)) {
|
1552 | switch (option) {
|
1553 | case 'deadline':
|
1554 | this._timeout = options.deadline;
|
1555 | break;
|
1556 |
|
1557 | case 'response':
|
1558 | this._responseTimeout = options.response;
|
1559 | break;
|
1560 |
|
1561 | case 'upload':
|
1562 | this._uploadTimeout = options.upload;
|
1563 | break;
|
1564 |
|
1565 | default:
|
1566 | console.warn('Unknown timeout option', option);
|
1567 | }
|
1568 | }
|
1569 | }
|
1570 |
|
1571 | return this;
|
1572 | };
|
1573 |
|
1574 |
|
1575 |
|
1576 |
|
1577 |
|
1578 |
|
1579 |
|
1580 |
|
1581 |
|
1582 |
|
1583 |
|
1584 |
|
1585 | RequestBase.prototype.retry = function (count, fn) {
|
1586 |
|
1587 | if (arguments.length === 0 || count === true) count = 1;
|
1588 | if (count <= 0) count = 0;
|
1589 | this._maxRetries = count;
|
1590 | this._retries = 0;
|
1591 | this._retryCallback = fn;
|
1592 | return this;
|
1593 | };
|
1594 |
|
1595 | var ERROR_CODES = ['ECONNRESET', 'ETIMEDOUT', 'EADDRINFO', 'ESOCKETTIMEDOUT'];
|
1596 |
|
1597 |
|
1598 |
|
1599 |
|
1600 |
|
1601 |
|
1602 |
|
1603 |
|
1604 |
|
1605 | RequestBase.prototype._shouldRetry = function (err, res) {
|
1606 | if (!this._maxRetries || this._retries++ >= this._maxRetries) {
|
1607 | return false;
|
1608 | }
|
1609 |
|
1610 | if (this._retryCallback) {
|
1611 | try {
|
1612 | var override = this._retryCallback(err, res);
|
1613 |
|
1614 | if (override === true) return true;
|
1615 | if (override === false) return false;
|
1616 | } catch (err_) {
|
1617 | console.error(err_);
|
1618 | }
|
1619 | }
|
1620 |
|
1621 | if (res && res.status && res.status >= 500 && res.status !== 501) return true;
|
1622 |
|
1623 | if (err) {
|
1624 | if (err.code && ERROR_CODES.includes(err.code)) return true;
|
1625 |
|
1626 | if (err.timeout && err.code === 'ECONNABORTED') return true;
|
1627 | if (err.crossDomain) return true;
|
1628 | }
|
1629 |
|
1630 | return false;
|
1631 | };
|
1632 |
|
1633 |
|
1634 |
|
1635 |
|
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 | RequestBase.prototype._retry = function () {
|
1641 | this.clearTimeout();
|
1642 |
|
1643 | if (this.req) {
|
1644 | this.req = null;
|
1645 | this.req = this.request();
|
1646 | }
|
1647 |
|
1648 | this._aborted = false;
|
1649 | this.timedout = false;
|
1650 | return this._end();
|
1651 | };
|
1652 |
|
1653 |
|
1654 |
|
1655 |
|
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 | RequestBase.prototype.then = function (resolve, reject) {
|
1662 | var _this = this;
|
1663 |
|
1664 | if (!this._fullfilledPromise) {
|
1665 | var self = this;
|
1666 |
|
1667 | if (this._endCalled) {
|
1668 | console.warn('Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises');
|
1669 | }
|
1670 |
|
1671 | this._fullfilledPromise = new Promise(function (resolve, reject) {
|
1672 | self.on('abort', function () {
|
1673 | var err = new Error('Aborted');
|
1674 | err.code = 'ABORTED';
|
1675 | err.status = _this.status;
|
1676 | err.method = _this.method;
|
1677 | err.url = _this.url;
|
1678 | reject(err);
|
1679 | });
|
1680 | self.end(function (err, res) {
|
1681 | if (err) reject(err);else resolve(res);
|
1682 | });
|
1683 | });
|
1684 | }
|
1685 |
|
1686 | return this._fullfilledPromise.then(resolve, reject);
|
1687 | };
|
1688 |
|
1689 | RequestBase.prototype.catch = function (cb) {
|
1690 | return this.then(undefined, cb);
|
1691 | };
|
1692 |
|
1693 |
|
1694 |
|
1695 |
|
1696 |
|
1697 | RequestBase.prototype.use = function (fn) {
|
1698 | fn(this);
|
1699 | return this;
|
1700 | };
|
1701 |
|
1702 | RequestBase.prototype.ok = function (cb) {
|
1703 | if (typeof cb !== 'function') throw new Error('Callback required');
|
1704 | this._okCallback = cb;
|
1705 | return this;
|
1706 | };
|
1707 |
|
1708 | RequestBase.prototype._isResponseOK = function (res) {
|
1709 | if (!res) {
|
1710 | return false;
|
1711 | }
|
1712 |
|
1713 | if (this._okCallback) {
|
1714 | return this._okCallback(res);
|
1715 | }
|
1716 |
|
1717 | return res.status >= 200 && res.status < 300;
|
1718 | };
|
1719 |
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 | RequestBase.prototype.get = function (field) {
|
1730 | return this._header[field.toLowerCase()];
|
1731 | };
|
1732 |
|
1733 |
|
1734 |
|
1735 |
|
1736 |
|
1737 |
|
1738 |
|
1739 |
|
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 |
|
1745 | RequestBase.prototype.getHeader = RequestBase.prototype.get;
|
1746 |
|
1747 |
|
1748 |
|
1749 |
|
1750 |
|
1751 |
|
1752 |
|
1753 |
|
1754 |
|
1755 |
|
1756 |
|
1757 |
|
1758 |
|
1759 |
|
1760 |
|
1761 |
|
1762 |
|
1763 |
|
1764 |
|
1765 |
|
1766 |
|
1767 | RequestBase.prototype.set = function (field, val) {
|
1768 | if (isObject(field)) {
|
1769 | for (var key in field) {
|
1770 | if (Object.prototype.hasOwnProperty.call(field, key)) this.set(key, field[key]);
|
1771 | }
|
1772 |
|
1773 | return this;
|
1774 | }
|
1775 |
|
1776 | this._header[field.toLowerCase()] = val;
|
1777 | this.header[field] = val;
|
1778 | return this;
|
1779 | };
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 | RequestBase.prototype.unset = function (field) {
|
1795 | delete this._header[field.toLowerCase()];
|
1796 | delete this.header[field];
|
1797 | return this;
|
1798 | };
|
1799 |
|
1800 |
|
1801 |
|
1802 |
|
1803 |
|
1804 |
|
1805 |
|
1806 |
|
1807 |
|
1808 |
|
1809 |
|
1810 |
|
1811 |
|
1812 |
|
1813 |
|
1814 |
|
1815 |
|
1816 |
|
1817 |
|
1818 |
|
1819 |
|
1820 | RequestBase.prototype.field = function (name, val) {
|
1821 |
|
1822 | if (name === null || undefined === name) {
|
1823 | throw new Error('.field(name, val) name can not be empty');
|
1824 | }
|
1825 |
|
1826 | if (this._data) {
|
1827 | throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");
|
1828 | }
|
1829 |
|
1830 | if (isObject(name)) {
|
1831 | for (var key in name) {
|
1832 | if (Object.prototype.hasOwnProperty.call(name, key)) this.field(key, name[key]);
|
1833 | }
|
1834 |
|
1835 | return this;
|
1836 | }
|
1837 |
|
1838 | if (Array.isArray(val)) {
|
1839 | for (var i in val) {
|
1840 | if (Object.prototype.hasOwnProperty.call(val, i)) this.field(name, val[i]);
|
1841 | }
|
1842 |
|
1843 | return this;
|
1844 | }
|
1845 |
|
1846 |
|
1847 | if (val === null || undefined === val) {
|
1848 | throw new Error('.field(name, val) val can not be empty');
|
1849 | }
|
1850 |
|
1851 | if (typeof val === 'boolean') {
|
1852 | val = String(val);
|
1853 | }
|
1854 |
|
1855 | this._getFormData().append(name, val);
|
1856 |
|
1857 | return this;
|
1858 | };
|
1859 |
|
1860 |
|
1861 |
|
1862 |
|
1863 |
|
1864 |
|
1865 |
|
1866 |
|
1867 | RequestBase.prototype.abort = function () {
|
1868 | if (this._aborted) {
|
1869 | return this;
|
1870 | }
|
1871 |
|
1872 | this._aborted = true;
|
1873 | if (this.xhr) this.xhr.abort();
|
1874 |
|
1875 | if (this.req) this.req.abort();
|
1876 |
|
1877 | this.clearTimeout();
|
1878 | this.emit('abort');
|
1879 | return this;
|
1880 | };
|
1881 |
|
1882 | RequestBase.prototype._auth = function (user, pass, options, base64Encoder) {
|
1883 | switch (options.type) {
|
1884 | case 'basic':
|
1885 | this.set('Authorization', "Basic ".concat(base64Encoder("".concat(user, ":").concat(pass))));
|
1886 | break;
|
1887 |
|
1888 | case 'auto':
|
1889 | this.username = user;
|
1890 | this.password = pass;
|
1891 | break;
|
1892 |
|
1893 | case 'bearer':
|
1894 |
|
1895 | this.set('Authorization', "Bearer ".concat(user));
|
1896 | break;
|
1897 |
|
1898 | default:
|
1899 | break;
|
1900 | }
|
1901 |
|
1902 | return this;
|
1903 | };
|
1904 |
|
1905 |
|
1906 |
|
1907 |
|
1908 |
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 | RequestBase.prototype.withCredentials = function (on) {
|
1917 |
|
1918 | if (on === undefined) on = true;
|
1919 | this._withCredentials = on;
|
1920 | return this;
|
1921 | };
|
1922 |
|
1923 |
|
1924 |
|
1925 |
|
1926 |
|
1927 |
|
1928 |
|
1929 |
|
1930 |
|
1931 | RequestBase.prototype.redirects = function (n) {
|
1932 | this._maxRedirects = n;
|
1933 | return this;
|
1934 | };
|
1935 |
|
1936 |
|
1937 |
|
1938 |
|
1939 |
|
1940 |
|
1941 |
|
1942 |
|
1943 |
|
1944 | RequestBase.prototype.maxResponseSize = function (n) {
|
1945 | if (typeof n !== 'number') {
|
1946 | throw new TypeError('Invalid argument');
|
1947 | }
|
1948 |
|
1949 | this._maxResponseSize = n;
|
1950 | return this;
|
1951 | };
|
1952 |
|
1953 |
|
1954 |
|
1955 |
|
1956 |
|
1957 |
|
1958 |
|
1959 |
|
1960 |
|
1961 |
|
1962 | RequestBase.prototype.toJSON = function () {
|
1963 | return {
|
1964 | method: this.method,
|
1965 | url: this.url,
|
1966 | data: this._data,
|
1967 | headers: this._header
|
1968 | };
|
1969 | };
|
1970 |
|
1971 |
|
1972 |
|
1973 |
|
1974 |
|
1975 |
|
1976 |
|
1977 |
|
1978 |
|
1979 |
|
1980 |
|
1981 |
|
1982 |
|
1983 |
|
1984 |
|
1985 |
|
1986 |
|
1987 |
|
1988 |
|
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 |
|
1997 |
|
1998 |
|
1999 |
|
2000 |
|
2001 |
|
2002 |
|
2003 |
|
2004 |
|
2005 |
|
2006 |
|
2007 |
|
2008 |
|
2009 |
|
2010 |
|
2011 |
|
2012 | RequestBase.prototype.send = function (data) {
|
2013 | var isObj = isObject(data);
|
2014 | var type = this._header['content-type'];
|
2015 |
|
2016 | if (this._formData) {
|
2017 | throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");
|
2018 | }
|
2019 |
|
2020 | if (isObj && !this._data) {
|
2021 | if (Array.isArray(data)) {
|
2022 | this._data = [];
|
2023 | } else if (!this._isHost(data)) {
|
2024 | this._data = {};
|
2025 | }
|
2026 | } else if (data && this._data && this._isHost(this._data)) {
|
2027 | throw new Error("Can't merge these send calls");
|
2028 | }
|
2029 |
|
2030 |
|
2031 | if (isObj && isObject(this._data)) {
|
2032 | for (var key in data) {
|
2033 | if (Object.prototype.hasOwnProperty.call(data, key)) this._data[key] = data[key];
|
2034 | }
|
2035 | } else if (typeof data === 'string') {
|
2036 |
|
2037 | if (!type) this.type('form');
|
2038 | type = this._header['content-type'];
|
2039 |
|
2040 | if (type === 'application/x-www-form-urlencoded') {
|
2041 | this._data = this._data ? "".concat(this._data, "&").concat(data) : data;
|
2042 | } else {
|
2043 | this._data = (this._data || '') + data;
|
2044 | }
|
2045 | } else {
|
2046 | this._data = data;
|
2047 | }
|
2048 |
|
2049 | if (!isObj || this._isHost(data)) {
|
2050 | return this;
|
2051 | }
|
2052 |
|
2053 |
|
2054 | if (!type) this.type('json');
|
2055 | return this;
|
2056 | };
|
2057 |
|
2058 |
|
2059 |
|
2060 |
|
2061 |
|
2062 |
|
2063 |
|
2064 |
|
2065 |
|
2066 |
|
2067 |
|
2068 |
|
2069 |
|
2070 |
|
2071 |
|
2072 |
|
2073 |
|
2074 |
|
2075 |
|
2076 |
|
2077 |
|
2078 |
|
2079 |
|
2080 |
|
2081 |
|
2082 |
|
2083 |
|
2084 |
|
2085 |
|
2086 | RequestBase.prototype.sortQuery = function (sort) {
|
2087 |
|
2088 | this._sort = typeof sort === 'undefined' ? true : sort;
|
2089 | return this;
|
2090 | };
|
2091 |
|
2092 |
|
2093 |
|
2094 |
|
2095 |
|
2096 |
|
2097 |
|
2098 | RequestBase.prototype._finalizeQueryString = function () {
|
2099 | var query = this._query.join('&');
|
2100 |
|
2101 | if (query) {
|
2102 | this.url += (this.url.includes('?') ? '&' : '?') + query;
|
2103 | }
|
2104 |
|
2105 | this._query.length = 0;
|
2106 |
|
2107 | if (this._sort) {
|
2108 | var index = this.url.indexOf('?');
|
2109 |
|
2110 | if (index >= 0) {
|
2111 | var queryArr = this.url.slice(index + 1).split('&');
|
2112 |
|
2113 | if (typeof this._sort === 'function') {
|
2114 | queryArr.sort(this._sort);
|
2115 | } else {
|
2116 | queryArr.sort();
|
2117 | }
|
2118 |
|
2119 | this.url = this.url.slice(0, index) + '?' + queryArr.join('&');
|
2120 | }
|
2121 | }
|
2122 | };
|
2123 |
|
2124 |
|
2125 | RequestBase.prototype._appendQueryString = function () {
|
2126 | console.warn('Unsupported');
|
2127 | };
|
2128 |
|
2129 |
|
2130 |
|
2131 |
|
2132 |
|
2133 |
|
2134 |
|
2135 | RequestBase.prototype._timeoutError = function (reason, timeout, errno) {
|
2136 | if (this._aborted) {
|
2137 | return;
|
2138 | }
|
2139 |
|
2140 | var err = new Error("".concat(reason + timeout, "ms exceeded"));
|
2141 | err.timeout = timeout;
|
2142 | err.code = 'ECONNABORTED';
|
2143 | err.errno = errno;
|
2144 | this.timedout = true;
|
2145 | this.abort();
|
2146 | this.callback(err);
|
2147 | };
|
2148 |
|
2149 | RequestBase.prototype._setTimeouts = function () {
|
2150 | var self = this;
|
2151 |
|
2152 | if (this._timeout && !this._timer) {
|
2153 | this._timer = setTimeout(function () {
|
2154 | self._timeoutError('Timeout of ', self._timeout, 'ETIME');
|
2155 | }, this._timeout);
|
2156 | }
|
2157 |
|
2158 |
|
2159 | if (this._responseTimeout && !this._responseTimeoutTimer) {
|
2160 | this._responseTimeoutTimer = setTimeout(function () {
|
2161 | self._timeoutError('Response timeout of ', self._responseTimeout, 'ETIMEDOUT');
|
2162 | }, this._responseTimeout);
|
2163 | }
|
2164 | };
|
2165 |
|
2166 | },{"./is-object":5}],7:[function(require,module,exports){
|
2167 | "use strict";
|
2168 |
|
2169 |
|
2170 |
|
2171 |
|
2172 | var utils = require('./utils');
|
2173 |
|
2174 |
|
2175 |
|
2176 |
|
2177 |
|
2178 | module.exports = ResponseBase;
|
2179 |
|
2180 |
|
2181 |
|
2182 |
|
2183 |
|
2184 |
|
2185 | function ResponseBase(obj) {
|
2186 | if (obj) return mixin(obj);
|
2187 | }
|
2188 |
|
2189 |
|
2190 |
|
2191 |
|
2192 |
|
2193 |
|
2194 |
|
2195 |
|
2196 |
|
2197 | function mixin(obj) {
|
2198 | for (var key in ResponseBase.prototype) {
|
2199 | if (Object.prototype.hasOwnProperty.call(ResponseBase.prototype, key)) obj[key] = ResponseBase.prototype[key];
|
2200 | }
|
2201 |
|
2202 | return obj;
|
2203 | }
|
2204 |
|
2205 |
|
2206 |
|
2207 |
|
2208 |
|
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 | ResponseBase.prototype.get = function (field) {
|
2214 | return this.header[field.toLowerCase()];
|
2215 | };
|
2216 |
|
2217 |
|
2218 |
|
2219 |
|
2220 |
|
2221 |
|
2222 |
|
2223 |
|
2224 |
|
2225 |
|
2226 |
|
2227 |
|
2228 |
|
2229 | ResponseBase.prototype._setHeaderProperties = function (header) {
|
2230 |
|
2231 |
|
2232 |
|
2233 | var ct = header['content-type'] || '';
|
2234 | this.type = utils.type(ct);
|
2235 |
|
2236 | var params = utils.params(ct);
|
2237 |
|
2238 | for (var key in params) {
|
2239 | if (Object.prototype.hasOwnProperty.call(params, key)) this[key] = params[key];
|
2240 | }
|
2241 |
|
2242 | this.links = {};
|
2243 |
|
2244 | try {
|
2245 | if (header.link) {
|
2246 | this.links = utils.parseLinks(header.link);
|
2247 | }
|
2248 | } catch (_unused) {
|
2249 | }
|
2250 | };
|
2251 |
|
2252 |
|
2253 |
|
2254 |
|
2255 |
|
2256 |
|
2257 |
|
2258 |
|
2259 |
|
2260 |
|
2261 |
|
2262 |
|
2263 |
|
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 |
|
2269 |
|
2270 |
|
2271 |
|
2272 |
|
2273 | ResponseBase.prototype._setStatusProperties = function (status) {
|
2274 | var type = status / 100 | 0;
|
2275 |
|
2276 | this.statusCode = status;
|
2277 | this.status = this.statusCode;
|
2278 | this.statusType = type;
|
2279 |
|
2280 | this.info = type === 1;
|
2281 | this.ok = type === 2;
|
2282 | this.redirect = type === 3;
|
2283 | this.clientError = type === 4;
|
2284 | this.serverError = type === 5;
|
2285 | this.error = type === 4 || type === 5 ? this.toError() : false;
|
2286 |
|
2287 | this.created = status === 201;
|
2288 | this.accepted = status === 202;
|
2289 | this.noContent = status === 204;
|
2290 | this.badRequest = status === 400;
|
2291 | this.unauthorized = status === 401;
|
2292 | this.notAcceptable = status === 406;
|
2293 | this.forbidden = status === 403;
|
2294 | this.notFound = status === 404;
|
2295 | this.unprocessableEntity = status === 422;
|
2296 | };
|
2297 |
|
2298 | },{"./utils":8}],8:[function(require,module,exports){
|
2299 | "use strict";
|
2300 |
|
2301 |
|
2302 |
|
2303 |
|
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 | exports.type = function (str) {
|
2309 | return str.split(/ *; */).shift();
|
2310 | };
|
2311 |
|
2312 |
|
2313 |
|
2314 |
|
2315 |
|
2316 |
|
2317 |
|
2318 |
|
2319 |
|
2320 | exports.params = function (str) {
|
2321 | return str.split(/ *; */).reduce(function (obj, str) {
|
2322 | var parts = str.split(/ *= */);
|
2323 | var key = parts.shift();
|
2324 | var val = parts.shift();
|
2325 | if (key && val) obj[key] = val;
|
2326 | return obj;
|
2327 | }, {});
|
2328 | };
|
2329 |
|
2330 |
|
2331 |
|
2332 |
|
2333 |
|
2334 |
|
2335 |
|
2336 |
|
2337 |
|
2338 | exports.parseLinks = function (str) {
|
2339 | return str.split(/ *, */).reduce(function (obj, str) {
|
2340 | var parts = str.split(/ *; */);
|
2341 | var url = parts[0].slice(1, -1);
|
2342 | var rel = parts[1].split(/ *= */)[1].slice(1, -1);
|
2343 | obj[rel] = url;
|
2344 | return obj;
|
2345 | }, {});
|
2346 | };
|
2347 |
|
2348 |
|
2349 |
|
2350 |
|
2351 |
|
2352 |
|
2353 |
|
2354 |
|
2355 |
|
2356 | exports.cleanHeader = function (header, changesOrigin) {
|
2357 | delete header['content-type'];
|
2358 | delete header['content-length'];
|
2359 | delete header['transfer-encoding'];
|
2360 | delete header.host;
|
2361 |
|
2362 | if (changesOrigin) {
|
2363 | delete header.authorization;
|
2364 | delete header.cookie;
|
2365 | }
|
2366 |
|
2367 | return header;
|
2368 | };
|
2369 |
|
2370 | },{}],9:[function(require,module,exports){
|
2371 | (function (global){
|
2372 | 'use strict';
|
2373 |
|
2374 | var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null),
|
2375 | superagent = require('superagent');
|
2376 |
|
2377 | L.TileLayer.XServer = L.TileLayer.extend({
|
2378 | _isrsLayer: false,
|
2379 | options: {
|
2380 | disableMouseEvents : false,
|
2381 | },
|
2382 |
|
2383 | initialize: function (url, options) {
|
2384 | options = L.setOptions(this, options);
|
2385 |
|
2386 | var resolvedUrl = L.Util.template(url, L.extend({s: 0, x: 0, y: 0, z: 0}, options));
|
2387 | this._isrsLayer = resolvedUrl.indexOf('/renderMap') !== -1;
|
2388 |
|
2389 | if (!this._isrsLayer && resolvedUrl.indexOf('contentType=JSON') === -1)
|
2390 | throw new Error('L.TileLayer.XServer cannot be intatiated directly without contentType=JSON');
|
2391 |
|
2392 | L.TileLayer.prototype.initialize.call(this, url, options);
|
2393 | },
|
2394 |
|
2395 | onAdd: function (map) {
|
2396 | L.TileLayer.prototype.onAdd.call(this, map);
|
2397 |
|
2398 | if(!this.options.disableMouseEvents) {
|
2399 | var cont = map._container;
|
2400 |
|
2401 | cont.addEventListener('mousemove', L.bind(this._onMouseMove, this), true);
|
2402 | cont.addEventListener('mousedown', L.bind(this._onMouseDown, this), true);
|
2403 |
|
2404 | map._mapPane.addEventListener('click', L.bind(this._onClick, this), true);
|
2405 | map.addEventListener('click', L.bind(this._onMapClick, this), false);
|
2406 | }
|
2407 | },
|
2408 |
|
2409 | onRemove: function (map) {
|
2410 | if(!this.options.disableMouseEvents) {
|
2411 | var cont = map._container;
|
2412 |
|
2413 | cont.removeEventListener('mousemove', L.bind(this._onMouseMove, this), true);
|
2414 | cont.removeEventListener('mousedown', L.bind(this._onMouseDown, this), true);
|
2415 |
|
2416 | map._mapPane.removeEventListener('click', L.bind(this._onClick, this), true);
|
2417 | map.removeEventListener('click', L.bind(this._onMapClick, this), false);
|
2418 | }
|
2419 |
|
2420 | L.TileLayer.prototype.onRemove.call(this, map);
|
2421 | },
|
2422 |
|
2423 | findElement: function (e, container) {
|
2424 | if (!container)
|
2425 | return null;
|
2426 |
|
2427 | var result = {};
|
2428 |
|
2429 | var tiles = Array.prototype.slice.call(container.getElementsByTagName('img')),
|
2430 | i, len, tile;
|
2431 |
|
2432 | for (i = 0, len = tiles.length; i < len; i++) {
|
2433 | tile = tiles[i];
|
2434 | var mp = L.DomEvent.getMousePosition(e, tile);
|
2435 |
|
2436 | for (var j = tile._layers.length - 1; j >= 0; j--) {
|
2437 | var layer = tile._layers[j];
|
2438 | var width = Math.abs(layer.pixelBoundingBox.right - layer.pixelBoundingBox.left);
|
2439 | var height = Math.abs(layer.pixelBoundingBox.top - layer.pixelBoundingBox.bottom);
|
2440 | if ((layer.referencePixelPoint.x - width / 2 <= mp.x) && (layer.referencePixelPoint.x + width / 2 >= mp.x) &&
|
2441 | (layer.referencePixelPoint.y - height / 2 <= mp.y) && (layer.referencePixelPoint.y + height / 2 >= mp.y)) {
|
2442 | if (!result[layer.id])
|
2443 | result[layer.id] = layer;
|
2444 | }
|
2445 | }
|
2446 | }
|
2447 |
|
2448 | if (Object.keys(result).length > 0)
|
2449 | return result;
|
2450 |
|
2451 | return null;
|
2452 | },
|
2453 |
|
2454 | _onMouseMove: function (e) {
|
2455 | if (!this._map || this._map.dragging._draggable._moving || this._map._animatingZoom) {
|
2456 | return;
|
2457 | }
|
2458 |
|
2459 | if (this.findElement(e, this._container)) {
|
2460 | e.preventDefault();
|
2461 |
|
2462 | this._map._container.style.cursor = 'pointer';
|
2463 |
|
2464 | e.stopPropagation();
|
2465 | } else {
|
2466 | this._map._container.style.cursor = '';
|
2467 | }
|
2468 | },
|
2469 |
|
2470 | _onMouseDown: function (e) {
|
2471 | var found = this.findElement(e, this._container);
|
2472 | if (found) {
|
2473 | e.preventDefault();
|
2474 |
|
2475 | e.stopPropagation();
|
2476 | return false;
|
2477 | }
|
2478 | },
|
2479 |
|
2480 | _onClick: function (e) {
|
2481 | var found = this.findElement(e, this._container);
|
2482 | if (found) {
|
2483 | e.preventDefault();
|
2484 |
|
2485 | var description = this.buildDescriptionText(found);
|
2486 |
|
2487 | var point = found[Object.keys(found)[0]].latLng;
|
2488 |
|
2489 | L.popup()
|
2490 | .setLatLng(point)
|
2491 | .setContent(description)
|
2492 | .openOn(this._map);
|
2493 |
|
2494 | e.stopPropagation();
|
2495 | return false;
|
2496 | }
|
2497 | },
|
2498 |
|
2499 | _onMapClick: function (e) {
|
2500 | var found = this.findElement(e.originalEvent, this._container);
|
2501 | if (found) {
|
2502 | var description = this.buildDescriptionText(found);
|
2503 |
|
2504 | var point = found[Object.keys(found)[0]].latLng;
|
2505 |
|
2506 | L.popup()
|
2507 | .setLatLng(point)
|
2508 | .setContent(description)
|
2509 | .openOn(this._map);
|
2510 |
|
2511 | return false;
|
2512 | }
|
2513 | },
|
2514 |
|
2515 | buildDescriptionText: function (found) {
|
2516 | var description = '';
|
2517 | var isFirstLayer = true;
|
2518 |
|
2519 | for (var layer in found) {
|
2520 | if (isFirstLayer) {
|
2521 | isFirstLayer = false;
|
2522 | } else {
|
2523 | description = description + '<br>';
|
2524 | }
|
2525 |
|
2526 | for (var i = 0; i < found[layer].attributes.length; i++) {
|
2527 | var attribute = found[layer].attributes[i];
|
2528 | description = description.concat(
|
2529 | attribute.key.replace(/[A-Z]/g, ' $&') + ': ' +
|
2530 | attribute.value.replace('_', ' ') + '<br>');
|
2531 | }
|
2532 | }
|
2533 |
|
2534 | return description.toLowerCase();;
|
2535 | },
|
2536 |
|
2537 | pixToLatLng: function (tileKey, point) {
|
2538 | var earthHalfCircum = Math.PI;
|
2539 | var earthCircum = earthHalfCircum * 2.0
|
2540 | var arc = earthCircum / Math.pow(2, tileKey.z);
|
2541 | var x = -earthHalfCircum + (tileKey.x + (point.x / 256.0)) * arc;
|
2542 | var y = earthHalfCircum - (tileKey.y + (point.y / 256.0)) * arc;
|
2543 |
|
2544 | return L.latLng(
|
2545 | (360 / Math.PI) * (Math.atan(Math.exp(y)) - (Math.PI / 4)),
|
2546 | (180.0 / Math.PI) * x);
|
2547 | },
|
2548 |
|
2549 | _removeTile: function (key) {
|
2550 | var tile = this._tiles[key];
|
2551 | if (tile && tile.el && tile.el.request)
|
2552 | tile.el.request.abort();
|
2553 |
|
2554 | return L.TileLayer.prototype._removeTile.call(this, key);
|
2555 | },
|
2556 |
|
2557 | createTile: function (coords, done) {
|
2558 | var url = this.getTileUrl(coords);
|
2559 |
|
2560 | if (this._isrsLayer) {
|
2561 |
|
2562 | var request = {
|
2563 | 'mapSection': {
|
2564 | '$type': 'MapSectionByTileKey',
|
2565 | 'zoomLevel': coords.z,
|
2566 | 'x': coords.x,
|
2567 | 'y': coords.y
|
2568 | },
|
2569 | 'imageOptions': {
|
2570 | 'width': 256,
|
2571 | 'height': 256
|
2572 | },
|
2573 | 'resultFields': {
|
2574 | 'image': true
|
2575 | }
|
2576 | };
|
2577 |
|
2578 | if (this.options.requestExtension) {
|
2579 | request = L.extend(request, this.options.requestExtension);
|
2580 | }
|
2581 | }
|
2582 |
|
2583 | var tile = document.createElement('img');
|
2584 | tile._map = this._map;
|
2585 | tile._layers = [];
|
2586 |
|
2587 | tile.request = this._isrsLayer ?
|
2588 | superagent.post(url)
|
2589 | .set('Content-Type', 'application/json')
|
2590 | .send(request) :
|
2591 | superagent.get(url);
|
2592 |
|
2593 | if(this.options.username && this.options.password)
|
2594 | tile.request = tile.request.auth(this.options.username, this.options.password);
|
2595 |
|
2596 | tile.request.responseType('json')
|
2597 | .end(L.bind(function (err, response) {
|
2598 | tile.request = null;
|
2599 |
|
2600 | if(response && response.body && response.body.image)
|
2601 | {
|
2602 | var resp = response.body;
|
2603 |
|
2604 | var prefixMap = {
|
2605 | 'iVBOR': 'data:image/png;base64,',
|
2606 | 'R0lGO': 'data:image/gif;base64,',
|
2607 | '/9j/4': 'data:image/jpeg;base64,',
|
2608 | 'Qk02U': 'data:image/bmp;base64,'
|
2609 | };
|
2610 |
|
2611 | var rawImage = resp.image;
|
2612 | tile.src = prefixMap[rawImage.substr(0, 5)] + rawImage;
|
2613 |
|
2614 | if (resp.features) {
|
2615 | var objectInfos = resp.features;
|
2616 |
|
2617 | for (var i = 0; i < objectInfos.length; i++) {
|
2618 | var oi = objectInfos[i];
|
2619 | oi.latLng = this.pixToLatLng(coords, oi.referencePixelPoint);
|
2620 | tile._layers.push(oi);
|
2621 | }
|
2622 | }
|
2623 | }
|
2624 |
|
2625 | done(null, tile);
|
2626 | }, this));
|
2627 | return tile;
|
2628 | }
|
2629 | });
|
2630 |
|
2631 | L.tileLayer.xserver = function (url, options) {
|
2632 |
|
2633 | var resolvedUrl = L.Util.template(url, L.extend({s: 0, x: 0, y: 0, z: 0}, options));
|
2634 |
|
2635 | if ((resolvedUrl.indexOf('/renderMap') !== -1) || (url.indexOf('contentType=JSON') !== -1)) {
|
2636 | return new L.TileLayer.XServer(url, options);
|
2637 | } else {
|
2638 | return new L.TileLayer(url, options);
|
2639 | }
|
2640 | };
|
2641 |
|
2642 | module.exports = L.tileLayer.xserver;
|
2643 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
2644 | },{"superagent":4}],10:[function(require,module,exports){
|
2645 | (function (global){
|
2646 |
|
2647 | (function () {
|
2648 | 'use strict';
|
2649 |
|
2650 | var L = (typeof window !== 'undefined' ? window['L'] : typeof global !== 'undefined' ? global['L'] : null),
|
2651 | superagent = require('superagent');
|
2652 |
|
2653 |
|
2654 | var proto = L.TileLayer.prototype;
|
2655 | var prev = proto.initialize;
|
2656 |
|
2657 |
|
2658 | var xmapRegex = new RegExp('(^https?:\/\/.*\/)services\/(rest|rs)\/XMap\/');
|
2659 |
|
2660 |
|
2661 | var tokenRegex = new RegExp('[&\?]xtok=(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})');
|
2662 |
|
2663 | proto.initialize = function (url, options) {
|
2664 |
|
2665 | prev.call(this, url, options);
|
2666 |
|
2667 | autoSetAttributions(this);
|
2668 | };
|
2669 |
|
2670 | var prevRedraw = proto.redraw;
|
2671 |
|
2672 | proto.redraw = function () {
|
2673 | autoSetAttributions(this);
|
2674 |
|
2675 | prevRedraw.call(this);
|
2676 | };
|
2677 |
|
2678 | function autoSetAttributions(layer) {
|
2679 |
|
2680 | var resolvedUrl = layer.getTileUrl({
|
2681 | x: 0,
|
2682 | y: 0,
|
2683 | z: 0
|
2684 | });
|
2685 |
|
2686 |
|
2687 | var urlMatch = xmapRegex.exec(resolvedUrl);
|
2688 | if (!urlMatch || urlMatch.length < 2)
|
2689 | return;
|
2690 |
|
2691 |
|
2692 | var host = urlMatch[1];
|
2693 |
|
2694 |
|
2695 | var tokenMatch = tokenRegex.exec(resolvedUrl);
|
2696 | var token = (tokenMatch && tokenMatch.length > 1) ? tokenMatch[1] : null;
|
2697 |
|
2698 |
|
2699 | var req = superagent.post(host + 'services/rs/XRuntime/getDataInformation')
|
2700 | .set('Content-Type', 'application/json')
|
2701 | .send({});
|
2702 |
|
2703 | if (token)
|
2704 | req.auth('xtok', token);
|
2705 |
|
2706 | req.end(function (err, resp) {
|
2707 | var oldCopyright = layer.options.attribution;
|
2708 |
|
2709 | var newCopyright = (err || !resp || !resp.body || !resp.body.mapDescription ||
|
2710 | !resp.body.mapDescription.copyright) ?
|
2711 | 'PTV' :
|
2712 | matchCopyrights(resolvedUrl, resp.body.mapDescription.copyright);
|
2713 |
|
2714 | layer.options.attribution = newCopyright;
|
2715 |
|
2716 |
|
2717 | if (layer._map && layer._map.attributionControl) {
|
2718 | if (oldCopyright)
|
2719 | layer._map.attributionControl.removeAttribution(oldCopyright);
|
2720 |
|
2721 | layer._map.attributionControl.addAttribution(newCopyright);
|
2722 | }
|
2723 | });
|
2724 | }
|
2725 |
|
2726 | function matchCopyrights(url, copyright) {
|
2727 | var matchedCopyrights = [];
|
2728 |
|
2729 |
|
2730 | var baselayerRegex = new RegExp('(&|\\?)(layers=.*(background|labels|transport)|^((?!layers=).)*$)');
|
2731 | var baselayerMatch = baselayerRegex.exec(url);
|
2732 | if (baselayerMatch && baselayerMatch.length > 0 || matchedCopyrights.length === 0) {
|
2733 | matchedCopyrights = matchedCopyrights.concat(copyright.basemap ? copyright.basemap : copyright);
|
2734 | }
|
2735 |
|
2736 |
|
2737 | var featurelayerRegex = /(PTV_[A-Za-z]*)/g;
|
2738 | if (copyright.featureLayers && copyright.featureLayers.length > 0) {
|
2739 | var featurelayerMatches = url.match(featurelayerRegex);
|
2740 | if (featurelayerMatches && featurelayerMatches.length > 0) {
|
2741 | copyright.featureLayers.forEach(function (el) {
|
2742 | if (featurelayerMatches.indexOf(el.themeId) !== -1)
|
2743 | matchedCopyrights = matchedCopyrights.concat(el.copyright);
|
2744 | });
|
2745 | }
|
2746 | }
|
2747 |
|
2748 |
|
2749 | return matchedCopyrights.filter(function(elem, pos, arr) {
|
2750 | return arr.indexOf(elem) == pos;
|
2751 | }).join(', ');
|
2752 | }
|
2753 |
|
2754 | var protoAttribution = L.Control.Attribution.prototype;
|
2755 |
|
2756 | protoAttribution._update = function () {
|
2757 | if (!this._map) {
|
2758 | return;
|
2759 | }
|
2760 |
|
2761 | var attribs = [];
|
2762 |
|
2763 | for (var i in this._map._layers) {
|
2764 | if (this._map._layers[i].getAttribution) {
|
2765 | var attr = this._map._layers[i].getAttribution();
|
2766 | if(attr && this._attributions[attr]) {
|
2767 | attribs = attribs.concat(attr.split(','));
|
2768 | }
|
2769 | }
|
2770 | }
|
2771 |
|
2772 | var uniqueAttribs = attribs
|
2773 | .map(function(elem) {
|
2774 | return elem.trim();
|
2775 | })
|
2776 | .filter(function(elem, pos, arr) {
|
2777 | return arr.indexOf(elem) == pos;
|
2778 | });
|
2779 |
|
2780 | var prefixAndAttribs = [];
|
2781 |
|
2782 | if (this.options.prefix) {
|
2783 | prefixAndAttribs.push(this.options.prefix);
|
2784 | }
|
2785 | if (uniqueAttribs.length) {
|
2786 | prefixAndAttribs.push(uniqueAttribs.join(', '));
|
2787 | }
|
2788 |
|
2789 | this._container.innerHTML = prefixAndAttribs.join(' | ');
|
2790 | };
|
2791 | })();
|
2792 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
2793 | },{"superagent":4}]},{},[9,10])(10)
|
2794 | });
|