openlayers6.4.3+geoserver+vue

openlayers6.4.3+geoserver+vue(开源)


前言

提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。


提示:以下是本篇文章正文内容,下面案例可供参考

一、openlayers6.4.3和geoserver的安装使用?

1.在geoserver官网下载最新的geoser的war包

--- http://geoserver.org/release/2.17.x/

在这里插入图片描述

2、我是后端开发所以配置了java环境,geoserver是基于java,将war丢到tomcat中的webapp下,运行

3、默认账户密码【admin,geoser】

在这里插入图片描述

4、建立工作区发布图层,点击获取图层数据:

在这里插入图片描述

5、点击获取图层地址用于openlayers调用,这是基于wms服务的地址,openlayers调用可用tile或者image切片服务;如果需要矢量数据在select one 中选择geojson调用供vector调用

二、服务发布完毕,引入openlayers

1.vue中引入库

--- npm install ol

2.全局定义

//openLayer全局引用
import ol from 'openlayers';
Vue.prototype.$ol=ol;

3.创建基本的map

1.生成map.vue

<template>
    <div class = "viewDiv" style="position:relative">
        <div id = "map" style="height: 100%;width: 100%;"></div>
    </div>
</template>
<script>
export default {
    data(){
        return{		
		}
    }   
}
</script>
<style lang = "less">
    .viewDiv {
        height:100%;
        width: 100%;
        background: #cccccc;
        position: absolute;
    }
    #map{
        width: 100% !important;
    }
</style>

2.创建地图,我是调用天地图为地图

<template>
    <div class = "viewDiv" style="position:relative">
        <div id = "map" style="height: 100%;width: 100%;"></div>
    </div>
</template>
<script>
export default {
import 'ol/ol.css';
    data(){
        return{
        	map: null,
            url:'xxxx:8090',
            tk:"xxxxxxxx",// 天地图开发者key
            ol:this.$ol,
            ZfeatureLayer19:null	
		}
    },
    mounted(){
    	this.openMap();
    },
    methods:{
    	openMap(){
    		this.overlay = new this.ol.Overlay({
                element: this.container,
                autoPan: true,
                autoPanAnimation: {
                    duration: 250,
                },
            });

            this.currentMap = new this.ol.Map({
                target: 'map',
                view: new this.ol.View({
                    center:[120.00,30.356],
                    projection: 'EPSG:4326',
                    zoom:11.5,

                }),
                layers:[
                    // 天地图
                    new this.ol.layer.Tile({
                        source: new this.ol.source.XYZ({
                            url: 'http://t3.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=' + this.tk,
                            maxZoom:18
                        }),
                        visible:false
                    }),
                    new this.ol.layer.Tile({
                        source: new this.ol.source.XYZ({
                            url: 'http://t3.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=' + this.tk,
                            maxZoom:18   //设置放大到某一级别
                        }),
                        visible:false
                    }),
                    // 影像图
                    new this.ol.layer.Tile({
                        source: new this.ol.source.XYZ({
                            url: 'http://t3.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=' + this.tk,
                            maxZoom:18   //设置放大到某一级别
                        })
                    }),
                    new this.ol.layer.Tile({
                        source: new this.ol.source.XYZ({
                            url: 'http://t3.tianditu.com/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=' + this.tk,
                            maxZoom:18
                        })
                    })
                ],
                controls: [
                ],
                overlays: [this.overlay],
            });
			// 2019图层
                this.ZfeatureLayer19 = new this.ol.layer.Tile({
                    source:new this.ol.source.TileWMS({
                        params:{
                            'SERVICE':'WMS',
                            'VERSION':'1.1.0',
                            'REQUEST':'GetMap',
                            'LAYERS':'xxxx:dk2019',
                            'BBOX':'[468983.25514828326,338072.9067438194,532768.4108643836,3382793.009806053]',
                            'WIDTH':'768',
                            'HEIGHT':'538',
                            'SRS':"EPSG:4549",//根据自己图层的坐标系而定
                            'FORMAT': 'image/png',
                            'RILED': true,
                            'TRANSPARENT':true,
                        },
                        url:"http://xxxxx:8080/geoserver/xxx/wms",
                    }),
                    visible:true,
                    name:'Dk2019',
                    opacity:'0.5'
                });
                this.map.addLayer(this.ZfeatureLayer19)
    	}
    }
}
</script>
<style lang = "less">
    .viewDiv {
        height:100%;
        width: 100%;
        background: #cccccc;
        position: absolute;
    }
    #map{
        width: 100% !important;
    }
</style>

3.显示:代码由于工作原因只能显示部分

在这里插入图片描述


总结

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程迷学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值