【问题标题】:Highcharts Highmaps How to add mappoint to custom mapHighcharts Highmaps 如何将地图点添加到自定义地图
【发布时间】:2020-10-27 17:13:13
【问题描述】:

我用 Highmaps 构建了一个自定义地图:see fiddle

现在我想添加一个带有地图点的系列:

{
        type: 'mappoint',
        name: 'Cities',
        zIndex: 100,
        color: '#000000',
        data: [{
            name: 'Birmingham',
            lat: 52,
            lon: 1.8
            }]
    }

但我不知道在这种情况下如何使用 fromLatLonToPoint。我该怎么做?

【问题讨论】:

    标签: highcharts


    【解决方案1】:

    您可以直接使用 lat 和 lon 属性,但您的 mappoint 系列会被来自 data 属性的解析系列覆盖。作为解决方案,在加载主数据后使用addSeries方法,例如:

     parsed: function() {
       var chart = this.chart,
         center = chart.fromLatLonToPoint({
           lat: 50,
           lon: 10
         });
    
       setTimeout(function() {
         chart.mapZoom(.15, center.x, center.y);
    
         chart.addSeries({
           type: 'mappoint',
           name: 'Cities',
           zIndex: 100,
           color: '#000000',
           data: [{
             name: 'Birmingham',
             lat: 52,
             lon: 1.8
           }]
         });
       }, 500)
     }
    

    现场演示: https://jsfiddle.net/BlackLabel/vw1p4jtr/

    API 参考:

    https://api.highcharts.com/class-reference/Highcharts.Chart#addSeries

    https://api.highcharts.com/highmaps/series.mappoint.data.lat

    【讨论】:

    • 谢谢@ppotaczek 它可以工作,但是数据标签显示在绘图区域之外:fiddle你能告诉我如何防止这种情况吗?
    • 嗨@Johannes Christ,谢谢你的例子。作为解决方案,启用crop 属性。现场演示:jsfiddle.net/BlackLabel/e7hym0dL
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    • 1970-01-01
    • 1970-01-01
    • 2017-01-01
    • 2018-10-11
    • 2014-02-20
    相关资源
    最近更新 更多