[fusion-commits] r1838 - trunk/layers/MapGuide

svn_fusion at osgeo.org svn_fusion at osgeo.org
Wed Apr 29 11:44:26 EDT 2009


Author: pagameba
Date: 2009-04-29 11:44:26 -0400 (Wed, 29 Apr 2009)
New Revision: 1838

Modified:
   trunk/layers/MapGuide/MapGuideViewerApi.js
Log:
re #249, #250 update viewer API to correctly locate the Fusion instance and add a ClearDigitization method.

Modified: trunk/layers/MapGuide/MapGuideViewerApi.js
===================================================================
--- trunk/layers/MapGuide/MapGuideViewerApi.js	2009-04-29 15:05:58 UTC (rev 1837)
+++ trunk/layers/MapGuide/MapGuideViewerApi.js	2009-04-29 15:44:26 UTC (rev 1838)
@@ -30,6 +30,13 @@
 var mgApimgApiActiveWidget = null;
 var mgApiActiveControl = null;
 var mgApiDrawControls;
+var mgApiDigitizingLayer = null;
+var mgApiInitialized = false;
+var MainFusionWindow = GetFusionWindow();
+var OpenLayers = MainFusionWindow.OpenLayers;
+var Fusion = MainFusionWindow.Fusion;
+var Class = MainFusionWindow.Class;
+var Object = MainFusionWindow.Object;
 
 function Refresh() {
     var Fusion = window.top.Fusion;
@@ -76,6 +83,12 @@
     mgApiStartDigitizing('polygon', handler)
 }
 
+function ClearDigitization() {
+    if (mgApiDigitizingLayer) {
+        mgApiDigitizingLayer.removeFeatures(mgApiDigitizingLayer.features);
+    }
+}
+
 //Theses are the Geometry classes used in the MapGuide Viewer API
 function Point(x, y) {
     this.X = x;
@@ -129,6 +142,7 @@
 //The following methods are private and not intended for use by applications
 //
 function mgApiStartDigitizing(type, handler) {
+    mgApiInit();
     if (handler) {
       var Fusion = window.top.Fusion;
       var mapWidget = Fusion.getWidgetById(mgApiMapWidgetId);
@@ -204,13 +218,17 @@
 
 //set up of digitizing tools once everything is initialized
 function mgApiInit() {
+    if (mgApiInitialized) {
+        return;
+    }
+    mgApiInitialized = true;
   var map = window.top.Fusion.getWidgetById(mgApiMapWidgetId).oMapOL;
   
-  var digiLayer = new OpenLayers.Layer.Vector("Digitizing Layer", {styleMap: mgApiStyleMap});
-  map.addLayers([digiLayer]);
+  mgApiDigitizingLayer = new OpenLayers.Layer.Vector("Digitizing Layer", {styleMap: mgApiStyleMap});
+  map.addLayers([mgApiDigitizingLayer]);
 
   mgApiDrawControls = {
-      point: new OpenLayers.Control.DrawFeature(digiLayer,
+      point: new OpenLayers.Control.DrawFeature(mgApiDigitizingLayer,
               OpenLayers.Handler.Point, {
                 handlerOptions: {
                   layerOptions: {
@@ -218,7 +236,7 @@
                   }
                 }
               }),
-      line: new OpenLayers.Control.DrawFeature(digiLayer,
+      line: new OpenLayers.Control.DrawFeature(mgApiDigitizingLayer,
                   OpenLayers.Handler.Path, {
                     handlerOptions: {
                       freehandToggle: null, 
@@ -233,7 +251,7 @@
                       'point': mgApiCheckLine
                     }
                   }),
-      linestr: new OpenLayers.Control.DrawFeature(digiLayer,
+      linestr: new OpenLayers.Control.DrawFeature(mgApiDigitizingLayer,
                   OpenLayers.Handler.Path, {
                     handlerOptions: {
                       freehand: false, 
@@ -244,7 +262,7 @@
                       }
                     }
                   }),
-      rectangle: new OpenLayers.Control.DrawFeature(digiLayer,
+      rectangle: new OpenLayers.Control.DrawFeature(mgApiDigitizingLayer,
                   OpenLayers.Handler.RegularPolygon, {
                     handlerOptions: {
                       persist: true, 
@@ -256,7 +274,7 @@
                       }
                     }
                   }),
-      polygon: new OpenLayers.Control.DrawFeature(digiLayer,
+      polygon: new OpenLayers.Control.DrawFeature(mgApiDigitizingLayer,
                   OpenLayers.Handler.Polygon, {
                     handlerOptions: {
                       freehand: false, 
@@ -286,4 +304,18 @@
   }
 }
 
-
+/* locate the Fusion window */
+function GetFusionWindow() {
+    var curWindow = window;
+    while (!curWindow.Fusion) {
+        if (curWindow.parent && curWindow != curWindow.parent) {
+            curWindow = curWindow.parent;
+        } else if(curWindow.opener) {
+            curWindow = curWindow.opener;
+        } else {
+            alert('Could not find Fusion instance');
+            break;
+        }
+    }
+    return curWindow;
+}



More information about the fusion-commits mailing list