[mapserver-commits] r7244 - in trunk/mapserver: . mapscript/csharp/examples mapscript/doc mapscript/swiginc

svn at osgeo.org svn at osgeo.org
Sat Jan 5 10:50:54 EST 2008


Author: tamas
Date: 2008-01-05 10:50:53 -0500 (Sat, 05 Jan 2008)
New Revision: 7244

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapobject.c
   trunk/mapserver/mapscript/csharp/examples/drawquery.cs
   trunk/mapserver/mapscript/doc/mapscript.txt
   trunk/mapserver/mapscript/swiginc/map.i
   trunk/mapserver/mapscript/swiginc/rect.i
   trunk/mapserver/mapserver.h
Log:
Implement mapObj.setCenter, mapObj.offsetExtent, mapObj.scaleExtent, rectObj.getCenter at the SWIG API (#2346)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2008-01-03 17:42:52 UTC (rev 7243)
+++ trunk/mapserver/HISTORY.TXT	2008-01-05 15:50:53 UTC (rev 7244)
@@ -12,6 +12,8 @@
 
 Current Version (5.1-dev, SVN trunk):
 -------------------------------------
+- Implement mapObj.setCenter, mapObj.offsetExtent, mapObj.scaleExtent, 
+  rectObj.getCenter at the SWIG API (#2346)
 
 - mapogcfilter.c: use USE_LIBXML2 in ifdefs (#2416)
 

Modified: trunk/mapserver/mapobject.c
===================================================================
--- trunk/mapserver/mapobject.c	2008-01-03 17:42:52 UTC (rev 7243)
+++ trunk/mapserver/mapobject.c	2008-01-05 15:50:53 UTC (rev 7244)
@@ -256,6 +256,65 @@
 }
 
 /************************************************************************/
+/*                           msMapOffsetExtent()                        */
+/************************************************************************/
+
+int msMapOffsetExtent( mapObj *map, double x, double y) 
+{ 
+	return msMapSetExtent( map, 
+                        map->extent.minx + x, map->extent.miny + y, 
+		                map->extent.maxx + x, map->extent.maxy + y);
+}
+
+/************************************************************************/
+/*                           msMapScaleExtent()                         */
+/************************************************************************/
+
+int msMapScaleExtent( mapObj *map, double zoomfactor, 
+					 double minscaledenom, double maxscaledenom) 
+{ 
+	double geo_width, geo_height, center_x, center_y, md;
+
+	if (zoomfactor <= 0.0) {
+		msSetError(MS_MISCERR, "The given zoomfactor is invalid", "msMapScaleExtent()"); 
+	}
+
+	geo_width = map->extent.maxx - map->extent.minx;
+    geo_height = map->extent.maxy - map->extent.miny;
+
+    center_x = map->extent.minx + geo_width * 0.5;
+    center_y = map->extent.miny + geo_height * 0.5;
+
+	geo_width *= zoomfactor;
+
+	if (minscaledenom > 0 || maxscaledenom > 0) {
+		/* ensure we are within the valid scale domain */
+		md = (map->width-1)/(map->resolution * msInchesPerUnit(map->units, center_y));
+		if (minscaledenom > 0 && geo_width < minscaledenom * md)
+			geo_width = minscaledenom * md;
+		if (maxscaledenom > 0 && geo_width > maxscaledenom * md)
+			geo_width = maxscaledenom * md;
+	}
+
+	geo_width *= 0.5;
+	geo_height = geo_width * map->height / map->width;
+	
+	return msMapSetExtent( map, 
+                        center_x - geo_width, center_y - geo_height, 
+		                center_x + geo_width, center_y + geo_height);
+}
+
+/************************************************************************/
+/*                           msMapSetCenter()                           */
+/************************************************************************/
+
+int msMapSetCenter( mapObj *map, pointObj *center) 
+{ 
+	return msMapOffsetExtent(map, center->x - (map->extent.minx + map->extent.maxx) * 0.5,
+		                          center->y - (map->extent.miny + map->extent.maxy) * 0.5);
+}
+
+/************************************************************************/
 /*                           msMapSetRotation()                         */
 /************************************************************************/
 

Modified: trunk/mapserver/mapscript/csharp/examples/drawquery.cs
===================================================================
--- trunk/mapserver/mapscript/csharp/examples/drawquery.cs	2008-01-03 17:42:52 UTC (rev 7243)
+++ trunk/mapserver/mapscript/csharp/examples/drawquery.cs	2008-01-05 15:50:53 UTC (rev 7244)
@@ -98,8 +98,12 @@
             // setting the map extent to the result bounds
 			if (query_bounds != null) 
 			{
-				if (zoomToResults)
+				if (zoomToResults) 
+				{
 					map.setExtent(query_bounds.minx, query_bounds.miny, query_bounds.maxx, query_bounds.maxy);
+					map.scaleExtent(1.2, 0, 0); // increasing the visible area
+					Console.WriteLine("Current map scale: 1:" + (int)map.scaledenom);
+				}
 			}
 			else
 				Console.WriteLine("The query returned 0 results ...");

Modified: trunk/mapserver/mapscript/doc/mapscript.txt
===================================================================
--- trunk/mapserver/mapscript/doc/mapscript.txt	2008-01-03 17:42:52 UTC (rev 7243)
+++ trunk/mapserver/mapscript/doc/mapscript.txt	2008-01-05 15:50:53 UTC (rev 7244)
@@ -2129,6 +2129,21 @@
 
 setExtent( float minx, float miny, float miny, float maxy ) : int
     Set the map extent, returns MS_SUCCESS or MS_FAILURE.
+    
+offsetExtent( float x, float y) : int
+    Offset the map extent based on the given distances in map coordinates, 
+    returns MS_SUCCESS or MS_FAILURE.
+    
+scaleExtent( float zoomfactor, float minscaledenom, float maxscaledenom) : int
+    Scale the map extent using the zoomfactor and ensure the extent
+    within the minscaledenom and maxscaledenom domain.
+    If minscaledenom and/or maxscaledenom is 0 then the parameter is
+    not taken into account.
+    returns MS_SUCCESS or MS_FAILURE.
+    
+setCenter( pointObj_ center ) : int
+    Set the map center to the given map point,
+    returns MS_SUCCESS or MS_FAILURE.
 
 setFontSet( string filename ) : int
     Load fonts defined in *filename* into map fontset.  The existing

Modified: trunk/mapserver/mapscript/swiginc/map.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/map.i	2008-01-03 17:42:52 UTC (rev 7243)
+++ trunk/mapserver/mapscript/swiginc/map.i	2008-01-05 15:50:53 UTC (rev 7244)
@@ -85,6 +85,19 @@
     int setExtent(double minx, double miny, double maxx, double maxy) {	
 	return msMapSetExtent( self, minx, miny, maxx, maxy );
     }
+    
+    int offsetExtent(double x, double y) {	
+	return msMapOffsetExtent( self, x, y );
+    }
+    
+    int scaleExtent(double zoomfactor, 
+					 double minscaledenom, double maxscaledenom) {	
+	return msMapScaleExtent( self, zoomfactor, minscaledenom, maxscaledenom );
+    }
+    
+    int setCenter(pointObj *center) {	
+	return msMapSetCenter( self, center );
+    }
 
     /* recent rotation work makes setSize the only reliable 
        method for changing the image size.  direct access is deprecated. */

Modified: trunk/mapserver/mapscript/swiginc/rect.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/rect.i	2008-01-03 17:42:52 UTC (rev 7243)
+++ trunk/mapserver/mapscript/swiginc/rect.i	2008-01-05 15:50:53 UTC (rev 7244)
@@ -69,6 +69,21 @@
     
         return MS_SUCCESS;
     }
+    
+    %newobject getCenter;
+    pointObj *getCenter() 
+    {
+		pointObj *center;
+        center = (pointObj *)calloc(1, sizeof(pointObj));
+        if (!center) {
+            msSetError(2, "Failed to allocate memory for point", "getCenter()");
+            return NULL;
+        }
+        center->x = (self->minx + self->maxx)/2;
+        center->y = (self->miny + self->maxy)/2;
+        
+        return center;
+    }
 
     %newobject toPolygon;
     shapeObj *toPolygon() 

Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h	2008-01-03 17:42:52 UTC (rev 7243)
+++ trunk/mapserver/mapserver.h	2008-01-05 15:50:53 UTC (rev 7244)
@@ -1488,6 +1488,10 @@
 
 MS_DLL_EXPORT int msMapSetExtent(mapObj *map, double minx, double miny, 
                                  double maxx, double maxy);
+MS_DLL_EXPORT int msMapOffsetExtent( mapObj *map, double x, double y);
+MS_DLL_EXPORT int msMapScaleExtent( mapObj *map, double zoomfactor, 
+					 double minscaledenom, double maxscaledenom);
+MS_DLL_EXPORT int msMapSetCenter( mapObj *map, pointObj *center);
 MS_DLL_EXPORT int msMapSetRotation( mapObj *map, double rotation_angle );
 MS_DLL_EXPORT int msMapSetSize( mapObj *map, int width, int height );
 MS_DLL_EXPORT int msMapSetSize( mapObj *map, int width, int height );



More information about the mapserver-commits mailing list