首页 / 浏览问题 / 云GIS / 问题详情
classic在做空间矩形范围查询时,无法正确显示图层
xx
4EXP 2020年03月04日

在查询医院数据集时,在矩形框外的医院也被查询出来;

在查询公司等数据集时,显示查询目标不存在

1个回答

您好,您方便把您的代码能够在官网范例运行的代码发过来我看一下吗
5,668EXP 2020年03月05日
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title data-i18n="resources.title_queryByBounds"></title>
<style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
<div class='panel-heading'>
<h5 class='panel-title text-center' data-i18n="resources.title_queryByBounds"></h5></div>
<div class='panel-body content'>
<input type="button" class="btn btn-default" data-i18n="[value]resources.text_query" onclick="drawGeometry()"/>&nbsp;

<span style="width:95px;color:black;font-size:15px ;position:left"></span>
    <select id='QueryNames'>
            <option>医院</option>
            <option>公园</option>
            <option>学校</option>
            <option>公司</option>
           
        <\select>

<input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear" onclick="clearFeatures()"/>
</div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script>
    var map, local, layer, vectorLayer, control, queryBounds, markerLayer, drawFeature,
        style = {
            strokeColor: "#304DBE",
            strokeWidth: 1,
            pointerEvents: "visiblePainted",
            fillColor: "#304DBE",
            fillOpacity: 0.3
        },
        host = window.isLocal ? window.server : "https://iserver.supermap.io",
        url =host + "/iserver/services/map-changchun/rest/maps/长春市区图";
    init();

    function init() {
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })]
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("changchun", url, {
            transparent: true,
            cacheEnabled: true
        }, {maxResolution: "auto"});
        layer.events.on({"layerInitialized": addLayer});
        vectorLayer = new SuperMap.Layer.Vector("Vector Layer");//新建一个vectorLayer的矢量图层
        markerLayer = new SuperMap.Layer.Markers("Markers");//创建一个有标签的图层

        drawFeature = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Box, {"handlerOptions": {"cursorCSS": "crosshair"}});
        drawFeature.events.on({"featureadded": drawCompleted});
        map.addControl(drawFeature);
    }

    function addLayer() {
        map.addLayers([layer, vectorLayer, markerLayer]);
        map.setCenter(new SuperMap.LonLat(0, 0), 0);
    }

    function drawGeometry() {
        //先清除上次的显示结果
        clearFeatures();

        drawFeature.activate();
    }

    function drawCompleted(obj) {
        drawFeature.deactivate();
        var feature = obj.feature;
        feature.style = style;
        vectorLayer.addFeatures(feature);
        var queryBounds = feature.geometry.bounds;

/*根据用户绘制的几何对象,查询Hospital@Changchun等图层中,落在集合对象边界内的范围*/
        var queryParam, queryByBoundsParams, queryService;
      var QueryNamesSelect = document.getElementById("QueryNames");
      
    var QueryFieldName = QueryNamesSelect.options[QueryNamesSelect.selectedIndex].text;
   
        if(QueryFieldName=="医院"){
            
        /*FilterParameter(name):查询过滤条件参数类,该类用于设置查询数据集的查询过滤参数*/
       
            queryParam = new SuperMap.REST.FilterParameter({name: "Hospital@Changchun"});                                     }
                                                                   
             if(QueryFieldName=="公园"){
                queryParam=new SuperMap.REST.FilterParameter({name: "Park@Changchun"});
                                        }
                else if(QueryFieldName=="学校"){
                 queryParam=new SuperMap.REST.FilterParameter({name: "School@Changchun"});
                                            }
            else if(QueryFieldName=="公司"){
                 queryParam=new SuperMap.REST.FilterParameter({name: "Company@Changchun"});
                                            }
                                           
                queryByBoundsParams = new SuperMap.REST.QueryByBoundsParameters({
                         queryParams: [queryParam],
                         bounds: queryBounds
                                           });//queryParams查询过滤条件参数数组。bounds查询范围
                                           queryService = new SuperMap.REST.QueryByBoundsService(url, {
                                               eventListeners: {
                                                   "processCompleted": processCompleted,
                                                   "processFailed": processFailed
                                               }
                                           });
                                           queryService.processAsync(queryByBoundsParams);//向服务端传递参数,然后服务端返回对象
                               }
                               
                               
    function processCompleted(queryEventArgs) {
        var i, j, result = queryEventArgs.result, marker;//queryEventArgs服务端返回的对象
        if (result && result.recordsets) {
            for (i = 0, recordsets = result.recordsets, len = recordsets.length; i < len; i++) {
                if (recordsets[i].features) {
                    for (j = 0; j < recordsets[i].features.length; j++) {
                        var f = recordsets[i].features[j];
                        var point = f.geometry,
                            size = new SuperMap.Size(44, 33),
                            offset = new SuperMap.Pixel(-(size.w / 2), -size.h),
                            icon = new SuperMap.Icon("./images/marker.png", size, offset);
                        marker = new SuperMap.Marker(new SuperMap.LonLat(point.x, point.y), icon);
                        marker.name = f.attributes.name;
                        marker.events.on({
                            "click": openInfoWin,
                            "touchstart": openInfoWin,        //假如要在移动端的浏览器也实现点击弹框,则在注册touch类事件
                            "scope": marker
                        });
                        markerLayer.addMarker(marker);
                    }
                }
            }
        }
    }

    function processFailed(e) {
        widgets.alert.showAlert(e.error.errorMsg, false);
    }

    function clearFeatures() {
        vectorLayer.removeAllFeatures();
        markerLayer.clearMarkers();
        closeInfoWin();
    }

    var infowin = null;

    function openInfoWin() {
        closeInfoWin();
        var marker = this;
        var lonlat = marker.getLonLat();
        var contentHTML = "<div style='font-size:.8em; opacity: 0.8; overflow-y:hidden;'>";
        contentHTML += "<div>" + marker.name + "</div></div>";
        var size = new SuperMap.Size(0, 33);
        var offset = new SuperMap.Pixel(0, -size.h);
        var icon = new SuperMap.Icon("./images/marker.png", size, offset);
        var popup = new SuperMap.Popup.FramedCloud("popwin",
            new SuperMap.LonLat(lonlat.lon, lonlat.lat),
            null,
            contentHTML,
            icon,
            true);

        infowin = popup;
        map.addPopup(popup);
    }

    function closeInfoWin() {
        if (infowin) {
            try {
                infowin.hide();
                infowin.destroy();
            }
            catch (e) {
            }
        }
    }
</script>
</body>
</html>
图层名有问题,iserver里的图层名与你代码里的不一致,打开iserver地图服务看下

是一样的,这个图就是iServer中发布的

请问是原本数据的问题,还是我的代码的问题呢?
应该就是你name: "Company@Changchun"这块的问题,不是看数据服务,你的查询是走地图服务的,所以要看地图服务中company所在的图层名

请问您说的是要在哪里查看啊?

这个使用supermap 10i 打开的数据:

这个是在iServer发布的工作空间里的数据:

找到相应的名字

是这个吗?是一样的啊

非常感谢,解决了,确实是名字不一样。yesyesyes

那请问这个医院的数据,为什么没有查询的地点也会显示啊?
这个确定不是你数据的问题吗?看起来好像没啥问题
...