SNEL STARTEN
Een kaart in een paar regels
Dezelfde API in Delphi, C++ Builder en C#: OpenStreetMap-tiles, drie markers, een geodetische lijn en een straal, aangepast aan de markers en opgeslagen als PNG.
Een VCL-kaart in code gebouwd: een gecachete OpenStreetMap-laag, markers, een geodetische lijn en een cirkel, daarna een PNG van het resultaat.
uses
SysUtils, Controls, Graphics, sgcMaps_Classes, sgcMaps_Providers,
sgcMaps_Geometry, sgcMaps_VCL;
// OpenStreetMap with cached tiles, three capitals, a geodesic flight line
// and a 300 km radius, fitted to the markers and saved as PNG.
procedure BuildMap(aOwner: TWinControl);
var
oMap: TsgcVCLMap;
oLayer: TsgcMapLayer;
oLine: TsgcMapPolyline;
begin
oMap := TsgcVCLMap.Create(aOwner);
oMap.Parent := aOwner;
oMap.Align := alClient;
oLayer := oMap.Layers.Add;
oLayer.Name := 'OpenStreetMap';
oLayer.Provider := mtpOpenStreetMap;
sgcMapApplyProvider(oLayer);
oLayer.CacheFolder := ExtractFilePath(ParamStr(0)) + 'tile_cache';
oMap.AddMarker(48.8566, 2.3522, 'Paris', 'France');
oMap.AddMarker(52.5200, 13.4050, 'Berlin', 'Germany');
oMap.AddMarker(41.9028, 12.4964, 'Rome', 'Italy');
oMap.MarkerOptions.Clustering.Enabled := True;
oLine := oMap.AddPolyline;
oLine.Geodesic := True;
oLine.Dashed := True;
oLine.Color := clRed;
oLine.AddPoint(48.8566, 2.3522);
oLine.AddPoint(52.5200, 13.4050);
oMap.AddCircle(48.8566, 2.3522, 300000).FillOpacity := 0.15;
oMap.FitToMarkers(40);
oMap.AddLabel(50.7, 8, Format('Paris to Berlin: %.0f km',
[sgcMapDistance(48.8566, 2.3522, 52.52, 13.405) / 1000]));
oMap.SaveToPNG('europe.png', 1200, 800);
end;
Het helponderwerp lezen →
Dezelfde kaart in C++ Builder met de gegenereerde sgcMaps-headers.
#include <vcl.h>
#include "sgcMaps_Classes.hpp"
#include "sgcMaps_Providers.hpp"
#include "sgcMaps_Geometry.hpp"
#include "sgcMaps_VCL.hpp"
// OpenStreetMap with cached tiles, three capitals, a geodesic flight line
// and a 300 km radius, fitted to the markers and saved as PNG.
void BuildMap(TWinControl *aOwner)
{
TsgcVCLMap *oMap = new TsgcVCLMap(aOwner);
oMap->Parent = aOwner;
oMap->Align = alClient;
TsgcMapLayer *oLayer = oMap->Layers->Add();
oLayer->Name = "OpenStreetMap";
oLayer->Provider = mtpOpenStreetMap;
sgcMapApplyProvider(oLayer);
oLayer->CacheFolder = ExtractFilePath(ParamStr(0)) + "tile_cache";
oMap->AddMarker(48.8566, 2.3522, "Paris", "France");
oMap->AddMarker(52.5200, 13.4050, "Berlin", "Germany");
oMap->AddMarker(41.9028, 12.4964, "Rome", "Italy");
oMap->MarkerOptions->Clustering->Enabled = true;
TsgcMapPolyline *oLine = oMap->AddPolyline();
oLine->Geodesic = true;
oLine->Dashed = true;
oLine->Color = clRed;
oLine->AddPoint(48.8566, 2.3522);
oLine->AddPoint(52.5200, 13.4050);
oMap->AddCircle(48.8566, 2.3522, 300000)->FillOpacity = 0.15;
oMap->FitToMarkers(40);
int iKm = (int)(sgcMapDistance(48.8566, 2.3522, 52.52, 13.405) / 1000);
oMap->AddLabel(50.7, 8, "Paris to Berlin: " + IntToStr(iKm) + " km");
oMap->SaveToPNG("europe.png", 1200, 800, false);
}
Het helponderwerp lezen →
De headless MapView rendert dezelfde kaart naar een PNG-bestand, op Windows of Linux.
using System;
using System.IO;
using esegece.sgcMaps;
using esegece.sgcMaps.Rendering;
// OpenStreetMap with cached tiles, three capitals, a geodesic flight line
// and a 300 km radius, fitted to the markers and saved as PNG (no window).
public static class EuropeMap
{
public static void Render()
{
var oMap = new MapView();
Layer oLayer = oMap.Layers.Add();
oLayer.Name = "OpenStreetMap";
oLayer.Provider = TileProvider.OpenStreetMap;
MapProviders.ApplyProvider(oLayer);
oLayer.CacheFolder = Path.Combine(AppContext.BaseDirectory, "tile_cache");
oMap.AddMarker(48.8566, 2.3522, "Paris", "France");
oMap.AddMarker(52.5200, 13.4050, "Berlin", "Germany");
oMap.AddMarker(41.9028, 12.4964, "Rome", "Italy");
oMap.MarkerOptions.Clustering.Enabled = true;
Polyline oLine = oMap.AddPolyline();
oLine.Geodesic = true;
oLine.Dashed = true;
oLine.Color = MapColors.Red;
oLine.AddPoint(48.8566, 2.3522);
oLine.AddPoint(52.5200, 13.4050);
oMap.AddCircle(48.8566, 2.3522, 300000).FillOpacity = 0.15;
oMap.FitToMarkers(40);
double vKm = MapGeometry.Distance(48.8566, 2.3522, 52.52, 13.405) / 1000;
oMap.AddLabel(50.7, 8, $"Paris to Berlin: {vKm:F0} km");
oMap.RenderToPng("europe.png", 1200, 800);
}
}
dotnet add package esegece.sgcMaps.Rendering
Het helponderwerp lezen →