Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 传单计时器。每秒钟高亮显示一个不同的城镇(多边形)_Javascript_Leaflet_Gis - Fatal编程技术网

Javascript 传单计时器。每秒钟高亮显示一个不同的城镇(多边形)

Javascript 传单计时器。每秒钟高亮显示一个不同的城镇(多边形),javascript,leaflet,gis,Javascript,Leaflet,Gis,我有一张4个城镇的地图,上面有传单。Mouseover和Mouseout工作得很好,但我希望有一个计时器,每5或10秒自动对每个城镇进行轮换。我试图在文档中找到一种方法,找到地图上的所有多边形,然后无限期地循环到这些多边形中,但我无法单独访问它们以应用函数高亮显示和重置样式 $.getJSON('./data/mymap.json', function (geojson) { var geojsonLayer = new L.GeoJSON(geojson, { style: funct

我有一张4个城镇的地图,上面有传单。Mouseover和Mouseout工作得很好,但我希望有一个计时器,每5或10秒自动对每个城镇进行轮换。我试图在文档中找到一种方法,找到地图上的所有多边形,然后无限期地循环到这些多边形中,但我无法单独访问它们以应用函数高亮显示和重置样式

$.getJSON('./data/mymap.json', function (geojson) {
var geojsonLayer = new L.GeoJSON(geojson, {
    style: function () {
        return {
            color: 'blue'
        }
    },
    onEachFeature: function (feature, layer) {
        layer.on('mouseover', function () {
            this.setStyle({
                color: 'green'
            });
            document.getElementById("mapdetails").innerText = layer.feature.properties.name;
        });
        layer.on('mouseout', function () {
            geojsonLayer.resetStyle(this);
            document.getElementById("mapdetails").innerText = '';
        });
        layer.on('click', function () {
            mymap.fitBounds(arrayBounds);
        });
    }
}).addTo(mymap);

});

function highlightLayer(layerID) {
    mymap._layers['name'+layerID].setStyle(highlight); }

var highlight = {
    'color': '#333333',
    'weight': 2,
    'opacity': 1 };

$(document).ready(function() {

    var layerGroup = L.LayerGroup([polygon]);

    for (var i in this._layers) {
        if (this._layers[i].options.name == 'Mytown') {
            console.log('found');
        }
    }

您必须从geojsonLayer调用每个层或getLayers


var i = 0;
function highlightLayer(){
   setTimeout(function(){
      geojsonLayer.resetStyle(); //To clear style of all layers
      var layers =  geojsonLayer.getLayers();
      if(layers.length >= i){
         i = 0;
      }
      layers[i].setStyle(highlight);
      i++;
      highlightLayer(); //Restart Timer
   },1000);
}

layerGroup.eachLayer应该有帮助-@peeebee是的,我研究过这个,但是当我打印到控制台时,我找不到这个大对象内部的功能。mymap.eachLayerfunctionlayer{console.loglayer};