Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[udig-devel] Re: getting a handle to a MapGraphic

Ah, yes, that's the code I found too.  The problem is, as you can see, there's no handle to the MapGraphic.  In the end, I was able to get it from the layer AFTER it was created, using:

mapGraphic = _layer.getGeoResource().resolve(GpsMapGraphic.class, null);

As you can see, that method is deprecated by the docs (there are none on that method) don't hint as to what is replacing it.

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)



Back to the top