[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
"iFrameMap"
1. Create a Invoke Script button in your layout that will call Javascript
code from your main page (i.e. home.htm).
top.digPolygon()
2. Create Javascript in your main page - that will call OnPolygonDigitized
once the user draws the poly.
function digPolygon()
{
top.parent.iFrameMap.mapFrame.DigitizePolygon(top.OnPolygonDigitized);
}
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
top.parent.iFrameMap.GetScriptFrame().location.href="insertNewPolygon.php?myGEOM="+POLYSTRING;
}
Then the PHP is something like this.
<?php
$conn=odbc_connect('mydatabse','sa','password');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql="insert into mytable(geom) VALUES('"
.stripslashes($_REQUEST["POLYSTRING"])."')"";
$rs=odbc_exec($conn,$sql);
odbc_close($conn);
?>
--
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