package com.github.davidmoten.grumpy.wms;

import java.awt.Color;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import com.github.davidmoten.grumpy.projection.Projector;
import com.github.davidmoten.grumpy.projection.ProjectorTarget;

public class WmsUtil {

    public static List<Color> getColorFromStyles(List<String> styles) {
        List<Color> colors = new ArrayList<Color>();
        for (String style : styles) {
            Field field;
            try {
                field = Color.class.getField(style);
                Color color = (Color) field.get(null);
                colors.add(color);
            } catch (SecurityException e) {
                // ignore
            } catch (NoSuchFieldException e) {
                // ignore
            } catch (IllegalArgumentException e) {
                // ignore
            } catch (IllegalAccessException e) {
                // ignore;
            }
        }
        return colors;
    }

    public static Projector getProjector(WmsRequest request) {
        ProjectorTarget target = new ProjectorTarget(request.getWidth(), request.getHeight());
        return new Projector(request.getBounds(), target);
    }

}

@@ -145,73 +145,340 @@
 til.
-List;%0D%0A%0D%0Aimport com.github.davidmoten.grumpy.projection.Projector
+Collections;%0D%0Aimport java.util.List;%0D%0A%0D%0Aimport org.geotools.geometry.jts.ReferencedEnvelope;%0D%0Aimport org.geotools.renderer.lite.RendererUtilities;%0D%0A%0D%0Aimport com.github.davidmoten.grumpy.projection.FeatureUtil;%0D%0Aimport com.github.davidmoten.grumpy.projection.Projector;%0D%0Aimport com.github.davidmoten.grumpy.projection.ProjectorBounds
 ;%0D%0Ai
@@ -1518,11 +1518,458 @@
    %7D%0D%0A%0D%0A
+    public static double calculateScale(WmsRequest request) %7B%0D%0A        ProjectorBounds b = request.getBounds();%0D%0A        ReferencedEnvelope envelope = new ReferencedEnvelope(b.getMinX(), b.getMaxX(), b.getMinY(),%0D%0A                b.getMaxY(), FeatureUtil.getCrs(request.getCrs()));%0D%0A        double scale = RendererUtilities.calculateOGCScale(envelope, request.getWidth(),%0D%0A                Collections.emptyMap());%0D%0A        return scale;%0D%0A    %7D%0D%0A%0D%0A
 %7D%0D%0A

add calculateScale