AI2 Component  (Version nb184)
FeatureCollection.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright © 2017 Massachusetts Institute of Technology, 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 
21 
22 import android.view.View;
23 import org.json.JSONException;
24 
31 @DesignerComponent(version = YaVersion.FEATURE_COLLECTION_COMPONENT_VERSION,
32  category = ComponentCategory.MAPS,
33  description = "A FeatureCollection contains one or more map features as a group. Any events " +
34  "fired on a feature in the collection will also trigger the corresponding event on the " +
35  "collection object. FeatureCollections can be loaded from external resources as a means " +
36  "of populating a Map with content.")
37 @SimpleObject
39  private String source = "";
40  private Map map;
41 
43  super(container);
44  map = container.getMap();
45  }
46 
54  @SuppressWarnings("squid:S00100")
56  @SimpleProperty(description = "Loads a collection of features from the given string. If the " +
57  "string is not valid GeoJSON, the ErrorLoadingFeatureCollection error will be run with " +
58  "url = <string>.")
59  public void FeaturesFromGeoJSON(String geojson) {
60  try {
61  processGeoJSON("<string>", geojson);
62  } catch(JSONException e) {
63  $form().dispatchErrorOccurredEvent(this, "FeaturesFromGeoJSON",
64  ErrorMessages.ERROR_INVALID_GEOJSON, e.getMessage());
65  }
66  }
67 
77  @Override
78  @SimpleEvent(description = "A GeoJSON document was successfully read from url. The features " +
79  "specified in the document are provided as a list in features.")
80  public void GotFeatures(String url, YailList features) {
81  source = url;
82  super.GotFeatures(url, features);
83  }
84 
85  @Override
87  public void Source(String source) {
88  // Only set from the designer. Blocks will call {@link #LoadFromURL} instead.
89  this.source = source;
90  }
91 
92  @Override
94  description = "Specifies the source URL used to populate the feature collection. If " +
95  "the feature collection was not loaded from a URL, this will be the empty string.")
96  public String Source() {
97  return source;
98  }
99 
105  category = PropertyCategory.APPEARANCE)
106  public boolean Visible() {
108  }
109 
116  defaultValue = "True")
117  @SimpleProperty(description = "Specifies whether the component should be visible on the screen. "
118  + "Value is true if the component is showing and false if hidden.")
119  public void Visible(boolean visibility) {
120  getMap().getController().setFeatureCollectionVisible(this, visibility);
121  }
122 
123  @Override
124  public View getView() {
125  // Even though we are an AndroidViewComponent, we don't actually have a view because the view
126  // hierarchy is handled by the map controller.
127  return null;
128  }
129 
130  @Override
131  public Map getMap() {
132  return map;
133  }
134 }
com.google.appinventor.components.runtime.MapFeatureContainerBase.$form
Form $form()
Definition: MapFeatureContainerBase.java:322
com.google.appinventor.components.runtime.MapFeatureContainerBase
Definition: MapFeatureContainerBase.java:42
com.google.appinventor.components.runtime.util.YailList
Definition: YailList.java:26
com.google.appinventor.components.runtime.util.MapFactory.MapController.setFeatureCollectionVisible
void setFeatureCollectionVisible(MapFeatureCollection collection, boolean visible)
com.google.appinventor.components.runtime.MapFeatureContainerBase.features
List< MapFeature > features
Definition: MapFeatureContainerBase.java:62
com.google.appinventor.components.runtime.FeatureCollection.getView
View getView()
Definition: FeatureCollection.java:124
com.google.appinventor.components.runtime.util.ErrorMessages
Definition: ErrorMessages.java:17
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.common.YaVersion
Definition: YaVersion.java:14
com.google.appinventor.components.runtime.FeatureCollection.GotFeatures
void GotFeatures(String url, YailList features)
Definition: FeatureCollection.java:80
com.google.appinventor.components.annotations.DesignerProperty
Definition: DesignerProperty.java:25
com.google.appinventor.components.runtime.FeatureCollection.FeatureCollection
FeatureCollection(MapFactory.MapFeatureContainer container)
Definition: FeatureCollection.java:42
com.google.appinventor.components
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.common.PropertyTypeConstants.PROPERTY_TYPE_GEOJSON_TYPE
static final String PROPERTY_TYPE_GEOJSON_TYPE
Definition: PropertyTypeConstants.java:194
com.google.appinventor.components.annotations.SimpleEvent
Definition: SimpleEvent.java:20
com.google.appinventor.components.annotations.PropertyCategory.BEHAVIOR
BEHAVIOR
Definition: PropertyCategory.java:15
com.google.appinventor.components.runtime.FeatureCollection.Source
String Source()
Definition: FeatureCollection.java:96
com.google.appinventor.components.runtime.util.ErrorMessages.ERROR_INVALID_GEOJSON
static final int ERROR_INVALID_GEOJSON
Definition: ErrorMessages.java:240
com.google.appinventor.components.runtime.FeatureCollection
Definition: FeatureCollection.java:38
com.google.appinventor.components.common.PropertyTypeConstants.PROPERTY_TYPE_TEXTAREA
static final String PROPERTY_TYPE_TEXTAREA
Definition: PropertyTypeConstants.java:248
com.google.appinventor.components.runtime.util.MapFactory.MapFeatureCollection
Definition: MapFactory.java:963
com.google.appinventor.components.annotations.SimpleProperty
Definition: SimpleProperty.java:23
com.google.appinventor.components.runtime.FeatureCollection.getMap
Map getMap()
Definition: FeatureCollection.java:131
com.google.appinventor.components.annotations.PropertyCategory
Definition: PropertyCategory.java:13
com.google.appinventor.components.common.PropertyTypeConstants.PROPERTY_TYPE_VISIBILITY
static final String PROPERTY_TYPE_VISIBILITY
Definition: PropertyTypeConstants.java:278
com.google.appinventor.components.runtime
Copyright 2009-2011 Google, All Rights reserved.
Definition: AccelerometerSensor.java:8
com.google.appinventor.components.runtime.Map
Definition: Map.java:84
com.google.appinventor.components.common
Definition: ComponentCategory.java:7
com.google.appinventor.components.runtime.util.MapFactory.MapController.isFeatureCollectionVisible
boolean isFeatureCollectionVisible(MapFeatureCollection collection)
com.google.appinventor.components.runtime.FeatureCollection.FeaturesFromGeoJSON
void FeaturesFromGeoJSON(String geojson)
Definition: FeatureCollection.java:59
com.google.appinventor.components.common.ComponentCategory
Definition: ComponentCategory.java:48
com.google.appinventor.components.runtime.Form.dispatchErrorOccurredEvent
void dispatchErrorOccurredEvent(final Component component, final String functionName, final int errorNumber, final Object... messageArgs)
Definition: Form.java:1011
com.google.appinventor.components.annotations.SimpleObject
Definition: SimpleObject.java:23
com.google.appinventor.components.runtime.AndroidViewComponent.container
final ComponentContainer container
Definition: AndroidViewComponent.java:29
com.google
com
com.google.appinventor.components.runtime.util.MapFactory.MapFeatureContainer
Definition: MapFactory.java:800
com.google.appinventor.components.runtime.FeatureCollection.Visible
boolean Visible()
Definition: FeatureCollection.java:106
com.google.appinventor.components.annotations.PropertyCategory.APPEARANCE
APPEARANCE
Definition: PropertyCategory.java:16
com.google.appinventor.components.runtime.MapFeatureContainerBase.processGeoJSON
void processGeoJSON(final String url, final String content)
Definition: MapFeatureContainerBase.java:442
com.google.appinventor.components.common.PropertyTypeConstants
Definition: PropertyTypeConstants.java:14
com.google.appinventor.components.annotations
com.google.appinventor