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

Is there a method to delete layer style attributes #2683

Closed
mdxiaohu opened this issue Jun 14, 2023 · 11 comments · Fixed by #2837
Closed

Is there a method to delete layer style attributes #2683

mdxiaohu opened this issue Jun 14, 2023 · 11 comments · Fixed by #2837
Labels
enhancement New feature or request good first issue Good for newcomers PR is more than welcomed Extra attention is needed

Comments

@mdxiaohu
Copy link

mdxiaohu commented Jun 14, 2023

maplibre-gl-js version: 2.4.0

browser:

Steps to Trigger Behavior

I briefly describe the needs .
According to some attributes of the api map, they have priority among each other .
For example: line-color and line-pattern .
line-pattern has higher priority than line-color .
When I create a layer and set the line-pattern property .

		map.addLayer({
			type: 'line',
			source: 'line',
			id: 'line',
			paint: {
				'line-color': 'red',
				'line-width': 14,
				// 'line-gradient' must be specified using an expression
				// with the special 'line-progress' property
				'line-gradient': [
					'interpolate',
					['linear'],
					['line-progress'],
					0,
					'blue',
					0.1,
					'royalblue',
					0.3,
					'cyan',
					0.5,
					'lime',
					0.7,
					'yellow',
					1,
					'red'
				]
			},
			layout: {
				'line-cap': 'round',
				'line-join': 'round'
			}
		});

Now I want to use the line-color property .
How should I remove the effect of the line-gradient attribute .
I tried the following .

map.setPaintProperty('line', 'line-gradient', undefined)
map.setPaintProperty('line', 'line-color', 'red')

In this way, the console will report an error .
I checked the api and couldn't find the corresponding method .
Is it possible to provide a method to delete an attribute .
For example :
map.removePaintProperty('line', 'line-gradient')

Link to Demonstration

https:maplibre.org/maplibre-gl-js-docs/example/line-gradient/

Expected Behavior

Use the following method to delete an attribute in a layer

map.removePaintProperty(layerId, 'line-gradient')

Actual Behavior

@mdxiaohu mdxiaohu changed the title Why can't the removePaintProperty method be opened to the map object Is there a method to delete layer style attributes Jun 14, 2023
@mdxiaohu
Copy link
Author

@HarelM Can you help me take a look at this problem .

I don't know if I have described it clearly .

I am using translation software to communicate .

@HarelM
Copy link
Collaborator

HarelM commented Jun 15, 2023

You can add and remove a layer in theory to solve this.
Can you create a jsbin with setting to undefined to see where it fails?
Setting to undefine seems like a reasonable solution to me...

@HarelM HarelM added the need more info Further information is requested label Jun 15, 2023
@mdxiaohu
Copy link
Author

mdxiaohu commented Jun 16, 2023

@HarelM
Adding or deleting layers can solve this problem, but it is not a good solution .

I created an example with the following address .

Url: https://jsfiddle.net/mdxiaohu/7kvnsz4L/4/

map.setPaintProperty('line', 'line-gradient', undefined)

This line of code failed to perform the expected operation .

There are many attributes in map styles that have priority .

I don't know how to change the priority attribute through encoding after setting it to a higher priority attribute .

If there were a corresponding method, it would be great .

for example

map.removePaintProperty(layerId, 'line-gradient')

Of course, without changing the existing API .

map.setPaintProperty('line', 'line-gradient', undefined)

If it can perform the operation perfectly, it is also excellent .

@mdxiaohu
Copy link
Author

@HarelM
Are there any other ways to handle it .
I am not particularly familiar with this map .

@HarelM
Copy link
Collaborator

HarelM commented Jun 19, 2023

I don't think so, only adding and removing the layer as I mentioned.
This probably requires implementing...

@HarelM HarelM added enhancement New feature or request PR is more than welcomed Extra attention is needed and removed need more info Further information is requested labels Jun 19, 2023
@mdxiaohu
Copy link
Author

mdxiaohu commented Jun 19, 2023

Thank you for your reply .
I noticed that this issue has been added a new label .
I am very looking forward to improving this feature .
If we could use the API alone to handle it, it would be great .
map.removePaintProperty('line', 'line-gradient')
Of course, maintaining the original API is also good .
map.setPaintProperty('line', 'line-gradient', undefined)
Also, I have a little idea .
If there were still an API for resetting layer styles, it would be great .
for example :

// Reset Layer Style
map.resetStyleLayer('line')
// Reset Layer Part Attribute Style
map.resetStyleLayer('line', 'line-color')
// Suddenly, I thought of a way to achieve this, which can be directly achieved by adding or removing layers .

Of course, this is just a small idea from me, which may not meet the design requirements very well .
Anyway, I hope to improve this feature as soon as possible. I'm looking forward to it.
Thank you .

@HarelM
Copy link
Collaborator

HarelM commented Jun 27, 2023

I would consider allowing setting undefined and "fix" the code to handle that.
It doesn't need an API change which I think has a smaller impact.
If this works well and we think a public API is needed, we can simply call the set method with undefined.
If you would like to open a PR with the support of undefined I'll be happy to review it.

@mdxiaohu
Copy link
Author

I would be happy to participate .
But my current TS ability is still relatively weak .
We have only recently started transitioning from JS to TS .
If you can handle this .
Will achieve better results .
I will strive to improve my own abilities and strive to participate as soon as possible .
At present, I can only provide some improvement ideas .

@HarelM
Copy link
Collaborator

HarelM commented Jun 27, 2023

typescript is not that different than javascript, try fixing this issue, if you get stuck on something I'd love to help.

@tangerine-orange
Copy link
Contributor

I'd like to try my hand at this one!

@HarelM HarelM added the good first issue Good for newcomers label Jul 9, 2023
@HarelM
Copy link
Collaborator

HarelM commented Jul 9, 2023

Go ahead 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers PR is more than welcomed Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants