Hello
I have implemented the cluster example exactly in the same way as described on mapbox site (https://www.mapbox.com/mapbox-gl-js/example/cluster/) ,
Since I have upgraded to mapboxgl-js from 0.29.0 to 0.34.0 I have got the following error message when loading my map
"The layer 'cluster-count' does not exist in the map's style and cannot be removed.
this is occuring for all cluster layers.
it is occuring while executing the following part of the code:
// define cluster colors depending on nb of clustered points
var layers = [
[100, '#ff2c97'],
[20, '#ff6fb9'],
[0, '#ffb0d8']
];
for (i = 0; i < layers.length; i++) {
// Remove all of the layers and source associated
// with a previous filter if needed
try {
map.removeLayer("cluster-" + i);
map.removeLayer("clusterGlow-" + i);
map.removeLayer("cluster-count");
} catch (err) {};
};
It looks like as if the error message was not caught with the try/catch.
Have I missed anything?
mapbox-gl-js version: 0.34.0
removeLayer handles errors by emitting an error event, rather than throwing an exception. I've submitted a PR to correct the documentation on this point.
We aim to use an error event for all error handling, though there are still inconsistencies that we want to fix. The reason for using error events rather than exceptions is that some errors may happen asynchronously, and in those cases throwing an exception is not an option. For consistency, we intend not to use exceptions in synchronous cases either.
To safely remove a layer that may or may not exist, guard the call to removeLayer with getLayer:
if (map.getLayer("cluster-count")) {
map.removeLayer("cluster-count");
}
Most helpful comment
removeLayerhandles errors by emitting anerrorevent, rather than throwing an exception. I've submitted a PR to correct the documentation on this point.We aim to use an
errorevent for all error handling, though there are still inconsistencies that we want to fix. The reason for usingerrorevents rather than exceptions is that some errors may happen asynchronously, and in those cases throwing an exception is not an option. For consistency, we intend not to use exceptions in synchronous cases either.To safely remove a layer that may or may not exist, guard the call to
removeLayerwithgetLayer: