This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
103fbd0
commit 42b76cd
Showing
13 changed files
with
282 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
.../main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QuerySourceFeaturesActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package com.mapbox.mapboxsdk.testapp.activity.feature; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.widget.Toast; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.mapbox.mapboxsdk.geometry.LatLng; | ||
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.Filter; | ||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; | ||
import com.mapbox.mapboxsdk.testapp.R; | ||
import com.mapbox.services.commons.geojson.Feature; | ||
import com.mapbox.services.commons.geojson.FeatureCollection; | ||
import com.mapbox.services.commons.geojson.Point; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Test activity showcasing using the query source features API to query feature counts | ||
*/ | ||
public class QuerySourceFeaturesActivity extends AppCompatActivity { | ||
|
||
public MapView mapView; | ||
private MapboxMap mapboxMap; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_query_source_features); | ||
|
||
final float density = getResources().getDisplayMetrics().density; | ||
|
||
// Initialize map as normal | ||
mapView = (MapView) findViewById(R.id.mapView); | ||
mapView.onCreate(savedInstanceState); | ||
mapView.getMapAsync(new OnMapReadyCallback() { | ||
@Override | ||
public void onMapReady(final MapboxMap mapboxMap) { | ||
QuerySourceFeaturesActivity.this.mapboxMap = mapboxMap; | ||
|
||
JsonObject properties = new JsonObject(); | ||
properties.addProperty("key1", "value1"); | ||
final GeoJsonSource source = new GeoJsonSource("test-source", | ||
FeatureCollection.fromFeatures(new Feature[] { | ||
Feature.fromGeometry(Point.fromCoordinates(new double[] {0, 0}), properties) | ||
})); | ||
mapboxMap.addSource(source); | ||
|
||
mapboxMap.addLayer(new CircleLayer("test-layer", source.getId()).withFilter(Filter.neq("key1", "value1"))); | ||
|
||
// Add a click listener | ||
mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() { | ||
@Override | ||
public void onMapClick(@NonNull LatLng point) { | ||
// Query | ||
List<Feature> features = source.querySourceFeatures(Filter.eq("key1", "value1")); | ||
Toast.makeText(QuerySourceFeaturesActivity.this, String.format("Found %s features", | ||
features.size()), Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
} | ||
|
||
public MapboxMap getMapboxMap() { | ||
return mapboxMap; | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
mapView.onStart(); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
mapView.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
mapView.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
mapView.onStop(); | ||
} | ||
|
||
@Override | ||
protected void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
mapView.onSaveInstanceState(outState); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
mapView.onDestroy(); | ||
} | ||
|
||
@Override | ||
public void onLowMemory() { | ||
super.onLowMemory(); | ||
mapView.onLowMemory(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_query_source_features.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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"> | ||
|
||
<com.mapbox.mapboxsdk.maps.MapView | ||
android:id="@+id/mapView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:mapbox_cameraTargetLat="0" | ||
app:mapbox_cameraTargetLng="0" | ||
app:mapbox_cameraZoom="16"/> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "../android_conversion.hpp" | ||
#include <mbgl/style/conversion.hpp> | ||
#include <mbgl/style/conversion/filter.hpp> | ||
|
||
#include <jni/jni.hpp> | ||
|
||
#include <tuple> | ||
#include <map> | ||
|
||
namespace mbgl { | ||
namespace android { | ||
namespace conversion { | ||
|
||
inline optional<mbgl::style::Filter> toFilter(jni::JNIEnv& env, jni::Array<jni::Object<>> jfilter) { | ||
mbgl::optional<mbgl::style::Filter> filter; | ||
if (jfilter) { | ||
Value filterValue(env, jfilter); | ||
auto converted = mbgl::style::conversion::convert<mbgl::style::Filter>(filterValue); | ||
if (!converted) { | ||
mbgl::Log::Error(mbgl::Event::JNI, "Error converting filter: " + converted.error().message); | ||
} | ||
filter = std::move(*converted); | ||
} | ||
return filter; | ||
} | ||
|
||
} // namespace conversion | ||
} // namespace android | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.