I am putting pins on a map dynamically and it appears that ShapeIndex is always zero…and I am creating a new layer for every pin?
I want to do a identify shape and get a field of data based on the ShapeIndex but it is always zero with the code below…is there a better way to dynamically place pins?
Blockquote
public void mapPins(string callLabel, double gridLat, double gridLong)
{
var places = new[]
{
new { Lat = gridLat, Lng = gridLong, Name = callLabel },
};
//151N - 33.5
// it's default setting but just in casevar gs = new GlobalSettings() {AllowLayersWithoutProjections = true};
_shape = new Shapefile();
// use empty string to create in-memory shapefile
_shape.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
int fieldIndex = _shape.EditAddField("Name", FieldType.STRING_FIELD, 0, 20);
foreach (var place in places)
{
// convert our degrees to meters in map projection
double projX = 0.0, projY = 0.0;
axMap1.DegreesToProj(place.Lng, place.Lat, ref projX, ref projY);
// create shapes for each location
shape = new Shape();
shape.Create(ShpfileType.SHP_POINT);
shape.AddPoint(projX, projY);
// add it to shapefile along with name
shapeIndex = _shape.EditAddShape(shape);
_shape.EditCellValue(fieldIndex, shapeIndex, place.Name);
}
//sf.Labels.Generate("[Name]", tkLabelPositioning.lpCenter, true);
//sf.Labels.AvoidCollisions = false;
//sf.Labels.FontSize = 6;
layerHandle = axMap1.AddLayer(_shape, true);
//MessageBox.Show(shapeIndex.ToString());
}