Skip to content

Commit

Permalink
WMS Layer support added
Browse files Browse the repository at this point in the history
  • Loading branch information
ashina-creator committed Nov 1, 2016
1 parent de8118f commit 87a25a0
Show file tree
Hide file tree
Showing 7 changed files with 816 additions and 2 deletions.
76 changes: 75 additions & 1 deletion Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ define([
'esri/layers/ArcGISDynamicMapServiceLayer',
'esri/layers/ArcGISTiledMapServiceLayer',
'esri/layers/ArcGISImageServiceLayer',
"esri/layers/WMSLayer",
"esri/layers/WMSLayerInfo",
'esri/layers/FeatureLayer',
'esri/layers/WebTiledLayer',
'esri/layers/ImageParameters',
Expand Down Expand Up @@ -54,6 +56,8 @@ define([
ArcGISDynamicMapServiceLayer,
ArcGISTiledMapServiceLayer,
ArcGISImageServiceLayer,
WMSLayer,
WMSLayerInfo,
FeatureLayer,
WebTiledLayer,
ImageParameters,
Expand Down Expand Up @@ -593,6 +597,28 @@ define([
_basemapGallery.add(_newBasemap);
_basemapGallery.select('defaultBasemap');
_basemapGallery.destroy();
} else if (layer.type.toUpperCase() === 'WMS') {
lLayer = new WMSLayer(layer.url)//,{visibleLayers:layer.visibleLayers,resourceInfo:layer.resourceInfo});
if (layer.name) {
lLayer._titleForLegend = layer.name;
lLayer.title = layer.name;
lLayer.noservicename = true;
}
_layersToAdd.push(lLayer);
lLayer.on("load",lang.hitch(this,function(_layer){
//console.log(layer)
_layer.layer.title = layer.name
if (layer.maxScale){
_layer.layer.maxScale = layer.maxScale
}
if (layer.minScale){
_layer.layer.minScale = layer.minScale
}
_layer.layer.layerInfos = layer.resourceInfo.layerInfos
//_layer.layer.visibleLayers = layer.visibleLayers
_layer.layer.setVisibleLayers(layer.visibleLayers)
}))
this._viewerMap.setInfoWindowOnClick(true);
} else if (layer.type.toUpperCase() === 'GEOJSON') {
dojo.xhrGet({
url: lang.trim(layer.url || ""),
Expand Down Expand Up @@ -725,16 +751,35 @@ define([
}))
this._operLayers = newOriginOperLayers;
LayerInfos.getInstanceSync()._initLayerInfos();
console.log('work?')
});

//hook into the updater, and use the empty property as our 'hitch'
aspect.after(LayerInfos.prototype,"update",function(){
//this._layerInfos = this._finalLayerInfos;
array.forEach(this._finalLayerInfos,lang.hitch(this,function(layerInfo){
if (layerInfo.layerObject.layers){
layerInfo.originOperLayer.layers = layerInfo.layerObject.layers
}
if (layerInfo.layerObject.showLegend === false){
layerInfo.originOperLayer.showLegend = layerInfo.layerObject.showLegend
}
/*
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)
*/
}))
});

Expand All @@ -746,10 +791,39 @@ define([
})
return returnArray;
}))

/*
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)
aspect.around(LayerInfos.prototype,"_onTableChange",lang.hitch(this,function(originalFunction){
return lang.hitch(this,function(tableInfos,changedType){
if (tableInfos.length > 0){
return originalFunction.call(this,tableInfos,changedType);
}
})
}), true)
*/
//var testlyrinfo = new WMSLayerInfo({"name":"vegetation","title":"Vegetation"})
//var testlyr = new WMSLayer("http://wms.ess-ws.nrcan.gc.ca/wms/toporama_en",{visibleLayers:["Vegetation","Feature_names"],resourceInfo:{layerInfos:testlyrinfo,extent:_viewerMap.extent}})
//_layersToAdd.push(testlyr);

window._viewerMap.addLayers(_layersToAdd);
window._viewerMap.updatedLayerInfos = LayerInfos.getInstanceSync()

//LayerInfos.getInstanceSync()._initLayerInfos();
LayerInfos.getInstanceSync()._initTablesInfos()
//LayerInfos.getInstanceSync().update()
}
});
return clazz;
Expand Down
4 changes: 4 additions & 0 deletions setting/Setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<span class="btn-add-icon"></span>
<span class="btn-add-label">${nls.addimagelayer}</span>
</div>
<div class="btn-image-section" data-dojo-attach-point="btnAddWMSLayer" style="margin-right:10px;">
<span class="btn-add-icon"></span>
<span class="btn-add-label">${nls.addwmslayer}</span>
</div>
</div>
<div class="layers-table" data-dojo-attach-point="LayersTable" data-dojo-type="jimu/dijit/SimpleTable" data-dojo-props='fields:[{name:"name",title:"${nls.layerTitle}",class:"layer-title",type:"text",editable:false},{name:"type",title:"${nls.layerType}",class:"layer-type",type:"text",editable:false,width:"200px"},{name:"actions",title:"${nls.actions}",class:"actions",width:"120px",type:"actions",actions:["up","down","edit","delete"]}]'
></div>
Expand Down
87 changes: 87 additions & 0 deletions setting/Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ define([
'./geoJSONEdit',
'./WebTiledLayerEdit',
'./ImageLayerEdit',
'./WMSLayerEdit',
'./ReverseProxyEdit',
'dojo/keys'
],
Expand All @@ -61,6 +62,7 @@ define([
GeoJsonEdit,
WebTiledLayerEdit,
ImageLayerEdit,
WMSLayerEdit,
ReverseProxyEdit,
keys) {
return declare([BaseWidgetSetting, _WidgetsInTemplateMixin], {
Expand All @@ -70,6 +72,7 @@ define([
popupfeatlyredit: null,
popuptiledlyredit: null,
popupwebtiledlyredit: null,
popupwmsedit: null,
popupbmedit: null,
popupgjedit: null,
popupimageedit: null,
Expand All @@ -82,15 +85,20 @@ define([
this._bindEvents();
this.setConfig(this.config);
aspect.before(this, 'destroy', function(){
//LayerInfos.getInstanceSync()._operLayers = this.map.updatedLayerInfos._operLayers;
LayerInfos.getInstanceSync()._tables = this.map.updatedLayerInfos._tables;
//LayerInfos.getInstanceSync()._initLayerInfos();
LayerInfos.getInstanceSync()._initTablesInfos();
aspect.before(LayerInfos.prototype,"update",function(){
var newOriginOperLayers = []
//LayerInfos.getInstanceSync()._tables = this.map.updatedLayerInfos._tables;
array.forEach(this._finalLayerInfos,lang.hitch(this,function(layerInfo){
newOriginOperLayers.push(layerInfo.originOperLayer);
}))
this._operLayers = newOriginOperLayers;
LayerInfos.getInstanceSync()._initLayerInfos();
//LayerInfos.getInstanceSync()._initTablesInfos();
console.log('work?')
});
})
},
Expand Down Expand Up @@ -182,6 +190,8 @@ define([
return this.nls.webtiledlayer;
}else if(type === 'IMAGE'){
return this.nls.imagelayer;
}else if(type === 'WMS'){
return this.nls.wmslayer;
}
},

Expand Down Expand Up @@ -214,6 +224,8 @@ define([
this._openWebTileEdit(this.nls.editwebtile + ': ' + editLayer.name , tr);
}else if(editLayer.type.toUpperCase() === 'IMAGE'){
this._openImageEdit(this.nls.editimage + ': ' + editLayer.name , tr);
}else if(editLayer.type.toUpperCase() === 'WMS'){
this._openWMSEdit(this.nls.editwms + ': ' + editLayer.name , tr);
}
})));
this.own(on(this.LayersTable,'row-delete',lang.hitch(this,function(tr){
Expand Down Expand Up @@ -289,6 +301,16 @@ define([
this._openImageEdit(this.nls.addimagelayer, tr);
}
})));
this.own(on(this.btnAddWMSLayer,'click',lang.hitch(this,function(){
var args = {
config:{type:'WMS'}
};
this.popupState = 'ADD';
var tr = this._createLayer(args);
if (tr) {
this._openWMSEdit(this.nls.addwmslayer, tr);
}
})));
},

_onDLEditOk: function() {
Expand Down Expand Up @@ -670,6 +692,71 @@ define([
this.popupimageedit.startup();
},

_onWMSEditOk: function() {
var layerConfig = this.popupwmsedit.getConfig();
console.info(layerConfig);

if (layerConfig.length < 0) {
new Message({
message: this.nls.warning
});
return;
}
if(this.popupState === 'ADD'){
this.LayersTable.editRow(layerConfig[1], {
name: layerConfig[0].name
});
layerConfig[1].singleLayer = layerConfig[0];
this.popupState = '';
}else{
this.LayersTable.editRow(layerConfig[1], {
name: layerConfig[0].name
});
layerConfig[1].singleLayer = layerConfig[0];
}

this.popup.close();
this.popupState = '';
},

_onWMSEditClose: function() {
var layerConfig = this.popupwmsedit.getConfig();
if(this.popupState === 'ADD'){
this.LayersTable.deleteRow(layerConfig[1]);
}
this.popupwmsedit = null;
this.popup = null;
},

_openWMSEdit: function(title, tr) {
this.popupwmsedit = new WMSLayerEdit({
nls: this.nls,
config: tr.singleLayer || {},
tr: tr,
map: this.map
});

this.popup = new Popup({
titleLabel: title,
autoHeight: true,
content: this.popupwmsedit,
container: 'main-page',
width: 840,
height: 420,
buttons: [{
label: this.nls.ok,
key: keys.ENTER,
onClick: lang.hitch(this, '_onWMSEditOk')
}, {
label: this.nls.cancel,
key: keys.ESCAPE
}],
onClose: lang.hitch(this, '_onWMSEditClose')
});
html.addClass(this.popup.domNode, 'widget-setting-popup');
this.popupwmsedit.startup();
},

_onGJEditOk: function() {
var layerConfig = this.popupgjedit.getConfig();
console.info(layerConfig);
Expand Down
Loading

0 comments on commit 87a25a0

Please sign in to comment.