wiki:CodeSamples/JavaScript/CustomCursors

This page is one of the MapGuide Community CodeSamples. Visit the CodeSamples page to view more!

Displaying custom cursors in the AJAX viewer

This page describes how to modify the AJAX viewer for WebLayouts to display a custom cursor when the user has selected one of the zoom tools. The code and files here have been posted to the MapGuide mailing list, but frequent requests indicate that a more formal description will be appreciated.

Modifying the AJAX viewer

The javascript/html for the AJAX viewer can be found in the WebServerExtensions installation directory, which is usually at: C:\Program Files\MapGuideOpenSource\WebServerExtensions\www\viewerfiles

The only file to modify is the "toolbar.templ", which has code for handling button clicks on the toolbar. Simply add the folowing code inside the body tag:

<script type="text/javascript">
/* Custom icon handler */
function changeIcon(action){
        var cururl = "http://localhost/mapguide/stdicons/";
        var map = parent.mapFrame.document.getElementById("map");
        switch(action)
        {
                case 1:
                        map.style.cursor = cururl + "pan.cur"
                        break;
                case 7:
                        map.style.cursor = cururl + "zoomin.cur"
                        break;
                case 8:
                        map.style.cursor = cururl + "zoomout.cur"
                        break;
                case 9:
                        map.style.cursor = cururl + "zoomrect.cur"
                        break;
                default:
                        map.style.cursor = 'default';
                        break;
        } 
        
}
</script>

Inside the same file is the actual handler for button clicks, called OnCommandExecuted. Modify OnCommandExecuted to also change the cursor:

<script type="text/javascript">
function OnCommandExecuted(action)
{
        changeIcon(action)
        .....
        .....
        .....
}
</script>

Finally, place the .cur files in the folder where the viewer files reside, or change the path int the changeIcon method above. The cursor files are attached to this post.

Original code by Jackie Ng. Cursors by Ivan Milicevic.

Last modified 5 years ago Last modified on Feb 6, 2013 1:12:30 PM

Attachments (4)

Download all attachments as: .zip