teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5993: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.shared; ingo@1328: ingo@2440: import java.util.Date; ingo@2440: ingo@1328: ingo@1328: public class MapUtils { ingo@1328: ingo@1328: public static final String GET_LEGEND_GRAPHIC_TEMPLATE = ingo@1328: "${SERVER}SERVICE=WMS&VERSION=1.1.1&layer=${LAYER}" + ingo@1328: "&REQUEST=getLegendGraphic&FORMAT=image/png"; ingo@1328: ingo@1328: ingo@1328: private MapUtils() { ingo@1328: } ingo@1328: aheinecke@5676: public static String getLegendGraphicUrl(String server, String layer) { aheinecke@5676: return getLegendGraphicUrl(server, layer, -1); aheinecke@5676: } ingo@1328: tom@8856: public static String getLegendGraphicUrl( tom@8856: String server, tom@8856: String layer, tom@8856: int dpi tom@8856: ) { ingo@1328: if (server == null || layer == null) { ingo@1328: return null; ingo@1328: } ingo@1328: aheinecke@5676: if (server.contains("osm.intevation.de")) { aheinecke@5676: // GetLegend is not implemented at osm.intevation.de aheinecke@5676: // This avoids an error in the print log aheinecke@5676: return null; aheinecke@5676: } ingo@1328: server = server.indexOf("?") >= 0 ? server : server + "?"; ingo@1328: ingo@1328: String url = GET_LEGEND_GRAPHIC_TEMPLATE; ingo@1328: url = url.replace("${SERVER}", server); ingo@1328: url = url.replace("${LAYER}", layer); ingo@2440: url = url + "×tamp=" + new Date().getTime(); aheinecke@5676: if (dpi != -1) { aheinecke@5676: url+="&legend_options=dpi:" + dpi; aheinecke@5676: } ingo@1328: ingo@1328: return url; ingo@1328: } ingo@1328: } ingo@1328: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :