public static Map createNonDynamicMapAndRenderer(IGeoResource resource, Dimension displaySize, Style style) throws Exception {
return createNonDynamicMapAndRenderer(resource, displaySize, style, true);
}
public static Map createNonDynamicMapAndRenderer(IGeoResource resource, Dimension displaySize, Style style, boolean createRenderManager) throws Exception {
final Map map=ProjectFactory.eINSTANCE.createMap(ProjectPlugin.getPlugin().getProjectRegistry().getDefaultProject(),
"testMap", new ArrayList<Layer>()); //$NON-NLS-1$
Layer tmp=map.getLayerFactory().createLayer(resource);
Layer layer=new TestLayer();
layer.setID(tmp.getID());
layer.setStyleBlackboard(tmp.getStyleBlackboard());
layer.setDefaultColor(tmp.getDefaultColor());
layer.setName(tmp.getName());
if( style!=null ){
StyleBlackboard styleBlackboard = layer.getStyleBlackboard();
styleBlackboard.put(SLDContent.ID, style);
}
map.getLayersInternal().add(layer);
if( createRenderManager){
map.setRenderManagerInternal(new RenderManagerImpl(){
@Override
public boolean isViewer() {
return true;
}
@Override
public void refresh( Envelope bounds ) {
// do nothing
}
@Override
public void refresh( ILayer layer, Envelope bounds ) {
//do nothing
}
@Override
public void refreshSelection( ILayer layer, Envelope bounds ) {
// do nothing
}
@Override
public void refreshImage() {
//do nothing
}
});
RenderManager rm=map.getRenderManagerInternal();
rm.setMapDisplay(new TestMapDisplay(displaySize));
rm.getRendererCreator().getLayers().add(layer);
map.getViewportModelInternal().setCRS(layer.getCRS());
final Runnable job = new Runnable() {
@Override
public void run() {
map.getViewportModelInternal().zoomToExtent();
}
};
final Thread jobThread = new Thread(job);
jobThread.start();
jobThread.join();