6 package com.google.appinventor.components.runtime;
11 import android.util.Log;
12 import androidx.annotation.NonNull;
32 import java.util.ArrayList;
33 import java.util.List;
34 import org.json.JSONArray;
35 import org.json.JSONException;
36 import org.locationtech.jts.geom.Geometry;
37 import org.osmdroid.util.GeoPoint;
45 @DesignerComponent(version = YaVersion.LINESTRING_COMPONENT_VERSION,
46 category = ComponentCategory.MAPS,
47 description =
"LineString")
50 private static final String TAG =
LineString.class.getSimpleName();
51 private List<GeoPoint> points =
new ArrayList<GeoPoint>();
55 public Double visit(
MapMarker marker, Object... arguments) {
56 if ((Boolean) arguments[1]) {
64 public Double visit(
MapLineString lineString, Object... arguments) {
65 if ((Boolean) arguments[1]) {
73 public Double visit(
MapPolygon polygon, Object... arguments) {
74 if ((Boolean) arguments[1]) {
82 public Double visit(
MapCircle circle, Object... arguments) {
83 if ((Boolean) arguments[1]) {
91 public Double visit(
MapRectangle rectangle, Object... arguments) {
92 if ((Boolean) arguments[1]) {
107 description =
"Returns the type of the map feature. For LineString, this returns "
108 +
"the text \"LineString\".")
115 description =
"A list of latitude and longitude pairs that represent the line segments " +
129 if (points.size() < 2) {
153 final String functionName =
"PointsFromString";
155 List<GeoPoint> geopoints =
new ArrayList<GeoPoint>();
156 JSONArray array =
new JSONArray(points);
157 if (array.length() < 2) {
161 int length = array.length();
162 for (
int i = 0; i < length; ++i) {
163 JSONArray point = array.optJSONArray(i);
166 array.get(i).toString());
167 }
else if (point.length() < 2) {
171 double latitude = point.optDouble(0, Double.NaN);
172 double longitude = point.optDouble(1, Double.NaN);
173 if (!isValidLatitude(latitude)) {
175 i, array.get(0).toString());
176 }
else if (!isValidLongitude(longitude)) {
178 i, array.get(1).toString());
180 geopoints.add(
new GeoPoint(latitude, longitude));
182 this.points = geopoints;
185 }
catch(JSONException e) {
186 Log.e(TAG,
"Malformed string to LineString.PointsFromString", e);
201 super.StrokeWidth(width);
211 return visitor.
visit(
this, arguments);
221 this.points = points;