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

Commit

Permalink
[android] #352 - update gyp with new C++ files, added feature concept…
Browse files Browse the repository at this point in the history
… for Android binding, removed Multipoint inheritance issue
  • Loading branch information
tobrun committed Jul 26, 2016
1 parent b51592e commit d3d8c05
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
package com.mapbox.mapboxsdk.annotations;

public class MultiPoint extends PointCollectionShape {
import com.mapbox.mapboxsdk.geometry.LatLng;

import java.util.ArrayList;
import java.util.List;

public class MultiPoint extends Shape {

private List<LatLng> points;
private float alpha = 1.0f;

protected MultiPoint() {
super();
points = new ArrayList<>();
}

/**
* Returns a copy of the points.
*
* @return points - as a copy
*/
public List<LatLng> getPoints() {
return new ArrayList<>(points);
}

/**
* Sets the points of this polyline. This method will take a copy
* of the points, so further mutations to points will have no effect
* on this polyline.
*
* @param points the points of the polyline
*/
void setPoints(List<LatLng> points) {
this.points = new ArrayList<>(points);
}

void addPoint(LatLng point) {
points.add(point);
}

public float getAlpha() {
return alpha;
}

void setAlpha(float alpha) {
this.alpha = alpha;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.mapbox.mapboxsdk.annotations;

import java.util.ArrayList;
import java.util.List;

public class MultiPolygon extends Shape{

private List<Polygon> polygons;

public MultiPolygon(List<Polygon> polygons) {
this.polygons = polygons;
public MultiPolygon() {
polygons = new ArrayList<>();
}

public void addPolygon(Polygon polygon){
polygons.add(polygon);
}

public List<Polygon> getPolygons() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.mapbox.mapboxsdk.annotations;

import java.util.List;
import java.util.Map;

public class MultiPolygonFeature extends MultiPolygon implements Feature{
private long featureId;
private Map<String, Object> attributes;

public MultiPolygonFeature(List<Polygon> polygonList) {
super(polygonList);
public MultiPolygonFeature() {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,46 @@
*/
public class Polygon extends PointCollectionShape {

private List<LatLng> points;
private float alpha = 1.0f;

private int fillColor = Color.BLACK; // default fillColor is black
private int strokeColor = Color.BLACK; // default strokeColor is black

public Polygon() {
super();
points = new ArrayList<>();
}
/**
* Returns a copy of the points.
*
* @return points - as a copy
*/
public List<LatLng> getPoints() {
return new ArrayList<>(points);
}

/**
* Sets the points of this polyline. This method will take a copy
* of the points, so further mutations to points will have no effect
* on this polyline.
*
* @param points the points of the polyline
*/
void setPoints(List<LatLng> points) {
this.points = new ArrayList<>(points);
}

void addPoint(LatLng point) {
points.add(point);
}

public float getAlpha() {
return alpha;
}

void setAlpha(float alpha) {
this.alpha = alpha;
}

public int getFillColor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,56 @@

import android.graphics.Color;

import com.mapbox.mapboxsdk.geometry.LatLng;

import java.util.ArrayList;
import java.util.List;

/**
* Polyline is a geometry feature with an unclosed list of coordinates drawn as a line
*/
public class Polyline extends PointCollectionShape {

private int color = Color.BLACK; // default color is black
private float width = 10; // As specified by Google API Docs (in pixels)
private List<LatLng> points;
private float alpha = 1.0f;

public Polyline() {
super();
points = new ArrayList<>();
}

/**
* Returns a copy of the points.
*
* @return points - as a copy
*/
public List<LatLng> getPoints() {
return new ArrayList<>(points);
}

/**
* Sets the points of this polyline. This method will take a copy
* of the points, so further mutations to points will have no effect
* on this polyline.
*
* @param points the points of the polyline
*/
void setPoints(List<LatLng> points) {
this.points = new ArrayList<>(points);
}

void addPoint(LatLng point) {
points.add(point);
}

public float getAlpha() {
return alpha;
}

void setAlpha(float alpha) {
this.alpha = alpha;
}

public int getColor() {
Expand Down
3 changes: 3 additions & 0 deletions platform/android/platform.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
'sources': [
'src/native_map_view.cpp',
'src/jni.cpp',
'src/java_types.cpp',
'src/attach_env.cpp',
'src/log_android.cpp',
'src/http_file_source.cpp',
'src/asset_file_source.cpp',
'src/feature/value.cpp',
'src/feature/feature.cpp',
'src/thread.cpp',
'../default/string_stdlib.cpp',
'../default/image.cpp',
Expand Down
Empty file.
Empty file.
Empty file.
48 changes: 34 additions & 14 deletions platform/android/src/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ jni::jmethodID* offlineRegionDeleteOnErrorId = nullptr;
jni::jclass* polygonFeatureClass = nullptr;
jni::jmethodID* polygonFeatureConstructorId = nullptr;

//jni::jclass* multiPolygonFeatureClass = nullptr;
//jni::jmethodID* multiPolygonFeatureConstructorId = nullptr;
jni::jclass* multiPolygonFeatureClass = nullptr;
jni::jmethodID* multiPolygonFeatureConstructorId = nullptr;

jni::jclass* polylineFeatureClass = nullptr;
jni::jmethodID* polylineFeatureConstructorId = nullptr;
Expand Down Expand Up @@ -1119,24 +1119,44 @@ jni::jobject* nativeGetVisibleFeatures(JNIEnv *env, jni::jobject* obj, jlong na
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
mbgl::optional<std::vector<std::string>> optionalLayerIDs;

// call core for features at point
std::vector<mbgl::Feature> features = nativeMapView->getMap().queryRenderedFeatures(mbgl::ScreenCoordinate(x, y), optionalLayerIDs);
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetVisibleFeatures 2: "+std::to_string(features.size()));
mbgl::Log::Debug(mbgl::Event::JNI, "Amount of features found: "+std::to_string(features.size()));

// create FeatureWrapper return type
// create wrapping java object to put features in
jni::jobject* joutput = &jni::NewObject(*env, *featureWrapperClass, *featureWrapperConstructorId);

//jni::jobject* jhashmap = &jni::NewObject(*env, *mapClass, *mapConstructorId);
mbgl::ToFeatureType toFeatureType;
for (const auto &feature : features) {
const mbgl::FeatureType featureType = apply_visitor(toFeatureType, feature.geometry);
if(featureType==mbgl::FeatureType::Point) {
mbgl::Log::Debug(mbgl::Event::JNI, "It's a point");
}else if(featureType==mbgl::FeatureType::LineString) {
if(featureType == mbgl::FeatureType::Point) {
mbgl::Log::Debug(mbgl::Event::JNI, "It's a point");

// create point
jni::jobject* point = &jni::NewObject(*env, *pointFeatureClass, *pointFeatureConstructorId);

// add point to wrapper
jni::CallMethod<void>(*env, joutput, *featureWrapperAddId, point);

}else if(featureType == mbgl::FeatureType::LineString) {
mbgl::Log::Debug(mbgl::Event::JNI, "It's a polyline");
jni::CallMethod<void>(*env, joutput, *featureWrapperAddId,&jni::NewObject(*env, *polylineFeatureClass, *polylineFeatureConstructorId));
}else if(featureType==mbgl::FeatureType::Polygon) {
jni::CallMethod<void>(*env, joutput, *featureWrapperAddId,&jni::NewObject(*env, *polygonFeatureClass, *polygonFeatureConstructorId));

// create polyline
jni::jobject* polyline = &jni::NewObject(*env, *polylineFeatureClass, *polylineFeatureConstructorId);

// add polyline to wrapper
jni::CallMethod<void>(*env, joutput, *featureWrapperAddId, polyline);

}else if(featureType == mbgl::FeatureType::Polygon) {
mbgl::Log::Debug(mbgl::Event::JNI, "It's a polygon");

// create polyline
jni::jobject* polygon = &jni::NewObject(*env, *polygonFeatureClass, *polygonFeatureConstructorId);

// add polygon to wrapper
jni::CallMethod<void>(*env, joutput, *featureWrapperAddId,polygon);

}else{
mbgl::Log::Debug(mbgl::Event::JNI, "Unsupported feature type found!");
}
Expand Down Expand Up @@ -1687,9 +1707,9 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
polygonFeatureClass = jni::NewGlobalRef(env, polygonFeatureClass).release();
polygonFeatureConstructorId = &jni::GetMethodID(env, *polygonFeatureClass, "<init>", "()V");

//multiPolygonFeatureClass = &jni::FindClass(env, "com/mapbox/mapboxsdk/annotations/MultiPolygonFeature");
//multiPolygonFeatureClass = jni::NewGlobalRef(env, multiPolygonFeatureClass).release();
//multiPolygonFeatureConstructorId = &jni::GetMethodID(env, *multiPolygonFeatureClass, "<init>", "()V");
multiPolygonFeatureClass = &jni::FindClass(env, "com/mapbox/mapboxsdk/annotations/MultiPolygonFeature");
multiPolygonFeatureClass = jni::NewGlobalRef(env, multiPolygonFeatureClass).release();
multiPolygonFeatureConstructorId = &jni::GetMethodID(env, *multiPolygonFeatureClass, "<init>", "()V");

polylineFeatureClass = &jni::FindClass(env, "com/mapbox/mapboxsdk/annotations/PolylineFeature");
polylineFeatureClass = jni::NewGlobalRef(env, polylineFeatureClass).release();
Expand Down

0 comments on commit d3d8c05

Please sign in to comment.