Skip to content

其他 ​

OGC标准服务图层(WMTS,WMS, WFS) ​


一. 添加WMS

javascript
map.addSource('wms-test-source', {
    'type': 'raster',
    'tiles': [
        // 需要服务器端添加cors相关response header
        // Access-Control-Allow-Origin: *
        'http://localhost:8080/geoserver/word/wms?service=WMS&version=1.1.0&request=GetMap&layers=word:town3857&styles=&bbox={bbox-epsg-3857}&width=256&height=256&srs=EPSG:3857&format=image/png&TRANSPARENT=TRUE'
    ],
    'tileSize': 256
});

map.addLayer({
        'id': 'wms-test-layer',
        'type': 'raster',
        'source': 'wms-test-source',
        'paint': {}
});

二. 添加WMTS

javascript
// WMTS 服务地址
var vectorLayerUrl = "http://localhost:8088/geoserver/gwc/service/wmts?"+
                    "REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&LAYER=cite:town" +
                    "&STYLE=&TILEMATRIX=EPSG:900913:{z}&TILEMATRIXSET=EPSG:900913&" +
                    "FORMAT=application/vnd.mapbox-vector-tile&TILECOL={x}&TILEROW={y}"
map.addLayer({
    "id":"tms-test",
    "type": "line",
    'source': {
        'type': 'vector',
        'tiles': [
            vectorLayerUrl
        ]
    },
    "source-layer": "town",//图层名称
    "layout": {
        "line-join": "round",
        "line-cap": "round"
    },
    //样式
    "paint": {
        "line-color": "#E31A1C",
        "line-width": 3,
        "line-opacity": 0.9
    }
});

三. 添加WFS

​ sdk不直接支持WFS的加载。但开发者可在请求到WFS要素数据(GML)后,转换为GeoJSON格式后使用sdk提供的api叠加到地图上。

超图的地图服务 ​


javascript
var map = new SFMap.Map({
    container: 'map',
    style: {
        "version": 8,
        "sources": {
            "raster-tiles": {
                "type": "raster",
                "tiles": ['http://support.supermap.com.cn:8090/iserver/services/map-china400/rest/maps/China/zxyTileImage.png?z={z}&x={x}&y={y}'],
                "tileSize": 256
            }
        },
        "layers": [{
            "id": "simple-tiles",
            "type": "raster",
            "source": "raster-tiles",
            "minzoom": 0,
            "maxzoom": 22
        }]
    },
    center: [114.138947, 22.373061], // starting position
    zoom: 3 // starting zoom
});

深入使用可参考超图https://gitee.com/isupermap/iClient-JavaScript/tree/master/src/mapboxgl

互联网地图服务(百度、高德等) ​


高德

javascript
// 加载高德栅格底图
var map = new SFMap.Map({
    container: 'map', // container id
    style: {
        'version': 8,
        'sources': {
            'raster-tiles': {
                'type': 'raster',
                'tiles': [
                    // 高德底图
                    'http://webst03.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}'
                ],
                'tileSize': 256
            }
        },
        'layers': [
            {
                'id': 'simple-tiles',
                'type': 'raster',
                'source': 'raster-tiles',
                'minzoom': 0,
                'maxzoom': 22
            }
        ]
    },
    center: [114.138947, 22.373061], // starting position
    zoom: 12 // starting zoom
});

V3.2-202604301400