<div dir="ltr"><div><div>Dear Shoby,<br><br></div>DON'T BE LAZY OR HIJACK THREADS<br><a href="http://www.gerv.net/hacking/how-to-ask-good-questions/">http://www.gerv.net/hacking/how-to-ask-good-questions/</a><br><br></div>
<div>z<br></div><br><br><br><br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Mar 5, 2013 at 4:32 PM, Shoby Shah <span dir="ltr"><<a href="mailto:shobyshah@hotmail.com" target="_blank">shobyshah@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div dir="ltr">
<div><span style="font-size:10pt">Can u please tell me how can i add layer dynamically from search results, please help me out as i am new user.</span></div><div>please give me the steps.</div><div>thanks.</div><div><br>
</div><div><br><br><div><div></div>> Date: Mon, 4 Mar 2013 18:23:58 -0800<br>> From: <a href="mailto:mgvillablanca@yahoo.com" target="_blank">mgvillablanca@yahoo.com</a><br>> To: <a href="mailto:mapguide-users@lists.osgeo.org" target="_blank">mapguide-users@lists.osgeo.org</a><br>
> Subject: Re: [mapguide-users] Set feature properties to a point<div><div class="h5"><br>> <br>> After you have created the properties, you need to create your feature schema<br>> and add data to the SDF.<br>
> <br>> Your code looks ok. I did something similar in PHP sometime ago.<br>> <br>> See:<br>> <br>> function makePoint($id, $x, $y) {<br>> //makes a point<br>> <br>> global $fp;<br>> <br>
> //debug ($fp, "makePoint():\r\n");<br>> $name = "Node " . $id;<br>> $propertyCollection = new MgPropertyCollection();<br>> //name prop<br>> $nameProperty = new MgStringProperty("NAME", $name);<br>
> $propertyCollection->Add($nameProperty);<br>> //id prop<br>> $idProperty = new MgInt32Property("ID", $id);<br>> $propertyCollection->Add($idProperty);<br>> <br>> //geom<br>> $wktReaderWriter = new MgWktReaderWriter();<br>
> $agfReaderWriter = new MgAgfReaderWriter(); <br>> <br>> $geometry = $wktReaderWriter->Read("POINT XY ($x $y)"); <br>> $geometryByteReader = $agfReaderWriter->Write($geometry); <br>> $geometryProperty = new MgGeometryProperty("GEOM", $geometryByteReader);<br>
> $propertyCollection->Add($geometryProperty);<br>> <br>> return $propertyCollection;<br>> }<br>> <br>> function addNodesLayerToGroup($layer, $layerGroupName,<br>> $layerGroupLegendLabel, &$map) {<br>
> <br>> global $fp;<br>> <br>> // Adds a layer to a layer group. If necessary, it creates the layer<br>> group.<br>> // Get the layer group<br>> $layerGroupCollection = $map->GetLayerGroups();<br>
> if ($layerGroupCollection->Contains($layerGroupName)) {<br>> $layerGroup = $layerGroupCollection->GetItem($layerGroupName);<br>> } else {<br>> // It does not exist, so create it<br>> $layerGroup = new MgLayerGroup($layerGroupName); <br>
> $layerGroup->SetVisible(true);<br>> $layerGroup->SetDisplayInLegend(true);<br>> $layerGroup->GetExpandInLegend();<br>> $layerGroup->SetLegendLabel($layerGroupLegendLabel);<br>> $layerGroupCollection->Add($layerGroup); <br>
> //place the group under "Filters"<br>> //$parentGroup = $layerGroupCollection->GetItem("Filters");<br>> //$layerGroup->SetGroup($parentGroup);<br>> }<br>> <br>> // Add the layer to the group<br>
> $layer->SetGroup($layerGroup);<br>> //make the layer and its parents visible<br>> $elem = $layer;<br>> while ($elem != NULL) {<br>> $elem->SetVisible(true);<br>> $elem->SetDisplayInLegend(true);<br>
> $elem->GetExpandInLegend(); <br>> $elem = $elem->GetGroup();<br>> } <br>> }<br>> <br>> function addNodesToMap($nodes) {<br>> //adds nodes to the map<br>> <br>> global $sessionId, $mapName, $fp;<br>
> <br>> try {<br>> $userInfo = new MgUserInformation($sessionId);<br>> $siteConnection = new MgSiteConnection();<br>> $siteConnection->Open($userInfo);<br>> $resourceService =<br>
> $siteConnection->CreateService(MgServiceType::ResourceService);<br>> $featureService =<br>> $siteConnection->CreateService(MgServiceType::FeatureService); <br>> <br>> // Open the map<br>
> $map = new MgMap();<br>> $map->Open($resourceService, $mapName);<br>> <br>> // Create a feature source with point data.<br>> // Create a feature class definition for the new feature source<br>
> $classDefinition = new MgClassDefinition();<br>> $classDefinition->SetName("Points");<br>> $classDefinition->SetDescription("Feature class with point data.");<br>> $classDefinition->SetDefaultGeometryPropertyName("GEOM");<br>
> <br>> // Create a FeatId property<br>> $featIdProp = "FeatId";<br>> $identityProperty = new MgDataPropertyDefinition($featIdProp);<br>> $identityProperty->SetDataType(MgPropertyType::Int32);<br>
> $identityProperty->SetAutoGeneration(true);<br>> $identityProperty->SetReadOnly(true); <br>> // Add the identity property to the class definition<br>> $classDefinition->GetIdentityProperties()->Add($identityProperty);<br>
> $classDefinition->GetProperties()->Add($identityProperty);<br>> <br>> // Create a name property<br>> $nameProp = "NAME";<br>> $nameProperty = new MgDataPropertyDefinition($nameProp);<br>
> $nameProperty->SetDataType(MgPropertyType::String); <br>> // Add the name property to the class definition<br>> $classDefinition->GetProperties()->Add($nameProperty);<br>> <br>> // Create an ID property<br>
> $idProp = "ID";<br>> $idProperty = new MgDataPropertyDefinition($idProp);<br>> $idProperty->SetDataType(MgPropertyType::Int32);<br>> // Add the name property to the class definition<br>
> $classDefinition->GetProperties()->Add($idProperty);<br>> <br>> // Create a geometry property<br>> $geometryProperty = new MgGeometricPropertyDefinition("GEOM");<br>> $geometryProperty->SetGeometryTypes(MgFeatureGeometricType::Point); <br>
> // Add the geometry property to the class definition<br>> $classDefinition->GetProperties()->Add($geometryProperty);<br>> <br>> // Create a feature schema<br>> $featureSchema = new MgFeatureSchema("PointSchema", "Point schema");<br>
> // Add the feature schema to the class definition<br>> $featureSchema->GetClasses()->Add($classDefinition); <br>> <br>> // Create the feature source<br>> $featureSourceName =<br>> 'Library://SS_testing/Network_analysis/Data/Nodes.FeatureSource'; <br>
> $resourceIdentifier = new MgResourceIdentifier($featureSourceName);<br>> $srs = $map->GetMapSRS();<br>> $spatialContext = "LL84";<br>> $sdfParams = new MgCreateSdfParams($spatialContext, $srs,<br>
> $featureSchema);<br>> $featureService->CreateFeatureSource($resourceIdentifier, $sdfParams);<br>> <br>> // We need to add some data to the sdf before using it. The spatial<br>> context reader must have an extent.<br>
> $batchPropertyCollection = new MgBatchPropertyCollection();<br>> $wktReaderWriter = new MgWktReaderWriter();<br>> $agfReaderWriter = new MgAgfReaderWriter();<br>> $geometryFactory = new MgGeometryFactory();<br>
> <br>> for ($t=0; $t < count($nodes); $t++) {<br>> $node = $nodes[$t];<br>> $x = $node->X;<br>> $y = $node->Y;<br>> $id = $node->ID;<br>> //$coordLL = transformCoordinate("CA83-VF", $spatialContext, $x, $y);<br>
> //$x = $coordLL->GetX();<br>> //$y = $coordLL->GetY();<br>> $propertyCollection = makePoint($id, $x, $y);<br>> $batchPropertyCollection->Add($propertyCollection);<br>> unset($propertyCollection);<br>
> }<br>> <br>> // Add the batch property collection to the feature source<br>> $cmd = new MgInsertFeatures("Points", $batchPropertyCollection); <br>> $featureCommandCollection = new MgFeatureCommandCollection();<br>
> $featureCommandCollection->Add($cmd);<br>> <br>> // Execute the "add" commands<br>> $featureService->UpdateFeatures($resourceIdentifier,<br>> $featureCommandCollection, false); <br>
> <br>> // Create a new layer<br>> $factory = new LayerDefinitionFactory();<br>> <br>> // Create a mark symbol<br>> $resourceId =<br>> 'Library://Samples/Sheboygan/Symbols/BasicSymbols.SymbolLibrary';<br>
> $symbolName = 'PushPin';<br>> $width = '11'; // unit = points<br>> $height = '11'; // unit = points<br>> $color = 'FFFF0000';<br>> $markSymbol = $factory->CreateMarkSymbol($resourceId, $symbolName,<br>
> $width, $height, $color); <br>> <br>> // Create a text symbol<br>> $text = $idProp; //"ID"<br>> $fontHeight="12";<br>> $foregroundColor = 'FF000000';<br>
> $textSymbol = $factory->CreateTextSymbol($text, $fontHeight,<br>> $foregroundColor);<br>> <br>> // Create a point rule.<br>> $legendLabel = 'Nodes';<br>> $filter = '';<br>
> //$pointRule = $factory->CreatePointRule($legendLabel, $filter,<br>> $textSymbol, $markSymbol);//don't use symbols<br>> $pointRule = $factory->CreatePredefinedPointRule($legendLabel,<br>> $filter, $text);<br>
> <br>> // Create a point type style.<br>> $pointTypeStyle = $factory->CreatePointTypeStyle($pointRule);<br>> <br>> // Create a scale range.<br>> $minScale = '0';<br>
> $maxScale = '1000000000000';<br>> $pointScaleRange = $factory->CreateScaleRange($minScale, $maxScale,<br>> $pointTypeStyle);<br>> <br>> // Create the layer definiton.<br>
> $featureName = 'PointSchema:Points';<br>> $geometry = 'GEOM';<br>> //$layerDefinition =<br>> $factory->CreateLayerDefinition($featureSourceName, $featureName, $geometry,<br>
> $pointScaleRange); <br>> //the original class doesn't use mappings for the features' layer<br>> definition<br>> $layerDefinition =<br>> $factory->CreateNodeLayerDefinition($featureSourceName, $featureName,<br>
> $nameProp, $idProp, $featIdProp, $geometry, $pointScaleRange);<br>> <br>> // Add the layer to the map<br>> $newLayer = add_layer_definition_to_map($layerDefinition, "Points",<br>
> "Nodes", $sessionId, $resourceService, $map);<br>
> addNodesLayerToGroup($newLayer, "Analysis", "Analysis", $map);<br>> <br>> // Turn on the visibility of this layer.<br>> // (If the layer does not already exist in the map, it will be visible<br>
> by default when it is added.<br>> // But if the user has already run this script, he or she may have set<br>> the layer to be invisible.)<br>> $layerCollection = $map->GetLayers();<br>> if ($layerCollection->Contains("Points")) {<br>
> $pointsLayer =$layerCollection->GetItem("Points");<br>> $pointsLayer->SetVisible(true);<br>> $pointsLayer->SetSelectable(true);<br>> }<br>> <br>
> // Save the map back to the session repository<br>> $sessionIdName = "Session:$sessionId//$mapName.Map";<br>> $sessionResourceID = new MgResourceIdentifier($sessionIdName);<br>> $sessionResourceID->Validate();<br>
> $map->Save($resourceService, $sessionResourceID);<br>> }<br>> <br>> catch (MgException $e) {<br>> debug ($fp, "\tMgException:" . $e->GetMessage() . "\r\n");<br>> } <br>
> }<br>> <br>> <br>> <br>> --<br>> View this message in context: <a href="http://osgeo-org.1560.n6.nabble.com/Set-feature-properties-to-a-point-tp5037772p5038429.html" target="_blank">http://osgeo-org.1560.n6.nabble.com/Set-feature-properties-to-a-point-tp5037772p5038429.html</a><br>
> Sent from the MapGuide Users mailing list archive at Nabble.com.<br>> _______________________________________________<br>> mapguide-users mailing list<br>> <a href="mailto:mapguide-users@lists.osgeo.org" target="_blank">mapguide-users@lists.osgeo.org</a><br>
> <a href="http://lists.osgeo.org/mailman/listinfo/mapguide-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/mapguide-users</a><br></div></div></div></div> </div></div>
<br>_______________________________________________<br>
mapguide-users mailing list<br>
<a href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/mapguide-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/mapguide-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Zac Spitzer<br>Solution Architect / Director<br>Ennoble Consultancy Australia<br>+61 405 847 168<br><br>
</div>