使用mapbox-gl有一段時間了,今天整理了一下地圖載入的程式碼段,比較簡單,就是方便以後貼程式碼而已。mapboxgl對地圖服務座標系的要求僅僅是EPSG:3857,也就是web墨卡託投影。如果你的地圖服務是此之外的座標系,你需要另找擴充套件或自己去寫外掛了。如果你使用的是cgcs2000(國家2000、4490)的座標系,可以參考下面這個擴充套件,本人測試過,geoserver釋出的向量切片、arcgis 柵格切片、arcgis 動態圖服務,都是可以的。
貼過來的程式碼、有修改,錯誤請指正,如果你也在用mapbox開發,可以交流學習一下。
1、
TMS
mapboxgl針對切片服務有兩種schema,一種是OGC標準的“xyz”切片原點在左上角,另一種是OSGeo的“tms”,切片原點在左下角。
geoserver向量切片:
{
“tiles”
:
[
“http://xxx/service/tms/1。0。0/NT_Z%3ANT_Z@EPSG%3A900913@pbf/{z}/{x}/{y}。pbf”
],
“type”
:
“vector”
,
“scheme”
:
“tms”
}
arcgis server 切片服務
{
type
:
‘raster’
,
tiles
:
[
‘https://wi。maptiles。arcgis。com/arcgis/rest/services/World_Imagery/MapServer
/tile/{z}/{y}/{x}’
],
tileSize
:
256
,
zoomOffset
:
-
1
}
2、
WMS(geoserver-3857/900913)
{
“type”
:
“raster”
,
“tiles”
:
[
“http://xxx/geoserver/CS_GX/wms?
SERVICE=WMS&
VERSION=1。1。1&
REQUEST=GetMap&
FORMAT=image/png&
TRANSPARENT=true&
LAYERS=CS_GX:dl_ld_pt&exceptions=application/vnd。ogc。se_inimage&
SRS=EPSG:3857&
STYLES=&WIDTH=256&HEIGHT=256&
BBOX={bbox-epsg-3857}”
],
“tileSize”
:
256
,
}
3、
WMS(arcgis-4490)
{
“type”
:
“raster”
,
“tiles”
:
[
“http://xxx/arcgis/rest/services/SYZLXDH/DJ_DYZS/MapServer/export?
dpi=96&
transparent=true&
format=png8&
WIDTH=256&
HEIGHT=256&
BBOX={bbox-epsg-4490}&f=image&SRS=EPSG:4490&layers=show:39”
],
“tileSize”
:
256
,
“zoomOffset”
:
-
1
}
}
4、
WMTS
參考這個地址的介紹:
{
‘type’
:
‘raster’
,
‘tiles’
:
[
‘https://900913。cn/geoserver/gwc/service/wmts?
REQUEST=GetTile&SERVICE=WMTS&
VERSION=1。0。0&
LAYER=buildings:Chongqing&
STYLE=&
TILEMATRIX=EPSG:900913:{z}&
TILEMATRIXSET=EPSG:900913&FORMAT=image/png&TILECOL={x}&TILEROW={y}’
// 或 geoserver rest 服務
// ‘https://900913。cn/geoserver/gwc/service/wmts/rest/buildings:
//Chongqing/polygon/EPSG:900913/EPSG:900913:{z}/{y}/{x}?format=image/png’
]
}
cgcs2000座標服務、arcgis tile、geoserver wms、arcgis dynamic
“arcgisTile”
:
{
type
:
‘raster’
,
tiles
:
[
‘https://wi。maptiles。arcgis。com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}’
],
tileSize
:
256
,
zoomOffset
:
-
1
},
“geoserverwms”
:
{
type
:
‘raster’
,
tiles
:
[
“http://ip:8080/geoserver/CS_GX/wms?SERVICE=WMS&VERSION=1。1。1&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&LAYERS=CS_GX:dl_ld_pt&exceptions=application/vnd。ogc。se_inimage&SRS=EPSG:4490&STYLES=&WIDTH=256&HEIGHT=256&BBOX={bbox-epsg-4490}”
],
tileSize
:
256
,
zoomOffset
:
-
1
},
“arcgisDynamic”
:
{
type
:
‘raster’
,
tiles
:
[
“http://ip:6080/arcgis/rest/services/SYZLXDH/ZQ_SZFD/MapServer/export?dpi=96&transparent=true&format=png8&bbox=&SRS=EPSG:4490&STYLES=&WIDTH=256&HEIGHT=256&f=imageBBOX={bbox-epsg-4490}”
],
tileSize
:
256
,
zoomOffset
:
-
1
},