From julianferes at gmail.com Mon Jul 13 10:08:15 2015 From: julianferes at gmail.com (=?UTF-8?Q?Juli=C3=A1n_Felipe?=) Date: Mon, 13 Jul 2015 12:08:15 -0500 Subject: [OSGeo-Edu] Consultation mapguide to be send Message-ID: Hello Mapguides List, I am developing an aplication about vehicle tracking and i have beed reading the MgOpenSourceDevGuide.pdf. I need to draw the car image about location on the map but i don?t understand how to do it. Coul you help me with this please. My code is the follow: loadXML($layerDefinition); // Save the new layer definition to the session repository $byteSource = new MgByteSource($layerDefinition, strlen($layerDefinition)); echo "
echo 111
"; $byteSource->SetMimeType(MgMimeType::Xml); echo "
echo 2222
"; echo "session: ".$sessionId; $resourceID = new MgResourceIdentifier("Session:$sessionId//$layerName.LayerDefinition"); echo "
echo 3333
"; $resourceService->SetResource($resourceID, $byteSource->GetReader(), null); echo "
echo 4444
"; $newLayer = add_layer_resource_to_map($resourceID, $resourceService, $layerName, $layerLegendLabel, $map); echo "
echo 5555
"; return $newLayer; } function add_layer_resource_to_map($layerResourceID, $resourceService, $layerName, $layerLegendLabel, $map) // Adds a layer defition (which can be stored either in the Library or a session // repository) to the map. // Returns the layer. { $newLayer = new MgLayer($layerResourceID, $resourceService); // Add the new layer to the map's layer collection $newLayer->SetName($layerName); $newLayer->SetVisible(true); $newLayer->SetLegendLabel($layerLegendLabel); $newLayer->SetDisplayInLegend(true); $newLayer->SetDisplayInLegend(true); $layerCollection = $map->GetLayers(); if (! $layerCollection->Contains($layerName) ) { // Insert the new layer at position 0 so it is at the top // of the drawing order $layerCollection->Insert(0, $newLayer); } return $newLayer; } ?> Open($userInfo); echo "Instanciamos Feature service

"; $featureService = $siteConnection->CreateService(MgServiceType::FeatureService); echo "Instanciamos Resource service

"; $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService); echo "Instanciamos ResourceIdentifier

"; $bufferFeatureResId = new MgResourceIdentifier("Session:" . $mgSessionId . "//Buffer.FeatureSource"); $map = new MgMap($siteConnection); $map->Open($resourceService, $mgMapName); // Set up some objects for coordinate conversion $mapWktSrs = $map->GetMapSRS(); $agfReaderWriter = new MgAgfReaderWriter(); $wktReaderWriter = new MgWktReaderWriter(); echo "Creando FeatureSource

