I have a SQLite database that has my label names and the lat & long, I am using a while db reader to get the name, lat and long from the database, with each iteration I am calling the method below to put the pins on the map.
I clear the layer and cycle through the 100+ records and rewrite the pins every 20 seconds, but I am bleeding memory with each cycle …maybe 250kb but it adds up over time…clearly I am not handling this correctly…
Any guidance would be appreciated.
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};
var sf = new Shapefile();
// use empty string to create in-memory shapefile
sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
int fieldIndex = sf.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
var shape = new Shape();
shape.Create(ShpfileType.SHP_POINT);
shape.AddPoint(projX, projY);
// add it to shapefile along with name
int shapeIndex = sf.EditAddShape(shape);
sf.EditCellValue(fieldIndex, shapeIndex, place.Name);
}
sf.Labels.Generate("[Name]", tkLabelPositioning.lpCenter, true);
sf.Labels.AvoidCollisions = false;
sf.Labels.FontSize = 6;
layerHandle = axMap1.AddLayer(sf, true);
}