Skip to content

Changing the MapGuide Active Tool Map Cursor

by Romany Saad on November 2nd, 2010

At Websoft, we have many clients that use various versions of MapGuide: 6.5, Open Source, Enterprise 2009, 2010 and 2011.

When working with the map, it is easy to forget which tool you are using. For example, you may think that you are in pan mode when you are really in zoom to rectangle mode.  Clicking and dragging the cursor across the map, you will end up zooming instead of panning.

As a result, one of the features that many of our MapGuide Enterprise/Open Source clients have requested is changing the active cursor to specify which toolbar tool is selected.

This feature has since been implemented in MapGuide Enterprise 2011 and MapGuide Open Source 2.1. However, for our clients who have yet to upgrade, we apply the patch manually to previous versions of MapGuide.

Those interested in seeing how this change was implemented originally can view the original discussion, the submitted patch, and the final submitted changeset.

Implementing the Cursors

To implement this change in your own MapGuide deployment, the first step is to download the new cursors.

Then, make a backup of your current cursors/icons directory and extract the cursors from the ZIP file to that directory.
For MapGuide Enterprise, the directory is found here:
C:\Program Files\Autodesk\MapGuideEnterprise2010\WebServerExtensions\www\stdicons
For MapGuide Open Source, the directory is found here:
C:\Program Files\OSGeo\MapGuide\Web\www\stdicons

Then, backup the ajaxmappane.templ and mainframe.templ files found in the viewerfiles directory.
For MapGuide Enterprise, the directory is found here:
C:\Program Files\Autodesk\MapGuideEnterprise2010\WebServerExtensions\www\viewerfiles
For MapGuide Open Source, the directory is found here:
C:\Program Files\OSGeo\MapGuide\Web\www\viewerfiles

Next, find the following nine functions in the ajaxmappane.templ file and add the highlighted lines:

function DigitizePoint(handler)
{
    if(handler == null)
        return;
    SetDigitizeCursor("Point");
    StartDigitizing(new PointDigitizer(OnShapeDigitized, ScreenToMapUnits), handler);
}

 

function DigitizeLine(handler)
{
    if(handler == null)
        return;
    SetDigitizeCursor("Line");
    StartDigitizing(new LineDigitizer(OnShapeDigitized, ScreenToMapUnits, cancelTgt, shape, "shapeFeedback", "#000000", mapPosX, mapDevW, mapDevH), handler);
}

 

function DigitizeCircle(handler)
{
    if(handler == null)
        return;
    SetDigitizeCursor("Circle");
    StartDigitizing(new CircleDigitizer(OnShapeDigitized, ScreenToMapUnits, cancelTgt, shape, "shapeFeedback", "#000000", mapPosX, mapDevW, mapDevH), handler);
}

 

function DigitizeRectangle(handler)
{
    if(handler == null)
        return;
    SetDigitizeCursor("Rectangle");
    StartDigitizing(new RectangleDigitizer(OnShapeDigitized, ScreenToMapUnits, cancelTgt, shape, "shapeFeedback", "#000000", mapPosX, mapDevW, mapDevH), handler);
}

 

function DigitizeLineString(handler)
{
    if(handler == null)
        return;
    SetDigitizeCursor("LineString");
    StartDigitizing(new LineStringDigitizer(OnShapeDigitized, ScreenToMapUnits, cancelTgt, shape, "shapeFeedback", "#000000", mapPosX, mapDevW, mapDevH, ShowSelectionTip, selTtipText, false), handler);
}

 

function DigitizePolygon(handler)
{
    if(handler == null)
        return;
    SetDigitizeCursor("Polygon");
    StartDigitizing(new LineStringDigitizer(OnShapeDigitized, ScreenToMapUnits, cancelTgt, shape, "shapeFeedback", "#000000", mapPosX, mapDevW, mapDevH, ShowSelectionTip, selTtipText, true), handler);
}

 

function ExecuteMapAction(action)
{
    if(!mapInit)
        return;
    CancelDigitization();
    switch(action)
    {
        case 1:
            UpdateMapActionCursor(action);
            tool = 4;
            break;
        case 2:
            PanUp();
            break;
        case 3:
            PanDown();
            break;
        case 4:
            PanRight();
            break;
        case 5:
            PanLeft();
            break;
        case 7:
            UpdateMapActionCursor(action);
            tool = 1;
            break;
        case 8:
            UpdateMapActionCursor(action);
            tool = 2;
            break;
        case 9:
            UpdateMapActionCursor(action);
            tool = 3;
            break;
        case 10:
            ZoomSelection();
            break;
        case 11:
            InitialMapView();
            break;
        case 12:
            PreviousView();
            break;
        case 13:
            NextView();
            break;
        case 14:
            InitialMapView();
            break;
        case 15:
            UpdateMapActionCursor(action);
            tool = 0;
            break;
        case 16:
            UpdateMapActionCursor(action);
            tool = 5;
            break;
        case 17:
            UpdateMapActionCursor(action);
            tool = 6;
            break;
        case 19:
            ClearSelection();
            break;
        case 20:
            Refresh();
            break;
        case 21:
            break;
        case 22:
            About();
            break;
    }
}

 

