This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for polygon overlays to the Google Maps plugin (#1551)
This is relatively trivial, requiring only some additional logic to disambiguate click events between the various possible overlays. Also adds a page to the example app demonstrating polygons, which I tested on iOS and Android.
- Loading branch information
1 parent
9baf6ec
commit 4900e75
Showing
25 changed files
with
1,432 additions
and
1 deletion.
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
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
63 changes: 63 additions & 0 deletions
63
...ogle_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/PolygonBuilder.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,63 @@ | ||
package io.flutter.plugins.googlemaps; | ||
|
||
import com.google.android.gms.maps.model.LatLng; | ||
import com.google.android.gms.maps.model.PolygonOptions; | ||
import java.util.List; | ||
|
||
class PolygonBuilder implements PolygonOptionsSink { | ||
private final PolygonOptions polygonOptions; | ||
private boolean consumeTapEvents; | ||
|
||
PolygonBuilder() { | ||
this.polygonOptions = new PolygonOptions(); | ||
} | ||
|
||
PolygonOptions build() { | ||
return polygonOptions; | ||
} | ||
|
||
boolean consumeTapEvents() { | ||
return consumeTapEvents; | ||
} | ||
|
||
@Override | ||
public void setFillColor(int color) { | ||
polygonOptions.fillColor(color); | ||
} | ||
|
||
@Override | ||
public void setStrokeColor(int color) { | ||
polygonOptions.strokeColor(color); | ||
} | ||
|
||
@Override | ||
public void setPoints(List<LatLng> points) { | ||
polygonOptions.addAll(points); | ||
} | ||
|
||
@Override | ||
public void setConsumeTapEvents(boolean consumeTapEvents) { | ||
this.consumeTapEvents = consumeTapEvents; | ||
polygonOptions.clickable(consumeTapEvents); | ||
} | ||
|
||
@Override | ||
public void setGeodesic(boolean geodisc) { | ||
polygonOptions.geodesic(geodisc); | ||
} | ||
|
||
@Override | ||
public void setVisible(boolean visible) { | ||
polygonOptions.visible(visible); | ||
} | ||
|
||
@Override | ||
public void setStrokeWidth(float width) { | ||
polygonOptions.strokeWidth(width); | ||
} | ||
|
||
@Override | ||
public void setZIndex(float zIndex) { | ||
polygonOptions.zIndex(zIndex); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...e_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/PolygonController.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,71 @@ | ||
package io.flutter.plugins.googlemaps; | ||
|
||
import com.google.android.gms.maps.model.LatLng; | ||
import com.google.android.gms.maps.model.Polygon; | ||
import java.util.List; | ||
|
||
/** Controller of a single Polygon on the map. */ | ||
class PolygonController implements PolygonOptionsSink { | ||
private final Polygon polygon; | ||
private final String googleMapsPolygonId; | ||
private boolean consumeTapEvents; | ||
|
||
PolygonController(Polygon polygon, boolean consumeTapEvents) { | ||
this.polygon = polygon; | ||
this.consumeTapEvents = consumeTapEvents; | ||
this.googleMapsPolygonId = polygon.getId(); | ||
} | ||
|
||
void remove() { | ||
polygon.remove(); | ||
} | ||
|
||
@Override | ||
public void setConsumeTapEvents(boolean consumeTapEvents) { | ||
this.consumeTapEvents = consumeTapEvents; | ||
polygon.setClickable(consumeTapEvents); | ||
} | ||
|
||
@Override | ||
public void setFillColor(int color) { | ||
polygon.setFillColor(color); | ||
} | ||
|
||
@Override | ||
public void setStrokeColor(int color) { | ||
polygon.setStrokeColor(color); | ||
} | ||
|
||
@Override | ||
public void setGeodesic(boolean geodesic) { | ||
polygon.setGeodesic(geodesic); | ||
} | ||
|
||
@Override | ||
public void setPoints(List<LatLng> points) { | ||
polygon.setPoints(points); | ||
} | ||
|
||
@Override | ||
public void setVisible(boolean visible) { | ||
polygon.setVisible(visible); | ||
} | ||
|
||
@Override | ||
public void setStrokeWidth(float width) { | ||
polygon.setStrokeWidth(width); | ||
} | ||
|
||
@Override | ||
public void setZIndex(float zIndex) { | ||
polygon.setZIndex(zIndex); | ||
} | ||
|
||
String getGoogleMapsPolygonId() { | ||
return googleMapsPolygonId; | ||
} | ||
|
||
boolean consumeTapEvents() { | ||
return consumeTapEvents; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
..._maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/PolygonOptionsSink.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,24 @@ | ||
package io.flutter.plugins.googlemaps; | ||
|
||
import com.google.android.gms.maps.model.LatLng; | ||
import java.util.List; | ||
|
||
/** Receiver of Polygon configuration options. */ | ||
interface PolygonOptionsSink { | ||
|
||
void setConsumeTapEvents(boolean consumetapEvents); | ||
|
||
void setFillColor(int color); | ||
|
||
void setStrokeColor(int color); | ||
|
||
void setGeodesic(boolean geodesic); | ||
|
||
void setPoints(List<LatLng> points); | ||
|
||
void setVisible(boolean visible); | ||
|
||
void setStrokeWidth(float width); | ||
|
||
void setZIndex(float zIndex); | ||
} |
Oops, something went wrong.