Skip to content
Permalink
Browse files

Ensure Polygon Points and HolePoints invalidate map view

Change-Id: I35b143a3dbe3aecdc6c57352468c73e9baf40b72
  • Loading branch information...
ewpatton authored and SusanRatiLane committed Jan 23, 2019
1 parent 12188c7 commit 5395a8340112b42e168bf8442a5e1a06a0a57984
@@ -141,6 +141,7 @@ public void Points(YailList points) {
"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 void HolePoints(YailList points) {
"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 void HolePoints(YailList points) {
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 @@ public void updateFeaturePosition(MapPolygon polygon) {
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 @@
*/
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 @@ public void updateFeaturePosition(MapPolygon aiPolygon) {
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 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 Map getMap() {
return map;
}

public ShadowMapView getMapShadow() {
return Shadow.extract(((ViewGroup)map.getView()).getChildAt(0));
}

@Before
public void setUp() {
super.setUp();
@@ -5,20 +5,27 @@

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;
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 void testPointsPolygon() {
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 void testHolePoints() {
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 void testUpdateFeaturePositionPolygon() {
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);

0 comments on commit 5395a83

Please sign in to comment.
You can’t perform that action at this time.