2016-09-19 299 views
0

我正在嘗試創建一個柵格圖層,顯示海拔高度的熱圖,紅色是高峯,藍色是海洋。我試圖利用OpenLayer 3的地理位置(ol.Geolocation),但它返回undefined。我明白,地理定位的主要用途是實時當前GPS定位,但我當然也應該可以在其他位置使用它,不是嗎?如何獲取OpenLayers 3的高程數據?

否則,是否有任何其他免費服務(除了需要使用Google地圖的Google 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

我認爲你誤解了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打開。在其他地方,你需要研究美國宇航局可能產生的結果。這個網站 - http://gisgeography.com/free-global-dem-data-sources/ - 可能是一個很好的起點。