Serial port and GPS

OsmDld.download Method 

Downloads maps for the given coordinates.

[Visual Basic]
Public Shared Sub download( _
   ByVal aCb As OsmDldDelegate, _
   ByVal aCfg As OsmDldCfg _
)
[C#]
public static void download(
   OsmDldDelegate aCb,
   OsmDldCfg aCfg
);

Parameters

aCb
Callback function called after each downloaded map or after each error during the download.
aCfg
The download configuration containing the basename, minimum and maximum coordinates, steps, the mapnik scale, osmarender zoom, exporter, export formats etc.

Remarks

Divides the given area between minimum and maximum latitude and longitude into rectangles according to the given steps for the latitude and longitude. For each rectangle it makes then a POST request to the openstreetmap server with the URL defined in the variable URI with the following parameters:

maxlatmaximum latitude of the rectangle
minlonminimum longitude of the rectangle
maxlonmaximum longitude of the rectangle
minlatminimum latitude of the rectangle
format Selects the exporter to use. Currently it should be either osm, mapnik or osmarender. The exporter osm creates openstreetmap xml files, mapnik and osmarender are able to create jpeg or png bitmaps. In my opinion mapnik creates better exports than osmarender, but it often doesn't work.
mapnik_format Currently it should ne either png or jpeg This setting is considered only for the exporter mapnik.
osmarender_format Currently it should ne either png or jpeg. This setting is considered only for the exporter osmarender.
mapnik_scale The mapnik scale given in the configuration. This setting is considered only for the exporter mapnik.
osmarender_zoom The osmarender zoom factor. No idea about a correct value, but the height of the resulting osmarender bitmap must be maximally 2000 pixels. The higher the zoom and the bigger the area resulting from the latitude step then the higher is the resulting bitmap. For example I was able to export bitmaps using steplat 0.04 and ther osmarender zoom factor of 15. This setting is considered only for the exporter osmarender.

If the content type of the resulting web response it one of:

then the whole response is stored to a file. The name of the file results from aCfg.basename, a sequential number of the file and and a file extension suitable for the selected exporter and export type. The file name extension is:

Additionally to the downloaded bitmap or xml files the routine creates one map file, a text file with one record per line, each record consisting of the following entries:
  1. minimum longitude of the downloaded rectangle
  2. maximum latitude of the downloaded rectangle
  3. maximum longitude of the downloaded rectangle
  4. minimum latitude of the downloaded rectangle
  5. name of the file, to which the map for the rectangle was downloaded
Such a map file can be then used in classes BmpMap or BmpMaps for showing the current position within the map. Please consider, that BmpMap currently only supports bitmap formats, so it will be able to handle maps downloaded as jpeg or png, but it won't be able to recognize the osm xml files.

After each download, regardless if it was successfull or not, the method calls the given callback delegate aCb. In this delegate the user of this method can for example show the progress of the download process or evtl. error messages. If the delegate callback returns false, then the download process is interrupted.

The call to this method should result in a set of png, jpeg or osm files with map fragments according to the given parameters and in one map description file. The names of the created file start with the given basename. Both the map description file and the created bitmap files with the map fragments can be used for the initialization of the class BmpMap, so it can be used as the map definitions in the applications sgps.exe and map.exe (as long, as the xml format osm was not used).

Warning The download of the mapnik generated files from www.openstreetmap.org is very sensitive and it often ends with an error, if requested for a too large area or a scale factor resulting with a too big bitmap. If the method generates exceptions with the message text like "ContentType text/html ContentLength n" then either decrease the step values or increase the scale factor. Also downloading maps using the osmarender exporter fails, if the size of the height of the resulting bitmap will be > 2000 pixels. In this case you'll have to adapt the osmarender zoom parameter.

See Also

OsmDld Class | serial Namespace | URI