Issue
-
When using a Geolocation field in a Web Content Structure and displaying it from the template on a page using the
map-displaytag, the location marker is draggable by end-users. -
You must make the marker static and prevent visitors from moving it.
Environment
- Liferay DXP 2025.Q1
Resolution
The ability for users to drag the marker is the default and expected behavior for both OpenStreetMaps and Google Maps, as the draggable attribute is set to true in the component's implementation. To override this functionality and disable dragging for an OpenStreetMap marker, you can implement a custom JavaScript workaround. Complete the following steps:
-
Identify the map's name in your template (e.g.,
contactGeolocation). -
Add the following proof-of-concept script to the page or theme to disable dragging:
(function() { var mapDiv = document.querySelector('[id$="contactGeolocationMap"]'); if (!mapDiv) { console.log('[disable-marker-dragging] Map div not found'); return; } var registeredName = mapDiv.id.slice(0, -3); // remove the final 'Map' Liferay.componentReady(registeredName).then(function(map) { console.log('[map-disable-dragging] Component ready'); map.on('positionChange', function onReady() { console.log('[disable-marker-dragging] positionChange fired'); map.off('positionChange', onReady); var marker = map._geolocationMarker && map._geolocationMarker._nativeMarker; if (!marker) { console.log('[disable-marker-dragging] nativeMarker not found'); return; } marker.dragging.disable(); console.log('[disable-marker-dragging] Dragging disabled'); }); }); })();