Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google-maps: After adding transparency all the way through...only have black empty space all around the map. #2109

Open
askilondz opened this issue May 20, 2024 · 2 comments

Comments

@askilondz
Copy link

Bug Report

Plugin(s)

@capacitor/google-maps

Platform(s)

Android

Current Behavior

Added transparency per docs to html, body ion-content and any other parent elements that the google-maps element is nested in. I can see the map. The issue is we are stuck with a solid black background around the map and no way to style the underlying divs because everything has to be transparent.

How else can we work around this so the map doesn't just look like it's floating on a black abyss of empty space?

@tafelnl
Copy link
Contributor

tafelnl commented Jun 10, 2024

You should probably just add elements (which then do have a background) around the area/div the map is displayed in. So you could add a header above it, a footer below it and just add some empty divs to the left and right

@matboccardo
Copy link

Hi, I have the same problem. Were you able to fix it? I'm using Vite 6, Capacitorjs 7 and ChakraUI V3. On the web I can see it fine, but on Android it looks like a floating map, and when I do the "destroy" my screen goes black.

Any ideas?

Image
Image

Code:
`import { useParams } from 'react-router-dom';
import { useEffect, useRef } from 'react';
import { GoogleMap } from '@capacitor/google-maps';
import { GOOGLE_API_KEY } from '@/apis';
import { Box } from '@chakra-ui/react';

const FarmDetails = () => {
const { id } = useParams<{ id: string }>();
const mapRef = useRef<HTMLElement | null>(null);
let map: GoogleMap | null = null;

useEffect(() => {
    async function loadMap() {
        if (!mapRef.current) return;

        map = await GoogleMap.create({
            id: 'farm-map',
            element: mapRef.current,
            apiKey: GOOGLE_API_KEY,
            config: {
                center: { lat: 37.422, lng: -122.084 },
                zoom: 14,
            },
        });

        await map.addPolygons([
            {
                paths: [
                    { lat: 37.422, lng: -122.084 },
                    { lat: 37.422, lng: -122.090 },
                    { lat: 37.428, lng: -122.090 },
                    { lat: 37.428, lng: -122.084 },
                ],
                strokeColor: "#FF0000",
                strokeOpacity: 1.0,
                strokeWeight: 2,
                fillColor: "#FF0000",
                fillOpacity: 0.3,
            },
        ]);
    }

    loadMap();

    return () => {
        if (map) {
            map.destroy();
        }
    };
}, []);

return (
    <Box>
        <h1>Detalles del Farm</h1>
        <p>ID: {id}</p>
        <capacitor-google-map
            id="map"
            ref={mapRef}
            style={{
                display: 'inline-block',
                width: '100%',
                height: '400px'
            }}
        />
        <a href="/farms">Volver a la lista</a>
    </Box>
);

};

export default FarmDetails;`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants