欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

天地图二次开发

程序员文章站 2022-07-02 09:48:49
...
<!DOCTYPE html>
<html>
  <head>
    <title>Accessible Map</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v4.3.1/css/ol.css" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script src="https://openlayers.org/en/v4.3.1/build/ol.js"></script>
    <style>
     #map {
      position: absolute;
      width: 100%;
      height: 100%;
      overflow: hidden;
      left: 0;
      top: 0;
    }
    </style>
    
  </head>
  <body>
    <div id="map" class="map" tabindex="0"></div>
    <script>
        var projection = ol.proj.get("EPSG:4326");
        var projectionExtent = projection.getExtent();

        var res = [
  1.40625,
  0.703125,
  0.3515625,
  0.17578125,
  0.087890625,
  0.0439453125,
  0.02197265625,
  0.010986328125,
  0.0054931640625,
  0.00274658203125,
  0.001373291015625,
  0.0006866455078125,
  0.00034332275390625,
  0.000171661376953125,
  0.0000858306884765625,
  0.00004291534423828125,
  0.000021457672119140625,
  0.000010728836059570312
];

        var map = new ol.Map({
            layers: [
    new ol.layer.Tile({
        source: new ol.source.WMTS({
            name: "中国矢量1-4级",
            url: "http://t{0-6}.tianditu.com/img_c/wmts",
            layer: "img",
            style: "default",
            matrixSet: "c",
            format: "tiles",
            wrapX: true,
            tileGrid: new ol.tilegrid.WMTS({
                origin: ol.extent.getTopLeft(projectionExtent),
                resolutions: res.slice(0, 15),
                matrixIds: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
            })
        }),
        minResolution: 0.00004291534423828125,
        maxResolution: 1.40625
    }),
    new ol.layer.Tile({
        source: new ol.source.WMTS({
            name: "中国矢量注记1-4级",
            url: "http://t{0-6}.tianditu.com/cia_c/wmts",
            layer: "cia",
            style: "default",
            matrixSet: "c",
            format: "tiles",
            wrapX: true,
            tileGrid: new ol.tilegrid.WMTS({
                origin: ol.extent.getTopLeft(projectionExtent),
                resolutions: res.slice(0, 15),
                matrixIds: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
            })
        }),
        minResolution: 0.00004291534423828125,
        maxResolution: 1.40625
    }),
    new ol.layer.Tile({
        source: new ol.source.WMTS({
            name: "浙江矢量15-17级",
            url: "http://srv{0-6}.zjditu.cn/ZJDOM_2D/wmts",
            layer: "imgmap",
            style: "default",
            matrixSet: "TileMatrixSet0",
            format: "image/png",
            wrapX: true,
            tileGrid: new ol.tilegrid.WMTS({
                origin: ol.extent.getTopLeft(projectionExtent),
                resolutions: res.slice(15, 18),
                matrixIds: [15, 16, 17]
            })
        }),
        minResolution: 0.000005364418029785156,
        maxResolution: 0.0000858306884765625
    }),
    new ol.layer.Tile({
        source: new ol.source.WMTS({
            name: "浙江矢量注记15-17级",
            url: "http://srv{0-6}.zjditu.cn/ZJEMAPANNO_2D/wmts",
            layer: "TDT_ZJIMGANNO",
            style: "default",
            matrixSet: "TileMatrixSet0",
            format: "image/png",
            wrapX: true,
            tileGrid: new ol.tilegrid.WMTS({
                origin: ol.extent.getTopLeft(projectionExtent),
                resolutions: res.slice(15, 18),
                matrixIds: [15, 16, 17]
            })
        }),
        minResolution: 0.000005364418029785156,
        maxResolution: 0.0000858306884765625
    })
  ],
            target: "map",
            view: new ol.View({
                center: [120.14805, 30.26971],
                projection: projection,
                zoom: 7,
                maxZoom: 17,
                minZoom: 1
            })
        });

    </script>
  </body>
</html>