com.esri.android.map.MapView Java Examples

The following examples show how to use com.esri.android.map.MapView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  // First, we initialize the Hub singleton
  final Hub hub = Hub.getInstance();
  if (!hub.init(this, getPackageName())) {
    // We can't do anything with the Myo device if the Hub can't be initialized, so exit.
    Toast.makeText(this, "Couldn't initialize Hub", Toast.LENGTH_SHORT).show();
    finish();
    return;
  }
  hub.setLockingPolicy(Hub.LockingPolicy.NONE);
  // Connects to a Myo that is physically touching the device
  hub.attachToAdjacentMyo();
  mMapView = new MapView(this, "http://csf.maps.arcgis.com/home/item.html?id=f065c8fa4e514749aeef57919b3d192e", null, null);
  mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
    @Override
    public void onStatusChanged(Object source, STATUS status) {
      if (source instanceof ArcGISFeatureLayer && status == STATUS.LAYER_LOADED) {
        mFeatureControlListener = new MyoFeatureControlListener(MainActivity.this, mMapView, (ArcGISFeatureLayer) source);
      }
    }
  });
  mMapControlListener = new MyoMapControlListener(this, mMapView);
  hub.addListener(mMapControlListener);
  setContentView(mMapView);
  mWearMessageListener = new WearMessageListener(mMapView);
  initGoogleApiClient();
}
 
Example #2
Source File: GPSTesterActivityController.java    From android-gps-test-tool with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that uses latitude/longitude points to programmatically 
 * draw a <code>SimpleMarkerSymbol</code> and adds the <code>Graphic</code> to map.
 * @param latitude
 * @param longitude
 * @param attributes
 * @param style You defined the style via the Enum <code>SimpleMarkerSymbol.STYLE</code>
 */
public static void addGraphicLatLon(double latitude, double longitude, Map<String, Object> attributes, 
		SimpleMarkerSymbol.STYLE style,int color,int size, GraphicsLayer graphicsLayer, MapView map){
	
	Point latlon = new Point(longitude,latitude);		
	
	//Convert latlon Point to mercator map point.
	Point point = (Point)GeometryEngine.project(latlon,SpatialReference.create(4326), map.getSpatialReference());		
	
	//Set market's color, size and style. You can customize these as you see fit
	SimpleMarkerSymbol symbol = new SimpleMarkerSymbol(color,size, style);			
	Graphic graphic = new Graphic(point, symbol,attributes);
	graphicsLayer.addGraphic(graphic);
}
 
Example #3
Source File: GPSTesterActivityController.java    From android-gps-test-tool with Apache License 2.0 5 votes vote down vote up
public GPSTesterActivityController(Activity activity, Context context, MapView map){
		_map = map;
		_activity = activity;
		_elapsedTimer = new ElapsedTimer();
	    _elapsedTime = (TextView) _activity.findViewById(R.id.elapsedTime);
	    _elapsedTime.setTextColor(Color.YELLOW);
	    _context = context;

		_cachedLocationNetworkProvider = (TextView) _activity.findViewById(R.id.cachedNetworkProvider);
		_cachedLocationGPSProvider = (TextView) _activity.findViewById(R.id.cachedGPS);
		_networkLocationTextView = (TextView) _activity.findViewById(R.id.networkLocationProvider);
		_gpsLocationTextView = (TextView) _activity.findViewById(R.id.gpsLocationProvider);
		_gpsNMEATextView = (TextView) _activity.findViewById(R.id.gpsNMEAInfo);
		_gpsSatelliteTextView = (TextView) _activity.findViewById(R.id.gpsSatelliteInfo);
		_allLocationProvidersTextView = (TextView) _activity.findViewById(R.id.allLocationProviders);
		_bestLocationProviderTextView = (TextView) _activity.findViewById(R.id.bestLocationProviders);
		_bestAvailableInfoTextView = (TextView) _activity.findViewById(R.id.bestAvailableInfo);
		_bestAvailableImageView = (ImageView) _activity.findViewById(R.id.bestAvailableImageView);
		_pauseButton = (Button) _activity.findViewById(R.id.PauseButton);
		_startButton = (Button)_activity.findViewById(R.id.StartAllButton);
		_preferences = PreferenceManager.getDefaultSharedPreferences(_activity);
		_imGPS = (ImageView)_activity.findViewById(R.id.gpsEnabledIcon);
		_imNetwork = (ImageView)_activity.findViewById(R.id.networkEnabledIcon);
		_imCriteria = (ImageView) _activity.findViewById(R.id.criteriaEnabledIcon);

		setUI();
		setOnClickListeners();	
		
		//This is very expensive to run - but hey if you need it...it's here.
		//My recommendation is move it off the UI thread and put it on a timer.
//    	String cpu = Float.toString(getCPU() * 100);
//    	Log.d("GPSTester","CPU usage: " + cpu);
				
	}
 
