首页 / 浏览问题 / 其他 / 问题详情
如何添加2个layer?
1EXP 2017年06月16日

我是这么写的,但总是只能显示1个图层

1个回答

注意坐标系
 

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>图层叠加</title>
    <style type="text/css">
        #map {
            position: relative;
            height: 520px;
            border: 1px solid #3473b7;
        }
    </style>
    <script src="http://support.supermap.com.cn:8090/iserver/iClient/forJavaScript/libs/SuperMap.Include.js"></script>
    <script type="text/javascript">
        var map, layer,
            url = "http://support.supermap.com.cn:8090/iserver/services/map-world/rest/maps/World",
            urlJJ = "http://support.supermap.com.cn:8090/iserver/services/map-jingjin/rest/maps/京津地区地图";
        function init() {
            map = new SuperMap.Map("map", {
                controls: [
                    new SuperMap.Control.ScaleLine(),
                    new SuperMap.Control.Zoom(),
                    new SuperMap.Control.LayerSwitcher(),
                    new SuperMap.Control.MousePosition(),
                    new SuperMap.Control.Navigation({
                        dragPanOptions: {
                            enableKinetic: true
                        }
                    })], allOverlays: true
            });
            // map.allOverlays=true;
            layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, { transparent: true, cacheEnabled: true });
            layer.events.on({ "layerInitialized": addLayer });
        }
        function addLayer() {
            map.addLayer(layer);
            var jjLayer = new SuperMap.Layer.TiledDynamicRESTLayer("京津地区地图", urlJJ, { transparent: true, cacheEnabled: true },
                { resolutions: layer.resolutions });
            jjLayer.events.on({ "layerInitialized": function(){
                map.addLayers([layer,jjLayer]);
                map.setCenter(new SuperMap.LonLat(117.01, 40.04), 4);
            } });
        }
    </script>
</head>
<body onload="init()">
    <div id="map"></div>
</body>
</html>

加上LayerSwitcher看有没有添加上地图,或者浏览器控制台查看map对象。

1,780EXP 2017年06月16日
...