首页 / 浏览问题 / 云GIS / 问题详情
addLayer加载wmts图层
44EXP 2017年04月20日
您好,请教一下这个问题

我的需求:

将两幅地图发布成wmts服务,并且做底图的切换

wmtsLayer.events.on({
         "layerInitialized": addLayer
     });

function addLayer(){

}

将addLayer方法写完后,地图没有加载进来,并且在报wrapDateLine的错误

但是使用map.addLayers就可以加载进来

求大神帮忙

2 个回答

您好,您能否将您的完整的代码贴上来,我好进一步分析。
1,695EXP 2017年04月20日
恩恩,好嘞,您看看iserver自带的例子,我昨天试了一下,将iserver例子修改了一下也是不行

这个是iserver中自带的例子(例子名字叫:wmtsLayer.html)源码:

<!DOCTYPE>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>WMTS图层</title>
        <style type="text/css">
            body{
                margin: 0;
                overflow: hidden;
                background: #fff;
            }
            #map{
                position: relative;
                height: 553px;
                border:1px solid #3473b7;
            }
        </style>
        <link href='./css/bootstrap.min.css' rel='stylesheet' />
        <link href='./css/bootstrap-responsive.min.css' rel='stylesheet' />
        <script src='../libs/SuperMap.Include.js'></script>
        <script type="text/javascript">
            var map, layer,
            host = document.location.toString().match(/file:\/\//)?"http://localhost:8090":'http://' + document.location.host,
            url=host+"/iserver/services/map-world/wmts100";
            function init(){
                map = new SuperMap.Map("map",{controls: [
                    new SuperMap.Control.ScaleLine(),
                    new SuperMap.Control.Zoom(),
                    new SuperMap.Control.Navigation({
                        dragPanOptions: {
                            enableKinetic: true
                        }
                    })]
                });

                //wmts或许所需要的matrixID信息
                var matrixIds = [];
                for (var i=0; i<22; ++i) {
                    matrixIds[i] = {identifier:i};
                };
                //当前图层的分辨率数组信息,和matrixIds一样,需要用户从wmts服务获取并明确设置,resolutions数组和matrixIds数组长度相同
                var resolutions = [1.25764139776733,0.628820698883665,0.251528279553466,
                    0.125764139776733,0.0628820698883665,0.0251528279553466,
                    0.0125764139776733,0.00628820698883665,0.00251528279553466,
                    0.00125764139776733,0.000628820698883665,0.000251528279553466,
                    0.000125764139776733,0.0000628820698883665,0.0000251528279553466,
                    0.0000125764139776733, 0.00000628820698883665,0.00000251528279553466,
                    0.00000125764139776733,0.000000628820698883665,0.000000251528279553466];
                //新建图层
                layer = new SuperMap.Layer.WMTS({name: "World",
                    url: url,
                    layer: "World",
                    style: "default",
                    matrixSet: "GlobalCRS84Scale_World",
                    format: "image/png",
                    resolutions:resolutions,
                    matrixIds:matrixIds,
                    opacity: 1,
                    requestEncoding:"KVP"});

                //图层添加并显示指定级别
                map.addLayers([layer]);
                map.setCenter(new SuperMap.LonLat(0, 0), 2);
            }
        </script>
    </head>
    <body onload="init()">
        <div id="map"></div>
    </body>
</html>

我的修改:

<!DOCTYPE>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>WMTS图层</title>
        <style type="text/css">
            body{
                margin: 0;
                overflow: hidden;
                background: #fff;
            }
            #map{
                position: relative;
                height: 553px;
                border:1px solid #3473b7;
            }
        </style>
        <link href='./css/bootstrap.min.css' rel='stylesheet' />
        <link href='./css/bootstrap-responsive.min.css' rel='stylesheet' />
        <script src='../libs/SuperMap.Include.js'></script>
        <script type="text/javascript">
            var map, layer,
            host = document.location.toString().match(/file:\/\//)?"http://localhost:8090":'http://' + document.location.host,
            url=host+"/iserver/services/map-world/wmts100";
            function init(){
                map = new SuperMap.Map("map",{controls: [
                    new SuperMap.Control.ScaleLine(),
                    new SuperMap.Control.Zoom(),
                    new SuperMap.Control.Navigation({
                        dragPanOptions: {
                            enableKinetic: true
                        }
                    })]
                });

                //wmts或许所需要的matrixID信息
                var matrixIds = [];
                for (var i=0; i<22; ++i) {
                    matrixIds[i] = {identifier:i};
                };
                //当前图层的分辨率数组信息,和matrixIds一样,需要用户从wmts服务获取并明确设置,resolutions数组和matrixIds数组长度相同
                var resolutions = [1.25764139776733,0.628820698883665,0.251528279553466,
                    0.125764139776733,0.0628820698883665,0.0251528279553466,
                    0.0125764139776733,0.00628820698883665,0.00251528279553466,
                    0.00125764139776733,0.000628820698883665,0.000251528279553466,
                    0.000125764139776733,0.0000628820698883665,0.0000251528279553466,
                    0.0000125764139776733, 0.00000628820698883665,0.00000251528279553466,
                    0.00000125764139776733,0.000000628820698883665,0.000000251528279553466];
                //新建图层
                layer = new SuperMap.Layer.WMTS({name: "World",
                    url: url,
                    layer: "World",
                    style: "default",
                    matrixSet: "GlobalCRS84Scale_World",
                    format: "image/png",
                    resolutions:resolutions,
                    matrixIds:matrixIds,
                    opacity: 1,
                    requestEncoding:"KVP"});

                //图层添加并显示指定级别

               layer.events.on({
                    "layerInitialized": addLayer
                });
            }

            function addLayer(){

                map.addLayers([layer]);
                map.setCenter(new SuperMap.LonLat(0, 0), 2);

         }
        </script>
    </head>
    <body onload="init()">
        <div id="map"></div>
    </body>
</html>

只改动了添加图层的地方
您这里的WMTS的layer并不需要进行异步加载,直接加载即可。

你好,只有在使用SuperMap.Layer.TiledDynamicRESTLayer添加地图图层时,需要用异步加载的方式;添加其他地图图层直接加载即可。

建议参考一下类参考:

1、关于SuperMap.Layer.WMTS,可参考:

http://support.supermap.com.cn:8090/iserver/iClient/forJavaScript/apidoc/files/SuperMap/Layer/WMTS-js.html

2、关于SuperMap.Layer.TiledDynamicRESTLayer,可参考:

http://support.supermap.com.cn:8090/iserver/iClient/forJavaScript/apidoc/files/SuperMap/Layer/TiledDynamicRESTLayer-js.html

2EXP 2017年04月20日
...