angular-google-maps icon indicating copy to clipboard operation
angular-google-maps copied to clipboard

Cannot read property 'then' of undefined agm-circle

Open MerlinMoos opened this issue 4 years ago • 23 comments

Hello,

i've got an error since i've installed new version...

Issue description

image

Steps to reproduce and a minimal demo of the problem Install Angular 9 and AGM 3.0.0-beta.0

Current behavior

Expected/desired behavior No error

angular-google-maps, Angular, & any other relevant dependency versions

Angular 9 AGM 3.0.0-beta.0 Other information

MerlinMoos avatar Aug 27 '20 10:08 MerlinMoos

This was fixed, but not deployed.

ghost avatar Aug 28 '20 13:08 ghost

Thank you.

MerlinMoos avatar Aug 28 '20 13:08 MerlinMoos

when will it be deployed? any idea? I am also facing same issue.

anshusingh1234 avatar Aug 31 '20 15:08 anshusingh1234

This was fixed, but not deployed.

I have the same problem. When it will be deployed? And when AGM 3.0.0 will be no more in beta?

ilprima avatar Sep 09 '20 10:09 ilprima

I also faced the issue. What I guess is they are registering the events before the circle is created. Before we get updated version you can make the following changes to make it work

Go to the file at /node_modules/@agm/core/fesm2015/agm-core.js You will get the bellow function

addCircle(circle) {
    this._apiWrapper.getNativeMap().then(() => {
        this._circles.set(circle, this._apiWrapper.createCircle({
            center: { lat: circle.latitude, lng: circle.longitude },
            clickable: circle.clickable,
            draggable: circle.draggable,
            editable: circle.editable,
            fillColor: circle.fillColor,
            fillOpacity: circle.fillOpacity,
            radius: circle.radius,
            strokeColor: circle.strokeColor,
            strokeOpacity: circle.strokeOpacity,
            strokePosition: google.maps.StrokePosition[circle.strokePosition],
            strokeWeight: circle.strokeWeight,
            visible: circle.visible,
            zIndex: circle.zIndex,
        }))
    });
}

Change it to the following

addCircle(circle) {
    return this._apiWrapper.getNativeMap().then(() => {
        this._circles.set(circle, this._apiWrapper.createCircle({
            center: { lat: circle.latitude, lng: circle.longitude },
            clickable: circle.clickable,
            draggable: circle.draggable,
            editable: circle.editable,
            fillColor: circle.fillColor,
            fillOpacity: circle.fillOpacity,
            radius: circle.radius,
            strokeColor: circle.strokeColor,
            strokeOpacity: circle.strokeOpacity,
            strokePosition: google.maps.StrokePosition[circle.strokePosition],
            strokeWeight: circle.strokeWeight,
            visible: circle.visible,
            zIndex: circle.zIndex,
        }))
    });
}

At line 1450 you will find this code

ngOnInit() {
   this._manager.addCircle(this);
   this._circleAddedToManager = true;
   this._registerEventListeners();
}

Change it to the below code

ngOnInit() {
    var rip = this._manager.addCircle(this);
    rip.then(() => {
        this._circleAddedToManager = true;
        this._registerEventListeners();
    })
}

Now this issue will be gone and all the events will work, I checked the radius change as I need this event to work.

codebeginer avatar Sep 22 '20 19:09 codebeginer

Personnally, i put the @codebeginer 's modifications in node/modules/@agm/core/ivy_ngcc/fesm2015/agm-core.js .

@SebastianM or anyone else to add it ?

Foreverdie avatar Sep 24 '20 10:09 Foreverdie

@SebastianM any update on this?

ikashifullah avatar Oct 21 '20 18:10 ikashifullah

@SebastianM we really need this, please add it when possible.

IgorGeorgioski avatar Dec 18 '20 17:12 IgorGeorgioski

I'm facing the same issue ... was this pushed?

Alexise857 avatar Dec 21 '20 22:12 Alexise857

I also faced the issue. What I guess is they are registering the events before the circle is created. Before we get updated version you can make the following changes to make it work

Go to the file at /node_modules/@agm/core/fesm2015/agm-core.js You will get the bellow function

addCircle(circle) {
    this._apiWrapper.getNativeMap().then(() => {
        this._circles.set(circle, this._apiWrapper.createCircle({
            center: { lat: circle.latitude, lng: circle.longitude },
            clickable: circle.clickable,
            draggable: circle.draggable,
            editable: circle.editable,
            fillColor: circle.fillColor,
            fillOpacity: circle.fillOpacity,
            radius: circle.radius,
            strokeColor: circle.strokeColor,
            strokeOpacity: circle.strokeOpacity,
            strokePosition: google.maps.StrokePosition[circle.strokePosition],
            strokeWeight: circle.strokeWeight,
            visible: circle.visible,
            zIndex: circle.zIndex,
        }))
    });
}

Change it to the following

addCircle(circle) {
    return this._apiWrapper.getNativeMap().then(() => {
        this._circles.set(circle, this._apiWrapper.createCircle({
            center: { lat: circle.latitude, lng: circle.longitude },
            clickable: circle.clickable,
            draggable: circle.draggable,
            editable: circle.editable,
            fillColor: circle.fillColor,
            fillOpacity: circle.fillOpacity,
            radius: circle.radius,
            strokeColor: circle.strokeColor,
            strokeOpacity: circle.strokeOpacity,
            strokePosition: google.maps.StrokePosition[circle.strokePosition],
            strokeWeight: circle.strokeWeight,
            visible: circle.visible,
            zIndex: circle.zIndex,
        }))
    });
}

At line 1450 you will find this code

