Skip to content

Commit

Permalink
fix(places): ignore opacity when comparing color/label color
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Schmidt committed Aug 19, 2019
1 parent 7e32198 commit d2bce3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/os/command/feature/featurecolorcmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ os.command.FeatureColor.prototype.getOldValue = function() {
/**
* Gets the old label color
*
* @return {Array<number>|string|undefined}
* @return {Array<number>|string}
*/
os.command.FeatureColor.prototype.getLabelValue = function() {
var feature = /** @type {ol.Feature} */ (this.getFeature());
Expand All @@ -133,6 +133,10 @@ os.command.FeatureColor.prototype.getLabelValue = function() {
os.command.FeatureColor.prototype.applyValue = function(configs, value) {
var color = os.style.toRgbaString(/** @type {string} */ (value));

// ignore opacity when comparing the label color to the current color
var labelColor = os.color.toHexString(this.getLabelValue());
var currentColor = os.color.toHexString(this.state === os.command.State.EXECUTING ? this.oldValue : this.value);

switch (this.changeMode) {
case os.command.style.ColorChangeType.FILL:
for (var i = 0; i < configs.length; i++) {
Expand All @@ -151,8 +155,7 @@ os.command.FeatureColor.prototype.applyValue = function(configs, value) {
}

// if the label color matches the style color, change it as well
if ((this.state === os.command.State.EXECUTING && this.oldValue == this.getLabelValue()) ||
(this.state === os.command.State.REVERTING && this.value == this.getLabelValue())) {
if (labelColor == currentColor) {
this.applyLabelValue(configs, color);
}
break;
Expand All @@ -163,8 +166,7 @@ os.command.FeatureColor.prototype.applyValue = function(configs, value) {
}

// if the label color matches the style color, change it as well
if ((this.state === os.command.State.EXECUTING && this.oldValue == this.getLabelValue()) ||
(this.state === os.command.State.REVERTING && this.value == this.getLabelValue())) {
if (labelColor == currentColor) {
this.applyLabelValue(configs, color);
}
break;
Expand Down
4 changes: 3 additions & 1 deletion src/os/command/feature/featureopacitycmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ os.command.FeatureOpacity.prototype.applyValue = function(configs, value) {
os.style.getConfigColor(configs[i], true);

if (color) {
var fillColor = os.style.getConfigColor(configs[i], true, os.style.StyleField.FILL);

color[3] = value;
colorValue = os.style.toRgbaString(color);
os.style.setConfigColor(configs[i], colorValue);

var fillColor = os.style.getConfigColor(configs[i], true, os.style.StyleField.FILL);
// preserve the original fill color when changing the stroke
if (fillColor) {
os.style.setFillColor(configs[i], fillColor);
}
Expand Down

0 comments on commit d2bce3f

Please sign in to comment.