function CreateMarkup() { $resourceService = $this->site->CreateService(MgServiceType::ResourceService); $featureService = $this->site->CreateService(MgServiceType::FeatureService); $map = new MgMap(); $map->Open($resourceService, $this->args['MAPNAME']); $featureSourceId = ""; $bUpdate = array_key_exists("EDITMARKUPLAYER", $this->args) && array_key_exists("MARKUPLAYERNAME", $this->args) && array_key_exists("EDITFEATURESOURCE", $this->args); // Create the Markup Feature Source if not updating if (!$bUpdate) { $markupName = $this->args["MARKUPNAME"]; $this->UniqueMarkupName($markupName); $markupFsId = new MgResourceIdentifier($this->GetResourceIdPrefix() . $markupName . '.FeatureSource'); //MARKUPGEOMTYPE is any constant from MgFeatureGeometricType if (array_key_exists("MARKUPGEOMTYPE", $this->args)) { $markupSchema = MarkupSchemaFactory::CreateMarkupSchema(intval($this->args["MARKUPGEOMTYPE"])); } else { $markupSchema = MarkupSchemaFactory::CreateMarkupSchema(-1); } $fsParams = new MgFileFeatureSourceParams($this->args["MARKUPFDOPROVIDER"], 'Default', $map->GetMapSRS(), $markupSchema); $featureService->CreateFeatureSource($markupFsId, $fsParams); $featureSourceId = $markupFsId->ToString(); } else { $featureSourceId = $this->args["EDITFEATURESOURCE"]; } //HACK: SQLite leaky abstraction (hard-coded schema name), SHP probably has some leaks of its own, so we can't assume MarkupSchema:Markup //as the class name interrogate our schema to figure it out $fsId = new MgResourceIdentifier($featureSourceId); $schemas = $featureService->DescribeSchema($fsId, "", null); $schema = $schemas->GetItem(0); $classes = $schema->GetClasses(); $cls = $classes->GetItem(0); $className = $schema->GetName() . ":" . $cls->GetName(); $markupLayerDefinition = $this->CreateMarkupLayerDefinitionContent($featureSourceId, $className); $byteSource = new MgByteSource($markupLayerDefinition, strlen($markupLayerDefinition)); //Save to new resource or overwrite existing $layerDefId = new MgResourceIdentifier($bUpdate ? $this->args["EDITMARKUPLAYER"] : $this->GetResourceIdPrefix() . $markupName . '.LayerDefinition'); $resourceService->SetResource($layerDefId, $byteSource->GetReader(), null); $cmds = new MgFeatureCommandCollection(); //Register markup with markup registry if not updating if (!$bUpdate) { $props = new MgPropertyCollection(); $props->Add(new MgStringProperty("ResourceId", $markupFsId->ToString())); $props->Add(new MgStringProperty("LayerDefinition", $layerDefId->ToString())); $props->Add(new MgStringProperty("Name", $layerDefId->GetName())); $props->Add(new MgStringProperty("FdoProvider", $this->args["MARKUPFDOPROVIDER"])); $props->Add(new MgInt32Property("GeometryTypes", intval($this->args["MARKUPGEOMTYPE"]))); $insertCmd = new MgInsertFeatures("Default:MarkupRegistry", $props); $cmds->Add($insertCmd); } if ($cmds->GetCount() > 0) { $res = $featureService->UpdateFeatures($this->markupRegistryId, $cmds, false); MarkupManager::CleanupReaders($res); } return $layerDefId->ToString(); }
// add a point to the ParcelMarker layer to mark the // centroid. // Collect all the points into an MgFeatureCommandCollection, // so they can all be added in one operation. $parcelMarkerCommands = new MgFeatureCommandCollection(); while ($featureReader->ReadNext()) { $byteReader = $featureReader->GetGeometry('SHPGEOM'); $geometry = $agfReaderWriter->Read($byteReader); $point = $geometry->GetCentroid(); // Create an insert command for this parcel. $properties = new MgPropertyCollection(); $properties->Add(new MgGeometryProperty('ParcelLocation', $agfReaderWriter->Write($point))); $parcelMarkerCommands->Add(new MgInsertFeatures('ParcelMarkerClass', $properties)); } $featureReader->Close(); if ($parcelMarkerCommands->GetCount() > 0) { // Old way, pre MapGuide OS 2.0. Kept here for reference //$featureService->UpdateFeatures($parcelFeatureResId, $parcelMarkerCommands, false); // New way, post MapGuide OS 2.0 $parcelMarkerLayer->UpdateFeatures($parcelMarkerCommands); } else { echo '</p><p>No parcels within the buffer area match.'; } // Create a feature in the buffer feature source to show the area covered by the buffer. $properties = new MgPropertyCollection(); $properties->Add(new MgGeometryProperty('BufferGeometry', $agfReaderWriter->Write($bufferGeometry))); $commands = new MgFeatureCommandCollection(); $commands->Add(new MgInsertFeatures('BufferClass', $properties)); // Old way, pre MapGuide OS 2.0 //$featureService->UpdateFeatures($bufferFeatureResId, $commands, false); // New way, post MapGuide OS 2.0