HistoricEarthquakesLayer extends AbstractLayer implements Loader { protected void generateMagnitudeColoring(FloatBuffer colorBuffer, List<Earthquake> earthquakes) { double minMagnitude = Double.MAX_VALUE; double maxMagnitude = -Double.MAX_VALUE; for (Earthquake earthquake : earthquakes) { minMagnitude = Math.min(minMagnitude, earthquake.magnitude); maxMagnitude = Math.max(maxMagnitude, earthquake.magnitude); } for (Earthquake earthquake : earthquakes) { double percent = (earthquake.magnitude - minMagnitude) / (maxMagnitude - minMagnitude); percent = 1 - Math.pow(percent, 0.2); Color color = new HSLColor((float) (240d * percent), 100f, 50f).getRGB(); colorBuffer.put(color.getRed() / 255f).put(color.getGreen() / 255f).put(color.getBlue() / 255f); } } HistoricEarthquakesLayer(AVList params);  HistoricEarthquakesLayer(Document dom, AVList params);  HistoricEarthquakesLayer(Element domElement, AVList params); @Override boolean isLoading(); @Override void addLoadingListener(LoadingListener listener); @Override void removeLoadingListener(LoadingListener listener); final static String DATE_COLORING; final static String MAGNITUDE_COLORING; final static String DEPTH_COLORING; }
@Test public void testMagnitudeColoring() throws Exception { List<Earthquake> quakes = new ArrayList<Earthquake>(); quakes.add(new Earthquake(Position.fromDegrees(100, 100, 0), 0, getMillisForDate("1990-01-01"))); quakes.add(new Earthquake(Position.fromDegrees(100, 100, -100), 5, getMillisForDate("1990-01-01"))); quakes.add(new Earthquake(Position.fromDegrees(100, 100, -200), 10, getMillisForDate("1990-01-01"))); FloatBuffer colorBuffer = FloatBuffer.allocate(quakes.size() * 3); classUnderTest.generateMagnitudeColoring(colorBuffer, quakes); colorBuffer.rewind(); List<HSLColor> colors = getColors(colorBuffer); assertEquals(3, colors.size()); assertEquals(BLUE_HUE, colors.get(0).getHue(), 1); assertEquals(RED_HUE, colors.get(2).getHue(), 1); }