如何获取 OpenLayers 3 的高程数据?

How to get elevation data for OpenLayers 3?

我正在尝试创建一个显示海拔热图的栅格图层,红色代表高峰,蓝色代表大海。我试图为此使用 OpenLayer 3 的地理定位 (ol.Geolocation),但它 returns 未定义。我知道 Geolocation 的主要用途是用于实时当前 GPS 定位,但我当然也应该能够将它用于其他位置,不是吗?

否则,是否有任何其他免费服务(除了 Google 的海拔 API,需要使用 Google 地图)可以让我获得海拔基于经纬度的数据?

app.rasterCounter = 0;
var geolocation = new ol.Geolocation({
    projection: map.getView().getProjection()
});
var raster = new ol.source.Raster({
    sources: [bing],
    operation: function(pixels, data) {
        //find the current pixel's location
        var y = Math.floor(app.rasterCounter/map.getSize()[0]);
        var x = Math.floor(app.rasterCounter % map.getSize()[0]);
        //find the pixel's coordinate equivalent
        var coords = map.getCoordinateFromPixel([x, y]);
        var lonlat = ol.proj.toLonLat(coords);
        geolocation.set('position', lonlat);
        //if above sea level, then display a heatmap of the long/lati, otherwise display red
        var pixel = geolocation.getAltitude() > 0 || geolocation.getAltitude() === undefined ? [0, lonlat[0]+100, lonlat[1]+100, 128] : [255, 0, 0, 128];
        app.rasterCounter++;
        return pixel;
    },
    //allow access to the DOM
    threads: 0
});
raster.on('afteroperations', function(e) {app.rasterCounter=0;});

注意:结果上没有红色,因为所有高度都未定义。 :/

我认为您误解了地理定位的目的 API。 Geolocation API 用于根据用户可用的任何传感器(GPS、Wi-Fi、IP 地址等)获取有关当前用户位置的信息。在可用的情况下,它还 returns 他们的高度。它不会告诉你特定点的地面高度,这不是它的设计目的。

您需要一个免费的高程数据源。如果您只是查询单个点,您可以使用类似 MapQuest Open Elevation Service 的东西 - https://open.mapquestapi.com/elevation/ - Its very similar to the Google Maps Elevation service but without the same restrictions (You should check this properly, I only had a cursory glance). If you want to create a map you'll probably want pre made raster data, either already made and available via a WMS or TMS service, or as a point cloud that you can ingest and render yourself. For this you'll need to do your own research and it will depend entirely on what area you are looking for. For example, in the UK a lot of LiDAR based terrain models are available completely freely and open via https://data.gov.uk. Elsewhere you'll need to look into perhaps what NASA produces. This site - http://gisgeography.com/free-global-dem-data-sources/ - 可能是一个很好的起点。