diff --git a/samples/3d-marker-collision-behavior/index.html b/samples/3d-marker-collision-behavior/index.html index 0af4d003..c555747a 100644 --- a/samples/3d-marker-collision-behavior/index.html +++ b/samples/3d-marker-collision-behavior/index.html @@ -17,25 +17,16 @@ + ({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "beta",}); -
- - -
- REQUIRED: (default) Always display the marker regardless of collision.
- OPTIONAL_AND_HIDES_LOWER_PRIORITY: Display the marker only if it does not overlap with other markers. If two markers of this type would overlap, the one with the higher zIndex is shown. If they have the same zIndex, the one with the lower vertical screen position is shown.
- REQUIRED_AND_HIDES_OPTIONAL: Always display the marker regardless of collision, and hide any OPTIONAL_AND_HIDES_LOWER_PRIORITY markers or labels that would overlap with the marker.
-
-
- -
-
Select the marker collision method.
-
+ + + diff --git a/samples/3d-marker-collision-behavior/index.ts b/samples/3d-marker-collision-behavior/index.ts index 47d4692b..e205e724 100644 --- a/samples/3d-marker-collision-behavior/index.ts +++ b/samples/3d-marker-collision-behavior/index.ts @@ -6,59 +6,57 @@ // @ts-nocheck // [START maps_3d_marker_collision_behavior] -let map; - async function init() { - // Request needed libraries. - const { Map3DElement, Marker3DElement } = await google.maps.importLibrary("maps3d"); - - map = new Map3DElement({ - center: { lat: 47.6094, lng: -122.3390, altitude: 0 }, - range: 1000, - mode: 'HYBRID' - }); - - map.mode = "SATELLITE"; - let zindex = 0; - for (const [lng, lat] of positions) { - const marker = new Marker3DElement({ - position: { lat, lng }, - // Try setting a different collision behavior here. - collisionBehavior: google.maps.CollisionBehavior.REQUIRED, - drawsWhenOccluded : true, - zIndex : zindex++, - label: zindex.toString(), - }); - map.append(marker); - } - - const collisionSelect = document.getElementById('collisionSelect'); - collisionSelect.addEventListener('change', handleCollisionSelection); - document.body.append(map); - } - - function handleCollisionSelection() { - const selectedIndex = collisionSelect.selectedIndex; - for (const marker of map.getElementsByTagName("gmp-marker-3d")) { - marker.collisionBehavior = collisionSelect.value; - } - } - - const positions = [ - [-122.3402, 47.6093], - [-122.3402, 47.6094], - [-122.3403, 47.6094], - [-122.3384, 47.6098], - [-122.3389, 47.6095], - [-122.3396, 47.6095], - [-122.3379, 47.6097], - [-122.3378, 47.6097], - [-122.3396, 47.6091], - [-122.3383, 47.6089], - [-122.3379, 47.6093], - [-122.3381, 47.6095], - [-122.3378, 47.6095], - ]; - - init(); +const markers = []; + +async function init() { + // Request needed libraries. + const { Map3DElement, MapMode, Marker3DElement } = await google.maps.importLibrary("maps3d"); + + const map = new Map3DElement({ + center: { lat: 47.6094, lng: -122.3390, altitude: 0 }, + range: 1000, + mode: MapMode.HYBRID, + }); + + for (const [lng, lat] of positions) { + const marker = new Marker3DElement({ + position: {lat, lng}, + // Try setting a different collision behavior here. + collisionBehavior: google.maps.CollisionBehavior.REQUIRED + }); + + markers.push(marker) + map.append(marker); + } + + document.body.append(map); +} + +const positions = [ + [-122.3402, 47.6093], + [-122.3402, 47.6094], + [-122.3403, 47.6094], + [-122.3384, 47.6098], + [-122.3389, 47.6095], + [-122.3396, 47.6095], + [-122.3379, 47.6097], + [-122.3378, 47.6097], + [-122.3396, 47.6091], + [-122.3383, 47.6089], + [-122.3379, 47.6093], + [-122.3381, 47.6095], + [-122.3378, 47.6095], +]; + +init(); + +const dropdown = document.getElementById('selectElementId'); +dropdown.addEventListener('change', drawMap); + +function drawMap(event) { + for (const marker of markers) { + marker.collisionBehavior = dropdown.value || google.maps.CollisionBehavior.REQUIRED; + } +} // [END maps_3d_marker_collision_behavior] diff --git a/samples/3d-marker-collision-behavior/style.css b/samples/3d-marker-collision-behavior/style.css index a0e2d445..6dfc5e12 100644 --- a/samples/3d-marker-collision-behavior/style.css +++ b/samples/3d-marker-collision-behavior/style.css @@ -16,40 +16,8 @@ body { margin: 0; padding: 0; } -.textContainer { - background-color: #4d90fe; - box-shadow: 0 1px 4px -1px rgba(0, 0, 0, 0.3); - margin: 10px; - overflow: hidden; - position: absolute; - left: 50%; - bottom: 5px; - transform: translateX(-50%); - border: 1px solid white; - border-radius: 2px; - padding: 5px; - z-index: 1000; -} - -.detailsContainer { - background-color: #fff; - box-shadow: 0 1px 4px -1px rgba(0, 0, 0, 0.3); - margin: 10px; - font: 400 18px Roboto, Arial, sans-serif; - overflow: hidden; - position: absolute; - left: 50%; - bottom: 50px; - transform: translateX(-50%); - border: 2px solid #4d90fe; - border-radius: 2px; - padding: 5px; - z-index: 1000; -} - -.text { - color: white; - font-size: 1em; - text-align: center; -} +selector { + padding: 2px; + float: right; +} /* [END maps_3d_marker_collision_behavior] */