|
|
@@ -19,6 +19,7 @@ export default function MapView() {
|
|
|
const { user, isLoading } = useAuth()
|
|
|
const [places, setPlaces] = useState<Place[]>([])
|
|
|
const [selectedPlace, setSelectedPlace] = useState<Place | null>(null)
|
|
|
+ const [mapError, setMapError] = useState(false)
|
|
|
|
|
|
const fetchPlaces = useCallback(async (bounds?: MapBounds) => {
|
|
|
if (!user) return
|
|
|
@@ -45,18 +46,26 @@ export default function MapView() {
|
|
|
if (!containerRef.current || mapRef.current) return
|
|
|
|
|
|
const provider = createYandexMapProvider()
|
|
|
- provider.init(containerRef.current, [37.6173, 55.7558], 10)
|
|
|
mapRef.current = provider
|
|
|
|
|
|
- if (navigator.geolocation) {
|
|
|
- navigator.geolocation.getCurrentPosition(
|
|
|
- (pos) => provider.setCenter(pos.coords.latitude, pos.coords.longitude),
|
|
|
- () => {},
|
|
|
- )
|
|
|
- }
|
|
|
+ provider.init(containerRef.current, [37.6173, 55.7558], 10).then(() => {
|
|
|
+ if (!provider.isReady()) {
|
|
|
+ setMapError(true)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (navigator.geolocation) {
|
|
|
+ navigator.geolocation.getCurrentPosition(
|
|
|
+ (pos) => provider.setCenter(pos.coords.latitude, pos.coords.longitude),
|
|
|
+ () => {},
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
- provider.onMove((center, zoom, bounds) => {
|
|
|
- fetchPlacesRef.current(bounds)
|
|
|
+ provider.onMove((center, zoom, bounds) => {
|
|
|
+ fetchPlacesRef.current(bounds)
|
|
|
+ })
|
|
|
+ }).catch(() => {
|
|
|
+ setMapError(true)
|
|
|
})
|
|
|
|
|
|
return () => {
|
|
|
@@ -66,9 +75,8 @@ export default function MapView() {
|
|
|
}, [])
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (!mapRef.current) return
|
|
|
-
|
|
|
const provider = mapRef.current
|
|
|
+ if (!provider || !provider.isReady()) return
|
|
|
|
|
|
places.forEach((place) => {
|
|
|
provider.addMarker(place.id, place.lat, place.lng, {
|
|
|
@@ -86,8 +94,8 @@ export default function MapView() {
|
|
|
const { visitors } = useWebSocket(!user)
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (!mapRef.current) return
|
|
|
const provider = mapRef.current
|
|
|
+ if (!provider || !provider.isReady()) return
|
|
|
|
|
|
visitors.forEach((v, i) => {
|
|
|
provider.addMarker(`ws-visitor-${i}`, v.lat, v.lng, { type: 'visitor' })
|
|
|
@@ -100,9 +108,18 @@ export default function MapView() {
|
|
|
|
|
|
return (
|
|
|
<div className="relative h-full w-full">
|
|
|
- <div ref={containerRef} className="h-full w-full" />
|
|
|
+ {mapError ? (
|
|
|
+ <div className="flex h-full w-full items-center justify-center">
|
|
|
+ <div className="text-center">
|
|
|
+ <p className="mb-2 text-lg text-white/60">Карта временно недоступна</p>
|
|
|
+ <p className="text-sm text-white/40">Попробуйте обновить страницу позже</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ ) : (
|
|
|
+ <div ref={containerRef} className="h-full w-full" />
|
|
|
+ )}
|
|
|
|
|
|
- {!user && !isLoading && (
|
|
|
+ {!user && !isLoading && !mapError && (
|
|
|
<div className="absolute left-1/2 top-4 z-10 -translate-x-1/2 rounded-lg bg-white/10 px-6 py-3 text-center text-white backdrop-blur-md">
|
|
|
<p className="text-sm">Зарегистрируйтесь, чтобы исследовать места для фотосъёмок</p>
|
|
|
</div>
|