Skip to content

Commit

Permalink
issue planetfederal#216 - Vector Layer Styling - refine and and refac…
Browse files Browse the repository at this point in the history
…tor into StylesDialog.js ABC
  • Loading branch information
justb4 committed Jan 21, 2014
1 parent e091852 commit bf12ae3
Show file tree
Hide file tree
Showing 5 changed files with 1,466 additions and 227 deletions.
1 change: 1 addition & 0 deletions src/script/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"widgets/QueryPanel.js",
"widgets/StylePropertiesDialog.js",
"widgets/WMSLayerPanel.js",
"widgets/StylesDialog.js",
"widgets/WMSStylesDialog.js",
"widgets/VectorStylesDialog.js",
"widgets/NewSourceDialog.js",
Expand Down
155 changes: 42 additions & 113 deletions src/script/plugins/VectorStyleWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,42 +69,29 @@ gxp.plugins.VectorStyleWriter = Ext.extend(gxp.plugins.StyleWriter, {
* * scope - ``Object`` A scope to call the ``success`` function with.
*/
write: function (options) {
var layerRecord = this.target.layerRecord;
var layer = layerRecord.getLayer();
if (layer.customStyling && layer.features && layer.styleMap && layer.styleMap.styles['default']) {
var layerStyle = layer.styleMap.styles['default'];

var features = layer.features, feature, featureStyle;
for (var f = 0; f < features.length; f++) {
feature = features[f];
if (feature.style) {
continue;
}
featureStyle = layerStyle;
if (feature.renderIntent && feature.renderIntent != 'default') {
featureStyle = layer.styleMap.styles[feature.renderIntent ];
}
// Some features still may not yet have local style object
// assign now from Layer Style before Style permanently changes
feature.style = featureStyle.createSymbolizer(feature);
}
}

this.target.stylesStore.commitChanges();
this.target.fireEvent("saved", this.target, this.target.selectedStyle.get("name"));
return;

// delete this._failed;
// options = options || {};
// var dispatchQueue = [];
// var store = this.target.stylesStore;
// store.each(function(rec) {
// (rec.phantom || store.modified.indexOf(rec) !== -1) &&
// this.writeStyle(rec, dispatchQueue);
// }, this);
// var success = function() {
// var target = this.target;
// if (this._failed !== true) {
// // we don't need any callbacks for deleting styles.
// this.deleteStyles();
// var modified = this.target.stylesStore.getModifiedRecords();
// for (var i=modified.length-1; i>=0; --i) {
// // mark saved
// modified[i].phantom = false;
// }
// target.stylesStore.commitChanges();
// options.success && options.success.call(options.scope);
// target.fireEvent("saved", target, target.selectedStyle.get("name"));
// } else {
// target.fireEvent("savefailed", target, target.selectedStyle.get("name"));
// }
// };
// if(dispatchQueue.length > 0) {
// gxp.util.dispatch(dispatchQueue, function() {
// this.assignStyles(options.defaultStyle, success);
// }, this);
// } else {
// this.assignStyles(options.defaultStyle, success);
// }
},

/** private: method[writeStyle]
Expand All @@ -118,45 +105,10 @@ gxp.plugins.VectorStyleWriter = Ext.extend(gxp.plugins.StyleWriter, {
*/
writeStyle: function (styleRec, dispatchQueue) {
var styleName = styleRec.get("userStyle").name;
// dispatchQueue.push(function(callback, storage) {
// Ext.Ajax.request({
// method: styleRec.phantom === true ? "POST" : "PUT",
// url: this.baseUrl + "/styles" + (styleRec.phantom === true ?
// "" : "/" + styleName + ".xml"),
// headers: {
// "Content-Type": "application/vnd.ogc.sld+xml; charset=UTF-8"
// },
// xmlData: this.target.createSLD({
// userStyles: [styleName]
// }),
// failure: function() {
// this._failed = true;
// callback.call(this);
// },
// success: styleRec.phantom === true ? function(){
// Ext.Ajax.request({
// method: "POST",
// url: this.baseUrl + "/layers/" +
// this.target.layerRecord.get("name") + "/styles.json",
// jsonData: {
// "style": {
// "name": styleName
// }
// },
// failure: function() {
// this._failed = true;
// callback.call(this);
// },
// success: callback,
// scope: this
// });
// } : callback,
// scope: this
// });
// });
},

/** private: method[assignStyles]
* Assigns Style's symbology from (Vector) Layer to Features in Layer.
* :arg defaultStyle: ``String`` The default style. Optional.
* :arg callback: ``Function`` The function to call when all operations
* succeeded. Will be called in the scope of this instance. Optional.
Expand All @@ -170,7 +122,7 @@ gxp.plugins.VectorStyleWriter = Ext.extend(gxp.plugins.StyleWriter, {
var layerStyles = layer.styleMap;
var styleRec = this.target.selectedStyle;
if (styleRec) {
var oldStyleName = styleRec.get("userStyle").name;
// var oldStyleName = styleRec.get("userStyle").name;
var oldStyle = styleRec.get("userStyle");
var newStyle = oldStyle.clone();
newStyle.defaultsPerSymbolizer = false;
Expand All @@ -181,7 +133,7 @@ gxp.plugins.VectorStyleWriter = Ext.extend(gxp.plugins.StyleWriter, {
var symbolizer;
if (newStyle.rules) {
for (var i = 0, len = newStyle.rules.length; i < len; i++) {
var rule = newStyle.rules[i].clone();
var rule = newStyle.rules[i];
rule.symbolizer = {};

for (var j = 0; j < rule.symbolizers.length; j++) {
Expand All @@ -193,12 +145,11 @@ gxp.plugins.VectorStyleWriter = Ext.extend(gxp.plugins.StyleWriter, {
textStyle.fontSize = symbolizer.fontSize;
textStyle.fontWeight = symbolizer.fontWeight;
textStyle.fontStyle = symbolizer.fontStyle;
textStyle.fontColor= symbolizer.fontColor;
textStyle.fontColor = symbolizer.fontColor;
}
rule.symbolizer[symbolType] = rule.symbolizers[j];
rule.symbolizer[symbolType] = rule.symbolizers[j].clone();
// newStyle.label = rule.symbolizer[symbolType].label;
}
newStyle.rules[i] = rule;
rule.symbolizers = undefined;
}
}
Expand All @@ -208,51 +159,29 @@ gxp.plugins.VectorStyleWriter = Ext.extend(gxp.plugins.StyleWriter, {
layerStyles.styles[styleName] = newStyle;
// newStyle.defaultStyle = undefined;
var feature;
layer.eraseFeatures(layer.features);
for (var f = 0; f < layer.features.length; f++) {
feature = layer.features[f];
// Some features still may have local style object
if (feature.style) {
delete feature.style;
// if (layer.customStyling === true && (!layer.selectedFeatures || layer.selectedFeatures.length == 0)) {
// return;
// }
// Assign Style to all or, if features selected, to individual Layer features
var features = (layer.selectedFeatures && layer.selectedFeatures.length > 0) ? layer.selectedFeatures : layer.features;
layer.eraseFeatures(features);
for (var f = 0; f < features.length; f++) {
feature = features[f];

var changeFeatureStyle = !layer.customStyling || (layer.customStyling && ((layer.selectedFeatures && layer.selectedFeatures.length > 0) || !feature.style) && !(feature.renderIntent && feature.renderIntent != 'default'));
if (changeFeatureStyle) {
// Some features still may have local style object
if (feature.style) {
delete feature.style;
}
feature.style = newStyle.createSymbolizer(feature);
}
feature.style = newStyle.createSymbolizer(feature);

layer.drawFeature(feature);
}

// layerRecord.store.fireEvent("update", layerRecord.store, layerRecord, Ext.data.Record.EDIT)
}
// this.target.stylesStore.each(function(rec) {
// if (!defaultStyle && rec.get("userStyle").isDefault === true) {
// defaultStyle = rec.get("name");
// }
// if (rec.get("name") !== defaultStyle &&
// this.deletedStyles.indexOf(rec.id) === -1) {
// styles.push({"name": rec.get("name")});
// }
// }, this);
// Ext.Ajax.request({
// method: "PUT",
// url: this.baseUrl + "/layers/" +
// this.target.layerRecord.get("name") + ".json",
// jsonData: {
// "layer": {
// "defaultStyle": {
// "name": defaultStyle
// },
// "styles": styles.length > 0 ? {
// "style": styles
// } : {},
// "enabled": true
// }
// },
// success: callback,
// failure: function() {
// this._failed = true;
// callback.call(this);
// },
// scope: this
// });
},

/** private: method[deleteStyles]
Expand Down
Loading

0 comments on commit bf12ae3

Please sign in to comment.