6 package com.google.appinventor.components.runtime;
12 import org.locationtech.jts.geom.Geometry;
13 import org.osmdroid.api.IGeoPoint;
14 import org.osmdroid.util.GeoPoint;
34 import android.util.Log;
43 @DesignerComponent(version = YaVersion.MARKER_COMPONENT_VERSION,
44 category = ComponentCategory.MAPS,
45 description =
"<p>An icon positioned at a point to indicate information on a map. Markers " +
46 "can be used to provide an info window, custom fill and stroke colors, and custom " +
47 "images to convey information to the user.</p>")
49 @UsesLibraries(libraries =
"osmdroid.aar, androidsvg.jar")
51 private static final String TAG =
Marker.class.getSimpleName();
57 private String imagePath =
"";
63 private int anchorHAlign = 3;
69 private int anchorVAlign = 3;
74 private GeoPoint location =
new GeoPoint(0.0, 0.0);
79 private int width = LENGTH_PREFERRED;
84 private int height = LENGTH_PREFERRED;
88 public Double visit(
MapMarker marker, Object... arguments) {
93 public Double visit(
MapLineString lineString, Object... arguments) {
94 if ((Boolean) arguments[1]) {
102 public Double visit(
MapPolygon polygon, Object... arguments) {
103 if ((Boolean) arguments[1]) {
111 public Double visit(
MapCircle circle, Object... arguments) {
112 if ((Boolean) arguments[1]) {
120 public Double visit(
MapRectangle rectangle, Object... arguments) {
121 if ((Boolean) arguments[1]) {
131 public Double visit(
MapMarker marker, Object... arguments) {
136 public Double visit(
MapLineString lineString, Object... arguments) {
137 if ((Boolean) arguments[1]) {
145 public Double visit(
MapPolygon polygon, Object... arguments) {
146 if ((Boolean) arguments[1]) {
154 public Double visit(
MapCircle circle, Object... arguments) {
155 if ((Boolean) arguments[1]) {
163 public Double visit(
MapRectangle rectangle, Object... arguments) {
164 if ((Boolean) arguments[1]) {
179 super(container, distanceComputation);
180 container.addFeature(
this);
185 Width(LENGTH_PREFERRED);
186 Height(LENGTH_PREFERRED);
213 Log.d(TAG,
"Latitude");
214 if (latitude < -90 || latitude > 90) {
217 location.setLatitude(latitude);
219 map.getController().updateFeaturePosition(
this);
228 return location.getLatitude();
243 Log.d(TAG,
"Longitude");
244 if (longitude < -180 || longitude > 180) {
247 location.setLongitude(longitude);
249 map.getController().updateFeaturePosition(
this);
258 return location.getLongitude();
270 Log.d(TAG,
"ImageAsset");
271 this.imagePath = path;
272 map.getController().updateFeatureImage(
this);
279 @
SimpleProperty(description =
"The ImageAsset property is used to provide an alternative image " +
281 public String ImageAsset() {
291 super.StrokeColor(argb);
292 map.getController().updateFeatureStroke(
this);
300 if (horizontal == anchorHAlign) {
302 }
else if (horizontal > 3 || horizontal < 1) {
306 anchorHAlign = horizontal;
307 map.getController().updateFeaturePosition(
this);
315 @
SimpleProperty(description =
"The horizontal alignment property controls where the Marker's " +
316 "anchor is located relative to its width.")
317 public
int AnchorHorizontal() {
326 if (vertical == anchorVAlign) {
328 }
else if (vertical > 3 || vertical < 1) {
332 anchorVAlign = vertical;
333 map.getController().updateFeaturePosition(
this);
341 @
SimpleProperty(description =
"The vertical alignment property controls where the Marker's " +
342 "anchor is located relative to its height.")
343 public
int AnchorVertical() {
349 public
void ShowShadow(
boolean show) {
354 @
SimpleProperty(description =
"Gets whether or not the shadow of the Marker is shown.")
355 public
boolean ShowShadow() {
368 map.getController().updateFeatureSize(
this);
377 if (this.width == LENGTH_FILL_PARENT) {
378 return map.getView().getWidth();
379 }
else if (this.width < LENGTH_PERCENT_TAG) {
380 return (
int)(((double) -this.width + LENGTH_PERCENT_TAG)/100.0 * map.getView().getWidth());
391 @SuppressWarnings(
"squid:S00100")
393 public
void WidthPercent(
int pCent) {
394 this.width = LENGTH_PERCENT_TAG - pCent;
395 map.getController().updateFeatureSize(
this);
406 this.height = height;
407 map.getController().updateFeatureSize(
this);
416 if (this.height == LENGTH_FILL_PARENT) {
417 return map.getView().getHeight();
418 }
else if (this.height < LENGTH_PERCENT_TAG) {
419 return (
int)(((double) -this.height + LENGTH_PERCENT_TAG)/100.0 * map.getView().getHeight());
430 @SuppressWarnings(
"squid:S00100")
432 public
void HeightPercent(
int pCent) {
433 this.height = LENGTH_PERCENT_TAG - pCent;
434 map.getController().updateFeatureSize(
this);
444 public
void SetLocation(
double latitude,
double longitude) {
445 Log.d(TAG,
"SetLocation");
446 location.setCoords(latitude, longitude);
448 map.getController().updateFeaturePosition(
this);
463 return DistanceToPoint(latitude, longitude);
473 @SuppressWarnings(
"squid:S00100")
474 @
SimpleFunction(description =
"Compute the distance, in meters, between a Marker and a " +
475 "latitude, longitude point.")
476 public
double DistanceToPoint(
double latitude,
double longitude) {
488 @SuppressWarnings(
"squid:S00100")
489 @
SimpleFunction(description =
"Returns the bearing from the Marker to the given latitude and " +
490 "longitude, in degrees " +
492 public
double BearingToPoint(
double latitude,
double longitude) {
493 return location.bearingTo(
new GeoPoint(latitude, longitude));
507 @SuppressWarnings(
"squid:S00100")
508 @
SimpleFunction(description =
"Returns the bearing from the Marker to the given map feature, " +
509 "in degrees from due north. If the centroids parameter is true, the bearing will be to the " +
510 "center of the map feature. Otherwise, the bearing will be computed to the point in the " +
511 "feature nearest the Marker.")
512 public
double BearingToFeature(
MapFeature mapFeature, final
boolean centroids) {
513 return mapFeature ==
null ? -1 : mapFeature.accept(bearingComputation,
this, centroids);
523 this.location =
new GeoPoint(latitude, longitude);
529 return visitor.
visit(
this, arguments);