[fusion-commits] r1625 - in trunk: MapGuide MapGuide/php lib/OpenLayers templates/mapguide/standard

svn_fusion at osgeo.org svn_fusion at osgeo.org
Thu Oct 30 15:39:28 EDT 2008


Author: madair
Date: 2008-10-30 15:39:28 -0400 (Thu, 30 Oct 2008)
New Revision: 1625

Modified:
   trunk/MapGuide/MapGuide.js
   trunk/MapGuide/php/CreateSession.php
   trunk/lib/OpenLayers/OpenLayers.js
   trunk/templates/mapguide/standard/ApplicationDefinition.xml
Log:
re #120: update of OL Mapguide layer to use the new GETDYNAMICOVERLAY API call from MapGuide

Modified: trunk/MapGuide/MapGuide.js
===================================================================
--- trunk/MapGuide/MapGuide.js	2008-10-30 19:00:30 UTC (rev 1624)
+++ trunk/MapGuide/MapGuide.js	2008-10-30 19:39:28 UTC (rev 1625)
@@ -47,7 +47,7 @@
     bMapLoaded: false,
     bIsMapWidgetLayer: true,  //Set this to false for overview map layers
     bLayersReversed: false,     //MGOS returns layers top-most layer first
-    selectionAsOverlay: true,
+    selectionAsOverlay: false,
 
     //the resource id of the current MapDefinition
     _sResourceId: null,
@@ -73,8 +73,8 @@
         this.selectionType = extension.SelectionType ? extension.SelectionType[0] : 'INTERSECTS';
         this.selectionColor = extension.SelectionColor ? extension.SelectionColor[0] : '';
         this.selectionFormat = extension.SelectionFormat ? extension.SelectionFormat[0] : 'PNG';
-        if (extension.SelectionAsOverlay && extension.SelectionAsOverlay[0] == 'false') {
-          this.selectionAsOverlay = false;
+        if (extension.SelectionAsOverlay && extension.SelectionAsOverlay[0] == 'true') {
+          this.selectionAsOverlay = true;
         }
         this.ratio = extension.MapRatio ? extension.MapRatio[0] : 1.0;
         
@@ -147,6 +147,13 @@
             var o;
             eval('o='+xhr.responseText);
             this.session[0] = o.sessionId;
+            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.triggerEvent(Fusion.Event.MAP_SESSION_CREATED);
         }
     },
@@ -534,12 +541,15 @@
      * Returns an OpenLayers MapGuide layer object
      */
     createOLLayer: function(layerName, bIsBaseLayer, bSingleTile, behaviour) {
+      if ( !(this.siteVersion[0]>1 && this.siteVersion[2]>=0 && this.siteVersion[3]>2) ) { //v2.0.x or higher
+        this.selectionAsOverlay = false;
+      }
       var layerOptions = {
         units: this.units,
         isBaseLayer: bIsBaseLayer,
         maxExtent: this._oMaxExtent,
         maxResolution: 'auto',
-        useOverlay: true, //this.selectionAsOverlay,
+        useOverlay: this.selectionAsOverlay,
         ratio: this.ratio
       };
       if (!/WebKit/.test(navigator.userAgent)) {
@@ -579,7 +589,6 @@
         
         if (behaviour != null) {
           params.behavior = behaviour;
-          params.version = "2.0.0";
           params.selectioncolor = this.selectionColor;
           params.format = this.selectionFormat;
         }

Modified: trunk/MapGuide/php/CreateSession.php
===================================================================
--- trunk/MapGuide/php/CreateSession.php	2008-10-30 19:00:30 UTC (rev 1624)
+++ trunk/MapGuide/php/CreateSession.php	2008-10-30 19:39:28 UTC (rev 1625)
@@ -29,18 +29,21 @@
  *****************************************************************************/
 
 include('Common.php');
+include('Utilities.php');
 include('../../common/php/Utilities.php');
 
 try {
     $site = $siteConnection->GetSite();
     $sessionId =  $site->CreateSession();
     $user->SetMgSessionId($sessionId);
+    $siteVersion = GetSiteVersion();
 
     header('Content-type: text/x-json');
     header('X-JSON: true');
     $result = null;
     $result->sessionId = $sessionId;
     $result->userName = $username;
+    $result->siteVersion = $siteVersion;
     echo var2json($result);
     
     /* start a php session in the web tier as well, using same session id */

Modified: trunk/lib/OpenLayers/OpenLayers.js
===================================================================
--- trunk/lib/OpenLayers/OpenLayers.js	2008-10-30 19:00:30 UTC (rev 1624)
+++ trunk/lib/OpenLayers/OpenLayers.js	2008-10-30 19:39:28 UTC (rev 1625)
@@ -192,7 +192,6 @@
             "OpenLayers/Tween.js",
             "Rico/Corner.js",
             "Rico/Color.js",
-            "Gears/gears_init.js",
             "OpenLayers/Ajax.js",
             "OpenLayers/Request.js",
             "OpenLayers/Request/XMLHttpRequest.js",
@@ -1655,7 +1654,7 @@
                 var postChunk = relStr.substr(index + 3);                
                 relStr = prevChunk + postChunk;
             }
-        } while(index != -1)
+        } while(index != -1);
 
         var windowAnchor = document.createElement("a");
         var windowUrl = window.location.href;
