I have several 3D models (animated arrows) that I dynamically add to the map as a user clicks on buttons. Some buttons may have 3D models, while others do not.
Whenever I click on a button that does not have any 3D model, I remove all previously added models:
function clearMapAnimations() {
console.log("CLEARING MAP ANIMATIONS");
// Loop through all layers with arrows and hide them
toggleableLayerIds.forEach(layer => {
const layer_name = "layer_" + layer;
console.log ("Layer visibility is none: " + layer_name);
map.setLayoutProperty(layer_name, 'visibility', 'none');
});
}
The toggleableLayerIds is an array that holds all of the ids of the layers previously added.
If I comment out the map.setLayoutProperty(layer_name, 'visibility', 'none'); the expected behaviour exists.... the arrows/layers remain on the map and the map does not turn white. So, I have narrowed down the problem to this line.
I should also note that when I add a custom layer to the map I make its 'visibility' property 'visible'.
const arrow_layer = addArrow(lyr_id, map, lng_lat, rot, arrow_length, arrow_type);
map.addLayer(arrow_layer, 'waterway-label');
map.setLayoutProperty(lyr_id, 'visibility', 'visible');
The addArrow function does a lot of heavy lifting in terms of assigning the origin, rotation, length of the model, and also deals with the animation.
There is an onRemove: function (map, gl) { } that is not currently implemented. Do I need to do something there if I'm hiding the layer and not removing it?
I appreciate any help you can give me! Thanks