Skip to content
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
@@ -1,13 +1,14 @@
package com.mapbox.mapboxsdk.plugins.testapp.activity.annotation;


import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.mapbox.geojson.LineString;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
Expand Down Expand Up @@ -75,6 +76,15 @@ protected void onCreate(Bundle savedInstanceState) {
LineChangeActivity.this,
"Clicked: " + line.getId(),
Toast.LENGTH_SHORT).show());

LineManager dottedLineManger = new LineManager(mapView, mapboxMap, style);
dottedLineManger.create(new LineOptions()
.withLinePattern("airfield-11")
.withLineWidth(5.0f)
.withGeometry(LineString.fromLngLats(new ArrayList<Point>() {{
add(Point.fromLngLat(9.997167, 53.547476));
add(Point.fromLngLat(12.587986, 55.675313));
}})));
});
});

Expand Down
49 changes: 49 additions & 0 deletions plugin-annotation/scripts/annotation_element_provider.java.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<%
const type = locals.type;
const properties = locals.properties;
const doc = locals.doc;
-%>
// This file is generated.

package com.mapbox.mapboxsdk.plugins.annotation;

import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;

import java.util.concurrent.atomic.AtomicLong;

/**
* Concrete instance of a core element provider for <%- camelize(type) %>.
*/
class <%- camelize(type) %>ElementProvider implements CoreElementProvider<<%- camelize(type) %>Layer>{

private static final AtomicLong ID_GENERATOR = new AtomicLong(0);
private static final String ID_GEOJSON_LAYER = "mapbox-android-<%- type %>-layer-%s";
private static final String ID_GEOJSON_SOURCE = "mapbox-android-<%- type %>-source-%s";

private final String layerId;
private final String sourceId;

<%- camelize(type) %>ElementProvider() {
long id = ID_GENERATOR.incrementAndGet();
this.layerId = String.format(ID_GEOJSON_LAYER, id);
this.sourceId = String.format(ID_GEOJSON_SOURCE, id);
}

@Override
public String getLayerId() {
return layerId;
}

@Override
public <%- camelize(type) %>Layer getLayer() {
return new <%- camelize(type) %>Layer(layerId, sourceId);
}

@Override
public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) {
return new GeoJsonSource(sourceId, geoJsonOptions);
}
}
32 changes: 1 addition & 31 deletions plugin-annotation/scripts/annotation_manager.java.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer;
import com.mapbox.mapboxsdk.style.layers.PropertyValue;
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
import com.mapbox.mapboxsdk.style.layers.Property;

import java.util.ArrayList;
Expand All @@ -36,9 +35,6 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*;
*/
public class <%- camelize(type) %>Manager extends AnnotationManager<<%- camelize(type) %>Layer, <%- camelize(type) %>, <%- camelize(type) %>Options, On<%- camelize(type) %>DragListener, On<%- camelize(type) %>ClickListener, On<%- camelize(type) %>LongClickListener> {

public static final String ID_GEOJSON_SOURCE = "mapbox-android-<%- type %>-source";
public static final String ID_GEOJSON_LAYER = "mapbox-android-<%- type %>-layer";

<% for (const property of properties) { -%>
<% if (!supportsPropertyFunction(property) && property.name !== "line-gradient" && property.name !== "symbol-z-order") { -%>
private static final String PROPERTY_<%- snakeCaseUpper(property.name) %> = "<%- property.name %>";
Expand Down Expand Up @@ -78,23 +74,7 @@ public class <%- camelize(type) %>Manager extends AnnotationManager<<%- camelize
*/
@UiThread
public <%- camelize(type) %>Manager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions) {
this(mapView, mapboxMap, style,
new CoreElementProvider<<%- camelize(type) %>Layer>() {
@Override
public <%- camelize(type) %>Layer getLayer() {
return new <%- camelize(type) %>Layer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE);
}

@Override
public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) {
if (geoJsonOptions != null) {
return new GeoJsonSource(ID_GEOJSON_SOURCE, geoJsonOptions);
} else {
return new GeoJsonSource(ID_GEOJSON_SOURCE);
}
}
},
belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap));
this(mapView, mapboxMap, style, new <%- camelize(type) %>ElementProvider(), belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap));
}

@VisibleForTesting
Expand Down Expand Up @@ -200,16 +180,6 @@ public class <%- camelize(type) %>Manager extends AnnotationManager<<%- camelize
return create(options);
}

/**
* Get the layer id of the annotation layer.
*
* @return the layer id
*/
@Override
String getAnnotationLayerId() {
return ID_GEOJSON_LAYER;
}

