Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leaflet-bing-layer

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-bing-layer - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

79

leaflet-bing-layer.js

@@ -21,2 +21,9 @@ /* https://github.com/camsong/fetch-jsonp */

/**
* Converts tile xyz coordinates to Quadkey
* @param {Number} x
* @param {Number} y
* @param {Number} z
* @return {Number} Quadkey
*/
function toQuadKey (x, y, z) {

@@ -30,3 +37,8 @@ var key = ''

function bboxIntersect (bbox1, bbox2){
/**
* @param {Array} bbox1
* @param {Array} bbox2
* @return {Boolean} Returns true if bboxes intersect.
*/
function bboxIntersect (bbox1, bbox2) {
return !(

@@ -41,2 +53,12 @@ bbox1[0] > bbox2[2] ||

/**
* Converts Leaflet BBoxString to Bing BBox
* @param {String} bboxString 'southwest_lng,southwest_lat,northeast_lng,northeast_lat'
* @return {Array} [south_lat, west_lng, north_lat, east_lng]
*/
function toBingBBox (bboxString) {
var bbox = bboxString.split(',')
return [bbox[1], bbox[0], bbox[3], bbox[2]]
}
/**
* Create a new Bing Maps layer.

@@ -58,3 +80,4 @@ * @param {string|object} options Either a [Bing Maps Key](https://msdn.microsoft.com/en-us/library/ff428642.aspx) or an options object

imagerySet: 'Aerial',
culture: 'en-US'
culture: 'en-US',
minZoom: 1
},

@@ -74,2 +97,3 @@

options = L.setOptions(this, options)
options.minZoom = Math.max(1, options.minZoom)

@@ -84,2 +108,3 @@ var metaDataUrl = L.Util.template(L.BingLayer.METADATA_URL, {

// Keep a reference to the promise so we can use it later
this._fetch = window.fetchJsonp(metaDataUrl, {jsonpCallback: 'jsonp'})

@@ -137,2 +162,3 @@ .then(function (response) {

// Update the attribution control every time the map is moved
onAdd: function (map) {

@@ -143,2 +169,3 @@ map.on('moveend', this._updateAttribution, this)

// Clean up events
onRemove: function (map) {

@@ -153,5 +180,6 @@ map.off('moveend', this._updateAttribution, this)

}
this._url = metaData.resourceSets[0].resources[0].imageUrl
this._imageryProviders = metaData.resourceSets[0].resources[0].imageryProviders
this.options.subdomains = metaData.resourceSets[0].resources[0].imageUrlSubdomains
var resource = metaData.resourceSets[0].resources[0]
this._url = resource.imageUrl
this._imageryProviders = resource.imageryProviders
this.options.subdomains = resource.imageUrlSubdomains
this._updateAttribution()

@@ -161,2 +189,6 @@ return Promise.resolve()

/**
* Update the attribution control of the map with the provider attributions
* within the current map bounds
*/
_updateAttribution: function () {

@@ -166,33 +198,40 @@ var map = this._map

var zoom = map.getZoom()
var bbox = map.getBounds().toBBoxString().split(',')
var bbox = toBingBBox(map.getBounds().toBBoxString())
this._fetch.then(function () {
var attributions = this._getAttributions(bbox, zoom)
var newAttributions = this._getAttributions(bbox, zoom)
var prevAttributions = this._attributions
attributions.forEach(function (attr) {
// Add any new provider attributions in the current area to the attribution control
newAttributions.forEach(function (attr) {
if (prevAttributions.indexOf(attr) > -1) return
map.attributionControl.addAttribution(attr)
})
// Remove any attributions that are no longer in the current area from the attribution control
prevAttributions.filter(function (attr) {
if (attributions.indexOf(attr) > -1) return
if (newAttributions.indexOf(attr) > -1) return
map.attributionControl.removeAttribution(attr)
})
this._attributions = attributions
this._attributions = newAttributions
}.bind(this))
},
/**
* Returns an array of attributions for given bbox and zoom
* @private
* @param {Array} bbox [west, south, east, north]
* @param {Number} zoom
* @return {Array} Array of attribution strings for each provider
*/
_getAttributions: function (bbox, zoom) {
return this._imageryProviders.reduce(function (attribution, provider) {
var coverageAreas = provider.coverageAreas
for (var i = 0; i < coverageAreas.length; i++) {
if (bboxIntersect(bbox, coverageAreas[i].bbox) &&
zoom > coverageAreas[i].zoomMin &&
zoom < coverageAreas[i].zoomMax) {
attribution.push(provider.attribution)
return attribution
return this._imageryProviders.reduce(function (attributions, provider) {
for (var i = 0; i < provider.coverageAreas.length; i++) {
if (bboxIntersect(bbox, provider.coverageAreas[i].bbox) &&
zoom >= provider.coverageAreas[i].zoomMin &&
zoom <= provider.coverageAreas[i].zoomMax) {
attributions.push(provider.attribution)
return attributions
}
}
return attribution
return attributions
}, [])
}
})

@@ -199,0 +238,0 @@

{
"name": "leaflet-bing-layer",
"version": "1.1.1",
"version": "1.1.2",
"description": "Bing Maps Layer for Leaflet v1.0.0",

@@ -5,0 +5,0 @@ "main": "leaflet-bing-layer.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc