Hello,
I use the following code for creating a new map with layers
CatalogPlugin catalog = CatalogPlugin.getDefault();
IServiceFactory svf = catalog.getServiceFactory();
List<IGeoResource> resourceList = new
ArrayList<IGeoResource>();
List<IService> services;
try {
services = svf.acquire(new
URL("http://mstaging/cgi-bin/movida/sclmapserver.exe?service=wms"));
for( IService service : services ) {
resourceList.addAll(service.members(null));
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Project project = (Project)
ApplicationGIS.getActiveProject();
CreateMapCommand command=new
CreateMapCommand("Zones", resourceList, project);
project.sendSync(command);
IMap map=command.getCreatedMap();
OpenMapCommand omCommand = new OpenMapCommand((Map)
map);
project.sendSync(omCommand);
Should I loop through the service.members to select the right layers? And
how can I use this code to add layers to a map which is already created.
Map.getMapLayers.add() wants a ILayer as parameter.
Best regards,
Johan de Koning
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of Jody Garnett
Sent: Friday, February 17, 2006 5:31 PM
To: User-friendly Desktop Internet GIS
Subject: Re: [udig-devel] Adding layers from code
Johan C. de Koning wrote:
Hello,
How could I add layers to the map programmatically? Just like the
url's (with parameters) inside I umap file are stored, I want these
like of urls to one or more layers from the code to a map. I looked at
the code how a project is opened, but I was wondering if this could
also be done without using the different Project classes.
So for example I have an url for a WMS server (with layers specified)
I want to add these to a map without defining that I am going to add
WMS layers (or use the catalog.wms classes). It should be done by the
catalog. I found the code inside the UDIG Developers Guide about
creating a map from the code, but using a GeoResource adds all the
layers from a url (which I don't).
Yes, the catalog has a lookup function that will basically figure out
the best match for your url (you never have to notice if it was based on
a WMS or WFS or shapefile).
For an example of this in action please review the code for loading and
save OWS Context documents.
Hopefully somebody can give me a little piece of example code about
how to get this working.
The programmers guide (included with your default uDig install or on the
webstite) should be a help here - Look in the GIS Platform section on
how to get a hold of georesources without knowing before hand what type
they are. From there you can follow the example you have already found.
Jody
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel