[mapserver-commits] r7245 - in branches/branch-5-0/mapserver: . mapscript/csharp/examples mapscript/doc mapscript/swiginc

svn at osgeo.org svn at osgeo.org
Sat Jan 5 11:05:15 EST 2008


Author: tamas
Date: 2008-01-05 11:05:15 -0500 (Sat, 05 Jan 2008)
New Revision: 7245

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

Modified: branches/branch-5-0/mapserver/HISTORY.TXT
===================================================================
--- branches/branch-5-0/mapserver/HISTORY.TXT	2008-01-05 15:50:53 UTC (rev 7244)
+++ branches/branch-5-0/mapserver/HISTORY.TXT	2008-01-05 16:05:15 UTC (rev 7245)
@@ -12,6 +12,9 @@
 
 Current Version (SVN branch-5-0)
 --------------------------------
+- Implement mapObj.setCenter, mapObj.offsetExtent, mapObj.scaleExtent, 
+  rectObj.getCenter at the SWIG API (#2346)
+
 - SLD using a single BBOX filter should generate an SQL ststement for 
   oracle/postgis/ogr (#2450)
 

Modified: branches/branch-5-0/mapserver/mapobject.c
===================================================================
--- branches/branch-5-0/mapserver/mapobject.c	2008-01-05 15:50:53 UTC (rev 7244)
+++ branches/branch-5-0/mapserver/mapobject.c	2008-01-05 16:05:15 UTC (rev 7245)
@@ -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: branches/branch-5-0/mapserver/mapscript/csharp/examples/drawquery.cs
===================================================================
--- branches/branch-5-0/mapserver/mapscript/csharp/examples/drawquery.cs	2008-01-05 15:50:53 UTC (rev 7244)
+++ branches/branch-5-0/mapserver/mapscript/csharp/examples/drawquery.cs	2008-01-05 16:05:15 UTC (rev 7245)
@@ -95,8 +95,12 @@
                 }
             }
             // setting the map extent to the result bounds
-            if (zoomToResults)
-                map.setExtent(query_bounds.minx, query_bounds.miny, query_bounds.maxx, query_bounds.maxy);
+			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);
+			}
         }
         catch (Exception e)
         {

Modified: branches/branch-5-0/mapserver/mapscript/doc/mapscript.txt
===================================================================
--- branches/branch-5-0/mapserver/mapscript/doc/mapscript.txt	2008-01-05 15:50:53 UTC (rev 7244)
+++ branches/branch-5-0/mapserver/mapscript/doc/mapscript.txt	2008-01-05 16:05:15 UTC (rev 7245)
@@ -2115,6 +2115,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: branches/branch-5-0/mapserver/mapscript/swiginc/map.i
===================================================================
--- branches/branch-5-0/mapserver/mapscript/swiginc/map.i	2008-01-05 15:50:53 UTC (rev 7244)
+++ branches/branch-5-0/mapserver/mapscript/swiginc/map.i	2008-01-05 16:05:15 UTC (rev 7245)
@@ -79,6 +79,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: branches/branch-5-0/mapserver/mapscript/swiginc/rect.i
===================================================================
--- branches/branch-5-0/mapserver/mapscript/swiginc/rect.i	2008-01-05 15:50:53 UTC (rev 7244)
+++ branches/branch-5-0/mapserver/mapscript/swiginc/rect.i	2008-01-05 16:05:15 UTC (rev 7245)
@@ -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: branches/branch-5-0/mapserver/mapserver.h
===================================================================
--- branches/branch-5-0/mapserver/mapserver.h	2008-01-05 15:50:53 UTC (rev 7244)
+++ branches/branch-5-0/mapserver/mapserver.h	2008-01-05 16:05:15 UTC (rev 7245)
@@ -1355,6 +1355,10 @@
 
 MS_DLL_EXPORT int msMapSetExtent(mapObj *map, double minx, double miny, 
                                  double maxx, double maxy);
+S_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