this._getLayer是未定义的传单组图层

时间:2018-05-08 10:05:20

标签: javascript plugins leaflet

我想在我的传单地图中集成此插件https://github.com/davicustodio/Leaflet.StyledLayerControl。 我从json创建标记:

jQuery().ready(function (){ 
$.getJSON(
    'recinto_new/json/json_track.php?days=' + days,
    function(data){
        var latlngs = Array();
        var coordinate = Array();
        var coordinate1 = Array();
        var cow = new L.LayerGroup();           
        for ( var i=0; i < data.length; ++i )
        {               
            if (i==0){
                var myIconStart = L.icon({
                iconUrl: 'recinto_new/maps/images/start-cow.png',
                iconRetinaUrl: 'recinto_new/maps/images/start-cow.png',
                iconSize: [69, 70],
                iconAnchor: [9, 21],
                popupAnchor: [0, -14]
                });
                markerArray[i] = L.marker( [data[i].latitude, data[i].longitude], {icon: myIconStart, title: data[i].title } )
                .bindPopup( '<div>' + 'Alla data: ' + data[i].date + '<br/>'
                    + data[i].title + ' si trova'
                    + '<b>Latitudine: </b> ' + data[i].latitude + ' - ' + '<b>Longitudine:</b> ' + data[i].longitude + '</br>'
                    + '<b>Nome: </b>' + data[i].title
                    + '</div>',
                    {direction: 'left'} )
                .addTo( map );

            } else if(i == data.length-1){
                var myIconEnd = L.icon({
                iconUrl: 'recinto_new/maps/images/end-cow.png',
                iconRetinaUrl: 'recinto_new/maps/images/end-cow.png',
                iconSize: [69, 70],
                iconAnchor: [9, 21],
                popupAnchor: [0, -14]
                });
                markerArray[i] = L.marker( [data[i].latitude, data[i].longitude], {icon: myIconEnd, title: data[i].title } )
                .bindPopup( '<div>' + 'Il bovino <b>' + data[i].title + '</b> si trova qui: ' + '<br/>'
                    + '<b>Latitudine: </b> ' + data[i].latitude + ' - ' + '<b>Longitudine:</b> ' + data[i].longitude + '</br>'
                    + '<b>Ultima rilevazione: </b>' + data[i].date
                    + '</div>',
                    {direction: 'left'} )
                .addTo( map );
                markerArray[i].openPopup();
                zoomTo(data[i].latitude, data[i].longitude);

            } else {
                var myIcon = L.icon({
                iconUrl: 'recinto_new/maps/images/cow.png',
                iconRetinaUrl: 'recinto_new/maps/images/cow.png',
                iconSize: [69, 70],
                iconAnchor: [9, 21],
                popupAnchor: [0, -14]
                });
                markerArray[i] = L.marker( [data[i].latitude, data[i].longitude], {icon: myIcon, title: data[i].title } )

                .bindPopup( '<div>' + 'Il bovino si trova qui: ' + '<br/>'
                    + '<b>Latitudine: </b> ' + data[i].latitude + ' - ' + '<b>Longitudine:</b> ' + data[i].longitude + '</br>'
                    + '<b>Nome: </b>' + data[i].title
                    + '</div>',
                    {direction: 'left'} )

                .addTo( map );


                    }

我创建了一个layerGroup var cow = new L.LayerGroup();并添加标记markerArray [i] .addTo(cow); 然后我创建一个控件并添加到地图:     var control = L.Control.styledLayerControl(baseMaps,overlays,options);             map.addControl(对照); 我可视化菜单但是当我点击隐藏我的标记的复选框时,控制台会给我这个错误:TypeError:this._getLayer(...)is undefined 任何人都可以帮助我吗?

0 个答案:

没有答案