基于 supermap 服务的 leaflet + 4490坐标系(国家2000)
版本 目前的最新版 “@supermap/iclient-leaflet”: “^11.1.1”, “leaflet”: “^1.9.4”,
引用
1
2
3
4
5
import { tiledMapLayer } from '@supermap/iclient-leaflet'
import 'leaflet/dist/leaflet.css'
import * as L from 'leaflet'
const PROJ4 = proj4 // proj4 在 leaflet 是全局函数
- 初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const defs = PROJ4.defs(
'EPSG:4490',
'+proj=longlat +ellps=GRS80 +no_defs'
) // https://epsg.io/ 来源这个
const crs = L.Proj.CRS('EPSG:4490', {
def: defs,
// 这几个参数可以不按照显示顺序书写,scales参数官网说明为比例尺数组,但是根据官网书写会报错
/**
* 起点和比例尺表参数必须填写,设置origin参数才能正确计算切片的位置,设置比例尺表才能在地图初始化时设置
* 缩放级别,而zoom参数是生成地图必填参数
*/
origin: [-180, 90],
// scales: 0.00000100000,
// scales: [0.00000100000],
// 比例尺因子
// scaleDenominators: [1000000, 500000, 250000, 125000, 62500, 31250, 15625, 7812, 3906, 1953],
// 分辨率数组
resolutions: [
1.40625, 0.703125, 0.3515625, 0.17578125, 0.087890625, 0.0439453125,
0.02197265625, 0.010986328125, 0.0054931640625, 0.00274658203125,
0.001373291015625, 6.866455078125e-4, 3.4332275390625e-4,
1.71661376953125e-4, 8.58306884765625e-5, 4.291534423828125e-5,
// eslint-disable-next-line no-loss-of-precision
2.1457672119140625e-5, 1.0728836059570312e-5, 5.364418029785156e-6,
2.682209064925356e-6, 1.3411045324626732e-6
]
})
this.map = L.map('allmap', {
crs: crs,
center: [31.990397, 119.936871],
maxZoom: 18,
minZoom: 10,
rotate: true,
bearing: 45,
zoom: 16,
preferCanvas: true,
attributionControl: false, //去掉右下角logo
zoomControl: false //缩放组件
})
tiledMapLayer(import.meta.env.VITE_APP_MAP_SERVER).addTo(this.map)
This post is licensed under CC BY 4.0 by the author.