Example #4
Source File: GPSTesterActivity.java    From android-gps-test-tool with Apache License 2.0 5 votes vote down vote up
/** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

_map = (MapView)findViewById(R.id.map);

_activityController = new GPSTesterActivityController(this,GPSTesterActivity.this,_map);	

_preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
PreferenceManager.setDefaultValues(this,R.xml.preferences , false);			

  }
 
Example #5
Source File: DevSummitDemoActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 5 votes vote down vote up
/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // Set license level for the demo. Override "license_client_id" and
  // "license_standard_string" in strings.xml to use Standard license level.
  // Otherwise comment out the following line to use Developer license level.
  // @see <a href="https://developers.arcgis.com/android/guide/license-your-app.htm">License your app</a>
  setLicense();
  setContentView(R.layout.main);

  // Obtain a map view from the layout
  mMap = (MapView) findViewById(R.id.mapView);

  // Load a raster layer as basemap
  // Obtain the path to the folder where raster data is stored on device
  String path = Environment.getExternalStorageDirectory() + File.separator
      + this.getResources().getString(R.string.raster_dir) + File.separator;
  // Create an instance of the helper class to handle raster analysis operations
  mRasterHelper = new RasterAnalysisHelper(mMap,
      (path + this.getResources().getString(R.string.raster_basemap_layer)),
      (path + this.getResources().getString(R.string.raster_task)));
  mRasterHelper.loadRasterAsBasemap();

  // Add floating action button
  FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  fab.setOnCheckedChangeListener(this);

}
 
Example #6
Source File: MainActivity.java    From arcgis-android-moremap with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    MapView mMapView = findViewById(R.id.map);
    mMapView.addLayer(new MoreMapLayer(MoreMapLayerTypes.AMAP_VECTOR));

    String cachePath = Environment.getExternalStorageDirectory().getAbsoluteFile() + "/MoreMapCache";
    MoreMapLayer vec_c = new MoreMapLayer(MoreMapLayerTypes.AMAP_IMAGE, cachePath);
    mMapView.addLayer(vec_c);
}
 
Example #7
Source File: ArcGISMapManager.java    From react-native-arcgis-sdk-demo with Apache License 2.0 5 votes vote down vote up
@ReactProp(name = "layers")
public void setLayers(MapView view, @Nullable ReadableArray layers) {
    Log.v(REACT_CLASS, "set layers");

    if (layers == null || layers.size() < 1) {
        Log.v(REACT_CLASS, "set layers: adding default layer");
        mapView.addLayer(new ArcGISTiledMapServiceLayer(DEFAULT_LAYER));
    } else {
        mapView.removeAll();
        for (int i = 0; i < layers.size(); i++) {
            ReadableMap layer = layers.getMap(i);
            String type = layer.getString("type");
            String url = layer.getString("url");

            if (!url.equals("")) {
                if (type.equals("ArcGISTiledMapServiceLayer")) {
                    Log.v(REACT_CLASS, "set layers: adding ArcGISTiledMapServiceLayer:" + url);
                    mapView.addLayer(new ArcGISTiledMapServiceLayer(url));
                } else if (type.equals("ArcGISFeatureLayer")) {
                    Log.v(REACT_CLASS, "set layers: adding ArcGISFeatureLayer:" + url);
                    mapView.addLayer(new ArcGISFeatureLayer(url, ArcGISFeatureLayer.MODE.SNAPSHOT));
                } else {
                    Log.v(REACT_CLASS, "set layers: unrecognized layer: " + type);
                }
            } else {
                Log.v(REACT_CLASS, "set layers: invalid url:" + url);
            }
        }
    }
}
 
Example #8
Source File: RasterAnalysisHelper.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
public RasterAnalysisHelper(MapView mapView, String pathLayer, String pathTask) {
  mMapView = mapView;
  mPathLayer = pathLayer;
  mPathTask = pathTask;
}
 
Example #9
Source File: ArcGISMapManager.java    From react-native-arcgis-sdk-demo with Apache License 2.0 4 votes vote down vote up
@Override
protected MapView createViewInstance(ThemedReactContext reactContext) {
    Log.v(REACT_CLASS, "createViewInstance");

    mapView = new MapView(reactContext);

    /*
    // TODO: attempt to listen to map change globally
    //  there is a mention of center property at https://developers.arcgis.com/android/api-reference/reference/com/esri/android/map/event/OnStatusChangedListener.html
    //  another way to go seems to listen for touch but that probably won't be fired when chaging center programmatically
    //  https://developers.arcgis.com/android/api-reference/reference/com/esri/android/map/MapOnTouchListener.html
    mapView.setOnStatusChangedListener(new OnStatusChangedListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void onStatusChanged(Object source, STATUS status) {
            switch (status) {
                case INITIALIZED:
                    extentChangeListener.addPropertyChangeListener("center", new PropertyChangeListener() {
                        @Override
                        public void propertyChange(PropertyChangeEvent event) {
                            if (event.getOldValue() != event.getNewValue()) {
                                Log.v(REACT_CLASS, "extent change");
                                emitExtentChange();
                            }
                        }
                    });
                    break;
            }
        }
    });
    */

    mapView.setAllowRotationByPinch(true);
    mapView.enableWrapAround(true);

    // Give the module a reference to MapView
    arcGISMapModule.setMapView(mapView);

    return mapView;
}
 
