diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-06-13 09:27:25 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-06-13 09:27:25 +0700 |
| commit | 9df666030d1e3a4bd1293e96122f1df8611f1cd4 (patch) | |
| tree | 5ced896f025a5426c7ae86202a939ac30a1c3d1f /ab_openstreetmap/static | |
| parent | 34759639fa2db3b28bac410e24984775ce823ac5 (diff) | |
(andri) fix edit maps
Diffstat (limited to 'ab_openstreetmap/static')
| -rw-r--r-- | ab_openstreetmap/static/src/js/googlemap_widget.js | 47 | ||||
| -rw-r--r-- | ab_openstreetmap/static/src/xml/googlemap_template.xml | 3 |
2 files changed, 23 insertions, 27 deletions
diff --git a/ab_openstreetmap/static/src/js/googlemap_widget.js b/ab_openstreetmap/static/src/js/googlemap_widget.js index 61708486..f8cafb4b 100644 --- a/ab_openstreetmap/static/src/js/googlemap_widget.js +++ b/ab_openstreetmap/static/src/js/googlemap_widget.js @@ -10,19 +10,20 @@ odoo.define("ab_openstreetmap.googlemap_widget", function (require) { start: async function () { await this._super(...arguments); - const apiKey = await rpc.query({ - model: "ir.config_parameter", - method: "get_param", - args: ["google.maps.api_key"], - }); - this._waitForElement("#mapid", () => { + + this._waitForElement("#mapid", async () => { + const apiKey = await rpc.query({ + model: "ir.config_parameter", + method: "get_param", + args: ["google.maps.api_key"], + }); this._loadGoogleMaps(apiKey); }); }, _waitForElement: function (selector, callback) { const el = document.querySelector(selector); - if (el) { + if (el && el.offsetHeight > 0 && el.offsetWidth > 0) { callback(); } else { setTimeout(() => this._waitForElement(selector, callback), 100); @@ -32,20 +33,17 @@ odoo.define("ab_openstreetmap.googlemap_widget", function (require) { _loadGoogleMaps: function (apiKey) { if (!window.google || !window.google.maps) { const script = document.createElement("script"); - // script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=marker`; - script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&v=beta&libraries=marker,maps`; + script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&v=weekly`; script.async = true; script.defer = true; - script.onload = async () => { - await this._initMap(); - }; + script.onload = () => this._initMap(); document.head.appendChild(script); } else { this._initMap(); } }, - _initMap: async function () { + _initMap: function () { const lat = parseFloat(this.recordData.latitude) || -6.2; const lng = parseFloat(this.recordData.longtitude) || 106.816666; const edit = this.mode === "edit"; @@ -53,31 +51,28 @@ odoo.define("ab_openstreetmap.googlemap_widget", function (require) { const mapEl = document.getElementById("mapid"); if (!mapEl) return; - // ✅ Load required Google Maps libraries dynamically - const { Map } = await google.maps.importLibrary("maps"); - const { AdvancedMarkerElement } = await google.maps.importLibrary("marker"); + // Bersihkan inner map jika sudah pernah load sebelumnya + mapEl.innerHTML = ""; - const map = new Map(mapEl, { + const map = new google.maps.Map(mapEl, { center: { lat, lng }, zoom: 15, - mapId: "DEMO_MAP_ID", // optional, ganti kalau punya map ID khusus }); - const marker = new AdvancedMarkerElement({ - map, + const marker = new google.maps.Marker({ position: { lat, lng }, - title: "Lokasi", - gmpDraggable: edit, + map, + draggable: edit, }); if (edit) { - marker.addListener("dragend", () => { - const pos = marker.position; + marker.addListener("dragend", (e) => { + const pos = e.latLng; this.trigger_up("field_changed", { dataPointID: this.dataPointID, changes: { - latitude: pos.lat.toString(), - longtitude: pos.lng.toString(), + latitude: pos.lat().toString(), + longtitude: pos.lng().toString(), }, viewType: this.viewType, }); diff --git a/ab_openstreetmap/static/src/xml/googlemap_template.xml b/ab_openstreetmap/static/src/xml/googlemap_template.xml index 3a80a4f2..53aef261 100644 --- a/ab_openstreetmap/static/src/xml/googlemap_template.xml +++ b/ab_openstreetmap/static/src/xml/googlemap_template.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <templates id="template" xml:space="preserve"> <t t-name="googlemap_template"> - <div id="mapid" style="height: 400px; width: 100%;"></div> + <!-- <div id="mapid" style="height: 400px; width: 100%;"></div> --> + <div t-attf-id="mapid" style="height: 400px; width: 100%;" ></div> </t> </templates> |
