带纬度和经度的 HighCharts 地图点不起作用

发布于 2025-01-09 15:05:59 字数 2204 浏览 0 评论 0原文

我正在处理一个要求,我们需要加载自定义 GeoJSON 数据并在加载的地图上添加点。不幸的是,这些点没有显示出来。

编辑以添加要求,我想向钻取地图添加点(向下钻取示例),如果有人可以指导我如何在向下钻取地图上实现点映射,那就太好了。

我已经用演示代码“带有纬度/经度的地图点”重现了该问题,请有人指导我。

示例代码可以在 https://jsfiddle.net/5te18vzm/1/

let data = Highcharts.geojson(Highcharts.maps['countries/gb/gb-all']);
        const separators = Highcharts.geojson(Highcharts.maps['countries/gb/gb-all'], 'mapline');

Highcharts.mapChart('container', {

chart: {
    //map: 'countries/gb/gb-all'
},

title: {
    text: 'Highmaps basic lat/lon demo'
},

mapNavigation: {
    enabled: true
},

tooltip: {
    headerFormat: '',
    pointFormat: '<b>{point.name}</b><br>Lat: {point.lat}, Lon: {point.lon}'
},

series: [{
    // Use the gb-all map with no data as a basemap
    name: 'Basemap',
    data:data,
    borderColor: '#A0A0A0',
    nullColor: 'rgba(200, 200, 200, 0.3)',
    showInLegend: true
}, {
    name: 'Separators',
    type: 'mapline',
    nullColor: '#707070',
    showInLegend: false,
    enableMouseTracking: false
}, {
    // Specify points using lat/lon
    type: 'mappoint',
    name: 'Cities',
    color: Highcharts.getOptions().colors[1],
    data: [{
        name: 'London',
        lat: 51.507222,
        lon: -0.1275
    }, {
        name: 'Birmingham',
        lat: 52.483056,
        lon: -1.893611
    }, {
        name: 'Leeds',
        lat: 53.799722,
        lon: -1.549167
    }, {
        name: 'Glasgow',
        lat: 55.858,
        lon: -4.259
    }, {
        name: 'Sheffield',
        lat: 53.383611,
        lon: -1.466944
    }, {
        name: 'Liverpool',
        lat: 53.4,
        lon: -3
    }, {
        name: 'Bristol',
        lat: 51.45,
        lon: -2.583333
    }, {
        name: 'Belfast',
        lat: 54.597,
        lon: -5.93
    }, {
        name: 'Lerwick',
        lat: 60.155,
        lon: -1.145,
        dataLabels: {
            align: 'left',
            x: 5,
            verticalAlign: 'middle'
        }
    }]
}]

}) ;

I'm working on a requirement where we need to load custom GeoJSON data and add points on the loaded map. unfortunately the points are not showing up.

Editing to add the requirement, I want to add points to the drill down map(Drill down example), it would be great if someone can guide me on how can I achieve point mapping on the drill down map.

I have reproduced the issue with the demo code "Map point with lat/long", please could someone guide me on this.

The sample code can be found at https://jsfiddle.net/5te18vzm/1/

let data = Highcharts.geojson(Highcharts.maps['countries/gb/gb-all']);
        const separators = Highcharts.geojson(Highcharts.maps['countries/gb/gb-all'], 'mapline');

Highcharts.mapChart('container', {

chart: {
    //map: 'countries/gb/gb-all'
},

title: {
    text: 'Highmaps basic lat/lon demo'
},

mapNavigation: {
    enabled: true
},

tooltip: {
    headerFormat: '',
    pointFormat: '<b>{point.name}</b><br>Lat: {point.lat}, Lon: {point.lon}'
},

series: [{
    // Use the gb-all map with no data as a basemap
    name: 'Basemap',
    data:data,
    borderColor: '#A0A0A0',
    nullColor: 'rgba(200, 200, 200, 0.3)',
    showInLegend: true
}, {
    name: 'Separators',
    type: 'mapline',
    nullColor: '#707070',
    showInLegend: false,
    enableMouseTracking: false
}, {
    // Specify points using lat/lon
    type: 'mappoint',
    name: 'Cities',
    color: Highcharts.getOptions().colors[1],
    data: [{
        name: 'London',
        lat: 51.507222,
        lon: -0.1275
    }, {
        name: 'Birmingham',
        lat: 52.483056,
        lon: -1.893611
    }, {
        name: 'Leeds',
        lat: 53.799722,
        lon: -1.549167
    }, {
        name: 'Glasgow',
        lat: 55.858,
        lon: -4.259
    }, {
        name: 'Sheffield',
        lat: 53.383611,
        lon: -1.466944
    }, {
        name: 'Liverpool',
        lat: 53.4,
        lon: -3
    }, {
        name: 'Bristol',
        lat: 51.45,
        lon: -2.583333
    }, {
        name: 'Belfast',
        lat: 54.597,
        lon: -5.93
    }, {
        name: 'Lerwick',
        lat: 60.155,
        lon: -1.145,
        dataLabels: {
            align: 'left',
            x: 5,
            verticalAlign: 'middle'
        }
    }]
}]

});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-小熊_ 2025-01-16 15:05:59

