alex_ending


Hello all,
I'm convert my v.4 source code to the new v.5 SDK. In the new v.5 the pushpins are now shapes. When you creates a new shape, this have an Id (diferent of my internal Id).
How I can delete a pushpin on v.5
How I can know the internal id of a pushpin (shape)
Can you mail me some source code for delete pushpins for v.5

Thanks a lot!!!
Alex




Re: Delete pushpins?

Jared H


Interesting questions...here's the scoop on the internal ID of the pushpin -- which means to delete a specific shape within a layer by this internal identifier, you'd need to first establish a reference to the VEShape class object itself (shape2delete = VEShapeLayer.GetShapeByID(ID); ) and then call the DeleteShape method from the layer....VEShapeLayer.DeleteShape(shape);.

At least that's what it looks like at first glance through the docs...there's also an indexer provided for the layers and shapes, but i'm not sure if that'll be easier or not..haven't tried yet!






Re: Delete pushpins?

Keith Kinnan

yes, that is correct DeleteShape is the method on VEMap to delete shapes. The DeleteShape method takes a reference to the VEShape. Here is some sample code:

var shape = new VEShape(VEShapeType.Pushpin,new VELatLong(36, -95));
map.AddShape(shape);
map.DeleteShape(shape)






Re: Delete pushpins?

alex_ending

Dear Jared,

I'm reading about GetShapeById(Id)...

You write about an indexer... Where I can read more about indexer for the shapes

Thanks a lot






Re: Delete pushpins?

Jared H

Hey Alex -- for starters (although I do like the interactive SDK) I live pretty much solely in the msdn documention (or even better .chm which you can download for local and/or offline browsing) reference here. When you add a shape to a ShapeLayer, it appears the API generates the internal ID value, and sets an Index value. To iterate over all the shapes in a given layer, you could probably go with a simple javascript for(i=0;i++;i=VEShapeLayer.GetShapeCount()-1) -- I haven't tried this yet so I'm not certain if it's a 0 based index or not, in which case you wouldn't need the -1. Anyway, inside that loop, references to the individual shapes, by index, would be established with this method: VEShapeLayer.GetShapeByIndex(index).

Lastly, if you think about ShapeLayers are to Shapes as VEMap is to ShapeLayers, you'll find the equvialent indexing methods at the map container level:

VEMap.GetShapeLayerCount();

VEMap.GetShapeLayerByIndex(index);

I THINK this is the correct syntax for GetShapeLayerCount()...the documentation says to pass in an ID, which doesn't make sense to me seeing as it is a method attached to the VEMap class object. Anyhow, the idea being you can get a count of the ShapeLayers, iterate over each one, and in turn do the iteration describe above to go through all the shapes in each layer.

For performance considerations you may want to consider keeping track of these ID's and Index values as the various Constructors are called -- that way you can call the Index-specific methods directly, rather than having to establish the upper bounds of the arrays and then iterate over them to find what you're looking for...

Hope this helps,

Jared





Re: Delete pushpins?

alex_ending

Solved! This is my final source code:

function addPushpin(Id, Lat, Lon, Title, Text, ImgNodo)
{
var LL = new VELatLong(Lat, Lon);
var shape = new VEShape(VEShapeType.Pushpin, LL);
shape.SetTitle(Title);
shape.SetDescription(Text);
//Set the icon
if (ImgNodo!='')
{
shape.SetCustomIcon(ImgNodo);
}
else
{}
layer.AddShape(shape);
shape.Show();
}

function DeletePushpin(Title)
{
try
{
var n = layer.GetShapeCount();
//alert(n);
for(var i=0;i<=n-1;i++){
shape = layer.GetShapeByIndex(i);
texto = shape.GetTitle();
//alert(texto+'=='+ Title);
if (texto==Title)
{
layer.DeleteShape(shape);
}
else
{
}
}
}
catch (err)
{
}
}