Composant Delphi / Google Maps / OpenStreetMap / Leaflet  / Mappilary / Native Maps 100% Delphi 0% WebBrowser 0% Javascript

Offline mode

you are here :TECNativeMap

The tiles are first searched in the memory cache (the tiles displayed recently), the local cache, archive local then on the internet if need.

Local cache

By assigning a directory to LocalCache property internet downloaded tiles are saved locally and are available offline.

Fig. 71 My local tiles

Use the MaxDayInCache property to specify the duration of retention in the cache by default 30 days.

map.MaxDayInCache := 7; // max 7 days

Archive local

An archive local is the local cache in a Zip, this simplifies deployment of the tiles and other files.

To improve the speed, the tiles are extracted from archive and placed in the local cache during the first request, you must set a local cache to use an archive.

Fig. 72 Archive ile de ré

map.LocalCache := TPath.Combine(TPath.GetSharedDocumentsPath, 'cache');
map.TileServer := tsOSM;
map.LocalArchive := ExtractfilePath(ParamStr(0))+'ile_de_re.zip';

If roads or geolocations of addresses are saved in archive recovery is completely transparent

64
map.Routing.engine(reMapBox);
// if an archive is connected and contains the route, no internet connection is made to return the way
map.Routing.Request('saint-martin de ré', 'la couarde sur mer');

You can store your images or data files (kml, geojson etc...), to load start the name of the file by /

// load data
map.Shapes.LoadFromFile('/DATA/tdf.kml');
map.LoadFromFile('/DATA/tarbes.txt');
// load image in marker
marker.filename := '/IMAGE/node.png';

Use MapArchive to directly manipulate your archive and retrieve other data.

m := TMemoryStream.Create;
try

map.MapArchive.ReadStream('DATA/mydata.txt',m);

memo1.Lines.LoadFromStream(m);

finally
m.Free;
end;

MapArchiveCreator

This small utility allows you to create your archives, you can download areas of tiles, save routes, add images and files.

Fig. 73 MapArchiveCreator

You can ban any internet connection for the tiles and geocoding using the property OnlyLocal

65
// tiles and geocoding only uses local cache and local archive
map.onlyLocal := true;

Download full a zone

The TECDownLoadTiles class allows you to download in the background one complete zone, the EcNativeMapFiremonkeyDemo shows you how to preload the viewable area on the screen.

FECDownLoadTiles:=TECDownLoadTiles.create;

FECDownLoadTiles.OnDownLoad := doDownLoadtiles;
FECDownLoadTiles.OnEndDownLoad := doEndDownLoadtiles;

// tiles are saved in DirectoryTiles
FECDownLoadTiles.DirectoryTiles := map.LocalCache;

FECDownLoadTiles.TileServer := map.TileServer;
FECDownLoadTiles.TileSize := map.TileSize;

// download visible area from zoom+1 to MaxZoom

FECDownLoadTiles.DownLoadTiles(map.Zoom+1,map.MaxZoom,
map.NorthEastLatitude,map.NorthEastLongitude,
map.SouthWestLatitude,map.SouthWestLongitude);

...


// for abort
FECDownLoadTiles.Cancel;

// see ECNativeMapFiremokeyDemo for complete use

Make sure that your provider of tile allows it !

24

Fill the Stream of tiles

You can also directly return a stream containing the jpeg or png of your tiles, useful if you have your tiles in a database.

procedure TForm.getTileStream(var TileStream: TMemoryStream;const x, y, z: integer);
begin
// here fill the stream with your tile

end;

procedure TForm.FormCreate(Sender: TObject);
begin

map.TileServerInfo.GetTileStream := getTileStream;
map.TileServerInfo.Name := 'MyStream';
map.TileServerInfo.TileFormat := stJpeg; // or stPng
// called last, if not the first display is not performed
map.TileServer := tsOwnerDraw;

end;

Also allows to use a Server's remote tiles.

12
go to page
© 2016 ESCOT-SEP Christophe - Made width Help&Web - RSS - Google+