@@ -4564,7 +4563,23 @@
     display: function(display) {
         this.imageDiv.style.display = (display) ? "" : "none"; 
     },
+    
 
+    /**
+     * APIMethod: isDrawn
+     * 
+     * Returns:
+     * {Boolean} Whether or not the icon is drawn.
+     */
+    isDrawn: function() {
+        // nodeType 11 for ie, whose nodes *always* have a parentNode
+        // (of type document fragment)
+        var isDrawn = (this.imageDiv && this.imageDiv.parentNode && 
+                       (this.imageDiv.parentNode.nodeType != 11));    
+
+        return isDrawn;   
+    },
+
     CLASS_NAME: "OpenLayers.Icon"
 });
 /* ======================================================================
@@ -8947,7 +8962,7 @@
 };
 
 /** 
- * Function: loadURL
+ * APIFunction: loadURL
  * Background load a document.  For more flexibility in using XMLHttpRequest,
  *     see the <OpenLayers.Request> methods.
  *
@@ -12228,6 +12243,17 @@
     },
 
     /**
+     * APIMethod: isDrawn
+     * 
+     * Returns:
+     * {Boolean} Whether or not the marker is drawn.
+     */
+    isDrawn: function() {
+        var isDrawn = (this.icon && this.icon.isDrawn());
+        return isDrawn;   
+    },
+
+    /**
      * Method: onScreen
      *
      * Returns:
@@ -14124,7 +14150,7 @@
         if (this.checkModifiers(evt) && 
             this.control.handleRightClicks && 
             OpenLayers.Event.isRightClick(evt)) {
-          propogate = this.rightclick(evt);
+          propagate = this.rightclick(evt);
         }
 
         return propagate;
@@ -17230,7 +17256,6 @@
             if ((marker.icon != null) && (marker.icon.imageDiv != null) &&
                 (marker.icon.imageDiv.parentNode == this.div) ) {
                 this.div.removeChild(marker.icon.imageDiv);    
-                marker.drawn = false;
             }
         }
     },
@@ -17261,10 +17286,11 @@
         if (px == null) {
             marker.display(false);
         } else {
-            var markerImg = marker.draw(px);
-            if (!marker.drawn) {
+            if (!marker.isDrawn()) {
+                var markerImg = marker.draw(px);
                 this.div.appendChild(markerImg);
-                marker.drawn = true;
+            } else if(marker.icon) {
+                marker.icon.moveTo(px);
             }
         }
     },
@@ -18243,12 +18269,12 @@
                 tileoffsetlon += tilelon;       
                 tileoffsetx += this.tileSize.w;
             } while ((tileoffsetlon <= bounds.right + tilelon * this.buffer)
-                     || colidx < minCols)  
+                     || colidx < minCols);
              
             tileoffsetlat -= tilelat;
             tileoffsety += this.tileSize.h;
         } while((tileoffsetlat >= bounds.bottom - tilelat * this.buffer)
-                || rowidx < minRows)
+                || rowidx < minRows);
         
         //shave off exceess rows and colums
         this.removeExcessTiles(rowidx, colidx);
@@ -19469,18 +19495,23 @@
     isBaseLayer: true,
     
     /** 
+     * APIProperty: singleTile
+     * {Boolean} use tile server or request single tile image. Note that using
+     *    singleTile *and* isBaseLayer false is *not recommend*: it uses synchronous
+     *    XMLHttpRequests to load tiles, and this will *lock up users browsers*
+     *    during requests if the server fails to respond.
+     **/
+    singleTile: false,
+    
+    /** 
      * APIProperty: useOverlay
      * {Boolean} flag to indicate if the layer should be retrieved using
      * GETMAPIMAGE (default) or using GETDYNAMICOVERLAY requests.
+     * Using an Ooerlay image is only available in MapGuide Enterprise 2010
+     * and MapGuide Open Source v2.0.3 or higher. 
      **/
     useOverlay: false,
     