"; echo "
echo 1
"; // Create a temporary feature source $bufferClass = new MgClassDefinition(); $className = 'BufferClass'; $bufferClass->SetName('BufferClass'); $properties = $bufferClass->GetProperties(); $idProperty = new MgDataPropertyDefinition('ID'); $idProperty->SetDataType(MgPropertyType::Int32); $idProperty->SetReadOnly(true); $idProperty->SetNullable(false); $idProperty->SetAutoGeneration(true); $properties->Add($idProperty); $polygonProperty = new MgGeometricPropertyDefinition('BufferGeometry'); $polygonProperty->SetGeometryTypes(MgFeatureGeometricType::Point); $polygonProperty->SetHasElevation(false); $polygonProperty->SetHasMeasure(false); $polygonProperty->SetReadOnly(false); $polygonProperty->SetSpatialContextAssociation('defaultSrs'); $properties->Add($polygonProperty); $idProperties = $bufferClass->GetIdentityProperties(); $idProperties->Add($idProperty); $bufferClass->SetDefaultGeometryPropertyName('BufferGeometry'); $bufferSchema = new MgFeatureSchema('BufferLayerSchema', 'temporary schema to hold a buffer'); $bufferSchema->GetClasses()->Add($bufferClass); $sdfParams = new MgCreateSdfParams('defaultSrs', $mapWktSrs, $bufferSchema); $featureService->CreateFeatureSource($bufferFeatureResId, $sdfParams); echo "
echo 2
"; //--------------------Creamos Layer Definition-------------------------------// // ... //---------------------------------------------------// echo "
echo 3
"; $factory = new LayerDefinitionFactory(); echo "
echo 4
"; // Create a mark symbol $resourceId = 'Library://Samples/Sheboygan/Symbols/BasicSymbols.SymbolLibrary'; $symbolName = 'PushPin'; $width = '100'; // points $height = '100'; // points $color = 'FFFF0000'; $markSymbol = $factory->CreateMarkSymbol($resourceId, $symbolName, $width, $height, $color); // Create a text symbol $text = "ID"; $fontHeight="100"; $foregroundColor = 'FF000000'; $textSymbol = $factory->CreateTextSymbol($text, $fontHeight, $foregroundColor); // Create a point rule. $legendLabel = 'trees'; $filter = ''; $pointRule = $factory->CreatePointRule($legendLabel, $filter, $textSymbol, $markSymbol); // Create a point type style. $pointTypeStyle = $factory->CreatepointTypeStyle($pointRule); // Create a scale range. $minScale = '0'; $maxScale = '1000000000000'; $pointScaleRange = $factory->CreateScaleRange($minScale, $maxScale, $pointTypeStyle); // Create the layer definiton. $featureClass = 'Library://Tests/Trees.FeatureSource'; $featureName = 'Default:Trees'; $geometry = 'SHPGEOM'; $layerDefinition = $factory->CreateLayerDefinition($bufferFeatureResId, $featureName, $geometry, $pointScaleRange); $layerName = "capaferez"; $layerLegendLabel = "capaferez"; $nuevaLayer = add_layer_definition_to_map($layerDefinition, $layerName, $layerLegendLabel, $mgSessionId, $resourceService, $map); echo "
inicio insercion feature actualizando fea 1
"; $commands = new MgFeatureCommandCollection(); $properties = new MgPropertyCollection(); echo "lllllllllllllllllllllllllllllllll"; // create a coordinate $geometryFactory = new MgGeometryFactory(); $coordinate = $geometryFactory->CreateCoordinateXY(-87.755686,43.719265); echo "oooooooooooooooooooooooo"; // create a point $point = $geometryFactory->CreatePoint($coordinate); echo "Creando MgPoint ..."; $pointAgfText = $wktReaderWriter->Write($point); echo "AGF Text representation of Point: $pointAgfText\n"; echo " agfByteStream ..."; $agfByteStream = $agfReaderWriter->Write($point); echo " punto creado ..."; $geometryProperty = new MgGeometryProperty('BufferGeometry', $agfByteStream); $properties->Add($geometryProperty); $insertCommand = new MgInsertFeatures($className, $properties); $commands->Add($insertCommand); echo "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"; $featureService->UpdateFeatures($bufferFeatureResId, $commands, false); echo "fffffffffffffffffffffffffffffffffff"; echo "
fin insercion feature actualizando fea 1
"; $nuevaLayer->SetVisible(true); $nuevaLayer->ForceRefresh(); $nuevaLayer->SetDisplayInLegend(true); $nuevaLayer->SetSelectable(false); //If you created a MgMap with a MgSiteConnection $map->Save(); echo "Fin creacion feature source

"; echo "

