0
votes

An app I inherited at http://bei.bclcmaps.com shows popups when locations are clicked, which works fine.

However, I need to add the ability to auto-show a popup on page load based on something in the URL. Whether it's a latitude and longitude of some sort of ID or anything, it doesn't matter, anything will do.

The problem I'm having is that I can't figure out how to programmatically open a popup. I've tried figuring out some way to trigger a click on a location in JS using the wax API or the modestmaps API and I can't get it.

I've even tried manually clicking with jQuery, using:

function clickAt(x, y) {
  var e = new jQuery.Event("click");
  e.pageX = 10; 
  e.pageY = 10; 
  $(".zoombox").trigger(e);
}

And from there I've set debugger within a .click() callback on zoombox to get the coordinate of an example location, and tried those coordinates with the clickAt function, and nothing happens.

On IRC, someone told me to use map.gridLayer.fire('click', {latLng: L.latLng(0, 0)) to trigger a click, but this doesn't seem like a proper mapbox app since I don't have access to the full mapbox JS API, so I don't have mapbox.gridLayer.

Any tips? Or maybe programmatically triggering a click isn't the correct approach and there's an easier way to show a prepopulated popup on page load? I'm out of ideas.

2

2 Answers

0
votes

You can do something like this

$(document.elementFromPoint(x, y)).click();

https://developer.mozilla.org/En/DOM:document.elementFromPoint

0
votes

I ended up just converting it to use the regular mapbox API after all, making things like this easier.