[mapguide-users] Re: Need to draw lines, points, possibly polygons to database

GordonL gordon.luckett at arrowgeomatics.com
Thu Oct 13 09:52:26 EDT 2011

Ok, big assumption here - your current map is in the same coordinate system
as your data in SQL Server.
Another assumption, your basic web layout is in an iframe/frame called

1. Create a Invoke Script button in your layout that will call Javascript
code from your main page (i.e. home.htm).

2. Create Javascript in your main page - that will call OnPolygonDigitized
once the user draws the poly.

    function digPolygon()

3. Catch the linestring returned from the user.
 function OnPolygonDigitized(lineString)
    var totalCoords = "";
    var coords="";
    var POLYSTRING="";

	for(var i=0;i<lineString.Count;i++)
	    point  = lineString.Point(i);
	    coords = point.X + " " + point.Y;
                 totalCoords = coords + ","  totalCoords;
        //take off the extra comma
        totalCoords = totalCoords.substr(0,totalCoords.length-1); 

       //NOTE:  SQL Server needs a polygon like this: 'POLYGON((30 30, 50
30, 50 50, 30 50, 30 30))'

        POLYSTRING = "'POLYGON((" + totalCoords + "))'";

    //now you have POLYSTRING send it to an insert statement 

Then the PHP is something like this.
                if (!$conn)
                        {exit("Connection Failed: " . $conn);}
                $sql="insert into  mytable(geom) VALUES('"

View this message in context: http://osgeo-org.1803224.n2.nabble.com/Need-to-draw-lines-points-possibly-polygons-to-database-tp6860154p6888997.html
Sent from the MapGuide Users mailing list archive at Nabble.com.

More information about the mapguide-users mailing list