Finaliza
"; }catch (MgException $e){ echo $e->GetStackTrace() . "
"; }catch (Exception $ex) { echo 'Excepci?n capturada: ', $e->getMessage(), "\n"; } ?> -- Ing. Julian Felipe Feres Santander Ingeniero De Software -- Ing. Julian Felipe Feres Santander Ingeniero De Software -------------- next part -------------- An HTML attachment was scrubbed... URL: From sstein at geo.uzh.ch Mon Jul 13 11:18:54 2015 From: sstein at geo.uzh.ch (Stefan Steiniger) Date: 13 Jul 2015 14:18:54 -0400 Subject: [OSGeo-Edu] Consultation mapguide to be send In-Reply-To: References: Message-ID: <55A4010E.5040806@geo.uzh.ch> Hey Julian, I think you did send this question to the wrong list. Try it with the MapGuide Open Source list http://lists.osgeo.org/mailman/listinfo/mapguide-users ;) stefan Am 13.07.15 um 13:08 schrieb Juli?n Felipe: > Hello Mapguides List, > > I am developing an aplication about vehicle tracking and i have beed > reading the MgOpenSourceDevGuide.pdf. > > I need to draw the car image about location on the map but i don?t > understand how to do it. > > Coul you help me with this please. > > > My code is the follow: > > > > > > > > > function add_layer_definition_to_map($layerDefinition, $layerName, > $layerLegendLabel, $sessionId, $resourceService, $map) > // Adds the layer definition (XML) to the map. > // Returns the layer. > { > echo "Iniciando metodo add_layer_definition_to_map..."; > global $schemaDirectory; > > // Validate the XML. > $domDocument = new DOMDocument; > $domDocument->loadXML($layerDefinition); > > > // Save the new layer definition to the session repository > $byteSource = new MgByteSource($layerDefinition, > strlen($layerDefinition)); > echo "
echo 111
"; > $byteSource->SetMimeType(MgMimeType::Xml); > echo "
echo 2222
"; > echo "session: ".$sessionId; > $resourceID = new > MgResourceIdentifier("Session:$sessionId//$layerName.LayerDefinition"); > echo "
echo 3333
"; > $resourceService->SetResource($resourceID, > $byteSource->GetReader(), null); > echo "
echo 4444
"; > $newLayer = add_layer_resource_to_map($resourceID, > $resourceService, $layerName, $layerLegendLabel, $map); > echo "
echo 5555
"; > return $newLayer; > } > > > function add_layer_resource_to_map($layerResourceID, $resourceService, > $layerName, $layerLegendLabel, $map) > // Adds a layer defition (which can be stored either in the Library or a > session > // repository) to the map. > // Returns the layer. > { > $newLayer = new MgLayer($layerResourceID, $resourceService); > > // Add the new layer to the map's layer collection > $newLayer->SetName($layerName); > $newLayer->SetVisible(true); > $newLayer->SetLegendLabel($layerLegendLabel); > $newLayer->SetDisplayInLegend(true); > $newLayer->SetDisplayInLegend(true); > $layerCollection = $map->GetLayers(); > if (! $layerCollection->Contains($layerName) ) > { > // Insert the new layer at position 0 so it is at the top > // of the drawing order > $layerCollection->Insert(0, $newLayer); > } > > return $newLayer; > } > > > ?> > > > try{ > define('__ROOT__', dirname(dirname(__FILE__))); > require_once(__ROOT__.'/../phpsamples/common/common.php'); > echo "ferez".__ROOT__.'/../findaddress/layerdefinitionfactory.php'; > require_once(__ROOT__.'/findaddress/layerdefinitionfactory.php'); > > // Get the session information passed from the viewer. > $args = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST : $_GET; > $mgSessionId = $args['SESSION']; > $mgMapName = $args['MAPNAME']; > > // Initialize the web extensions, > MgInitializeWebTier ($webconfigFilePath); > // Get the user information using the session id, > // and set up a connection to the site server. > $userInfo = new MgUserInformation($mgSessionId); > $siteConnection = new MgSiteConnection(); > $siteConnection->Open($userInfo); > > echo "Instanciamos Feature service

"; > $featureService = > $siteConnection->CreateService(MgServiceType::FeatureService); > echo "Instanciamos Resource service

"; > $resourceService = > $siteConnection->CreateService(MgServiceType::ResourceService); > echo "Instanciamos ResourceIdentifier

"; > $bufferFeatureResId = new MgResourceIdentifier("Session:" . $mgSessionId > . "//Buffer.FeatureSource"); > $map = new MgMap($siteConnection); > $map->Open($resourceService, $mgMapName); > > > // Set up some objects for coordinate conversion > $mapWktSrs = $map->GetMapSRS(); > $agfReaderWriter = new MgAgfReaderWriter(); > $wktReaderWriter = new MgWktReaderWriter(); > echo "Creando FeatureSource

"; > echo "
echo 1
"; > // Create a temporary feature source > $bufferClass = new MgClassDefinition(); > $className = 'BufferClass'; > $bufferClass->SetName('BufferClass'); > $properties = $bufferClass->GetProperties(); > > $idProperty = new MgDataPropertyDefinition('ID'); > $idProperty->SetDataType(MgPropertyType::Int32); > $idProperty->SetReadOnly(true); > $idProperty->SetNullable(false); > $idProperty->SetAutoGeneration(true); > $properties->Add($idProperty); > > $polygonProperty = new MgGeometricPropertyDefinition('BufferGeometry'); > $polygonProperty->SetGeometryTypes(MgFeatureGeometricType::Point); > $polygonProperty->SetHasElevation(false); > $polygonProperty->SetHasMeasure(false); > $polygonProperty->SetReadOnly(false); > $polygonProperty->SetSpatialContextAssociation('defaultSrs'); > $properties->Add($polygonProperty); > > $idProperties = $bufferClass->GetIdentityProperties(); > $idProperties->Add($idProperty); > > $bufferClass->SetDefaultGeometryPropertyName('BufferGeometry'); > $bufferSchema = new MgFeatureSchema('BufferLayerSchema', 'temporary > schema to hold a buffer'); > $bufferSchema->GetClasses()->Add($bufferClass); > $sdfParams = new MgCreateSdfParams('defaultSrs', $mapWktSrs, $bufferSchema); > $featureService->CreateFeatureSource($bufferFeatureResId, $sdfParams); > echo "
echo 2
"; > //--------------------Creamos Layer > Definition-------------------------------// > // ... > //---------------------------------------------------// > echo "
echo 3
"; > $factory = new LayerDefinitionFactory(); > echo "
echo 4
"; > // Create a mark symbol > $resourceId = > 'Library://Samples/Sheboygan/Symbols/BasicSymbols.SymbolLibrary'; > $symbolName = 'PushPin'; > $width = '100'; // points > $height = '100'; // points > $color = 'FFFF0000'; > $markSymbol = $factory->CreateMarkSymbol($resourceId, $symbolName, > $width, $height, $color); > > // Create a text symbol > $text = "ID"; > $fontHeight="100"; > $foregroundColor = 'FF000000'; > $textSymbol = $factory->CreateTextSymbol($text, $fontHeight, > $foregroundColor); > // Create a point rule. > $legendLabel = 'trees'; > $filter = ''; > $pointRule = $factory->CreatePointRule($legendLabel, $filter, > $textSymbol, $markSymbol); > > // Create a point type style. > $pointTypeStyle = $factory->CreatepointTypeStyle($pointRule); > > // Create a scale range. > $minScale = '0'; > $maxScale = '1000000000000'; > $pointScaleRange = $factory->CreateScaleRange($minScale, $maxScale, > $pointTypeStyle); > // Create the layer definiton. > $featureClass = 'Library://Tests/Trees.FeatureSource'; > $featureName = 'Default:Trees'; > $geometry = 'SHPGEOM'; > $layerDefinition = $factory->CreateLayerDefinition($bufferFeatureResId, > $featureName, $geometry, $pointScaleRange); > $layerName = "capaferez"; > $layerLegendLabel = "capaferez"; > $nuevaLayer = add_layer_definition_to_map($layerDefinition, $layerName, > $layerLegendLabel, $mgSessionId, $resourceService, $map); > echo "
inicio insercion feature actualizando fea 1
"; > $commands = new MgFeatureCommandCollection(); > $properties = new MgPropertyCollection(); > echo "lllllllllllllllllllllllllllllllll"; > // create a coordinate > $geometryFactory = new MgGeometryFactory(); > $coordinate = $geometryFactory->CreateCoordinateXY(-87.755686,43.719265); > echo "oooooooooooooooooooooooo"; > // create a point > $point = $geometryFactory->CreatePoint($coordinate); > echo "Creando MgPoint ..."; > $pointAgfText = $wktReaderWriter->Write($point); > echo "AGF Text representation of Point: $pointAgfText\n"; > echo " agfByteStream ..."; > $agfByteStream = $agfReaderWriter->Write($point); > echo " punto creado ..."; > > $geometryProperty = new MgGeometryProperty('BufferGeometry', > $agfByteStream); > $properties->Add($geometryProperty); > > $insertCommand = new MgInsertFeatures($className, $properties); > $commands->Add($insertCommand); > > > echo "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"; > $featureService->UpdateFeatures($bufferFeatureResId, $commands, false); > echo "fffffffffffffffffffffffffffffffffff"; > echo "
fin insercion feature actualizando fea 1
"; > $nuevaLayer->SetVisible(true); > $nuevaLayer->ForceRefresh(); > $nuevaLayer->SetDisplayInLegend(true); > $nuevaLayer->SetSelectable(false); > //If you created a MgMap with a MgSiteConnection > $map->Save(); > echo "Fin creacion feature source

"; > > echo "

Finaliza
"; > }catch (MgException $e){ > echo $e->GetStackTrace() . "
"; > }catch (Exception $ex) { > echo 'Excepci?n capturada: ', $e->getMessage(), "\n"; > } > > ?> > > > > > > > > > > > -- > Ing. Julian Felipe Feres Santander > Ingeniero De Software > > > > > > -- > Ing. Julian Felipe Feres Santander > Ingeniero De Software > > > > > _______________________________________________ > Edu_discuss mailing list > Edu_discuss at lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/edu_discuss >