从Geoserver向地图框gl添加wmts图层

问题描述

我正在尝试从geoserver 2.18添加wmts图层。我的代码

            window.mymap.addSource(
                "mvt-test-source",{
                 "type": "vector","tiles": [
                    "http://localhost:8080/geoserver/gwc/service/wmts?SERVICE=WMTS&&VERSION=1.0.0&REQUEST=GetTile&layer=mapBox:roads4326&TILEMATRIX=epsg:4326:{z}&TILEMATRIXSET=epsg:4326&FORMAT=application/vnd.mapBox-vector-tile&TILECOL={x}&TILEROW={y}"
                    ],"minZoom": 0,"maxZoom": 14
            });

            window.mymap.addLayer(
                {
                    'id': 'my_mvt_layer','type': 'line','source': 'mvt-test-source','source-layer': 'mapBox:roads4326',"visibility": "visible",'paint': {
                        'line-color': 'Red','line-width': 7
                    }
                }
            );

浏览器中没有错误,但图层未出现在地图上。 可能是什么原因? 当我尝试使用wms服务时-一切正常。下一个具有wms格式的代码

window.mymap.addSource("wms-test-source",{
                "type": 'raster',"tiles": [
                  "http://localhost:8080/geoserver/wms?bBox={bBox-epsg-3857}&format=image/png&service=WMS&&version=1.1.1&request=GetMap&srs=epsg:900913&transparent=true&width=256&height=256&layers=mapBox:roads4326"
                ],'tileSize': 256
            });

            window.mymap.addLayer(
                {
                    "id": 'wms-test-layer',"type": 'raster',"source": 'wms-test-source',"paint": {
                    }
                }                
            );

解决方法

您的visibility属性不应以这种方式添加。像这样添加它:

 window.mymap.addLayer(
                {
                    'id': 'my_mvt_layer','type': 'line','source': 'mvt-test-source','source-layer': 'mapbox:roads4326','layout':{
                     "visibility": "visible",}
                    'paint': {
                        'line-color': 'Red','line-width': 7
                    }
                }
            );