Map
TsgcHTMLComponent_Map — 渲染一个交互式 Leaflet.js 地图,带有 OpenStreetMap 或 CartoDB 瓦片以及您自己的标记、弹出框和工具提示,适用于 Delphi、C++ Builder 和 .NET。
TsgcHTMLComponent_Map — 渲染一个交互式 Leaflet.js 地图,带有 OpenStreetMap 或 CartoDB 瓦片以及您自己的标记、弹出框和工具提示,适用于 Delphi、C++ Builder 和 .NET。
一个地图组件,发出 Leaflet.js 地图容器以及初始化它的脚本。设置中心点、缩放和瓦片提供商,添加标记,然后读取 HTML 属性。
设置 CenterLatitude、CenterLongitude 和 Zoom,选择 TileProvider,为每个点调用 AddMarker,然后读取 HTML。
uses
sgcHTML_Enums, sgcHTML_Component_Map;
var
oMap: TsgcHTMLComponent_Map;
begin
oMap := TsgcHTMLComponent_Map.Create(nil);
try
oMap.CenterLatitude := 40.4168;
oMap.CenterLongitude := -3.7038;
oMap.Zoom := 12;
oMap.Height := '420px';
oMap.TileProvider := mtCartoDB;
oMap.AddMarker(40.4168, -3.7038, 'Madrid', 'Head office');
oMap.AddMarker(41.3851, 2.1734, 'Barcelona');
WebModule.Response := oMap.HTML; // Leaflet map + markers
finally
oMap.Free;
end;
end;
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Map.hpp
TsgcHTMLComponent_Map *oMap = new TsgcHTMLComponent_Map(NULL);
try
{
oMap->CenterLatitude = 40.4168;
oMap->CenterLongitude = -3.7038;
oMap->Zoom = 12;
oMap->Height = "420px";
oMap->TileProvider = mtCartoDB;
oMap->AddMarker(40.4168, -3.7038, "Madrid", "Head office");
oMap->AddMarker(41.3851, 2.1734, "Barcelona");
String html = oMap->HTML; // Leaflet map + markers
}
__finally
{
delete oMap;
}
using esegece.sgcWebSockets;
var map = new TsgcHTMLComponent_Map();
map.CenterLatitude = 40.4168;
map.CenterLongitude = -3.7038;
map.Zoom = 12;
map.Height = "420px";
map.TileProvider = TsgcHTMLMapTileProvider.mtCartoDB;
map.AddMarker(40.4168, -3.7038, "Madrid", "Head office");
map.AddMarker(41.3851, 2.1734, "Barcelona");
string html = map.HTML; // Leaflet map + markers
您最常使用的成员。
CenterLatitude 和 CenterLongitude(Double)设置初始视图;Zoom(默认 13)设置缩放级别。
TileProvider(TsgcHTMLMapTileProvider)选择 mtOpenStreetMap、mtCartoDB(明亮)或 mtCartoDBDark。
Markers(TsgcHTMLMapMarkers)保存这些图钉;每个 TsgcHTMLMapMarker 都有 Latitude、Longitude、PopupText、TooltipText 和 Color。
AddMarker(aLat, aLng, aPopup, aTooltip) 放置一个图钉;弹出框在点击时打开,工具提示在悬停时显示。
Height(如 '420px' 之类的 CSS 长度)控制地图高度;MapID 设置容器的元素 id。
HTML 返回 Leaflet 样式表链接、地图 <div> 和初始化脚本 — 直接提供服务,或将其赋给页面模板的 BodyContent。