【问题标题】:leaflet.js (using geojson data) country labels incorrectLeaflet.js(使用geojson数据)国家标签不正确
【发布时间】:2019-01-06 03:06:08
【问题描述】:

我正在使用 leaflet.js(带有 geojson)来显示地图。 【去掉部分代码代码,更简洁】。

   $.getJSON('./api/map/data', function(data){
        let minZoom = 2.25
        let defaultZoom = 2.25
        let map = L.map('map', {
            minZoom: minZoom,
            zoomSnap: 0.1
        }).setView([43, 0], defaultZoom);

        let onEachFeature = (feature, layer) => {
            var label = L.marker(layer.getBounds().getCenter(), {
                icon: L.divIcon({
                    className: 'countryLabel',
                    html: feature.properties.name,
                    iconSize: [0, 0]
                })
            }).addTo(map);
        };

        L.geoJson(data, {
            clickable: false,
            style: {},
            onEachFeature: onEachFeature,
        }).addTo(map);

我使用this website 下载矢量地图。有些标签显然是不正确的(有些标签几乎是正确的)。经检查,似乎某些纬度/经度设置不正确(或者看起来如此)。关于如何正确显示此内容的任何反馈?如果我能想出适合国家边界的标签,那就太好了(这意味着可能在必要时添加国家代码)。

【问题讨论】:

    标签: leaflet geojson


    【解决方案1】:

    问题与您的标签选项有关。此时,您的图标位置指向标签的左上角,您需要设置偏移量以将标签移动到坐标中心。可能对您有帮助的属性是 iconAnchor (see leaflet docs)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-10
      • 2019-10-07
      • 1970-01-01
      • 2018-09-22
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 2020-06-08
      相关资源
      最近更新 更多