vue 中 openlayers扩展自定义投影

本文介绍了如何通过proj4模块安装和注册自定义投影,包括中国2000国家大地坐标系(CGCS2000)的多种Gauss-Kruger带区投影及其对应的EPSG格式。展示了如何在openlayers中使用这些自定义投影进行地图展示。
摘要由CSDN通过智能技术生成

1.先安装proj4,

2.引入proj4模块和openlayers的proj4包下的register方法.

3.用proj4定义扩展的自定义投影,用register注册。

4.EPSG proj4格式定义列表

# Xian 1980
<4610> +proj=longlat +a=6378140 +b=6356755.288157528 +no_defs  <>
# China Geodetic Coordinate System 2000
<4490> +proj=longlat +ellps=GRS80 +no_defs  <>
# WGS 84
<4326> +proj=longlat +datum=WGS84 +no_defs  <>
# CGCS2000 / Gauss-Kruger zone 13
<4491> +proj=tmerc +lat_0=0 +lon_0=75 +k=1 +x_0=13500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger zone 14
<4492> +proj=tmerc +lat_0=0 +lon_0=81 +k=1 +x_0=14500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger zone 15
<4493> +proj=tmerc +lat_0=0 +lon_0=87 +k=1 +x_0=15500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger zone 16
<4494> +proj=tmerc +lat_0=0 +lon_0=93 +k=1 +x_0=16500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger zone 17
<4495> +proj=tmerc +lat_0=0 +lon_0=99 +k=1 +x_0=17500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger zone 18
<4496> +proj=tmerc +lat_0=0 +lon_0=105 +k=1 +x_0=18500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger zone 19
<4497> +proj=tmerc +lat_0=0 +lon_0=111 +k=1 +x_0=19500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger zone 20
<4498> +proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=20500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger zone 21
<4499> +proj=tmerc +lat_0=0 +lon_0=123 +k=1 +x_0=21500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger zone 22
<4500> +proj=tmerc +lat_0=0 +lon_0=129 +k=1 +x_0=22500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger zone 23
<4501> +proj=tmerc +lat_0=0 +lon_0=135 +k=1 +x_0=23500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger CM 75E
<4502> +proj=tmerc +lat_0=0 +lon_0=75 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger CM 81E
<4503> +proj=tmerc +lat_0=0 +lon_0=81 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger CM 87E
<4504> +proj=tmerc +lat_0=0 +lon_0=87 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger CM 93E
<4505> +proj=tmerc +lat_0=0 +lon_0=93 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger CM 99E
<4506> +proj=tmerc +lat_0=0 +lon_0=99 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger CM 105E
<4507> +proj=tmerc +lat_0=0 +lon_0=105 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger CM 111E
<4508> +proj=tmerc +lat_0=0 +lon_0=111 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger CM 117E
<4509> +proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger CM 123E
<4510> +proj=tmerc +lat_0=0 +lon_0=123 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger CM 129E
<4511> +proj=tmerc +lat_0=0 +lon_0=129 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / Gauss-Kruger CM 135E
<4512> +proj=tmerc +lat_0=0 +lon_0=135 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 25
<4513> +proj=tmerc +lat_0=0 +lon_0=75 +k=1 +x_0=25500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 26
<4514> +proj=tmerc +lat_0=0 +lon_0=78 +k=1 +x_0=26500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 27
<4515> +proj=tmerc +lat_0=0 +lon_0=81 +k=1 +x_0=27500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 28
<4516> +proj=tmerc +lat_0=0 +lon_0=84 +k=1 +x_0=28500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 29
<4517> +proj=tmerc +lat_0=0 +lon_0=87 +k=1 +x_0=29500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 30
<4518> +proj=tmerc +lat_0=0 +lon_0=90 +k=1 +x_0=30500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 31
<4519> +proj=tmerc +lat_0=0 +lon_0=93 +k=1 +x_0=31500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 32
<4520> +proj=tmerc +lat_0=0 +lon_0=96 +k=1 +x_0=32500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 33
<4521> +proj=tmerc +lat_0=0 +lon_0=99 +k=1 +x_0=33500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 34
<4522> +proj=tmerc +lat_0=0 +lon_0=102 +k=1 +x_0=34500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 35
<4523> +proj=tmerc +lat_0=0 +lon_0=105 +k=1 +x_0=35500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 36
<4524> +proj=tmerc +lat_0=0 +lon_0=108 +k=1 +x_0=36500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 37
<4525> +proj=tmerc +lat_0=0 +lon_0=111 +k=1 +x_0=37500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 38
<4526> +proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=38500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 39
<4527> +proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=39500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 40
<4528> +proj=tmerc +lat_0=0 +lon_0=120 +k=1 +x_0=40500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 41
<4529> +proj=tmerc +lat_0=0 +lon_0=123 +k=1 +x_0=41500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 42
<4530> +proj=tmerc +lat_0=0 +lon_0=126 +k=1 +x_0=42500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 43
<4531> +proj=tmerc +lat_0=0 +lon_0=129 +k=1 +x_0=43500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 44
<4532> +proj=tmerc +lat_0=0 +lon_0=132 +k=1 +x_0=44500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger zone 45
<4533> +proj=tmerc +lat_0=0 +lon_0=135 +k=1 +x_0=45500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 75E
<4534> +proj=tmerc +lat_0=0 +lon_0=75 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 78E
<4535> +proj=tmerc +lat_0=0 +lon_0=78 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 81E
<4536> +proj=tmerc +lat_0=0 +lon_0=81 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 84E
<4537> +proj=tmerc +lat_0=0 +lon_0=84 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 87E
<4538> +proj=tmerc +lat_0=0 +lon_0=87 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 90E
<4539> +proj=tmerc +lat_0=0 +lon_0=90 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 93E
<4540> +proj=tmerc +lat_0=0 +lon_0=93 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 96E
<4541> +proj=tmerc +lat_0=0 +lon_0=96 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 99E
<4542> +proj=tmerc +lat_0=0 +lon_0=99 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 102E
<4543> +proj=tmerc +lat_0=0 +lon_0=102 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 105E
<4544> +proj=tmerc +lat_0=0 +lon_0=105 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 108E
<4545> +proj=tmerc +lat_0=0 +lon_0=108 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 111E
<4546> +proj=tmerc +lat_0=0 +lon_0=111 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 114E
<4547> +proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 117E
<4548> +proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 120E
<4549> +proj=tmerc +lat_0=0 +lon_0=120 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 123E
<4550> +proj=tmerc +lat_0=0 +lon_0=123 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 126E
<4551> +proj=tmerc +lat_0=0 +lon_0=126 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 129E
<4552> +proj=tmerc +lat_0=0 +lon_0=129 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 132E
<4553> +proj=tmerc +lat_0=0 +lon_0=132 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
# CGCS2000 / 3-degree Gauss-Kruger CM 135E
<4554> +proj=tmerc +lat_0=0 +lon_0=135 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs  <>
 

