我正在嘗試創建一個柵格圖層,顯示海拔高度的熱圖,紅色是高峯,藍色是海洋。我試圖利用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;});
注意:結果沒有紅色,因爲所有的高度都是未定義的。 :/