首页 / 浏览问题 / 其他 / 问题详情
将天地图作为底图添加到图层后普通图层不显示也不报错
7EXP 2019年03月21日

使用产品:iserver 8c 810 操作系统:win10 x64 

<!DOCTYPE HTML>
<html>

<head>   
    <title>SuperMap iClient for JavaScript:TiledDynamicRESTLayer</title>
    <!--引用需要的脚本-->
    <script src="./libs/SuperMap.Include.js"></script>
    <script type="text/javascript">
    //声明变量map、layer、url
    var map, layer,tiandituLayer ,
    url = "http://10.220.105.185:8100/iserver/services/map-PDV2WB/rest/maps/LXGGHD",
	WMTSLayer, WMTSLayer2;
    //创建地图控件
   function init(){
    //初始化地图
    map = new SuperMap.Map('map');	
// 天地图图层
 WMTSLayer = new SuperMap.Layer.WMTS({
			name: "vec", //自定义图层名称
			url: "http://t0.tianditu.gov.cn/vec_c/wmts?tk=我的tk", //wmts服务地址
			layer: "vec",  //服务中的图层名称
			style: "default",  //风格描述
			matrixSet: "c",  //标识符矩阵集
			format: "tiles",  //瓦片格式 
			isBaseLayer: true, // 图层是否为基础图层,默认为true。
			requestEncoding: "KVP",
			opacity: 1,
			//resolutions: resolutions,
			matrixIds: [],
			tileOrigin: new SuperMap.LonLat(-180, 90), //切图原点,天地图标准都是(-180,,90)
			tileSize: new SuperMap.Size(256,256) //瓦片大小
		});
		// 天地图图层
	 WMTSLayer2 = new SuperMap.Layer.WMTS({
		name: "cva", //自定义图层名称
		url: "http://t0.tianditu.gov.cn/cva_c/wmts?tk=我的tk", //wmts服务地址
		layer: "cva",  //服务中的图层名称
		style: "default",  //风格描述
		matrixSet: "c",  //标识符矩阵集
		format: "tiles",  //瓦片格式 
		isBaseLayer: false, // 图层是否为基础图层,默认为true。
		requestEncoding: "KVP",
		opacity: 1,
		//resolutions: resolutions,
		matrixIds: [],
		tileOrigin: new SuperMap.LonLat(-180, 90), //切图原点,天地图标准都是(-180,,90)
		tileSize: new SuperMap.Size(256,256), //瓦片大小
		
	});
	//初始化图层
    //layer = new SuperMap.Layer.TiledVectorLayer("LXGGHD", url, null, {maxResolution:"auto"});
    layer = new SuperMap.Layer.TiledDynamicRESTLayer("LXGGHD", url, null, {maxResolution:"auto"});
    layer.events.on({"layerInitialized":addLayer});
	
		//map.addLayers([WMTSLayer2]);  //添加图层到地图中
		//map.setCenter(new SuperMap.LonLat(0,0), 20);  //设置底图中心点和缩放级别

    
	
     //addLayer();
}
	function addLayer(){
		map.addLayers([WMTSLayer,WMTSLayer2]);  //添加图层到地图中
		map.addLayer(layer);
		//显示地图范围
		map.setCenter(new SuperMap.LonLat(121.475830,31.210450), 11);
		 
	}
     
    </script>
</head>
<body onload="init()">
    <!--地图显示的div -->
	
    <div id="map" style="position:absolute;left:0px;right:0px;width:98%;height:98%;" >             
    </div>    
</body>
</html>

不添加这一行时 map.addLayers([WMTSLayer,WMTSLayer2,layer]);  //添加图层到地图中

可以展示出

添加 map.addLayers([WMTSLayer,WMTSLayer2]);

后无法显示上面那个图层了

 2中图层单独添加均正常出现图层

同时添加无法出现带线的图层

2 个回答

你好,可能是因为你的底图覆盖你当前的普通地图图层,你可以先使用map.getLayerIndex()方法查看图层 当前的索引值,然后在通过map.setLayerIndex()来改变除底图的其他图层的z-index值

或者是你改一下map.addLayers([])里面的加载顺序

