【问题标题】:Leaflet use popup not display传单使用弹出窗口不显示
【发布时间】:2020-10-31 23:35:27
【问题描述】:

我使用 highchart 图表显示在弹出窗口中。

第一次点击标记时可以显示。

但打开另一个弹出窗口无法显示图表。

如果我关闭原来的,再打开一个新的,就可以显示了。

有什么问题?

第一次开机

打开另一个时

代码:

 function onEachFeature(feature, layer) {
    var popupContent = '<p style="font-size:130%;">' + feature.properties.id + "<br>PM2.5: " + air + '</p><div class="d-flex"> <button class="day-button">24 hr</button>   <button class="week-button">7 Days</button> <button class="mon-button ">30 Days</button></div>' + '</p><div id="container" style="min-width: 350px; height: 190px; margin: 0 auto"></div> <p> ';
    if (feature.properties && feature.properties.popupContent) {
            popupContent += feature.properties.popupContent;
        }
  layer.bindPopup(popupContent, { minWidth: 370 }).on("popupopen", function(e) {
        
        var id1 = feature.properties.id;
        Highcharts.setOptions({ global: { useUTC: false } });
        var chart = null;
        test(id1);
    }
}

高图:

function test (station){
    var ob = [];
    var json_hour ="data.csv";
    var count_nul = 0;
 
    d3.csv(json_hour, function (error, result) {
        function date_to_epoch(key) {
            var epoch_seconds = new Date(key).getTime();
            return Math.floor(epoch_seconds);
        }
        for (var i = 0; i < result.length; i++) {
            var apoche = date_to_epoch(result[i]['date']).toString();
            apoche = parseFloat(apoche);
             
            if (parseFloat(result[i]['pm25']).toString() == 'NaN') {
                count_nul++;
            } else {
                var miles = parseFloat(result[i]['pm25']);

            }
            ob.push([apoche, miles]);
        }

        if (count_nul >= 24) {
            $("#con").text("no data");
        }
        else {
            $("#con").empty();
            console.log((ob));
           
       new Highcharts.Chart({
                chart: {
                    renderTo: 'con',
                    type: 'line'
                },
                title: { text: '' },
                xAxis: {
                    type: 'datetime',
                    dateTimeLabelFormats: {
                        minute: '%H:%M',
                        hour: '%H:%M',
                        day: '%Y<br/>%m%d',
                        week: '%Y<br/>%m-%d',
                        month: '%Y<br/>%m',
                        year: '%Y'
                    }
                    , crosshair: true,
                },
                tooltip: {
                    split: false,
                    shared: true,
                    animation: true,
                    xDateFormat: '%Y-%m-%d %H:%M',
                    valueSuffix: ' µm'
                },
                series: [{
                    name: "PM2.5",
                    data: ob,
                    showInLegend: true
                }
                ],
                credits: {
                    enabled: false 
                },
                exporting: {
                    enabled: false 
                },
                plotOptions: {
                    line: {
                        connectNulls: true,
                    }

                },
                responsive: {
                    rules: [{
                        condition: {
                            maxWidth: 330
                        },

                    }]
                }
            });
          
        }
    });
}

【问题讨论】:

标签: highcharts leaflet


【解决方案1】:

将您的代码更改为:

 function onEachFeature(feature, layer) {
    var popupContent = '<p style="font-size:130%;">' + feature.properties.id + "<br>PM2.5: " + air + '</p><div class="d-flex"> <button class="day-button">24 hr</button>   <button class="week-button">7 Days</button> <button class="mon-button ">30 Days</button></div>' + '</p><div id="container" style="min-width: 350px; height: 190px; margin: 0 auto"></div> <p> ';
    if (feature.properties && feature.properties.popupContent) {
            popupContent += feature.properties.popupContent;
        }
  layer.bindPopup(popupContent, { minWidth: 370 }).on("popupopen", function(e) {
        
        var id1 = e.popup._source.feature.properties.id;
        Highcharts.setOptions({ global: { useUTC: false } });
        var chart = null;
        test(id1);
    }
}

使用e.popup._source.feature.properties.id,您可以确定 id 来自当前开放层

【讨论】:

  • 仍然不显示。
  • id 是正确的。测试函数也有数据,但是“con”不显示数据。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-12
  • 1970-01-01
  • 1970-01-01
  • 2015-06-27
相关资源
最近更新 更多