Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: Can't find variable: LatLong<number> when I try to create new LatLong #180

Open
AdrianStaskiewicz opened this issue Apr 8, 2019 · 5 comments

Comments

@AdrianStaskiewicz
Copy link

Hello,
I'm trying to use a method addMapShape(), but when I'm adding a new point to my array (on mouse click event) and run MVCArray pmvc = new MVCArray(points.toArray()); I get:
ReferenceError: Can't find variable: LatLong This issue shows only when I'm catching new point on this mouse event. When I'm predefining some points on method initializeMap() and create new MVCArray with this points everything is OK, all methods work correctly and the new polygon shows.

Additionally the number new LatLong object get a random number. Often starts from 13 or something like this, and increase by random value, fro example 13, 15, 17, 22, 27....
And then the error occurs with the number of first element of array. F.E.
ReferenceError: Can't find variable: LatLong13

@GeoffCapper
Copy link
Collaborator

Hi @AdrianStaskiewicz ,

My guess is you're not converting to an proper LatLong in the mouse event. Without seeing code I can't be sure. It needs to be done like this:

map.addUIEventHandler(UIEventType.click, (JSObject obj) -> {
    LatLong myLatLong = new LatLong((JSObject) obj.getMember("latLng"));
    ... add that to your raw array....
});

LatLong[] ary = new LatLong[]{myLatLong, myLatLong2};
MVCArray mvc = new MVCArray(ary);

etc.

Hope that helps, if not, post some code, the mouse event at least.

Cheers,
Geoff

@AdrianStaskiewicz
Copy link
Author

AdrianStaskiewicz commented Apr 8, 2019

Hi @GeoffCapper
Thanks for your answer! I'm not sure what do You mean, so I'm pasting my source code. This is a whole mouse event implementation.

        map.addMouseEventHandler(UIEventType.click, (GMapMouseEvent event) -> {
            LatLong latLong = event.getLatLong();
            points.add(latLong);

            MVCArray pmvcTest = new MVCArray();
            if (points.size() > 2) {
                try {
                    pmvcTest = new MVCArray(points.toArray());
                } catch (Exception e) {
                    System.out.println(e);
                }
                polygOpts = new PolygonOptions()
                        .paths(pmvcTest)
                        .strokeColor("blue")
                        .strokeWeight(2)
                        .editable(false)
                        .fillColor("lightBlue")
                        .fillOpacity(0.5);

                pg = new Polygon(polygOpts);

                map.addUIEventHandler(pg, UIEventType.click, (JSObject obj) -> {
                    pg.setEditable(!pg.getEditable());
                });
                map.addMapShape(pg);
            }
        });

And of course variable points is declared as ArrayList

The issue occurs at this line: pmvcTest = new MVCArray(points.toArray());

What I have to change on my code?

@GeoffCapper
Copy link
Collaborator

GeoffCapper commented Apr 8, 2019

Sorry, I'd forgotten about the addMouseEventHandler method. In that case I suspect there is a problem with the delegates converting the original javascript event over to the java event.

Try using the addUIEventHandler method instead of the addMouseEventHandler, and see if that makes a difference. The top of your code would look like:

map.addUIEventHandler(UIEventType.click, (JSObject obj) -> {
    LatLong latLong = new LatLong((JSObject) obj.getMember("latLng"));
    points.add(latLong);

@AdrianStaskiewicz
Copy link
Author

AdrianStaskiewicz commented Apr 8, 2019

@GeoffCapper
It still doesn't work.. This same issue..
Now in my array exists LatLong10, but I'm getting

Can't find variable: LatLong10

I supose that the problem is at line:
this.runtime.execute("var " + this.variableName + " = " + this.runtime.getArrayConstructor(type, ary));

It is in JavaScriptObject.class:48

@Morstern
Copy link

@GeoffCapper
Hey, I encountered same problem in my case.
So creating "static" fields work. But whenever I want to add them in real-time (after user clicks) - it crashes: same error as above.
Any ideas how to fix it?

Best Regards,
Morstern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants