function add_layer_to_group($layer, $layerGroupName, $layerGroupLegendLabel, &$map) { // Get the layer group $layerGroupCollection = $map->GetLayerGroups(); if ($layerGroupCollection->Contains($layerGroupName)) { $layerGroup = $layerGroupCollection->GetItem($layerGroupName); } else { // It does not exist, so create it $layerGroup = new MgLayerGroup($layerGroupName); $layerGroup->SetVisible(true); $layerGroup->SetDisplayInLegend(true); $layerGroup->SetLegendLabel($layerGroupLegendLabel); $layerGroupCollection->Add($layerGroup); } // Add the layer to the group $layer->SetGroup($layerGroup); }
function OpenMarkup() { $resourceService = $this->site->CreateService(MgServiceType::ResourceService); $map = new MgMap(); $map->Open($resourceService, $this->args['MAPNAME']); // Create the Layer Groups $markupGroup = null; $layerGroups = $map->GetLayerGroups(); if ($layerGroups->Contains('_Markup')) { $markupGroup = $layerGroups->GetItem('_Markup'); } else { $markupGroup = new MgLayerGroup('_Markup'); $markupGroup->SetVisible(true); $markupGroup->SetLegendLabel('Markup'); $markupGroup->SetDisplayInLegend(true); $layerGroups->Add($markupGroup); } // Add the Markup Layer $markupLayerResId = new MgResourceIdentifier($this->args['MARKUPLAYER']); $markupLayer = new MgLayer($markupLayerResId, $resourceService); $markupLayer->SetName('_' . $markupLayerResId->GetName()); $markupLayer->SetLegendLabel($markupLayerResId->GetName()); $markupLayer->SetDisplayInLegend(true); $markupLayer->SetSelectable(true); $markupLayer->SetGroup($markupGroup); $map->GetLayers()->Insert(0, $markupLayer); $map->Save($resourceService); }