Example #10
Source File: GPSTesterActivityController.java    From android-gps-test-tool with Apache License 2.0 4 votes vote down vote up
private void setUI(){
		
		final Display display = _activity.getWindowManager().getDefaultDisplay();
		final int width = display.getWidth(); //WARNING: this method was deprecated at API level 13
		final int height = (int)(display.getHeight() * .3333); //WARNING: this method was deprecated at API level 13
		
		_baseMap = new ArcGISTiledMapServiceLayer(
				"http://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer");
		
		_graphicsLayer = new GraphicsLayer();
		
		String bestAvailableText = "";
		String cachedLocationNetworkProviderText = "";
		String cachedLocationGPSProviderText = "";
		String gpsLocationText = "";
		String networkLocationText = "";
		
		final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width, height);
		final MapView temp = (MapView)_activity.findViewById(R.id.map);
		temp.setLayoutParams(layoutParams);
		
		//Keep screen awake
		_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
		
		//Load the map
//		if(_map.layerExists(MapType.TOPO)){
//			_map.clearAllGraphics(); 
//		}
//		else{
			_map.addLayer(_baseMap);
			_map.addLayer(_graphicsLayer);
//		}
		
		bestAvailableText = "<b><font color='yellow'>Best Accuracy = N/A</b></font>" + 
				"<br><b>Lat/Lon:</b> N/A" +  
				"<br><b>Accuracy:</b> N/A";
		
  		setBestAvailableImageView(BestAvailableType.NULL);
		
		cachedLocationNetworkProviderText = "<b><font color='yellow'>Cached Network Provider</b></font>" + 
				"<br><b>Lat/Lon:</b> N/A" +  
				"<br><b>Accuracy:</b> N/A";
		
		cachedLocationGPSProviderText = "<b><font color='yellow'>Cached GPS Provider</b></font>" + 
				"<br><b>Lat/Lon:</b> N/A" + 
				"<br><b>Accuracy:</b> N/A";
		
		gpsLocationText = "<b><font color='yellow'>GPS Provider</b></font>" + 
				"<br><b>Lat/Lon:</b> N/A" + 
				"<br><b>Accuracy:</b> N/A";	
		
		networkLocationText = "<b><font color='yellow'>Network Provider</b></font>" + 
				"<br><b>Lat/Lon:</b> N/A" + 
				"<br><b>Accuracy:</b> N/A";
		
		_bestAvailableInfoTextView.setText(Html.fromHtml(bestAvailableText));
		_cachedLocationNetworkProvider.setText(Html.fromHtml(cachedLocationNetworkProviderText));
		_cachedLocationGPSProvider.setText(Html.fromHtml(cachedLocationGPSProviderText));
		_gpsLocationTextView.setText(Html.fromHtml(gpsLocationText));
		_networkLocationTextView.setText(Html.fromHtml(networkLocationText));
		_allLocationProvidersTextView.setText(Html.fromHtml("<b><font color='yellow'>List of available providers</b></font><br><br><br>"));		
		_bestLocationProviderTextView.setText(Html.fromHtml("<b><font color='yellow'>List of best providers</b></font><br><br><br>"));
		
	}
 
