[PLUGINS] ~maj globale
[lhc/web/www.git] / www / plugins / gis / lib / leaflet / plugins / Bing.js
index 1a98f70..8e2bd12 100755 (executable)
@@ -6,15 +6,16 @@ L.BingLayer = L.TileLayer.extend({
                culture: ''
        },
 
-       initialize: function(key, options) {
+       initialize: function (key, options) {
                L.Util.setOptions(this, options);
 
                this._key = key;
                this._url = null;
+               this._providers = [];
                this.metaRequested = false;
        },
 
-       tile2quad: function(x, y, z) {
+       tile2quad: function (x, y, z) {
                var quad = '';
                for (var i = z; i > 0; i--) {
                        var digit = 0;
@@ -26,16 +27,16 @@ L.BingLayer = L.TileLayer.extend({
                return quad;
        },
 
-       getTileUrl: function(p, z) {
+       getTileUrl: function (tilePoint) {
                var zoom = this._getZoomForUrl();
                var subdomains = this.options.subdomains,
-                       s = this.options.subdomains[Math.abs((p.x + p.y) % subdomains.length)];
+                       s = this.options.subdomains[Math.abs((tilePoint.x + tilePoint.y) % subdomains.length)];
                return this._url.replace('{subdomain}', s)
-                               .replace('{quadkey}', this.tile2quad(p.x, p.y, zoom))
+                               .replace('{quadkey}', this.tile2quad(tilePoint.x, tilePoint.y, zoom))
                                .replace('{culture}', this.options.culture);
        },
 
-       loadMetadata: function() {
+       loadMetadata: function () {
                if (this.metaRequested) return;
                this.metaRequested = true;
                var _this = this;
@@ -45,6 +46,7 @@ L.BingLayer = L.TileLayer.extend({
                        var e = document.getElementById(cbid);
                        e.parentNode.removeChild(e);
                        if (meta.errorDetails) {
+                               throw new Error(meta.errorDetails);
                                return;
                        }
                        _this.initMetadata(meta);
@@ -60,11 +62,10 @@ L.BingLayer = L.TileLayer.extend({
                document.getElementsByTagName('head')[0].appendChild(script);
        },
 
-       initMetadata: function(meta) {
+       initMetadata: function (meta) {
                var r = meta.resourceSets[0].resources[0];
                this.options.subdomains = r.imageUrlSubdomains;
                this._url = r.imageUrl;
-               this._providers = [];
                if (r.imageryProviders) {
                        for (var i = 0; i < r.imageryProviders.length; i++) {
                                var p = r.imageryProviders[i];
@@ -84,14 +85,14 @@ L.BingLayer = L.TileLayer.extend({
                this._update();
        },
 
-       _update: function() {
+       _update: function () {
                if (this._url === null || !this._map) return;
                this._update_attribution();
                L.TileLayer.prototype._update.apply(this, []);
        },
 
-       _update_attribution: function() {
-               var bounds = this._map.getBounds();
+       _update_attribution: function () {
+               var bounds = L.latLngBounds(this._map.getBounds().getSouthWest().wrap(),this._map.getBounds().getNorthEast().wrap());
                var zoom = this._map.getZoom();
                for (var i = 0; i < this._providers.length; i++) {
                        var p = this._providers[i];
@@ -107,13 +108,13 @@ L.BingLayer = L.TileLayer.extend({
                        }
                }
        },
-       
-       onAdd: function(map) {
+
+       onAdd: function (map) {
                this.loadMetadata();
                L.TileLayer.prototype.onAdd.apply(this, [map]);
        },
 
-       onRemove: function(map) {
+       onRemove: function (map) {
                for (var i = 0; i < this._providers.length; i++) {
                        var p = this._providers[i];
                        if (p.active && this._map.attributionControl) {
@@ -121,7 +122,7 @@ L.BingLayer = L.TileLayer.extend({
                                p.active = false;
                        }
                }
-               L.TileLayer.prototype.onRemove.apply(this, [map]);
+               L.TileLayer.prototype.onRemove.apply(this, [map]);
        }
 });