So
you've just identified an area that we need to work on a bit.
Ideally the MapGraphic Service should always be loaded in the
catalog but it isn't yet. So you have to load it manually if
it isn't in the local catalog the following code will do it.
yourExtensionID is the id
of your map graphic :
Map map
= ApplicationGISInternal.getActiveMap();
try
{
IGeoResource
mapGraphicResource = null;
URL url =
"">new
URL(MapGraphicService.SERVICE_URL, "#" + yourExtensionID);
//$NON-NLS-1$
List<IResolve>
matches =
CatalogPlugin.getDefault().getLocalCatalog().find(url,
new
NullProgressMonitor());
if
(!matches.isEmpty())
mapGraphicResource = (IGeoResource)
matches.get(0);
if (mapGraphicResource
== null)
{
List<IService>
results =
CatalogPlugin.getDefault().getServiceFactory()
.acquire(url);
for( IGeoResource
resource : results.get(0).members(new
NullProgressMonitor()) ) {
if
(resource.getIdentifier().getRef().equals(url.getRef()))
{
mapGraphicResource = resource;
break;
}
}
}
if (mapGraphicResource
== null)
return;
Layer layer =
map.getLayerFactory().createLayer(mapGraphicResource);
map.sendCommandSync(BasicCommandFactory.getInstance().createAddLayer(layer));
} catch
(MalformedURLException e) {
MapGraphicPlugin.log("", e);
//$NON-NLS-1$
} catch (IOException e)
{
MapGraphicPlugin.log("", e);
//$NON-NLS-1$
}
The code also creates and adds the mapgraphics to a map.
Cheers,
Jesse
On 28-Oct-06, at 4:25 AM, Andy Czerwonka wrote:
I've implemented a MapGraphic extension,
but I need a handle to the
MapGraphic. I see the example of
creating a layer based on the
MapGraphicService URL, but nowhere do I
see how to get the MapGraphic
handle. I see (in the debugger)
that the MapGraphic is contained in the
IGeoResource, but I can't figure out how
it's exposed.
Thanks in advance,
-andy
_______________________________________________
User-friendly Desktop Internet GIS
(uDig)