hi all i have this problem:
how can i delete all pushpins which were added to a map ?
i don't want to add a pushpin anf then delete it but add for example 10 pushpins and then from a control, it would be a button , delete all those i have added
i hope someone can help me
masty
10-04-2006, 11:07 AM
Hi Bule,
To remove all the pushpin you've created you should use the follow code snippet (assuming your map is called "map"):
foreach (MapPoint.DataSet objDataSet in map.DataSets)
{
if (objDataSet.Name == "My Pushpins")
{
objDataSet.Delete();
}
This because all the Pushpin added by the user ar added in the DataSet "My Pushpins".
Otherwise, if you want to remove only some pushpin you should use something like the follow code snippet:
foreach (MapPoint.DataSet objDataSet in map.DataSets)
{
if (objDataSet.Name == "My Pushpins")
{
Recordset rs = objDataSet.QueryAllRecords();
while (!rs.EOF)
{
if (rs.Pushpin.Name.StartsWith("PushPinToDelete1") ||
rs.Pushpin.Name.StartsWith("PushPinToDelete2"))
rs.Pushpin.Delete();
rs.MoveNext();
}
}
}
In this example the pushpin named "PushPinToDelete1" and "PushPinToDelete2" will be deleted.
Of course you should use the same pushpin names you used to create them.
Bye!
Wilfried
10-04-2006, 04:29 PM
Hi,
Very right. In addition, remember that if you delete the dataset (first example and very fast), then you have to check for NULL if other parts of code want to work with it. The dataset is automically recreated if adding a pushpin again.
Thanks a lot ....this is the replay i was waiting for...
doMapPoint
05-16-2007, 06:55 AM
Hi!
This is also the code I looked for... and it works great!
But... what if you have the German or, for example, the French version of MapPoint? In the German version the DataSet's name is "Meine Pins" instead of "My Pushpins".
Is there a solution which is language-independent?
Regards,
Dietmar
Paul Larson
05-16-2007, 01:50 PM
If you wish to delete all pushpins from the map, simply:
foreach (MapPoint.DataSet objDataSet in map.DataSets)
{
if (objDataSet.DataMapType == geoDataMapTypePushpin)
{
objDataSet.Delete();
}
doMapPoint
05-17-2007, 10:46 AM
Hi Paul,
thanks! I use Delphi, but I understand your code.
There is only a little question I have: Of what type is your "MapPoint" object? I think I have to use the Map Object to access the DataSets, e.g. FMap.DataSets
Regards
Dietmar
Wilfried
05-17-2007, 01:18 PM
hi Dietmar,
Yes MP.ActiveMap (where MP is the name of the activeX component) translate to you as TMappointClass.FMap.
Wilfried
05-17-2007, 01:19 PM
Sorry I was incomplete. Map in Paul his reply is the ActiveMap property.