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: GmapCluster - Allow passing options to MarkererClusterer #255

Closed
alisspers opened this issue Feb 22, 2022 · 17 comments · Fixed by #257
Closed

Feature: GmapCluster - Allow passing options to MarkererClusterer #255

alisspers opened this issue Feb 22, 2022 · 17 comments · Fixed by #257
Assignees
Labels
bug Something isn't working released solved The problem presented is considered solved and the issue closed
Projects

Comments

@alisspers
Copy link

alisspers commented Feb 22, 2022

Is your feature request related to a problem? Please describe.

The GmapCluster component works great but doesn't allow customizing the end result. Specifically, we'd like to change the colors of the cluster icons to follow our site's color palette.

Describe the solution you'd like

A way to pass in the options allowed by MarkerClusterer to the GmapCluster component. We probably need the renderer option for our use case but all options would probably be good to support.

Describe alternatives you've considered

None other than trying to pass in an :options prop to GmapCluster and setting renderer there, but with no luck.

Additional context

Using an old version of gmap-vue (which used the markererplus package), we leveraged custom png:s for the cluster icons to achieve the following:

old version

With the new version we get this result (which is functionally OK but not as good looking when seen in the context of our website):

new version

@alisspers alisspers added the feature requested A new feature requested for the community label Feb 22, 2022
@diegoazh
Copy link
Owner

diegoazh commented Mar 1, 2022

Hi @alisspers did you try with the options prop? with that option you can set the properties of Google Map objects that we didn't map to Vue props. I mean for example with the InfoWindow component before v3.4.3 we didn't have a content prop but you could set it using the options prop like below

<template>
    <gmap-map :center="center" :zoom="15" style="width: 100%; height: 500px">
      <gmap-info-window
        :content="newOptionContent"
        :options="{
          content: 'this is my info window content',
        }"
        :position="infoWindowPos"
        :opened="infoWinOpen"
        @closeclick="infoWinOpen = false"
      ></gmap-info-window>

      <gmap-marker
        :key="i"
        v-for="(m, i) in markers"
        :position="m.position"
        :clickable="true"
        @click="() => toggleInfoWindow(m, i)"
      ></gmap-marker>
    </gmap-map>
<template>

Please can you try with the option prop first and let me know if that prop doesn't allow you to set the render property of MarkerClusterer.

@alisspers
Copy link
Author

alisspers commented Mar 2, 2022

Yes, I tried that already (I think). This is what I tried, which doesn't seem to make any difference:

<GmapCluster :options="clusterOptions">
<!-- ... -->
</GmapCluster>

And clusterOptions looks like this (renderer copied from Googles examples):

       clusterOptions() {
            return {
                renderer: ({ count, position }) =>
                    new google.maps.Marker({
                        label: { text: String(count), color: 'white', fontSize: '10px' },
                        position,
                        // adjust zIndex to be above other markers
                        zIndex: Number(google.maps.Marker.MAX_ZINDEX) + count,
                    }),
            };
        },

I looked closer at the source code here. In this part of cluster-icon.vue, it seems like the only options being propagated to the MarkerClusterer are map and markers, right?

@diegoazh
Copy link
Owner

diegoazh commented Mar 2, 2022

Try to execute the function because the prop expects a litteral object not a function reference, I mean

<GmapCluster :options="clusterOptions()">
<!-- ... -->
</GmapCluster>

@alisspers
Copy link
Author

Thanks for getting back! Sorry, I forgot to mention that I had "clusterOptions" as a computed property in my example above.
I've also tried having it in a data property (plaing object) as well as hardcoding it into <GmapCluster :options="{ renderer: ... }">. No luck I'm afraid.

Did you take a look at those lines of code I linked? L58-L63 in cluster-icon.vue
It seems to me that not the whole options object is passed, just map & markers?

@diegoazh
Copy link
Owner

diegoazh commented Mar 3, 2022

@alisspers you're right, I'll fix it right now.

@diegoazh diegoazh self-assigned this Mar 3, 2022
@create-issue-branch
Copy link

