[fusion-commits] r2699 - in sandbox/createruntimemap: layers/MapGuide lib

svn_fusion at osgeo.org svn_fusion at osgeo.org
Tue May 14 07:55:13 PDT 2013


Author: jng
Date: 2013-05-14 07:55:11 -0700 (Tue, 14 May 2013)
New Revision: 2699

Modified:
   sandbox/createruntimemap/layers/MapGuide/MapGuide.js
   sandbox/createruntimemap/lib/MGBroker.js
Log:
This submission includes the following changes:
 - Add a new MGCreateRuntimeMap class to MGBroker.js
 - Implement an initialization shortcut in MapGuide.js using the response of CREATERUNTIMEMAP. The old and new initialization behaviour is driven by a boolean variable (bUseNativeServices). Currently, this produces the same legend tree but for some reason that's currently unknown to me, the checkboxes do not register visibility changes even though debugging shows that the correct group and layer ids are being passed to the GETDYNAMICMAPOVERLAYIMAGE request that is sent by OpenLayers. We'll figure this out sooner or later. Also selection is mildly broken at the moment as it is looking for PHP session-cached objects that have been put there by LoadMap.php and LoadScaleRanges.php, but are obviously missing since we've taken a different initialization path.

Modified: sandbox/createruntimemap/layers/MapGuide/MapGuide.js
===================================================================
--- sandbox/createruntimemap/layers/MapGuide/MapGuide.js	2013-05-14 09:30:26 UTC (rev 2698)
+++ sandbox/createruntimemap/layers/MapGuide/MapGuide.js	2013-05-14 14:55:11 UTC (rev 2699)
@@ -123,6 +123,9 @@
         this.noCache = true;
         this.oLayersOLTile = [];
         