3,357EXP 2019年03月22日
没有用的
私信发你的qq我加你 我看看
好了不用了已经解决了
<!DOCTYPE HTML>
<html>

<head>   
    <title>SuperMap iClient for JavaScript:TiledDynamicRESTLayer</title>
    <!--引用需要的脚本-->
    <script src="./libs/SuperMap.Include.js"></script>
    <script src="./layer/Tianditu.js"></script>
    <script type="text/javascript">
    //声明变量map、layer、url
    var map, layer,tiandituLayer ,
    url = "http://loclhost:8100/iserver/services/map-PDV2WB/rest/maps/LXGGHD",
	WMTSLayer, WMTSLayer2,  tiandituLayer , tianMarkerLayer;
    //创建地图控件
   function init(){
    //初始化地图
    map = new SuperMap.Map('map', {controls:[
            new SuperMap.Control.Navigation() ,
            new SuperMap.Control.Zoom(),
            new SuperMap.Control.LayerSwitcher()

        ], allOverlays: true});	
	
		name: "cva", //自定义图层名称
		url: "http://t0.tianditu.gov.cn/cva_c/wmts?tk=8c8423722d0791e18dc8b9866b71a96f", //wmts服务地址
		layer: "cva",  //服务中的图层名称
		style: "default",  //风格描述
		matrixSet: "c",  //标识符矩阵集
		format: "tiles",  //瓦片格式 
		isBaseLayer: false, // 图层是否为基础图层,默认为true。
		requestEncoding: "KVP",
		opacity: 1,
		//resolutions: resolutions,
		matrixIds: [],
		tileOrigin: new SuperMap.LonLat(-180, 90), //切图原点,天地图标准都是(-180,,90)
		tileSize: new SuperMap.Size(256,256), //瓦片大小
		
	});
	tiandituLayer = new SuperMap.Layer.Tianditu();
         tianMarkerLayer = new SuperMap.Layer.Tianditu();
        tianMarkerLayer.layerType="cva";
        tianMarkerLayer.isLabel=true;
        map.addControl(new SuperMap.Control.MousePosition());
        
		
	//初始化图层
	var  options = {
            projection:"EPSG:4326",
            maxExtent: new SuperMap.Bounds(121.467391159432,30.845632378681,121.963621370315,31.381153363854),
            resolutions: [0.703125,0.35156249999999994, 0.17578124999999997, 0.08789062500000014, 0.04394531250000007,
                0.021972656250000007, 0.01098632812500002, 0.00549316406250001, 0.0027465820312500017, 0.0013732910156250008,
                0.000686645507812499, 0.0003433227539062495, 0.00017166137695312503, 0.00008583068847656251, 0.000042915344238281406, 0.000021457672119140645,
                0.000010728836059570307, 0.00000536441802978516]
        };
   layer = new SuperMap.Layer.TiledDynamicRESTLayer("Mapssd沙发", url, {transparent: true}, options);
   //layer = new SuperMap.Layer.Vector("LXGGHD", url, {}, {maxResolution:"auto"});
    //layer = new SuperMap.Layer.TiledDynamicRESTLayer("LXGGHD", url, 	null, {maxResolution:"auto", overlapDisplayed: false});
    layer.events.on({"layerInitialized":addLayer});
	
	//map.addLayers([WMTSLayer2]);  //添加图层到地图中 tk=8c8423722d0791e18dc8b9866b71a96f&
	//map.setCenter(new SuperMap.LonLat(0,0), 20);  //设置底图中心点和缩放级别
	//addLayer()
	
}
	function addLayer(){
		//map.addLayers([WMTSLayer,WMTSLayer2, layer]);  //添加图层到地图中
		map.addLayers([tiandituLayer,tianMarkerLayer]);
		 map.addLayers([layer]);
		//显示地图范围
		map.setCenter(new SuperMap.LonLat(121.475830,31.210450), 11);
		 
	}
     
    </script>
</head>
<body onload="init()">
    <!--地图显示的div -->
	
    <div id="map" style="position:absolute;left:0px;right:0px;width:98%;height:98%;" >             
    </div>    
</body>
</html>

完整代码,已解决

7EXP 2019年03月22日
...