Open($userInfo);
$resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);
// --------------------------------------------------//
// Open the map
$map = new MgMap($siteConnection);
$map->Open($mapName);
// ...
//---------------------------------------------------//
// Create a new layer
$factory = new LayerDefinitionFactory();
/// Create three area rules for three different
// scale ranges.
$areaRule1 = $factory->CreateAreaRule( '1 to 800',
'SQFT >= 1 AND SQFT < 800', 'FFFFFF00');
$areaRule2 = $factory->CreateAreaRule( '800 to 1600',
'SQFT >= 800 AND SQFT < 1600', 'FFFFBF20');
$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");
$squareFootageLayer->SetVisible(true);
}
//---------------------------------------------------//
// Save the map back to the session repository
$map->Save();
//---------------------------------------------------//
}
catch (MgException $e)
{
echo " \n";
}
?>