Select to view content in your preferred language

[Solution] Embedding JMap in SWT Application

3207
2
03-22-2013 09:02 AM
StephenBaier
Occasional Contributor
Took me a while to figure this one out, so I figured I would get it in the forums for those who run into the issue in the future...

I don't know if anyone has come across this problem, but I am developing an Eclipse RCP application with a map display. Eclipse is SWT based and ArcGIS is AWT/Swing based. When I used the SWT_AWT bridge, I ran into the issue of the map flickering excessively upon interaction (panning, zooming, etc). This was fixed by placing the JMap component inside of a JApplet, rather than directly in the Frame created by the SWT_AWT bridge.

createPartControl(Composite parent) {     Composite embed = new Composite(parent, SWT.EMBEDDED | SWT.DOUBLE_BUFFERED);      Frame frame = SWT_AWT.new_Frame(embed);     JApplet japp = new JApplet();      JMap jmap = new JMap();     jmap.setDoubleBuffering(true);      // add layers to map     ...      frame.add(japp);     japp.add(jmap); }


I haven't tested it without the Double Buffering set, might not be making a difference; though Double Buffering could yield a performance increase even if its not necessary to fix flicker.
0 Kudos
2 Replies
MarkBaird
Esri Regular Contributor
Yes I have seen the flickering you are experiencing.

The solution however is quite simple, before putting the JMap in the SWT bridge put it in a JPanel and your flicker will go away.  Check out the following code sample which should get you displaying a flicker free map:

import org.eclipse.swt.widgets.Text;

import com.esri.client.toolkit.overlays.DrawingOverlay;
import com.esri.client.toolkit.overlays.DrawingOverlay.DrawingMode;
import com.esri.core.symbol.SimpleFillSymbol;
import com.esri.core.symbol.SimpleLineSymbol;
import com.esri.map.ArcGISTiledMapServiceLayer;
import com.esri.map.JMap;
import com.esri.runtime.ArcGISRuntime;
import com.esri.runtime.ArcGISRuntime.RenderEngine;

public class SWTJMapTest {

  public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    ArcGISRuntime.setRenderEngine(RenderEngine.OpenGL);
    final Display display = new Display();
    Shell shell = new Shell(display);

    Composite comp = new Composite(shell, SWT.EMBEDDED | SWT.NO_BACKGROUND); 
    comp.setBounds(5, 5, 500, 500);
    
    final java.awt.Frame frame = SWT_AWT.new_Frame(comp);
    SwingUtilities.invokeAndWait(new Runnable() {
      
      @Override
      public void run() {
        JMap map = new JMap();
        ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(
            "http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer");
        
        map.getLayers().add(tiledLayer);
        
        DrawingOverlay drawing = new DrawingOverlay();
        drawing.setUp(DrawingMode.POLYLINE_RECTANGLE, new SimpleLineSymbol(Color.red, 2.0f), null);
        map.addMapOverlay(drawing);
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add(map, BorderLayout.CENTER);
        frame.add(panel); // no flicker
        //frame.add(map);  // flickers      
      }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}



Let me know if this helps

Mark
0 Kudos
StephenBaier
Occasional Contributor
I was actually posting my solution, not my problem. Great to see alternatives though!
0 Kudos