首页 / 浏览问题 / 云GIS / 问题详情
矢量切片叠加在wmts上不显示问题
3EXP 2017年03月08日
var bool = false;//测试时只修改该值,以进入不同判断
if(bool)
{
    tiandituLayer = new SuperMap.Layer.Tianditu();
    //tianMarkerLayer = new SuperMap.Layer.Tianditu();
    //tianMarkerLayer.layerType="cva";
    //tianMarkerLayer.isLabel=true;
}
else
{
    var matrixIds_baselayer = ['1','2','3','4','5', '6','7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'];
    var resolutions_baselayer = [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, 8.58306884765625e-005, 4.291534423828125e-005, 2.1457672119140625e-005, 1.0728836059570313e-005, 5.3644180297851563e-006, 2.6822090148925781e-006, 1.3411045074462891e-006];
    var baselayer_vec_options = {
        name: "baselayer_vec",
        url: "http://t1.tianditu.com/vec_c/wmts",
        layer: "vec",
        style: "default",
        format: "tiles",
        matrixIds: matrixIds_baselayer,
        matrixSet: "c",
        buffer: 0,
        resolutions: resolutions_baselayer
    };
    tiandituLayer = new SuperMap.Layer.WMTS(baselayer_vec_options);
}
//vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
cartoCss=document.getElementById("cartoCssStr").text;
var hightLightCartoCss=document.getElementById("textData").text;
layer = new SuperMap.Layer.TiledVectorLayer("China", url,{cacheEnabled:true,returnAttributes:true},{useLocalStorage:true,cartoCss:cartoCss,donotNeedServerCartoCss:true,highLightCartoCss:hightLightCartoCss});
map.addLayers([tiandituLayer,layer]);

当我使用tiandituLayer = new SuperMap.Layer.Tianditu();时,TiledVectorLayer就可以显示,使用WMTS的时候,图层就不显示了。。但是也会去请求tilefeature.json,但是都是空值。。这是为什么。。难道是我数据问题?

1个回答

只有WMTS地图能出来么?
另外,坐标系一样么?全幅范围有冲突么?

1,780EXP 2017年03月08日
用wmts时候出不来~用tianditu就出的来,wmts也是调的天地图,坐标系应该是用arcgis转的2000吧,但是转的成功不成功就不太确定了,但layer.tianditu看得到啊…

关于范围我是直接setcenter到同一个位置,所以应该不是超出范围问题,还把mouseposition开起来经纬度没差~

现在主要是奇怪用layer.tianditu就可以看到矢量切片,不过也要缩放一下才会看到矢量切片…但是用wmts调用天地图就完全不显示矢量图层了…

TiledVectorLayer用异步加载试试

似乎没用,我将两个示例的代码合并,会出现先加载谁另一个就不加载的情况。

http://localhost:8090/iserver/iClient/forJavaScript/examples/examples.html#tiledVectorLayer

http://localhost:8090/iserver/iClient/forJavaScript/examples/examples.html#wmtsLayer

附代码:

<script type="text/javascript">
var map, layer,layer2, lat, lon, geolocate, infowin,lonLat,geometryInfo, host = document.location.toString().match(/file:\/\//) ? "http://localhost:8090" : 'http://' + document.location.host;
url = host + "/iserver/services/map-china400/rest/maps/China";
url2 = host + "/iserver/services/map-world/wmts100";

function init() {
if(!document.createElement('canvas').getContext) {
alert('您的浏览器不支持 canvas,请升级');
return;
}

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];
//新建图层
layer2 = new SuperMap.Layer.WMTS({name: "World",
url: url2,
layer: "World",
style: "default",
matrixSet: "GlobalCRS84Scale_World",
format: "image/png",
resolutions:resolutions,
matrixIds:matrixIds,
opacity: 1,
requestEncoding:"KVP"});

layer = new SuperMap.Layer.TiledVectorLayer("China", url,{cacheEnabled:true,returnAttributes:true},{useLocalStorage:true});
layer.events.on({"layerInitialized": addLayer});
}

function addLayer() {
map.addLayers([layer,layer2]);

//map.addLayers([layer2,layer]);//换为先添加layer2就不加载layer,先添加layer就不加载layer2
var center = new SuperMap.LonLat(0,0);
map.setCenter(center, 1);
}

</script>

那么我只能想到这来服务固定的比例尺不一样了,你输出下俩图层对象的比例尺对比下
或者把TiledVectorLayer的resolutionsscales属性写上,在构造函数第四个参数

resolutions应该是由添加的第一个图层决定的,我用tianditu作为第一个图层,resolutions就是0-16,用我自己建立var resolutions (Array[20]),那就是0-19。

我做了个测试,什么都不修改,一个tianditulayer,一个wmtslayer,一个tilevectorlayer,

map.addlayer(tianditu,wmts,tilevector) 可以显示矢量切片,wmts,和tianditu,但是级别只到17,没法到wmts的最大级别20(天地图地区最大级别是20级)

map.addlayer(wmts,tianditu,tilevector) 可以显示wmts,和tianditu,缩放级别可以到20,但是无法显示矢量切片,tileFeature.json的返回值是{"recordsets":[]}

比例尺确实是按第一个加的图层来的,按理说俩都设置一样的比例尺就没问题,tilevectorlayer的比例尺应该是连续的,也就是任何比例尺都可以,我先试试

好~您可以试试自带的那两个示例叠加,话说SuperMap.Layer.Tianditu难道不是将SuperMap.Layer.WMTS扩展一下么,或者您那边试试矢量和wmts叠加吧。。如果可以我这边再找找问题。

看了下是scales计算得不一样,直接用WMTS对接,反算出来的scales和SuperMap.Layer.Tianditu的scales不一样,这个服务地址("http://t1.tianditu.com/vec_c/wmts")不填分辨率等参数也能出来的,如下。

layer = new SuperMap.Layer.WMTS({
                name: "baselayer_vec",
                url: "http://t1.tianditu.com/vec_c/wmts",
                layer: "vec",
                style: "default",
                matrixSet: "c",
                format: "tiles"
            });

你们是要天地图20级比例尺么?可以用别的办法搞定
iClient js\examples\js\layer\Tianditu.js就是SuperMap.Layer.Tianditu的源码,可以改setTiandituParam方法里的resLen和numZoomLevels变量让它显示20级
setTiandituParam:function(projection){
        var lt = this.layerType;
        if(lt=="vec"){
            var resLen = 17;
            var resStart = 0;
            this.zOffset = 1;
            this.numZoomLevels = 17;
        }
        else if(lt=="img"){
            var resLen = 17;
            var resStart = 0;
            this.zOffset = 1;
            this.numZoomLevels = 17;
        }
        else if(lt=="ter"){
            var resLen = 13;
            var resStart = 0;
            this.zOffset = 1;
            this.numZoomLevels = 13;
        }

...

改后,在SuperMap.Include.js之后引用这个js,或者直接SuperMap.Layer.Tianditu.prototype.setTiandituParam=function(projection){}重写这个方法,下次new的就是20级比例尺的了

好的,也算是一种解决办法~我试试~谢谢!
...