$batchPropertyCollection->Add($propertyCollection); // Add the batch property collection to the feature source $cmd = new MgInsertFeatures($layerName, $batchPropertyCollection); $featureCommandCollection = new MgFeatureCommandCollection(); $featureCommandCollection->Add($cmd); // Execute the "add" commands $featureService->UpdateFeatures($resourceIdentifier, $featureCommandCollection, false); //---------------------------------------------------// $layerExists = DoesLayerExist($layerName, $map); if (!$layerExists) { // Create a new layer which uses that feature source // Create a line rule to stylize the lines $ruleLegendLabel = 'Lines Rule'; $filter = ''; $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
MgInitializeWebTier($webconfigFilePath); $args = $_SERVER['REQUEST_METHOD'] == "POST" ? $_POST : $_GET; $sessionId = $args['SESSION']; $mapName = $args['MAPNAME']; $userInfo = new MgUserInformation($sessionId); $siteConnection = new MgSiteConnection(); $siteConnection->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';
$lineTypeStyle = LayerDefinitionFactory::CreateLineTypeStyle($lineRule); $scaleRange = LayerDefinitionFactory::CreateScaleRange('0', '1000000000000', $lineTypeStyle); */ /* //Point Rules $markSymbol = LayerDefinitionFactory::CreateMarkSymbol("", "", 5, 5, "FF800000"); $textSymbol = LayerDefinitionFactory::CreateTextSymbol("", "10", "FF808000"); $pointRule = LayerDefinitionFactory::CreatePointRule("TestPoint", "", $textSymbol, $markSymbol); $pointStyle = LayerDefinitionFactory::CreatePointTypeStyle($pointRule); $scaleRange = LayerDefinitionFactory::CreateScaleRange('0', '1000000000000', $pointStyle); */ //Create layer definition $layerDef = LayerDefinitionFactory::CreateLayerDefinition('Library://NewParcels.LayerDefinition', 'Parcels', 'SHPGEOM', $scaleRange); //Uncomment to check out the generated xml //file_put_contents('test.xml',$layerDef); $byteSource = new MgByteSource($layerDef, strlen($layerDef)); $byteReader = $byteSource->GetReader(); $cred = new MgUserInformation(); $cred->SetMgUsernamePassword('Anonymous', ''); $cred->SetClientIp(GetClientIp()); $cred->SetClientAgent(GetClientAgent()); $siteConn = new MgSiteConnection(); $siteConn->Open($cred); $svc = $siteConn->CreateService(MgServiceType::ResourceService); $resId = new MgResourceIdentifier('Library://Test/NewLayer.LayerDefinition'); try { $svc->SetResource($resId, $byteReader, null); } catch (MgException $e) {
$propertyCollection = MakePoint("Point C", -87.726, 43.75); $batchPropertyCollection->Add($propertyCollection); unset($propertyCollection); $propertyCollection = MakePoint("Point D", -87.72799999999999, 43.75); $batchPropertyCollection->Add($propertyCollection); unset($propertyCollection); // Add the batch property collection to the feature source $cmd = new MgInsertFeatures("Points", $batchPropertyCollection); $featureCommandCollection = new MgFeatureCommandCollection(); $featureCommandCollection->Add($cmd); // Execute the "add" commands $featureService->UpdateFeatures($resourceIdentifier, $featureCommandCollection, false); // ... //---------------------------------------------------// // Create a new layer $factory = new LayerDefinitionFactory(); // Create a mark symbol $resourceId = 'Library://Samples/Sheboygan/' . 'Symbols/BasicSymbols.SymbolLibrary'; $symbolName = 'PushPin'; $width = '24'; // unit = points $height = '24'; // unit = points $color = 'FFFF0000'; $markSymbol = $factory->CreateMarkSymbol($resourceId, $symbolName, $width, $height, $color); // Create a text symbol $text = "ID"; $fontHeight = "12"; $foregroundColor = 'FF000000'; $textSymbol = $factory->CreateTextSymbol($text, $fontHeight, $foregroundColor); // Create a point rule.