Fork me on GitHub

MAPSTRACTION

The Javascript Mapping Abstraction Library

Exceptions

Sometimes things go wrong and Mapstraction uses Javascript exceptions to tell your code that something has gone wrong and what has gone wrong.

All exceptions that Mapstraction throws are Error exceptions; you’re strongly advised to wrap your map initialisation code and other calls to the Mapstraction API in a try ... catch block.

If your code isn’t working as you expect it to, it’s likely that an uncaught exception is being thrown; you can check this via the Javascript Console in Chrome or Firebug in Firefox.

Map Script Not Imported Exception

A map script not imported exception is thrown when you try to create a map and have not included the required Javascript support files needed by your selected maps provider.

try {
	var map = new mxn.Mapstraction('mapdiv', 'openlayers'); 
	var latlon = new mxn.LatLonPoint(39.74,-104.98);
	map.setCenterAndZoom(latlon, 10);
}

catch (e) {
	var msg = e.message;
	// the msg variable holds the exception reason message
	// how you react to/display this depends on your application
	// in this example, msg will contain the text
	// "openlayers map script not imported"
}

Function Not Supported Exception

Not all mapping providers are created equal and in some cases you may find yourself trying to call a Mapstraction API function that isn’t currently supported; in this situation a function not supported exception will be thrown.

For example, the Mapstraction.declutterMarkers API call isn’t currently supported by Leaflet.

try {
	var opts = {};
	map.declutterMarkers(opts);
}

catch (e) {
	var msg = e.message;
	// the msg variable holds the exception reason message
	// in this example, msg will contain the text
	// "Mapstraction.declutterMarkers is not currently supported by provider leaflet"
}