Gianmaria
09-07-2006, 09:31 AM
Hi,
a question:
I have to trace a full route made of lat/lon positions over the map. Numer of points may vary from 1 to much more as 30.000 or more.
I use this code cycling on a datatable:
MapPoint.Pushpin pushpin = this.mMap.AddPushpin(this.mMap.GetLocation(Convert .ToDouble(lat]), Convert.ToDouble(lon), 1), Convert.ToDateTime(theTime).ToLocalTime().ToString ());
pushpin.Symbol = 133;
problem is that this operation is very slow on plotting.....
any idea to make it faster?
Regards,
Gianmaria
Wilfried
09-07-2006, 01:01 PM
Hi,
You can speed up a little to not do the conversions whilst plotting but to convert when you got the data before you store it, however the main slowness is the plotting itself.
I suggest to only display what needed. Nobody can see thousands of pushpins on a map, so you can display only what is in view and eventually depending on zoom level. I mean if zoom level is so that all 30000 pushpins are in view, you can as wel display 100, nobody will see the difference. If zomming in then you display waht is in view etc.
Needs a little thinking and a some smart algoritm to do this but sure to do.
masty
09-08-2006, 02:17 PM
Hi Gianmaria,
I also need to plot a large number of pushpins in a map. I found this solution which increase a lot the speed of drawing pushpins. Anyway I also use the trick suggested by Wilfried.. only plot the points that really need.
The first suggestion is: don't use the AddPushPin method... it's good for a very few number of pushpins... otherways it takes too much time.
Use the ImportData method as shown in the follow example:
I suppose to have a DataTable (dt) with two columns. The first contains the Latitude, the second the Longitude as double data type.
From the DataTable I create first a CSV file, which consists in a list of rows with Latitude and Longitude separated by a semicolon.
Then I create a MapPoint DataSet object with the Method ImportData.
Finally I choose the symbol of the PushPins.
Hope this helps.
Everything can go faster if you use a RamDisk to save/read the CSV.
If you want to know the alghortim I used to decide which and how many points are anough for the users... just ask me.
DataRow dr;
//Write the CSV file.
//Open the file in the application path.
TextWriter txtw = new StreamWriter(Path.GetDirectoryName(Assembly.GetExe cutingAssembly().GetModules()[0].FullyQualifiedName) +
"\\temp.csv",false);
//Write the Column Header
txtw.WriteLine("Lat;Lon");
for (int k=0;k<dt.Rows.Count; k++)
{
dr = dt.Rows[k];
Lat = (double) dr["Lat"];
Lon =(double) dr["Lon"];
txtw.WriteLine(Lat.ToString()+";"+Lon.ToString());
}
txtw.Close();
MapPoint.DataSet oDS;
//Define field specification
object[,] fieldSpecifications = null;
fieldSpecifications = new object[2,2];
//Specify what fields are geographic and what fields are not
fieldSpecifications[0,0] = "Lat";
fieldSpecifications[0,1] = MapPoint.GeoFieldType.geoFieldLatitude;
fieldSpecifications[1,0] = "Lon";
fieldSpecifications[1,1] = MapPoint.GeoFieldType.geoFieldLongitude;
oDS = map.DataSets.ImportData(Path.GetDirectoryName(Asse mbly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName) + "\\temp.csv",
fieldSpecifications,
MapPoint.GeoCountry.geoCountryItaly,
MapPoint.GeoDelimiter.geoDelimiterSemicolon, 0);
oDS.Symbol = 37;