openlayer4 calls the tms service of geoserver

Posted by anurag2003 on Sun, 29 Mar 2020 17:42:23 +0200

Based on openlayer4, the service published by geoserver is called, which mainly uses wms service. Recently, because a project released terrain data service, the leader disliked that the sld rendering result was not delicate, and required to achieve the global mapper rendering effect. After two days of struggling, it was finally completed and recorded as a later reference.

global mapper exports tif data with shading

Use global mapper to open the tif data of the dsm, then click file - > export - > export raster / image format, select geoTIFF, and select Image optimized platter in the pop-up panel

geoserver Publishing

Publish the service using the geotiff data source and slice it. There is a fatal problem at this stage, the published service has a yellow background color. When Du Niang has no fruit, he can only process the yellow part of the png image in a single way in the slice source as transparent (pure artificial work, experts can write a small program with python to automatically process it)

openlayer call

Mainly refer to this article tileUrlFunction processing logic:

<!DOCTYPE html>
    <link rel="stylesheet" href="" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src=",Element.prototype.classList,URL"></script>
    <script src=""></script>
    <div id="map" class="map"></div>
        var url="";
         var resolutions = [];
         for (var i = 0; i < 19; i++) {
            resolutions[i] = Math.pow(2, 18 - i);
      var projection=new ol.proj.get("EPSG:4326");
      var map = new ol.Map({
        target: 'map',
        layers: [
          new ol.layer.Tile({source:new ol.source.OSM(),id:"Electronic map",visible:true}),
            new ol.layer.Tile({
                source:  new ol.source.XYZ({  
                            projection: projection,
                            tileGrid: ol.tilegrid.createXYZ({extent: projection.getExtent()}),
                            tileUrlFunction: function (tileCoord, pixelRatio, proj) {
                                            return url+(tileCoord[0]-1)+ '/'+tileCoord[1] + '/' + (Math.pow(2,tileCoord[0]-1)+tileCoord[2]) + '.png'; 
        view: new ol.View({
            projection: projection,
            center:[115.55145, 23.01361],

Topics: Python Android