Mapbox GL 加载GeoServer底图服务器的WMS source

貌似加载有点慢啊!!

1 这是底图

2 这是加载geoserver中的地图效果

3源码

3.1 geoserver中的网络请求

http://192.168.10.10:8080/geoserver/ne/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&format=image/png&TRANSPARENT=true&STYLES&LAYERS=ne:countries&exceptions=application/vnd.ogc.se_inimage&srs=EPSG:3857&WIDTH=768&HEIGHT=370&BBOX=-8296780.798186172,5087648.60266133,-8218509.281222152,5165920.119625352

///地址填写geoserver图层预览的时候 网络请求中的地址

///然后把把bbbox换一下 src坐标换一下,貌似mapbox只支持3857坐标系

///srs=EPSG:3857

///BBOX={bbox-epsg-3857}

​

复制代码
<template>
    <div class="mapbox-maps">
        <div id="map"></div>
    </div>
</template>

<script>
import mapboxgl from './../../public/mapbox-gl.js'
import './../../public/mapbox-gl.css' // 一定要引入样式, 否则有些东西显示不出来(比如导航控制条)
//import MapboxLanguage  from '@mapbox/mapbox-gl-language'

let res = [];
const MAPTYPE = {
    NAVIMG: 'nav_img',
    NAVLBL: 'nav_lbl',
    NAVVEC: 'nav_vec'
}
export default {
    data: () => ({
        map: null
    }),

    methods: {
        getNavTileUrls(lyr) {
            const dict = {
                'nav_img': 'https://webst0${subdomain}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
                'nav_lbl': 'https://webst0${subdomain}.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}',
                'nav_vec': 'http://webrd0${subdomain}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1&style=8'
            }
            for (let i = 1; i < 5; i++) {
                let url = dict[lyr];
                url = url.split('${subdomain}').join(i);
                res.push(url)
            }
            return res;
        },

        initMap() {
            //mapboxgl.accessToken = 'pk.eyJ1IjoibW9ob25nIiwiYSI6ImNrNGFsdjY5ZzA1NW4zbG14b2JoMnA5c3IifQ.1qVWFsyHW2wKThTgQg08SA';
            const BEIJING_COORDINATE = [116.39123296750768, 39.907180309385694];
            const style = {
                version: 8,
                name: "tianditu",
                //sprite: "mapbox://sprites/mapbox/streets-v8",
                //glyphs: "mapbox://fonts/mapbox/{fontstack}/{range}.pbf",
                sources: {
                    // 天地图电子标记
                    tianditu_cav: {
                        type: 'raster',
                        tiles: [
                            'https://t0.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=3602668176205a735014c430d4bfd5c4',
                            'https://t1.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=3602668176205a735014c430d4bfd5c4',
                        ],
                        tileSize: 256
                    },
                    // 天地图电子底图
                    tianditu_vec: {
                        type: 'raster',
                        tiles: [
                            'https://t0.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=3602668176205a735014c430d4bfd5c4',
                            'https://t1.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=3602668176205a735014c430d4bfd5c4',
                        ],
                        tileSize: 256
                    },
                    // 天地图影像图
                    tianditu_img: {
                        type: 'raster',
                        tiles: [
                            'https://t0.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=3602668176205a735014c430d4bfd5c4'
                        ],
                        tileSize: 256
                    },
                    tianditu_cia: {
                        type: 'raster',
                        tiles: [
                            'https://t1.tianditu.gov.cn/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=3602668176205a735014c430d4bfd5c4'
                        ],
                        tileSize: 256
                    }
                },
                layers: [
                    {
                        id: "tianditu_img",
                        type: "raster",
                        source: "tianditu_img",
                        minzoom: 0,
                        maxzoom: 22,
                        layout: {
                            "visibility": "none"
                        }
                    },
                    {
                        id: "tianditu_vec",
                        type: "raster",
                        source: "tianditu_vec",
                        minzoom: 0,
                        maxzoom: 22
                    },
                    {
                        id: "tianditu_cav",
                        type: "raster",
                        source: "tianditu_cav",
                        minzoom: 0,
                        maxzoom: 22
                    },
                    {
                        id: 'tianditu_cia',
                        type: 'raster',
                        source: 'tianditu_cia',
                        minzoom: 0,
                        maxzoom: 22
                    }
                ]
            }
            const map = new mapboxgl.Map({
                container: 'map',
                style: style,
                //center: [116.40355, 39.91737],
                zoom: 8,
                center: [-74.5447, 40.6892]
            });
            map.on('load', () => {
                map.addSource('wms-source', {
                    'type': 'raster',
                    'tiles': [
                        ///地址填写geoserver图层预览的时候  网络请求中的地址
                        ///然后把把bbbox换一下  src坐标换一下,貌似mapbox只支持3857坐标系
                        ///srs=EPSG:3857
                        ///BBOX={bbox-epsg-3857}
                        'http://192.168.10.10:8080/geoserver/ne/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&format=image/png&TRANSPARENT=true&STYLES&LAYERS=ne%3Acountries&exceptions=application%2Fvnd.ogc.se_inimage&srs=EPSG:3857&WIDTH=768&HEIGHT=370&BBOX={bbox-epsg-3857}',
                    ],
                    'tileSize': 256
                });
                map.addLayer({
                    'id': 'wms-layer',
                    'type': 'raster',
                    'source': 'wms-source',
                    'paint': {
                        'raster-opacity': 1
                    }
                },
                    //'aeroway-line'
                );

            });


        }
    },
    mounted() {
        this.initMap()
    }
}
</script>

<style lang="less">
.mapbox-maps {
    width: 100%;
    height: calc(100vh - 50px);
    position: relative;

    #map {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;

        .mapboxgl-canvas {
            outline: none;
        }

        // 隐藏mapbox商标
        .mapboxgl-ctrl-logo {
            display: none;
        }
    }
}
</style>


















<!-- <template>
  <div class="map_box">
      <div ref="map" class="map" id="map"></div>
  </div>
</template>

<script>
import maxboxMap from './futureMap.js'

export default {
  components: {},
  data() {
      return {
          map: null,
      }
  },
  computed: {},
  methods: {
      handleInitMap() {
          // 后期想传入一些值 比如areaCode 之类的 自动定位至改城市的中心

          let map = new maxboxMap({
              element: 'map'
          })
      },
  },
  watch: {},

  mounted() {
      this.handleInitMap()
  },
}
</script> -->
相关推荐
考虑考虑2 小时前
nginx拦截url
运维·后端·nginx
速捷工控 PLC触摸屏还原程序4 小时前
欧姆龙NB上传密码忘了,换屏前怎么保留原程序?
运维·服务器·欧姆龙
方便面不加香菜5 小时前
Docker Volume -- 对照总结及综合实战案例操作演示
运维·docker·容器
爱勇宝5 小时前
SSL 证书别再手动续了:acme.sh + Let's Encrypt + 云厂商 DNS 全自动实战
运维·服务器
数据库小学妹6 小时前
数据库容量规划:四个数与扩容触发线
运维·数据库·后端
wacsii7 小时前
【Linux进程(五)】进程控制全解析:从创建、终止、等待到程序替换
linux·服务器
七夜zippoe8 小时前
Nexent Linux 部署:用 deploy.sh
linux·服务器·docker·部署·ai智能体·nexent
去码头整点薯条988 小时前
NFS服务器
linux·运维·服务器
蜗牛一步步往上爬9 小时前
第一章 初识Linux shell
linux·运维·服务器
无足鸟ICT9 小时前
【RHCA+】系统调优配置文件
linux·服务器