Skip to content

Commit

Permalink
aspect used to make core code change unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ashina-creator committed Apr 14, 2016
1 parent 25fe545 commit c87b6cd
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ define([
'dojo/_base/array',
'dojo/_base/query',
'dojo/topic',
'dojo/aspect',
'jimu/LayerInfos/LayerInfos',
'esri/geometry/webMercatorUtils',
'esri/layers/ArcGISDynamicMapServiceLayer',
'esri/layers/ArcGISTiledMapServiceLayer',
Expand Down Expand Up @@ -38,6 +40,8 @@ define([
array,
query,
topic,
aspect,
LayerInfos,
webMercatorUtils,
ArcGISDynamicMapServiceLayer,
ArcGISTiledMapServiceLayer,
Expand Down Expand Up @@ -99,6 +103,8 @@ define([
});
}

var _layersToAdd=[];

this.config.layers.layer.forEach(function(layer) {
var lLayer;
var lOptions = {};
Expand Down Expand Up @@ -256,7 +262,8 @@ define([

evt.layer.setVisibleLayers(lOptions.hidelayers);
});
this._viewerMap.addLayer(lLayer);
//this._viewerMap.addLayer(lLayer);
_layersToAdd.push(lLayer);
this._viewerMap.setInfoWindowOnClick(true);
} else if (layer.type.toUpperCase() === 'WEBTILEDLAYER') {
if (layer.hasOwnProperty('subdomains')) {
Expand All @@ -279,7 +286,8 @@ define([
}
evt.layer.name = lOptions.id;
});
this._viewerMap.addLayer(lLayer);
//this._viewerMap.addLayer(lLayer);
_layersToAdd.push(lLayer);
} else if (layer.type.toUpperCase() === 'WEBTILEDBASEMAP') {
lOptions.type = "WebTiledLayer"
lOptions.url = layer.url
Expand Down Expand Up @@ -384,7 +392,8 @@ define([
}
evt.layer.name = lOptions.id;
});
this._viewerMap.addLayer(lLayer);
//this._viewerMap.addLayer(lLayer);
_layersToAdd.push(lLayer);
} else if (layer.type.toUpperCase() === 'TILED') {
if (layer.displayLevels) {
lOptions.displayLevels = layer.displayLevels.split(',');
Expand Down Expand Up @@ -427,7 +436,8 @@ define([
});
lLayer.setInfoTemplates(finalInfoTemp2);
}
this._viewerMap.addLayer(lLayer);
//this._viewerMap.addLayer(lLayer);
_layersToAdd.push(lLayer);
} else if (layer.type.toUpperCase() === 'BASEMAP') {
var bmLayers = array.map(layer.layers.layer, function(bLayer) {
var bmLayerObj = {
Expand Down Expand Up @@ -569,12 +579,47 @@ define([
evt.layer.setMaxScale(lOptions.maxScale)
}
})
this._viewerMap.addLayer(lLayer);
//this._viewerMap.addLayer(lLayer);
_layersToAdd.push(lLayer);
}), lang.hitch(this, function(err) {
console.log('error')
}));
}
});
//hook into the updater, and use the empty property as our 'hitch'
aspect.after(LayerInfos.prototype,"update",function(){
array.forEach(this._finalLayerInfos,function(layerInfo){
aspect.before(layerInfo.__proto__,"_bindEvent",function(){
if (this.layerObject){
if (!this.layerObject.empty){
this.layerObject.modified = true;
this.layerObject.empty = true;
}
}
})
aspect.after(layerInfo.__proto__,"_bindEvent",function(){
if (this.layerObject){
if (this.layerObject.modified){
this.layerObject.empty = false;
}
}
},true)
})
});
aspect.before(LayerInfos.prototype,"_addTable",function(changedType,evt){
var _foundMatch = false
array.forEach(this._finalTableInfos,function(table){
if (table.id == changedType.id){
_foundMatch = true;
}
})
if (!_foundMatch){
return [changedType,evt];
}else{
return [null, null]
}
}, true)
window._viewerMap.addLayers(_layersToAdd);
}
});
return clazz;
Expand Down

0 comments on commit c87b6cd

Please sign in to comment.