$color = 'FF0000FF'; $factory = new LayerDefinitionFactory(); $lineRule = $factory->CreateLineRule($ruleLegendLabel, $filter, $color); // Create a line type style $lineTypeStyle = $factory->CreateLineTypeStyle($lineRule); // Create a scale range $minScale = '0'; $maxScale = '1000000000000'; $lineScaleRange = $factory->CreateScaleRange($minScale, $maxScale, $lineTypeStyle); // Create the layer definiton $featureName = 'SHP_Schema:Lines'; $geometry = 'SHPGEOM'; $layerDefinition = $factory->CreateLayerDefinition($featureSourceName, $featureName, $geometry, $lineScaleRange); //---------------------------------------------------// // Add the layer to the map $newLayer = add_layer_definition_to_map($layerDefinition, $layerName, $layerLegendLabel, $sessionId, $resourceService, $map); // Add the layer to a layer group add_layer_to_group($newLayer, $groupName, $groupLegendLabel, $map); } // --------------------------------------------------// // Turn on the visibility of this layer. // (If the layer does not already exist in the map, it will be visible by default when it is added. // But if the user has already run this script, he or she may have set the layer to be invisible.) $layerCollection = $map->GetLayers(); if ($layerCollection->Contains($layerName)) { $linesLayer = $layerCollection->GetItem($layerName); $linesLayer->SetVisible(true); } $groupCollection = $map->GetLayerGroups(); if ($groupCollection->Contains($groupName)) { $analysisGroup = $groupCollection->GetItem($groupName);
// Change the legend label $query = '//LegendLabel'; // Get a list of all the <LegendLabel> elements in the // XML. $nodes = $xpath->query($query); // Find the correct node and change it foreach ($nodes as $node) { if ($node->nodeValue == 'Built after 1950') { $node->nodeValue = 'Built after 1980'; } } // --------------------------------------------------// // ... // Add the layer to the map $layerDefinition = $domDocument->saveXML(); $newLayer = add_layer_definition_to_map($layerDefinition, "RecentlyBuilt", "Built after 1980", $sessionId, $resourceService, $map); add_layer_to_group($newLayer, "Analysis", "Analysis", $map); // --------------------------------------------------// // Turn off the "Square Footage" themed layer (if it // exists) so it does not hide this layer. $layerCollection = $map->GetLayers(); if ($layerCollection->Contains("SquareFootage")) { $squareFootageLayer = $layerCollection->GetItem("SquareFootage"); $squareFootageLayer->SetVisible(false); } // --------------------------------------------------// // Turn on the visibility of this layer. // (If the layer does not already exist in the map, it will be visible by default when it is added. // But if the user has already run this script, he or she may have set the layer to be invisible.) $layerCollection = $map->GetLayers(); if ($layerCollection->Contains("RecentlyBuilt")) {
$lineRule = $factory->CreateLineRule($legendLabel, $filter, $color); // Create a line type style. $lineTypeStyle = $factory->CreateLineTypeStyle($lineRule); // Create a scale range. $minScale = '0'; $maxScale = '1000000000000'; $lineScaleRange = $factory->CreateScaleRange($minScale, $maxScale, $lineTypeStyle); // Create the layer definiton. $featureClass = 'Library://Samples/Sheboygan/Data/' . 'HydrographicLines.FeatureSource'; $featureName = 'SHP_Schema:HydrographicLines'; $geometry = 'SHPGEOM'; $layerDefinition = $factory->CreateLayerDefinition($featureClass, $featureName, $geometry, $lineScaleRange); //---------------------------------------------------// // ... // Add the layer to the map $newLayer = add_layer_definition_to_map($layerDefinition, "Hydro", "Hydro", $sessionId, $resourceService, $map); add_layer_to_group($newLayer, "Analysis", "Analysis", $map); // --------------------------------------------------// // Turn on the visibility of this layer. // (If the layer does not already exist in the map, it will be visible by default when it is added. // But if the user has already run this script, he or she may have set the layer to be invisible.) $layerCollection = $map->GetLayers(); if ($layerCollection->Contains("Hydro")) { $squareFootageLayer = $layerCollection->GetItem("Hydro"); $squareFootageLayer->SetVisible(true); } //---------------------------------------------------// // Save the map back to the session repository $sessionIdName = "Session:{$sessionId}//{$mapName}.Map"; $sessionResourceID = new MgResourceIdentifier($sessionIdName); $sessionResourceID->Validate();
$areaRule3 = $factory->CreateAreaRule('1600 to 2400', 'SQFT >= 1600 AND SQFT < 2400', 'FFFF8040'); // Create an area type style. $areaTypeStyle = $factory->CreateAreaTypeStyle($areaRule1 . $areaRule2 . $areaRule3); // Create a scale range. $minScale = '0'; $maxScale = '10000'; $areaScaleRange = $factory->CreateScaleRange($minScale, $maxScale, $areaTypeStyle); // Create the layer definiton. $featureClass = 'Library://Samples/Sheboygan/Data/' . 'Parcels.FeatureSource'; $featureName = 'SHP_Schema:Parcels'; $geometry = 'SHPGEOM'; $layerDefinition = $factory->CreateLayerDefinition($featureClass, $featureName, $geometry, $areaScaleRange); //---------------------------------------------------// // ... // Add the layer to the map $newLayer = add_layer_definition_to_map($layerDefinition, "SquareFootage", "Square Footage", $sessionId, $resourceService, $map); add_layer_to_group($newLayer, "Analysis", "Analysis", $map); //---------------------------------------------------// // Turn off the "Recently Built" themed layer (if it exists) so it does not hide this layer. $layerCollection = $map->GetLayers(); if ($layerCollection->Contains("RecentlyBuilt")) { $recentlyBuiltLayer = $layerCollection->GetItem("RecentlyBuilt"); $recentlyBuiltLayer->SetVisible(false); } // --------------------------------------------------// // Turn on the visibility of this layer. // (If the layer does not already exist in the map, it will be visible by default when it is added. // But if the user has already run this script, he or she may have set the layer to be invisible.) $layerCollection = $map->GetLayers(); if ($layerCollection->Contains("SquareFootage")) { $squareFootageLayer = $layerCollection->GetItem("SquareFootage");
$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. $featureName = 'PointSchema:Points'; $geometry = 'GEOM'; $layerDefinition = $factory->CreateLayerDefinition($featureSourceName, $featureName, $geometry, $pointScaleRange); //---------------------------------------------------// // ... // Add the layer to the map $newLayer = add_layer_definition_to_map($layerDefinition, "Points", "Points of Interest", $sessionId, $resourceService, $map); add_layer_to_group($newLayer, "Analysis", "Analysis", $map); // --------------------------------------------------// // Turn on the visibility of this layer. // (If the layer does not already exist in the map, it will be visible by default when it is added. // But if the user has already run this script, he or she may have set the layer to be invisible.) $layerCollection = $map->GetLayers(); if ($layerCollection->Contains("Points")) { $pointsLayer = $layerCollection->GetItem("Points"); $pointsLayer->SetVisible(true); } //---------------------------------------------------// // Save the map back to the session repository $map->Save(); //---------------------------------------------------// } catch (MgException $e) {