douzhi3779 2019-08-11 04:28
浏览 119

从数组添加动态叠加层

I am trying to add new layers to the map using the leaflet. First I create the layers by a form then I put the elements related to their relationship. The problem is that to add a new layer to the overlayers object is using static code, and I wanted to use all the layers that I am creating and are downloaded from the database. Does anyone have an idea?

var tipo1 = L.layerGroup();
var tipo2 = L.layerGroup();

var overlayers = {
  "Tipo 1": tipo1,
  "Tipo 2": tipo2
};  

This example works. This is how it should be used. But in my case, instead of using tipo1 and tipo2 ... I would have one or more types coming from a database, and wanted to add to overlayers.

  • 写回答

2条回答 默认 最新

  • dongzhashou0116 2019-08-11 09:44
    关注

    You don't post much code, but assuming you're using a Layers control, you can add layers dynamically - eg

    var myLayersControl = L.control.layers(null, null).addTo(map);
    var myNewLayer = L.layerGroup();
    myLayersControl.addOverlay(myNewLayer, "Description");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现