|
| 1 | +goog.provide('os.command.FeatureStrokeColor'); |
| 2 | + |
| 3 | +goog.require('os.command.AbstractFeatureStyle'); |
| 4 | +goog.require('os.events.PropertyChangeEvent'); |
| 5 | +goog.require('os.metrics'); |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +/** |
| 10 | + * Changes the stroke color of a feature |
| 11 | + * @extends {os.command.AbstractFeatureStyle} |
| 12 | + * @param {string} layerId |
| 13 | + * @param {string} featureId |
| 14 | + * @param {Array<number>|string} color |
| 15 | + * @param {(Array<number>|string)=} opt_oldColor |
| 16 | + * @constructor |
| 17 | + */ |
| 18 | +os.command.FeatureStrokeColor = function(layerId, featureId, color, opt_oldColor) { |
| 19 | + os.command.FeatureStrokeColor.base(this, 'constructor', layerId, featureId, color, opt_oldColor); |
| 20 | + this.title = 'Change Feature Stroke Color'; |
| 21 | + this.metricKey = os.metrics.Layer.FEATURE_STROKE_COLOR; |
| 22 | + |
| 23 | + if (!color) { |
| 24 | + var feature = this.getFeature(); |
| 25 | + var config = /** @type {Object|undefined} */ (feature.get(os.style.StyleType.FEATURE)); |
| 26 | + |
| 27 | + if (config) { |
| 28 | + if (goog.isArray(config)) { |
| 29 | + config = config[0]; |
| 30 | + } |
| 31 | + var configColor = /** @type {Array<number>|string|undefined} */ (os.style.getConfigColor(config)); |
| 32 | + |
| 33 | + if (configColor) { |
| 34 | + color = os.color.toHexString(color); |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + // Make sure the value is a string |
| 40 | + this.value = os.style.toRgbaString(color); |
| 41 | +}; |
| 42 | +goog.inherits(os.command.FeatureStrokeColor, os.command.AbstractFeatureStyle); |
| 43 | + |
| 44 | + |
| 45 | +/** |
| 46 | + * @type {string} |
| 47 | + * @const |
| 48 | + */ |
| 49 | +os.command.FeatureStrokeColor.DEFAULT_COLOR = 'rgba(255,255,255,1)'; |
| 50 | + |
| 51 | + |
| 52 | +/** |
| 53 | + * @inheritDoc |
| 54 | + */ |
| 55 | +os.command.FeatureStrokeColor.prototype.getOldValue = function() { |
| 56 | + var feature = /** @type {ol.Feature} */ (this.getFeature()); |
| 57 | + var config = /** @type {Array<Object>|Object|undefined} */ (this.getFeatureConfigs(feature)); |
| 58 | + if (goog.isArray(config)) { |
| 59 | + config = config[0]; |
| 60 | + } |
| 61 | + |
| 62 | + if (config) { |
| 63 | + return os.style.getConfigColor(config, false, os.style.StyleField.STROKE); |
| 64 | + } else { |
| 65 | + return os.command.FeatureStrokeColor.DEFAULT_COLOR; |
| 66 | + } |
| 67 | +}; |
| 68 | + |
| 69 | + |
| 70 | +/** |
| 71 | + * Gets the old label color |
| 72 | + * @return {Array<number>|string|undefined} |
| 73 | + */ |
| 74 | +os.command.FeatureStrokeColor.prototype.getLabelValue = function() { |
| 75 | + var feature = /** @type {ol.Feature} */ (this.getFeature()); |
| 76 | + var labelColor = /** @type {Array<number>|string|undefined} */ (feature.get(os.style.StyleField.LABEL_COLOR)); |
| 77 | + return labelColor ? labelColor : os.style.DEFAULT_LAYER_COLOR; |
| 78 | +}; |
| 79 | + |
| 80 | + |
| 81 | +/** |
| 82 | + * @inheritDoc |
| 83 | + */ |
| 84 | +os.command.FeatureStrokeColor.prototype.applyValue = function(configs, value) { |
| 85 | + var color = os.style.toRgbaString(/** @type {string} */ (value)); |
| 86 | + for (var i = 0; i < configs.length; i++) { |
| 87 | + os.style.setConfigColor(configs[i], color, [os.style.StyleField.STROKE, os.style.StyleField.IMAGE]); |
| 88 | + } |
| 89 | + |
| 90 | + if (this.oldValue == this.getLabelValue()) { |
| 91 | + this.applyLabelValue(configs, value); |
| 92 | + } |
| 93 | + |
| 94 | + os.command.FeatureStrokeColor.base(this, 'applyValue', configs, value); |
| 95 | +}; |
| 96 | + |
| 97 | + |
| 98 | +/** |
| 99 | + * Set the label color |
| 100 | + * @param {Object} configs The style config |
| 101 | + * @param {string} value The value to apply |
| 102 | + */ |
| 103 | +os.command.FeatureStrokeColor.prototype.applyLabelValue = function(configs, value) { |
| 104 | + var feature = /** @type {ol.Feature} */ (this.getFeature()); |
| 105 | + feature.set(os.style.StyleField.LABEL_COLOR, value); |
| 106 | + |
| 107 | + for (var i = 0; i < configs.length; i++) { |
| 108 | + configs[i][os.style.StyleField.LABEL_COLOR] = value; |
| 109 | + } |
| 110 | +}; |
| 111 | + |
| 112 | + |
| 113 | +/** |
| 114 | + * @inheritDoc |
| 115 | + */ |
| 116 | +os.command.FeatureStrokeColor.prototype.finish = function(configs) { |
| 117 | + // dispatch the color change event on the source for the histogram |
| 118 | + var feature = this.getFeature(); |
| 119 | + |
| 120 | + feature.dispatchEvent(new os.events.PropertyChangeEvent('colors')); |
| 121 | + |
| 122 | + os.command.FeatureStrokeColor.base(this, 'finish', configs); |
| 123 | +}; |
0 commit comments