AI2 Component  (Version nb184)
Circle.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2016-2017 MIT, All rights reserved
3 // Released under the Apache License, Version 2.0
4 // http://www.apache.org/licenses/LICENSE-2.0
5 
6 package com.google.appinventor.components.runtime;
7 
10 import org.locationtech.jts.geom.Geometry;
11 import org.osmdroid.util.GeoPoint;
12 
29 
32 
45 @DesignerComponent(version = YaVersion.CIRCLE_COMPONENT_VERSION,
46  category = ComponentCategory.MAPS,
47  description = "Circle")
48 @SimpleObject
49 public class Circle extends PolygonBase implements MapCircle {
53  private GeoPoint center = new GeoPoint(0.0, 0.0);
54 
58  private double latitude;
59 
63  private double longitude;
64 
68  private double radius;
69 
70  private static final MapFeatureVisitor<Double> distanceComputation = new MapFeatureVisitor<Double>() {
71  @Override
72  public Double visit(MapMarker marker, Object... arguments) {
73  if ((Boolean) arguments[1]) {
74  return GeometryUtil.distanceBetweenCentroids(marker, (Circle) arguments[0]);
75  } else {
76  return GeometryUtil.distanceBetweenEdges(marker, (Circle) arguments[0]);
77  }
78  }
79 
80  @Override
81  public Double visit(MapLineString lineString, Object... arguments) {
82  if ((Boolean) arguments[1]) {
83  return GeometryUtil.distanceBetweenCentroids(lineString, (Circle) arguments[0]);
84  } else {
85  return GeometryUtil.distanceBetweenEdges(lineString, (Circle) arguments[0]);
86  }
87  }
88 
89  @Override
90  public Double visit(MapPolygon polygon, Object... arguments) {
91  if ((Boolean) arguments[1]) {
92  return GeometryUtil.distanceBetweenCentroids(polygon, (Circle) arguments[0]);
93  } else {
94  return GeometryUtil.distanceBetweenEdges(polygon, (Circle) arguments[0]);
95  }
96  }
97 
98  @Override
99  public Double visit(MapCircle circle, Object... arguments) {
100  if ((Boolean) arguments[1]) {
101  return GeometryUtil.distanceBetweenCentroids(circle, (Circle) arguments[0]);
102  } else {
103  return GeometryUtil.distanceBetweenEdges(circle, (Circle) arguments[0]);
104  }
105  }
106 
107  @Override
108  public Double visit(MapRectangle rectangle, Object... arguments) {
109  if ((Boolean) arguments[1]) {
110  return GeometryUtil.distanceBetweenCentroids((Circle) arguments[0], rectangle);
111  } else {
112  return GeometryUtil.distanceBetweenEdges((Circle) arguments[0], rectangle);
113  }
114  }
115  };
116 
118  super(container, distanceComputation);
119  container.addFeature(this);
120  }
121 
122  @Override
123  @SimpleProperty(description = "Returns the type of the feature. For Circles, "
124  + "this returns the text \"Circle\".")
125  public String Type() {
126  return MapFactory.MapFeatureType.TYPE_CIRCLE;
127  }
128 
129  @Override
131  defaultValue = "0")
133  public void Radius(double radius) {
134  this.radius = radius;
135  clearGeometry();
137  }
138 
142  @Override
144  description = "The radius of the circle in meters.")
145  public double Radius() {
146  return radius;
147  }
148 
149  @Override
151  defaultValue = "0")
153  public void Latitude(double latitude) {
154  if (isValidLatitude(latitude)) {
155  this.latitude = latitude;
156  this.center.setLatitude(latitude);
157  clearGeometry();
159  } else {
162  }
163  }
164 
170  @Override
172  description = "The latitude of the center of the circle.")
173  public double Latitude() {
174  return latitude;
175  }
176 
177  @Override
179  defaultValue = "0")
181  public void Longitude(double longitude) {
182  if (isValidLongitude(longitude)) {
183  this.longitude = longitude;
184  this.center.setLongitude(longitude);
185  clearGeometry();
187  } else {
190  }
191  }
192 
198  @Override
200  description = "The longitude of the center of the circle.")
201  public double Longitude() {
202  return longitude;
203  }
204 
211  @Override
212  @SimpleFunction(description = "Set the center of the Circle.")
213  public void SetLocation(double latitude, double longitude) {
214  if (!isValidLatitude(latitude)) {
215  getDispatchDelegate().dispatchErrorOccurredEvent(this, "SetLocation",
217  } else if (!isValidLongitude(longitude)) {
218  getDispatchDelegate().dispatchErrorOccurredEvent(this, "SetLocation",
220  } else {
221  this.latitude = latitude;
222  this.longitude = longitude;
223  this.center.setLatitude(latitude);
224  this.center.setLongitude(longitude);
225  clearGeometry();
227  }
228  }
229 
230  @Override
231  public <T> T accept(MapFeatureVisitor<T> visitor, Object... arguments) {
232  return visitor.visit(this, arguments);
233  }
234 
235  @Override
236  protected Geometry computeGeometry() {
237  return GeometryUtil.createGeometry(center);
238  }
239 
240  @Override
241  public void updateCenter(double latitude, double longitude) {
242  this.latitude = latitude;
243  this.longitude = longitude;
244  clearGeometry();
245  }
246 }
com.google.appinventor.components.runtime.util.MapFactory.MapCircle
Definition: MapFactory.java:1028
com.google.appinventor.components.runtime.HandlesEventDispatching.dispatchErrorOccurredEvent
void dispatchErrorOccurredEvent(Component component, String functionName, int errorCode, Object... args)
com.google.appinventor.components.annotations.SimpleFunction
Definition: SimpleFunction.java:23
com.google.appinventor.components.runtime.util.MapFactory.MapFeatureContainer.addFeature
void addFeature(MapFeature feature)
com.google.appinventor.components.runtime.util.ErrorMessages
Definition: ErrorMessages.java:17
com.google.appinventor.components.runtime.Circle.computeGeometry
Geometry computeGeometry()
Definition: Circle.java:236
com.google.appinventor.components.runtime.util
-*- mode: java; c-basic-offset: 2; -*-
Definition: AccountChooser.java:7
com.google.appinventor.components.runtime.util.MapFactory
Definition: MapFactory.java:30
com.google.appinventor.components.runtime.util.ErrorMessages.ERROR_INVALID_LATITUDE
static final int ERROR_INVALID_LATITUDE
Definition: ErrorMessages.java:242
com.google.appinventor.components.runtime.util.MapFactory.MapController.updateFeaturePosition
void updateFeaturePosition(MapMarker marker)
com.google.appinventor.components.runtime.Circle
Definition: Circle.java:49
com.google.appinventor.components.runtime.Circle.updateCenter
void updateCenter(double latitude, double longitude)
Definition: Circle.java:241
com.google.appinventor.components.common.YaVersion
Definition: YaVersion.java:14
com.google.appinventor.components.annotations.DesignerProperty
Definition: DesignerProperty.java:25
com.google.appinventor.components.runtime.util.ErrorMessages.ERROR_INVALID_LONGITUDE
static final int ERROR_INVALID_LONGITUDE
Definition: ErrorMessages.java:243
com.google.appinventor.components
com.google.appinventor.components.runtime.Circle.Radius
void Radius(double radius)
Definition: Circle.java:133
com.google.appinventor.components.runtime.Circle.Longitude
double Longitude()
Definition: Circle.java:201
com.google.appinventor.components.runtime.util.MapFactory.MapLineString
Definition: MapFactory.java:1373
com.google.appinventor.components.runtime.util.MapFactory.MapPolygon
Definition: MapFactory.java:1410
com.google.appinventor.components.runtime.Circle.SetLocation
void SetLocation(double latitude, double longitude)
Definition: Circle.java:213
com.google.appinventor.components.runtime.Map.getController
MapController getController()
Definition: Map.java:667
com.google.appinventor.components.annotations.DesignerComponent
Definition: DesignerComponent.java:22
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapMarker marker, MapLineString lineString)
Definition: GeometryUtil.java:249
com.google.appinventor.components.runtime.util.MapFactory.MapRectangle
Definition: MapFactory.java:1099
com.google.appinventor.components.runtime.PolygonBase
Definition: PolygonBase.java:17
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapMarker marker, MapLineString lineString)
Definition: GeometryUtil.java:327
com.google.appinventor.components.runtime.Component.getDispatchDelegate
HandlesEventDispatching getDispatchDelegate()
com.google.appinventor.components.runtime.util.MapFactory.MapFeatureVisitor.visit
T visit(MapMarker marker, Object... arguments)
com.google.appinventor.components.runtime.Circle.Longitude
void Longitude(double longitude)
Definition: Circle.java:181
com.google.appinventor.components.runtime.MapFeatureBase.container
MapFeatureContainer container
Definition: MapFeatureBase.java:33
com.google.appinventor.components.runtime.Circle.Type
String Type()
Definition: Circle.java:125
com.google.appinventor.components.runtime.MapFeatureBase.map
Map map
Definition: MapFeatureBase.java:34
com.google.appinventor.components.runtime.util.MapFactory.MapMarker
Definition: MapFactory.java:1205
com.google.appinventor.components.runtime.util.GeometryUtil.isValidLongitude
static boolean isValidLongitude(double longitude)
Definition: GeometryUtil.java:454
com.google.appinventor.components.runtime.Circle.Radius
double Radius()
Definition: Circle.java:145
com.google.appinventor.components.annotations.SimpleProperty
Definition: SimpleProperty.java:23
com.google.appinventor.components.runtime.util.GeometryUtil
Definition: GeometryUtil.java:41
com.google.appinventor.components.annotations.PropertyCategory
Definition: PropertyCategory.java:13
com.google.appinventor.components.runtime.util.GeometryUtil.createGeometry
static Geometry createGeometry(GeoPoint point)
Definition: GeometryUtil.java:120
com.google.appinventor.components.runtime
Copyright 2009-2011 Google, All Rights reserved.
Definition: AccelerometerSensor.java:8
com.google.appinventor.components.common
Definition: ComponentCategory.java:7
com.google.appinventor.components.common.ComponentCategory
Definition: ComponentCategory.java:48
com.google.appinventor.components.runtime.Circle.Latitude
double Latitude()
Definition: Circle.java:173
com.google.appinventor.components.runtime.util.MapFactory.MapFeatureType
Definition: MapFactory.java:1483
com.google.appinventor.components.annotations.SimpleObject
Definition: SimpleObject.java:23
com.google
com.google.appinventor.components.common.PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_FLOAT
static final String PROPERTY_TYPE_NON_NEGATIVE_FLOAT
Definition: PropertyTypeConstants.java:200
com
com.google.appinventor.components.runtime.MapFeatureBase.clearGeometry
final synchronized void clearGeometry()
Definition: MapFeatureBase.java:430
com.google.appinventor.components.runtime.Circle.Latitude
void Latitude(double latitude)
Definition: Circle.java:153
com.google.appinventor.components.common.PropertyTypeConstants.PROPERTY_TYPE_LONGITUDE
static final String PROPERTY_TYPE_LONGITUDE
Definition: PropertyTypeConstants.java:169
com.google.appinventor.components.runtime.util.MapFactory.MapFeatureContainer
Definition: MapFactory.java:800
com.google.appinventor.components.runtime.Circle.Circle
Circle(MapFactory.MapFeatureContainer container)
Definition: Circle.java:117
com.google.appinventor.components.runtime.util.GeometryUtil.isValidLatitude
static boolean isValidLatitude(double latitude)
Definition: GeometryUtil.java:444
com.google.appinventor.components.runtime.util.MapFactory.MapFeatureVisitor
Definition: MapFactory.java:745
com.google.appinventor.components.common.PropertyTypeConstants.PROPERTY_TYPE_LATITUDE
static final String PROPERTY_TYPE_LATITUDE
Definition: PropertyTypeConstants.java:94
com.google.appinventor.components.annotations.PropertyCategory.APPEARANCE
APPEARANCE
Definition: PropertyCategory.java:16
com.google.appinventor.components.common.PropertyTypeConstants
Definition: PropertyTypeConstants.java:14
com.google.appinventor.components.annotations
com.google.appinventor