Example #11
Source File: ArcGISMapModule.java    From react-native-arcgis-sdk-demo with Apache License 2.0 4 votes vote down vote up
public void setMapView(MapView mapView) {
    this.mapView = mapView;
}
 
Example #12
Source File: MainActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  mMapView = (MapView) findViewById(R.id.mapView);
  mLocationDisplayManager = mMapView.getLocationDisplayManager();

  mFab = (FloatingActionButton) findViewById(R.id.fab);
  mFab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

      // If locationManager already started, then stop it.
      if (mLocationDisplayManager.isStarted()) {
        mLocationDisplayManager.stop();
        mFab.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(MainActivity.this, R.color.colorAccentOff)));
      } else {
        // If not started, check permissions before starting.
        if ((ContextCompat.checkSelfPermission(MainActivity.this, reqPermissions[0]) == PackageManager.PERMISSION_GRANTED) && (ContextCompat.checkSelfPermission(MainActivity.this, reqPermissions[1]) == PackageManager.PERMISSION_GRANTED)) {
          startLocationDisplay();
        } else {
          // Ask for permissions - in this case, do not show rationale.
          ActivityCompat.requestPermissions(MainActivity.this, reqPermissions, requestCode);
        }
      }
    }
  });

  //    // Can listen for location updates if required.
  //    mLocationDisplayManager.setLocationListener(new LocationListener() {
  //      @Override
  //      public void onLocationChanged(Location location) {
  //        if (location != null) {
  //          if (location.hasAccuracy()) {
  //            // Do something.
  //          }
  //        }
  //      }
  //
  //      @Override
  //      public void onStatusChanged(String s, int i, Bundle bundle) {
  //
  //      }
  //
  //      @Override
  //      public void onProviderEnabled(String s) {
  //
  //      }
  //
  //      @Override
  //      public void onProviderDisabled(String s) {
  //
  //      }
  //    });
}
 
Example #13
Source File: GeofenceMapActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_geofence_map);

  mMapView = (MapView)findViewById(R.id.map);
  mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
    @Override
    public void onStatusChanged(Object o, STATUS status) {
      if (status == STATUS.INITIALIZED) {
        // When map is initialized, allow user to select a feature to use
        // as the geofence.
        mMapView.setOnSingleTapListener(mapSingleTapListener);
      }
    }
  });

  // If the app is offline, use a local TPK as a basemap. If online, then
  // use online global basemap instead.
  if (isOffline()) {
    String tpkPath = getResources().getString(R.string.tpk_path);
    String path = Environment.getExternalStorageDirectory().getPath() + tpkPath;
    File f = new File(path);
    if (f.exists()) {
      ArcGISLocalTiledLayer localTiledLayer = new ArcGISLocalTiledLayer(path);
      mMapView.addLayer(localTiledLayer);
      mMapView.setExtent(localTiledLayer.getExtent());
    }
    else
    {
      Toast.makeText(this, getResources().getString(
          R.string.noBasemapMessage), Toast.LENGTH_SHORT).show();
      Log.i(TAG, "Failed to find tpk: " + tpkPath);
    }
  }
  else
  {
    // If online, use an online basemap.
    String url = getResources().getString(R.string.basemap_url);
    ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(url);
    mMapView.addLayer(tiledLayer);
    mMapView.setExtent(tiledLayer.getExtent(), 0, false);
  }

  addGeofenceFeatureLayer();
}
 
