[mapguide-users] Dynamically creating a line layer with SDF Feature Source

Jackie Ng jackie.ng at aecsystems.com.au
Thu Nov 29 20:59:58 EST 2007


Ok, I just actually re-read the LayerDefinitionFactory code and it seems your
code is actually correct. Just a bad choice of variable names :|

Try this:

echo the output of $factory->CreateLayerDefinition() and see if there are
any %s in the xml. 

If there are, chances are you left out some parameter in one of the
LayerDefinitionFactory calls, as it uses sprintf() string substitution.

- Jackie


uXuf wrote:
> 
> Hi Jackie,
> 
> I am getting a little confused by all this. I am actually trying to
> dynamically add a copy of a layer that already exists in the map. You see,
> I already have a layer from the "Arteries.FeatureSource" in my map. I just
> want to check out how dynamically created layers can be added.
> 
> So I just copied the FeatureClass and Geometry from the layer in the
> Studio, and I also referred to the devguide Hydrography example. Still I
> have no clue.
> 
> Could anyone take out a little time and explain it to me?
> 
> Regards,
> uXuf
> 
> 
> 
> 
> Jackie Ng wrote:
>> 
>> Just looking at your code...
>> 
>> Validation is failing because the $featureName should be an enumerated
>> value ( "FeatureClass" or "NamedExtension" )
>> 
>> The value of $featureClass should actually be the resourceid of the layer
>> definition xml document. The current value should be the current value of
>> $featureName (ie. $featureClass = "SDF_2_Schema:Selected")
>> 
>> - Jackie
>> 
>> 
>> uXuf wrote:
>>> 
>>> Hi all,
>>> 
>>> I am trying to add a layer of lines to my map using an existing
>>> FeatureSource in the library. This FeatureSource was generated from an
>>> SDF (created by Map 3D). I want to create the layer using the
>>> LayerDefinitionFactory instead of the usual XML file way. 
>>> 
>>> However, I get a "The new XML document is invalid" error when I try to
>>> use the add_layer_definition_to_map() function of the
>>> LayerDefinitionFactory.php. Inspecting this problem it turns out that
>>> the layer definition that (I think) I am sending with the code is
>>> failing to validate with the LayerDefinition-1.0.0.xsd. I haven't
>>> touched the XSD file at all since installation. Probably this error
>>> could lie when I am creating my geometry, I checked in the examples and
>>> consistently it was specified as "SHPGEOM", however when I check it out
>>> in Studio by creating a temporary layer from the feature source it is
>>> specified as "Data". I have also checked by specifying geometry as
>>> "Data". The error remains so.
>>> 
>>> Another thing I am getting confused in is to provide the Feature Name. I
>>> provide it with the value of "SDF_2_Schema:Selected", but I am not sure
>>> whether I should use "SHP_Schema:Selected". Any pointers in this regard
>>> would be greatly welcomed.
>>> 
>>> Here is the relevant part of my code:
>>> 
>>> //Set up a temporary layer
>>> $factory = new LayerDefinitionFactory();
>>> $legendLabel = '';
>>> $filter = '';
>>> $color = 'FF0000FF';
>>> $lineRule = $factory->CreateLineRule($legendLabel, $filter, $color);
>>> $lineTypeStyle = $factory->CreateLineTypeStyle($lineRule);
>>> $minScale = '0';
>>> $maxScale = '1000000';
>>> $lineScaleRange = $factory->CreateScaleRange($minScale, $maxScale,
>>> $lineTypeStyle);
>>> 
>>> //The following FeatureSource is generated from and SDF
>>> $featureClass = "Library://akMaps/Data/Arteries.FeatureSource";
>>> 
>>> //Could this be the real culprit?
>>> $featureName = "SDF_2_Schema:Selected";
>>> 
>>> //Or this?
>>> $geometry = 'Data';
>>> $layerDefinition = $factory->CreateLayerDefinition($featureClass,
>>> $featureName, $geometry, $lineScaleRange);
>>> 
>>> //error occurs in this function, fails to validate with
>>> LayerDefinition.xsd
>>> $newLayer = add_layer_definition_to_map($layerDefinition, "Selected",
>>> "Selected", $mgSessionID, $resourceService, $map);
>>> 
>>> 
>>> Any help would be greatly appreciated.
>>> 
>>> Thanks in advance,
>>> uXuf
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Dynamically-creating-a-line-layer-with-SDF-Feature-Source-tf4893966s16610.html#a14039272
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list