Show GeoTiff image Openlayers 3

回眸只為那壹抹淺笑 提交于 2020-01-04 05:01:04

问题


I need to display a raster image in GeoTiff format, it was georeferenced with QGIS. It looks like Openlayers 3.15 doesn't support this kind of format. Do you know anything about that?

var agentUrl = 'http://localhost:9925/Wgis/assets/img/allertaMeteoGeo.tif';

    var bounds = [ 713101.704, 4044061.027, 713101.704, 4044061.027];



    var view2 = new ol.View({
        center : [ -87.7302542509315, 43.744459064634 ],
        projection : "EPSG:3857",
        zoom : 12
    });

    var sorgente = new ol.source.ImageMapGuide({
        projection : "EPSG:3857",
        url : agentUrl,
        metersPerUnit : 111319.4908,

        imageSize: [792, 452],
        ratio : 2
    });

    var raster = new ol.layer.Image({
        extent : bounds,
        source : sorgente
    });

    var map2 = new ol.Map({
        layers : [ raster ],
        target : 'map2',
        view : view2
    });

回答1:


I agree with chrki, that it is not currently possible to display a TIFF (or GeoTiFF) in an OpenLayers map as stated here: https://gis.stackexchange.com/a/98029. Browsers do not display TIFF images natively.

As an experiment, I exported both TIFF and PNG files from an ArcGIS raster image. Then in an openlayers map (using v3.18.2), I used the following function to successfully add a PNG as an ol.layer.Image, but it failed without notice for the TIFF:

function addImage() {

    extent = [-13602803.9769, 4920816.12423, -13599949.5192, 4923458.74552]; // [left, bottom, right, top]

    var projection = new ol.proj.Projection({
        code: 'xkcd-image',
        units: 'pixels',
        extent: extent
    });

    var StaticImage = new ol.layer.Image({
        source: new ol.source.ImageStatic({
        attributions: 'yada yada',
        url: /robs/gis_data/LiDAR Elevations2.png',
        projection: projection,
        imageExtent: extent
        })
    });    

    map.addLayer(StaticImage);
    map.getView().fit(extent, map.getSize());    
} 



回答2:


Actually you could tile your image before, load it in IIS and get it from something like this:

var newLayer = new ol.layer.Tile({
source: new ol.source.OSM({
        url: 'maps/{z}/{x}/{y}.png'
})});


来源:https://stackoverflow.com/questions/37207329/show-geotiff-image-openlayers-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!