Example #14
Source File: CurrentLocationActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_current_location);

  mMapView = (MapView)findViewById(R.id.map);
  mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
    @Override
    public void onStatusChanged(Object o, STATUS status) {
      if (status == STATUS.INITIALIZED) {
        // When the map is initialized, start the LocationDisplayManager.
        mLocDispMgr.setLocationListener(mLocationListener);
        mLocDispMgr.start();
      }
    }
  });
  mMapView.setAllowRotationByPinch(true);

  if (isOffline()) {
    String tpkPath = getResources().getString(R.string.tpk_path);
    String path = Environment.getExternalStorageDirectory().getPath() + tpkPath;
    File f = new File(path);
    if (f.exists()) {
      ArcGISLocalTiledLayer localTiledLayer = new ArcGISLocalTiledLayer(path);
      mMapView.addLayer(localTiledLayer);
      mMapView.setExtent(localTiledLayer.getExtent());

      FeatureLayer fenceFeatureLayer = new FeatureLayer(MainActivity.mGdbFeatureTable);
      mMapView.addLayer(fenceFeatureLayer);
    }
    else
    {
      Toast.makeText(this, getResources().getString(
          R.string.noBasemapMessage), Toast.LENGTH_SHORT).show();
      Log.i(TAG, "Failed to find tpk: " + tpkPath);
    }
  }
  else
  {
    // If online, use an online basemap.
    String url = getResources().getString(R.string.basemap_url);
    ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(url);
    mMapView.addLayer(tiledLayer);
    mMapView.setExtent(tiledLayer.getExtent(), 0, false);
  }

  mLocDispMgr = mMapView.getLocationDisplayManager();
  mLocDispMgr.setAutoPanMode(LocationDisplayManager.AutoPanMode.OFF);

}
 
Example #15
Source File: RasterAnalysisHelper.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
public OnTouchListenerViewshed(Context context, MapView map,
                               Viewshed task) {
  super(context, map);
  mMap = map;
  mTask = task;
}
 
Example #16
Source File: RasterAnalysisHelper.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
public OnTouchListenerLOS(Context context, MapView map, LineOfSight task) {
  super(context, map);
  mMap = map;
  mTask = task;
}
 
Example #17
Source File: CurrentLocationActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_current_location);

  mMapView = (MapView)findViewById(R.id.map);
  mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
    @Override
    public void onStatusChanged(Object o, STATUS status) {
      if (status == STATUS.INITIALIZED) {
        // When the map is initialized, start the LocationDisplayManager.
        mLocDispMgr.setLocationListener(mLocationListener);
        mLocDispMgr.start();
      }
    }
  });
  mMapView.setAllowRotationByPinch(true);

  if (isOffline()) {
    String tpkPath = getResources().getString(R.string.tpk_path);
    String path = Environment.getExternalStorageDirectory().getPath() + tpkPath;
    File f = new File(path);
    if (f.exists()) {
      ArcGISLocalTiledLayer localTiledLayer = new ArcGISLocalTiledLayer(path);
      mMapView.addLayer(localTiledLayer);
      mMapView.setExtent(localTiledLayer.getExtent());

      FeatureLayer fenceFeatureLayer = new FeatureLayer(MainActivity.mGdbFeatureTable);
      mMapView.addLayer(fenceFeatureLayer);
    }
    else
    {
      Toast.makeText(this, getResources().getString(
          R.string.noBasemapMessage), Toast.LENGTH_SHORT).show();
      Log.i(TAG, "Failed to find tpk: " + tpkPath);
    }
  }
  else
  {
    // If online, use an online basemap.
    String url = getResources().getString(R.string.basemap_url);
    ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(url);
    mMapView.addLayer(tiledLayer);
    mMapView.setExtent(tiledLayer.getExtent(), 0, false);
  }

  mLocDispMgr = mMapView.getLocationDisplayManager();
  mLocDispMgr.setAutoPanMode(LocationDisplayManager.AutoPanMode.OFF);

}
 
Example #18
Source File: MainActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
public TouchListener(Context context, MapView view) {
    super(context, view);
}
 
Example #19
Source File: MyoControlListener.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
public MyoControlListener(MainActivity activity, MapView mapView) {
  mActivity = activity;
  mMapView = mapView;
  mActivatedTime = System.currentTimeMillis();
}
 
Example #20
Source File: MyoMapListener.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
public MyoMapListener(Activity activity, MapView mapView) {
  mActivity = activity;
  mMapView = mapView;
}
 
Example #21
Source File: WearMessageListener.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
public WearMessageListener(MapView mapView) {
  mMapView = mapView;
}
 
Example #22
Source File: MyoMapControlListener.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
public MyoMapControlListener(MainActivity activity, MapView mapView) {
  super(activity, mapView);
}
 
