drcx71276 2016-02-12 16:13
浏览 53
已采纳

传单控制Joomla问题

I've created a Joomla Component and i have a Leaflet map in the component window. I've used Leaflet with Omnivore plugin to add GPX and KML to my map and I used the Leaflet controls to allow to add and remove the layers.

I've tested the controls in a clean joomla development installation and the controls are OK, as seen in the first image enter image description here

When I use the component in my Joomla site che controls are not OK, there are some dirty entry as seen in the second figures enter image description here

I think this is because of the templates and some script that interfere with Leaflet but I can't fix it. The joomla versions are the same, the template no, the joomla site use gantry. This is the function I used to populate the map:

function showRouteTracks(tracce, baseURI, popup=false, enableLayers=true, enableElevation=false){
var layerControl = new Array();
for (var i = 0; i < tracce.length; i++) {

    var customLayer = L.geoJson(null, {
        style: getStyle(i)
    });

    if(tracce[i][3]=='GPX'){
        var layer = omnivore.gpx(baseURI+tracce[i][2], null, customLayer).on('ready', function() {
                elevation(enableElevation,layer);
            });
        if(popup){
            link='<a href="'+tracce[i][4]+'">'+tracce[i][5]+'</a>'
            layer.bindPopup(tracce[i][0]+"&#10141;"+tracce[i][1]+"<br/>"+link);
        }
        lvrtMap.addLayer(layer);
        layerControl[tracce[i][0]+"&#10141;"+tracce[i][1]]=layer;
    }
    if(tracce[i][3]=='KML'){
        var layer = omnivore.kml(baseURI+tracce[i][2], null, customLayer).on('ready', function() {
            elevation(enableElevation,layer);
        });
        if(popup){
            link='<a href="'+tracce[i][4]+'">'+tracce[i][5]+'</a>'
            layer.bindPopup(tracce[i][0]+"&#10141;"+tracce[i][1]+"<br/>"+link);
        }
        lvrtMap.addLayer(layer);
        layerControl[tracce[i][0]+"&#10141;"+tracce[i][1]]=layer;
    }
}

if(!enableLayers)
    layerControl=null;
if(enableElevation)
    L.control.layers(lvrtMapLayers,layerControl,{'position':'bottomright'}).addTo(lvrtMap);
else
    L.control.layers(lvrtMapLayers,layerControl).addTo(lvrtMap);

}

  • 写回答

1条回答 默认 最新

  • dsakktdog498483070 2016-02-12 17:00
    关注

    Currently you're creating an array to store the title/layer items:

    var layerControl = new Array();
    

    But L.Control.Layers takes object literals as baselayer/overlay parameters:

    var baseLayers = {
        "Mapbox": mapbox,
        "OpenStreetMap": osm
    };
    
    var overlays = {
        "Marker": marker,
        "Roads": roadsLayer
    };
    
    L.control.layers(baseLayers, overlays).addTo(map);
    

    So you should use an object literal:

    var layerControl = {};
    

    You can add items the same way as you did before:

    layerControl['MyTitle'] = myLayerInstance;
    

    I'll bet you'll have no problem then. What happening now is that your trying to assign string keys to items in an array, which isn't supported (even supposed to work but that aside). A javascript array can only have numeric keys and nothing else.

    That it works for you with a clean install and not in your production setup is that probably in production you have a javascript library/framework loaded which adds methods/properties to javascript's native array prototype and they are enumerable. Thus when the layercontrol instance iterates the array it also finds these extra methods/properties and tries to add them to the layercontrol.

    Just use a object literal: {} not an Array, you'll be fine, good luck.

    EDIT: Got curious and did some digging. As it turns out this is caused by Mootools and then i ran into this question: Looping through empty javascript array returns array object functions which gives some explanation and some other solutions but it's best if you just use a object literal because at the moment you're kind of abusing Array.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里