Commit 5c4c9573 authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Fix issues with HolePointsFromString in Polygon (#1654)

Change-Id: I9b23ee39bb46e63d56e4bd7b6cc24b8d32cdade3
parent 6d606ea1
...@@ -256,8 +256,8 @@ public class MockPolygon extends MockPolygonBase { ...@@ -256,8 +256,8 @@ public class MockPolygon extends MockPolygonBase {
} }
for (var i = 1; i < latlngs.length; i++) { for (var i = 1; i < latlngs.length; i++) {
var hole = []; var hole = [];
for (var j = 0; j < latlngs[i].length; i++) { for (var j = 0; j < latlngs[i].length; j++) {
holesJson.push([latlngs[i][j].lat, latlngs[i][j].lng]); hole.push([latlngs[i][j].lat, latlngs[i][j].lng]);
} }
holesJson.push(hole); holesJson.push(hole);
} }
......
...@@ -46,6 +46,7 @@ public class Polygon extends PolygonBase implements MapPolygon { ...@@ -46,6 +46,7 @@ public class Polygon extends PolygonBase implements MapPolygon {
private List<List<GeoPoint>> points = new ArrayList<List<GeoPoint>>(); private List<List<GeoPoint>> points = new ArrayList<List<GeoPoint>>();
private List<List<List<GeoPoint>>> holePoints = new ArrayList<List<List<GeoPoint>>>(); private List<List<List<GeoPoint>>> holePoints = new ArrayList<List<List<GeoPoint>>>();
private boolean multipolygon = false; private boolean multipolygon = false;
private boolean initialized = false;
private static final MapFeatureVisitor<Double> distanceComputation = new MapFeatureVisitor<Double>() { private static final MapFeatureVisitor<Double> distanceComputation = new MapFeatureVisitor<Double>() {
@Override @Override
...@@ -99,6 +100,13 @@ public class Polygon extends PolygonBase implements MapPolygon { ...@@ -99,6 +100,13 @@ public class Polygon extends PolygonBase implements MapPolygon {
container.addFeature(this); container.addFeature(this);
} }
public void Initialize() {
initialized = true;
clearGeometry();
map.getController().updateFeaturePosition(this);
map.getController().updateFeatureHoles(this);
}
@Override @Override
@SimpleProperty(category = PropertyCategory.BEHAVIOR, @SimpleProperty(category = PropertyCategory.BEHAVIOR,
description = "The type of the feature. For polygons, this returns the text \"Polygon\".") description = "The type of the feature. For polygons, this returns the text \"Polygon\".")
...@@ -140,8 +148,10 @@ public class Polygon extends PolygonBase implements MapPolygon { ...@@ -140,8 +148,10 @@ public class Polygon extends PolygonBase implements MapPolygon {
throw new DispatchableError(ErrorMessages.ERROR_POLYGON_PARSE_ERROR, throw new DispatchableError(ErrorMessages.ERROR_POLYGON_PARSE_ERROR,
"Unable to determine the structure of the points argument."); "Unable to determine the structure of the points argument.");
} }
clearGeometry(); if (initialized) {
map.getController().updateFeaturePosition(this); 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());
} }
...@@ -166,8 +176,10 @@ public class Polygon extends PolygonBase implements MapPolygon { ...@@ -166,8 +176,10 @@ public class Polygon extends PolygonBase implements MapPolygon {
} }
points = GeometryUtil.multiPolygonToList(content); points = GeometryUtil.multiPolygonToList(content);
multipolygon = points.size() > 1; multipolygon = points.size() > 1;
clearGeometry(); if (initialized) {
map.getController().updateFeaturePosition(this); clearGeometry();
map.getController().updateFeaturePosition(this);
}
} catch(JSONException e) { } catch(JSONException e) {
container.$form().dispatchErrorOccurredEvent(this, "PointsFromString", container.$form().dispatchErrorOccurredEvent(this, "PointsFromString",
ErrorMessages.ERROR_POLYGON_PARSE_ERROR, e.getMessage()); ErrorMessages.ERROR_POLYGON_PARSE_ERROR, e.getMessage());
...@@ -209,8 +221,10 @@ public class Polygon extends PolygonBase implements MapPolygon { ...@@ -209,8 +221,10 @@ public class Polygon extends PolygonBase implements MapPolygon {
throw new DispatchableError(ErrorMessages.ERROR_POLYGON_PARSE_ERROR, throw new DispatchableError(ErrorMessages.ERROR_POLYGON_PARSE_ERROR,
"Unable to determine the structure of the points argument."); "Unable to determine the structure of the points argument.");
} }
clearGeometry(); if (initialized) {
map.getController().updateFeatureHoles(this); clearGeometry();
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());
...@@ -234,7 +248,10 @@ public class Polygon extends PolygonBase implements MapPolygon { ...@@ -234,7 +248,10 @@ public class Polygon extends PolygonBase implements MapPolygon {
return; return;
} }
holePoints = GeometryUtil.multiPolygonHolesToList(content); holePoints = GeometryUtil.multiPolygonHolesToList(content);
map.getController().updateFeatureHoles(this); if (initialized) {
clearGeometry();
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);
......
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