package org.gisandchips.gwt.maps.wms.client; import com.google.gwt.maps.client.TileLayer; import com.google.gwt.maps.client.geom.LatLng; import com.google.gwt.maps.client.geom.MercatorProjection; import com.google.gwt.maps.client.geom.Point; import com.google.gwt.maps.client.geom.Projection; public class WMSTileLayer extends TileLayer{ private String baseServerUrl; private String layers; private String styles; private Projection projection; private String getMapUrl = null; public WMSTileLayer(String baseServerUrl, String layers, String styles, Projection projection) { super(null, 0, 20); this.baseServerUrl = baseServerUrl; this.layers = layers; this.styles = styles; //construct the base URL String urlBase = baseServerUrl + "?" + "FORMAT=image/png&SERVICE=WMS&REQUEST=GetMap&WIDTH=256&HEIGHT=256&VERSION=1.1.0&" + "STYLES=" + styles + "&" + "LAYERS="+ layers + "&"; getMapUrl = urlBase; } @Override public String getTileURL(Point tile, int zoom) { //Transforma las coordenadas a coordenadas Lat/Lon Point tileIndexLLPoint = Point.newInstance(tile.getX() * 256, (tile.getY() + 1) * 256); Point tileIndexURPoint = Point.newInstance(((tile.getX() + 1) * 256), (tile.getY()) * 256); LatLng llPoint = projection.fromPixelToLatLng(tileIndexLLPoint, zoom, true); LatLng urPoint = projection.fromPixelToLatLng(tileIndexURPoint, zoom, true); String url = getMapUrl + "SRS=EPSG:4326&BBOX=" + llPoint.getLongitude() + "," + llPoint.getLatitude() + "," + urPoint.getLongitude() + "," + urPoint.getLatitude(); return url; } @Override public double getOpacity() { return 1.0; } @Override public boolean isPng() { return true; } }