@diegoazh diegoazh added this to To do in gmap-vue via automation Mar 3, 2022
@diegoazh diegoazh added bug Something isn't working WIP work in progress and removed feature requested A new feature requested for the community waiting for feedback labels Mar 3, 2022
gmap-vue automation moved this from To do to Done Mar 3, 2022
github-actions bot pushed a commit that referenced this issue Mar 3, 2022
## [3.4.5](v3.4.4...v3.4.5) (2022-03-03)

### Bug Fixes

* **gmap-vue:** add missing options on marker-clusterer constructor ([7b4d573](7b4d573)), closes [#255](#255)
@github-actions
Copy link

github-actions bot commented Mar 3, 2022

🎉 This issue has been resolved in version 3.4.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@diegoazh
Copy link
Owner

diegoazh commented Mar 3, 2022

@alisspers can you test the new version and confirm if this component is working as expected?

@diegoazh diegoazh added waiting for feedback and removed WIP work in progress labels Mar 3, 2022
@alisspers
Copy link
Author

It didn't, but I've found another bug that causes it not to work. The prop specification states "algorithm" instead of "options" for the prop name: https://github.com/diegoazh/gmap-vue/blob/master/packages/gmap-vue/src/components/cluster-icon.vue#L93-L100

I changed that locally and tried again, then it works!

@diegoazh
Copy link
Owner

diegoazh commented Mar 3, 2022

🤦 you're right again. My bad 🙇‍♂️.

@diegoazh
Copy link
Owner

diegoazh commented Mar 3, 2022

@alisspers finally I added the options prop but also render and onClusterClick props were added too on new v3.5.1. Thanks again and let me know if it's working now.

@diegoazh diegoazh added solved The problem presented is considered solved and the issue closed and removed waiting for feedback labels Mar 9, 2022
@Anjgpt
Copy link

Anjgpt commented Mar 23, 2022

@alisspers does this work for you? I'm passing options and not able to apply the custom style.

<gmap-cluster
      :options="clusterOptions()"
    >
...
</gmap-cluster>
clusterOptions() {
      return {
        renderer: ({ count, position }) => new google.maps.Marker({
          label: { text: String(count), color: 'white', fontSize: '10px' },
          icon: VesselCluster,
          position,
          // adjust zIndex to be above other markers
          zIndex: Number(google.maps.Marker.MAX_ZINDEX) + count,
        }),
      };
    },

getting this error Uncaught TypeError: this.renderer.render is not a function

@alisspers
Copy link
Author

@diegoazh sorry I forgot to update you here – it works great for me now. Really appreciate your work and your quick response to my issue.

@Anjgpt the "renderer" option must be an object. In your case, it should be a plain JS object with a method called "render". Then it works!
Like this:

    clusterOptions() {
            return {
                renderer: {
                    render: ({ count, position }) => new google.maps.Marker({
                        label: { text: String(count), color: 'white', fontSize: '10px' },
                        icon: VesselCluster,
                        position,
                        // adjust zIndex to be above other markers
                        zIndex: Number(google.maps.Marker.MAX_ZINDEX) + count,
                    }),
                },
            };
        }

@Anjgpt
Copy link

Anjgpt commented Mar 23, 2022

Thanks, @alisspers for the quick response really appreciate it. It works now.

@jesscostello
Copy link

Should the changes above allow setting options on the cluster object or just allow adding rendering options? I have tried adding options to the cluster object but they don't seem to be picked up at all
<gmap-cluster :options="{ minPoints: 2, maxZoom 10, }">

@diegoazh
Copy link
Owner

In that case, we only added the renderer option to the defined props @jesscostello, on the other hand, the way you are using the options prop is correct; finally, I strongly recommend moving to the new version of this plugin for Vue 3, in that version we defined all cluster options as available props on the component.

@jesscostello
Copy link

@diegoazh thanks for confirming! In this case unfortunately the project I was working on had to stick on Vue 2 for the time being

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released solved The problem presented is considered solved and the issue closed
Projects
No open projects
gmap-vue
  
Done
Development

Successfully merging a pull request may close this issue.

4 participants