[Bug] MapTypeControl cannot switch from hybrid/satellite to roadmap when initialized with hybrid/satellite in 45° imagery areas
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- react, typescript
Línea de trabajo
Comienza con el manejo estático de mapTypeId del componente Map y con las rutas mapTypeId/onMapTypeIdChanged descritas en el informe. Reproduce el ejemplo mínimo en un área de imágenes de 45° y comprueba después si la reconciliación restaura el valor inicial; se considera terminado cuando el control nativo de Map puede cambiar de hybrid o satellite a roadmap sin volver atrás.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
When a map is initialized with mapTypeId="hybrid" or mapTypeId="satellite" and the user is viewing a location with 45° imagery available, clicking the "Map" button in the native mapTypeControl fails to switch to roadmap view.
The map briefly flickers (appears to attempt the switch) but immediately reverts back to hybrid/satellite view. This only occurs in areas where 45° imagery is available and at zoom levels where tilt is active.
Workarounds
Option 1: Controlled state with onMapTypeIdChanged
Using React state to manage mapTypeId and syncing it via onMapTypeIdChanged resolves the issue:
import { APIProvider, Map, type MapProps } from '@vis.gl/react-google-maps'
import { useState } from 'react'
const MAP_ID = 'YOUR_MAP_ID' // Must have vector maps enabled
function App() {
const [mapTypeId, setMapTypeId] = useState<MapProps['mapTypeId']>('hybrid')
return (
<APIProvider apiKey="YOUR_API_KEY">
<Map
style={{ width: '100%', height: '500px' }}
defaultCenter={{ lat: 48.8630, lng: 2.3622 }} // Paris 3e - has 45° imagery
defaultZoom={18}
mapTypeId={mapTypeId}
mapTypeControl
mapId={MAP_ID}
onMapTypeIdChanged={(event) => setMapTypeId(event.map.getMapTypeId())}
/>
</APIProvider>
)
}
Option 2: Initialize as roadmap and switch after mount
Initializing without mapTypeId prop and programmatically switching to hybrid after mount also works:
import { APIProvider, Map, useMap } from '@vis.gl/react-google-maps'
import { useEffect } from 'react'
const MAP_ID = 'YOUR_MAP_ID' // Must have vector maps enabled
const SwitchToHybridOnMount = () => {
const map = useMap()
useEffect(() => {
if (!map) return
const timer = setTimeout(() => {
map.setMapTypeId('hybrid')
}, 50)
return () => clearTimeout(timer)
}, [map])
return null
}
function App() {
return (
<APIProvider apiKey="YOUR_API_KEY">
<Map
style={{ width: '100%', height: '500px' }}
defaultCenter={{ lat: 48.8630, lng: 2.3622 }} // Paris 3e - has 45° imagery
defaultZoom={18}
// Note: mapTypeId prop must NOT be provided (even undefined won't work)
mapTypeControl
mapId={MAP_ID}
>
<SwitchToHybridOnMount />
</Map>
</APIProvider>
)
}
Observations
- ✅ Works: Initialize with
roadmaporterrain→ switch to hybrid → switch back to roadmap - ❌ Fails: Initialize with
hybridorsatellite→ cannot switch to roadmap (in 45° areas) - ✅ Works: Same scenario in non-45° areas (low zoom or locations without 45° imagery)
- ✅ Works: Native Google Maps API without react-google-maps wrapper (tested via Google's demo)
- ✅ Works: Using controlled state with
onMapTypeIdChangedto syncmapTypeId - ✅ Works: Not providing
mapTypeIdprop and switching viamap.setMapTypeId()after mount
Possible causes
- When
mapTypeIdis passed as a static prop, the library may be forcing it back to the initial value on every camera/tilt change event - The internal reconciliation between Google Maps state and React props seems to conflict with the automatic tilt behavior in 45° areas
- Using controlled state via
onMapTypeIdChangedallows the component to accept the new mapTypeId from Google Maps instead of reverting it - Not providing the
mapTypeIdprop at all lets Google Maps maintain full control over the map type state
Steps to Reproduce
- Initialize a map with
mapTypeId="hybrid"ormapTypeId="satellite"as a static prop (not via useState) - Navigate to a location with 45° imagery (e.g., Paris 3e Arrondissement)
- Zoom in until the 45° tilt view activates
- Click the "Map" button in the mapTypeControl
- Expected: Map switches to roadmap view
- Actual: Map flickers briefly then stays in hybrid/satellite view
Minimal reproduction
import { APIProvider, Map } from '@vis.gl/react-google-maps'
const MAP_ID = 'YOUR_MAP_ID' // Must have vector maps enabled
function App() {
return (
<APIProvider apiKey="YOUR_API_KEY">
<Map
style={{ width: '100%', height: '500px' }}
defaultCenter={{ lat: 48.8630, lng: 2.3622 }} // Paris 3e - has 45° imagery
defaultZoom={18}
mapTypeId="hybrid" // Bug occurs with static hybrid or satellite
mapTypeControl
mapId={MAP_ID}
/>
</APIProvider>
)
}
Environment
- Library version:
^1.7.1 - Google maps version:
3.62 - Browser and Version:
Firefox 147.0.1 - OS:
macOS Tahoe 26.2
Logs
As of version 3.62, Maps JavaScript API satellite and hybrid map types will no longer automatically switch to 45° Imagery at higher zoom levels. For more info, see https://developers.google.com/maps/deprecations
(I know it's outdated, but as long as it works, I'd like to use it)
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.9k
- Forks
- 195
- Merge medio
- 2 d 11 h
- PR fusionados (30 d)
- 14
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de visgl/react-google-maps
-
google maps issue
Dificultad 3/5 1-2 días Aptitud para principiantes 74/100
visgl/react-google-maps#1080 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
bug needs more info
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
visgl/react-google-maps#1039 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
visgl/react-google-maps#918 · 9 comentarios ·
Los mantenedores suelen responder en 2 días
-
google maps issue
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
visgl/react-google-maps#889 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
visgl/react-google-maps#884 · 1 comentario ·
Los mantenedores suelen responder en 2 días
Todos los issues de visgl/react-google-maps
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
automated issue report
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
github/copilot-sdk#2804 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
drizzle-team/drizzle-orm#6418 ·
Los mantenedores suelen responder en 4 días
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
diegosouzapw/OmniRoute#15307 · 1 comentario ·
Los mantenedores suelen responder en 2 días