Mapbox: is it possible to update layer hierarchy? - mapbox

I have a Mapbox with my own layers, says labels of towns and landmarks...
say I want to highlight one specific landmark and I want to move its z-index higher because otherwise, it would overlap with some other elements...
Can I use map.setLayoutProperty or is there anything else that I can do?

If I got your question correctly, you're looking for a way to change z-index of some layer above another layer. (not some feature above another feature). Here it the way:
https://www.mapbox.com/mapbox-gl-js/api/#map#movelayer
map.moveLayer(yourLandmarkLayerId, someAnotheLayerId);
If you would like just to move landmark layer to top of layer hierarchy:
map.moveLayer(yourLandmarkLayerId);
P.S. For moving layer, you should know it's ID:
var layers = map.getStyle().layers;
var layerId = layers[i].id;

For someone looking to do it on android, the simplest way to do it is to remove the layer and add it again above or below another layer. I do not find a better way:
/**
* Remove the target layer and add it again above the specific layer
*/
fun moveLayerAvobe(layer: Layer, breakpointLayerID: String, style: Style) {
// Remove Layer
style.removeLayer(layer)
// Add it again
style.addLayerAbove(layer, breakpointLayerID)
}

Related

Unity Blank Layer Mask

So I'm new to unity and I was wondering how can I remove the layer mask on a game object? Every time I create a game object, it has 'Default' layer mask like this picture :
http://www.upsara.com/images/8ha1_untitled1.png
I imported an AI package and I noticed that all npc characters in this package don't have a layer mask like this picture :
http://www.upsara.com/images/uv73_untitled2.png
And I dont know how is that possible and I want add a few new characters but when I import this new characters and add them to scene thier layer is 'Default' and AI system wont intract whith them.
This is just a layer with no name and you can easily re-create that.
To understand what's happening, go to Add layers:
See the image below:
Notice how layer 3 doesn't have a name? That's what that asset is doing. It is setting is layer to a layer that not named. For example, layer 3, 6, 7 and 10 are not named in the image above.
You can do that from code. Let's set it to one of the empty layers (6):
this.gameObject.layer = 6;
This is what happens:
Now, you can use one of the AssetPostprocessor functions to detect when anything is imported then automatically change the layer to an empty layer.

How to find all layers in Mapboxgl ? Ultimately I want to show custom layer only on water and not on land

I created a custom circle layer. I want to show this layer only on water and not on land. I managed to do the opposite (ie: showing the layer on land and not on water) using below command. Refer this image for better understanding
map.moveLayer('polygon','water');
Now I need to know the land layer which is used by mapboxgl so that I can call function map.moveLayer('polygon','land'); to achieve what i want.
I need help to find the different layers present in the mapboxgl-streets map. But unfortunately, Mapboxgl doesn't have map.eachLayer function.
You can use the Map#getStyle method to get a serialized representation of the entire style including the layers.
map.getStyle().layers
It depends on the map style you're using. In general, you either have to look at its source or load it in Mapbox Studio to identify the correct layer name. Also keep an eye on https://github.com/mapbox/mapbox-gl-js/issues/4173.
Just to add to Lucas' answer (which is still correct), map.getStyle().layers provides all layers in the style, including ones you have explicitly added (via map.addLayer()), and those that are included in the style (which could be a lot). Careful how you filter through these. For my case, I created arrays to hold the layers I created myself, to make future iteration simpler.

How is the Layer Order is decided in leaflet map?

When I use the following code to go through all the layers in a leaflet map,
map.eachLayer(function (layer) {
console.log(layer);
});
I just wants what rule is used to create this order. Is it because of the ZIndex of the layer? Or is it because the layer is added in different time? If the layer is added early, it will be in the bottom.
Thanks,
Good question, it seems the LeafletJS docs don't say anything about the ordering of the layers via eachLayer, so...
Looking at the code on github, L.Map.eachLayer loops through L.Map._layers which is an object (not an array). So technically the layers could come back in any order...
That said, the individual layers are added to the _layers object in the order they are added to the map. So in all likelihood, eachLayer will be iterating over the layers in that same order (whatever order they were added to the map).

User control of order of overlays in a Leaflet map

Is there a Leaflet plugin or example for letting the user control the display order of overlay layers in a map?
Turning layers on and off is working fine, but I'd like the user to be able to drag layer names within the layer control to set the Z order.
For Path class (Polygons, Polylines, etc.) there are methods 'bringToFront()' and 'bringToBack()'. You can't exactly set precise position in draw order, but iterating over layer list and calling 'bringToFront()' could be less time consuming, then re-drawing every layer (especialy if they are bigger).

Leaflet layer ordering

I'm having problems about the layer ordering in leaflet.
I've followed this page
http://leafletjs.com/examples/layers-control.html
exact question would be... how can I reorder the layers (foreground background etc).
Lets say, one of my "base layers" is made of semi transparent tiles, and I want to see the "overlay layers" through my base layer (it should be at the foreground)
Depending on the page example, here is a snippet to explain more about the issue:
var baseMaps = {
"Minimal": minimal,
"Night View": midnight,
"My Custom Layer": customlayer
};
var overlayMaps = {
"Motorways": motorways,
"Cities": cities
};
In other words, I would like to know how to set "My Custom Layer" as the layer that will be at the foreground (above overlayMaps).
I've tried setting zindex values of layers, didn't help.
Thanks.
The layers control has two sets of layers, the set of base layers and the set of overlay layers. The overlay layers will be drawn on top of the base layers.
So generally, you'll want to add your transparent layer to the overlay layers.
The autoZIndex option, which is by default On, specifies that the control must assign z indices to each of its layers in the order in which they are added, and that means they'll be drawn in that order.
See http://leafletjs.com/reference.html#control-layers
Sets the zIndex of the tile layer.
setZIndex( <Number> zIndex )
myLayer1.setZIndex(4);
myLayer2.setZIndex(5);
Layer 2 over Layer 1