Tms Webosmaps For Firemonkey: Developers Guide
Tms Webosmaps For Firemonkey: Developers Guide
June 2016
Copyright 2016 by tmssoftware.com bvba
Web: http://www.tmssoftware.com
Email: info@tmssoftware.com
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Table of contents
Introduction .............................................................................................................................................3
Availability ................................................................................................................................................3
Terms of use .............................................................................................................................................4
Windows support .....................................................................................................................................5
List of included components ....................................................................................................................6
Online references .....................................................................................................................................6
TMSFMXWebOSMaps description ...................................................................................................... 7
TMSFMXWebOSMaps features ........................................................................................................... 7
TMSFMXWebOSMaps architecture..................................................................................................... 8
TMSFMXWebOSMaps use ................................................................................................................... 8
Getting started ................................................................................................................................ 9
General map settings ........................................................................................................................ 11
TMSFMXWebOSMaps.MapOptions properties ............................................................................ 11
Map markers ..................................................................................................................................... 12
Adding markers ............................................................................................................................. 12
TMSFMXWebOSMaps.Markers properties ................................................................................... 13
Map polygons .................................................................................................................................... 14
Adding polygons ............................................................................................................................ 15
TMSFMXWebOSMaps.Polygons properties .................................................................................. 16
Map polylines .................................................................................................................................... 18
Adding polylines ............................................................................................................................ 18
TMSFMXWebOSMaps.Polylines properties .................................................................................. 20
Maps ControlsOptions....................................................................................................................... 21
TMSFMXWebOSMaps.ControlsOptions properties ...................................................................... 21
Maps methods................................................................................................................................... 24
WebOSMaps events .......................................................................................................................... 25
TMSFMXWebOSMaps demo ............................................................................................................. 28
Main screen: .................................................................................................................................. 28
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Introduction
The TMSFMXWebOSMaps is a component that allows integration of the OpenStreetMaps road map
control. TMSFMXWebOSMaps offers pan, zoom and scale control.
In this document you will find an overview of the TMSFMXWebOSMaps component and its features,
code snippets to quickly start using the component and overviews of properties, methods and
events.
Availability
TMS WebOSMaps for FireMonkey is a set of components for FireMonkey application development
and is available for Embarcadero Delphi XE8 & C++Builder XE8 or newer releases.
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Terms of use
With the purchase of TMSFMXWebOSMaps, you are entitled to our consulting and support services
to integrate the OpenStreetMaps service in FireMonkey for FireMonkey applications and with this
consulting and support comes the full source code needed to do this integration. As
TMSFMXWebOSMaps uses the OpenStreetMaps and OpenLayers services, you're bound to the terms
of these services that can be found at:
http://www.openstreetmap.org/copyright
TMS software is not responsible for the use of TMSFMXWebOSMaps. The purchase of
TMSFMXWebOSMaps does not include any license fee that you might possibly be required to pay to
OpenStreetMaps/OpenLayers. It will depend on your type of usage of the
OpenStreetMaps/OpenLayers services whether a license fee needs to be paid to
OpenStreetMaps/OpenLayers.
It is the sole responsibility of the user or company providing the application that integrates the
OpenStreetMaps/OpenLayers services to respect the OpenStreetMaps/OpenLayers terms and
conditions. TMS software does not take any responsibility nor indemnifies any party violating the
OpenStreetMaps/OpenLayers services terms & conditions.
Limited warranty
TMS software cannot guarantee the current or future operation & uptime of the
OpenStreetMaps/OpenLayers services. TMS software offers the consulting and support for
TMSFMXWebOSMaps in good faith that the OpenStreetMaps/OpenLayers services are reliable and
future-proof services. In no case, TMS software shall offer refunds or any other compensation in case
the OpenStreetMaps/OpenLayers services terms/operation change or stop.
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Windows support
Windows support in the TMS WebOSMaps for FireMonkey is based on the Delphi Chromium
Embedded opensource library and can be installed and compiled by following the steps below.
1) Download and Extract http://www.tmssoftware.biz/download/ChromiumFMX.zip
2) Open the package ChromiumFMX.dpk, compile and then install the package.
3) Add the directory where the ChromiumFMX source is located to your Win32 library path in the IDE
(ceffmx.pas, ceflib.pas, ...)
4) Navigate to the directory where the TMS WebOSMaps for FireMonkey source is installed.
5) Open the file FMX.TMSWebOSMapsWebBrowser.Win and comment the line {$DEFINE
CHROMIUMOFF}
6) Copy the files inside the lib directory from the extracted ChromiumFMX.zip file to the directory
where your application executable is or will be located.
7) Create or open a new or existing project and build your project.
Our browser solution for the Windows target is only available in the registered version of TMS
WebOSMaps for FireMonkey. Windows is not supported in the trial version.
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Online references
TMS software website:
http://www.tmssoftware.com
TMS TMSFMXWebOSMaps page:
http://www.tmssoftware.com/site/tmsfmxwebosmaps.asp
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
TMSFMXWebOSMaps
TMSFMXWebOSMaps description
TMSFMXWebOSMaps features
Position markers can be added to the maps. Markers can be default balloons or custom
images.
Markers is a collection of positions that are indicated on the map. Markers are based on
longitude and latitude coordinates.
A custom label text can optionally be displayed on top of a Marker, polyline or polygon or
anywhere on the map.
Polylines is a collection of lines that are displayed on the map. Polylines are based on a list of
longitude and latitude coordinates.
Polygons is a collection of closed lines with a filled region that are displayed on the map.
Polygons are based on a list of longitude and latitude coordinates (for Polygons of type
ptPath), a center point and radius (for Polygons of type ptCircle) or two longitude and
latitude coordinates (for Polygons of type ptRectangle).
Different controls are available and can be turned on or off. LayerSwitcher, OverViewMap
control, PanZoom control, Scale control and MousePosition. The position on the screen of
the control as well as the visibility can be defined.
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
TMSFMXWebOSMaps architecture
The core part of the TMS WebOSMaps for FireMonkey is the TMSFMXWebOSMaps control, a VCL
component integrating the Internet Explorer browser and exposing properties, methods and events
to control OpenStreetMaps using the OpenLayers service. Additional OpenLayers controls can be
optionally enabled on the map, i.e. a PanControl (1), a ZoomControl (2), a ScaleControl (3), a
LayerSwitcherControl (4), a MousePosition (5) and an OverviewmapControl (6).
Different markers (7) can be added to display preferred locations. The marker can display a default
balloon or when a valid URL is provided, an image or icon is displayed.
Various events are triggered when the user interacts with the map.
TMSFMXWebOSMaps use
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Getting started
From the component palette, select TMSFMXWebOSMaps and drop it on a form. This shows the map
at the default location. The default center location is set by:
TMSFMXWebOSMaps.MapOptions.DefaultLongitude,
TMSFMXWebOSMaps.MapOptions.DefaultLatitude.
Markers can be added to the map by adding a new entry to the collection
TMSFMXWebOSMaps.Markers and setting the Markers properties Longitude & Latitude.
This code snippet sets up the default view of the TMSFMXWebOSMaps to show the Los Angeles
Theatre on Broadway at zoom level:
begin
// center the map at the coordinate
TMSFMXWebOSMaps1.MapOptions.DefaultLatitude := 34.04;
TMSFMXWebOSMaps1.MapOptions.DefaultLongitude := -118.25;
// Add a marker for the Los Angeles theatre
TMSFMXWebOSMaps1.Markers.Add(WebOSMaps1.MapOptions.DefaultLatitude,
TMSFMXWebOSMaps1.MapOptions.DefaultLongitude,'Broadway theatre');
// set zoom level
TMSFMXWebOSMaps1.MapOptions.ZoomMap := 14;
end;
end;
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
10
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
DefaultLatitude: Sets the latitude value for the default position of the map.
DefaultLongitude: Sets the longitude value for the default position of the map.
Draggable: When set to true, the entire map can be moved around in the control.
ImageURL: Defines the path to the image used for the OpenLayers controls. If no path is
LanguageURL: Defines the path to the JavaScript file that contains the text values in a
ScriptURL: Defines the path to the OpenLayers.js file used by the OpenLayers service. If no
path is specified the default JavaScript file from the OpenLayers.org server is used.
-
StyleURL: Defines the path to Style.css file used by the OpenLayers service. If no path is
specified the default JavaScript file from the OpenLayers.org server is used.
-
ZoomMap: Is to be used to set the default zoom at startup. The zoom value is a value
11
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Map markers
TMarkers is a collection of marker items giving the possibility to highlight certain locations on the
map. A marker is either a default balloon or can be set to a custom icon by defining the URL for it.
The example below shows a mix of pictures and a standard Google balloon marker. A sample on how
to create a marker info window can be found in the samples paragraph.
On the left hand side, a PNG image is used as marker. In the middle section, a JPEG image is
displayed as marker. On the right hand side, a standard OpenLayers balloon marker is used, as the
marker was created with an empty icon property.
Adding markers
First open the markers collection editor by clicking the TMSFMXWebOSMaps.Markers property in the
Object Inspector. From here, markers can be added or removed.
12
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
TMSFMXWebOSMaps.Markers properties
Draggable: When set to true, the marker can be moved around the map when dragged.
13
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Icon: Allows the use of an image as marker. This can also be a picture when the url to that
image is defined. An example can be found in the samples paragraph.
Map polygons
14
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Adding polygons
First open the polygons collection editor by clicking the TMSFMXWebOSMaps.Polygons property in
the Object Inspector. From here, polygons can be added or removed.
uses
UWebOSMapsPolygons;
var
Circle: TMapPolygon;
PolygonItem: TPolygonItem;
begin
PolygonItem := TMSFMXWebOSMaps1.Polygons.Add;
Circle := PolygonItem.Polygon;
Circle.PolygonType := ptCircle;
Circle.BackgroundOpacity := 50;
Circle.BorderWidth := 2;
Circle.Radius := 75000;
Circle.Center.Latitude := 48.86;
Circle.Center.Longitude := 2.35;
Circle.LabelText := 'Paris';
Circle.LabelFont.Color := clRed;
15
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Circle.LabelFont.Size := 18;
Circle.LabelFont.Style := [fsBold];
Circle.LabelOffset.Y := 30;
TMSFMXWebOSMaps1.CreateMapPolygon(Circle);
end;
Editing a polygon:
TMSFMXWebOSMaps1.Polygons[0].Polygon.Visible := not
TMSFMXWebOSMaps1.Polygons[0].Polygon.Visible;
TMSFMXWebOSMaps1.UpdateMapPolygon(WebOSMaps1.Polygons[0].Polygon);
Removing a polygon:
TMSFMXWebOSMaps1.DeleteMapPolygon(Index);
TMSFMXWebOSMaps.Polygons properties
NorthEast: Sets the latitude/longitude of the north east corner of the rectangle
Latitude
Longitude
SouthWest: Sets the latitude/longitude of the south west corner of the rectangle
Latitude
Longitude
Center: Sets the latitude/longitude of the center point of the circle when PolygonType is set
to ptCircle.
16
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Latitude
Longitude
LabelFont: The font name used for the label text. The label is displayed based on the
LabelFont.Color, LabelFont.Name, LabelFont.Size and LabelFont.Style.fsBold settings.
LabelText: The text displayed in the label. If this value is empty, no label is displayed.
Path: The ordered sequence of coordinates of the polygon that forms a closed loop (when
PolygonType is set to ptPath). Paths are closed automatically.
Latitude: Sets the latitude value of the polygon path item on the map.
Longitude: Sets the longitude value of the polygon path item on the map.
ptCircle: Renders a circle based on the Radius and Center property values.
Radius: The radius of the polygon in meters. (When PolygonType is set to ptCircle)
17
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Map polylines
Adding polylines
First open the polylines collection editor by clicking the TMSFMXWebOSMaps.Polylines property in
the Object Inspector. From here, polylines can be added or removed.
18
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
19
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
end;
Editing a polyline:
TMSFMXWebOSMaps1.Polylines[0].Polyline.Visible := not
TMSFMXWebOSMaps1.Polylines[0].Polyline.Visible;
TMSFMXWebOSMaps1.UpdateMapPolyline(WebOSMaps1.Polylines[0].Polyline);
Removing a polyline:
TMSFMXWebOSMaps1.DeleteMapPolyline(Index);
TMSFMXWebOSMaps.Polylines properties
LabelFont: The font name used for the label text. The label is displayed based on the
LabelFont.Color, LabelFont.Name, LabelFont.Size and LabelFont.Style.fsBold settings.
LabelText: The text displayed in the label. If this value is empty, no label is displayed.
Latitude: Sets the latitude value of the polyline path item on the map.
Longitude: Sets the longitude value of the polyline path item on the map.
20
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Maps ControlsOptions
The ControlsOptions class property bundles various settings for controlling the appearance and
behaviour of various controls in the map.
TMSFMXWebOSMaps.ControlsOptions properties
-
LayerSwitcherControl: Defines the settings for layer switcher control. This control allows to
Left: The left position of the control in pixels. If the value is -1 the controls is
Top: The top position of the control in pixels. If the value is -1 the controls is
OverviewMapControl: Defines the settings for the overview map control that shows a larger
area, with the actual view displayed inside a red dotted line. When holding the mouse down
in this area, and moving within the overviewmap control, the map can be panned to another
location.
21
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Left: The left position of the control in pixels. If the value is -1 the controls is
Top: The top position of the control in pixels. If the value is -1 the controls is
PanZoomControl:
o
Sets the pan control that allows panning the actual view of the map within the
control, by clicking the arrow keys (up, down, left, right).
Defines the settings for the Zoom control that allows to zoom in on the actual view
of the map, or to zoom out to a larger area. The center position on the screen is used
as zooming location.
22
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Left: The left position of the control in pixels. If the value is -1 the controls is
Top: The top position of the control in pixels. If the value is -1 the controls is
ScaleControl: Defines the settings for the Scale control that shows the actual scale of the
Left: The left position of the control in pixels. If the value is -1 the controls is
Top: The top position of the control in pixels. If the value is -1 the controls is
23
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
MousePosition: Defines the settings for the MousePosition control that displays the
longitude and latitude coordinates of the location that the mouse cursor is hovering.
Left: The left position of the control in pixels. If the value is -1 the controls is
PrefixText: The prefix text used in front of the mouse position coordinates.
Top: The top position of the control in pixels. If the value is -1 the controls is
Maps methods
This function performs a pan to a location set by latitude and longitude coordinates. This is
useful to set a certain position in the center of the control canvas.
-
24
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
This function performs a zoom to fit the map inside the given bounds coordinates.
WebOSMaps events
OnDownloadFinish(Sender: TObject):
Event triggered when the map is clicked. Returns the latitude and longitude coordinates of
that position, the X and Y values indicate the pixel coordinates in the control window.
-
Event triggered when the entire map is moved within the control.
-
OnMapMoveEnd(Sender: TObject):
Event triggered at the end of an entire map move within the control.
-
OnMapMoveStart(Sender: TObject):
Event triggered at the start of an entire map move within the control.
-
OnMapMoveStart(Sender: TObject):
Event triggered when the zoom level is changed via any type of the zoom control. The event
returns the selected zoom level.
-
Event triggered when a marker is dragged around the control. The event returns the marker
id, latitude and longitude coordinates of the selected marker.
-
25
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Event triggered at the end of when a marker is dragged in the control. The event returns the
marker id, latitude and longitude coordinates of the selected marker.
-
Event triggered at the start of when a marker is dragged in the control. The event returns the
marker id, latitude and longitude coordinates of the selected marker.
-
Event triggered when a polyline is clicked. The event returns the polyline id.
-
Event triggered when a polygon is clicked. The event returns the polygon id.
-
Event triggered when an error is received. This event returns the error type.
26
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
Sample 1
This example shows how to add a transparent circle polygon to the map with a custom label text.
Var
PolygonItem: TPolygonItem;
Circle: TMapPolygon;
Begin
PolygonItem := TMSFMXWebOSMaps1.Polygons.Add;
Circle := PolygonItem.Polygon;
Circle.LabelText := Circle Polygon;
Circle.PolygonType := ptCircle;
Circle.BackgroundOpacity := 50;
Circle.BorderWidth := 2;
Circle.Radius := 75000;
Circle.Center.Latitude := 48;
Circle.Center.Longitude := 2;
TMSFMXWebOSMaps1.CreateMapPolygon(Circle);
end;
27
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
TMSFMXWebOSMaps demo
The TMS WebOSMaps for FireMonkey Demo program shows the various configuration possibilities of
the TMSFMXWebOSMaps component. It allows to interactively set various properties and the
changes will be immediately reflected in the map.
Main screen:
Note that a selection of asynchronous events that occur are displayed in the top right of the screen.
Markers menu
28
TMS SOFTWARE
TMS WebOSMaps for FireMonkey
DEVELOPERS GUIDE
From here a marker can be set at specific latitude/longitude coordinates or via the OnMapClick
event. All markers can be deleted.
Polygons menu
From here a Line, Circle or Square polygon can be added at a latitude/longitude coordinate. All
polygons can be deleted.
Options menu
From here the visibility of the various controls on the TMSFMXWebOSMaps can be set.
29