MapBox加载GeoServer发布的WMS地图服务

版权声明: https://blog.csdn.net/GISuuser/article/details/88353436

使用MapBox加载GeoServer发布的WMS地图服务,测试一下成功,但是发现好像不支持4326坐标系,只支持3857坐标系,最终没有找到怎么加载4326坐标系的WMS服务。加载代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>MapBox加载WMS地图服务</title>
    <script src='https://api.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.js'></script>
    <link href='https://api.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.css' rel='stylesheet' />
    <style>
        body { margin:0; padding:0; }
        #map { position:absolute; top:0; bottom:0; width:100%; }
        /*隐藏logo*/
        .mapboxgl-ctrl.mapboxgl-ctrl-attrib{
            display: none !important;
        }
        .mapboxgl-ctrl-logo{
            display: none !important;
        }
    </style>
</head>
<body>
<div id='map'></div>
<script >
    mapboxgl.accessToken = 'pk.eyJ1IjoiaGFtYnVnZXJkZXZlbG9wIiwiYSI6ImNqNXJtZjF4ZzB3em4yd21pZmVqbHlleDAifQ.I9eqVjtotz7jaU7XcJm9pQ';
    var map = new mapboxgl.Map({
        container: 'map',
        style: 'mapbox://styles/mapbox/streets-v10',
        center: [108.438,34.431],
        zoom: 7
    });
    map.on("load",function () {
        map.addLayer({
            'id': 'wms-test-layer',
            'type': 'raster',
            'source': {
                'type': 'raster',
                'tiles': [
                    "http://localhost:8080/geoserver/word/wms?service=WMS&version=1.1.0&request=GetMap&layers=word:town3857&styles=&bbox={bbox-epsg-3857}&width=256&height=256&srs=EPSG:3857&format=image/png&TRANSPARENT=TRUE"
                ],
                'tileSize': 256
            },
            'paint': {}
        });
    })
</script>
</body>
</html>

效果图如下:

需要注意的是URL,连接WMS中的bbox参数用{bbox-epsg-3857}替换了,加载的时候,MapBox会自动替换成对应的参数,这样地图就可以加载了

猜你喜欢

转载自blog.csdn.net/GISuuser/article/details/88353436