Mapbox:它呈现最后一个点而不是所有

Mapbox: It renders the last point instead of all

我正在尝试使用 Mapbox 渲染多个点,但它只显示最后一个点。我已经添加了功能参数,但什么也没有。这应该呈现两个标记,但我不知道为什么不。我在控制台中没有收到任何错误。

我卡住了,找不到解决方法。有帮助吗?

这是负责积分的代码。:

map.on('load', function() {
    map.loadImage('images/celltower.png', function(error, image) {
        if (error) throw error;
        map.addImage('tower', image);
        map.addLayer({
            "id": "points",
            "type": "symbol",
            "source": {
                "type": "geojson",
                "data": {
                    "type": "FeatureCollection",
                    "features": [{
                        "type": "Feature",
                        "geometry": {
                            "type": "Point",
                            "coordinates": [21.42559803007430, 42.00038270989050]
                        },
                        "geometry": {
                            "type": "Point",
                            "coordinates": [21.38529272846381, 42.0080397578202]
                        }
                    }]
                }
            },
            "layout": {
                "icon-image": "tower",
                "icon-size": 0.25
            }
        });
    });
});

谢谢:)

您有一个重复的 geometry 密钥。从 features 是一个数组这一事实来看,我猜这是正确的方法:

map.on('load', function() {
    map.loadImage('images/celltower.png', function(error, image) {
        if (error) throw error;
        map.addImage('tower', image);
        map.addLayer({
            "id": "points",
            "type": "symbol",
            "source": {
                "type": "geojson",
                "data": {
                    "type": "FeatureCollection",
                    "features": [{
                        "type": "Feature",
                        "geometry": {
                            "type": "Point",
                            "coordinates": [21.42559803007430, 42.00038270989050]
                        }
                    }, {
                        "type": "Feature",
                        "geometry": {
                            "type": "Point",
                            "coordinates": [21.38529272846381, 42.0080397578202]
                        }
                    }]
                }
            },
            "layout": {
                "icon-image": "tower",
                "icon-size": 0.25
            }
        });
    });
});

根据GeoJSON specification,应该有一种方法可以指定多个点。例如:

"features": [{
    "type": "Feature",
    "geometry": {
        "type": "MultiPoint",
        "coordinates": [
            [21.42559803007430, 42.00038270989050],
            [21.38529272846381, 42.0080397578202]
        ]
    }
}]