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 Fill API support #49

Merged
merged 18 commits into from Oct 24, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -40,7 +40,7 @@ This project is available on [pub.dev](https://pub.dev/packages/mapbox_gl), foll
| Symbol | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Circle | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Line | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Fill | | | |
| Fill | :white_check_mark: | :white_check_mark: | |

## Map Styles

Expand Down
58 changes: 55 additions & 3 deletions android/src/main/java/com/mapbox/mapboxgl/Convert.java
Expand Up @@ -5,7 +5,7 @@
package com.mapbox.mapboxgl;

import android.graphics.Point;

import com.mapbox.geojson.Polygon;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
Expand Down Expand Up @@ -100,7 +100,7 @@ static CameraUpdate toCameraUpdate(Object o, MapboxMap mapboxMap, float density)
case "bearingTo":
return CameraUpdateFactory.bearingTo(toFloat(data.get(1)));
case "tiltTo":
return CameraUpdateFactory.tiltTo(toFloat(data.get(1)));
return CameraUpdateFactory.tiltTo(toFloat(data.get(1)));
default:
throw new IllegalArgumentException("Cannot interpret " + o + " as CameraUpdate");
}
Expand Down Expand Up @@ -168,6 +168,31 @@ private static List<LatLng> toLatLngList(Object o) {
return latLngList;
}

private static List<List<LatLng>> toLatLngListList(Object o) {
if (o == null) {
return null;
}
final List<?> data = toList(o);
List<List<LatLng>> latLngListList = new ArrayList<>();
for (int i = 0; i < data.size(); i++) {
List<LatLng> latLngList = toLatLngList(data.get(i));
latLngListList.add(latLngList);
}
return latLngListList;
}

static Polygon interpretListLatLng(List<List<LatLng>> geometry) {
List<List<com.mapbox.geojson.Point>> points = new ArrayList<>(geometry.size());
for (List<LatLng> innerGeometry : geometry) {
List<com.mapbox.geojson.Point> innerPoints = new ArrayList<>(innerGeometry.size());
for (LatLng latLng : innerGeometry) {
innerPoints.add(com.mapbox.geojson.Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
}
points.add(innerPoints);
}
return Polygon.fromLngLats(points);
}

private static List<?> toList(Object o) {
return (List<?>) o;
}
Expand Down Expand Up @@ -423,7 +448,6 @@ static void interpretCircleOptions(Object o, CircleOptionsSink sink) {
sink.setDraggable(toBoolean(draggable));
}
}

static void interpretLineOptions(Object o, LineOptionsSink sink) {
final Map<?, ?> data = toMap(o);
final Object lineJoin = data.get("lineJoin");
Expand Down Expand Up @@ -477,4 +501,32 @@ static void interpretLineOptions(Object o, LineOptionsSink sink) {
sink.setDraggable(toBoolean(draggable));
}
}

static void interpretFillOptions(Object o, FillOptionsSink sink) {
final Map<?, ?> data = toMap(o);
final Object fillOpacity = data.get("fillOpacity");
if (fillOpacity != null) {
sink.setFillOpacity(toFloat(fillOpacity));
}
final Object fillColor = data.get("fillColor");
if (fillColor != null) {
sink.setFillColor(toString(fillColor));
}
final Object fillOutlineColor = data.get("fillOutlineColor");
if (fillOutlineColor != null) {
sink.setFillOutlineColor(toString(fillOutlineColor));
}
final Object fillPattern = data.get("fillPattern");
if (fillPattern != null) {
sink.setFillPattern(toString(fillPattern));
}
final Object geometry = data.get("geometry");
if (geometry != null) {
sink.setGeometry(toLatLngListList(geometry));
}
final Object draggable = data.get("draggable");
if (draggable != null) {
sink.setDraggable(toBoolean(draggable));
}
}
}
58 changes: 58 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/FillBuilder.java
@@ -0,0 +1,58 @@
// 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 com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.plugins.annotation.Fill;
import com.mapbox.mapboxsdk.plugins.annotation.FillManager;
import com.mapbox.mapboxsdk.plugins.annotation.FillOptions;

import java.util.List;

class FillBuilder implements FillOptionsSink {
private final FillManager fillManager;
private final FillOptions fillOptions;

FillBuilder(FillManager fillManager) {
this.fillManager = fillManager;
this.fillOptions = new FillOptions();
}

Fill build() {
return fillManager.create(fillOptions);
}

@Override
public void setFillOpacity(float fillOpacity) {
fillOptions.withFillOpacity(fillOpacity);
}

@Override
public void setFillColor(String fillColor) {
fillOptions.withFillColor(fillColor);
}

@Override
public void setFillOutlineColor(String fillOutlineColor) {
fillOptions.withFillOutlineColor(fillOutlineColor);
}

@Override
public void setFillPattern(String fillPattern) {
fillOptions.withFillPattern(fillPattern);
}

@Override
public void setGeometry(List<List<LatLng>> geometry) {
fillOptions.withGeometry(Convert.interpretListLatLng(geometry));
}

@Override
public void setDraggable(boolean draggable) {
fillOptions.withDraggable(draggable);
}
}
74 changes: 74 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/FillController.java
@@ -0,0 +1,74 @@
// 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 android.graphics.Color;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.plugins.annotation.Fill;
import com.mapbox.mapboxsdk.plugins.annotation.FillManager;

import java.util.List;

/**
* Controller of a single Fill on the map.
*/
class FillController implements FillOptionsSink {
private final Fill fill;
private final OnFillTappedListener onTappedListener;
private boolean consumeTapEvents;

FillController(Fill fill, boolean consumeTapEvents, OnFillTappedListener onTappedListener) {
this.fill = fill;
this.consumeTapEvents = consumeTapEvents;
this.onTappedListener = onTappedListener;
}

boolean onTap() {
if (onTappedListener != null) {
onTappedListener.onFillTapped(fill);
}
return consumeTapEvents;
}

void remove(FillManager fillManager) {
fillManager.delete(fill);
}

@Override
public void setFillOpacity(float fillOpacity) {
fill.setFillOpacity(fillOpacity);
}

@Override
public void setFillColor(String fillColor) {
fill.setFillColor(Color.parseColor(fillColor));
}

@Override
public void setFillOutlineColor(String fillOutlineColor) {
fill.setFillOutlineColor(Color.parseColor(fillOutlineColor));
}

@Override
public void setFillPattern(String fillPattern) {
fill.setFillPattern(fillPattern);
}

@Override
public void setGeometry(List<List<LatLng>> geometry) {
fill.setGeometry(Convert.interpretListLatLng(geometry));
}

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

public void update(FillManager fillManager) {
fillManager.update(fill);
}
}
27 changes: 27 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/FillOptionsSink.java
@@ -0,0 +1,27 @@
// 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 com.mapbox.mapboxsdk.geometry.LatLng;

import java.util.List;

/** Receiver of Fill configuration options. */
interface FillOptionsSink {

void setFillOpacity(float fillOpacity);

void setFillColor(String fillColor);

void setFillOutlineColor(String fillOutlineColor);

void setFillPattern(String fillPattern);

void setGeometry(List<List<LatLng>> geometry);

void setDraggable(boolean draggable);
}