地图控件
# Smart 控件使用(地图)
此组主要显示地图显示与定位相关的控件。
# 1. TFNCMaps
此控件是地图服务的抽象层展示,可通过地图信息服务商提供的API来实现特定的地图显示的功能。
关于自定义的图形的添加方法。
- 添加折线的示例。
var
pl: TTMSFNCMapsPolyline;
har,bat: TTMSFNCMapsCoordinateRec;
begin
FThis.FNCMaps1.ClearPolylines;
har.Longitude := 49.0564068515288;
har.Latitude := 24.1373163639494;
bat.Longitude := 51.4464373615322;
bat.Latitude := 24.1401611354134;
pl := FThis.FNCMaps1.AddPolyline([har, bat],false);
pl.DataInteger := 6;
pl.StrokeColor := clGreen;
pl.StrokeWidth := 3;
FThis.FNCMaps1.AddMarkerCoordinate((har.Latitude + bat.Latitude)/2, (har.Longitude + bat.Longitude)/2,'','').DataInteger := 3;
FThis.FNCMaps1.ZoomToBoundsArray1([har,bat]);
end;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- 添加多边形的示例。
var
pg: TTMSFNCMapsPolygon;
p1, p2, p3, p4: TTMSFNCMapsCoordinateRec;
begin
FThis.FNCMaps1.ClearPolygons;
p1.Latitude := 40.768082023319;
p1.Longitude := -73.9818960428238;
p2.Latitude := 40.8005952613788;
p2.Longitude := -73.958161778013;
p3.Latitude := 40.7968781747203;
p3.Longitude := -73.9492411198608;
p4.Latitude := 40.7643144104723;
p4.Longitude := -73.9730009241094;
pg := FThis.FNCMaps1.AddPolygon([p1, p2, p3, p4], True);
pg.DataInteger := 5;
pg.StrokeColor := clBlue;
pg.StrokeWidth := 2;
pg.FillColor := clBlue;
pg.FillOpacity := 0.1;
FThis.FNCMaps1.AddMarkerCoordinate(40.7811313, -73.9687576,'','').DataInteger := 4;
FThis.FNCMaps1.ZoomToBoundsArray1([p1, p2, p3, p4]);
end;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
- 添加矩形的示例。
var
b: TTMSFNCMapsBoundsRec;
r: TTMSFNCMapsRectangle;
begin
FThis.FNCMaps1.ClearRectangles;
b.NorthEast.Latitude := 32.217;
b.NorthEast.Longitude := 110.183;
b.SouthWest.Latitude := 28.167;
b.SouthWest.Longitude := 105.283;
r := FThis.FNCMaps1.Rectangles.Add;
r.Bounds.NorthEast.Latitude := b.NorthEast.Latitude;
r.Bounds.NorthEast.Longitude := b.NorthEast.Longitude;
r.Bounds.SouthWest.Latitude := b.SouthWest.Latitude;
r.Bounds.SouthWest.Longitude := b.SouthWest.Longitude;
r.DataInteger := 1;
r.StrokeWidth := 3;
r.StrokeColor := $00848484;
r.FillColor := clGreen;
r.FillOpacity := 0.1;
FThis.FNCMaps1.AddMarkerCoordinate(29.4584295, 106.8656296,'','').DataInteger := 1;
FThis.FNCMaps1.ZoomToBoundsRec(b);
end;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
- 添加圆示例:
var
c: TTMSFNCMapsCircle;
tamboraC: TTMSFNCMapsCoordinateRec;
begin
FThis.FNCMaps1.ClearCircles;
tamboraC.Latitude := -8.24791127099354;
tamboraC.Longitude := 117.991082668304;
c := FThis.FNCMaps1.Circles.Add;
c.Radius := 1300000;
c.DataInteger := 4;
c.StrokeColor := clYellow;
c.FillColor := clYellow;
c.FillOpacity := 0.2;
c := FThis.FNCMaps1.Circles.Add;
c.Radius := 500000;
c.DataInteger := 3;
c.StrokeColor := clRed;
c.FillColor := clRed;
c.FillOpacity := 0.3;
c := FThis.FNCMaps1.Circles.Add;
c.Radius := 75000;
c.DataInteger := 2;
c.StrokeColor := clRed;
c.FillColor := clRed;
c.FillOpacity := 0.4;
FThis.FNCMaps1.AddMarkerRec(tamboraC,'','').DataInteger := 2;
FThis.FNCMaps1.SetCenterCoordinate(tamboraC);
FThis.FNCMaps1.ZoomToBounds(CreateCircle(tamboraC, 140000));
end;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 1.1. 属性
# 1.1.1. APIKey
property APIKey: UnicodeString;
用于设置APIKey,对于部分地图信息提供商,需要填写此属性后才可使用。
# 1.1.2. Circles
property Circles: TTMSFNCMapsCircles;
圆标记的管理。点击属性右侧 [...]
按钮可手动添加标记。添加的标记包含以下属性:
名称 | 说明 |
---|---|
Center | 设置圆的中心位置,指定标记的纬度与经度位置 |
FillColor | 圆所使用的填充层的颜色 |
FillOpacity | 填充层的透明度 |
Radius | 圆的半径 |
StrokeColor | 圆边线的颜色 |
StrokeOpacity | 圆边线的透明度 |
StrokeWidth | 圆边线的像素宽度 |
Visible | 是否显示 |
# 1.1.3. ElementContainer
property ElementContainer: TTMSFNCElementContainer;
通过此属性的设置,可在地图上层添加HTML与CSS元素。通过Actions 可创建自定义控件,这部分内容与地图服务相互独立,在任何地图服务下均显示为相同的效果。点击属性右侧的 [...]
按钮可手动添加。添加的元素包含以下属性:
名称 | 说明 |
---|---|
Actions | 设置执行的动作 |
HTML | 元素的HTML |
HTMLElementClass | 元素的类名称 |
HTMLElementID | 元素的ID |
# 1.1.4. Markers
property Markers: TTMSFNCMapsMarkers;
地图标记的管理。点击按钮可手动添加标记。添加的标记包含以下属性:
名称 | 说明 |
---|---|
IconURL | 如使用自定义图标,则在此处指定自定义图标的URL |
Latitude | 指定标记所在的纬度 |
Longtitude | 指定标记所在的经度 |
Title | 标记的标题信息 |
Visible | 标记是否可见 |
# 1.1.5. Polygons
property Polygons: TTMSFNCPolygons;
多边形标记的管理,点击属性右侧的 [...]
可手动添加标记。添加的标记包含以下属性:
名称 | 说明 |
---|---|
Coordinates | 多边形的角所在的经纬度位置 |
FillColor | 填充层的颜色 |
FillOpacity | 填充层的透明度 |
StrokeColor | 边线的颜色 |
StrokeOpacity | 边线的透明度 |
StrokeWidth | 边线的像素宽度 |
Visible | 是否显示 |
# 1.1.6. Polylines
property Polylines: TTMSFNCPolylines;
折线标记的管理,点击点击属性右侧的 [...]
可手动添加标记。添加的标记包含以下属性:
名称 | 说明 |
---|---|
Coordinates | 折线的端点所在的经纬度位置 |
StrokeColor | 边线的颜色 |
StrokeOpacity | 边线的透明度 |
StrokeWidth | 边线的像素宽度 |
Visible | 是否显示 |
# 1.1.7. Rectangles
property Rectangles: TTMSFNCRectangles;
矩形标记的管理,点击点击属性右侧的 [...]
可手动添加标记。添加的标记包含以下属性:
名称 | 说明 |
---|---|
Bounds | 设置定位边线的坐标位置,需为 NorthEast 与 SouthWest 设置经纬度位置。 |
FillColor | 填充层的颜色 |
FillOpacity | 填充层的透明度 |
StrokeColor | 边线的颜色 |
StrokeOpacity | 边线的透明度 |
StrokeWidth | 边线的像素宽度 |
Visible | 是否显示 |
# 1.1.8. Service
property Service: TTMSFNCMapsService;
设置地图服务的提供商。您可以在程序中动态切换地图服务提供商,动态切换后,已设置的标记、折线、多边形等仍然会保留。但是定位信息与缩放等会恢复至默认设置。可选项目如下:
名称 | 说明 |
---|---|
msAzureMaps | Azure 地图 |
msBingMaps | Bing 地图 |
msGoogleMaps | Google 地图 |
msHere | Here 地图 |
msMapBox | MapBox 地图 |
msMapKit | MapKit 地图 |
msOpenLayers | OpenLayers 地图 |
msTomTom | TomTom 地图 |
# 1.2. 方法
# 1.2.1. BeginUpdate
procedure BeginUpdate;
开始执行更新。
# 1.2.2. EndUpdate
procedure EndUpdate;
结束更新。
# 1.2.3. AddMarkerRec
function AddMarkerRec(var ACoordinate: TTMSFNCMapsCoordinateRec;ATitle: UnicodeString;AIconURL:UnicodeString): TTMSFNCOpenLayersMarker;
在地图的指定位置添加标记。
var
Coordinate: TTMSFNCMapsCoordinateRec;
begin
Coordinate.Logtitude := 49.0564068515288;
Coordinate.Latitude := 24.1373163639494;
FThis.FNCMaps1.AddMarkerRec(Coordinate,'','');
end;
2
3
4
5
6
7
# 1.2.4. AddMarkerCoordinate
function AddMarkerCoordinate(ALatitude: Double; ALongtitude: Double; ATitle: UnicodeString; AIconURL: UnicodeString): TTMSFNCOpenLayersMarker;
直接指定标记位置,进行标记添加。
FThis.FNCMaps1.AddMarkerCoordinate(49.05,24.13,'','');
# 1.2.5. ClearMarkers
procedure ClearMarkers;
清除所有的地图标记。
# 1.2.6. ClearPolyLines
procedure ClearPolyLines;
清除所有的折线标记。
# 1.2.7. ClearPolygons
procedure ClearPolygons;
清除所有的多边形标记。
# 1.2.8. ClearRectangles
procedure ClearRectangles;
清除所有矩形标记。
# 1.2.9. ShowPopup
function ShowPopup(var ACoordinate: TTMSFNCMapsCoordinateRec;AText: UnicodeString; AOffsetX: Double; AOffserY: Double): UnicodeString:
设置显示弹出式窗口。
# 1.2.10. SetZoomLevel
procedure SetZoomLevel(AZoomLevel: Double);
设置地图的缩放级别。
# 2. TFNCOpenLayers
TFNCOpenLayers 继承于 TFNCMaps,并公开了特定于 OpenLayers API 的额外功能。如需要了解此组件的通用属性、事件与方法,请参考 TFNCMaps。
# 2.1. TileServer
当使用此组件时,您可以指定自定义的瓦片图层服务器,可在 Options.TileServer
中进行指定。
# 2.1.1. TileLayers
您可以指定切片图层列表以显示地图图层的顶部。TileLayers 具有 URL 值和可选 Opacity 值的 tilelayers 集合。
# 2.1.2. 折线与多边形标签
您可以为折线和多边形指定标签文本。 默认情况下,标签文本显示在折线的中心。可指定的内容属性如下:
名称 | 描述 |
---|---|
Label.Text | 设置标签文本 |
Label.FontColor | 设置标签文本的的字体颜色 |
Label.FontSize | 设置标签文本的字体大小 |
Label.OffsetX | 设置标签在X方向上的偏移量 |
Label.OffsetY | 设置标签在Y方向上的偏移量 |
# 3. TFNCGeocoding
此组件用于执行地址地理编码或者坐标反向地理编码。
# 3.1. 属性
# 3.1.1. APIKey
property APIKey: UnicodeString;
用于设置APIKey,对于部分地图信息提供商,需要填写此属性后才可使用。
# 3.1.2. GeocodingRequests
property GeocodingRequests: TTMSFNCGeocodingRequests;
设置地理信息编码请求的项目。
# 3.1.3. Service
property Service: TTMSFNCMapsService;
设置地理编码信息服务的提供商。可选项目有 gsAzure
、gsBing
、gsGeoApify
、gsGoogle
、gsHere
、gsMapBox
、gsOpenRoute
、gsOpenStreetMap
。
# 3.2. 事件
事件名称 | 触发方式 |
---|---|
OnGetGeocoding | 调用 GetGeocoding 后触发。 包含地理编码操作的结果。 ARequest.Status 和 ARequest.ErrorMessage 值可用于查看所选服务返回的状态和错误消息(如果有)。 在多个地理编码调用的情况下,ARequest.ID 值可用于确定结果与哪个调用相关联。 从请求返回的数据可以在 ARequest.Items 集合中找到。 |
OnGetReverseGeocoding | 调用 GetReverseGeocoding 后触发。 包含反向地理编码操作的结果。 ARequest.Status 和 ARequest.ErrorMessage 值可用于查看所选服务返回的状态和错误消息(如果有)。 在多个 GetReverseGeocoding 调用的情况下,ARequest.ID 值可用于确定结果与哪个调用相关联。 从请求返回的数据可以在 ARequest.Items 集合中找到。 |
OnGetGeocodingResult | 调用 GetGeocoding 后触发。 包含地理编码操作的结果。 从请求返回的数据可以在 AResult.Items 集合中找到。 |
OnGetReverseGeocodingResult | 调用 GetReverseGeocoding 后触发。 包含反向地理编码操作的结果。 从请求返回的数据可以在 AResult.Items 集合中找到。 |
# 3.3. 方法
# 3.3.1. GetGeocodingAddress
procedure GetGeocodingAddress(AAddress: UnicodeString; AID: UnicodeString; ADataPointer: Pointer; AMode: TTMSFNCMapsLocaleMode);
获取指定位置的地理地点信息。