gityopie / odoo-addons

Odoo and Google maps integration
GNU Lesser General Public License v3.0
100 stars 159 forks source link

Error starting the map view on all forms in Odoo 12.0 TypeError: Cannot read property 'equals' of undefined #177

Open schinto777 opened 3 years ago

schinto777 commented 3 years ago

Hello When starting the map view, on all forms in Odoo 12.0, there is an error:

Error: Uncaught TypeError: Cannot read property 'equals' of undefined

https://dh.test.pl/web/content/871-a9192dd/web.assets_backend.js:3250 Traceback: TypeError: Cannot read property 'equals' of undefined at https://dh.test.pl/web/content/871-a9192dd/web.assets_backend.js:3250:358 at Array.forEach () at Class._clusterAddMarker (https://dh.test.pl/web/content/871-a9192dd/web.assets_backend.js:3250:275) at Class._createMarker [as _super] (https://dh.test.pl/web/content/871-a9192dd/web.assets_backend.js:3250:75) at Class._createMarker (https://dh.test.pl/web/content/871-a9192dd/web.assets_backend.js:3323:528) at Class._createMarker (https://dh.test.pl/web/content/521-1cebeb7/web.assets_common.js:3541:371) at https://dh.test.pl/web/content/871-a9192dd/web.assets_backend.js:3252:1674 at Function..each..forEach (https://dh.test.pl/web/content/521-1cebeb7/web.assets_common.js:12:558) at Class._renderUngrouped (https://dh.test.pl/web/content/871-a9192dd/web.assets_backend.js:3252:1488) at Class._renderMarkers (https://dh.test.pl/web/content/871-a9192dd/web.assets_backend.js:3252:941)

The error probably appeared after updating your add-on. Please help

gityopie commented 3 years ago

@schinto777 looks like the variable value on this line https://github.com/gityopie/odoo-addons/blob/12.0/web_google_maps/static/src/js/view/map/map_renderer.js#L315

var position = marker.getPosition();

assigned invalid value, normally marker is an instance of class google.maps.Marker. could you please console this variable?

schinto777 commented 3 years ago

Thank you very much for such a quick reply. Even if I have any one contact on the list, pressing the map button causes an error. He's different: Uncaught TypeError: Cannot read property 'getSouthWest' of undefined https://dh.test.pl/web_google_maps/static/lib/markercluster/markerclusterer.js:797 Traceback: TypeError: Cannot read property 'getSouthWest' of undefined at MarkerClusterer.createClusters_ (https://dh.test.pl/web_google_maps/static/lib/markercluster/markerclusterer.js:797:69) at MarkerClusterer.redraw (https://dh.test.pl/web_google_maps/static/lib/markercluster/markerclusterer.js:724:8) at MarkerClusterer.addMarker (https://dh.test.pl/web_google_maps/static/lib/markercluster/markerclusterer.js:454:10) at Class._clusterAddMarker (https://dh.test.pl/web/content/957-a9192dd/web.assets_backend.js:3251:20) at Class._createMarker [as _super] (https://dh.test.pl/web/content/957-a9192dd/web.assets_backend.js:3250:75) at Class._createMarker (https://dh.test.pl/web/content/957-a9192dd/web.assets_backend.js:3323:528) at Class._createMarker (https://dh.test.pl/web/content/521-1cebeb7/web.assets_common.js:3541:371) at https://dh.test.pl/web/content/957-a9192dd/web.assets_backend.js:3252:1674 at Function..each..forEach (https://dh.test.pl/web/content/521-1cebeb7/web.assets_common.js:12:558) at Class._renderUngrouped (https://dh.test.pl/web/content/957-a9192dd/web.assets_backend.js:3252:1488)

schinto777 commented 3 years ago

Even if the latitude and longitude is 0, the error is still there.

gityopie commented 3 years ago

@schinto777 did you use the map view on your custom model? or is it from my modules? I'm just tested it by installed the module contacts_maps on fresh DB without demo data and I found no issue.

schinto777 commented 3 years ago

Welcome I found such a description below. Maybe it can help you sort out the problem. https://gitlab.com/IvanSanchez/Leaflet.GridLayer.GoogleMutant/-/issues/101

http://huguowen.blogspot.com/2015/11/cannot-read-property-getsouthwest-of.html

Please let me know when you correct the error.

gityopie commented 3 years ago

@schinto777 Could you please debug the code on your side? add a console.log on function _clusterAddMarker https://github.com/gityopie/odoo-addons/blob/12.0/web_google_maps/static/src/js/view/map/map_renderer.js#L311

_clusterAddMarker: function (marker) {
    console.log(' marker = ', marker); // <-- debug
    var markerInClusters = this.markerCluster.getMarkers();
    var existingRecords = [];
    if (markerInClusters.length > 0) {
        var position = marker.getPosition();
        console.log(' position = ', position); // <-- debug
        markerInClusters.forEach(function (_cMarker) {
            if (position && position.equals(_cMarker.getPosition())) {
                existingRecords.push(_cMarker._odooRecord);
            }
        });
    }
    this.markerCluster.addMarker(marker);
    google.maps.event.addListener(
        marker,
        'click',
        this._markerInfoWindow.bind(this, marker, existingRecords)
    );
},

and come back with result that gets printed on the browser console.

or if you are willing to provide or send me the data that caused the error so I can test it on my side.

schinto777 commented 3 years ago

On your request

marker = Object { gm: {…} } ​ e3_: Object { click: {…} } ​​ click: Object { 26: {…} } ​​​ 26: Object { g: "click", o: 0, Vo: true, … } ​​​

