Skip to content

Commit

Permalink
rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickarlt committed Feb 25, 2014
1 parent c599305 commit 7792aca
Show file tree
Hide file tree
Showing 18 changed files with 293 additions and 169 deletions.
135 changes: 76 additions & 59 deletions dist/esri-leaflet-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
},
Expand Down Expand Up @@ -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);
};
Expand All @@ -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
Expand All @@ -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);
};
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
},
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions dist/esri-leaflet.js

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions dist/extras/clustered-feature-layer-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion dist/extras/clustered-feature-layer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions dist/extras/esri-basemaps-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:";
Expand Down
Loading

0 comments on commit 7792aca

Please sign in to comment.