/******************************************************************************* * Copyright (c) 2012 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.maps.tests; /* import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URISyntaxException; import javax.imageio.ImageIO; import javax.swing.SwingUtilities; import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpMethodParams; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.canvas.chassis.FullscreenAwtChassis; import org.simantics.g2d.canvas.chassis.ICanvasChassis; import org.simantics.g2d.canvas.chassis.IChassisListener; import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant; import org.simantics.g2d.canvas.impl.CanvasContext; import org.simantics.g2d.canvas.impl.PainterReflection.Painter; import org.simantics.g2d.canvas.participant.GridPainter; import org.simantics.g2d.canvas.participant.MouseMonitor; import org.simantics.g2d.canvas.participant.PanZoomInteractor; import org.simantics.utils.threads.AWTThread; import org.simantics.maps.Service; import org.simantics.maps.WebService; import org.simantics.maps.wms.WMSGetMapQuery; public class WMSTest2 { private static String serviceUrl = "http://wms.jpl.nasa.gov/wms.cgi"; WMSTest2() throws URISyntaxException { try { final Service service = new WebService(serviceUrl); final BufferedImage bi = getData(service, new Dimension(600, 300), new Rectangle2D.Double(-180,-90,360,180), 1); GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); FullscreenAwtChassis chassis = new FullscreenAwtChassis("WMS Test", true); ICanvasContext canvasContext = new CanvasContext(AWTThread.getThreadAccess()); chassis.setCanvasContext(canvasContext); // Paints a cursor, follows mouse movement new MouseMonitor(canvasContext); // Pan & Zoom features new PanZoomInteractor(canvasContext); GridPainter grid = new GridPainter(canvasContext); // Ruler painter // new RulerPainter(canvasContext); new AbstractCanvasParticipant(canvasContext) { @Painter(priority = Integer.MAX_VALUE - 1000) public void paint(Graphics2D g) { g.drawImage(bi, new AffineTransformOp(new AffineTransform(), AffineTransformOp.TYPE_BICUBIC), 100, 100); } }; chassis.addChassisListener(new IChassisListener() { @Override public void chassisClosed(ICanvasChassis sender) { ICanvasContext ctx = sender.getCanvasContext(); if (ctx!=null) ctx.dispose(); }}); } catch (MalformedURLException e) { e.printStackTrace(); } } */ /** * Get a bufferedimage of the map data for the geographical coordinates. * * @param x * @param y * @param z * @return * @throws MalformedURLException */ /* public BufferedImage getData(Service service, Dimension rasterSize, Rectangle2D bbox, double zoom) throws MalformedURLException { if (rasterSize.width == 0 || rasterSize.height == 0) return new BufferedImage(0, 0, BufferedImage.TYPE_INT_ARGB); // Create an instance of HttpClient. HttpClient client = new HttpClient(); // Create a method instance. WMSGetMapQuery req = new WMSGetMapQuery(rasterSize.width, rasterSize.height, bbox, "image/jpeg", "global_mosaic"); GetMethod method = new GetMethod(service.getRequestURL(req.toString())); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } InputStream response = method.getResponseBodyAsStream(); BufferedImage img = ImageIO.read(response); if (img == null) { // Maybe the method produced a WMS error XML? return null; } return img; } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } return null; } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { new WMSTest2(); } catch (URISyntaxException e) { e.printStackTrace(); } } }); } } */