user2932991
user2932991

Reputation:

Google Maps - "b is undefined" when simulating polygon clicks?

We have a campus map which has been created by a number of our students. For the most part, it runs fine, but there is one persistent error which we are unable to clear. There is a sidebar which lists out the buildings and points of interests which are represented on the map which, when clicked, [simulate a click][1] on the polygon for the building/poi.

function sideClick(poly) {  
    google.maps.event.trigger(buildingpoi[poly],'click');   
};

Where buildingpoi[i] is an array which holds the information regarding each polygon.

Whenever a click is triggered, it refers to a method called shapeClick() which handles the display of information and repositioning of the map to center on the building/poi. Regardless of whether it is the polygon itself or the link in the sidebar, this method executes completely without error.

However, when the sideClick() function is used, or when the click trigger is called in the code, an error occurs in the Google API files, namely a main.js file:

TypeError: b is undefined
...(a.Va)||b.set("poly",null)})]};function VH(a){var b=a.Se;b.b||(Q(Xe,function(c){...

This error appears to occur after the successful execution of the shapeClick() method, suggesting that the error lies- as noted in the error message- in the GMaps API main.js file at some point after shapeClick() is called. Generally, this does not cause an issue on the front end, but when I attempted to include another method which calls sideClick(), any code I place after sideClick() is not executed due to the error.

I've attempted a number of my own tests/fixes, but the best I've been able to do is narrow down where the error is triggered. My searches also appear to come up with related yet dissimilar results. I assume the answer may be very simple, but for me it has been elusive.

Map: https://www.beloit.edu/maps/

Upvotes: 2

Views: 2103

Answers (2)

Dr.Molle
Dr.Molle

Reputation: 117354

Although you did not access the event-argument in shapeClick(what will not be supplied when you trigger the event), it seems that the API internally tries to access this argument.

The API tries to read the vertex-property(don't ask me why) of the PolyMouseEvent(that's what event is expected to be).

Accessing a property of an undefined object results in an error, that's what the message says.

Provide an empty object as argument when you trigger the event:

google.maps.event.trigger(buildingpoi[poly], 'click',{});

...and the error will go away(accessing an undefined property of an existing object is not an error)

Upvotes: 2

John Sly
John Sly

Reputation: 769

Is buildingpoi[i] as you said an array holding information for the polygons? or a reference to the polygon itself?

This function needs the reference to the actual polygon, which is fine if it's in an array.

Upvotes: 0

Related Questions