【发布时间】:2016-09-19 16:48:13
【问题描述】:
我正在尝试创建一个显示海拔热图的栅格图层,红色代表高峰,蓝色代表大海。我试图为此使用 OpenLayer 3 的地理位置(ol.Geolocation),但它返回未定义。我知道 Geolocation 的主要用途是用于实时当前 GPS 定位,但我当然也应该能够将它用于其他位置,不是吗?
否则,是否有任何其他免费服务(除了需要使用 Google 地图的 Google 海拔 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;});
注意:结果上没有红色,因为所有的高度都是未定义的。 :/
【问题讨论】: