Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[udig-devel] More question about "Adding images"

Hello:
I had read the answer of the mail "Adding images" where there were a few steps to add images (could be used to show the .png file from a "gridfile")
The point is that i was trying to implement it but without success.

The steps and examples in the mail were the following:
- Create an IGeoResource from your image
- Create a Layer from your IGeoResource
- Add the Layer to the Map

As for the last steps:
Create a layer from the IGeoResource:
IGeoResource pngGeoResource;
ILayer layer = pngGeoResource.resolve(ILayer.class, null);

Obtain the map:
ApplicationGIS.getProjects().get(0).getElements(IMap.class).get(0)

To add the layer to the map:
map.sendCommandASync(new AddLayerCommand(layer) );


I have this method that was working well with former versions of uDig (addToMap) and i changed some lines (in addToMap_1) to get my image but i do not know how can I create my IGeoResource from a FileStringPath and show it in the map editor:

This is the former method:
    public static void addToMap(String strOutputFilePath){
    	File file = new File(strOutputFilePath);
		List<IService> imagePng;		
		try {
			imagePng = new ServiceFactoryImpl().aquire(file.toURL());
			for( IService service : imagePng ) {
                if (service != null) {                
                    if (service.members(null) != null) {
                        try {                        	
                            MapFactory.instance().process(null, service.members(null),false);
                            break;
                        } catch (Exception e1) {
                            System.err.println(e1.getMessage());
                        }
                    }
                }
            }
		} catch (MalformedURLException e2) {
			e2.printStackTrace();	
		} catch (IOException e3) {
			e3.printStackTrace();
		}
    }

This is my failed shot:
 public static void addToMap_1(String strOutputFilePath){
    	File file = new File(strOutputFilePah);
    	List<IService> imagePng = null;
		try {
			imagePng = new ServiceFactoryImpl().aquire(file.toURL());
			IGeoResource pngGeoResource = null;
			ILayer layer = pngGeoResource.resolve(ILayer.class, null);			
			ApplicationGIS.getActiveMap().sendCommandASync(new AddLayerCommand((Layer) layer));
		} catch (MalformedURLException e2) {
			e2.printStackTrace();	
		} catch (IOException e3) {
			e3.printStackTrace();
		}
    }

Why I should do?
Thank you,
Magna


Back to the top