+        //NOTE: This can only be true in conjunction with support for QUERYMAPFEATURES 2.6.0 because the current LoadMap.php
+        //and LoadScaleRanges.php stash cached state server-side (yuck!) that would be missing if we go this route >:(
+        this.bUseNativeServices = true;
         var sid = Fusion.sessionId;
         if (sid) {
             this.session[0] = sid;
@@ -202,7 +205,7 @@
 
     loadMap: function(resourceId, options) {
         this.bMapLoaded = false;
-
+        
         if (!this.sessionReady()) {
             this.sMapResourceId = resourceId;
             return;
@@ -212,7 +215,6 @@
         this.mapWidget._addWorker();
 
         this._fScale = -1;
-        //this._nDpi = 96;
 
         options = options || {};
 
@@ -226,221 +228,390 @@
         this.oSelection = null;
         this.aSelectionCallbacks = [];
         this._bSelectionIsLoading = false;
+        
+        if (this.bUseNativeServices) {
+            var features = (1 | 2 | 4); //We want the whole lot
+            var r = new Fusion.Lib.MGRequest.MGCreateRuntimeMap(resourceId, features, 25);
+            if (this.session.length == 1)
+                r.setParams({ session: this.session[0] });
+            Fusion.oBroker.dispatchRequest(r, OpenLayers.Function.bind(this.onRuntimeMapCreated, this));
+        } else {
+            var sl = Fusion.getScriptLanguage();
+            var loadmapScript = 'layers/' + this.arch + '/' + sl  + '/LoadMap.' + sl;
 
-        var sl = Fusion.getScriptLanguage();
-        var loadmapScript = 'layers/' + this.arch + '/' + sl  + '/LoadMap.' + sl;
+            var sessionid = this.getSessionID();
 
-        var sessionid = this.getSessionID();
-
-        var params = {'mapid': resourceId, "session": sessionid};
-        var options = {onSuccess: OpenLayers.Function.bind(this.mapLoaded,this),
-                       parameters:params};
-        Fusion.ajaxRequest(loadmapScript, options);
+            var params = {'mapid': resourceId, "session": sessionid};
+            var options = {onSuccess: OpenLayers.Function.bind(this.mapLoaded,this),
+                           parameters:params};
+            Fusion.ajaxRequest(loadmapScript, options);
+        }
     },
-
-    mapLoaded: function(r) {
-        if (r.status == 200) {
-            var o = Fusion.parseJSON(r.responseText);
-            this._sResourceId = o.mapId;
-            this._sMapname = o.mapName;
-            this._sMapTitle = o.mapTitle;
+    /**
+     * Re-shapes the CREATERUNTIMEMAP response to match the structure that our
+     * existing initialization code is expecting
+     */
+    convertResponse: function(o) {
+        var rt = o.RuntimeMap;
+        
+        //LoadMap.php response
+        var lm = {
+            backgroundColor: ("#" + rt.BackgroundColor[0].substring(2)),
+            siteVersion: rt.SiteVersion[0],
+            mapId: rt.MapDefinition[0],
+            mapName: rt.Name[0],
+            mapTitle: rt.Name[0],
+            backgroundColor: rt.BackgroundColor[0],
+            metersPerUnit: parseFloat(rt.CoordinateSystem[0].MetersPerUnit[0]),
+            wkt: rt.CoordinateSystem[0].Wkt[0],
+            epsg: parseInt(rt.CoordinateSystem[0].EpsgCode[0]),
+            extent: [
+                parseFloat(rt.Extents[0].LowerLeftCoordinate[0].X[0]),
+                parseFloat(rt.Extents[0].LowerLeftCoordinate[0].Y[0]),
+                parseFloat(rt.Extents[0].UpperRightCoordinate[0].X[0]),
+                parseFloat(rt.Extents[0].UpperRightCoordinate[0].Y[0])
+            ],
+            hasBaseMapLayers: false,
+            hasDynamicLayers: false,
+            FiniteDisplayScales: [],
+            groups: [],
+            layers: []
+        };
+        if (rt.FiniteDisplayScale) {
+            for (var i = 0; i < rt.FiniteDisplayScale.length; i++) {
+                lm.FiniteDisplayScales.push(parseFloat(rt.FiniteDisplayScale[i]));
+            }
+        }
+        
+        for (var i = 0; i < rt.Group.length; i++) {
+            var grp = rt.Group[i];
+            var cg = {
+                groupName: grp.Name[0],
+                legendLabel: grp.LegendLabel[0],
+                uniqueId: grp.ObjectId[0],
+                displayInLegend: (grp.DisplayInLegend[0] == "true"),
+                expandInLegend: (grp.ExpandInLegend[0] == "true"), 
+                parentUniqueId: grp.ParentId ? grp.ParentId[0] : "",
+                visible: (grp.Visible[0] == "true"),
+                actuallyVisible: (grp.ActuallyVisible[0] == "true"),
+                isBaseMapGroup: (grp.Type[0] == "2")
+            };
+            if (grp.Type[0] == "2")
+                lm.hasBaseMapLayers = true;
+            else
+                lm.hasDynamicLayers = true;
+            lm.groups.push(cg);
+        }
+        
+        //LoadScaleRanges.php response
+        var lsr = {
+            layers: []
+        };
+        
+        for (var i = 0; i < rt.Layer.length; i++) {
+            var lyr = rt.Layer[i];
+            var cl = {
+                uniqueId: lyr.ObjectId[0],
+                layerName: lyr.Name[0],
+                layerTypes: [],
+                resourceId: lyr.LayerDefinition[0],
+                parentGroup: lyr.ParentId ? lyr.ParentId[0] : "",
+                selectable: (lyr.Selectable[0] == "true"),
+                visible: (lyr.Visible[0] == "true"),
+                actuallyVisible: (lyr.ActuallyVisible[0] == "true"),
+                editable: false,
+                isBaseMapLayer: (lyr.Type[0] == "2"),
+                legendLabel: lyr.LegendLabel[0],
+                displayInLegend: (lyr.DisplayInLegend[0] == "true"),
+                expandInLegend: (lyr.ExpandInLegend[0] == "true")
+            };
             
-            // Fix defect that background color in overview map will affect background color in main map.
-            // We'll first check if the loaded map is the one shown in main map.
-            var currentMaps = this.mapWidget.mapGroup.maps;
-            var isInMapWidget = false;
-            for(var index = 0, len = currentMaps.length; index < len; index++) {
-                var mapInMaps = currentMaps[index];
-                if(mapInMaps.resourceId == this._sResourceId) {
-                    isInMapWidget = this;
-                    break;
+            lm.layers.push(cl);
+            
+            var clsr = {
+                uniqueId: cl.uniqueId,
+                scaleRanges: []
+            };
+            
+            var ltypes = {};
+            
+            var minScale = 1.0e10;
+            var maxScale = 0;
+            
+            if (lyr.ScaleRange) {
+                for (var j = 0; j < lyr.ScaleRange.length; j++) {
+                    var sr = lyr.ScaleRange[j];
+                    var csr = {
+                        isCompressed: false,
+                        maxScale: sr.MaxScale[0],
+                        minScale: sr.MinScale[0],
+                        styles: [],
+                    };
+                    
+                    minScale = Math.min(minScale, sr.MinScale[0]);
+                    maxScale = Math.max(maxScale, sr.MaxScale[0]);
+                    
+                    if (sr.Rule) {
+                        for (var k = 0; k < sr.Rule.length; k++) {
+                            var rule = sr.Rule[k];
+                            var cr = {
+                                categoryIndex: parseInt(rule.ThemeCategory[0]),
+                                filter: rule.Filter ? rule.Filter[0] : "",
+                                geometryType: parseInt(rule.GeometryType[0]),
+                                legendLabel: rule.LegendLabel ? rule.LegendLabel[0] : ""
+                            };
+                            if (typeof(ltypes[cr.geometryType]) == 'undefined')
+                                ltypes[cr.geometryType] = cr.geometryType;
+                            //One single absence of an icon is enough to hint that it's compressed
+                            if (!rule.Icon) {
+                                csr.isCompressed = false;
+                            } else {
+                                cr.imageData = "data:" + rule.Icon[0].MimeType[0] + ";base64," + rule.Icon[0].Content[0];
+                            }
+                            csr.styles.push(cr);
+                        }
+                    }
+                    clsr.scaleRanges.push(csr);
                 }
             }
-            if(isInMapWidget) {
-                this.mapWidget.setMetersPerUnit(o.metersPerUnit);
-                this.mapWidget.setBackgroundColor(o.backgroundColor);
+            
+            for (var lt in ltypes)
+                cl.layerTypes.push(lt);
+            
+            cl.minScale = minScale;
+            cl.maxScale = maxScale;
+            
+            lsr.layers.push(clsr);
+        }
+        
+        return {
+            LoadMap: lm,
+            LoadScaleRanges: lsr
+        };
+    },
+    initLoadMapResponse: function(o) {
+        this._sResourceId = o.mapId;
+        this._sMapname = o.mapName;
+        this._sMapTitle = o.mapTitle;
+        
+        // Fix defect that background color in overview map will affect background color in main map.
+        // We'll first check if the loaded map is the one shown in main map.
+        var currentMaps = this.mapWidget.mapGroup.maps;
+        var isInMapWidget = false;
+        for(var index = 0, len = currentMaps.length; index < len; index++) {
+            var mapInMaps = currentMaps[index];
+            if(mapInMaps.resourceId == this._sResourceId) {
+                isInMapWidget = this;
+                break;
             }
+        }
+        if(isInMapWidget) {
+            this.mapWidget.setMetersPerUnit(o.metersPerUnit);
+            this.mapWidget.setBackgroundColor(o.backgroundColor);
+        }
 
-            var version = o.siteVersion;
-            var bits = version.split('.');
-            this.siteVersion = new Array(parseInt(bits[0]),
-                                          parseInt(bits[1]),
-                                          parseInt(bits[2]),
-                                          parseInt(bits[3])
-            );
+        var version = o.siteVersion;
+        var bits = version.split('.');
+        this.siteVersion = new Array(parseInt(bits[0]),
+                                      parseInt(bits[1]),
+                                      parseInt(bits[2]),
+                                      parseInt(bits[3])
+        );
 
 
-            this.mapTag.layerOptions.maxExtent = OpenLayers.Bounds.fromArray(o.extent);
+        this.mapTag.layerOptions.maxExtent = OpenLayers.Bounds.fromArray(o.extent);
 
-            this.layerRoot.clear();
-            this.layerRoot.legendLabel = this._sMapTitle;
-            this.layerRoot.displayInLegend = true;
-            this.layerRoot.expandInLegend = true;
+        this.layerRoot.clear();
+        this.layerRoot.legendLabel = this._sMapTitle;
+        this.layerRoot.displayInLegend = true;
+        this.layerRoot.expandInLegend = true;
 
-            this.parseMapLayersAndGroups(o);
+        this.parseMapLayersAndGroups(o);
 
-            this.minScale = 1.0e10;
-            this.maxScale = 0;
-            for (var i=0; i<this.aLayers.length; i++) {
-              this.minScale = Math.min(this.minScale, this.aLayers[i].minScale);
-              this.maxScale = Math.max(this.maxScale, this.aLayers[i].maxScale);
-            }
-            //a scale value of 0 is undefined
-            if (this.minScale <= 0) {
-              this.minScale = 1.0;
-            }
+        this.minScale = 1.0e10;
+        this.maxScale = 0;
+        for (var i=0; i<this.aLayers.length; i++) {
+          this.minScale = Math.min(this.minScale, this.aLayers[i].minScale);
+          this.maxScale = Math.max(this.maxScale, this.aLayers[i].maxScale);
+        }
+        //a scale value of 0 is undefined
+        if (this.minScale <= 0) {
+          this.minScale = 1.0;
+        }
 
-            for (var i=0; i<this.aShowLayers.length; i++) {
-                var layer =  this.layerRoot.findLayerByAttribute('layerName', this.aShowLayers[i]);
-                if (layer) {
-                    this.aShowLayers[i] = layer.uniqueId;
-                } else {
-                    this.aShowLayers[i] = '';
-                }
+        for (var i=0; i<this.aShowLayers.length; i++) {
+            var layer =  this.layerRoot.findLayerByAttribute('layerName', this.aShowLayers[i]);
+            if (layer) {
+                this.aShowLayers[i] = layer.uniqueId;
+            } else {
+                this.aShowLayers[i] = '';
             }
-            for (var i=0; i<this.aHideLayers.length; i++) {
-                var layer =  this.layerRoot.findLayerByAttribute('layerName', this.aHideLayers[i]);
-                if (layer) {
-                    this.aHideLayers[i] = layer.uniqueId;
-                } else {
-                    this.aHideLayers[i] = '';
-                }
+        }
+        for (var i=0; i<this.aHideLayers.length; i++) {
+            var layer =  this.layerRoot.findLayerByAttribute('layerName', this.aHideLayers[i]);
+            if (layer) {
+                this.aHideLayers[i] = layer.uniqueId;
+            } else {
+                this.aHideLayers[i] = '';
             }
+        }
 
-            for (var i=0; i<this.aShowGroups.length; i++) {
-                var group =  this.layerRoot.findGroupByAttribute('groupName', this.aShowGroups[i]);
-                if (group) {
-                    this.aShowGroups[i] = group.uniqueId;
-                } else {
-                    this.aShowGroups[i] = '';
-                }
+        for (var i=0; i<this.aShowGroups.length; i++) {
+            var group =  this.layerRoot.findGroupByAttribute('groupName', this.aShowGroups[i]);
+            if (group) {
+                this.aShowGroups[i] = group.uniqueId;
+            } else {
+                this.aShowGroups[i] = '';
             }
+        }
 
-            for (var i=0; i<this.aHideGroups.length; i++) {
-                var group =  this.layerRoot.findGroupByAttribute('groupName', this.aHideGroups[i]);
-                if (group) {
-                    this.aHideGroups[i] = group.uniqueId;
-                } else {
-                    this.aHideGroups[i] = '';
-                }
+        for (var i=0; i<this.aHideGroups.length; i++) {
+            var group =  this.layerRoot.findGroupByAttribute('groupName', this.aHideGroups[i]);
+            if (group) {
+                this.aHideGroups[i] = group.uniqueId;
+            } else {
+                this.aHideGroups[i] = '';
             }
+        }
 
-            if (o.hasBaseMapLayers && this.bIsMapWidgetLayer) {	//Use tile if there is base layer and in main map
-                this.bSingleTile = false;
-            }
+        if (o.hasBaseMapLayers && this.bIsMapWidgetLayer) {	//Use tile if there is base layer and in main map
+            this.bSingleTile = false;
+        }
 
-            //set projection units and code if supplied
-            var wktProj;
-            if (o.wkt && o.wkt.length > 0){
-              wktProj = new OpenLayers.Projection(o.wkt);
-            } 
-            if (!wktProj || (wktProj && wktProj.proj && !wktProj.proj.readyToUse)) {
-              if (o.epsg != 0) {
-                this.mapTag.layerOptions.projection = "EPSG:" + o.epsg;
-              } else {
-                //default to the local non-projected system if not otherwise specified
-                o.wkt = "LOCAL_CS[\"Non-Earth (Meter)\",LOCAL_DATUM[\"Local Datum\",0],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]";
-                wktProj = new OpenLayers.Projection(o.wkt);
-              }
-            }
-            //TODO: consider passing the metersPerUnit value into the framework
-            //to allow for scaling that doesn't match any of the pre-canned units
-            this.mapTag.layerOptions.units = Fusion.getClosestUnits(o.metersPerUnit);
+        //set projection units and code if supplied
+        var wktProj;
+        if (o.wkt && o.wkt.length > 0){
+          wktProj = new OpenLayers.Projection(o.wkt);
+        } 
+        if (!wktProj || (wktProj && wktProj.proj && !wktProj.proj.readyToUse)) {
+          if (o.epsg != 0) {
+            this.mapTag.layerOptions.projection = "EPSG:" + o.epsg;
+          } else {
+            //default to the local non-projected system if not otherwise specified
+            o.wkt = "LOCAL_CS[\"Non-Earth (Meter)\",LOCAL_DATUM[\"Local Datum\",0],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]";
+            wktProj = new OpenLayers.Projection(o.wkt);
+          }
+        }
+        //TODO: consider passing the metersPerUnit value into the framework
+        //to allow for scaling that doesn't match any of the pre-canned units
+        this.mapTag.layerOptions.units = Fusion.getClosestUnits(o.metersPerUnit);
 
-            //add in scales array if supplied
-            if (o.FiniteDisplayScales && o.FiniteDisplayScales.length>0) {
-              this.scales = o.FiniteDisplayScales;
-              this.mapWidget.fractionalZoom = false;
-              this.mapWidget.oMapOL.fractionalZoom = false;
-            }
-            
-            if (!this.bSingleTile) {
-                if (o.groups.length >0) {
-                    var tiledLayerIndex = 0;
-                    this.noCache = false;
-                    this.mapWidget.registerForEvent(Fusion.Event.MAP_EXTENTS_CHANGED, OpenLayers.Function.bind(this.mapExtentsChanged, this));
-                    
-                    for (var i=0; i<o.groups.length; i++) {
-                        if(o.groups[i].isBaseMapGroup) {
-                            this.oLayersOLTile[tiledLayerIndex] = this.createOLLayer(this._sMapname + "_Tiled[" + tiledLayerIndex + "]", false, 2, false, o.groups[i].groupName);              
-                            tiledLayerIndex++;
-                         }
-                    }
+        //add in scales array if supplied
+        if (o.FiniteDisplayScales && o.FiniteDisplayScales.length>0) {
+          this.scales = o.FiniteDisplayScales;
+          this.mapWidget.fractionalZoom = false;
+          this.mapWidget.oMapOL.fractionalZoom = false;
+        }
+        
+        if (!this.bSingleTile) {
+            if (o.groups.length >0) {
+                var tiledLayerIndex = 0;
+                this.noCache = false;
+                this.mapWidget.registerForEvent(Fusion.Event.MAP_EXTENTS_CHANGED, OpenLayers.Function.bind(this.mapExtentsChanged, this));
+                
+                for (var i=0; i<o.groups.length; i++) {
+                    if(o.groups[i].isBaseMapGroup) {
+                        this.oLayersOLTile[tiledLayerIndex] = this.createOLLayer(this._sMapname + "_Tiled[" + tiledLayerIndex + "]", false, 2, false, o.groups[i].groupName);              
+                        tiledLayerIndex++;
+                     }
                 }
-                else {
-                    this.bSingleTile = true;
-                }
             }
-     
-            //remove this layer if it was already created
-            if (this.oLayerOL) {
-                this.oLayerOL.events.unregister("loadstart", this, this.loadStart);
-                this.oLayerOL.events.unregister("loadend", this, this.loadEnd);
-                this.oLayerOL.events.unregister("loadcancel", this, this.loadEnd);
-                this.oLayerOL.destroy();
+            else {
+                this.bSingleTile = true;
             }
+        }
+ 
+        //remove this layer if it was already created
+        if (this.oLayerOL) {
+            this.oLayerOL.events.unregister("loadstart", this, this.loadStart);
+            this.oLayerOL.events.unregister("loadend", this, this.loadEnd);
+            this.oLayerOL.events.unregister("loadcancel", this, this.loadEnd);
+            this.oLayerOL.destroy();
+        }
 
-            if (this.oLayersOLTile.length != 0) {
-                this.oLayerOL = this.oLayersOLTile[this.oLayersOLTile.length-1]; // The last baselayer at the bottom.
-            } else {
-                this.oLayerOL = this.createOLLayer(this._sMapname, this.bSingleTile, 2, false, "");
-            }
+        if (this.oLayersOLTile.length != 0) {
+            this.oLayerOL = this.oLayersOLTile[this.oLayersOLTile.length-1]; // The last baselayer at the bottom.
+        } else {
+            this.oLayerOL = this.createOLLayer(this._sMapname, this.bSingleTile, 2, false, "");
+        }
+        
+        if (wktProj && wktProj.proj && wktProj.proj.readyToUse) {
+          this.oLayerOL.projection = wktProj;
+          this.oLayerOL.projection.proj.units = this.mapTag.layerOptions.units;
+        }
+        this.oLayerOL.events.register("loadstart", this, this.loadStart);
+        this.oLayerOL.events.register("loadend", this, this.loadEnd);
+        this.oLayerOL.events.register("loadcancel", this, this.loadEnd);
+
+        
+        //remove the dynamic overlay layer if it was already created
+        if (this.oLayerOL2) {
+            this.oLayerOL2.destroy();
+        }
+
+        //this is to distinguish between a regular map and an overview map
+        this.bMapLoaded = true;
+        if (this.bIsMapWidgetLayer) {
+            this.mapWidget.addMap(this);
             
-            if (wktProj && wktProj.proj && wktProj.proj.readyToUse) {
-              this.oLayerOL.projection = wktProj;
-              this.oLayerOL.projection.proj.units = this.mapTag.layerOptions.units;
+            if(this.oLayersOLTile.length > 1) {
+                for(var i=this.oLayersOLTile.length-2; i>=0; i--) {
+                    // Workaround to make multiple baselayers display. 
+                    // Openlayers only supports single baselayer.
+                    this.oLayersOLTile[i].isBaseLayer = false; 
+                    this.mapWidget.oMapOL.addLayer(this.oLayersOLTile[i]);
+                }                               
             }
-            this.oLayerOL.events.register("loadstart", this, this.loadStart);
-            this.oLayerOL.events.register("loadend", this, this.loadEnd);
-            this.oLayerOL.events.register("loadcancel", this, this.loadEnd);
-
             
-            //remove the dynamic overlay layer if it was already created
-            if (this.oLayerOL2) {
-                this.oLayerOL2.destroy();
+            //if we have a tiled map that also contains dynamic layers, we need to create
+            //an additional overlay layer to render them on top of the tiles
+            if(!this.bSingleTile && o.hasDynamicLayers) {
+                this.oLayerOL2 = this.createOLLayer(this._sMapname + "_DynamicOverlay",true,2,true, "");
+                this.mapWidget.oMapOL.addLayer(this.oLayerOL2);
+                this.oLayerOL2.setVisibility(true);
             }
+        }
 
-            //this is to distinguish between a regular map and an overview map
-            this.bMapLoaded = true;
-            if (this.bIsMapWidgetLayer) {
-                this.mapWidget.addMap(this);
-                
-                if(this.oLayersOLTile.length > 1) {
-                    for(var i=this.oLayersOLTile.length-2; i>=0; i--) {
-                        // Workaround to make multiple baselayers display. 
-                        // Openlayers only supports single baselayer.
-                        this.oLayersOLTile[i].isBaseLayer = false; 
-                        this.mapWidget.oMapOL.addLayer(this.oLayersOLTile[i]);
-                    }                               
-                }
-                
-                //if we have a tiled map that also contains dynamic layers, we need to create
-                //an additional overlay layer to render them on top of the tiles
-                if(!this.bSingleTile && o.hasDynamicLayers) {
-                    this.oLayerOL2 = this.createOLLayer(this._sMapname + "_DynamicOverlay",true,2,true, "");
-                    this.mapWidget.oMapOL.addLayer(this.oLayerOL2);
-                    this.oLayerOL2.setVisibility(true);
-                }
-            }
-
-            //Fix Defect: the Base Layer Group should be invisiable when the "initially visiable in map" is set to false
-            var i = 0;
-            var j = 0;
-            for(i = 0;i < this.layerRoot.groups.length; i++){  
-                if(this.layerRoot.groups[i].isBaseMapGroup && !this.layerRoot.groups[i].initiallyVisible){
-                    for(j = 0; j<this.oLayersOLTile.length; j++) {
-                        if(this.oLayersOLTile[j].params.basemaplayergroupname === this.layerRoot.groups[i].name) {
-                            this.oLayersOLTile[j].setVisibility(false);
-                        }
-                    }    
-                }   
-            }
+        //Fix Defect: the Base Layer Group should be invisiable when the "initially visiable in map" is set to false
+        var i = 0;
+        var j = 0;
+        for(i = 0;i < this.layerRoot.groups.length; i++){  
+            if(this.layerRoot.groups[i].isBaseMapGroup && !this.layerRoot.groups[i].initiallyVisible){
+                for(j = 0; j<this.oLayersOLTile.length; j++) {
+                    if(this.oLayersOLTile[j].params.basemaplayergroupname === this.layerRoot.groups[i].name) {
+                        this.oLayersOLTile[j].setVisibility(false);
+                    }
+                }    
+            }   
         }
+    },
+    /**
+     * Callback function from a LoadMap.php request
+     */
+    mapLoaded: function(r) {
+        if (r.status == 200) {
+            var o = Fusion.parseJSON(r.responseText);
+            this.initLoadMapResponse(o);
+        }
         this.mapWidget._removeWorker();
         this.triggerEvent(Fusion.Event.LAYER_LOADED);
 
     },
-
+    /**
+     * Callback function from a CREATERUNTIMEMAP request
+     */
+    onRuntimeMapCreated: function(r) {
+        if (r.status == 200) {
+            var o = Fusion.parseJSON(r.responseText);
+            var co = this.convertResponse(o);
+            this.initLoadMapResponse(co.LoadMap);
+            //Need to wait for the right event to trigger loadScaleRanges, so stash our
+            //prepared result for when it comes
+            this._initScaleRanges = co.LoadScaleRanges;
+        }
+        this.mapWidget._removeWorker();
+        this.triggerEvent(Fusion.Event.LAYER_LOADED);
+    },
 //TBD: this function not yet converted for OL
     reloadMap: function() {
 
@@ -483,43 +654,52 @@
      */
 
     loadScaleRanges: function() {
-        var sl = Fusion.getScriptLanguage();
-        var loadmapScript = 'layers/' + this.arch + '/' + sl  + '/LoadScaleRanges.' + sl;
+        if (this.bUseNativeServices && this._initScaleRanges) {
+            this.initLoadScaleRangeResponse(this._initScaleRanges);
+            delete this._initScaleRanges;
+        } else {
+            var sl = Fusion.getScriptLanguage();
+            var loadmapScript = 'layers/' + this.arch + '/' + sl  + '/LoadScaleRanges.' + sl;
 
-        //IE7 or lower: No pre-caching for you!
-        var preCacheIcons = !(Browser.Engine.trident4 || Browser.Engine.trident5);
-        //console.log("Layer icon pre-caching enabled: " + preCacheIcons);
-        var sessionid = this.getSessionID();
+            //IE7 or lower: No pre-caching for you!
+            var preCacheIcons = !(Browser.Engine.trident4 || Browser.Engine.trident5);
+            //console.log("Layer icon pre-caching enabled: " + preCacheIcons);
+            var sessionid = this.getSessionID();
 
-        var params = {'mapname': this._sMapname, "session": sessionid, "preCacheIcons": preCacheIcons};
-        var options = {onSuccess: OpenLayers.Function.bind(this.scaleRangesLoaded,this),
-                       parameters:params};
-        Fusion.ajaxRequest(loadmapScript, options);
+            var params = {'mapname': this._sMapname, "session": sessionid, "preCacheIcons": preCacheIcons};
+            var options = {onSuccess: OpenLayers.Function.bind(this.scaleRangesLoaded,this),
+                           parameters:params};
+            Fusion.ajaxRequest(loadmapScript, options);
+        }
     },
 
+    initLoadScaleRangeResponse: function(o) {
+        if (o.layers && o.layers.length > 0) {
+            var iconOpt = {
+                url: o.icons_url || null,
+                width: o.icons_width || 16,
+                height: o.icons_height || 16
+            };
+            for (var i=0; i<o.layers.length; i++)  {
+                var oLayer = this.getLayerById(o.layers[i].uniqueId);
+                if (oLayer) {
+                    oLayer.scaleRanges = [];
+                    for (var j=0; j<o.layers[i].scaleRanges.length; j++) {
+                        var scaleRange = new Fusion.Layers.ScaleRange(o.layers[i].scaleRanges[j],
+                                                                             oLayer.layerType, iconOpt);
+                        oLayer.scaleRanges.push(scaleRange);
+                    }
+                }
+            }
+        }
+        this.mapWidget.triggerEvent(Fusion.Event.MAP_SCALE_RANGE_LOADED);
+    },
+
     scaleRangesLoaded: function(r)
     {
         if (r.status == 200) {
             var o = Fusion.parseJSON(r.responseText);
-            if (o.layers && o.layers.length > 0) {
-                var iconOpt = {
-                    url: o.icons_url || null,
-                    width: o.icons_width || 16,
-                    height: o.icons_height || 16
-                };
-                for (var i=0; i<o.layers.length; i++)  {
-                    var oLayer = this.getLayerById(o.layers[i].uniqueId);
-                    if (oLayer) {
-                        oLayer.scaleRanges = [];
-                        for (var j=0; j<o.layers[i].scaleRanges.length; j++) {
-                            var scaleRange = new Fusion.Layers.ScaleRange(o.layers[i].scaleRanges[j],
-                                                                                 oLayer.layerType, iconOpt);
-                            oLayer.scaleRanges.push(scaleRange);
-                        }
-                    }
-                }
-            }
-            this.mapWidget.triggerEvent(Fusion.Event.MAP_SCALE_RANGE_LOADED);
+            this.initLoadScaleRangeResponse(o);
         }
     },
     

Modified: sandbox/createruntimemap/lib/MGBroker.js
===================================================================
--- sandbox/createruntimemap/lib/MGBroker.js	2013-05-14 09:30:26 UTC (rev 2698)
+++ sandbox/createruntimemap/lib/MGBroker.js	2013-05-14 14:55:11 UTC (rev 2699)
@@ -316,6 +316,34 @@
 });
 
 /****************************************************************************
+ * Class: Fusion.Lib.MGRequest.MGCreateRuntimeMap
+ *
+ * encapsulate a request to the server to create a new runtime map (and session if required)
+ * on the server
+ *
+ * Inherits from:
+ *  - <Fusion.Lib.MGRequest>
+ */
+Fusion.Lib.MGRequest.MGCreateRuntimeMap = OpenLayers.Class(Fusion.Lib.MGRequest, {
+    /**
+     * Constructor: Fusion.Lib.MGRequest.MGCreateRuntimeMap
+     * 
+     * initialize a new instance of Fusion.Lib.MGRequest.MGCreateRuntimeMap
+     */
+    initialize: function(mapDefinition, features, iconsPerScaleRange) {
+        this.initializeRequest();
+        this.setParams({
+            operation: "CREATERUNTIMEMAP",
+            mapdefinition: mapDefinition,
+            requestedfeatures: features,
+            iconsperscalerange: iconsPerScaleRange,
+            format: "application/json",
+            version: "2.6.0"
+        });
+    }
+});
+
+/****************************************************************************
  * Class: Fusion.Lib.MGRequest.MGCopyResource
  *
  * encapsulate a request to the server to copy a resource.



More information about the fusion-commits mailing list