/* Package GeoTools/WMS Implementation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: WebServiceLayer.java,v 1.7 2002/03/01 19:54:16 jmacgill Exp $ * $Author: jmacgill $ * $Date: 2002/03/01 19:54:16 $ */ package uk.ac.leeds.ccg.ogc; import uk.ac.leeds.ccg.geotools.*; import uk.ac.leeds.ccg.raster.*; import java.net.*; import java.util.*; import java.awt.image.*; import java.awt.*; /** * Class WebServiceLayer provides mechanisms for layers that * are built from URL addressable services. In particular, it provides * the double buffering required. Web Services Layers take a long time to * build, and consequently require double buffering which allows the old frame * to be viewed while the new frame is being built.
* WebServicesLayer is abstract, and hence cannot be used by itself. It needs * to be extented and buildLayer needs to be specified for each extention of * this class. * * @author Cameron Shorter * @version $Revision: 1.7 $ */ public abstract class WebServiceLayer extends MultiLayer { private final static boolean DEBUG=true; /** The extent of this layer last time it was called */ private GeoRectangle oldExtent = null; static int layerid=0; /** Create a new sub-layer based on the extent passed in. * This method needs to be over-ridden by the extending class. * @param gg Information (mainly extent) required for building a new layer. */ public abstract Layer buildLayer(GeoGraphics gg); /** This method provides double buffering for the layer used in * buildLayer, it assumes that if extent has not changed, then the * subLayer does not need to be rebuilt (just redrawn). This will cover * 98% of cases, however there will be some dynamic layers, like Web Map * Servers which show time changing weather data, which will not work * properly with this implementation. Hence, a more sophisticated * solution should be introduced at a later stage. * @author Cameron Shorter */ public void paintScaled(GeoGraphics gg) { GeoRectangle extent; Vector layers; extent = gg.getScale().getMapExtent(); if (extent==null||extent.isEmpty()){ if(DEBUG)System.out.println("WebServiceLayer.bbox not defined"); return; } layers = this.getLayers(); if (DEBUG) if((layers.size()>0))System.out.println( "WebServiceLayer - " +" layers.size="+layers.size() +" firstElement.status="+((Layer)layers.firstElement()).getStatus() +" lastElement.status="+((Layer)layers.lastElement()).getStatus() +" extent.equals(oldExtent)="+extent.equals(oldExtent) ); else System.out.println("WebServiceLayer - size=0" +" extent.equals(oldExtent)="+extent.equals(oldExtent)); // if ("no layers") addLayer() if (layers.isEmpty()) { if(DEBUG)System.out.println("WebServiceLayer: no layers"); Layer x = buildLayer(gg); x.setName(""+layerid++); this.addLayer(x,true); } // if ("one layer loading") {removeLayer;addLayer} else if ( (layers.size()==1) && (((Layer)layers.firstElement()).getStatus()!=Layer.COMPLETED) ) { if(DEBUG)System.out.println("WebServiceLayer: one layer loading"); if (!extent.equals(this.oldExtent)) { this.removeLayer((Layer)layers.firstElement(),true); Layer x = buildLayer(gg); x.setName(""+layerid++); this.addLayer(x,true); } } // ("one layer loaded") {paint the layer, start getting a new layer} else if ( (layers.size()==1) && (((Layer)layers.firstElement()).getStatus()==Layer.COMPLETED) ) { if(DEBUG)System.out.println("WebServiceLayer: one layer loaded"); ((Layer)layers.firstElement()).paintScaled(gg); if (!extent.equals(this.oldExtent)) { Layer x = buildLayer(gg); x.setName(""+layerid++); this.addLayer(x,true); } } // ("one layer loaded, one loading") {paint layer1, get layer2 again} else if ( (layers.size()==2) && (((Layer)layers.firstElement()).getStatus()==Layer.COMPLETED) && (((Layer)layers.lastElement()).getStatus()!=Layer.COMPLETED) ) { if(DEBUG)System.out.println("WebServiceLayer: one layer loaded, one loading"); ((Layer)layers.firstElement()).paintScaled(gg); if (!extent.equals(this.oldExtent)) { this.removeLayer((Layer)layers.lastElement(),true); Layer x = buildLayer(gg); x.setName(""+layerid++); this.addLayer(x,true); } } // ("2 layers loaded") {repaint last layer, remove first, get new layer} else if ( (layers.size()==2) && (((Layer)layers.firstElement()).getStatus()==Layer.COMPLETED) && (((Layer)layers.lastElement()).getStatus()==Layer.COMPLETED) ) { if(DEBUG)System.out.println("WebServiceLayer: 2 layers loaded"); ((Layer)layers.lastElement()).paintScaled(gg); this.removeLayer((Layer)layers.firstElement(),true); if (!extent.equals(this.oldExtent)) { Layer x = buildLayer(gg); x.setName(""+layerid++); this.addLayer(x,true); } } else if(DEBUG)System.out.println( "WebServiceLayer - unexpected paintScaled options" +" layers.size="+layers.size() +" firstElement.status="+((Layer)layers.firstElement()).getStatus() +" lastElement.status="+((Layer)layers.lastElement()).getStatus() ); this.oldExtent=extent; } /* protected void paintScaled(Graphics g, Scaler scale, Shader shade, GeoData data, ShadeStyle style){ if (DEBUG) System.out.println("WebServiceLayer.paintScaled2 "); GeoGraphics gg = new GeoGraphics(g,scale,shade,data,style,null,0); this.paintScaled(gg); } */ } /* * Changes in file: * * $Log: WebServiceLayer.java,v $ * Revision 1.7 2002/03/01 19:54:16 jmacgill * * removed outdated paintscaled method * * Revision 1.6 2002/01/31 10:21:48 ianturton * Added a layerid to use as the name of a layer to aid debugging. * * Revision 1.5 2001/11/21 13:48:19 kobit * Added support for creating ImageLayer with InputStream as image data source and full support for downaloding map data from WMS with jprotocols package * * Revision 1.4 2001/10/24 09:40:18 kobit * Added LOG cvs keyword to the end of file * * */