PageSourceSearch

https://spi-workshop.org/wp-content/plugins/easy-map/assets/leaflet/leaflet-bing-layer.js

js spi-workshop.org collected 2026-10-04 13:29:30 UTC 15,432 bytes, 399 lines download raw bytes

vendor: 15,432 bytes, lines 1-399
1(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2    (function (global){
3    var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null)
4    var fetchJsonp = require('fetch-jsonp')
5    var bboxIntersect = require('bbox-intersect')
6    
7    /**
8     * Converts tile xyz coordinates to Quadkey
9     * @param {Number} x
10     * @param {Number} y
11     * @param {Number} z
12     * @return {Number} Quadkey
13     */
14    function toQuadKey (x, y, z) {
15      var index = ''
16      for (var i = z; i > 0; i--) {
17        var b = 0
18        var mask = 1 << (i - 1)
19        if ((x & mask) !== 0) b++
20        if ((y & mask) !== 0) b += 2
21        index += b.toString()
22      }
23      return index
24    }
25    
26    /**
27     * Converts Leaflet BBoxString to Bing BBox
28     * @param {String} bboxString 'southwest_lng,southwest_lat,northeast_lng,northeast_lat'
29     * @return {Array} [south_lat, west_lng, north_lat, east_lng]
30     */
31    function toBingBBox (bboxString) {
32      var bbox = bboxString.split(',')
33      return [bbox[1], bbox[0], bbox[3], bbox[2]]
34    }
35    
36    var VALID_IMAGERY_SETS = [
37      'Aerial',
38      'AerialWithLabels',
39      'AerialWithLabelsOnDemand',
40      'Road',
41      'RoadOnDemand',
42      'CanvasLight',
43      'CanvasDark',
44      'CanvasGray',
45      'OrdnanceSurvey'
46    ]
47    
48    var DYNAMIC_IMAGERY_SETS = [
49      'AerialWithLabelsOnDemand',
50      'RoadOnDemand'
51    ]
52    
53    /**
54     * Create a new Bing Maps layer.
55     * @param {string|object} options Either a [Bing Maps Key](https://msdn.microsoft.com/en-us/library/ff428642.aspx) or an options object
56     * @param {string} options.BingMapsKey A valid Bing Maps Key (required)
57     * @param {string} [options.imagerySet=Aerial] Type of imagery, see https://msdn.microsoft.com/en-us/library/ff701716.aspx
58     * @param {string} [options.culture='en-US'] Language for labels, see https://msdn.microsoft.com/en-us/library/hh441729.aspx
59     * @return {L.TileLayer} A Leaflet TileLayer to add to your map
60     *
61     * Create a basic map
62     * @example
63     * var map = L.map('map').setView([51.505, -0.09], 13)
64     * L.TileLayer.Bing(MyBingMapsKey).addTo(map)
65     */
66    L.TileLayer.Bing = L.TileLayer.extend({
67      options: {
68        bingMapsKey: null, // Required
69        imagerySet: 'Aerial',
70        culture: 'en-US',
71        minZoom: 1,
72        minNativeZoom: 1,
73        maxNativeZoom: 19
74      },
75    
76      statics: {
77        METADATA_URL: 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/{imagerySet}?key={bingMapsKey}&include=ImageryProviders&uriScheme=https',
78        POINT_METADATA_URL: 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/{imagerySet}/{lat},{lng}?zl={z}&key={bingMapsKey}&uriScheme=https'
79      },
80    
81      initialize: function (options) {
82        if (typeof options === 'string') {
83          options = { bingMapsKey: options }
84        }
85        if (options && options.BingMapsKey) {
86          options.bingMapsKey = options.BingMapsKey
87          console.warn('use options.bingMapsKey instead of options.BingMapsKey')
88        }
89        if (!options || !options.bingMapsKey) {
90          throw new Error('Must supply options.BingMapsKey')
91        }
92        options = L.setOptions(this, options)
93        if (VALID_IMAGERY_SETS.indexOf(options.imagerySet) < 0) {
94          throw new Error("'" + options.imagerySet + "' is an invalid imagerySet, see https://github.com/digidem/leaflet-bing-layer#parameters")
95        }
96        if (options && options.style && DYNAMIC_IMAGERY_SETS.indexOf(options.imagerySet) < 0) {
97          console.warn('Dynamic styles will only work with these imagerySet choices: ' + DYNAMIC_IMAGERY_SETS.join(', '))
98        }
99    
100        var metaDataUrl = L.Util.template(L.TileLayer.Bing.METADATA_URL, {
101          bingMapsKey: this.options.bingMapsKey,
102          imagerySet: this.options.imagerySet
103        })
104    
105        this._imageryProviders = []
106        this._attributions = []
107    
108        // Keep a reference to the promise so we can use it later
109        this._fetch = fetchJsonp(metaDataUrl, {jsonpCallback: 'jsonp'})
110          .then(function (response) {
111            return response.json()
112          })
113          .then(this._metaDataOnLoad.bind(this))
114          .catch(console.error.bind(console))
115    
116        // for https://github.com/Leaflet/Leaflet/issues/137
117        if (!L.Browser.android) {
118          this.on('tileunload', this._onTileRemove)
119        }
120      },
121    
122      createTile: function (coords, done) {
123        var tile = document.createElement('img')
124    
125        L.DomEvent.on(tile, 'load', L.bind(this._tileOnLoad, this, done, tile))
126        L.DomEvent.on(tile, 'error', L.bind(this._tileOnError, this, done, tile))
127    
128        if (this.options.crossOrigin) {
129          tile.crossOrigin = ''
130        }
131    
132        /*
133         Alt tag is set to empty string to keep screen readers from reading URL and for compliance reasons
134         http://www.w3.org/TR/WCAG20-TECHS/H67
135        */
136        tile.alt = ''
137    
138        // Don't create closure if we don't have to
139        if (this._url) {
140          tile.src = this.getTileUrl(coords)
141        } else {
142          this._fetch.then(function () {
143            tile.src = this.getTileUrl(coords)
144          }.bind(this)).catch(function (e) {
145            console.error(e)
146            done(e)
147          })
148        }
149    
150        return tile
151      },
152    
153      getTileUrl: function (coords) {
154        var quadkey = toQuadKey(coords.x, coords.y, coords.z)
155        var url = L.Util.template(this._url, {
156          quadkey: quadkey,
157          subdomain: this._getSubdomain(coords),
158          culture: this.options.culture
159        })
160        if (typeof this.options.style === 'string') {
161          url += '&st=' + this.options.style
162        }
163        return url
164      },
165    
166      // Update the attribution control every time the map is moved
167      onAdd: function (map) {
168        map.on('moveend', this._updateAttribution, this)
169        L.TileLayer.prototype.onAdd.call(this, map)
170        this._attributions.forEach(function (attribution) {
171          map.attributionControl.addAttribution(attribution)
172        })
173      },
174    
175      // Clean up events and remove attributions from attribution control
176      onRemove: function (map) {
177        map.off('moveend', this._updateAttribution, this)
178        this._attributions.forEach(function (attribution) {
179          map.attributionControl.removeAttribution(attribution)
180        })
181        L.TileLayer.prototype.onRemove.call(this, map)
182      },
183    
184      /**
185       * Get the [Bing Imagery metadata](https://msdn.microsoft.com/en-us/library/ff701712.aspx)
186       * for a specific [`LatLng`](http://leafletjs.com/reference.html#latlng)
187       * and zoom level. If either `latlng` or `zoom` is omitted and the layer is attached
188       * to a map, the map center and current map zoom are used.
189       * @param {L.LatLng} latlng
190       * @param {Number} zoom
191       * @return {Promise} Resolves to the JSON metadata
192       */
193      getMetaData: function (latlng, zoom) {
194        if (!this._map && (!latlng || !zoom)) {
195          return Promise.reject(new Error('If layer is not attached to map, you must provide LatLng and zoom'))
196        }
197        latlng = latlng || this._map.getCenter()
198        zoom = zoom || this._map.getZoom()
199        var PointMetaDataUrl = L.Util.template(L.TileLayer.Bing.POINT_METADATA_URL, {
200          bingMapsKey: this.options.bingMapsKey,
201          imagerySet: this.options.imagerySet,
202          z: zoom,
203          lat: latlng.lat,
204          lng: latlng.lng
205        })
206        return fetchJsonp(PointMetaDataUrl, {jsonpCallback: 'jsonp'})
207          .then(function (response) {
208            return response.json()
209          })
210          .catch(console.error.bind(console))
211      },
212    
213      _metaDataOnLoad: function (metaData) {
214        if (metaData.statusCode !== 200) {
215          throw new Error('Bing Imagery Metadata error: \n' + JSON.stringify(metaData, null, '  '))
216        }
217        var resource = metaData.resourceSets[0].resources[0]
218        this._url = resource.imageUrl
219        this._imageryProviders = resource.imageryProviders || []
220        this.options.subdomains = resource.imageUrlSubdomains
221        this._updateAttribution()
222        return Promise.resolve()
223      },
224    
225      /**
226       * Update the attribution control of the map with the provider attributions
227       * within the current map bounds
228       */
229      _updateAttribution: function () {
230        var map = this._map
231        if (!map || !map.attributionControl) return
232        var zoom = map.getZoom()
233        var bbox = toBingBBox(map.getBounds().toBBoxString())
234        this._fetch.then(function () {
235          var newAttributions = this._getAttributions(bbox, zoom)
236          var prevAttributions = this._attributions
237          // Add any new provider attributions in the current area to the attribution control
238          newAttributions.forEach(function (attr) {
239            if (prevAttributions.indexOf(attr) > -1) return
240            map.attributionControl.addAttribution(attr)
241          })
242          // Remove any attributions that are no longer in the current area from the attribution control
243          prevAttributions.filter(function (attr) {
244            if (newAttributions.indexOf(attr) > -1) return
245            map.attributionControl.removeAttribution(attr)
246          })
247          this._attributions = newAttributions
248        }.bind(this))
249      },
250    
251      /**
252       * Returns an array of attributions for given bbox and zoom
253       * @private
254       * @param {Array} bbox [west, south, east, north]
255       * @param {Number} zoom
256       * @return {Array} Array of attribution strings for each provider
257       */
258      _getAttributions: function (bbox, zoom) {
259        return this._imageryProviders.reduce(function (attributions, provider) {
260          for (var i = 0; i < provider.coverageAreas.length; i++) {
261            if (bboxIntersect(bbox, provider.coverageAreas[i].bbox) &&
262              zoom >= provider.coverageAreas[i].zoomMin &&
263              zoom <= provider.coverageAreas[i].zoomMax) {
264              attributions.push(provider.attribution)
265              return attributions
266            }
267          }
268          return attributions
269        }, [])
270      }
271    })
272    
273    L.tileLayer.bing = function (options) {
274      return new L.TileLayer.Bing(options)
275    }
276    
277    module.exports = L.TileLayer.Bing
278    
279    }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
280    },{"bbox-intersect":2,"fetch-jsonp":3}],2:[function(require,module,exports){
281    module.exports = function(bbox1, bbox2){
282      if(!(
283          bbox1[0] > bbox2[2] ||
284          bbox1[2] < bbox2[0] ||
285          bbox1[3] < bbox2[1] ||
286          bbox1[1] > bbox2[3]
287        )){
288          return true;
289      } else {
290        return false;
291      }
292    }
293    },{}],3:[function(require,module,exports){
294    (function (global, factory) {
295      if (typeof define === 'function' && define.amd) {
296        define(['exports', 'module'], factory);
297      } else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
298        factory(exports, module);
299      } else {
300        var mod = {
301          exports: {}
302        };
303        factory(mod.exports, mod);
304        global.fetchJsonp = mod.exports;
305      }
306    })(this, function (exports, module) {
307      'use strict';
308    
309      var defaultOptions = {
310        timeout: 5000,
311        jsonpCallback: 'callback',
312        jsonpCallbackFunction: null
313      };
314    
315      function generateCallbackFunction() {
316        return 'jsonp_' + Date.now() + '_' + Math.ceil(Math.random() * 100000);
317      }
318    
319      // Known issue: Will throw 'Uncaught ReferenceError: callback_*** is not defined' error if request timeout
320      function clearFunction(functionName) {
321        // IE8 throws an exception when you try to delete a property on window
322        // http://stackoverflow.com/a/1824228/751089
323        try {
324          delete window[functionName];
325        } catch (e) {
326          window[functionName] = undefined;
327        }
328      }
329    
330      function removeScript(scriptId) {
331        var script = document.getElementById(scriptId);
332        document.getElementsByTagName('head')[0].removeChild(script);
333      }
334    
335      var fetchJsonp = function fetchJsonp(url) {
336        var options = arguments[1] === undefined ? {} : arguments[1];
337    
338        var timeout = options.timeout != null ? options.timeout : defaultOptions.timeout;
339        var jsonpCallback = options.jsonpCallback != null ? options.jsonpCallback : defaultOptions.jsonpCallback;
340    
341        var timeoutId = undefined;
342    
343        return new Promise(function (resolve, reject) {
344          var callbackFunction = options.jsonpCallbackFunction || generateCallbackFunction();
345    
346          window[callbackFunction] = function (response) {
347            resolve({
348              ok: true,
349              // keep consistent with fetch API
350              json: function json() {
351                return Promise.resolve(response);
352              }
353            });
354    
355            if (timeoutId) clearTimeout(timeoutId);
356    
357            removeScript(jsonpCallback + '_' + callbackFunction);
358    
359            clearFunction(callbackFunction);
360          };
361    
362          // Check if the user set their own params, and if not add a ? to start a list of params
363          url += url.indexOf('?') === -1 ? '?' : '&';
364    
365          var jsonpScript = document.createElement('script');
366          jsonpScript.setAttribute('src', url + jsonpCallback + '=' + callbackFunction);
367          jsonpScript.id = jsonpCallback + '_' + callbackFunction;
368          document.getElementsByTagName('head')[0].appendChild(jsonpScript);
369    
370          timeoutId = setTimeout(function () {
371            reject(new Error('JSONP request to ' + url + ' timed out'));
372    
373            clearFunction(callbackFunction);
374            removeScript(jsonpCallback + '_' + callbackFunction);
375          }, timeout);
376        });
377      };
378    
379      // export as global function
380      /*
381      let local;
382      if (typeof global !== 'undefined') {
383        local = global;
384      } else if (typeof self !== 'undefined') {
385        local = self;
386      } else {
387        try {
388          local = Function('return this')();
389        } catch (e) {
390          throw new Error('polyfill failed because global object is unavailable in this environment');
391        }
392      }
393      
394      local.fetchJsonp = fetchJsonp;
395      */
396    
397      module.exports = fetchJsonp;
398    });
399    },{}]},{},[1]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.