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

uk.ac.ceh.dynamo.providers.GridMapMapViewportProvider 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 uk.ac.ceh.dynamo.GridMapRequestFactory;
import java.util.HashMap;
import java.util.Map;
import org.springframework.web.bind.annotation.RequestParam;
import uk.ac.ceh.dynamo.BoundingBox;
import uk.ac.ceh.dynamo.GridMap;
import uk.ac.ceh.dynamo.GridMapMethod;
import uk.ac.ceh.dynamo.Provides;
import uk.ac.ceh.dynamo.GridMapRequestFactory.GridMapRequest;

/**
 *
 * @author Chris Johnson
 */
public class GridMapMapViewportProvider {
    
    @Provides(GridMapMethod.MAP)
    public Map processRequestParameters(
                    GridMapRequestFactory helper,
                    GridMap gridMapProperties, 
                    GridMap.GridLayer layer,
                    @RequestParam(value="imagesize", required=false, defaultValue="10") String imagesizeStr,
                    @RequestParam(value="feature", required=false) String featureId,
                    @RequestParam(value="nationalextent", required=false) String nationExtent) {
        Map toReturn = new HashMap<>();
        BoundingBox featureToFocusOn = helper.getFeatureToFocusOn(featureId, nationExtent, gridMapProperties);
        GridMapRequest request = helper.getGridMapRequest(featureToFocusOn, layer.resolution(), Integer.parseInt(imagesizeStr));
        
        if(!request.isValidRequest()) {
            throw new IllegalArgumentException("It is not possible to create an image for the given parameters.");
        }
        
        toReturn.put("SRS",     new String[]{ featureToFocusOn.getEpsgCode() });
        toReturn.put("HEIGHT",  new String[]{ Integer.toString(request.getHeight()) });
        toReturn.put("WIDTH",   new String[]{ Integer.toString(request.getWidth()) });
        toReturn.put("BBOX",    new String[] { request.getBBox() });
        return toReturn;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy