Crater Lake National Park

NPMap

Digital maps for the National Park Service

Load Hooks

The NPMap library is designed to be targeted and focused, and makes it easy for you to get web maps up and running quickly. The library does not, however, take care of everything you might want your web map to do. If you find that you need more functionality than what is provided out of the box, you'll probably want to look at extending the map yourself. Luckily, NPMap makes this easy by providing two "load hooks" that you can utilize to add custom functionality to your map. Both of these hooks can be added to the events config property on the NPMap.config object.

  1. The preinit hook gets called by NPMap after NPMap's dependencies have loaded (including the base API, but before the bulk of the NPMap library (two exceptions: NPMap.Event and NPMap.Util) has been loaded and the map has been created. This hook is ideal for "pre-loading" data or calling a web service for map configuration information before the map is loaded.
  2. The init hook gets called by NPMap after all of NPMap and its dependencies have been loaded and the map has been created, loaded, and is ready to be interacted with programatically. This hook is where you'll want to add code that customizes the functionality and look-and-feel of the web map.

Both of these hooks can be defined in the events object of the NPMap.config object, and should accept and call a callback function. Here is a simple example:


NPMap.config = {
  events: {
    preinit: function(callback) {
      // Write your custom code here.

      callback();
    },
    init: function(callback) {
      // Write your custom code here.

      callback();
    }
  }
}

Here's a link to an example that demonstrates how to hook up to these events: http://www.nps.gov/npmap/support/library/examples/load-events.html.