GeoWebCache

Ticket #31: geowebcache_mgmaps.diff

File geowebcache_mgmaps.diff, 8.0 kB (added by jaakl, 23 months ago)
  • C:/work/workspace2/maven.1208695595359/geowebcache/src/test/java/org/geowebcache/service/mgmaps/MGMapsConverterTest.java

     
     1package org.geowebcache.service.mgmaps; 
     2 
     3import java.util.Arrays; 
     4 
     5import junit.framework.TestCase; 
     6 
     7public class MGMapsConverterTest extends TestCase { 
     8 
     9    @Override 
     10    protected void setUp() throws Exception { 
     11        super.setUp(); 
     12    } 
     13 
     14    /** 
     15     * see 
     16     * Modified for MGMaps API 
     17     *  
     18     * @throws Exception 
     19     */ 
     20    public void testMGMapsConverter() throws Exception { 
     21        /* Check origin location */ 
     22        int x = 0; int y = 0; int z = 17; 
     23        int[] gridLoc = MGMapsConverter.convert(z, x, y); 
     24        int[] solution = {0,0,0}; 
     25         
     26        assert(Arrays.equals(gridLoc, solution)); 
     27         
     28        /* Check zoomlevel */ 
     29        x = 0; y = 0; z = 17-1; 
     30        solution[0] = 0; solution[1] = 1; solution[2] = 1; 
     31        gridLoc = MGMapsConverter.convert(z, x, y); 
     32        assert(Arrays.equals(gridLoc, solution)); 
     33         
     34        /* Check top right */ 
     35        x = 1; y = 0; z = 17-1; 
     36        solution[0] = 1; solution[1] = 1; solution[2] = 1; 
     37        gridLoc = MGMapsConverter.convert(z, x, y); 
     38        assert(Arrays.equals(gridLoc, solution)); 
     39         
     40        /* Check top right, zoomlevel */ 
     41        x = 3; y = 0; z = 17-2; 
     42        solution[0] = 3; solution[1] = 3; solution[2] = 2; 
     43        gridLoc = MGMapsConverter.convert(z, x, y); 
     44        assert(Arrays.equals(gridLoc, solution)); 
     45         
     46        /* Check middle */ 
     47        x = 2; y = 1; z = 17-2; 
     48        solution[0] = 2; solution[1] = 2; solution[2] = 2; 
     49        gridLoc = MGMapsConverter.convert(z, x, y); 
     50        assert(Arrays.equals(gridLoc, solution)); 
     51         
     52        //System.out.println(Arrays.toString(solution)); 
     53        //System.out.println(Arrays.toString(gridLoc)); 
     54    } 
     55} 
     56 No newline at end of file 
  • C:/work/workspace2/maven.1208695595359/geowebcache/src/main/java/org/geowebcache/service/mgmaps/MGMapsConverter.java

     
     1/** 
     2 * This program is free software: you can redistribute it and/or modify 
     3 * it under the terms of the GNU Lesser General Public License as published by 
     4 * the Free Software Foundation, either version 3 of the License, or 
     5 * (at your option) any later version. 
     6 * 
     7 *  This program is distributed in the hope that it will be useful, 
     8 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     9 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     10 *  GNU General Public License for more details. 
     11 * 
     12 *  You should have received a copy of the GNU Lesser General Public License 
     13 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     14 *  
     15 * @author Arne Kepp, The Open Planning Project, Copyright 2008 
     16 */ 
     17package org.geowebcache.service.mgmaps; 
     18 
     19import java.util.Map; 
     20 
     21import javax.servlet.http.HttpServletRequest; 
     22 
     23import org.apache.commons.logging.Log; 
     24import org.apache.commons.logging.LogFactory; 
     25import org.geowebcache.layer.SRS; 
     26import org.geowebcache.layer.TileLayer; 
     27import org.geowebcache.layer.TileRequest; 
     28import org.geowebcache.mime.MimeException; 
     29import org.geowebcache.mime.MimeType; 
     30import org.geowebcache.service.Service; 
     31import org.geowebcache.service.ServiceException; 
     32import org.geowebcache.service.ServiceRequest; 
     33import org.geowebcache.util.ServletUtils; 
     34 
     35/** 
     36 * Class to convert from Google Maps coordinates into the internal 
     37 * representation of a tile. 
     38 */ 
     39public class MGMapsConverter extends Service { 
     40    public static final String SERVICE_MGMAPS = "mgmaps"; 
     41 
     42    private static Log log = LogFactory 
     43            .getLog(org.geowebcache.service.mgmaps.MGMapsConverter.class); 
     44 
     45    public MGMapsConverter() { 
     46        super(SERVICE_MGMAPS); 
     47    } 
     48 
     49    public ServiceRequest getServiceRequest(HttpServletRequest request)  throws ServiceException { 
     50        return new ServiceRequest(super.getLayersParameter(request)); 
     51    } 
     52 
     53    public TileRequest getTileRequest(TileLayer tileLayer, HttpServletRequest request) 
     54    throws ServiceException { 
     55        Map params = request.getParameterMap(); 
     56         
     57        String mimeType = ServletUtils.stringFromMap(params, "format"); 
     58        String strZoom = ServletUtils.stringFromMap(params, "zoom"); 
     59        String strX = ServletUtils.stringFromMap(params, "x"); 
     60        String strY = ServletUtils.stringFromMap(params, "y"); 
     61 
     62        int[] gridLoc = MGMapsConverter.convert(Integer.parseInt(strZoom), Integer 
     63                .parseInt(strX), Integer.parseInt(strY)); 
     64         
     65        SRS srs = new SRS(900913); 
     66         
     67        MimeType mime = null;  
     68        try { 
     69            if(mimeType == null) { 
     70                mimeType = "image/png"; 
     71            } 
     72            mime = MimeType.createFromMimeType(mimeType); 
     73        } catch (MimeException me) { 
     74            throw new ServiceException("Unable to determine requested format, " + mimeType); 
     75        } 
     76        return new TileRequest(gridLoc,mime,srs); 
     77    } 
     78 
     79    /** 
     80     * Convert Google's tiling coordinates into an {x,y,x} 
     81     *  
     82     * see 
     83     * http://code.google.com/apis/maps/documentation/overlays.html#Custom_Map_Types 
     84     * Modified by JaakL for mgmaps zoom understanding 
     85     * @param quadKey 
     86     * @return 
     87     */ 
     88    public static int[] convert(int zoomLevel, int x, int y) { 
     89        // Extent is the total number of tiles in y direction 
     90        int newZoom=17-zoomLevel; 
     91        int extent = (int) Math.pow(2, newZoom); 
     92 
     93        if (x < 0 || x > extent - 1) { 
     94            log.error("The X coordinate is not sane: " + x); 
     95            return null; 
     96        } 
     97 
     98        if (y < 0 || y > extent - 1) { 
     99            log.error("The Y coordinate is not sane: " + y); 
     100            return null; 
     101        } 
     102 
     103        // xPos and yPos correspond to the top left hand corner 
     104        int[] gridLoc = { x, extent - y - 1, newZoom}; 
     105 
     106        return gridLoc; 
     107    } 
     108} 
  • C:/work/workspace2/maven.1208695595359/geowebcache/src/main/resources/applicationContext.xml

     
    5757  <bean id="serviceWMS"  
    5858        class="org.geowebcache.service.wms.WMSService"/> 
    5959  <bean id="serviceGMaps" 
    60         class="org.geowebcache.service.gmaps.GMapsConverter"/> 
     60        class="org.geowebcache.service.gmaps.GMapsConverter"/> 
     61  <bean id="serviceMGMaps" 
     62        class="org.geowebcache.service.mgmaps.MGMapsConverter"/> 
    6163  <bean id="serviceVE" 
    6264        class="org.geowebcache.service.ve.VEConverter"/> 
    6365  <bean id="serviceKML" 
  • C:/work/workspace2/maven.1208695595359/geowebcache/pom.xml

     
    44  <modelVersion>4.0.0</modelVersion> 
    55  <groupId>org.opengeo</groupId> 
    66  <artifactId>geowebcache</artifactId> 
    7   <packaging>jar</packaging> 
     7  <packaging>war</packaging> 
    88  <version>1.0-SNAPSHOT</version> 
    99  <name>geowebcache</name> 
    1010  <url>http://geowebcache.org</url>