要实现自定义绘图控件,需要使用VueOpenLayers的组件。首先,在Vue组件引入OpenLayers库: ```javascript import 'ol/ol.css'; import Map from 'ol/Map'; import View from 'ol/View'; import { Draw, Modify, Snap } from 'ol/interaction'; import { Tile as TileLayer, Vector as VectorLayer } from 'ol/layer'; import { OSM, Vector as VectorSource } from 'ol/source'; import { Circle as CircleStyle, Fill, Stroke, Style } from 'ol/style'; ``` 然后,在Vue组件定义一个地图容器和一个绘图控件容器: ```html <template> <div> <div ref="map" class="map"></div> <div ref="draw" class="draw"></div> </div> </template> ``` 接下来,在Vue组件的mounted钩子函数初始化地图和绘图控件: ```javascript mounted() { // 初始化地图 const map = new Map({ target: this.$refs.map, layers: [ new TileLayer({ source: new OSM() }) ], view: new View({ center: [0, 0], zoom: 2 }) }); // 初始化绘图控件 const source = new VectorSource(); const vector = new VectorLayer({ source: source, style: new Style({ fill: new Fill({ color: 'rgba(255, 255, 255, 0.2)' }), stroke: new Stroke({ color: '#ffcc33', width: 2 }), image: new CircleStyle({ radius: 7, fill: new Fill({ color: '#ffcc33' }) }) }) }); map.addLayer(vector); const draw = new Draw({ source: source, type: 'Circle' }); this.draw = draw; map.addInteraction(draw); const modify = new Modify({ source: source }); map.addInteraction(modify); const snap = new Snap({ source: source }); map.addInteraction(snap); } ``` 在这个例子,绘图控件使用了一个圆形绘图,通过Draw交互器实现,使用Modify和Snap交互器进行修改和捕捉。 最后,可以通过Vue的方法来控制绘图控件的启停,例如在一个按钮的点击事件: ```javascript methods: { startDraw() { this.draw.setActive(true); }, stopDraw() { this.draw.setActive(false); } } ``` 这样就可以实现一个自定义绘图控件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值