PDA

View Full Version : Making Pushpin Locations Immoveable



Anonymous
06-19-2003, 09:13 PM
Fernando Velasquez shares a solution for preventing a user from moving pushpins on a map

Read the full article here: http://www.mp2kmag.com/articles.asp?ArticleID=97&key=pushpins.immoveable

samitha
06-23-2003, 05:05 AM
Hi, Your method was very usefull but it disables the right click menu also, which was necessary in my application. So I changed your code a little bit so that it will give you the right click menu but doesnt allow you to move a push pin.


//class variable to hold the last mouse
//button pressed on the map control
private bool lastMouseButtonLeft=false;

private void MapControl_MouseDownEvent(object sender, AxMapPoint._IMappointCtrlEvents_MouseDownEvent e)
{
if(e.button == MapPoint.GeoMouseButtonConstants.geoLeftButton)
{
unSelectPushPin(MapControl.ActiveMap.Selection);
lastMouseButtonLeft=true;
}
}

private void MapControl_SelectionChange(object sender, AxMapPoint._IMappointCtrlEvents_SelectionChangeEve nt e)
{
if(lastMouseButtonLeft)
{
unSelectPushPin(e.pNewSelection);
lastMouseButtonLeft=false;
}
}


/// <summary>
/// This method deselects the selected item if it is
/// a pushpin
/// </summary>
/// <param name="MapSelection">object MapSelection</param>
private void unSelectPushPin(object mapSelection)
{
MapPoint.Shape sp;
MapPoint.Location loc;
MapPoint.Pushpin pp;

try
{
//try to get the selection if its a pushpin
pp = (MapPoint.Pushpin )mapSelection;

//get a location over at the arctic ocean
loc = MapControl.ActiveMap.GetLocation(80, 0,0);
sp = MapControl.ActiveMap.Shapes.AddShape
(MapPoint.GeoAutoShapeType.geoShapeRectangle, loc, 1, 1);
sp.Select();
sp.Delete();

sp = null;
loc = null;
pp = null;
}
catch (System.Exception e)
{
Console.WriteLine(e.Message);
}
}

Fer
06-25-2003, 12:42 PM
Hi samitha, I'm glad my article was useful to you. You are correct, since the application I conceived the method for didn't involve the use of the right click, I didn't consider the mouse clicks when I did it. I'm glad you shared your solution with the community. See you later!


Fernando

Anonymous
01-29-2004, 02:18 AM
thanks samitha, is very usefull for me your new code using the mouse buttons, but i'm using Visual Basic, not C and I don't know how to implement the "unSelectPushpin". Any idea?
Thanks very much.

Anonymous
01-29-2004, 02:57 AM
I've just found a way to implement samitha's suggestion in Visual Basic, it is a mix between samitha's and Fernando's. Look

Private Sub MappointControl1_MouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)

Dim sp As mappoint.Shape
Dim loc As mappoint.Location
If Button = mappoint.GeoMouseButtonConstants.geoLeftButton Then
If Not MappointControl1.ActiveMap.Selection Is Nothing Then
If TypeOf MappointControl1.ActiveMap.Selection Is Pushpin Then
Set loc = MappointControl1.ActiveMap.GetLocation(80, 0) 'get a location over at the arctic ocean
Set sp = MappointControl1.ActiveMap.Shapes.AddShape(GeoAuto ShapeType.geoShapeRectangle, loc, 1, 1)
sp.Select
sp.Delete
End If
End If
End If
End Sub


If button is "right" you can see the menu, but you can't move the pushpin.
I hope is usefull for someone.

Thanks.
:lol:

Wilfried
12-28-2004, 01:22 PM
Hi,

This is a very good idea :)
I made a little change to the code here:


pp = &#40;Pushpin&#41;mapSelection;
loc = MP.ActiveMap.GetLocation&#40;80, 0, 0&#41;;
// etc
Changed to:

pp = mapSelection as Pushpin;
if&#40;pp != null&#41; &#123;
loc = MP.ActiveMap.GetLocation&#40;80, 0, 0&#41;;
// etc
In this case pp will evaluate to null if mapSelection is not of type Pushpin, and in the first case if it is object of wrong type it will generate an exception because of the tyepcast.

Shaman
02-11-2010, 09:31 AM
Hello everyone,

I've found these old thread and I'm very interested in a solution to make pushpin unmovable.

Is there no simple way, a flag "fixed" or something like it?

Thanks,

Matteo

Winwaed
02-11-2010, 09:50 AM
No - nothing like that!