spacer2 1_1 1_2
 The MP2K Update!
Front Cover
What's New
Sample Data
MapPoint 2013
Press Releases
MapPoint Forums
Link to MP2Kmag
Wish List
MapPoint Trial
 Earlier Content
Past News Items
Past What's New Announcements

MapPoint 2013

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
SVG Tutorials

Map Visitors


Making Pushpin Locations Immoveable

Fernando Velasquez shares a solution for preventing a user from moving pushpins on a map

Recently, I came up against the problem of preventing a user from dragging around the map certain pushpins created programmatically. The idea behind this is that it is sometimes useful t o prevent the pushpins from being moved because afterwards the user may not remember where the pushpin was originally and the whole idea of representing information in a map loses its value.

What gave me a clue about how it could be done easily is the way in which one carries out the action of moving a pushpin around the map. The dragging action of a pushpin differs slightly from the dragging action we can carry out for a desktop icon, in which you only need to click on it and start dragging. In MapPoint, this is a two-step process. First, you need to click on the pushpin for it to be selected, and then you need to click and hold on it to start dragging it around. So, armed with this knowledge, I started out seeking a way to interrupt this process.

The Solution

The solution I found involves doing some actions on the map in the middle of the dragging process. By middle I mean the interval between the mouse click that selected the pushpin and the mouse click that will start the dragging operation. Since I have found it impossible to move a pushpin by making the mouse clicks real quick, meaning there is a short time span that has to pass before being able to drag the pushpin, this gave me the idea that I could do a lot of things in that interval.

The main purpose of doing some actions in the interval mentioned above is to have a way to make it impossible for the user to accomplish the drag by just click and holding the selected pushpin, so the easiest way to do this is just selecting another object just as soon as the pushpin we donít want moved is selected. MapPoint exposes an event called SelectionChange, which the help documentation states "Occurs when a selection on the map changes." This is the event that will do the magic for us.

In simple terms, what the code below does is detect when the pushpin we donít want moved is selected, create another selectable object in a location that will not be easily seen by the user, select this new object and then delete it from the map, thus effectively shifting the current selection from the pushpin and preventing the user from dragging it around.

VB.Net Code

Line 5 checks to see if the new selection made is of type MapPoint.Pushpin; if you are looking to restrict a specific pushpin then more processing will need to be done, but for now Iíll focus on restricting movement to anything that is a pushpin on the map. If the selection is a pushpin, then a location object will be created. What is special about this location object is the place it is being created: Latitude 80, Longitude 0 represents a place very far away, it is located somewhere in the Arctic Ocean. You can actually choose any location you want, but the important thing to keep in mind is that it should be a place where it is not near any of the locations you are currently working with. Weíll see why next.

Lines 7-9 create a rectangle shape in the map, with its center located in the Arctic Ocean, and with a width and height of 1. It is important that the rectangle is of small size so the user wonít be able to notice the "magic" we are doing to keep the pushpins locked, and in the case that we donít pay attention to the shapeís size, then the fact that it will be drawn far away from where the user is looking at will also help to achieve the desired effect. Personally, I think a combination of a far away object with a small size is the best one because there may be cases where the user could be looking at the whole globe, so this would minimize any traces of what has been done.

And thatís it! Now the user as much as he/she tries wonít be able to move anything that is a pushpin around the map, unless through the event handler we give permission to do so.

A final note: there are two VERY important remarks in the documentation for the SelectionChange event. One states that you shouldnít create any modal dialog boxes or message boxes inside this event; since we donít do that in the code then thatís not a problem, but the next one is. It says that we should NOT make that event infinitely recursive, either by calling itself or causing itself to be called. This is the main reason a shape object and the if statement in line 5 were used. Because the shape object is being programmatically selected, this could result in the SelectionChange event being raised, naturally creating a recursive call of itself, but since we first check to see if the newly selected object is a pushpin before doing anything, then the call will not advance and the normal flow will be returned when the code comes back from the recursion.


The above code was written to work under VB.Net, so I've included the code for VB6 here as well:

The logic is the same and the changes in code are minimal.

Discuss this story in the forum.

Author: Fernando Velasquez
Email: fvelasquez(AT)
Fernando works as a project manager for Real Systems, Inc. and also develops VB.Net-based applications using MapPoint. He lives in Tegucigalpa, Honduras (14.09489N, 87.20755W) and he enjoys sleeping, eating, reading books and solving complex computational problems using genetic programming.

MP2Kmag Internet

 Recent Discussion
-numeca fine
-SolidThinking Inspire v2016.1.5559 x64-BEAN (17/8)
-Auto FX PhotoGraphic Edges Ultimate Bundle Gen2 v9.6.0 (17/8)
-Mentor Graphics FloEFD 14.2-SSQ (17/8)
-Dlubal RFEM 5.06 (x64) Multilanguage (17/8)
-Bluebeam Revu eXtreme 2018.1 v18.x Multilingual (17/8)
-Autodesk Maya 2018.4 (17/8)
-Adobe Bridge CC 2018 (v8.1) x86-x64 Multilingual Update 2 (17/8)
-Simufact.Welding 4.0.1 (17/8)
-ANSYS Discovery Enterprise 19.1.1 (17/8)
-Aurora SPARK3D v2018
-ANSYS Electromagnetics Suite 17.1 (17/8)
-Solidthinking Inspire v2018.3.0.10526 Multilingual (x64) (17/8)
-Adobe Acrobat Pro DC 2018.011.20058 Multilingual (17/8)
-ANSYS Electromagnetics Suite 17.0 (x64) (17/8)
-GibbsCAM (x64) Multilingual (17/8)
-Autodesk Autocad Mechanical 2019.1 by m0nkrus (17/8)
-Adobe Bridge CC 2018 v8.1 (x86/x64) Update 2 Multilingual (17/8)
-Autodesk AutoCAD Electrical 2019.1 (17/8)
-DS V5R22 CATIA-DELMIA-ENOVIA last hotfixes for all SP (17/8)
-VMware Fusion Pro 10.1.3 Build 9472307 (17/8)
-MAGIX Fotostory easy Germany + English (17/8)
-Ds Simulia Abaqus v6.14-4 (17/8)
-Paragon Drive Copy 15 Professional (x86/x64) (17/8)
Browse GIS books and periodicals
Find a MapPoint Partner or Consultant
Real Estate Thornbrook Homes for Sale

Want Your Site To Appear Here?

   © 1999-2012 MP2K. Questions and comments to:
  Microsoft and MapPoint 2002/2004/2006/2009/2010/2011/2013 are either trademarks or registered trademarks of Microsoft.