[fusion-commits] r2695 - sandbox/queryfeatures_v2/layers/MapGuide

svn_fusion at osgeo.org svn_fusion at osgeo.org
Wed May 8 04:43:21 PDT 2013


Author: jng
Date: 2013-05-08 04:43:21 -0700 (Wed, 08 May 2013)
New Revision: 2695

Modified:
   sandbox/queryfeatures_v2/layers/MapGuide/MapGuide.js
Log:
Update Fusion.Layer.MapGuide to handle the updated v2.6.0 QUERYMAPFEATURES response structure, which simplifies the conversion process of the request response JSON to Fusion's client-side selection model. 

Also use MGQueryMapFeatures2 in place of MGQueryMapFeatures for maptips if supported as we get slimmer responses.


Modified: sandbox/queryfeatures_v2/layers/MapGuide/MapGuide.js
===================================================================
--- sandbox/queryfeatures_v2/layers/MapGuide/MapGuide.js	2013-05-06 11:33:06 UTC (rev 2694)
+++ sandbox/queryfeatures_v2/layers/MapGuide/MapGuide.js	2013-05-08 11:43:21 UTC (rev 2695)
@@ -1116,6 +1116,25 @@
             }
         }
     },
+    /**
+     * Checks if we can perform a v2.6.0 QUERYMAPFEATURES request. A v2.6.0 QUERYMAPFEATURES request gives us
+     *  - All attributes of selected features if requested (bypassing several follow-up requests to PHP scripts to get this data)
+     *  - Slimmer maptip requests.
+     * A much better option, if it is available to us.
+     */
+    supportsExtendedQuery: function() {
+        var bSupportsExtended = false;
+        if (this.siteVersion[0] >= 2) { //2.x or higher
+            if (this.siteVersion[0] == 2) { //Major is 2
+                if (this.siteVersion[1] >= 6) { //2.6 or higher 2.x
+                    bSupportsExtended = true;
+                }
+            } else { //3.x, 4.x, etc
+                bSupportsExtended = true;
+            }
+        }
+        return bSupportsExtended;
+    },
 
     /**
        Do a query on the map
@@ -1140,17 +1159,7 @@
             options.filter = '';
         }
         
-        var bSupportsExtended = false;
-        if (this.siteVersion[0] >= 2) { //2.x or higher
-            if (this.siteVersion[0] == 2) { //Major is 2
-                if (this.siteVersion[1] >= 6) { //2.6 or higher 2.x
-                    bSupportsExtended = true;
-                }
-            } else { //3.x, 4.x, etc
-                bSupportsExtended = true;
-            }
-        }
-        if (bSupportsExtended) {
+        if (this.supportsExtendedQuery()) {
             var reqData = 1; //attributes
             //TODO: Can't use inline selection image yet as we'll have to modify OpenLayers to accept an inline selection
             //over doing a GETDYNAMICMAPOVERLAYIMAGE request. When we can, or the value of 2 into the mask for inline 
@@ -1384,12 +1393,25 @@
         var layerAttributeFilter = 5;
         //TODO: possibly make the layer names configurable?
         var layerNames = mapTipWidget.aLayers.toString();
-        var r = new Fusion.Lib.MGRequest.MGQueryMapFeatures(this.getSessionID(),
-                                        this._sMapname,
-                                        sGeometry,
-                                        maxFeatures, persist, selection, filter, layerNames,
-                                        layerAttributeFilter);
-        oBroker.dispatchRequest(r, OpenLayers.Function.bind(this.parseMapTip, this));
+        if (this.supportsExtendedQuery()) {
+            var reqData = (4 | 8); //Tooltips and hyperlinks
+            var r = new Fusion.Lib.MGRequest.MGQueryMapFeatures2(this.getSessionID(),
+                                            this._sMapname,
+                                            sGeometry,
+                                            maxFeatures, persist, selection, filter, layerNames,
+                                            layerAttributeFilter,
+                                            reqData,
+                                            this.selectionColor,
+                                            this.selectionImageFormat);
+            oBroker.dispatchRequest(r, OpenLayers.Function.bind(this.parseMapTip, this));
+        } else {
+            var r = new Fusion.Lib.MGRequest.MGQueryMapFeatures(this.getSessionID(),
+                                            this._sMapname,
+                                            sGeometry,
+                                            maxFeatures, persist, selection, filter, layerNames,
+                                            layerAttributeFilter);
+            oBroker.dispatchRequest(r, OpenLayers.Function.bind(this.parseMapTip, this));
+        }
     },
     
     parseMapTip: function(xhr) {
@@ -1473,70 +1495,51 @@
         var bHasSelection = false;
         var result = {};
         var layerNames = [];
-        //First pass: Collect and group by layers
         var featuresByLayer = {};
-        var bp = efi.FeatureInformation.Attributes[0].BatchPropertyCollection[0].PropertyCollection;
-        for (var i = 0; i < bp.length; i++) {
-            bHasSelection = true;
-            var props = bp[i];
-            
-            var feat = { attributes: {} };
-            
-            for (var j = 0; j < props.Property.length; j++) {
-                var name = props.Property[j].Name[0];
-                var typeName = props.Property[j].Type[0];
-                var value = props.Property[j].Value == null ? null : props.Property[j].Value[0];
-                
-                if (name == "_MgLayerName") {
-                    if (!featuresByLayer[value]) {
-                        featuresByLayer[value] = [];
-                        layerNames.push(value);
-                    }
-                    featuresByLayer[value].push(feat);
-                } else if (name == "_MgFeatureBoundingBox") {
-                    var b = value.split(" ");
-                    feat.bounds = { minx: parseFloat(b[0]), miny: parseFloat(b[1]), maxx: parseFloat(b[2]), maxy: parseFloat(b[3]) };
-                } else {
-                    feat.attributes[name] = { type: typeName, value: value };
-                }
-            }
-        }
+        var selLayers = efi.FeatureInformation.SelectedFeatures[0].SelectedLayer;
+        bHasSelection = (selLayers.length > 0);
+        var box = new OpenLayers.Bounds();
         
-        //Second pass: Convert intermediate form to final result
-        var box = new OpenLayers.Bounds();
-        for (var layerName in featuresByLayer) {
-            var bSetProperties = false;
+        for (var i = 0; i < selLayers.length; i++) {
+            var selLayer = selLayers[i];
+            var layerName = selLayer["@name"];
             if (!result[layerName]) {
+                var layerMeta = selLayer.LayerMetadata[0];
+                var pnames = [];
+                var ptypes = [];
+                var pvals = [];
+                for (var j = 0; j < layerMeta.Property.length; j++) {
+                    var metaProp = layerMeta.Property[j];
+                    pnames.push(metaProp.Name[0]);
+                    ptypes.push(metaProp.Type[0]);
+                    pvals.push(metaProp.DisplayName[0]);
+                }
                 result[layerName] = {
-                    metadata: [],      //TODO: What do we put here?
-                    metadatanames: [], //TODO: What do we put here?
-                    numelements: featuresByLayer[layerName].length,
-                    propertynames: [], //TODO: QUERYMAPFEATURES 2.6.0 does not yet return system property names, this will always be empty for now
-                    propertytypes: [],
-                    propertyvalues: [],
+                    metadata: [],  //NOTE: Probably a defect, but regular code path is putting blank string arrays here too
+                    metadatanames: ["dimension", "bbox", "center", "area", "length"],
+                    numelements: selLayer.Feature.length,
+                    propertynames: pnames,
+                    propertytypes: ptypes,
+                    propertyvalues: pvals,
                     values: []
                 };
+                layerNames.push(layerName);
             }
-            for (var i = 0; i < featuresByLayer[layerName].length; i++) {
-                var feat = featuresByLayer[layerName][i];
+            
+            for (var j = 0; j < selLayer.Feature.length; j++) {
+                var feat = selLayer.Feature[j];
                 var featVals = [];
-                if (!bSetProperties) {
-                    for (var attrName in featuresByLayer[layerName][i].attributes) {
-                        var attrInfo = featuresByLayer[layerName][i].attributes[attrName];
-                        result[layerName].propertyvalues.push(attrName);
-                        result[layerName].propertytypes.push(this.typeNameToValue(attrInfo.type));
-                        featVals.push(attrInfo.value);
-                    }
-                    bSetProperties = true;
-                } else {
-                    for (var attrName in featuresByLayer[layerName][i].attributes) {
-                        var attrInfo = featuresByLayer[layerName][i].attributes[attrName];
-                        featVals.push(attrInfo.value);
-                    }
+                for (var k = 0; k < feat.Property.length; k++) {
+                    //Fusion represents null as empty string. Don't think that's right but we'll run with whatever
+                    //the old code path produces
+                    featVals.push(feat.Property[k].Value == null ? "" : feat.Property[k].Value[0]);
                 }
                 result[layerName].values.push(featVals);
-                box.extend(new OpenLayers.LonLat(feat.bounds.minx, feat.bounds.miny));
-                box.extend(new OpenLayers.LonLat(feat.bounds.maxx, feat.bounds.maxy));
+                //NOTE: Probably a defect, but regular code path is putting blank string arrays here too, so let's do the same
+                result[layerName].metadata.push(["","","","",""]);
+                var bounds = feat.Bounds[0].split(" "); //minx miny maxx maxy
+                box.extend(new OpenLayers.LonLat(parseFloat(bounds[0]), parseFloat(bounds[1])));
+                box.extend(new OpenLayers.LonLat(parseFloat(bounds[2]), parseFloat(bounds[3])));
             }
         }
         



More information about the fusion-commits mailing list