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 {
"Unable to determine the structure of the points argument.");
}
clearGeometry();
map.getController().updateFeaturePosition(this);
} catch(DispatchableError e) {
container.$form().dispatchErrorOccurredEvent(this, "Points", e.getErrorCode(), e.getArguments());
}
......@@ -209,7 +210,7 @@ public class Polygon extends PolygonBase implements MapPolygon {
"Unable to determine the structure of the points argument.");
}
clearGeometry();
map.getController().updateFeaturePosition(this);
map.getController().updateFeatureHoles(this);
} catch(DispatchableError e) {
container.$form().dispatchErrorOccurredEvent(this, "HolePoints",
e.getErrorCode(), e.getArguments());
......@@ -222,18 +223,18 @@ public class Polygon extends PolygonBase implements MapPolygon {
public void HolePointsFromString(String pointString) {
if (TextUtils.isEmpty(pointString)) {
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;
}
try {
JSONArray content = new JSONArray(pointString);
if (content.length() == 0) {
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;
}
holePoints = GeometryUtil.multiPolygonHolesToList(content);
map.getController().updateFeaturePosition(this);
map.getController().updateFeatureHoles(this);
Log.d(TAG, "Points: " + points);
} catch(JSONException e) {
Log.e(TAG, "Unable to parse point string", e);
......
......@@ -229,6 +229,11 @@ class DummyMapController implements MapController {
throw new UnsupportedOperationException();
}
@Override
public void updateFeatureHoles(MapPolygon polygon) {
throw new UnsupportedOperationException();
}
@Override
public void updateFeaturePosition(MapCircle circle) {
throw new UnsupportedOperationException();
......
......@@ -441,6 +441,13 @@ public final class MapFactory {
*/
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.
*
......
......@@ -737,6 +737,14 @@ class NativeOpenStreetMapController implements MapController, MapListener {
MultiPolygon polygon = (MultiPolygon) featureOverlays.get(aiPolygon);
if (polygon != null) {
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());
view.invalidate();
}
......
......@@ -5,6 +5,7 @@
package com.google.appinventor.components.runtime;
import android.view.ViewGroup;
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.views.ShadowMapView;
......@@ -13,6 +14,7 @@ import com.google.appinventor.components.runtime.util.YailList;
import org.junit.Before;
import org.osmdroid.util.GeoPoint;
import org.robolectric.annotation.Config;
import org.robolectric.internal.Shadow;
import static com.google.appinventor.components.runtime.util.GeometryUtil.ONE_DEG_IN_METERS;
......@@ -135,6 +137,10 @@ public class MapTestBase extends RobolectricTestBase {
return map;
}
public ShadowMapView getMapShadow() {
return Shadow.extract(((ViewGroup)map.getView()).getChildAt(0));
}
@Before
public void setUp() {
super.setUp();
......
......@@ -5,7 +5,9 @@
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.org.osmdroid.views.ShadowMapView;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.GeometryUtil;
import com.google.appinventor.components.runtime.util.YailList;
......@@ -13,12 +15,17 @@ import org.junit.Before;
import org.junit.Test;
import org.locationtech.jts.geom.Geometry;
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.Collections;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for the Polygon component.
......@@ -110,6 +117,14 @@ public class PolygonTest extends MapTestBase {
assertEquals(4, points.size());
}
@Test
public void testPointsInvalidatesView() {
ShadowMapView view = getMapShadow();
view.clearWasInvalidated();
defaultPolygon(polygon);
assertTrue(view.wasInvalidated());
}
@Test
public void testPointsMultipolygon() {
defaultMultipolygon(polygon);
......@@ -192,6 +207,22 @@ public class PolygonTest extends MapTestBase {
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
public void testHolePointsMultipolygon() {
defaultMultipolygon(polygon);
......
......@@ -243,6 +243,11 @@ public class DummyMapControllerTest {
mapController.updateFeaturePosition((MapPolygon) null);
}
@Test(expected = UnsupportedOperationException.class)
public void testUpdateFeatureHoles() {
mapController.updateFeatureDraggable(null);
}
@Test(expected = UnsupportedOperationException.class)
public void testUpdateFeaturePositionCircle() {
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