[OSGeo-Edu] Consultation mapguide to be send

Stefan Steiniger sstein at geo.uzh.ch
Mon Jul 13 11:18:54 PDT 2015


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:
>
>
>
>
> <html>
>
> <body onLoad="OnPageLoad()">
>
> <?php
> 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 "<br/> echo 111 <br/>";
>      $byteSource->SetMimeType(MgMimeType::Xml);
> echo "<br/> echo 2222 <br/>";
> echo "session: ".$sessionId;
>      $resourceID = new
> MgResourceIdentifier("Session:$sessionId//$layerName.LayerDefinition");
> echo "<br/> echo 3333 <br/>";
>      $resourceService->SetResource($resourceID,
> $byteSource->GetReader(), null);
> echo "<br/> echo 4444 <br/>";
>      $newLayer = add_layer_resource_to_map($resourceID,
> $resourceService, $layerName, $layerLegendLabel, $map);
> echo "<br/> echo 5555 <br/>";
>      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;
> }
>
>
> ?>
>
> <?php
>
> 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 <br/><br/>";
> $featureService =
> $siteConnection->CreateService(MgServiceType::FeatureService);
> echo "Instanciamos Resource service <br/><br/>";
> $resourceService =
> $siteConnection->CreateService(MgServiceType::ResourceService);
> echo "Instanciamos ResourceIdentifier <br/><br/>";
> $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 <br/><br/>";
> echo "<br/> echo 1 <br/>";
> // 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 "<br/> echo 2 <br/>";
> //--------------------Creamos Layer
> Definition-------------------------------//
> // ...
> //---------------------------------------------------//
> echo "<br/> echo 3 <br/>";
> $factory = new LayerDefinitionFactory();
> echo "<br/> echo 4 <br/>";
> // 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 "<br/> inicio insercion feature actualizando fea 1<br/>";
> $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 "<br/> fin insercion feature actualizando fea 1<br/>";
> $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 <br/><br/>";
>
> echo "<br/><br/>Finaliza<br/>";
> }catch (MgException $e){
> echo $e->GetStackTrace() . "<br />";
> }catch (Exception $ex) {
>      echo 'Excepción capturada: ',  $e->getMessage(), "\n";
> }
>
> ?>
>
>
> <script language="javascript">
> function OnPageLoad()
> {
> alert("probando");
> parent.parent.Refresh();
> }
> </script>
>
> </body>
> </html>
>
>
>
>
> --
> 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
>


More information about the Edu_discuss mailing list