Closed simtrax closed 2 years ago
Hi @simtrax Labels and tooltips are constantly added and removed in each one of the 22 examples, so this is not a bug in threebox. As you don't provide a code sandbox to test your code, my first feeling is that you are doing wrong assumptions or decisions in your code that are producing that error. To show labels in a fill extrusion layer, you don't need to build the labels manually, as you can see it in this example
First of all, you're assuming every click on the map will return features, that's mostly wrong, it could return an empty array. Second you create and remove the 3D layer every time, which is really a bad practice, extremely inefficient, and can produce other colateral errors. Other things I don't understand in your code is that you send the feature to addlabel
method but don't use it.
You're also using Mapbox v2.8.2, which this plugin hasn't been tested to (it could work or not), but hasn't been tested.
Thank you for the response @jscastro76
First, sorry for not sending a sandbox. This is just a very quick mock-up of what I wanted to achieve. I do not want to remove the whole layer, I understand that is bad practice. I have tried with different versions of Mabbox GL JS, does not seem to matter. I saw that I hade included Three.js, that was my mistake, I was tired after several hours of trying to understand why I could not remove tooltips from the map without it breaking things.
I have looked through many of the examples in the repository, especially 08-3dbuildings.html
, but as far as I have seen all the tooltips are shown when hovering over a feature.
I want to display a tooltip when the user clicks on a feature. I then want to let the user click on another feature and have two tooltips be displayed at the same time.
Somewhere else there's a "Clear selection" button, that should remove the tooltips.
After that the user should be able to place new tooltips if they want to.
And I want to be in control of what is displayed in the tooltip. It might be different for each feature the user clicks on.
I'm not asking you to send code how to do this, I'm just interested in knowing if it is possible. And if possible, is there a example that states how to remove manually added tooltips anywhere? Without it breaking how features added to the map behaves.
I just want tooltips shown on top of an extruded features, that's the only thing I need. But I want to control it manually. This repo might be overkill just to do that, but this is the only way I have found to make it work.
It might not be of any help but here's a sandbox. Click me
I added my token to your code sandbox, and I'm receiving other errors every time I click on the red building.
@jscastro76 Let's make it a bit simpler, is there a way to manually add and remove tooltips that are placed at an altitude? If there is, what is the correct way to do it? Thanks!
The best way to do it for a Fill extrusion feature is to basically call the method map.addTooltip that receives a feature and has been created specifically for fill-extrusions.
But as it seems you want a specific behavior, you can create a custom tooltip programming your own method based on its code, that creates a tb.tooltip
. You can avoid the feature and using just coordinates array including altitude [long, lat, altitude]
. Just be clear then you will need to manage the visibility and removal of that object separately.
You have everything in the documentation of tb.addTolltip
tb.tooltip
Describe the bug I'm trying to dynamically add and remove tooltips when the user interacts with features on the map.
To Reproduce Steps to reproduce the behavior: View the HTML file with python http server or something similar.
If clicking on the base of the 3D feature it will be registered
Expected behavior After the layer has been removed the 3D feature should still be found by the map when querying features. But it seems that the 3D information is lost.
For me it was easiest to create a HTML file, sorry if it's inconvenient.
Console Results