最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get elevation data for OpenLayers 3? - Stack Overflow

programmeradmin0浏览0评论

I'm trying to create a Raster layer that displays a heatmap of elevation, reddish colour being a high peak and blue being the sea. I was trying to utilise OpenLayer 3's Geolocation (ol.Geolocation) for that, but it returns undefined. I understand that Geolocation's primary usage is for realtime current GPS locating, but surely I should be able to use it for other locations too, no?

Otherwise, are there any other free services (apart from Google's Elevation API, which requires the use of the Google Map) that would allow me to get elevation data based on the longitude and latitude?

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

Note: the result has no red on it, as all of the altitude is undefined. :/

I'm trying to create a Raster layer that displays a heatmap of elevation, reddish colour being a high peak and blue being the sea. I was trying to utilise OpenLayer 3's Geolocation (ol.Geolocation) for that, but it returns undefined. I understand that Geolocation's primary usage is for realtime current GPS locating, but surely I should be able to use it for other locations too, no?

Otherwise, are there any other free services (apart from Google's Elevation API, which requires the use of the Google Map) that would allow me to get elevation data based on the longitude and latitude?

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

Note: the result has no red on it, as all of the altitude is undefined. :/

Share Improve this question asked Sep 19, 2016 at 16:48 MoxMox 5983 gold badges9 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

I think you've misunderstood the purpose of the Geolocation API. The Geolocation API is used to get information about a current users position based on whatever sensors they have available (GPS, Wi-Fi, IP Address etc.). Where available it also returns their altitude. What it won't do is tell you what the altitude on the ground is at a specific point, this just isn't what it is designed for.

What you need is a free source of data for elevation. If you are just querying single points you could use something like the MapQuest Open Elevation Service - https://open.mapquestapi./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 pletely freely and open via https://data.gov.uk. Elsewhere you'll need to look into perhaps what NASA produces. This site - http://gisgeography./free-global-dem-data-sources/ - Could be a good starting point.

发布评论

评论列表(0)

  1. 暂无评论