Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[android] #6083 - add circle example #6086

Merged
merged 3 commits into from
Aug 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions) {
mMarkerViewManager.invalidateViewMarkersInVisibleRegion();
return marker;
}

/**
* <p>
* Adds multiple markers to this map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
<activity
android:name=".activity.maplayout.NavigationDrawerActivity"
android:description="@string/description_navigation_drawer"
android:label="@string/title_activity_navigation_drawer"
android:label="@string/activity_navigation_drawer"
android:theme="@style/AppTheme.ActionBar.Transparent">
<meta-data
android:name="@string/category"
Expand All @@ -308,6 +308,14 @@
android:name="@string/category"
android:value="@string/category_style" />
</activity>
<activity
android:name=".activity.style.CircleLayerActivity"
android:description="@string/description_circle"
android:label="@string/activity_circle">
<meta-data
android:name="@string/category"
android:value="@string/category_style" />
</activity>
<activity
android:name=".activity.style.GeoJsonClusteringActivity"
android:description="@string/description_geojson_clustering"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,19 @@ private void showViewMarkers(int amount) {
drawable.setColorFilter(redColor, PorterDuff.Mode.SRC_IN);
Icon icon = IconFactory.getInstance(this).fromDrawable(drawable);

List<MarkerViewOptions> markerOptionsList = new ArrayList<>();
for (int i = 0; i < amount; i++) {
randomIndex = random.nextInt(mLocations.size());
LatLng latLng = mLocations.get(randomIndex);
mapboxMap.addMarker(new MarkerViewOptions()
markerOptionsList.add(new MarkerViewOptions()
.position(latLng)
.icon(icon)
.title(String.valueOf(i))
.snippet(formatter.format(latLng.getLatitude()) + ", " + formatter.format(latLng.getLongitude())));
}
for (MarkerViewOptions markerViewOptions : markerOptionsList) {
mapboxMap.addMarker(markerViewOptions);
}
}

private void showGlMarkers(int amount) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.mapbox.mapboxsdk.testapp.activity.style;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;

import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
import com.mapbox.mapboxsdk.testapp.R;

import java.net.MalformedURLException;
import java.net.URL;

import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;

/**
* Example to add a circle as a layer using runtime style API, contains adding
* GeoJSON as source that contains 1 Feature with a Point geometry, adding a circle layer and
* changing circle layer properties as size and colors.
*/
public class CircleLayerActivity extends AppCompatActivity {

private MapboxMap mapboxMap;
private MapView mapView;
private Layer circleLayer;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_circlelayer);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}

mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull final MapboxMap map) {
mapboxMap = map;
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setColorFilter(ContextCompat.getColor(CircleLayerActivity.this, R.color.primary));
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (circleLayer == null) {
// first time
try {
mapboxMap.addSource(new GeoJsonSource("point", new URL("https://gist.githubusercontent.com/anonymous/87eca90e80a72b1b42be9d0201ec3c8e/raw/acbb46384fd56044a504f122950d0637d98b4e7a/map.geojson")));
} catch (MalformedURLException e) {
Log.e(MapboxConstants.TAG, "That's not an url... " + e.getMessage());
}

circleLayer = new CircleLayer("circleLayer", "point");
circleLayer.setProperties(
circleColor(ResourcesCompat.getColor(getResources(), R.color.primary_dark, getTheme())),
circleRadius(getResources().getDimension(R.dimen.circle_size))
);

// lets add a circle below labels!
mapboxMap.addLayer(circleLayer, "waterway-label");
} else {
// change size and color
circleLayer = mapboxMap.getLayer("circleLayer");
circleLayer.setProperties(
circleRadius(mapView.getTag() == null ? getResources().getDimension(R.dimen.activity_horizontal_margin) : getResources().getDimension(R.dimen.circle_size)),
circleColor(mapView.getTag() == null ? ResourcesCompat.getColor(getResources(), R.color.blue_accent, getTheme()) : ResourcesCompat.getColor(getResources(), R.color.green_accent, getTheme())));
mapView.setTag(mapView.getTag() == null ? mapboxMap : null);
}
}
});
}
});
}

@Override
public void onResume() {
super.onResume();
mapView.onResume();
}

@Override
public void onPause() {
super.onPause();
mapView.onPause();
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}

@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}

@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<com.mapbox.mapboxsdk.maps.MapView
android:id="@id/mapView"
android:layout_below="@id/toolbar"
android:layout_width="match_parent"
app:center_latitude="52.519003"
app:center_longitude="13.400972"
app:style_url="@string/style_mapbox_streets"
app:zoom="16"
android:layout_height="match_parent"/>

<android.support.design.widget.FloatingActionButton
android:id="@id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add_24dp"
app:backgroundTint="@android:color/white" />

</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
<string name="activity_query_rendered_feature_properties">Query feature properties</string>
<string name="activity_query_rendered_features_box_count">Count features in box</string>
<string name="activity_query_rendered_features_box_highlight">Highlight features in box</string>
<string name="title_activity_navigation_drawer">Android SDK View integration</string>
<string name="activity_circle">Add Circle</string>
<string name="activity_navigation_drawer">Android SDK View integration</string>

<!-- Description -->
<string name="description_user_location_tracking">Tracks the location of the user</string>
Expand Down Expand Up @@ -100,6 +101,7 @@
<string name="description_location_picker">Use a fixed Marker to select your location</string>
<string name="description_viewpager">Use SupportMapFragments in a ViewPager</string>
<string name="description_runtime_style">Adopt the map style on the fly</string>
<string name="description_circle">Use GeoJson source to show a circle</string>
<string name="description_geojson_clustering">Use GeoJson sources and dynamic layers to cluster information</string>
<string name="description_print">Shows how to print a map</string>
<string name="description_navigation_drawer">Test animation of Android SDK View components</string>
Expand Down