mapbox / mapbox-gl-draw

Draw tools for mapbox-gl-js
https://www.mapbox.com/mapbox-gl-js/example/mapbox-gl-draw/
ISC License
946 stars 592 forks source link

Expressions not working the same way for different style types #1063

Open vinAirWorks opened 3 years ago

vinAirWorks commented 3 years ago

mapbox-gl-js version: 2.3.1 mapbox-gl-draw version: 1.3.0

I am trying to style features based on its properties. All the features I want to render have a property called 'my_property' whose value is either null or an integer. I have an expression like this which I want to use in the paint properties - ['case', ['==', ['get', 'user_my_property'], null], '#fff', '#000']

Example - I have 3 features- 1 MultiLineString feature(Feature 1) for which my_property is not null and 2 lineString features(Feature 2, Feature 3) with my_property null. These are the styles I'm applying -

{
    id: 'gl-draw-line-inactive',
    type: 'line',
    filter: ['all',
      ['==', 'active', 'false'],
      ['==', '$type', 'LineString'],
      ['!=', 'mode', 'static'],
    ],
    layout: {
      'line-cap': 'round',
      'line-join': 'round',
    },
    paint: {
      'line-color': ['case', ['==', ['get', 'user_my_property'], null], '#fff', '#000'],
      'line-width': 2,
    },
  },
  {
    id: 'gl-draw-line-active',
    type: 'line',
    filter: ['all',
      ['==', '$type', 'LineString'],
      ['==', 'active', 'true'],
    ],
    layout: {
      'line-cap': 'round',
      'line-join': 'round',
    },
    paint: {
      'line-color': ['case', ['==', ['get', 'user_my_property'], null], '#fff', '#000'],
      'line-width': 2,
    },
  },
  {
    id: 'gl-draw-polygon-and-line-vertex-stroke-inactive',
    type: 'circle',
    filter: ['all',
      ['==', 'meta', 'vertex'],
      ['==', '$type', 'Point'],
      ['!=', 'mode', 'static'],
    ],
    paint: {
      'circle-radius': 12,
      'circle-color': ['case', ['==', ['get', 'user_my_property'], null], '#fff', '#000'],
    },
  },
  {
    id: 'gl-draw-polygon-and-line-vertex-inactive',
    type: 'circle',
    filter: ['all',
      ['==', 'meta', 'vertex'],
      ['==', '$type', 'Point'],
      ['!=', 'mode', 'static'],
    ],
    paint: {
      'circle-radius': ['case', ['==', ['get', 'user_my_property'], null], 5, 10],
      'circle-color': ['case', ['==', ['get', 'user_my_property'], null], '#fff', '#000'],
    },
  },

Expected Behavior

When the features are not selected-

When the features are selected (simple_select or direct_select) and have vertices -

Actual Behavior

When the features are not selected-

When the features are selected (simple_select or direct_select) and have vertices -

(this is when features are not selected)

features

(this is when Feature 1 is in simple_select, the vertices are expected to be black and have radius 10)

Screen Shot 2021-07-13 at 5 33 42 PM

(this is when Feature 2 is in simple_select, the vertices are styled as expected)

Screen Shot 2021-07-13 at 5 34 16 PM

I think the problem is that the expression works for styles of type 'line' and 'fill' but not for type 'circle'. Am I missing something?

oodavid commented 2 years ago

The issue is that the vertex and midpoint elements don't act like the others.

I noticed this in #1077 - where the mode is also unavailable. I've created a PR that makes mode available. It seems that the user_* properties aren't available either.

Pingviinituutti commented 2 years ago

One year later, another fix to get the user_* properties to the supplementary points could be something like this too.

hosnar commented 11 months ago

Is there a workaround for this so i could dynamically style circles?

cfecherolle commented 4 months ago

Same problem here, I want to dynamically style circles but it does not seem to work 😞

MichalBurzynski89 commented 1 day ago

image

Same here, for some reason I cannot dynamically style circles in the first layer, but it works for other two layers :/