Commit 5395a834 authored by Evan W. Patton's avatar Evan W. Patton Committed by Susan Rati Lane

Ensure Polygon Points and HolePoints invalidate map view

Change-Id: I35b143a3dbe3aecdc6c57352468c73e9baf40b72
parent 12188c75
...@@ -141,6 +141,7 @@ public class Polygon extends PolygonBase implements MapPolygon { ...@@ -141,6 +141,7 @@ public class Polygon extends PolygonBase implements MapPolygon {
"Unable to determine the structure of the points argument."); "Unable to determine the structure of the points argument.");
} }
clearGeometry(); clearGeometry();
map.getController().updateFeaturePosition(this);
} catch(DispatchableError e) { } catch(DispatchableError e) {
container.$form().dispatchErrorOccurredEvent(this, "Points", e.getErrorCode(), e.getArguments()); container.$form().dispatchErrorOccurredEvent(this, "Points", e.getErrorCode(), e.getArguments());
} }
...@@ -209,7 +210,7 @@ public class Polygon extends PolygonBase implements MapPolygon { ...@@ -209,7 +210,7 @@ public class Polygon extends PolygonBase implements MapPolygon {
"Unable to determine the structure of the points argument."); "Unable to determine the structure of the points argument.");
} }
clearGeometry(); clearGeometry();
map.getController().updateFeaturePosition(this); map.getController().updateFeatureHoles(this);
} catch(DispatchableError e) { } catch(DispatchableError e) {
container.$form().dispatchErrorOccurredEvent(this, "HolePoints", container.$form().dispatchErrorOccurredEvent(this, "HolePoints",
e.getErrorCode(), e.getArguments()); e.getErrorCode(), e.getArguments());
...@@ -222,18 +223,18 @@ public class Polygon extends PolygonBase implements MapPolygon { ...@@ -222,18 +223,18 @@ public class Polygon extends PolygonBase implements MapPolygon {
public void HolePointsFromString(String pointString) { public void HolePointsFromString(String pointString) {
if (TextUtils.isEmpty(pointString)) { if (TextUtils.isEmpty(pointString)) {
holePoints = new ArrayList<List<List<GeoPoint>>>(); // create a new list in case the user has saved a reference holePoints = new ArrayList<List<List<GeoPoint>>>(); // create a new list in case the user has saved a reference
map.getController().updateFeaturePosition(this); map.getController().updateFeatureHoles(this);
return; return;
} }
try { try {
JSONArray content = new JSONArray(pointString); JSONArray content = new JSONArray(pointString);
if (content.length() == 0) { if (content.length() == 0) {
holePoints = new ArrayList<List<List<GeoPoint>>>(); // create a new list in case the user has saved a reference holePoints = new ArrayList<List<List<GeoPoint>>>(); // create a new list in case the user has saved a reference
map.getController().updateFeaturePosition(this); map.getController().updateFeatureHoles(this);
return; return;
} }
holePoints = GeometryUtil.multiPolygonHolesToList(content); holePoints = GeometryUtil.multiPolygonHolesToList(content);
map.getController().updateFeaturePosition(this); map.getController().updateFeatureHoles(this);
Log.d(TAG, "Points: " + points); Log.d(TAG, "Points: " + points);
} catch(JSONException e) { } catch(JSONException e) {
Log.e(TAG, "Unable to parse point string", e); Log.e(TAG, "Unable to parse point string", e);
......
...@@ -229,6 +229,11 @@ class DummyMapController implements MapController { ...@@ -229,6 +229,11 @@ class DummyMapController implements MapController {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public void updateFeatureHoles(MapPolygon polygon) {
throw new UnsupportedOperationException();
}
@Override @Override
public void updateFeaturePosition(MapCircle circle) { public void updateFeaturePosition(MapCircle circle) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
......
...@@ -441,6 +441,13 @@ public final class MapFactory { ...@@ -441,6 +441,13 @@ public final class MapFactory {
*/ */
void updateFeaturePosition(MapPolygon polygon); void updateFeaturePosition(MapPolygon polygon);
/**
* Update the holes in a polygon on the map.
*
* @param polygon the polygon that needs its holes updated
*/
void updateFeatureHoles(MapPolygon polygon);
/** /**
* Update the position of a circle on the map. * Update the position of a circle on the map.
* *
......
...@@ -737,6 +737,14 @@ class NativeOpenStreetMapController implements MapController, MapListener { ...@@ -737,6 +737,14 @@ class NativeOpenStreetMapController implements MapController, MapListener {
MultiPolygon polygon = (MultiPolygon) featureOverlays.get(aiPolygon); MultiPolygon polygon = (MultiPolygon) featureOverlays.get(aiPolygon);
if (polygon != null) { if (polygon != null) {
polygon.setMultiPoints(aiPolygon.getPoints()); polygon.setMultiPoints(aiPolygon.getPoints());
view.invalidate();
}
}
@Override
public void updateFeatureHoles(MapPolygon aiPolygon) {
MultiPolygon polygon = (MultiPolygon) featureOverlays.get(aiPolygon);
if (polygon != null) {
polygon.setMultiHoles(aiPolygon.getHolePoints()); polygon.setMultiHoles(aiPolygon.getHolePoints());
view.invalidate(); view.invalidate();
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package com.google.appinventor.components.runtime; package com.google.appinventor.components.runtime;
import android.view.ViewGroup;
import com.google.appinventor.components.common.ComponentConstants; import com.google.appinventor.components.common.ComponentConstants;
import com.google.appinventor.components.runtime.shadows.org.osmdroid.tileprovider.modules.ShadowMapTileModuleProviderBase; import com.google.appinventor.components.runtime.shadows.org.osmdroid.tileprovider.modules.ShadowMapTileModuleProviderBase;
import com.google.appinventor.components.runtime.shadows.org.osmdroid.views.ShadowMapView; import com.google.appinventor.components.runtime.shadows.org.osmdroid.views.ShadowMapView;
...@@ -13,6 +14,7 @@ import com.google.appinventor.components.runtime.util.YailList; ...@@ -13,6 +14,7 @@ import com.google.appinventor.components.runtime.util.YailList;
import org.junit.Before; import org.junit.Before;
import org.osmdroid.util.GeoPoint; import org.osmdroid.util.GeoPoint;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.internal.Shadow;
import static com.google.appinventor.components.runtime.util.GeometryUtil.ONE_DEG_IN_METERS; import static com.google.appinventor.components.runtime.util.GeometryUtil.ONE_DEG_IN_METERS;
...@@ -135,6 +137,10 @@ public class MapTestBase extends RobolectricTestBase { ...@@ -135,6 +137,10 @@ public class MapTestBase extends RobolectricTestBase {
return map; return map;
} }
public ShadowMapView getMapShadow() {
return Shadow.extract(((ViewGroup)map.getView()).getChildAt(0));
}
@Before @Before
public void setUp() { public void setUp() {
super.setUp(); super.setUp();
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
package com.google.appinventor.components.runtime; package com.google.appinventor.components.runtime;
import android.view.ViewGroup;
import com.google.appinventor.components.runtime.shadows.ShadowEventDispatcher; import com.google.appinventor.components.runtime.shadows.ShadowEventDispatcher;
import com.google.appinventor.components.runtime.shadows.org.osmdroid.views.ShadowMapView;
import com.google.appinventor.components.runtime.util.ErrorMessages; import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.GeometryUtil; import com.google.appinventor.components.runtime.util.GeometryUtil;
import com.google.appinventor.components.runtime.util.YailList; import com.google.appinventor.components.runtime.util.YailList;
...@@ -13,12 +15,17 @@ import org.junit.Before; ...@@ -13,12 +15,17 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.Geometry;
import org.osmdroid.util.GeoPoint; import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.robolectric.Shadows;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowView;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/** /**
* Unit tests for the Polygon component. * Unit tests for the Polygon component.
...@@ -110,6 +117,14 @@ public class PolygonTest extends MapTestBase { ...@@ -110,6 +117,14 @@ public class PolygonTest extends MapTestBase {
assertEquals(4, points.size()); assertEquals(4, points.size());
} }
@Test
public void testPointsInvalidatesView() {
ShadowMapView view = getMapShadow();
view.clearWasInvalidated();
defaultPolygon(polygon);
assertTrue(view.wasInvalidated());
}
@Test @Test
public void testPointsMultipolygon() { public void testPointsMultipolygon() {
defaultMultipolygon(polygon); defaultMultipolygon(polygon);
...@@ -192,6 +207,22 @@ public class PolygonTest extends MapTestBase { ...@@ -192,6 +207,22 @@ public class PolygonTest extends MapTestBase {
assertEquals(3, ((YailList) holes.get(1)).size()); // three points in the hole assertEquals(3, ((YailList) holes.get(1)).size()); // three points in the hole
} }
@Test
public void testHolePointsInvalidatesView() {
defaultPolygon(polygon);
ShadowMapView view = getMapShadow();
view.clearWasInvalidated();
polygon.HolePoints(YailList.makeList(new Object[] {
// First hole
YailList.makeList(new Object[] {
GeometryUtil.asYailList(new GeoPoint(0.5, 0.5)),
GeometryUtil.asYailList(new GeoPoint(0.25, 0.5)),
GeometryUtil.asYailList(new GeoPoint(0.5, 0.25))
})
}));
assertTrue(view.wasInvalidated());
}
@Test @Test
public void testHolePointsMultipolygon() { public void testHolePointsMultipolygon() {
defaultMultipolygon(polygon); defaultMultipolygon(polygon);
......
...@@ -243,6 +243,11 @@ public class DummyMapControllerTest { ...@@ -243,6 +243,11 @@ public class DummyMapControllerTest {
mapController.updateFeaturePosition((MapPolygon) null); mapController.updateFeaturePosition((MapPolygon) null);
} }
@Test(expected = UnsupportedOperationException.class)
public void testUpdateFeatureHoles() {
mapController.updateFeatureDraggable(null);
}
@Test(expected = UnsupportedOperationException.class) @Test(expected = UnsupportedOperationException.class)
public void testUpdateFeaturePositionCircle() { public void testUpdateFeaturePositionCircle() {
mapController.updateFeaturePosition((MapCircle) null); mapController.updateFeaturePosition((MapCircle) null);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment