package com.google.gwt.maps.client.visualizationlib; /* * #%L * GWT Maps API V3 - Core API * %% * Copyright (C) 2011 - 2012 GWT Maps API V3 * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import com.google.gwt.ajaxloader.client.ArrayHelper; import com.google.gwt.core.client.JsArray; import com.google.gwt.maps.client.AbstractMapsGWTTestHelper; import com.google.gwt.maps.client.LoadApi.LoadLibrary; import com.google.gwt.maps.client.MapOptions; import com.google.gwt.maps.client.MapWidget; import com.google.gwt.maps.client.base.LatLng; import com.google.gwt.maps.client.mvc.MVCArray; import com.google.gwt.user.client.ui.RootPanel; public class HeatMapLayerGwtTest extends AbstractMapsGWTTestHelper { @Override public LoadLibrary[] getLibraries() { return new LoadLibrary[] { LoadLibrary.VISUALIZATION }; } public void testUse() { asyncLibTest(new Runnable() { @Override public void run() { HeatMapLayerOptions options = HeatMapLayerOptions.newInstance(); @SuppressWarnings("unused") HeatMapLayer layer = HeatMapLayer.newInstance(options); finishTest(); } }); } public void testGetMap() { asyncLibTest(new Runnable() { @Override public void run() { MapOptions options = MapOptions.newInstance(); MapWidget mapWidget = new MapWidget(options); mapWidget.setSize("500px", "500px"); RootPanel.get().add(mapWidget); HeatMapLayerOptions layerOptions = HeatMapLayerOptions.newInstance(); HeatMapLayer layer = HeatMapLayer.newInstance(layerOptions); // test getting null map assertNull(layer.getMap()); // test clearing from map // layer.setMap(null); // odd Junit error, but function works in // production // ensure we can read back the map value and that it is correct // TODO figure out why this works on stepping through, but not // on running suite // layer.setMap(mapWidget); // assertLatLngEquals(mapWidget.getCenter(), // layer.getMap().getCenter()); finishTest(); } }); } public void testSetDataLatLngMVCArray() { asyncLibTest(new Runnable() { @Override public void run() { MapOptions options = MapOptions.newInstance(); MapWidget mapWidget = new MapWidget(options); mapWidget.setSize("500px", "500px"); RootPanel.get().add(mapWidget); HeatMapLayerOptions layerOptions = HeatMapLayerOptions.newInstance(); HeatMapLayer layer = HeatMapLayer.newInstance(layerOptions); // test getting empty map MVCArray<LatLng> actual = layer.getData(); assertEquals(0, actual.getLength()); // foo data MVCArray<LatLng> expected = getMVCLatLngData(); // ensure we can read back the map value and that it is correct layer.setData(expected); actual = layer.getData(); assertEquals(expected.getLength(), actual.getLength()); assertEquals(expected.get(0).toString(), actual.get(0).toString()); // test clearing from map MVCArray<LatLng> emptySet = MVCArray.newInstance(); layer.setData(emptySet); actual = layer.getData(); assertEquals(0, actual.getLength()); finishTest(); } }); } public void testSetDataWeightedLocationMVCArray() { asyncLibTest(new Runnable() { @Override public void run() { MapOptions options = MapOptions.newInstance(); MapWidget mapWidget = new MapWidget(options); mapWidget.setSize("500px", "500px"); RootPanel.get().add(mapWidget); HeatMapLayerOptions layerOptions = HeatMapLayerOptions.newInstance(); HeatMapLayer layer = HeatMapLayer.newInstance(layerOptions); // test getting empty map MVCArray<WeightedLocation> actual = layer.getDataWeighted(); assertEquals(0, actual.getLength()); // foo data MVCArray<WeightedLocation> expected = getMVCWeightedData(); // ensure we can read back the map value and that it is correct layer.setDataWeighted(expected); actual = layer.getDataWeighted(); assertEquals(expected.getLength(), actual.getLength()); assertEquals(expected.get(0).toString(), actual.get(0).toString()); // test clearing from map MVCArray<WeightedLocation> emptySet = MVCArray.newInstance(); layer.setDataWeighted(emptySet); actual = layer.getDataWeighted(); assertEquals(0, actual.getLength()); finishTest(); } }); } /** * Note that you can only GET as MVCArray, but you can set as JsArray */ public void testSetDataLatLngJsArray() { asyncLibTest(new Runnable() { @Override public void run() { MapOptions options = MapOptions.newInstance(); MapWidget mapWidget = new MapWidget(options); mapWidget.setSize("500px", "500px"); RootPanel.get().add(mapWidget); HeatMapLayerOptions layerOptions = HeatMapLayerOptions.newInstance(); HeatMapLayer layer = HeatMapLayer.newInstance(layerOptions); // test getting empty map MVCArray<LatLng> actual = layer.getData(); assertEquals(0, actual.getLength()); // TODO Unexpected error on this unit test /* // ensure we can read back the map value and that it is correct // foo data JsArray<LatLng> expected = * getJsLatLngArrayData(); * * layer.setData(expected); actual = layer.getData(); * * assertEquals(expected.length(), actual.getLength()); assertEquals(expected.get(0).toString(), * actual.get(0).toString()); // test clearing from map JsArray<LatLng> emptySet = ArrayHelper.toJsArray(new * LatLng[]{}); layer.setData(emptySet); actual = layer.getData(); assertEquals(0, actual.getLength()); */ finishTest(); } }); } public void testSetDataWeightedLocationJsArray() { asyncLibTest(new Runnable() { @Override public void run() { MapOptions options = MapOptions.newInstance(); MapWidget mapWidget = new MapWidget(options); mapWidget.setSize("500px", "500px"); RootPanel.get().add(mapWidget); HeatMapLayerOptions layerOptions = HeatMapLayerOptions.newInstance(); HeatMapLayer layer = HeatMapLayer.newInstance(layerOptions); // test getting empty map MVCArray<WeightedLocation> actual = layer.getDataWeighted(); assertEquals(0, actual.getLength()); // TODO Fix unexpected test error here /* // ensure we can read back the map value and that it is correct * * // foo data JsArray<WeightedLocation> expected = getJsWeightedArrayData(); layer.setDataWeighted(expected); * actual = layer.getDataWeighted(); * * assertEquals(expected.length(), actual.getLength()); assertEquals(expected.get(0).toString(), * actual.get(0).toString()); * * // test clearing from map JsArray<WeightedLocation> emptySet = ArrayHelper.toJsArray(new * WeightedLocation[]{}); layer.setDataWeighted(emptySet); actual = layer.getDataWeighted(); assertEquals(0, * actual.getLength()) */; finishTest(); } }); } /** * Get basic spatial data as MVCArray * * @return */ public final static MVCArray<LatLng> getMVCLatLngData() { MVCArray<LatLng> data = MVCArray.newInstance(getJsLatLngArrayData()); return data; } /** * Get weighted spatial data as MVCArray * * @return */ private static MVCArray<WeightedLocation> getMVCWeightedData() { MVCArray<WeightedLocation> data = MVCArray.newInstance(getJsWeightedArrayData()); return data; } /** * Get basic spatial data as JsArray * * @return */ private static JsArray<LatLng> getJsLatLngArrayData() { return ArrayHelper.toJsArray(getLatLngData()); } /** * Get weighted spatial data as JsArray * * @return */ private static JsArray<WeightedLocation> getJsWeightedArrayData() { return ArrayHelper.toJsArray(getWeightedData()); } /** * Get basic spatial data for use in tests * * @return */ private static LatLng[] getLatLngData() { LatLng[] data = new LatLng[] { LatLng.newInstance(37.782551d, -122.445368d), LatLng.newInstance(37.782745d, -122.444586d), LatLng.newInstance(37.782842d, -122.443688d), LatLng.newInstance(37.782919d, -122.442815d), LatLng.newInstance(37.782992d, -122.442112d), LatLng.newInstance(37.783100d, -122.441461d), LatLng.newInstance(37.783206d, -122.440829d), LatLng.newInstance(37.783273d, -122.440324d), LatLng.newInstance(37.783316d, -122.440023d), LatLng.newInstance(37.783357d, -122.439794d), LatLng.newInstance(37.783371d, -122.439687d), LatLng.newInstance(37.783368d, -122.439666d), LatLng.newInstance(37.783383d, -122.439594d), LatLng.newInstance(37.783508d, -122.439525d), LatLng.newInstance(37.783842d, -122.439591d), LatLng.newInstance(37.784147d, -122.439668d), LatLng.newInstance(37.784206d, -122.439686d), LatLng.newInstance(37.784386d, -122.439790d), LatLng.newInstance(37.784701d, -122.439902d), LatLng.newInstance(37.784965d, -122.439938d), LatLng.newInstance(37.785010d, -122.439947d), LatLng.newInstance(37.785360d, -122.439952d), LatLng.newInstance(37.785715d, -122.440030d), LatLng.newInstance(37.786117d, -122.440119d), LatLng.newInstance(37.786564d, -122.440209d), LatLng.newInstance(37.786905d, -122.440270d) }; return data; } /** * Get weighted spatial data for use in tests * * @return */ private static WeightedLocation[] getWeightedData() { WeightedLocation[] data = new WeightedLocation[] { WeightedLocation.newInstance(LatLng.newInstance(37.782551d, -122.445368d), 9d), WeightedLocation.newInstance(LatLng.newInstance(37.782745d, -122.444586d), 2d), WeightedLocation.newInstance(LatLng.newInstance(37.782842d, -122.443688d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.782919d, -122.442815d), 7d), WeightedLocation.newInstance(LatLng.newInstance(37.782992d, -122.442112d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.783100d, -122.441461d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.783206d, -122.440829d), 4d), WeightedLocation.newInstance(LatLng.newInstance(37.783273d, -122.440324d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.783316d, -122.440023d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.783357d, -122.439794d), 2d), WeightedLocation.newInstance(LatLng.newInstance(37.783371d, -122.439687d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.783368d, -122.439666d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.783383d, -122.439594d), 3d), WeightedLocation.newInstance(LatLng.newInstance(37.783508d, -122.439525d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.783842d, -122.439591d), 11d), WeightedLocation.newInstance(LatLng.newInstance(37.784147d, -122.439668d), 9d), WeightedLocation.newInstance(LatLng.newInstance(37.784206d, -122.439686d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.784386d, -122.439790d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.784701d, -122.439902d), 18d), WeightedLocation.newInstance(LatLng.newInstance(37.784965d, -122.439938d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.785010d, -122.439947d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.785360d, -122.439952d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.785715d, -122.440030d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.786117d, -122.440119d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.786564d, -122.440209d), 1d), WeightedLocation.newInstance(LatLng.newInstance(37.786905d, -122.440270d), 20d) }; return data; } }