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

时间:2016-09-19 16:48:13

标签: javascript openlayers-3

我正在尝试创建一个显示高程热图的Raster图层,红色是高峰,蓝色是大海。我试图利用OpenLayer 3的Geolocation(ol.Geolocation),但它返回undefined。我知道Geolocation的主要用途是用于实时当前的GPS定位,但我当然也应该可以将它用于其他地方,不是吗?

否则,是否还有其他免费服务(除了谷歌的Elevation API,需要使用谷歌地图),这将允许我根据经度和纬度获得高程数据?

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;});

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

1 个答案:

答案 0 :(得分:2)

我认为你误解了Geolocation API的目的。 Geolocation API用于根据可用的传感器(GPS,Wi-Fi,IP地址等)获取有关当前用户位置的信息。如果可用,它也会返回它们的高度。它所取得的成就是告诉你地面的高度在特定点上是什么,这不仅仅是它的设计目的。

您需要的是一个免费的海拔数据来源。如果您只是查询单点,您可以使用类似MapQuest Open Elevation Service的内容 - https://open.mapquestapi.com/elevation/ - 它与Google Maps Elevation服务非常相似,但没有相同的限制(您应该检查一下,我只是粗略一点一目了然)。如果您想要创建地图,您可能需要预制的栅格数据,既可以通过WMS或TMS服务制作和提供,也可以作为您可以自己摄取和渲染的点云。为此,您需要自己进行研究,这完全取决于您所寻找的领域。例如,在英国,许多基于LiDAR的地形模型可以通过https://data.gov.uk完全自由地打开。在其他地方,你可能需要研究NASA产生的东西。这个网站 - http://gisgeography.com/free-global-dem-data-sources/ - 可能是一个很好的起点。