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

svn_fusion at osgeo.org svn_fusion at osgeo.org
Wed Apr 29 11:58:45 EDT 2009


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

Modified:
   trunk/layers/MapGuide/MapGuideViewerApi.js
Log:
re #249, #250 fix up the mapguide viewer api callbacks for digitizing Rectangles to actually return a rectangle geometry.  Also avoid the toJSONString method added to Object prototype when enumerating controls during initialization.

Modified: trunk/layers/MapGuide/MapGuideViewerApi.js
===================================================================
--- trunk/layers/MapGuide/MapGuideViewerApi.js	2009-04-29 15:44:26 UTC (rev 1838)
+++ trunk/layers/MapGuide/MapGuideViewerApi.js	2009-04-29 15:58:44 UTC (rev 1839)
@@ -161,26 +161,29 @@
 function mgApiCallHandler(evt) {
   var geom = evt.feature.geometry;
   var apiGeom = null;
-  switch (geom.CLASS_NAME) {
-    case 'OpenLayers.Geometry.Point':
-      apiGeom = new Point(geom.x, geom.y);
-      break;
-    case 'OpenLayers.Geometry.LineString':
-      apiGeom = new LineString();
-      var nodes = geom.components;
-      for (var i=0; i<nodes.length; ++i) {
-        var node = nodes[i];
-        apiGeom.AddPoint(new Point(node.x, node.y));
-      }
-      break;
-    case 'OpenLayers.Geometry.Polygon':
-      apiGeom = new LineString();
-      var nodes = geom.components[0].components;
-      for (var i=0; i<nodes.length; ++i) {
-        var node = nodes[i];
-        apiGeom.AddPoint(new Point(node.x, node.y));
-      }
-      break;
+  if (this.handler.CLASS_NAME == 'OpenLayers.Handler.RegularPolygon') {
+      var v = geom.getVertices();
+      apiGeom = new Rectangle(new Point(v[0].x, v[0].y), new Point(v[2].x, v[2].y));
+  } else {
+      switch (geom.CLASS_NAME) {
+        case 'OpenLayers.Geometry.Point':
+          apiGeom = new Point(geom.x, geom.y);
+          break;
+        case 'OpenLayers.Geometry.LineString':
+          apiGeom = new LineString();
+          var v = geom.getVertices();
+          for (var i=0; i<v.length; ++i) {
+            apiGeom.AddPoint(new Point(v[i].x, v[i].y));
+          }
+          break;
+        case 'OpenLayers.Geometry.Polygon':
+          apiGeom = new LineString();
+          var v = geom.getVertices();
+          for (var i=0; i<v.length; ++i) {
+            apiGeom.AddPoint(new Point(v[i].x, v[i].y));
+          }
+          break;
+      }      
   }
   this.userHandler(apiGeom);
   
@@ -288,8 +291,10 @@
   };
 
   for(var key in mgApiDrawControls) {
-      mgApiDrawControls[key].events.register('featureadded', null, mgApiCallHandler);
-      map.addControl(mgApiDrawControls[key]);
+      if (mgApiDrawControls[key].events) {
+          mgApiDrawControls[key].events.register('featureadded', null, mgApiCallHandler);
+          map.addControl(mgApiDrawControls[key]);          
+      }
   }
 
 }



More information about the fusion-commits mailing list