Load Events
This example demonstrates hooking up to the two NPMap load events: preinit and init. These events enable developers to build custom functionality into their map.
Related resources:
Map
Code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="example-map" style="height:500px;position:absolute;width:500px;">
</div>
<div id="example-map" style="height:500px;">
</div>
<script>
var NPMap = NPMap || {};
function getDependencyStatus() {
var html = 'All dependencies (Bean, JSON, Modernizr, Morpheus, Reqwest, Underscore and ' + NPMap.config.api + ') have been loaded.\n\nYou can use the NPMap.Event and NPMap.Util modules.\n\nThe map has ';
if (!NPMap.Map) {
html += 'not ';
}
return html + 'been created.';
}
NPMap.config = {
api: 'bing',
div: 'example-map',
events: {
preinit: function(callback) {
alert('preinit\n\n' + getDependencyStatus());
callback();
},
init: function(callback) {
alert('init\n\n' + getDependencyStatus());
callback();
}
}
};
(function() {
var s = document.createElement('script');
s.src = 'http://www.nps.gov/npmap/1.0.0/bootstrap.js';
document.body.appendChild(s);
})();
</script>
</body>
</html>