/**
* Get the key of the id of the annotation.
*
Expand Down
2 changes: 2 additions & 0 deletions plugin-annotation/scripts/code-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ global.supportsPropertyFunction = function (property) {
const annotationJava = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation.java.ejs', 'utf8'), {strict: true});
const annotationOptionsJava = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation_options.java.ejs', 'utf8'), {strict: true});
const annotationManagerJava = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation_manager.java.ejs', 'utf8'), {strict: true});
const annotationElementProvider = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation_element_provider.java.ejs', 'utf8'), {strict: true});
const annotationDragListener = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation_drag_listener.java.ejs', 'utf8'), {strict: true});
const annotationClickListener = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation_click_listener.java.ejs', 'utf8'), {strict: true});
const annotationLongClickListener = ejs.compile(fs.readFileSync('plugin-annotation/scripts/annotation_long_click_listener.java.ejs', 'utf8'), {strict: true});
Expand All @@ -402,6 +403,7 @@ for (const layer of layers) {
writeIfModified(`plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}.java`, annotationJava(layer));
writeIfModified(`plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}Options.java`, annotationOptionsJava(layer));
writeIfModified(`plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}Manager.java`, annotationManagerJava(layer));
writeIfModified(`plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}ElementProvider.java`, annotationElementProvider(layer));
writeIfModified(`app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}Test.java`, annotationJavaInstrumentationTests(layer));
writeIfModified(`app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}ManagerTest.java`, annotationManagerJavaInstrumentationTests(layer));
writeIfModified(`plugin-annotation/src/test/java/com/mapbox/mapboxsdk/plugins/annotation/${camelize(layer.type)}ManagerTest.java`, annotationManagerJavaUnitTests(layer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Generic AnnotationManager, can be used to create annotation specific managers.
Expand Down Expand Up @@ -327,8 +328,6 @@ public void onDestroy() {
longClickListeners.clear();
}

abstract String getAnnotationLayerId();

abstract String getAnnotationIdKey();

abstract void initializeDataDrivenPropertyMap();
Expand Down Expand Up @@ -398,7 +397,7 @@ private T queryMapForFeatures(@NonNull LatLng point) {

@Nullable
T queryMapForFeatures(@NonNull PointF point) {
List<Feature> features = mapboxMap.queryRenderedFeatures(point, getAnnotationLayerId());
List<Feature> features = mapboxMap.queryRenderedFeatures(point, coreElementProvider.getLayerId());
if (!features.isEmpty()) {
long id = features.get(0).getProperty(getAnnotationIdKey()).getAsLong();
return annotations.get(id);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This file is generated.

package com.mapbox.mapboxsdk.plugins.annotation;

import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;

import java.util.concurrent.atomic.AtomicLong;

/**
* Concrete instance of a core element provider for Circle.
*/
class CircleElementProvider implements CoreElementProvider<CircleLayer>{

private static final AtomicLong ID_GENERATOR = new AtomicLong(0);
private static final String ID_GEOJSON_LAYER = "mapbox-android-circle-layer-%s";
private static final String ID_GEOJSON_SOURCE = "mapbox-android-circle-source-%s";

private final String layerId;
private final String sourceId;

CircleElementProvider() {
long id = ID_GENERATOR.incrementAndGet();
this.layerId = String.format(ID_GEOJSON_LAYER, id);
this.sourceId = String.format(ID_GEOJSON_SOURCE, id);
}

@Override
public String getLayerId() {
return layerId;
}

@Override
public CircleLayer getLayer() {
return new CircleLayer(layerId, sourceId);
}

@Override
public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) {
return new GeoJsonSource(sourceId, geoJsonOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.mapbox.mapboxsdk.style.layers.PropertyValue;
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
import com.mapbox.mapboxsdk.style.layers.Property;

import java.util.ArrayList;
Expand All @@ -31,9 +30,6 @@
*/
public class CircleManager extends AnnotationManager<CircleLayer, Circle, CircleOptions, OnCircleDragListener, OnCircleClickListener, OnCircleLongClickListener> {

public static final String ID_GEOJSON_SOURCE = "mapbox-android-circle-source";
public static final String ID_GEOJSON_LAYER = "mapbox-android-circle-layer";

private static final String PROPERTY_CIRCLE_TRANSLATE = "circle-translate";
private static final String PROPERTY_CIRCLE_TRANSLATE_ANCHOR = "circle-translate-anchor";
private static final String PROPERTY_CIRCLE_PITCH_SCALE = "circle-pitch-scale";
Expand Down Expand Up @@ -72,23 +68,7 @@ public CircleManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @No
*/
@UiThread
public CircleManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions) {
this(mapView, mapboxMap, style,
new CoreElementProvider<CircleLayer>() {
@Override
public CircleLayer getLayer() {
return new CircleLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE);
}

@Override
public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) {
if (geoJsonOptions != null) {
return new GeoJsonSource(ID_GEOJSON_SOURCE, geoJsonOptions);
} else {
return new GeoJsonSource(ID_GEOJSON_SOURCE);
}
}
},
belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap));
this(mapView, mapboxMap, style, new CircleElementProvider(), belowLayerId, geoJsonOptions, new DraggableAnnotationController<>(mapView, mapboxMap));
}

@VisibleForTesting
Expand Down Expand Up @@ -196,16 +176,6 @@ public List<Circle> create(@NonNull FeatureCollection featureCollection) {
return create(options);
}

/**
* Get the layer id of the annotation layer.
*
* @return the layer id
*/
@Override
String getAnnotationLayerId() {
return ID_GEOJSON_LAYER;
}

/**
* Get the key of the id of the annotation.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.mapbox.mapboxsdk.plugins.annotation;

import android.support.annotation.Nullable;

import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;

interface CoreElementProvider<L extends Layer> {

String getLayerId();

L getLayer();

GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This file is generated.

package com.mapbox.mapboxsdk.plugins.annotation;

import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.style.layers.FillLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;

import java.util.concurrent.atomic.AtomicLong;

/**
* Concrete instance of a core element provider for Fill.
*/
class FillElementProvider implements CoreElementProvider<FillLayer>{

private static final AtomicLong ID_GENERATOR = new AtomicLong(0);
private static final String ID_GEOJSON_LAYER = "mapbox-android-fill-layer-%s";
private static final String ID_GEOJSON_SOURCE = "mapbox-android-fill-source-%s";

private final String layerId;
private final String sourceId;

FillElementProvider() {
long id = ID_GENERATOR.incrementAndGet();
this.layerId = String.format(ID_GEOJSON_LAYER, id);
this.sourceId = String.format(ID_GEOJSON_SOURCE, id);
}

@Override
public String getLayerId() {
return layerId;
}

@Override
public FillLayer getLayer() {
return new FillLayer(layerId, sourceId);
}

@Override
public GeoJsonSource getSource(@Nullable GeoJsonOptions geoJsonOptions) {
return new GeoJsonSource(sourceId, geoJsonOptions);
}
}
Loading