`
夏莹_合肥
  • 浏览: 178736 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
最新评论

WfsGetFeatureControl,拉框获得多个features

 
阅读更多
以下是源代码,这个问题搞了我8个小时,郁闷死了。version为1.1.0的wfs服务,默认返回的GML带个节点叫<gml:featureMembers>,所有的format源代码查一遍,调试很久,还是不知道怎么解析,已经准备放弃自己写解析类了。突然想起试下以前的version1.0.0和outputformat:GML2,行了。虽然解决了,还是很郁闷,浪费了这么长的时间啊!!!
trms.GetFeaturesToDeleteVectorLayerControl = OpenLayers.Class(OpenLayers.Control, {

draw: function() {
        this.handler = new OpenLayers.Handler.Box( this,
                            {done: this.zoomBox}, {keyMask: this.keyMask} );
    },
   
    zoomBox: function (position) {
   
        if (position instanceof OpenLayers.Bounds) {
       
            if (!this.out) {
                var minXY = this.map.getLonLatFromPixel(
                            new OpenLayers.Pixel(position.left, position.bottom));
                var maxXY = this.map.getLonLatFromPixel(
                            new OpenLayers.Pixel(position.right, position.top));
                var bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat,
                                               maxXY.lon, maxXY.lat);
            } else {
                var pixWidth = Math.abs(position.right-position.left);
                var pixHeight = Math.abs(position.top-position.bottom);
                var zoomFactor = Math.min((this.map.size.h / pixHeight),
                    (this.map.size.w / pixWidth));
                var extent = this.map.getExtent();
                var center = this.map.getLonLatFromPixel(
                    position.getCenterPixel());
                var xmin = center.lon - (extent.getWidth()/2)*zoomFactor;
                var xmax = center.lon + (extent.getWidth()/2)*zoomFactor;
                var ymin = center.lat - (extent.getHeight()/2)*zoomFactor;
                var ymax = center.lat + (extent.getHeight()/2)*zoomFactor;
                var bounds = new OpenLayers.Bounds(xmin, ymin, xmax, ymax);
            }
           
            var bbox = bounds.left + ',' + bounds.bottom + ',' + bounds.right + ',' + bounds.top;
            var params = {
            service : 'WFS',
version : '1.0.0',
            request : 'GetFeature',
            typeName : 'shane:guandao_renkong,shane:guandao_guandao,shane:ganlu_diangan,shane:ganlu_diaoxian',
            OUTPUTFORMAT : 'GML2',
SRSNAME : 'EPSG:4326',
            BBOX : bbox
            };

            OpenLayers.loadURL("/geoserver/wfs", params, this.map, function(response) {
           
            var g = new OpenLayers.Format.GML();
var features = g.read(response.responseText);

alert(features.length);
            });
        }
    }
});
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics