All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.ac.ceh.dynamo.providers.GridMapMapProvider Maven / Gradle / Ivy

Go to download

A Spring MVC plugin for creating dynamic MapServer maps with freemarker templates

There is a newer version: 1.3
Show newest version
package uk.ac.ceh.dynamo.providers;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import uk.ac.ceh.dynamo.GridMapMethod;
import uk.ac.ceh.dynamo.Provides;

/**
 *
 * @author Chris Johnson
 */
public class GridMapMapProvider {
    private static final Map FORMATS;
    
    static {
        FORMATS = new HashMap<>();
        FORMATS.put("png", "image/png");
        FORMATS.put("gif", "image/gif");
        FORMATS.put("jpeg", "image/jpeg");
    }
    
    @Provides(GridMapMethod.MAP)
    public Map processRequestParameters(HttpServletRequest request) {
        Map toReturn = new HashMap<>();
        toReturn.put("SERVICE", new String[]{"WMS"});
        toReturn.put("VERSION", new String[]{"1.1.1"});
        toReturn.put("REQUEST", new String[]{"GetMap"});
        toReturn.put("STYLES", new String[]{""});
        toReturn.put("TRANSPARENT", new String[]{"true"});
        toReturn.put("FORMAT", new String[]{ checkAndGetValue(FORMATS, getValue(request.getParameterMap(), "format", "png")) });
        return toReturn;
    }
    
    private static String checkAndGetValue(Map map, String toGet) {
        if(!map.containsKey(toGet)) {
            throw new IllegalArgumentException("I don't understand " + toGet + 
                    " valid values are " + map.keySet());
        }
        return map.get(toGet);
    }
    
    private static String getValue(Map query, String toGet, String defaultVal) {
        return (query.containsKey(toGet)) ? query.get(toGet)[0] : defaultVal;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy