summaryrefslogtreecommitdiff
path: root/ab_openstreetmap/static/src/js/openstreetmap_widget.js
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2025-06-13 08:06:50 +0000
committerIT Fixcomart <it@fixcomart.co.id>2025-06-13 08:06:50 +0000
commit655512eee7016f2e321b9994455f87a4c8e91884 (patch)
tree361752527dde4be9c136f37a97ebec80f5dbfe4d /ab_openstreetmap/static/src/js/openstreetmap_widget.js
parent8ac5d556a6686c6b81d5e9178bff5d308e8f176f (diff)
parent80355d9de0d079ec2f1004efac0377b8c4bfa0eb (diff)
Merged in try-gmaps (pull request #333)
Try gmaps
Diffstat (limited to 'ab_openstreetmap/static/src/js/openstreetmap_widget.js')
-rw-r--r--ab_openstreetmap/static/src/js/openstreetmap_widget.js106
1 files changed, 0 insertions, 106 deletions
diff --git a/ab_openstreetmap/static/src/js/openstreetmap_widget.js b/ab_openstreetmap/static/src/js/openstreetmap_widget.js
deleted file mode 100644
index c84a2293..00000000
--- a/ab_openstreetmap/static/src/js/openstreetmap_widget.js
+++ /dev/null
@@ -1,106 +0,0 @@
-odoo.define("ab_openstreetmap.openstreetmap_widget", function (require) {
- "use strict";
-
- const fieldRegistry = require("web.field_registry");
- const AbstractField = require("web.AbstractField");
-
- const OpenStreetMapWidget = AbstractField.extend({
- template: "openstreetmap_template",
-
- start: function () {
- const self = this;
- return this._super.apply(this, arguments).then(() => {
- setTimeout(() => {
- self._renderMapWhenReady();
- }, 100);
- });
- },
-
- _renderMapWhenReady: function () {
- const self = this;
- const check = () => {
- const container = document.getElementById("mapid");
- if (container && container.offsetWidth > 0 && container.offsetHeight > 0) {
- self._initMap();
- } else {
- setTimeout(check, 100);
- }
- };
- check();
- },
-
- _initMap: function () {
- const self = this;
- const container = document.getElementById("mapid");
-
- // Bersihkan Leaflet instance sebelumnya jika ada
- if (container && container._leaflet_id) {
- container._leaflet_id = null;
- }
-
- let lat = self.recordData.latitude;
- let lng = self.recordData.longtitude;
-
- if (!lat && !lng) {
- lat = -6.2349;
- lng = 106.9896;
- }
-
- const map = L.map("mapid").setView([lat, lng], 13);
-
- L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
- attribution:
- '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
- }).addTo(map);
-
- const edit = self.mode === "edit";
- const marker = L.marker([lat, lng], { draggable: edit }).addTo(map);
-
- // Simpan koordinat saat marker digeser
- marker.on("dragend", function (e) {
- const latlng = e.target._latlng;
- self.trigger_up("field_changed", {
- dataPointID: self.dataPointID,
- changes: {
- latitude: latlng.lat.toString(),
- longtitude: latlng.lng.toString(),
- },
- viewType: self.viewType,
- });
- });
-
- // Fitur cari lokasi (geocoder)
- if (edit) {
- const geocode = L.Control.geocoder({ defaultMarkGeocode: false }).addTo(map);
- geocode.on("markgeocode", function (e) {
- const lat = e.geocode.center.lat;
- const lng = e.geocode.center.lng;
- map.flyTo([lat, lng]);
- marker.setLatLng(new L.LatLng(lat, lng));
- self.trigger_up("field_changed", {
- dataPointID: self.dataPointID,
- changes: {
- latitude: lat.toString(),
- longtitude: lng.toString(),
- },
- viewType: self.viewType,
- });
- });
- }
-
- // Force render ulang map
- const interval = setInterval(() => {
- if (map && map._size.x > 0) {
- clearInterval(interval);
- }
- window.dispatchEvent(new Event("resize"));
- }, 500);
- },
-
- isSet: function () {
- return true;
- },
- });
-
- fieldRegistry.add("openstreetmap", OpenStreetMapWidget);
-});