Skip to content
Draft
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
Expand Up @@ -11,7 +11,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
map3d:mapId="your_map_id"
map3d:mode="hybrid"
map3d:mapMode="hybrid"
map3d:centerLat="40.748392"
map3d:centerLng="-73.986060"
map3d:centerAlt="175"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
map3d:mapId="your_map_id"
map3d:mode="hybrid"
map3d:mapMode="hybrid"
map3d:centerLat="40.748392"
map3d:centerLng="-73.986060"
map3d:centerAlt="175"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
map3d:minAltitude="0"
map3d:minHeading="0"
map3d:minTilt="0"
map3d:mode="satellite"
map3d:mapMode="satellite"
map3d:range="4000"
map3d:roll="0"
map3d:tilt="67" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<com.google.android.gms.maps3d.Map3DView
android:id="@+id/map3dView"
map3d:mode="satellite"
map3d:mapMode="satellite"
map3d:centerLat="40.748392"
map3d:centerLng="-73.986060"
map3d:centerAlt="175"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<com.google.android.gms.maps3d.Map3DView
android:id="@+id/map3dView"
map3d:mapId="bcce776b92de1336e22c569f"
map3d:mode="hybrid"
map3d:mapMode="hybrid"
map3d:centerLat="38.743498"
map3d:centerLng="-109.499307"
map3d:centerAlt="1467"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<com.google.android.gms.maps3d.Map3DView
android:id="@+id/map3dView"
map3d:mode="hybrid"
map3d:mapMode="hybrid"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onMap3DViewReady(GoogleMap3D googleMap3D) {
super.onMap3DViewReady(googleMap3D);

googleMap3D.setOnMapReadyListener((map) -> {
googleMap3D.setOnMapReadyListener(null);
initializeMap(googleMap3D);
Expand All @@ -94,18 +94,21 @@ private void initializeMap(@NonNull GoogleMap3D googleMap3D) {
googleMap3D.setMapMode(Map3DMode.HYBRID);

// Listeners for map clicks.
googleMap3D.setMap3DClickListener((location, placeId) -> {
googleMap3D.setMap3DClickListener((event) -> {
runOnUiThread(() -> {
String message;
if (placeId != null) {
message = "Clicked Place ID: " + placeId;
if (event.getPlaceId() != null) {
message = "Clicked Place ID: " + event.getPlaceId();
} else {
message = "Clicked Location: " + location.getLatitude() + ", " + location.getLongitude();
message = "Clicked Location: " + event.getLocation().getLatitude() + ", "
+ event.getLocation().getLongitude();
}
clickedInfoText.setText(message);
clickedInfoText.setContentDescription(message);
showToast(message);

});
return true;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,24 @@

package com.example.maps3djava.markers;

import com.google.android.gms.maps3d.model.FlyAroundOptions;
import com.google.android.gms.maps3d.model.PopoverOptions;
import com.google.android.gms.maps3d.Popover;
import org.json.JSONObject;
import org.json.JSONArray;
import android.graphics.Color;
import android.util.Log;
import android.widget.TextView;
import android.widget.PopupMenu;
import java.util.concurrent.CompletableFuture;
import android.os.Looper;
import android.os.Handler;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Random;
import static com.example.maps3d.common.UtilitiesKt.toValidCamera;

import android.graphics.Color;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import android.widget.PopupMenu;
import android.widget.TextView;
import com.example.maps3dcommon.R;
import com.example.maps3djava.sampleactivity.SampleBaseActivity;
import com.google.android.gms.maps3d.GoogleMap3D;
import com.google.android.gms.maps3d.Popover;
import com.google.android.gms.maps3d.model.AltitudeMode;
import com.google.android.gms.maps3d.model.Camera;
import com.google.android.gms.maps3d.model.CollisionBehavior;
import com.google.android.gms.maps3d.model.FlyAroundOptions;
import com.google.android.gms.maps3d.model.FlyToOptions;
import com.google.android.gms.maps3d.model.Glyph;
import com.google.android.gms.maps3d.model.ImageView;
Expand All @@ -48,9 +40,13 @@
import com.google.android.gms.maps3d.model.Marker;
import com.google.android.gms.maps3d.model.MarkerOptions;
import com.google.android.gms.maps3d.model.PinConfiguration;

import java.util.List;
import com.google.android.gms.maps3d.model.PopoverOptions;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CompletableFuture;

/**
* Demonstrates the use of different altitude modes for markers in a 3D map.
Expand Down Expand Up @@ -111,9 +107,9 @@ public final Camera getInitialCamera() {
@Override
public void onMap3DViewReady(GoogleMap3D googleMap3D) {
super.onMap3DViewReady(googleMap3D);

Log.d(getTAG(), "onMap3DViewReady called");

googleMap3D.setOnMapReadyListener((map) -> {
Log.w(getTAG(), "on map ready listener fired");
googleMap3D.setOnMapReadyListener(null);
Expand Down Expand Up @@ -201,13 +197,17 @@ private void initializeMap(GoogleMap3D googleMap3D) {
stopButton.setOnClickListener(v -> stopMonsterTour(googleMap3D));
}

googleMap3D.setMap3DClickListener((location, placeId) -> {
runOnUiThread(() -> {
if (activePopover != null) {
activePopover.remove();
activePopover = null;
}
});
googleMap3D.setMap3DClickListener((event) -> {
boolean hadActivePopover = activePopover != null;
if (hadActivePopover) {
runOnUiThread(() -> {
if (activePopover != null) {
activePopover.remove();
activePopover = null;
}
});
}
return hadActivePopover;
});

// Marker 1: Absolute Altitude
Expand Down Expand Up @@ -594,4 +594,4 @@ private int getMonsterBlurbResId(String monsterId) {
return 0;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@ class MapInteractionsActivity : SampleBaseActivity() {

// Listeners for map clicks. We use lifecycleScope to ensure coroutines are cancelled when the activity is destroyed.
lifecycleScope.launch {
googleMap3D.setMap3DClickListener { location, placeId ->
googleMap3D.setMap3DClickListener { event ->
runOnUiThread {
val message = if (placeId != null) {
"Clicked Place ID: $placeId"
val message = if (event.placeId != null) {
"Clicked Place ID: ${event.placeId}"
} else {
"Clicked Location: ${location.latitude}, ${location.longitude}"
"Clicked Location: ${event.location.latitude}, ${event.location.longitude}"
}
clickedInfoText.text = message
clickedInfoText.contentDescription = message
showToast(message)
}
return@setMap3DClickListener true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ import android.widget.Button
import android.widget.Toast
import androidx.lifecycle.lifecycleScope
import com.example.maps3dcommon.R
import com.example.maps3dkotlin.common.awaitCameraAnimation
import com.example.maps3dkotlin.common.awaitMapSteady
import com.example.maps3dkotlin.markers.data.MonsterParser
import com.example.maps3dkotlin.sampleactivity.SampleBaseActivity
import com.google.android.gms.maps3d.GoogleMap3D
import com.google.android.gms.maps3d.model.AltitudeMode
import com.google.android.gms.maps3d.model.Camera
import com.google.android.gms.maps3d.model.CollisionBehavior
import com.google.android.gms.maps3d.model.Glyph
import com.google.android.gms.maps3d.model.ImageView
import com.google.android.gms.maps3d.model.Map3DMode
import com.google.android.gms.maps3d.model.Marker
import com.google.android.gms.maps3d.model.Camera
import com.google.android.gms.maps3d.model.camera
import com.google.android.gms.maps3d.model.flyToOptions
import com.google.android.gms.maps3d.model.latLngAltitude
import com.google.android.gms.maps3d.model.markerOptions
import com.google.android.gms.maps3d.model.pinConfiguration
import com.google.android.gms.maps3d.model.popoverOptions
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import com.example.maps3dkotlin.common.awaitCameraAnimation
import com.example.maps3dkotlin.common.awaitMapSteady
import com.example.maps3dkotlin.markers.data.MonsterParser
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.launch

/**
* This activity demonstrates the various altitude modes available for markers on a 3D map.
Expand Down Expand Up @@ -92,7 +92,7 @@ class MarkersActivity : SampleBaseActivity() {
private var monsterMarkers: List<Marker> = emptyList()
private var monsterIds: List<String> = emptyList()
private var monsterLabels: List<String> = emptyList()

private var tourJob: kotlinx.coroutines.Job? = null

// The initial camera position is defined declaratively, providing a clear overview of
Expand Down Expand Up @@ -174,7 +174,7 @@ class MarkersActivity : SampleBaseActivity() {
}
}
}

findViewById<Button>(R.id.stop_button)?.apply {
setOnClickListener {
stopMonsterTour()
Expand All @@ -184,35 +184,39 @@ class MarkersActivity : SampleBaseActivity() {
lifecycleScope.launch(Dispatchers.Default) {
addMarkers(googleMap3D)
}

googleMap3D.setMap3DClickListener { _, _ ->
lifecycleScope.launch(Dispatchers.Main) {
activePopover?.remove()
activePopover = null

googleMap3D.setMap3DClickListener { _ ->
val hadActivePopover = activePopover != null
if (hadActivePopover) {
lifecycleScope.launch(Dispatchers.Main) {
activePopover?.remove()
activePopover = null
}
}
return@setMap3DClickListener hadActivePopover
}
}

private fun startMonsterTour() {
val stopButton = findViewById<Button>(R.id.stop_button)
val tourButton = findViewById<Button>(R.id.tour_monsters_button)
val map = googleMap3D ?: return

runOnUiThread {
stopButton?.visibility = View.VISIBLE
tourButton?.visibility = View.GONE
}

tourJob = lifecycleScope.launch(Dispatchers.Main) {
var i = 0
while (isActive) {
activePopover?.remove()
activePopover = null

val camera = monsterCameras[i]
val marker = monsterMarkers[i]
val monsterId = monsterIds[i]

// Fly to the monster
map.awaitCameraAnimation(flyToOptions {
endCamera = camera
Expand All @@ -232,9 +236,9 @@ class MarkersActivity : SampleBaseActivity() {
if (!isActive) break

showMonsterPopover(marker, getMonsterBlurbResId(monsterId), map)

delay(4.seconds)

i = (i + 1) % monsterCameras.size
}
}
Expand All @@ -246,7 +250,7 @@ class MarkersActivity : SampleBaseActivity() {
googleMap3D?.stopCameraAnimation()
googleMap3D?.setCameraAnimationEndListener(null)
googleMap3D?.setOnMapSteadyListener(null)

runOnUiThread {
findViewById<Button>(R.id.stop_button)?.visibility = View.GONE
findViewById<Button>(R.id.tour_monsters_button)?.visibility = View.VISIBLE
Expand Down Expand Up @@ -356,7 +360,7 @@ class MarkersActivity : SampleBaseActivity() {
autoCloseEnabled = true
autoPanEnabled = false
})

activePopover?.remove()
activePopover = newPopover
activePopover?.show()
Expand Down Expand Up @@ -408,12 +412,12 @@ class MarkersActivity : SampleBaseActivity() {
try {
val jsonString = assets.open("monsters.json").bufferedReader().use { it.readText() }
val parsedMonsters = MonsterParser.parse(jsonString)

val cameras = mutableListOf<Camera>()
val markers = mutableListOf<Marker>()
val ids = mutableListOf<String>()
val labels = mutableListOf<String>()

for (monster in parsedMonsters) {
val cam = camera {
center = latLngAltitude {
Expand All @@ -425,15 +429,15 @@ class MarkersActivity : SampleBaseActivity() {
tilt = monster.tilt
range = monster.range
}

val markerPos = latLngAltitude {
latitude = monster.markerLatitude
longitude = monster.markerLongitude
altitude = monster.markerAltitude
}

val drawableId = getMonsterDrawableId(monster.drawable)

if (drawableId != 0) {
val m = googleMap3D.addMarker(markerOptions {
position = markerPos
Expand All @@ -443,7 +447,7 @@ class MarkersActivity : SampleBaseActivity() {
this.altitudeMode = monster.altitudeMode
setStyle(ImageView(drawableId))
})

if (m != null) {
cameras.add(cam)
markers.add(m)
Expand Down
Loading
Loading