ngOnInit() {
   this._manager.addCircle(this);
   this._circleAddedToManager = true;
   this._registerEventListeners();
}

Change it to the below code

ngOnInit() {
    var rip = this._manager.addCircle(this);
    rip.then(() => {
        this._circleAddedToManager = true;
        this._registerEventListeners();
    })
}

Now this issue will be gone and all the events will work, I checked the radius change as I need this event to work.

i follow all your tips but no event work and still has same problem

Abdelrahmansherwida avatar Dec 22 '20 18:12 Abdelrahmansherwida

I also faced the issue. What I guess is they are registering the events before the circle is created. Before we get updated version you can make the following changes to make it work Go to the file at /node_modules/@agm/core/fesm2015/agm-core.js You will get the bellow function

addCircle(circle) {
    this._apiWrapper.getNativeMap().then(() => {
        this._circles.set(circle, this._apiWrapper.createCircle({
            center: { lat: circle.latitude, lng: circle.longitude },
            clickable: circle.clickable,
            draggable: circle.draggable,
            editable: circle.editable,
            fillColor: circle.fillColor,
            fillOpacity: circle.fillOpacity,
            radius: circle.radius,
            strokeColor: circle.strokeColor,
            strokeOpacity: circle.strokeOpacity,
            strokePosition: google.maps.StrokePosition[circle.strokePosition],
            strokeWeight: circle.strokeWeight,
            visible: circle.visible,
            zIndex: circle.zIndex,
        }))
    });
}

Change it to the following

addCircle(circle) {
    return this._apiWrapper.getNativeMap().then(() => {
        this._circles.set(circle, this._apiWrapper.createCircle({
            center: { lat: circle.latitude, lng: circle.longitude },
            clickable: circle.clickable,
            draggable: circle.draggable,
            editable: circle.editable,
            fillColor: circle.fillColor,
            fillOpacity: circle.fillOpacity,
            radius: circle.radius,
            strokeColor: circle.strokeColor,
            strokeOpacity: circle.strokeOpacity,
            strokePosition: google.maps.StrokePosition[circle.strokePosition],
            strokeWeight: circle.strokeWeight,
            visible: circle.visible,
            zIndex: circle.zIndex,
        }))
    });
}

At line 1450 you will find this code

ngOnInit() {
   this._manager.addCircle(this);
   this._circleAddedToManager = true;
   this._registerEventListeners();
}

Change it to the below code

ngOnInit() {
    var rip = this._manager.addCircle(this);
    rip.then(() => {
        this._circleAddedToManager = true;
        this._registerEventListeners();
    })
}

Now this issue will be gone and all the events will work, I checked the radius change as I need this event to work.

i follow all your tips but no event work and still has same problem

Might the package get updated, still you can try. If you applied the code at correct place then after restart the app then check

codebeginer avatar Dec 22 '20 19:12 codebeginer

Same issue, using angular 11.

bogomips avatar Dec 27 '20 00:12 bogomips

This is still an issue using the "supported" version of Angular, Angular 10. Also, the silence in the repo bugs me. Is this project still maintained at all?

i follow all your tips but no event work and still has same problem

The node_modules hack did not work for me until I also applied the suggested changes to node_modules/@agm/core/__ivy_ngcc__/fesm2015/agm-core.js.

Just search the @agm/core node module for the addCircle method and you will find all the functions and files that need tweaking.

lukasbuehler avatar Dec 28 '20 10:12 lukasbuehler

Did anyone find any solution? I'm using Angular 10 with Agm ^1.1.0 version.

Syamhere avatar Dec 30 '20 05:12 Syamhere

Everyone says to update the file at /node_modules/@agm/core/fesm2015/agm-core.js However, I'm not sure how to do that , every time I update, an error shows up saying that "File is read-only" Can anyone help me to understant how to update the agm-core.js file pls ?

Alexise857 avatar Dec 30 '20 14:12 Alexise857

Screenshot from 2021-01-01 16-13-31 Screenshot from 2021-01-01 16-12-53 Screenshot from 2021-01-01 16-12-37

agm-core.zip

File path to update : node_modules/@agm/core/ivy_ngcc/fesm2015/agm-core.js

Demo: http://13.126.237.87/map

codebeginer avatar Jan 01 '21 11:01 codebeginer

A temporary solution is a downgrade to "@agm/core": "1.1.0"

This worked for me

The actual version is 3.0.0 beta and its a Pre Release, so this means that is not a stable version

I took the example package.json from this plunker https://stackblitz.com/edit/angular-google-maps-demo?file=app%2Fapp.component.html

Check the releases https://github.com/SebastianM/angular-google-maps/releases

ArmandoPerdomo avatar Feb 18 '21 21:02 ArmandoPerdomo

Any progress on the issue?

malcheg avatar Apr 05 '21 12:04 malcheg

Any progress on this issue?

codal-sbelim avatar Jun 30 '21 11:06 codal-sbelim

When it'll be merged?

AmerAnsari avatar Dec 17 '21 07:12 AmerAnsari

Hello everybody!

Infortuny it seems that this repository doesn't have more updates since one year ago. Does anyone try this library @angular/google-maps instead?

https://github.com/angular/components/blob/master/src/google-maps/README.md

piantino avatar Apr 07 '22 15:04 piantino

it is sad that this is not merged yet 🙁

@piantino we have it on backlog but did not get to the migration yet

Franco-Alejandro avatar Jun 17 '22 09:06 Franco-Alejandro

The fix provided above works, I did it using "patch-package", so that the change is not overwritten every time I run "npm install". Make sure you update the correct file: the one that is in "ivy_ngcc" folder and the correct lines (at line 1450).

hextrinity avatar Jul 01 '22 04:07 hextrinity