GMaps - Makers are not beeing removed on max zoom condition

asked 2023-09-03 07:38:30 +0800

MarcosFavaretto gravatar image MarcosFavaretto
103 2

updated 2023-09-03 07:44:38 +0800

Hello community!

Using icon in Gmaker I noticed that in one specific occasion, the icon continues to be displayed to the user, even after removing all child components of Gmaps.

I created a Fiddle so you can check the behavior. The link is present on comments section, since the Forum is not allowing me to post it on description.

Steps to reproduce:

  1. After run the fiddle provided, zoom in on the Java icon to the fullest.
  2. Hit the "Move Marker" button.
  3. Slowly zoom out until you see another icon rendered.

After the third step, you will be able to notice that the new Marker is being created on Gmaps as expected. Thus, the old one is not being removed correctly.

Note that this only happens when you render a new marker with the maximum zoom on the old one. To reproduce, you also need to provide a custom icon for gmarker instead of the default one.

I didn't find out why it happens or if I am doing something wrong. I would like to know if someone already fixed it or if there is any way to avoid that problem.

delete flag offensive retag edit


https://zkfiddle.org/sample/1b5jnh4/1-Gmaps-Markers-are-not-beeing-removed-after-change-lat-lng (Fiddle)

MarcosFavaretto ( 2023-09-03 07:42:53 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2023-10-25 18:39:56 +0800

MDuchemin gravatar image MDuchemin
2480 1 6
ZK Team

Hey there,

Bumped your karma to support links and images in future questions.

ALRIGHT this one is interesting :)

TL:DR and workaround:

Here's a script, it fixes this issue. You can put it in the zul page, or deploy globally with lang-addon:

    zk.afterLoad("gmaps", function () {
        var _xGmaps = {};
        zk.override(gmaps.Gmaps.prototype, _xGmaps, {
            _findMaxZoomLevel: function() {
                var types = this._gmaps.mapTypes;
                var mapsMaxZoom = 22;
                for (var type in types ) {
                    if (typeof types.get(type) === 'object' && typeof types.get(type).maxZoom === 'number') {
                        var zoom = types.get(type).maxZoom;
                        if (zoom > mapsMaxZoom) {
                            mapsMaxZoom = zoom;
                return mapsMaxZoom;


The Google maps library has a marker manager utility layer which manages markers. When the ZK Gmaps wrapper component initializes both the actual map object and the marker manager, ZK retrieves the maximum zoom level supported by the map from the google map object itself.

This used to be 19, but at some point has been modified to 22, but the internal function which retrieves this maximum zoom level doesn't actually find it on the map object for some reason.

As a result, the wrapper component initializes a marker manager with a max zoom of 19, even though the map actual max zoom is 22.

In turn, the marker manager will generate collections (layers) for each zoom level (from zoom 0 to zoom 19), and will automatically update, add and remove markers on these zoom levels.

This means that any operation done on a marker while the map is under zoom level 19 (zoom level 20, 21 and 22), will not be executed, and the marker object will also no longer be considered for destruction later on when the zoom level is back above the max level for the marker manager.

This means that under default settings, if you move a marker while zoom level is 20 or more, the marker is correctly moved in the abstract state, but the matching Marker Manager layer doesn't get updated because it doesn't have a layer for that marker.

Workaround above:

Modifies the default return value of the maximum zoom level expected by the gmaps wrapper component to 22 instead of 19.

This causes the marker manager to be created with layers 0 to 22 (instead of 0 to 19), and enables operations on these additional zoom levels which were not handled in the default case.

link publish delete flag offensive edit


I will post a bug ticket in a moment to have that be the default in future releases, will add the link here when done

MDuchemin ( 2023-10-25 18:40:44 +0800 )edit

I tested it on my scenario and works perfectly, thank you!!!

MarcosFavaretto ( 2023-10-25 21:55:18 +0800 )edit

Nice! good to hear ;) if the solution works for you, please mark the answer as accepted in case someone comes looking for it ;)

MDuchemin ( 2023-10-25 22:24:31 +0800 )edit

posted a bug ticket to include this in future release (link above)

MDuchemin ( 2023-10-25 22:24:47 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2023-09-03 07:38:30 +0800

Seen: 10 times

Last updated: Oct 25

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More