Created
September 5, 2015 18:58
-
-
Save geographika/af6faab6587cc7768ec4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
Ext.define('GeoExt.tree.ParameterLoader', { | |
requires: [ | |
'GeoExt.tree.LayerParamNode' | |
], | |
extend: 'GeoExt.tree.LayerLoader', | |
layerTitle: "", | |
constructor: function (config) { | |
//var customConfig = { | |
// preloadChildren: true | |
//}; | |
//Ext.apply(config, customConfig); | |
this.callParent([config]); | |
}, | |
createTooltip: function (layer) { | |
var scale = ""; | |
if (layer.maxScale && layer.minScale) { | |
scale = Ext.String.format("Visible between <b>1:{0}</b> and <b>1:{1}</b>", parseInt(layer.maxScale, 10), | |
parseInt(layer.minScale, 10)); | |
} | |
else { | |
if (layer.maxScale) { | |
scale = Ext.String.format("Visible at <b>1:{0}</b> and above", parseInt(layer.maxScale, 10)); | |
} | |
if (layer.minScale) { | |
scale = Ext.String.format("Visible at <b>1:{0}<b> and below", layer.minScale); | |
} | |
} | |
return scale; | |
}, | |
setAttributes: function (attr, rec) { | |
//if (this.baseAttrs) { | |
// Ext.apply(attr, this.baseAttrs); | |
//} | |
if (rec) { | |
//custom attributes | |
attr.iconCls = rec.get("iconCls"); | |
//attr.qtip = rec.get("qtip"); | |
//attr.text = rec.get("text"); // set by parameter loader | |
//attr.labels = rec.get("labels"); | |
//attr.legendURL = rec.get("legendURL"); | |
} | |
attr.layerOn = false; | |
//attr.scaletip = this.createTooltip(attr.layer); | |
return attr; | |
}, | |
createNode: function (attr) { | |
if (attr.bypassLoader !== true) { | |
// allow the custom loader to be bypassed | |
// so ready-made child nodes can be added to the parent node | |
var layerStore = this.store; //attr.layerStore; | |
var rec = layerStore.getByLayer(attr.layer); | |
attr = this.setAttributes(attr, rec); | |
} | |
return this.callParent([attr]); | |
}, | |
filter: function (record) { | |
// get the single layer with a matching title | |
var layerTitle = record.get("text"); | |
if (layerTitle) { | |
return layerTitle.localeCompare(this.layerTitle) === 0; | |
} | |
}, | |
addLayerNode: function (node, layerRecord, index) { | |
index = index || 0; | |
if (this.filter(layerRecord) === true) { | |
var layer = layerRecord.getLayer(); | |
var parameters = layerRecord.get("parameters").reverse(); | |
var aliases = layerRecord.get("parameterAliases").reverse(); | |
var parameterName = layerRecord.get("parameterName"); | |
var params = {}; | |
params[parameterName] = parameters; | |
layer.mergeNewParams(params); | |
var child; | |
// now add a child for each parameter setting | |
Ext.each(parameters, function (param, idx) { | |
child = this.createNode({ | |
plugins: [{ | |
ptype: 'gx_layerparam' // custom type | |
}], | |
layer: layer, | |
text: aliases[idx], | |
param: parameterName, | |
item: param, | |
listeners: { | |
move: this.onChildMove, | |
scope: this | |
} | |
}); | |
//if (index !== undefined) { | |
// node.insertChild(index, child); | |
//} else { | |
// node.appendChild(child); | |
//} | |
node.appendChild(child); | |
node.getChildAt(index).on("move", this.onChildMove, this); | |
}, this); | |
} | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment