[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| Re: [udig-devel] Re: FW: Add layer programmatically/1.1 question | 
Hi Stephan,
In order to have a functioning layer you need to do:
1.  Create a layer
2.  Set the ID of the layer to be equal to the ID of the IGeoResource  
that it represents.
You can think of a layer as an IGeoResource with a style.  That is  
simplistic but it is more or less the idea.  So when you use  
ApplicationGIS.addLayersToMap you only need the IGeoResource.
So if you are satisfied with the default style then you can simply use  
ApplicationGIS.addLayersToMap to add layer to a map.  However if you  
have a specific style or some other configuration that is done to the  
layer then you want to use the AddLayerCommand or the AddLayersCommand.
Jesse
On 17-Oct-08, at 3:31 AM, Jody Garnett wrote:
My understanding the two are very similar;
- option one sends the AddLayerCommand to the map
- option 2 creates a bunch of layers from the provided list of  
GeoResources and inserts these new layers at the indicated position.
There have been a number of off lists questions about creating and  
managing maps "by hand"; in general you can ignore all the udig  
stuff and create your own MapCommand; in the body of the command you  
can do anything you want...
Jody
Stephen Kilburn wrote:
To add a layer programmatically,
http://udig.refractions.net/confluence/display/DEV/How+do+I+add+a+layer+prog
rammatically says:
-for uDig 1.0:
 IMap map;
 map.sendCommandASync(new AddLayerCommand(layer) );
-for uDig 1.1:
 ApplicationGIS.addLayersToMap(map, layers, startposition, project);
But addLayersToMap takes a List<IGeoResource>, not a List<ILayer>,  
and when
I try:
 Layer layer = ProjectFactory.eINSTANCE.createLayer();
 // ... populate the new layer with geo and styling ...
 IGeoResource igr = (IGeoResource) layer;
I get a ClassCastException.
Do I need to use the 1.0 syntax to add *layers* or am I missing  
something?
(Latter exceedingly likely!)
_____________________________________________________________
Stephen Kilburn, GeoPraxis Inc.
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel