kekscom / osmbuildings

OSM Buildings Classic 2.5D
http://osmbuildings.org
BSD 2-Clause "Simplified" License
505 stars 140 forks source link

How to show and hide osmbuildings objects #108

Open rollinstar opened 6 years ago

rollinstar commented 6 years ago

Hi, Thank you for providing a wonderful project like this! I'm developing a map using OSMBuildings, leaflet, and geojson. But, I faced a problem. My client want that OSMBuildings be toggled (on and off buildings) when they would like to see base maps. Firstly, I used a function(onRemove()) for clearing a OSMBuilding objects and removed OSMBuildings objects. Then, when I called a function(set()) for loading objects again, it did not operate. So, I declared a new OSMBuildings object again, and I could render the OSMBuildings objects. However, z-index of the OSMBuilding's instance changed to last z-index of leaflet map. How can I toggle the OSMBuilding's objects which is already rendered without changing z-index? Can you help me to solve this problem?

kekscom commented 6 years ago

Could you try to use Leaflets layer control?

var layers = {
    "buildings": osmb
};
L.control.layers(layers).addTo(map);

It should also allow to remove layers. See: http://leafletjs.com/examples/layers-control/

rollinstar commented 6 years ago

Thank you for your advice! But this way still cannot solve problem that z-index of each layer is changed when layers are toggled. My client want that particular layer is shown upper than OSMBuildings objects. However, I think that this problem should be solved by leaflet, so I will try to find a way using leaflet library myself. Thank you!