Skip to content

issue with overrideStyleFunction on MVT layer (same style applied to all features) #380

@niconoe

Description

@niconoe

Hello,

To style individual features (based on the subject attribute of the feature), I wrote an overrideStyleFunction such as:

const overrideStyleFunctionSimple = (feature, currentStyle) => {
  const subject = feature.get("subject");
  
  let markerColor: string;

  if (subject === "MAN") {
    markerColor = "rgb(255, 0, 0)";
  } else {
    markerColor = "rgb(0, 255, 0)";
  }

  currentStyle.getImage().getFill().setColor(markerColor)

  return currentStyle;
}

Which is configured like this:

<ol-vector-tile-layer ref="simpleLayer" :minZoom="switchAtZoomLevel">
      <ol-source-vector-tile :format="mvtFormat"/>
      <ol-style :overrideStyleFunction="overrideStyleFunctionSimple">
        <ol-style-circle :radius="7"/>
      </ol-style>
 </ol-vector-tile-layer>

If I add console.log() statements, I can clearly see that overrideStyleFunctionSimple() is called multiple times and runs both branches of the if, depending on the value of subject. However, all drawn features have the same color (red or green). Sometimes everything is green, sometimes everything is red (I guess it applies the color from the last execution of the function to ALL features).

Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions