What's the best process for adding a custom control to a map? I need to add an extra button along the top of the displayed map (next to the map type selection buttons).

I don't see any interfaces in the code for adding custom controls from the server side code. So I've been exploring doing it with Javascript using the BpControl library from gmaptools.com. The problem I'm running into here though is knowing when the map object is loaded and available.

Here is my javascript code:

if (Drupal.jsEnabled) {
  $(document).ready(function() {
  var observation_map = Drupal.gmap.getMap("observation_map");
  FullScreenControl = new BpControl('<a href="javascript:vsexploredata_map_expand_map();">Full Screen</a>', new GSize(300, 10), G_ANCHOR_TOP_RIGHT, "vsexploredata_map_fullscreen_control");
  ExitFullScreenControl = new BpControl('<a href="javascript:vsexploredata_map_shrink_map();">Exit Full Screen</a>', new GSize(300, 10), G_ANCHOR_TOP_RIGHT, "vsexploredata_map_fullscreen_control");
  observation_map.map.addControl(FullScreenControl);
  observation_map.map.addControl(ExitFullScreenControl);
  FullScreenControl.show();

  });
}

Unfortunately the above doesn't work because Drupal.gmap.getMap("observation_map").map isn't initialized when the jquery document.ready function fires. The above code does work if I run it by manually clicking a link after everything has finished loading.

So that is sort of a long way of asking two questions:
1. Is there a way to add custom controls to a map via PHP?
2. Is there an event notification so that Javascript can know when the map object is initialized?

Comments

johnv’s picture

Status: Active » Closed (won't fix)

Closing this very old issue. Please reopen if it is still valid.