: Object { … } ​​ : Object { … } ​ __gm: Object { set: null, Zl: null, Sv: false, … } ​​ Ql: null ​​ Sv: false ​​ Zl: null ​​ ki: Object { map: null, streetView: null } ​​ set: null ​​ uh: null ​​ : Object { … } ​ isAdded: false ​ : Object { constructor: Ua(), map_changed: Ua(), getMap: Ua(), … } web.assets_backend.js:formatted:57084 znacznik = marker = Object { __gm: {…} } ​ __gm: Object { set: null, Zl: null, Sv: false, … } ​​ Ql: null ​​ Sv: false ​​ Zl: null ​​ ki: Object { map: null, streetView: null } ​​​ map: null ​​​ streetView: null ​​​ : Object { … } ​​ set: null ​​ uh: null ​​ : Object { … } ​ : Object { constructor: Ua(), map_changed: Ua(), getMap: Ua(), … } web.assets_backend.js:formatted:57084
gityopie commented 3 years ago

@schinto777 Thank you. Looks like something is missing, I don't see position on your debug data.

This is mine A marker inside cluster

Screen Shot 2021-09-08 at 22 52 12

A marker is not in a cluster

Screen Shot 2021-09-08 at 23 04 18
schinto777 commented 3 years ago

image

schinto777 commented 3 years ago

image

schinto777 commented 3 years ago

Hello, I also noticed that when I call up the map directly from the view of one contact (and not from the contact list), everything is correct. If one contact filters on the contact list (the same contact as above), this error is still there.

schinto777 commented 3 years ago

Rectification When I filter one contact on the list, the map works fine. If there is more than one contact on the list, the map stops working.

gityopie commented 3 years ago

@schinto777 looks like one your data (contacts) has invalid value. could you please debug this function?

_renderUngrouped: function () {
    var self = this;
    var defaultLatLng = this._getDefaultCoordinate();
    var color, latLng, lat, lng;

    _.each(this.state.data, function (record) {
        color = self._getIconColor(record);
        lat =
            typeof record.data[self.fieldLat] === 'number'
                ? record.data[self.fieldLat]
                : 0.0;
        lng =
            typeof record.data[self.fieldLng] === 'number'
                ? record.data[self.fieldLng]
                : 0.0;
        console.log({lat, lng}); // <-- debug
        if (lat === 0.0 && lng === 0.0) {
            self._createMarker(defaultLatLng, record, color);
        } else {
            latLng = new google.maps.LatLng(lat, lng);
            record.markerColor = color;
            self._createMarker(latLng, record, color);
        }
    });
},
schinto777 commented 3 years ago

I checked single display of all objects in contacts. All of them are displayed individually. Not knowing your function during debug.

gityopie commented 2 years ago

@schinto777 Sorry but it's really hard to debug just by saying there is an error or it's working fine on this and that.. In this case the error message is not enough to trace the issue.

Let's analyze your report

First, Regarding this error message

Error:
Uncaught TypeError: Cannot read property 'equals' of undefined

It's already clear that this variable var position = marker.getPosition(); has undefined value when it tries try to invoke the function equals.

Second, You said when you open the recordset on the map individually, there is no issue. my guesses is probably on the cluster marker.

If you want to resolve this issue please help me by provide the latitude and longitude of your contacts. No need to give all your contacts data, just one that caused the issue.

To debug, on your side please edit these two functions ( start from this line https://github.com/gityopie/odoo-addons/blob/12.0/web_google_maps/static/src/js/view/map/map_renderer.js#L402 )

_renderGrouped: function () {
    console.log(' _renderGrouped '); // <------------------------ debug
    var self = this;
    var defaultLatLng = this._getDefaultCoordinate();
    var color, latLng, lat, lng;

    _.each(this.state.data, function (record) {
        color = self._getGroupedMarkerColor();
        record.markerColor = color;
        _.each(record.data, function (rec) {
            lat =
                typeof rec.data[self.fieldLat] === 'number' ? rec.data[self.fieldLat] : 0.0;
            lng =
                typeof rec.data[self.fieldLng] === 'number' ? rec.data[self.fieldLng] : 0.0;

            console.log({lat, lng}); // <------------------------ debug

            if (lat === 0.0 && lng === 0.0) {
                self._createMarker(defaultLatLng, rec, color);
            } else {
                latLng = new google.maps.LatLng(lat, lng);
                self._createMarker(latLng, rec, color);
            }
        });
        self.markerGroupedInfo.push({
            title: record.value || 'Undefined',
            count: record.count,
            marker: self.iconUrl + record.markerColor.trim() + '.png',
        });
    });
},
_renderUngrouped: function () {
    console.log(' _renderUngrouped '); // <------------------------ debug
    var self = this;
    var defaultLatLng = this._getDefaultCoordinate();
    var color, latLng, lat, lng;

    _.each(this.state.data, function (record) {
        color = self._getIconColor(record);
        lat =
            typeof record.data[self.fieldLat] === 'number'
                ? record.data[self.fieldLat]
                : 0.0;
        lng =
            typeof record.data[self.fieldLng] === 'number'
                ? record.data[self.fieldLng]
                : 0.0;

        console.log({lat, lng}); // <------------------------ debug

        if (lat === 0.0 && lng === 0.0) {
            self._createMarker(defaultLatLng, record, color);
        } else {
            latLng = new google.maps.LatLng(lat, lng);
            record.markerColor = color;
            self._createMarker(latLng, record, color);
        }
    });
},

and send me the latitude and longitude that's printed on the browser console before the error occurs

schinto777 commented 2 years ago

Welcome I checked on the archival database, on which nothing had been added for a long time. Probably everything worked before in this base. Now it doesn't work. I don't know how I can help you solve the error yet. The problem is not in the data.