-    /** 
-     * APIProperty: singleTile
-     * {Boolean} use tile server or request single tile image. 
-     **/
-    singleTile: false,
-    
     /**
      * Constant: TILE_PARAMS
      * {Object} Hashtable of default parameter key/value pairs for tiled layer
@@ -19502,6 +19533,18 @@
         version: '1.0.0'
     },
     
+    /**
+     * Constant: OVERLAY_PARAMS
+     * {Object} Hashtable of default parameter key/value pairs for untiled layer
+     */
+    OVERLAY_PARAMS: {
+        operation: 'GETDYNAMICMAPOVERLAYIMAGE',
+        format: 'PNG',
+        locale: 'en',
+        clip: '1',
+        version: '2.1.0'
+    },
+    
     /** 
      * Property: defaultSize
      * {<OpenLayers.Size>} Tile size as produced by MapGuide server
@@ -19519,12 +19562,11 @@
      * 'session', or 'mapDefinition' and 'locale'.  
      *
      * For untiled overlay layers (singleTile=true and isBaseLayer=false), 
-     * mapName and session are required parameters for the Layer constructor.
+     * mapName and session are required parameters for the Layer constructor.  
+     * Also NOTE: untiled overlay layers issues a synchronous AJAX request 
+     * before the image request can be issued so the users browser may lock
+     * up if the MG Web tier does not respond in a timely fashion.
      *
-     * If the useOverlay flag is set to true, the image request will use
-     * GETDYNAMICOVERLAY instead of GETMAPIMAGE and some additonal parameters
-     * will be available as per http://trac.osgeo.org/mapguide/wiki/MapGuideRfc38 
-     *
      * NOTE: MapGuide OS uses a DPI value and degrees to meters conversion 
      * factor that are different than the defaults used in OpenLayers, 
      * so these must be adjusted accordingly in your application.  
@@ -19571,16 +19613,23 @@
                                 (this.transparent != true));
         }
 
+        if (options && options.useOverlay!=null) {
+          this.useOverlay = options.useOverlay;
+        }
+        
         //initialize for untiled layers
         if (this.singleTile) {
+          if (this.useOverlay) {
             OpenLayers.Util.applyDefaults(
                            this.params,
+                           this.OVERLAY_PARAMS
+                           );
+          } else {
+            OpenLayers.Util.applyDefaults(
+                           this.params,
                            this.SINGLE_TILE_PARAMS
                            );
-            if (options.useOverlay!=null) {
-              this.useOverlay = options.useOverlay;
-            }
-                           
+          }         
         } else {
             //initialize for tiled layers
             OpenLayers.Util.applyDefaults(
@@ -19647,19 +19696,13 @@
 
         if (this.singleTile) {
           //set up the call for GETMAPIMAGE or GETDYNAMICMAPOVERLAY
-          var params = {};
-          
-          if (this.useOverlay) {
-            // in this case the main image operation is remapped to this
-            params.operation = "GETDYNAMICMAPOVERLAYIMAGE";
-            
-          } else {
-            params.setdisplaydpi = OpenLayers.DOTS_PER_INCH;   
-            params.setdisplayheight = mapSize.h*this.ratio;
-            params.setdisplaywidth = mapSize.w*this.ratio;
-            params.setviewcenterx = center.lon;
-            params.setviewcentery = center.lat;
-            params.setviewscale = this.map.getScale();
+          var params = {
+            setdisplaydpi: OpenLayers.DOTS_PER_INCH,
+            setdisplayheight: mapSize.h*this.ratio,
+            setdisplaywidth: mapSize.w*this.ratio,
+            setviewcenterx: center.lon,
+            setviewcentery: center.lat,
+            setviewscale: this.map.getScale()
           }
           
           //construct the full URL
@@ -19784,82 +19827,6 @@
         };
     },
     
-    /**
-     * Method: moveTo
-     * Override of OpenLayers.Grid.moveTo to call MGOS asynchronously for 
-     * overlay layers.
-     * This function is called whenever the map is moved. All the moving
-     * of actual 'tiles' is done by the map, but moveTo's role is to accept
-     * a bounds and make sure the data that that bounds requires is pre-loaded.
-     *
-     * Parameters:
-     * bounds - {<OpenLayers.Bounds>}
-     * zoomChanged - {Boolean}
-     * dragging - {Boolean}
-     */
-    moveTo:function(bounds, zoomChanged, dragging) {
-        OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this, arguments);
-        
-        bounds = bounds || this.map.getExtent();
-
-        if (bounds != null) {
-             
-            // if grid is empty or zoom has changed, we *must* re-tile
-            var forceReTile = !this.grid.length || zoomChanged;
-
-            // total bounds of the tiles
-            var tilesBounds = this.getTilesBounds();            
-      
-            if (this.singleTile) {
-                
-                // We want to redraw whenever even the slightest part of the 
-                //  current bounds is not contained by our tile.
-                //  (thus, we do not specify partial -- its default is false)
-                if ( forceReTile || 
-                     (!dragging && !tilesBounds.containsBounds(bounds))) {
-                    if (this.useOverlay) {
-                        var center = bounds.getCenterLonLat();
-                        var mapSize = this.map.getCurrentSize();
-                      
-                        //first call GETVISIBLEMAPEXTENT to set the extent
-                        //and continue on in the callback asynchronously
-                        var getVisParams = {};
-                        getVisParams.operation = "GETVISIBLEMAPEXTENT";
-                        getVisParams.version = "1.0.0";
-                        getVisParams.setdisplaydpi = OpenLayers.DOTS_PER_INCH;   
-                        getVisParams.setdisplayheight = mapSize.h*this.ratio;
-                        getVisParams.setdisplaywidth = mapSize.w*this.ratio;
-                        getVisParams.setviewcenterx = center.lon;
-                        getVisParams.setviewcentery = center.lat;
-                        getVisParams.setviewscale = this.map.getScale();
-                        getVisParams.format = 'text/xml';
-                        url = this.getFullRequestString( getVisParams );
-                        
-                        OpenLayers.Request.GET({
-                            url: url, 
-                            success: OpenLayers.Function.bind(this.initSingleTile, this, bounds)});
-            
-                    } else {
-                        this.initSingleTile(bounds);
-                    }
-                }
-            } else {
-             
-                // if the bounds have changed such that they are not even 
-                //  *partially* contained by our tiles (IE user has 
-                //  programmatically panned to the other side of the earth) 
-                //  then we want to reTile (thus, partial true).  
-                //
-                if (forceReTile || !tilesBounds.containsBounds(bounds, true)) {
-                    this.initGriddedTiles(bounds);
-                } else {
-                    //we might have to shift our buffer tiles
-                    this.moveGriddedTiles(bounds);
-                }
-            }
-        }
-    },
-    
     CLASS_NAME: "OpenLayers.Layer.MapGuide"
 });
 /* ======================================================================
@@ -21528,9 +21495,7 @@
                 this.preFeatureInsert(feature);
             }
 
-            if (this.drawn) {
-                this.drawFeature(feature);
-            }
+            this.drawFeature(feature);
             
             if (notify) {
                 this.events.triggerEvent("featureadded", {
@@ -21649,6 +21614,12 @@
      * style - {Object} Symbolizer hash or {String} renderIntent
      */
     drawFeature: function(feature, style) {
+        // don't try to draw the feature with the renderer if the layer is not 
+        // drawn itself
+        if (!this.drawn) {
+            return
+        }
+        
         if (typeof style != "object") {
             var renderIntent = typeof style == "string" ?
                 style : feature.renderIntent;

Modified: trunk/templates/mapguide/standard/ApplicationDefinition.xml
===================================================================
--- trunk/templates/mapguide/standard/ApplicationDefinition.xml	2008-10-30 19:00:30 UTC (rev 1624)
+++ trunk/templates/mapguide/standard/ApplicationDefinition.xml	2008-10-30 19:39:28 UTC (rev 1625)
@@ -16,8 +16,8 @@
         <Extension>
           <ResourceId>Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition</ResourceId>
           <SelectionAsOverlay>true</SelectionAsOverlay>
-          <SelectionFormat>PNG8</SelectionFormat>
-          <SelectionColor>0xFF0000</SelectionColor>
+          <SelectionFormat>PNG</SelectionFormat>
+          <SelectionColor>0xFF0000FF</SelectionColor>
         </Extension>
       </Map>
     </MapGroup>



More information about the fusion-commits mailing list