Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add line annotations #33

Merged
merged 9 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
69 changes: 69 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.log.Logger;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.geojson.LineString;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -156,6 +158,19 @@ private static LatLngBounds toLatLngBounds(Object o) {
return builder.build();
}

private static List<LatLng> toLatLngList(Object o) {
if (o == null) {
return null;
}
final List<?> data = toList(o);
List<LatLng> latLngList = new ArrayList<>();
data.forEach((element) -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call requires API level 24?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I changed it to a for loop.

final List<?> coords = toList(element);
latLngList.add(new LatLng(toDouble(coords.get(0)), toDouble(coords.get(1))));
});
return latLngList;
}

private static List<?> toList(Object o) {
return (List<?>) o;
}
Expand Down Expand Up @@ -358,4 +373,58 @@ static void interpretSymbolOptions(Object o, SymbolOptionsSink sink) {
sink.setDraggable(toBoolean(draggable));
}
}

static void interpretLineOptions(Object o, LineOptionsSink sink) {
final Map<?, ?> data = toMap(o);
final Object lineJoin = data.get("lineJoin");
if (lineJoin != null) {
Logger.e(TAG, "setLineJoin" + lineJoin);
sink.setLineJoin(toString(lineJoin));
}
final Object lineOpacity = data.get("lineOpacity");
if (lineOpacity != null) {
Logger.e(TAG, "setLineOpacity" + lineOpacity);
sink.setLineOpacity(toFloat(lineOpacity));
}
final Object lineColor = data.get("lineColor");
if (lineColor != null) {
Logger.e(TAG, "setLineColor" + lineColor);
sink.setLineColor(toString(lineColor));
}
final Object lineWidth = data.get("lineWidth");
if (lineWidth != null) {
Logger.e(TAG, "setLineWidth" + lineWidth);
sink.setLineWidth(toFloat(lineWidth));
}
final Object lineGapWidth = data.get("lineGapWidth");
if (lineGapWidth != null) {
Logger.e(TAG, "setLineGapWidth" + lineGapWidth);
sink.setLineGapWidth(toFloat(lineGapWidth));
}
final Object lineOffset = data.get("lineOffset");
if (lineOffset != null) {
Logger.e(TAG, "setLineOffset" + lineOffset);
sink.setLineOffset(toFloat(lineOffset));
}
final Object lineBlur = data.get("lineBlur");
if (lineBlur != null) {
Logger.e(TAG, "setLineBlur" + lineBlur);
sink.setLineBlur(toFloat(lineBlur));
}
final Object linePattern = data.get("linePattern");
if (linePattern != null) {
Logger.e(TAG, "setLinePattern" + linePattern);
sink.setLinePattern(toString(linePattern));
}
final Object geometry = data.get("geometry");
if (geometry != null) {
Logger.e(TAG, "SetGeometry");
sink.setGeometry(toLatLngList(geometry));
}
final Object draggable = data.get("draggable");
if (draggable != null) {
Logger.e(TAG, "SetDraggable");
sink.setDraggable(toBoolean(draggable));
}
}
}
78 changes: 78 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/LineBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// This file is generated.

// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package com.mapbox.mapboxgl;

import java.util.List;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.plugins.annotation.Line;
import com.mapbox.mapboxsdk.plugins.annotation.LineManager;
import com.mapbox.mapboxsdk.plugins.annotation.LineOptions;

class LineBuilder implements LineOptionsSink {
private final LineManager lineManager;
private final LineOptions lineOptions;

LineBuilder(LineManager lineManager) {
this.lineManager = lineManager;
this.lineOptions = new LineOptions();
}

Line build() {
return lineManager.create(lineOptions);
}

@Override
public void setLineJoin(String lineJoin) {
lineOptions.withLineJoin(lineJoin);
}

@Override
public void setLineOpacity(float lineOpacity) {
lineOptions.withLineOpacity(lineOpacity);
}

@Override
public void setLineColor(String lineColor) {
lineOptions.withLineColor(lineColor);
}

@Override
public void setLineWidth(float lineWidth) {
lineOptions.withLineWidth(lineWidth);
}

@Override
public void setLineGapWidth(float lineGapWidth) {
lineOptions.withLineGapWidth(lineGapWidth);
}

@Override
public void setLineOffset(float lineOffset) {
lineOptions.withLineOffset(lineOffset);
}

@Override
public void setLineBlur(float lineBlur) {
lineOptions.withLineBlur(lineBlur);
}

@Override
public void setLinePattern(String linePattern) {
lineOptions.withLinePattern(linePattern);
}

@Override
public void setGeometry(List<LatLng> geometry) {
lineOptions.withLatLngs(geometry);
}

@Override
public void setDraggable(boolean draggable) {
lineOptions.setDraggable(draggable);
}
}
98 changes: 98 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/LineController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// This file is generated.

// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package com.mapbox.mapboxgl;

import java.util.List;

import android.graphics.PointF;
import android.util.Log;

import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.plugins.annotation.Line;
import com.mapbox.mapboxsdk.plugins.annotation.LineManager;
import com.mapbox.mapboxsdk.utils.ColorUtils;

/**
* Controller of a single Line on the map.
*/
class LineController implements LineOptionsSink {
private final Line line;
private final OnLineTappedListener onTappedListener;
private boolean consumeTapEvents;

LineController(Line line, boolean consumeTapEvents, OnLineTappedListener onTappedListener) {
this.line = line;
this.consumeTapEvents = consumeTapEvents;
this.onTappedListener = onTappedListener;
}

boolean onTap() {
if (onTappedListener != null) {
onTappedListener.onLineTapped(line);
}
return consumeTapEvents;
}

void remove(LineManager lineManager) {
lineManager.delete(line);
}

@Override
public void setLineJoin(String lineJoin) {
line.setLineJoin(lineJoin);
}

@Override
public void setLineOpacity(float lineOpacity) {
line.setLineOpacity(lineOpacity);
}

@Override
public void setLineColor(String lineColor) {
line.setLineColor(ColorUtils.rgbaToColor(lineColor));
}

@Override
public void setLineWidth(float lineWidth) {
line.setLineWidth(lineWidth);
}

@Override
public void setLineGapWidth(float lineGapWidth) {
line.setLineGapWidth(lineGapWidth);
}

@Override
public void setLineOffset(float lineOffset) {
line.setLineOffset(lineOffset);
}

@Override
public void setLineBlur(float lineBlur) {
line.setLineBlur(lineBlur);
}

@Override
public void setLinePattern(String linePattern) {
line.setLinePattern(linePattern);
}

@Override
public void setGeometry(List<LatLng> geometry) {
line.setLatLngs(geometry);
}

@Override
public void setDraggable(boolean draggable) {
line.setDraggable(draggable);
}

public void update(LineManager lineManager) {
lineManager.update(line);
}
}
36 changes: 36 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/LineOptionsSink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This file is generated.

// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package com.mapbox.mapboxgl;

import java.util.List;
import com.mapbox.mapboxsdk.geometry.LatLng;

/**
* Receiver of Line configuration options.
*/
interface LineOptionsSink {

void setLineJoin(String lineJoin);

void setLineOpacity(float lineOpacity);

void setLineColor(String lineColor);

void setLineWidth(float lineWidth);

void setLineGapWidth(float lineGapWidth);

void setLineOffset(float lineOffset);

void setLineBlur(float lineBlur);

void setLinePattern(String linePattern);

void setGeometry(List<LatLng> geometry);

void setDraggable(boolean draggable);
}
Loading