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

Feature: Advanced Marker supports slot customization elements. #275

Open
coderwyd opened this issue Aug 21, 2024 · 4 comments · May be fixed by #308
Open

Feature: Advanced Marker supports slot customization elements. #275

coderwyd opened this issue Aug 21, 2024 · 4 comments · May be fixed by #308
Labels
feature request New feature

Comments

@coderwyd
Copy link

coderwyd commented Aug 21, 2024

The specific usage is as follows:
<AdvancedMarker :options="markerOptions"> <div>custom content</div> </AdvancedMarker >

@coderwyd coderwyd changed the title [FEATURE REQUEST]: Advanced Marker supports slot customization elements. Feature: Advanced Marker supports slot customization elements. Aug 21, 2024
@HusamElbashir HusamElbashir added the feature request New feature label Aug 21, 2024
@BenJackGill
Copy link

BenJackGill commented Sep 27, 2024

Yeah I agree. This would be great. Without a slot for custom content it's kind of useless for me now, so I have reverted back to the old CustomMarker for now with the annoying console warning.

@richgcook
Copy link

This would be a great feature request especially with the upcoming deprecation(s).

@BenJackGill
Copy link

Any movement on this one? I would try and do a pull request myself but I'm not skilled enough to figure it out :/

Until slots are supposed with custom content I am stuck using the CustomMarker which gives a console hefty console warning.

@sk8gear
Copy link

sk8gear commented Feb 9, 2025

There is a workaround to customize the AdvanceMarker by using "content" inside options. The key is to return a function to HtmlDivElement into the "content"

E.g:
map.vue

<script setup>
import { GoogleMap, AdvancedMarker } from 'vue3-google-map'

const pinOptions = { background: '#FBBC04' }

function content(){
 const content = document.createElement("div")
 content.innerHtml = "<h3>Here's the HTML element</h3>"
 return content
}
</script>

<template>
  <GoogleMap
    api-key="YOUR_GOOGLE_MAPS_API_KEY"
    mapId="DEMO_MAP_ID"
    style="width: 100%; height: 500px"
    :center="center"
    :zoom="15"
  >
    <AdvancedMarker :options="{ position: { lat: 40.689247, lng: -74.044502 }, content: content}" :pin-options="pinOptions"/>
  </GoogleMap>
</template>

If you want to use a Vue component so we can style it as we want, we can make it like this:

map.vue

<script setup>
import mapballon from './mapballon.vue'
import { GoogleMap, AdvancedMarker } from 'vue3-google-map'

const pinOptions = { background: '#FBBC04' }

function content(){
 // here's the code to return our mapballon.vue into HTMLElement
 return document.findElementbyId("mystyle")
}
</script>

<template>
  <GoogleMap
    api-key="YOUR_GOOGLE_MAPS_API_KEY"
    mapId="DEMO_MAP_ID"
    style="width: 100%; height: 500px"
    :center="center"
    :zoom="15"
  >
    <mapballon id="mymapballon" /> <!-- This would load up the mapballon component so that we can use this element inside our function above -->
    <AdvancedMarker :options="{ position: { lat: 40.689247, lng: -74.044502 }, content: content}" :pin-options="pinOptions"/>
  </GoogleMap>
</template>

mapballon.vue

<script setup>
// your code here
</script>
<template>
 <div class="mystyle">
   <h3>Here's the HTML element</h3>
 </div>
</template>
<style scope>
.mystyle{
  background: white;
}
</style>

But it'll be nice if we can have a cleaner way to handle the content.

@coderwyd coderwyd linked a pull request Feb 11, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants