I tested it on my scenario and works perfectly, thank you!!!
MarcosFavaretto ( 2023-10-25 21:55:18 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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:
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.
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:
<script><![CDATA[
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;
}
});
});
]]></script>
details
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.
I tested it on my scenario and works perfectly, thank you!!!
MarcosFavaretto ( 2023-10-25 21:55:18 +0800 )editAsked: 2023-09-03 07:38:30 +0800
Seen: 10 times
Last updated: Oct 25
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