您需要设置 chart.map 属性,然后在 {name, lat, lon} 的简化数据集中指定您的点 - 我将其制作为 dataPointsOnly

试试这个

let data = Highcharts.geojson(Highcharts.maps['countries/gb/gb-all']);
            const separators = Highcharts.geojson(Highcharts.maps['countries/gb/gb-all'], 'mapline');

var dataPointsOnly = [];

// Set drilldown pointers
data.forEach((d, i) => {
  d.drilldown = d.properties['hc_key'];
  d.value = i; // Non-random bogus data
  
  dataPointsOnly.push({name: data[i].name, lat: parseFloat(data[i].properties.latitude), lon: parseFloat(data[i].properties.longitude)});
});

// Initialize the chart hc-key
Highcharts.mapChart('container', {

    chart: {
        map: 'countries/gb/gb-all'
    },

    title: {
        text: 'Highmaps basic lat/lon demo'
    },

    mapNavigation: {
        enabled: true
    },

    tooltip: {
        headerFormat: '',
        pointFormat: '<b>{point.name}</b><br>Lat: {point.lat}, Lon: {point.lon}'
    },

    series: [{
        // Use the gb-all map with no data as a basemap
        name: 'Basemap',
        data:data,
        borderColor: '#A0A0A0',
        nullColor: 'rgba(200, 200, 200, 0.3)',
        showInLegend: true
    }, {
        name: 'Separators',
        type: 'mapline',
        nullColor: '#707070',
        showInLegend: false,
        enableMouseTracking: false
    }, {
        // Specify points using lat/lon
        type: 'mappoint',
        name: 'Cities',
        color: Highcharts.getOptions().colors[1],
        data: dataPointsOnly
    }]
});

You need to set the chart.map property, and then specify your points in a simplified dataset of just {name, lat, lon} - which I have made as dataPointsOnly

Try this

let data = Highcharts.geojson(Highcharts.maps['countries/gb/gb-all']);
            const separators = Highcharts.geojson(Highcharts.maps['countries/gb/gb-all'], 'mapline');

var dataPointsOnly = [];

// Set drilldown pointers
data.forEach((d, i) => {
  d.drilldown = d.properties['hc_key'];
  d.value = i; // Non-random bogus data
  
  dataPointsOnly.push({name: data[i].name, lat: parseFloat(data[i].properties.latitude), lon: parseFloat(data[i].properties.longitude)});
});

// Initialize the chart hc-key
Highcharts.mapChart('container', {

    chart: {
        map: 'countries/gb/gb-all'
    },

    title: {
        text: 'Highmaps basic lat/lon demo'
    },

    mapNavigation: {
        enabled: true
    },

    tooltip: {
        headerFormat: '',
        pointFormat: '<b>{point.name}</b><br>Lat: {point.lat}, Lon: {point.lon}'
    },

    series: [{
        // Use the gb-all map with no data as a basemap
        name: 'Basemap',
        data:data,
        borderColor: '#A0A0A0',
        nullColor: 'rgba(200, 200, 200, 0.3)',
        showInLegend: true
    }, {
        name: 'Separators',
        type: 'mapline',
        nullColor: '#707070',
        showInLegend: false,
        enableMouseTracking: false
    }, {
        // Specify points using lat/lon
        type: 'mappoint',
        name: 'Cities',
        color: Highcharts.getOptions().colors[1],
        data: dataPointsOnly
    }]
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文