首页 / 浏览问题 / 桌面GIS / 问题详情
UTFGrid回调函数传入参数.id .data没值
33EXP 2016年11月20日
在执行UTFGrid控件回调函数时传入的参数infoLookup.id,infoLookup.data没值

url="http://localhost:8090/iserver/services/map-china400/rest/maps/China";
            function init(){
                map = new SuperMap.Map("map", {controls: [
                    new SuperMap.Control.ScaleLine(),
                    new SuperMap.Control.Zoom(),
                    new SuperMap.Control.LayerSwitcher(),
                    new SuperMap.Control.Navigation({
                        dragPanOptions: {
                            enableKinetic: true
                        }
                    })],
                    projection: "EPSG:3857"
                });

                layer = new SuperMap.Layer.TiledDynamicRESTLayer("China", url, {transparent: true}, {useCanvas: true, maxResolution: "auto"});

                //注意:pixcell与utfgridResolution两个属性有对应关系,在使用的时候也要注意场景;
                //1.其中pixcell为发送给服务端请求utfgrid瓦片的精度,数值越小,精度越高,相应的瓦片大小也就越大;
                //2.utfgridResolution为客户端解析瓦片使用的精度,应该与pixcell的值相等,否则会产生位置与属性对应不上的问题;
                //3.通常如果UTFGrid图层为面图层,对应的数据量会比较大,为了不影响页面的正常浏览,可以将这两个属性设的大一些;
                //4.isUseCache设置是否使用缓存,使用缓存能够提高性能;
                utfgrid = new SuperMap.Layer.UTFGrid("UTFGridLayer", url,
                        {
                            layerName: "China_Province_R@China",
                            utfTileSize: 256,
                            pixcell: 8,
                            isUseCache: true
                        },
                        {
                            utfgridResolution: 8
                        });

                layer.events.on({"layerInitialized": addLayer});
                control = new SuperMap.Control.UTFGrid({
                    layers: [utfgrid],
                    callback: callback,
                    handlerMode: "move"
                });
                map.addControl(control);
            }
   
            var callback = function (infoLookup,loc, pixel) {
                closeInfoWin();
                if (infoLookup) {
                    var info;
                    for (var idx in infoLookup) {
                        info = infoLookup[idx];
                        if (info && info.data) {
                            var dom = "<div style='font-size: 12px; color: #000000;'>" + info.data.NAME + "</div>";
                            //设置x与y的像素偏移量,不影响地图浏览;
                            var xOff = (1 / map.getScale()) * 0.001;
                            var yOff = -(1 / map.getScale()) * 0.005;
                            var pos = new SuperMap.LonLat(loc.lon+xOff, loc.lat+yOff);
                            infowin = new SuperMap.Popup("chicken",
                                    pos,
                                    new SuperMap.Size(100, 20),
                                    dom,
                                    false, null);
                            infowin.autoSize=true;
       //infowin.setBackgroundColor("#FD1715");
                            map.addPopup(infowin);
                        }
                    }
                }
            };

2 个回答

1.addLayer方法里加上,utfgrid.maxExtent=layer.maxExtent,
2.先把move改成click,在要素上点击查看是否有值,避免鼠标移出时在无值区域,导致看到的后面的输出都是无值
3.还未生效,检查比例尺,地图是否固定比例尺、UTFGrid是否预缓存,可以在addlayer方法加上,utfgrid.scales=layer.scales

毛瑞
2
1,780EXP 2016年11月21日

​我的是云南地图,要怎么设置maxExtent,调试是null

找到iServer REST服务地址那里会有显示全幅范围
或者TiledDynamicRESTLayer异步加载完成后(addlayer方法里),TiledDynamicRESTLayer图层对象会带这个属性,可以addlayer方法里console.log(layer)查看

谢谢,加上maxExtent就出来了
设置一下map的maxExtent,即地图的全幅范围,以及设置map的projection,坐标系的EPSG
1,615EXP 2016年11月21日

这个EPSG要怎么来设置,我的是云南地图,之前没设置过,但在iServer中发布后里面有4326和3857两个

你的地图是什么坐标系,就设置什么,是WGS84的就是4326,是墨卡托投影坐标系,就设置3857
地图是什么坐标系,要怎么看
...