I am having an issue creating a layer programmatically using the MapGuide API (PHP). Here is what I am trying to do:
From an existing feature source and existing layer I want to programmatically create a new layer based on a specific query in the feature source. What is the best way to go about this? Should I use LayerDefinitionFactory to create a new layer or can I copy the existing layer and modify it's definition? I'd also like to display this new layer in the legend - I have seen the example code on how to do this but I need to first get past the layer creation bit.
I have tried using the LayerDefinitionFactory approach but I am getting an empty LayerDefinition. Here is my code:
...
$site = new MgSiteConnection();
$site->Open(new MgUserInformation($args['SESSION']));
$resourceService = $site->CreateService(MgServiceType::ResourceService);
$featureService = $site->CreateService(MgServiceType::FeatureService);
$map = new MgMap($site);
$map->Open($args['MAPNAME']);
$factory = new LayerDefinitionFactory();
$areaRule = $factory->CreateAreaRule('1 to 300000','SQFT >= 1600','FFFFFF00');
$areaTypeStyle = $factory->CreateAreaTypeStyle($areaRule);
$minScale = '0';
$maxScale = '1000000000000';
$areaScaleRange = $factory->CreateScaleRange($minScale, $maxScale, $areaTypeStyle);
$featureClass = 'Library://Data/test2.FeatureSource'; // <-- This is the existing feature source
$featureName = "SDF_2_Schema:test';
$geometry = 'Data';
$layerDefinition = $factory->CreateLayerDefinition($featureClass, $featureName, $geometry, $areaScaleRange);
...
// At this point the layerDefinition is empty so when I try to execute "add_layer_definition_to_map(...)" it fails with an XML parsing error.
Thanks