function CancelDigitization()
{
    if(digitizing)
    {
        SetCurrentToolCursor();
        digitizer.Cancel();
        digitizing = false;
        digihandler = null;
    }
}

 

function OnShapeDigitized(shape)
{
    if(digitizing)
    {
        SetCurrentToolCursor();
        digitizing = false;
        if(digihandler != null)
        {
            digihandler(shape);
            digihandler = null;
        }
    }
}

Then, add the following four functions between the existing GotoView and ExecuteMapAction functions.

//Update the map cursor based on a map action
function UpdateMapActionCursor(action)
{
    var strCursor = "";
    switch(action)
    {
        case 1: /*pan*/             strCursor = "pan";          break;
        case 7: /*Zoom plus*/       strCursor = "zoomin";       break;
        case 8: /*Zoom minus*/      strCursor = "zoomout";      break;
        case 9: /*Zoom window*/     strCursor = "zoomrect";     break;
        case 16: /*Select Radius*/  strCursor = "selectRadius"; break;
        case 17: /*Select Polygon*/ strCursor = "selectPolygon";break;
    }
    SetMapCursor(strCursor)
}

 

//Update the map cursor to reflect the current tool
function SetCurrentToolCursor()
{
    var strCursor = "";
    switch(tool)
    {
        case 1: /*Zoom plus*/      strCursor = "zoomin";       break;
        case 2: /*Zoom minus*/     strCursor = "zoomout";      break;
        case 3: /*Zoom window*/    strCursor = "zoomrect";     break;
        case 4: /*pan*/            strCursor = "pan";          break;
        case 5: /*Select Radius*/  strCursor = "selectRadius"; break;
        case 6: /*Select Polygon*/ strCursor = "selectPolygon";break;
    }
    SetMapCursor(strCursor)
}

 

//Update the map cursor for digitization
function SetDigitizeCursor(digitizeTool)
{
    var strCursor = "";
    switch(digitizeTool)
    {
        case "Point":      strCursor = "digitizePoint"; break;
        case "Line":       strCursor = "digitizeLine"; break;
        case "Circle":     strCursor = "digitizeCircle"; break;
        case "Rectangle":  strCursor = "digitizeRectangle"; break;
        case "LineString": strCursor = "digitizeLineString"; break;
        case "Polygon":    strCursor = "digitizePolygon"; break;
    }
    SetMapCursor(strCursor)
}

 

function SetMapCursor(strCursor)
{
    if(strCursor == "")
    {
        strCursor = "auto";
    }
    else
    {
        strCursor = "url('../stdicons/" + strCursor + ".cur'), pointer";
    }
    document.getElementById("tbMap").style.cursor = strCursor;
}

Finally, find the following four functions in the mainframe.templ file and add the highlighted lines:

function EndMeasure()
{
    inMeasure = false;
    try
    {
        GetMapFrame().SetCurrentToolCursor();
        measureWinRef.MeasureEnded();
    }
    catch(e) {}
}

 

function ResumeMeasure()
{
    inMeasure = true;
    try
    {
        GetMapFrame().SetMapCursor("measure");
        measureWinRef.MeasureResumed();
    }
    catch(e) {}
}

 

function StopMeasure()
{
    inMeasure = false;
    GetMapFrame().SetCurrentToolCursor();
}

 

function ExecuteMeasureCommand(index)
{
    if(GetMapFrame().IsDigitizing()) {
        SetStatusMsg("__#DIGALREADYRUNNING#__");
        return;
    }
    inMeasure = true;
    pointBegin = null;
    GetMapFrame().SetMapCursor("measure");
    measureWinRef = OpenUrl("%s?PARTIAL=0&TOTAL=0", index);
}

Conclusion

After editing the two template files and adding the cursors, you should now be able to access your MapGuide map and view the new cursors when selecting specific toolbar tools such as zoom to rectangle in our example:

MapGuide Cursors

The New Zoom to Rectangle Cursor

From → MapGuide

No comments yet

Leave a Reply

You must be logged in to post a comment.