圆查询问题,求救,矩形和圆形共用方法怎么改

0 投票
var map, layer, vectorLayer, markerLayer, drawFeature,
            style = {
                strokeColor: "#304DBE",
                strokeWidth: 1,
                pointerEvents: "visiblePainted",
                fillColor: "#304DBE",
                fillOpacity: 0.3
            },
        url = "http://localhost:8090/iserver/services/map-zengcheng/rest/maps/增城区_region@ZengCheng";

        //页面加载
        function onPageLoad() {

            //初始化地图
            //map = new SuperMap.Map("map", {
            //    controls: [
            //        drawPolygon2
            //    ]
            //});//添加控件放着为什么报错??
            map = new SuperMap.Map("map");

            //初始化图层
            layer = new SuperMap.Layer.TiledDynamicRESTLayer("增城区_region@ZengCheng", url, { transparent: true, cacheEnabled: true }, { maxResolution: "auto" });

            //监听图层信息加载完成事件。类似:写了一个方法(addLayer();)在这里。
            layer.events.on({ "layerInitialized": addLayer });

            //新建一个Vector Layer的矢量图层,该图层渲染矢量要素
            vectorLayer = new SuperMap.Layer.Vector("Vector Layer");

            markerLayer = new SuperMap.Layer.Markers("Markers");//创建一个有标签的图层

        //矩形查询
            //Control:控件集;DraFeature:绘制要素类
            //SuperMap.Handler.Box:地图拖拽矩形框的控制事件处理器,这个矩形在按下鼠标的时候开始显示,然后移动鼠标,最后在鼠标松开时完成。Handler:实例化处理对象
            //handlerOptions:常用于设置控件的事情处理器的非默认属性;cursonrCSS:鼠标样式;crosshair:十字架
            drawFeature = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Box, { "handlerOptions": { "cursorCSS": "crosshair" } });

            //为地图添加控件。可选的位置参数用来指定控件的像素位置。
            map.addControl(drawFeature);

            //监听,featureaddeds(当要素绘制成功时调用该函数)事件完成时,触发方法drawCompleted()
            drawFeature.events.on({ "featureadded": drawCompleted });

        //几何圆查询
            //RegularPolygon:够构造方法,返回一个绘制规则多边形的处理器
            drawPolygon1 = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.RegularPolygon, { handlerOptions: { sides: 50 } });
            drawPolygon1.events.on({ "featureadded": drawCompleted2 });
            map.addControl(drawPolygon1);

        //多边形查询
            drawPolygon2 = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Polygon);
            drawPolygon2.eventsl.on({ "featureadded": drawCompleted });
            map.addControl(drawPolygon2);
            
        }
        function addLayer() {
            map.addLayers([layer, vectorLayer, markerLayer]);
            map.setCenter(new SuperMap.LonLat(113.8215, 23.28631), 4);
        }

        //矩形 查询并将结果(drawGeometryArgs)返回
        function drawCompleted(drawGeometryArgs) {

            drawFeature.deactivate();//注销控件
            drawPolygon1.deactivate();
            drawPolygon2.deactivate();

            var feature = drawGeometryArgs.feature;//获取所画区域的所有内容
            var queryBounds = feature.geometry.bounds;//获取几何图形的范围.geometry:几何

            feature.style = style;//设置所画区域的格式
            vectorLayer.addFeatures(feature);//所画的图层添加热点信息。
                
            var queryParam, queryByBoundsParams, queryService;

            //FilterParameter:设置查找条件,name必要参数,P15医疗服务_point@ZengCheng(图层格式名称:数据集名@数据源别名)。REST所有的枚举类。
            queryParam = new SuperMap.REST.FilterParameter({ name: "P15医疗服务_point@ZengCheng" });

            //QueryByBoundsParameters:Bounds 查询参数类,该类用于设置 Bounds 查询的相关参数。queryParams查找过滤条件数组。bounds查找范围。
            queryByBoundsParams = new SuperMap.REST.QueryByBoundsParameters({ queryParams: [queryParam], bounds: queryBounds });

            //QueryByBoundsService:Bounds 查询服务类。eventListeners:需要被注册的监听对象
            queryService = new SuperMap.REST.QueryByBoundsService(url, {
                eventListeners: {
                    "processCompleted": processCompleted,//触发方法processCompleted()
                    "processFailed": processFailed//触发方法processFailed()
                }
            });
            queryService.processAsync(queryByBoundsParams);//向服务端传递参数,然后服务端返回对象。processAsync:异步执行。 修
        }

        //圆形 查询并将结果(drawGeometryArgs)返回
        function drawCompleted2(drawGeometryArgs) {
            var feature = new SuperMap.Feature.Vector();//Feature.Vector:矢量要素类,存放几何信息
            feature.geometry = drawGeometryArgs.feature.geometry,//几何图形的范围
            feature.style = style;
            vectorLayer.addFeatures(feature);

            var queryParam, queryByGeometryParameters, queryService;
            queryParam = new SuperMap.REST.FilterParameter({ name: "P15医疗服务_point@ZengCheng" });
            //queryParams所要查询的数据集geometry用于查询的几何对象。spatialQueryMode空间查询模式SuperMap.REST.SpatialQueryMode.INTERSECT
            queryByGeometryParameters = new SuperMap.REST.QueryByGeometryParameters({ queryParams: [queryParam], geometry: drawGeometryArgs.feature.geometry, spatialQueryMode: SuperMap.REST.SpatialQueryMode.INTERSECT });
            //Geometry 查询服务类构造函数。
            queryService = new SuperMap.REST.QueryByGeometryService(url, {
                eventListeners: {
                    "processCompleted": processCompleted,
                    "processFailed": processFailed
                }
            });
            queryService.processAsync(queryByGeometryParameters);
        }

        //处理返回的结果。queryEventArgs:服务端返回的结果对象,返回值
        function processCompleted(queryEventArgs) {
         
            var i, j, result = queryEventArgs.result, marker;

            //recordsets:记录集
            if (result && result.recordsets) {

                for (i = 0, recordsets = result.recordsets,len = recordsets.length; i < len; i++) {

                    //recordsets[i].features:记录集中的所有要素
                    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);//此类描绘一对高宽值的实例

                            //偏移量:此类用x,y坐标描绘屏幕坐标(像素点)。
                            offset = new SuperMap.Pixel(-(size.w / 2), -size.h);

                            //图标类,显示在屏幕上的图标,通常与{SuperMap.Marker}配合使用表示屏幕上显示的Marker
                            //Icon具有url、size和position属性。
                            icon = new SuperMap.Icon("../scripts/theme/images/marker.png", size, offset);

                            //LonLat:这类表示经度和纬度对。SuperMap.Marker:创建标记
                            //标记当前的图标位置
                            marker = new SuperMap.Marker(new SuperMap.LonLat(point.x, point.y), icon);

                            //sm_capital为所要展示的内容,NAME:是图层(P15医疗服务_point@ZengCheng)内的属性名
                            marker.sm_capital = f.attributes.NAME;

                            //注册监听事件(click、touchstart、scope)
                            marker.events.on({

                                "click": openInfoWin,
                                "touchstart": openInfoWin,
                                "scope": marker//scope 范围
                            });
                            //addMarker:添加标记
                            markerLayer.addMarker(marker);

                        }
                    }
                }
            }
           
        }
1月 2, 2019 分类:  157次浏览 | 用户: pps (1 分)

1个回答

0 投票

您好!

请问你是用的是iserver发布的地图服务来进行查询的吗?

你是意思是无论是用圆这个feature或者矩形这个feature都能调用同一种方法进行查询?

我个人觉得发布一个数据服务,然后在查询参数里面设置  1.获取圆或者矩形的要素的geometry,2.查询的数据集,3.以及查询方式。一下为简单一个例子

function get(feature){

  let  boundsParam = ({

datasetNames: ["数据源名称:数据集名称"],

geometry:feature.getGeometry(),

spatialQueryMode: "INTERSECT"

});

new ol.supermap.FeatureService(dataurl).getFeaturesByGeometry(boundsParam, function (serviceResult) { 范围的结果进行的查找})

}

1月 2, 2019 用户: 阳俊林 名扬四海 (1,117 分)
...