Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
niconoe opened this issue Sep 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@niconoe
Copy link

niconoe commented Sep 5, 2024

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!

@niconoe niconoe added the bug Something isn't working label Sep 5, 2024
@bitblitz4use
Copy link

bitblitz4use commented Oct 7, 2024

Affected version: 11.2.1

Not sure if this is the same root cause but I am also having problems with setting the color of my features.
I try to pass it to the Icon class with no effect on Icon file:

const getMarkerStyle = (color) => {
return new Style({
image: new Icon({
anchor: [0.5, 1],
src: "/src/assets/map-marker.svg",
scale: 0.2,
color: color,
}),
});
};

If I log the features I also see that the color is correctly passed to the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants