Infrastructure Map Server Developer

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

Create Layers Programmatically

587 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 (587 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community