Digitizing and Redlining ...sample code.
Maciej Skorczewski
maciej.skorczewski at procad.pl
Wed Oct 4 09:11:01 EDT 2006
hi all!
I get x,y coorinates from user who cliked on map (he can add new point
to map like Hotels, Pubs etc.)
then i send it into php script (code below)
It works but not to end:
PROBLEMS:
1. New marker-symbol point is not in cliked point (it is upper-right
above my x,y coorinates)
2. when i want add another marker-symbol , the old disappears (so it is
still one marker)
So what is wrong whit this.
Can anybody help me?
Maciek
<?
// coordiantes of cliked point of map (user can add new point to map)
// it comes form javascript ,
$x=$_GET['x'];
$y=$_GET['y'];
require_once 'utilityfunctions.php';
//this file come form sample aplication Sheboygan
//so look there what is inside
require_once 'findparcelfunctions.php';
require_once('../common.php');
require_once($webExtensionsDirectory .
'www/mapviewerphp/layerdefinitionfactory.php');
try
{
//---------------------------------------------------//
// Initialize
MgInitializeWebTier($webconfigFilePath);
$mgSessionId = ($_SERVER['REQUEST_METHOD'] ==
"POST")?$_POST['SESSION']: $_GET['SESSION'];
$userInfo = new MgUserInformation($mgSessionId);
$siteConnection = new MgSiteConnection();
$siteConnection->Open($userInfo);
$parcelMarkerFeatureSourceId = new
MgResourceIdentifier("Session:".$mgSessionId."//PropertyMarker.FeatureSource");
$parcelMarkerCommands = new MgFeatureCommandCollection();
$resourceService =
$siteConnection->CreateService(MgServiceType::ResourceService);
$featureService =
$siteConnection->CreateService(MgServiceType::FeatureService);
//---------------------------------------------------//
// Open the map
$map = new MgMap();
$map->Open($resourceService, 'town');
$parcelMarkerLayer = GetLayerByName($map,'ParcelMarker');
if ($parcelMarkerLayer == null)
{
CreateParcelMarkerFeatureSource($featureService,
$parcelMarkerFeatureSourceId);
$parcelMarkerLayer =
CreateParcelMarkerLayer($resourceService, $parcelMarkerFeatureSourceId,
$mgSessionId);
$map->GetLayers()->Insert(0, $parcelMarkerLayer);
}
else
{
$parcelMarkerCommands->Add(new
MgDeleteFeatures('ParcelMarker', "ID like '%'"));
}
//Creating the point
$geometryFactory = new MgGeometryFactory();
$coordinate = $geometryFactory->CreateCoordinateXY($x, $y);
$point = $geometryFactory->CreatePoint($coordinate);
//Define a property collection
$geometryReaderWriter = new MgAgfReaderWriter();
$properties = new MgPropertyCollection();
$properties->Add(new MgStringProperty('Owner','Hotel'));
$properties->Add(new MgGeometryProperty('Location',
$geometryReaderWriter->Write($point)));
//Create an insert command for this property.
$parcelMarkerCommands->Add(new MgInsertFeatures('ParcelMarker',
$properties));
// If the parcel command set is non empty, then call the
// UpdateFeatures method to apply the commands to the
// temporary feature source. Then ensure the Parcel Marker
// Layer is visible and force a refresh.
if ($parcelMarkerCommands->GetCount() > 0)
{
$featureService->UpdateFeatures($parcelMarkerFeatureSourceId,
$parcelMarkerCommands, false);
$parcelMarkerLayer->SetVisible(true);
//$parcelMarkerLayer->ForceRefresh();
$sessionIdName = "Session:$mgSessionId//town.Map";
$sessionResourceID = new MgResourceIdentifier($sessionIdName);
$sessionResourceID->Validate();
$map->Save($resourceService, $sessionResourceID);
$mapUpdated = false;
}
else
{
echo '';
}
}
catch (MgException $e)
{
echo "<script language=\"javascript\" type=\"text/javascript\"> \n";
echo " alert(\" " . $e->GetMessage() . " \"); \n";
echo "</script> \n";
}
?>
--
Maciej Skorczewski
More information about the Mapguide-users
mailing list