diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-06-17 08:47:53 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-06-17 08:47:53 +0700 |
| commit | a80565682063e718fc55c90e4243b9d5b2432285 (patch) | |
| tree | bd3b65cc54b62a8994bafb5d38c25631888d6414 /ab_openstreetmap/static | |
| parent | a8460239603b7a73a185fec394b0f95ab0247207 (diff) | |
(andri) fix load gmaps pada view & edit
Diffstat (limited to 'ab_openstreetmap/static')
| -rw-r--r-- | ab_openstreetmap/static/src/js/googlemap_widget.js | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/ab_openstreetmap/static/src/js/googlemap_widget.js b/ab_openstreetmap/static/src/js/googlemap_widget.js index 1728fa54..6471be0b 100644 --- a/ab_openstreetmap/static/src/js/googlemap_widget.js +++ b/ab_openstreetmap/static/src/js/googlemap_widget.js @@ -13,30 +13,23 @@ odoo.define("ab_openstreetmap.googlemap_widget", function (require) { this._waitForMapReady(); }, + on_attach_callback: function () { + this._waitForMapReady(); // Trigger ulang saat widget dimunculkan + }, + _waitForMapReady: function () { const mapEl = document.getElementById("mapid"); if (mapEl && mapEl.offsetWidth > 0 && mapEl.offsetHeight > 0) { this._loadGoogle(); } else { - setTimeout(() => this._waitForMapReady(), 100); + setTimeout(() => this._waitForMapReady(), 300); // Tambah jeda untuk mode edit/tab } }, async _loadGoogle() { - // const apiKey = await rpc.query({ - // model: "ir.config_parameter", - // method: "get_param", - // args: ["google.maps.api_key"], - // }); - // const mapId = await rpc.query({ - // model: "ir.config_parameter", - // method: "get_param", - // args: ["google.maps.map_id"], - // }); - - const apiKey = "AIzaSyB7bG9aSNAJnSrj0Z7f1abFsqKVoiJfsPE"; // Ganti dengan API Key Anda - const mapId = "1af072c8d80a2adec8057f34"; - // Ganti dengan Map ID Anda + const apiKey = "AIzaSyB7bG9aSNAJnSrj0Z7f1abFsqKVoiJfsPE"; // Ganti sesuai kebutuhan + const mapId = "1af072c8d80a2adec8057f34"; // Ganti sesuai kebutuhan + if (!window.google || !window.google.maps) { const script = document.createElement("script"); script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&v=weekly&libraries=places,marker`; @@ -57,6 +50,7 @@ odoo.define("ab_openstreetmap.googlemap_widget", function (require) { if (!mapEl) return; mapEl.style.position = "relative"; + mapEl.style.minHeight = "400px"; // Pastikan map tidak collapse const { Map } = await google.maps.importLibrary("maps"); const { AdvancedMarkerElement } = await google.maps.importLibrary("marker"); @@ -67,6 +61,12 @@ odoo.define("ab_openstreetmap.googlemap_widget", function (require) { mapId: mapId || undefined, }); + // Trigger resize untuk menangani kasus map awalnya hidden + setTimeout(() => { + google.maps.event.trigger(map, "resize"); + map.setCenter({ lat, lng }); // Reset ulang posisi setelah resize + }, 300); + const marker = new AdvancedMarkerElement({ map, position: { lat, lng }, @@ -100,7 +100,6 @@ odoo.define("ab_openstreetmap.googlemap_widget", function (require) { `; mapEl.appendChild(input); - // Gunakan Autocomplete klasik (deprecated tapi stabil) const autocomplete = new google.maps.places.Autocomplete(input); autocomplete.addListener("place_changed", () => { const place = autocomplete.getPlace(); |
