
uk.ac.ceh.dynamo.providers.GridMapMapLayersProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dynamo-mapping Show documentation
Show all versions of dynamo-mapping Show documentation
A Spring MVC plugin for creating dynamic MapServer maps with freemarker templates
package uk.ac.ceh.dynamo.providers;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestParam;
import uk.ac.ceh.dynamo.GridMap;
import uk.ac.ceh.dynamo.GridMap.Layer;
import uk.ac.ceh.dynamo.GridMapMethod;
import uk.ac.ceh.dynamo.Provides;
/**
*
* @author Chris Johnson
*/
public class GridMapMapLayersProvider {
@Provides(GridMapMethod.MAP)
public Map processRequestParameters(
GridMap gridMapProperties,
@RequestParam(value="background", required=false) List requestedBackgroundLayers,
@RequestParam(value="overlay", required=false) List requestedOverlayLayers,
GridMap.GridLayer layer) {
Map toReturn = new HashMap<>();
List layersToRequest = new ArrayList<>();
layersToRequest.addAll(getLayersToRequest(requestedBackgroundLayers, gridMapProperties.backgrounds(), gridMapProperties.defaultBackgrounds()));
layersToRequest.add(layer.layer()); //add the resolution layer
layersToRequest.addAll(getLayersToRequest(requestedOverlayLayers, gridMapProperties.overlays(), gridMapProperties.defaultOverlays()));
toReturn.put("LAYERS", new String[]{ StringUtils.collectionToCommaDelimitedString(layersToRequest) });
return toReturn;
}
private List getLayersToRequest(List requestedBackgroundLayers, Layer[] validLayers, String[] defaultLayers) {
List supportedBackgroundLayers = Arrays.asList(validLayers); //get the valid background layers as a list
List backgroundLayers = (requestedBackgroundLayers != null) //get the requested background layers
? requestedBackgroundLayers
: Arrays.asList(defaultLayers);
List toReturn = new ArrayList<>();
//check the requested list is valid
for(String currRequestedLayer : backgroundLayers) {
toReturn.add(getBackground(currRequestedLayer, supportedBackgroundLayers));
}
return getWMSLayersFromLayerList(toReturn);
}
private static Layer getBackground(String name, List toFindIn) {
for(Layer currBackground : toFindIn) {
if(currBackground.name().equals(name)) {
return currBackground;
}
}
throw new IllegalArgumentException("The background layer " + name +
" was requested but is not valid.");
}
private static List getWMSLayersFromLayerList(List layerList) {
List toReturn = new ArrayList<>();
for(Layer currBackground : layerList) {
toReturn.addAll(Arrays.asList(currBackground.layers()));
}
return toReturn;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy