[geotk] Next step for WMS

Sam B totalsam at hotmail.com
Mon Aug 31 07:36:11 EDT 2009


Well, now I tested all with the DefaultPortrayService, but I still get the same distorted picture.... :-(

Here is the code of my TestFrame, the TestPanel class is just a simple JPanel with an overridden paintComponent that does a drawImage.

Does someone have an idea ?

Thanks,

Sam

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package testgo2nm;


import java.awt.Dimension;
import java.awt.RenderingHints;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.geotoolkit.display.exception.PortrayalException;
import org.geotoolkit.display2d.service.DefaultPortrayalService;
import org.geotoolkit.gui.swing.go2.JMap2D;
import org.geotoolkit.map.MapBuilder;
import org.geotoolkit.map.MapContext;
import org.geotoolkit.map.MapLayer;
import org.geotoolkit.referencing.CRS;
import org.geotoolkit.referencing.crs.DefaultGeographicCRS;
import org.geotoolkit.wms.WebMapServer;
import org.geotoolkit.wms.map.WMSMapLayer;
import org.geotoolkit.wms.xml.AbstractWMSCapabilities;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.TransformException;

/**
 *
 * @author
 */
public class TestFrame extends javax.swing.JFrame{
    JMap2D mapWidget;
    final MapLayer layer;

    //If we want to test the display using a simple image, then enable testpanel and add it to the JFrame instead of mapWidget
    //see below. !We need the picture some_picture.png!
    TestPanel testPanel;

    MapContext context;

    public TestFrame(){
        this.setSize(400, 400);
        this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
        mapWidget = new JMap2D();
        context = MapBuilder.createContext(DefaultGeographicCRS.WGS84);

        CoordinateReferenceSystem objectCRS = null;

        try {
            objectCRS = CRS.decode("EPSG:4326");
        } catch (NoSuchAuthorityCodeException ex) {
            Logger.getLogger(TestFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FactoryException ex) {
            Logger.getLogger(TestFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

        mapWidget.getContainer().setContext(context);

        mapWidget.getCanvas().setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        mapWidget.getCanvas().getController().setAutoRepaint(true);

        // add(mapWidget);
        // testPanel = new TestPanel();
        // add(testPanel);
        
        try {
            mapWidget.getCanvas().getController().setObjectiveCRS(objectCRS);
        } catch (TransformException ex) {
            Logger.getLogger(TestFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        //mapWidget.getCanvas().getController() is the place to change the point of view, dimension, coordinates, etc

        System.out.println("Obj : " + mapWidget.getCanvas().getObjectiveCRS().toWKT());
        System.out.println("Dev : " + mapWidget.getCanvas().getDeviceCRS().toWKT());
        System.out.println("Dis : " + mapWidget.getCanvas().getDisplayCRS().toWKT());


        System.out.println("Context: (" + context.getAreaOfInterest().getLowerCorner().getCoordinate()[0]
                + ":" + context.getAreaOfInterest().getLowerCorner().getCoordinate()[1] + ") , ("
                + context.getAreaOfInterest().getUpperCorner().getCoordinate()[0] + ":" +
                context.getAreaOfInterest().getUpperCorner().getCoordinate()[1]+")" );

        //Let's grab an image from WMS

        WebMapServer server = null;
        //final String url = "http://www2.demis.nl/WMS/wms.asp?wms=BlueMarble";
        //final String featureName = "EarthImage";

        final String url = "http://www2.demis.nl/WMS/wms.asp?wms=WorldMap";
        final String featureName = "Countries";

        final String version = "1.1.1";

        WebMapServer temp = null;

        try {
            temp = new WebMapServer(new URL(url),version);
        } catch (Exception ex) {
            Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
        }

        server = temp;

        if(server != null){
            layer = new WMSMapLayer(server,featureName);
        }else{
            layer = MapBuilder.createEmptyMapLayer();
        }

        final AbstractWMSCapabilities capa = server.getCapabilities();  //Ask the server for its capabilities

        //Display the layers names

        if(capa instanceof org.geotoolkit.wms.xml.v130.WMSCapabilities){
            org.geotoolkit.wms.xml.v130.WMSCapabilities cp13 =
                    (org.geotoolkit.wms.xml.v130.WMSCapabilities) capa;
            for(org.geotoolkit.wms.xml.v130.Layer tmpLayer : cp13.getCapability().getLayer().getLayer()){
                System.out.println("Layer v130 " + tmpLayer.getName());
            }
        }else if(capa instanceof org.geotoolkit.wms.xml.v111.WMT_MS_Capabilities){
            org.geotoolkit.wms.xml.v111.WMT_MS_Capabilities cp11 =
                    (org.geotoolkit.wms.xml.v111.WMT_MS_Capabilities) capa;
            for(org.geotoolkit.wms.xml.v111.Layer tmpLayer : cp11.getCapability().getLayer().getLayer()){
                System.out.println("Layer v111 " + tmpLayer.getName());
            }
        }

        context.layers().add(layer);

        try {

            testPanel = new TestPanel(DefaultPortrayalService.portray(context, context.getAreaOfInterest(), new Dimension(400, 400), false));

            add(testPanel);
        } catch (PortrayalException ex) {
            Logger.getLogger(TestFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}


_________________________________________________________________
Plus de 2 mio de Suisses utilisent Windows Live ! Découvrez les services gratuits.
http://www.microsoft.com/switzerland/windows/fr/windowslive/default.aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geotoolkit/attachments/20090831/2786c1a8/attachment-0001.html


More information about the Geotoolkit mailing list