|
36 | 36 | import java.util.HashMap;
|
37 | 37 | import java.util.List;
|
38 | 38 | import java.util.Map;
|
39 |
| -import java.util.Set; |
40 | 39 |
|
41 | 40 | /** Conversions between JSON-like values and GoogleMaps data types. */
|
42 | 41 | class Convert {
|
@@ -377,6 +376,13 @@ static Object latLngBoundsToJson(LatLngBounds latLngBounds) {
|
377 | 376 | return arguments;
|
378 | 377 | }
|
379 | 378 |
|
| 379 | + static Messages.PlatformLatLngBounds latLngBoundsToPigeon(LatLngBounds latLngBounds) { |
| 380 | + return new Messages.PlatformLatLngBounds.Builder() |
| 381 | + .setNortheast(latLngToPigeon(latLngBounds.northeast)) |
| 382 | + .setSouthwest(latLngToPigeon(latLngBounds.southwest)) |
| 383 | + .build(); |
| 384 | + } |
| 385 | + |
380 | 386 | static Object markerIdToJson(String markerId) {
|
381 | 387 | if (markerId == null) {
|
382 | 388 | return null;
|
@@ -431,13 +437,11 @@ static Object latLngToJson(LatLng latLng) {
|
431 | 437 | return Arrays.asList(latLng.latitude, latLng.longitude);
|
432 | 438 | }
|
433 | 439 |
|
434 |
| - static Object clustersToJson( |
435 |
| - String clusterManagerId, Set<? extends Cluster<MarkerBuilder>> clusters) { |
436 |
| - List<Object> data = new ArrayList<>(clusters.size()); |
437 |
| - for (Cluster<MarkerBuilder> cluster : clusters) { |
438 |
| - data.add(clusterToJson(clusterManagerId, cluster)); |
439 |
| - } |
440 |
| - return data; |
| 440 | + static Messages.PlatformLatLng latLngToPigeon(LatLng latLng) { |
| 441 | + return new Messages.PlatformLatLng.Builder() |
| 442 | + .setLat(latLng.latitude) |
| 443 | + .setLng(latLng.longitude) |
| 444 | + .build(); |
441 | 445 | }
|
442 | 446 |
|
443 | 447 | static Object clusterToJson(String clusterManagerId, Cluster<MarkerBuilder> cluster) {
|
@@ -470,6 +474,27 @@ static Object clusterToJson(String clusterManagerId, Cluster<MarkerBuilder> clus
|
470 | 474 | return data;
|
471 | 475 | }
|
472 | 476 |
|
| 477 | + static Messages.PlatformCluster clusterToPigeon( |
| 478 | + String clusterManagerId, Cluster<MarkerBuilder> cluster) { |
| 479 | + int clusterSize = cluster.getSize(); |
| 480 | + String[] markerIds = new String[clusterSize]; |
| 481 | + MarkerBuilder[] markerBuilders = cluster.getItems().toArray(new MarkerBuilder[clusterSize]); |
| 482 | + |
| 483 | + LatLngBounds.Builder latLngBoundsBuilder = LatLngBounds.builder(); |
| 484 | + for (int i = 0; i < clusterSize; i++) { |
| 485 | + MarkerBuilder markerBuilder = markerBuilders[i]; |
| 486 | + latLngBoundsBuilder.include(markerBuilder.getPosition()); |
| 487 | + markerIds[i] = markerBuilder.markerId(); |
| 488 | + } |
| 489 | + |
| 490 | + return new Messages.PlatformCluster.Builder() |
| 491 | + .setClusterManagerId(clusterManagerId) |
| 492 | + .setPosition(latLngToPigeon(cluster.getPosition())) |
| 493 | + .setBounds(latLngBoundsToPigeon(latLngBoundsBuilder.build())) |
| 494 | + .setMarkerIds(Arrays.asList(markerIds)) |
| 495 | + .build(); |
| 496 | + } |
| 497 | + |
473 | 498 | static LatLng toLatLng(Object o) {
|
474 | 499 | final List<?> data = toList(o);
|
475 | 500 | return new LatLng(toDouble(data.get(0)), toDouble(data.get(1)));
|
|
0 commit comments