maplibre自定义样式和图层

1.整合到一个html文件的源码

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Custom Map Style with Data</title>
    <meta charset='utf-8'>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel='stylesheet' href='https://unpkg.com/maplibre-gl@3.3.0/dist/maplibre-gl.css' />
    <script src='https://unpkg.com/maplibre-gl@3.3.0/dist/maplibre-gl.js'></script>
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        html,
        body,
        #map {
            height: 100%;
        }
    </style>
</head>

<body>
    <div id="map"></div>
    <script>
        var mapStyle = {
            "version": 8,
            "name": "Custom Map Style with Raster Data",
            "sources": {
                "custom-raster": {
                    "type": "raster",
                    "tiles": ["http://127.0.0.1:8080/geoserver/ne/gwc/service/wmts?layer=ne%3Aworld&style=&tilematrixset=EPSG%3A900913&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fpng&TileMatrix=EPSG%3A900913%3A{z}&TileCol={x}&TileRow={y}"],
                    "tileSize": 256
                }
            },
            "layers": [
                {
                    "id": "custom-raster-layer",
                    "type": "raster",
                    "source": "custom-raster"
                }
            ]

        };

        var map = new maplibregl.Map({
            container: 'map',
            style: mapStyle,
            center: [116, 40],
            zoom: 1
        });

        map.on('load', () => {
            map.addSource('railways', {
                type: 'vector',
                // Use any Mapbox-hosted tileset using its tileset id.
                // Learn more about where to find a tileset id:
                // https://docs.mapbox.com/help/glossary/tileset-id/
                // url: 'mapbox://mapbox.mapbox-terrain-v2'
                tiles: ['http://127.0.0.1:8080/geoserver/maplibre/gwc/service/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&LAYER=maplibre:gis_osm_railways_free_1&STYLE=&TILEMATRIX=EPSG:900913:{z}&TILEMATRIXSET=EPSG:900913&FORMAT=application/vnd.mapbox-vector-tile&TILECOL={x}&TILEROW={y}'],
                'minZoom': 0,
                'maxZoom': 14,

            });
            map.addLayer({
                'id': 'my_layer',
                'type': 'line',
                'source': 'railways',
                'source-layer': 'gis_osm_railways_free_1',
                'layout': {
                    'line-join': 'round',
                    'line-cap': 'round'
                },
                'paint': {
                    'line-color': '#ff69b4',
                    'line-width': 1
                }
            });

        });
    </script>
</body>

</html>

2.maplibre与Vue相结合

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值