Thanks for everyone that posted or contributed code on this thread.
This is very handy info, and I'll try to post the best excerpts to my
OpenJUMP blog.

The Sunburned Surveyor

On Fri, May 28, 2010 at 9:20 AM, Hernan Arellano <her...@hotmail.com> wrote:
> Hi all, in the same way that load a layer by code, I needed load a jpg image
> by code, at the same map.
> I want to share with you too, the code to load an image without a wizard:
>
> ***********
> ***********
> public boolean execute(PlugInContext context) throws Exception
> {
> LayerManager layerManager = context.getWorkbenchContext().getLayerManager();
> layerManager.setFiringEvents(false);
> File file = new File("c://image.jpg");
> Layer lyr = createLayer(layerManager, file);
> layerManager.setFiringEvents(true);
> Category category =
> TaskUtil.getSelectedCategoryName(context.getWorkbenchContext());
> category.add(0, (Layerable) lyr);
> ReferencedImageFactory imageFactory= new GraphicImageFactory(); //depends
> the image type
> Feature feature = createFeature(imageFactory, file,
> getImageryLayerDataset(lyr));
> lyr.getFeatureCollectionWrapper().add(feature);
> }
>
> private Feature createFeature(ReferencedImageFactory referencedImageFactory,
>             File file, ImageryLayerDataset imageryLayerDataset)
> {
> Feature feature = new BasicFeature(ImageryLayerDataset.getSchema());
> feature.setAttribute(ImageryLayerDataset.ATTR_FILE, file.getPath());
> feature.setAttribute(ImageryLayerDataset.ATTR_FORMAT,
> referencedImageFactory.getTypeName());
> feature.setAttribute(ImageryLayerDataset.ATTR_FACTORY,
> referencedImageFactory.getClass().getName());
> feature.setGeometry(new GeometryFactory().createPoint((Coordinate)null));
> imageryLayerDataset.createImage(feature);
> return feature;
> }
>
> private ImageryLayerDataset
> getImageryLayerDataset(com.vividsolutions.jump.workbench.model.Layer layer)
> {
> ReferencedImageStyle irs =
> (ReferencedImageStyle)layer.getStyle(ReferencedImageStyle.class);
> return irs.getImageryLayerDataset();
> }
> ***********
> ***********
> Note: in my proyect i have a xml map with layers and images paths, all them
> with the same projection.
>
> Regards!
>
> ________________________________
> ------------------------------------------------------------------------------
>
>
> _______________________________________________
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
>

------------------------------------------------------------------------------

_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to