Example #23
Source File: MyoFeatureControlListener.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
public MyoFeatureControlListener(MainActivity activity, MapView mapView, ArcGISFeatureLayer featureLayer) {
  super(activity, mapView);
  mFeatureLayer = featureLayer;
}
 
Example #24
Source File: MainActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.trafficmap_activity);

    //TODO YOU MUST SET THIS YOURSELF TO RUN THIS!
    ArcGISRuntime.setClientId(XXXXXXXXXXXXXXXX);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(getResources().getColor(R.color.myColorPrimaryDark));
    }

    //set up support toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.traffic_toolbar);
    setSupportActionBar(toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_action_ic_menu_24px);
    getSupportActionBar().setDisplayShowTitleEnabled(false);


    //set up action button
    mFabImageButton = (ImageButton) findViewById(R.id.fab_image_button);
    mFabImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isIncidentListVisible) {
                showCalendar();
            } else {
                showIncidentList();
            }
        }
    });


    //create credentials
    //TODO YOU MUST ADD VALID USERNAME AND PASSWORD OF AN ORG USER TO RUN THIS APP
    mUserCredentials = new UserCredentials();
    mUserCredentials.setUserAccount(XXX, XXX);

    //setup map
    FrameLayout mapFrame = (FrameLayout) findViewById(R.id.map_frame);
    String mapUrl = getResources().getString(R.string.webmap_url);
    mMapView = new MapView(getApplicationContext(), mapUrl, mUserCredentials, null, null);
    mapFrame.addView(mMapView);


    //wait for mapview to load then set zoom and query for incidents
    mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
        @Override
        public void onStatusChanged(Object source, STATUS status) {

            //Once map is loaded zoom to location
            if (source == mMapView && status == STATUS.INITIALIZED) {

                //Zoom to location
                Point point = new Point(-13046162, 4036352);
                mMapView.zoomToScale(point, 100000);

                //assume we do a geocode here for the location, currently hardcoded to redlands
                //LA incident 34.00, -118.31
                //Point point = new Point(-13173005, 4030270);
                //"34.056215, -117.195668" / -13046162, 4036352



                Log.d("T_APP", "map initialized");

                AsyncQueryTask ayncQuery = new AsyncQueryTask();
                ayncQuery.execute();

                //Get traffic layer
                //TODO should try and use the layer name or ID here, as if map changes then this will break, current bug prevents this
                Layer[] layers = mMapView.getLayers();
                mTrafficLayer = (ArcGISDynamicMapServiceLayer) layers[1];

                //TODO why have to do this here?
                mGraphicLayer = new GraphicsLayer();
                mMapView.addLayer(mGraphicLayer);

            }
        }
    });

    //TODO set up retain instance methods

}
 
Example #25
Source File: GeofenceMapActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_geofence_map);

  mMapView = (MapView)findViewById(R.id.map);
  mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
    @Override
    public void onStatusChanged(Object o, STATUS status) {
      if (status == STATUS.INITIALIZED) {
        // When map is initialized, allow user to select a feature to use
        // as the geofence.
        mMapView.setOnSingleTapListener(mapSingleTapListener);
      }
    }
  });

  // If the app is offline, use a local TPK as a basemap. If online, then
  // use online global basemap instead.
  if (isOffline()) {
    String tpkPath = getResources().getString(R.string.tpk_path);
    String path = Environment.getExternalStorageDirectory().getPath() + tpkPath;
    File f = new File(path);
    if (f.exists()) {
      ArcGISLocalTiledLayer localTiledLayer = new ArcGISLocalTiledLayer(path);
      mMapView.addLayer(localTiledLayer);
      mMapView.setExtent(localTiledLayer.getExtent());
    }
    else
    {
      Toast.makeText(this, getResources().getString(
          R.string.noBasemapMessage), Toast.LENGTH_SHORT).show();
      Log.i(TAG, "Failed to find tpk: " + tpkPath);
    }
  }
  else
  {
    // If online, use an online basemap.
    String url = getResources().getString(R.string.basemap_url);
    ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(url);
    mMapView.addLayer(tiledLayer);
    mMapView.setExtent(tiledLayer.getExtent(), 0, false);
  }

  addGeofenceFeatureLayer();
}