Embeddable maps
4. Adding Functionality - Using the Initialisation Methods
The best way to add additional functionality is to call a function once the map has loaded. To do this, a method should be created and its name appended to the script url using the initialisedcallback querystring parameter.
- Add the following inside the head tag:
Copy<script src="script/embeddedMapScript.js" ></script>
- Add the following to the embeddedMapScript.js file:
Copyfunction afterInitMethod(eventArgs){
alert('map loaded');
}
- Update the GetMap script tag to include a reference to the afterInitMethod.
Copy<script src="http://localhost/webmaplayers/GetMap.axd?mapid=myMap&mapname
=embedded&controlTag=MapPlaceholder&x=530284&y=179551&resolution=
1.2&showsymbol=true&controls=panzoom&initialisedcallback=afterInitMethod"
type="text/javascript"></script>
- When the page is loaded, the user see a message confirming “Map Loaded”. The mapping will not have loaded yet, as it will not be at that stage in the page lifecycle but the map object itself should now be accessible through the JavaScript.
The code explained
<script src="script/embeddedMapScript.js" ></script>
This is a reference to the embeddedMapScript.js file which holds the initialisation method.
function afterInitMethod(eventArgs){ alert('map loaded'); }
The afterinitMethod displays a JavaScript method, informing the user that the map has loaded.
<script src="http://localhost/SISWebMap9/GetMap.axd?mapid=myMap&mapname =embedded&controlTag=MapPlaceholder&x=530284&y=179551&resolution= 1.2&showsymbol=true&controls=panzoom&initialisedcallback=afterInitMethod" type="text/javascript"></script>
This is the same script tag as seen previously, but at the end there is a querystring parameter called initialisedcallback, which has a value of “afterInitMethod”.
The initialisedcallback parameter is used to specify a JavaScript function to call when the map is loaded.
The map object can now be accessed in the JavaScript in two ways.
- Refer to it using Cadcorp.myMap (or whatever the mapId parameter was set in the script src attribute), or
- Use eventArgs.main if using the afterInitMethod p (eventArgs is an argument sent by the initialised event, and it has a property of map, which holds a reference map JavaScript object).
Next we will add measuring functionality to our embedded map.
![]() |
5. Measure Line - Adding the Measuring Control |