Permalink
Browse files

rebuild

  • Loading branch information...
patrickarlt committed Feb 25, 2014
1 parent c599305 commit 7792aca227e8ec5e1ac0d07736207ad233961f40
View
@@ -279,6 +279,58 @@ L.esri.Mixins.identifiableLayer = {
}
};
+L.esri.Mixins.metadata = {
+ _getMetadata: function(){
+ var requestOptions = {};
+
+ if(this.options.token){
+ requestOptions.token = this.options.token;
+ }
+
+ L.esri.get(this.url, requestOptions, function(response){
+ // if there is a invalid token error...
+ if(response.error && (response.error.code === 499 || response.error.code === 498)) {
+
+ // if we have already asked for authentication
+ if(!this._authenticating){
+
+ // ask for authentication
+ this._authenticating = true;
+
+ // ask for authentication. developer should fire the retry() method with the new token
+ this.fire('authenticationrequired', {
+ retry: L.Util.bind(function(token){
+ // set the new token
+ this.options.token = token;
+
+ // get metadata again
+ this._getMetadata();
+
+ // reload the image so it shows up with the new token
+ this._update();
+ }, this)
+ });
+ }
+ } else {
+ var extent = response.extent || response.initialExtent || response.fullExtent;
+ var payload = {
+ metadata: response
+ };
+
+ if(extent && this._map){
+ if(this._map && (extent.spatialReference.wkid === 102100 || extent.spatialReference.wkid === 3857)) {
+ payload.bounds = L.esri.Util.mercatorExtentToBounds(extent, this._map);
+ } else if(extent.spatialReference.wkid === 4326) {
+ payload.bounds = L.esri.Util.extentToBounds(extent);
+ }
+ }
+
+ this.fire("metadata", payload);
+ }
+
+ }, this);
+ }
+};
(function(L){
// shallow object clone for feature properties and attributes
// from http://jsperf.com/cloning-an-object/2
@@ -651,9 +703,15 @@ L.esri.Mixins.identifiableLayer = {
// convert an extent (ArcGIS) to LatLngBounds (Leaflet)
extentToBounds: function(extent){
- var southWest = new L.LatLng(extent.ymin, extent.xmin);
- var northEast = new L.LatLng(extent.ymax, extent.xmax);
- return new L.LatLngBounds(southWest, northEast);
+ var sw = new L.LatLng(extent.ymin, extent.xmin);
+ var ne = new L.LatLng(extent.ymax, extent.xmax);
+ return new L.LatLngBounds(sw, ne);
+ },
+
+ mercatorExtentToBounds: function(extent, map){
+ var sw = map.unproject(L.point([extent.ymin, extent.xmin]));
+ var ne = map.unproject(L.point([extent.ymax, extent.xmax]));
+ return new L.LatLngBounds(sw, ne);
},
// convert an LatLngBounds (Leaflet) to extent (ArcGIS)
@@ -1683,15 +1741,9 @@ L.esri._rbush = rbush;
this.url = L.esri.Util.cleanUrl(url);
L.Util.setOptions(this, options);
- var requestOptions = {};
-
- if(this.options.token){
- requestOptions.token = this.options.token;
- }
+ L.Util.setOptions(this, options);
- L.esri.get(this.url, requestOptions, function(response){
- this.fire("metadata", { metadata: response });
- }, this);
+ this._getMetadata();
L.GeoJSON.prototype.initialize.call(this, [], options);
},
@@ -1779,6 +1831,8 @@ L.esri._rbush = rbush;
}
});
+ L.esri.FeatureLayer.include(L.esri.Mixins.metadata);
+
L.esri.featureLayer = function(url, options){
return new L.esri.FeatureLayer(url, options);
};
@@ -1793,7 +1847,7 @@ L.esri.TiledMapLayer = L.TileLayer.extend({
options = options || {};
// set the urls
- this.serviceUrl = L.esri.Util.cleanUrl(url);
+ this.url = L.esri.Util.cleanUrl(url);
this.tileUrl = L.esri.Util.cleanUrl(url) + "tile/{z}/{y}/{x}";
//if this is looking at the AGO tiles subdomain insert the subdomain placeholder
@@ -1802,15 +1856,17 @@ L.esri.TiledMapLayer = L.TileLayer.extend({
options.subdomains = ["1", "2", "3", "4"];
}
- L.esri.get(this.serviceUrl, {}, function(response){
- this.fire("metadata", { metadata: response });
- }, this);
+ L.Util.setOptions(this, options);
+
+ this._getMetadata();
// init layer by calling TileLayers initialize method
L.TileLayer.prototype.initialize.call(this, this.tileUrl, options);
}
});
+L.esri.TiledMapLayer.include(L.esri.Mixins.metadata);
+
L.esri.tiledMapLayer = function(key, options){
return new L.esri.TiledMapLayer(key, options);
};
@@ -1859,7 +1915,7 @@ L.esri.DynamicMapLayer = L.Class.extend({
},
initialize: function (url, options) {
- this.serviceUrl = L.esri.Util.cleanUrl(url);
+ this.url = L.esri.Util.cleanUrl(url);
this._layerParams = L.Util.extend({}, this._defaultLayerParams);
for (var opt in options) {
@@ -1871,53 +1927,13 @@ L.esri.DynamicMapLayer = L.Class.extend({
this._parseLayers();
this._parseLayerDefs();
-
L.Util.setOptions(this, options);
- if(!this._layerParams.transparent) {
- this.options.opacity = 1;
- }
-
this._getMetadata();
- },
-
- _getMetadata: function(){
- var requestOptions = {};
-
- if(this.options.token){
- requestOptions.token = this.options.token;
+ if(!this._layerParams.transparent) {
+ this.options.opacity = 1;
}
-
- L.esri.get(this.serviceUrl, requestOptions, function(response){
- // if there is a invalid token error...
- if(response.error && (response.error.code === 499 || response.error.code === 498)) {
-
- // if we have already asked for authentication
- if(!this._authenticating){
-
- // ask for authentication
- this._authenticating = true;
-
- // ask for authentication. developer should fire the retry() method with the new token
- this.fire('authenticationrequired', {
- retry: L.Util.bind(function(token){
- // set the new token
- this.options.token = token;
-
- // get metadata again
- this._getMetadata();
-
- // reload the image so it shows up with the new token
- this._update();
- }, this)
- });
- }
- } else {
- this.fire("metadata", { metadata: response });
- }
-
- }, this);
},
onAdd: function (map) {
@@ -2044,7 +2060,7 @@ L.esri.DynamicMapLayer = L.Class.extend({
this._layerParams.token = this.options.token;
}
- var url = this.serviceUrl + 'export' + L.Util.getParamString(this._layerParams);
+ var url = this.url + 'export' + L.Util.getParamString(this._layerParams);
return url;
},
@@ -2102,6 +2118,7 @@ L.esri.DynamicMapLayer = L.Class.extend({
});
L.esri.DynamicMapLayer.include(L.Mixin.Events);
+L.esri.DynamicMapLayer.include(L.esri.Mixins.metadata);
L.esri.dynamicMapLayer = function (url, options) {
return new L.esri.DynamicMapLayer(url, options);
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -18,17 +18,10 @@
},
initialize: function(url, options){
this.url = L.esri.Util.cleanUrl(url);
- L.Util.setOptions(this, options);
-
- var requestOptions = {};
- if(this.options.token){
- requestOptions.token = this.options.token;
- }
+ L.Util.setOptions(this, options);
- L.esri.get(this.url, requestOptions, function(response){
- this.fire("metadata", { metadata: response });
- }, this);
+ this._getMetadata();
this._loaded = [];
this.cluster = this.options.cluster || new L.MarkerClusterGroup();
@@ -107,6 +100,7 @@
});
L.esri.ClusteredFeatureLayer.include(L.Mixin.Events);
+ L.esri.ClusteredFeatureLayer.include(L.esri.Mixins.metadata);
L.esri.clusteredFeatureLayer = function(url, options){
return new L.esri.ClusteredFeatureLayer(url, options);

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -279,6 +279,58 @@ L.esri.Mixins.identifiableLayer = {
}
};
+L.esri.Mixins.metadata = {
+ _getMetadata: function(){
+ var requestOptions = {};
+
+ if(this.options.token){
+ requestOptions.token = this.options.token;
+ }
+
+ L.esri.get(this.url, requestOptions, function(response){
+ // if there is a invalid token error...
+ if(response.error && (response.error.code === 499 || response.error.code === 498)) {
+
+ // if we have already asked for authentication
+ if(!this._authenticating){
+
+ // ask for authentication
+ this._authenticating = true;
+
+ // ask for authentication. developer should fire the retry() method with the new token
+ this.fire('authenticationrequired', {
+ retry: L.Util.bind(function(token){
+ // set the new token
+ this.options.token = token;
+
+ // get metadata again
+ this._getMetadata();
+
+ // reload the image so it shows up with the new token
+ this._update();
+ }, this)
+ });
+ }
+ } else {
+ var extent = response.extent || response.initialExtent || response.fullExtent;
+ var payload = {
+ metadata: response
+ };
+
+ if(extent && this._map){
+ if(this._map && (extent.spatialReference.wkid === 102100 || extent.spatialReference.wkid === 3857)) {
+ payload.bounds = L.esri.Util.mercatorExtentToBounds(extent, this._map);
+ } else if(extent.spatialReference.wkid === 4326) {
+ payload.bounds = L.esri.Util.extentToBounds(extent);
+ }
+ }
+
+ this.fire("metadata", payload);
+ }
+
+ }, this);
+ }
+};
(function(L){
var tileProtocol = (window.location.protocol !== "https:") ? "http:" : "https:";
Oops, something went wrong.

0 comments on commit 7792aca

Please sign in to comment.