Full Disclosure, this issue was identified and written by AI.
Alternate title the AI wanted: geofieldMapInit can fire before async marker icon preload finishes, allowing default marker icons to overwrite integration updates (But it's human thought that was too wordy).
Problem/Motivation
In the Google Maps formatter, marker icons from GeoJSON properties.icon are not applied when the marker is created. Instead, place_feature() calls checkImage(), which creates a separate Image object and applies the icon in img.onload.
Because that preload callback is independent of the map initialization lifecycle, geofieldMapInit may be triggered before all marker icon callbacks have completed. Third-party/theme code that listens for geofieldMapInit and updates marker icons can then be overwritten later by Geofield Map’s pending img.onload callback.
This creates nondeterministic marker state. It depends on browser cache, image load timing, Google Maps idle timing, and script execution order.
Steps to reproduce
- Configure a Geofield Google Map View with a marker icon path or theming plugin so each feature has properties.icon.
- Add custom JS that listens for geofieldMapInit (example proof of concept below).
- In that handler, call marker.setIcon('/some-dynamic-icon.png') based on client-side state.
- Throttle image loading or use an uncached icon URL for the module-configured icon.
- Observe that the custom icon is sometimes replaced by the module-configured icon after geofieldMapInit.
Actual result:
A marker icon set by integration code after geofieldMapInit can be overwritten by Geofield Map’s later Image.onload callback.
Expected result:
After geofieldMapInit, markers should be stable for integrations, or the module should provide a separate event that fires after marker icons have finished resolving. The module should not asynchronously overwrite marker icon changes made by consumers after initialization.
Proof of Concept
I've set up a proof of concept demonstration in a repo in my GitHub: johnbburg/geofield_map-race-condition-poc
Which can be views in GitHub pages here.
While it's not literally the code from the module, this is a close approximation, this also provides an example of the fixed version.
Proposed resolution
Here are some ideas the agent suggested:
- Apply marker icons synchronously during marker construction instead of deferring through Image.onload.
- Or make icon preloading part of the initialization lifecycle and trigger geofieldMapInit only after icon preload callbacks have settled.
- Or add a dedicated geofieldMapMarkersReady / geofieldMapIconsReady event.
- At minimum, the Image.onload callback could avoid overwriting the marker if marker.getIcon() has changed since the preload was scheduled (attached patch handles this).
Remaining tasks
None
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| geofield-map-marker-icon-race-condition.patch | 875 bytes | bburg |
Comments
Comment #2
bburg