| ImageEn, unit iexVirtualBitmaps |
|
TIESlippyMap
Properties · Methods · Events · Demos · Examples
Declaration
TIESlippyMap = class(TIEVirtualBitmapProvider);
Description
Slippy Map is a term referring to the main openstreetmap.org map display, a web interface for browsing rendered OpenStreetMap data (from openstreetmap wiki).
For more detail:
wiki.openstreetmap.org/wiki/Slippy_Map
TIESlippyMap is a virtual image provider for
TIEBitmap objects. Selecting a position using Latitude and Longitude a map (an image) will be loaded and handled as TIEBitmap content.
Local caching is provided to speed up re-loading tiles and to support off-line jobs.
| Demos\InputOutput\GeoMaps\GeoMaps.dpr |
| Demos\ImageEditing\EveryMethod\EveryMethod.dpr |
ImageEnView1.IEBitmap.VirtualBitmapProvider := TIESlippyMap.Create();
with TIESlippyMap(ImageEnView1.IEBitmap.VirtualBitmapProvider) do
begin
// move to London
Latitude := 51.503614574056016;
Longitude := -0.12774750793460043;
// location at bitmap center
PointPosition := Point(ImageEnView1.IEBitmap.Width div 2, ImageEnView1.IEBitmap.Height div 2);
// zoom
Zoom := 14;
end;
ImageEnView1.Update();
// Save an image with pins drawn for GPS coordinates
const
Pin_Width = 40;
Pin_Height = 40;
var
i: integer;
idx: integer;
lat, lon: double;
x, y: integer;
fn: string;
begin
// Prompt for a filename
fn := ImageEnView1.IO.ExecuteSaveDialog();
if fn = '' then
exit;
// Hide changes from view
ImageEnView1.LockUpdate();
try
// Add pins as shape layers
for i := 0 to ImageEnMView1.MultiSelectedImagesCount - 1 do
begin
idx := ImageEnMView1.MultiSelectedImages[i];
lat := ImageEnMView1.MIO.Params[idx].EXIF_GPSLatitude;
lon := ImageEnMView1.MIO.Params[idx].EXIF_GPSLongitude;
x := map.LongitudeToBmpX(lon);
y := map.LatitudeToBmpY(lat);
ImageEnView1.LayersAdd( iesPinLeft, x, y - Pin_Height, Pin_Width, Pin_Height );
end;
// Save current image + layers to file
ImageEnView1.LayersSaveMergedTo( fn );
// Clean up
ImageEnView1.LayersClear(False);
finally
// Reenable ImageEnView1
ImageEnView1.UnlockUpdate();
end;
end;
// Show map as editable image (not-virtual)
bmp := TIEBitmap.Create( 500, 500, clWhite );
map := TIESlippyMap.Create();
try
bmp.VirtualBitmapProvider := map;
// move to London
map.Latitude := 51.503614574056016;
map.Longitude := -0.12774750793460043;
map.PointPosition := Point(bmp.Width div 2, bmp.Height div 2); // location at bitmap center
map.Zoom := 14;
ImageEnView1.Assign( bmp );
finally
bmp.Free();
// Note: Don't need to free map as bmp will free it automatically
end;
// Save a map with a Pin on London
const
Map_Provider = iesmpOSM_Mapnik;
Map_Width = 400;
Map_Height = 400;
Map_Latitude = 51.503614574056016; // London
Map_Longitude = -0.12774750793460043;
Map_Zoom = 9; // 4 - 18
Pin_Size = 40;
var
bmpMap, bmpOut: TIEBitmap;
map: TIESlippyMap;
begin
bmpMap := TIEBitmap.Create( Map_Width, Map_Height, clWhite );
bmpOut := TIEBitmap.Create();
map := TIESlippyMap.Create( Map_Provider );
try
bmpMap.VirtualBitmapProvider := map;
map.Latitude := Map_Latitude;
map.Longitude := Map_Longitude;
map.PointPosition := Point( bmpMap.Width div 2, bmpMap.Height div 2 ); // location at bitmap center
map.Zoom := Map_Zoom;
bmpOut.Assign( bmpMap );
// Draw pin at center of image
bmpOut.IECanvas.Pen.Color := clBlack;
bmpOut.IECanvas.Pen.Width := 1;
bmpOut.IECanvas.Brush.Color := clRed;
// Want bottom-left of shape at center
bmpOut.IECanvas.DrawShape( bmpOut.Width div 2, bmpOut.Height div 2 - Pin_Size, bmpOut.Width div 2 + Pin_Size, bmpOut.Height div 2, iesPinLeft );
bmpOut.SaveToFile( 'D:\London.jpg' );
finally
bmpMap.Free();
bmpOut.Free();
// Note: Don't need to free map as bmpMap will free it automatically
end;
end;

Generic Rendering
TIEVirtualBitmapProvider rendering
Multithreading and Cache
Map Coordinates and Zooming
Coordinates Conversion
Other