Infrastructure Map Server Developer

Infrastructure Map Server Developer

Reply
New Member
dhinkle
Posts: 1
Registered: ‎12-11-2009
Message 1 of 2 (599 Views)

Create Layers Programmatically

599 Views, 1 Replies
01-22-2010 08:27 AM
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
*Jason Birch
Message 2 of 2 (599 Views)

Re: Create Layers Programmatically

04-26-2010 10:58 PM in reply to: dhinkle
On 22/01/2010 8:27 AM, dhinkle@cisco.com wrote:
> // 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.

Have you tried wrapping this in a try/catch block to see if there is an
exception thrown at some point?

Jason
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.