Что нового
  • Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Using GPX files with WayPoints (POI) in TMS FNC Maps for Delphi

Sascha

Заместитель Администратора
Команда форума
Администратор
Регистрация
9 Май 2015
Сообщения
1,071
Баллы
155
Возраст
51
GPX (GPS Exchange Format) files are a popular way to share GPS data, including waypoints, routes, and tracks. If you’re working with

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

, you might find yourself needing to import GPX files to visualize and manipulate this data. In this blog post, we’ll walk you through the process of importing GPX files with waypoints using TMS FNC Maps.



What is a GPX file?


A GPX file is an XML-based format used to store GPS data. It can include waypoints (specific points of interest), tracks (a sequence of coordinates showing a path), and routes (a planned course of travel from one waypoint to another). These files are widely used in various applications, from hiking and cycling to geocaching and navigation.

An excerpt from the GPX file that shows track coordinates:

<trk>
<name>Loire by bike - Loire à vélo</name>
<trkseg>
<trkpt lat="46.98812" lon="3.15795">
<ele>196</ele>
</trkpt>
<trkpt lat="46.98754" lon="3.15822">
<ele>197</ele>
</trkpt>
...
</trkseg>
</trk>



Importing GPX files in TMS FNC Maps


TMS FNC Maps provides robust support for handling GPX files. Here&#146;s a step-by-step guide to importing GPX files with waypoints:




Adding a TTMSFNCMaps component to your form



First, place a TTMSFNCMaps component on your form. You can choose from various supported mapping services, all of which support GPX functionality. For this guide, we&#146;ll use msOpenLayers because it is free and doesn&#146;t require an API key.




procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCMaps1.Service := msOpenLayers;
end;



Loading and displaying an existing GPX file




In this guide we'll demonstrate how to display the contents of an existing GPX file on the map. There are numerous online resources for GPX files, we've chosen a bicycle route along the Loire river in France from

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

. Simply pass the filename as a parameter to the [FONT=Menlo, Monaco, Consolas, Courier New, monospace]LoadFromGPXFile[/FONT] function, and the routes and waypoints found in the GPX file will automatically appear on the map.


TMSFNCMaps1.LoadGPXFromFile('filename.gpx');





TMS Software Delphi  Components




Customizing GPX Waypoint (POI) display



By default, all waypoints in a GPX file are displayed with the same marker. However, our GPX file includes specific types for each waypoint. We can leverage this information to display unique markers for each waypoint type. For instance, we are particularly interested in highlighting the many castles found along the route. To achieve this, we&#146;ll use distinct colored markers and add labels with the castle names.

One of the Waypoints listed in the GPX file:


<wpt lat="47.47917" lon="1.18194">
<name>Château de Chaumont</name>
<desc>The Château de Chaumont, officially Château de Chaumont-sur-Loire, is a castle in Chaumont-sur-Loire, Centre-Val de Loire, France. The castle was founded in the 10th century by Odo I, Count of Blois.</desc>
<type>Castle</type>
</wpt>



TMS Software Delphi  Components


When loading data from the GPX file using the LoadFromGPXFile call, we set the second parameter to False to prevent automatic addition of polylines and markers. This allows us to manually add and customize these objects on the map.

Here are the steps to customize the display:

  1. Add Polyline
    Use AddPolyline to draw the polyline based on the GPX track coordinates.

  2. Add Markers
    For each GPX waypoint (POI), use AddMarker .

  3. Customize Markers
    Set the fill color of the marker to blue for waypoints of type &#147;Castle&#148;.

  4. Add Labels
    Use AddLabel to display the castle&#146;s name (included in the waypoint data) below the marker.

  5. Adjust View
    Use ZoomToBounds with the GPX route coordinates to ensure the polyline and markers fit within the map view.




var
I: Integer;
m: TTMSFNCMapsMarker;
lb: TTMSFNCMapsLabel;
p: TTMSFNCMapsPolyline;
gpx: TTMSFNCMapsGPXRec;
begin
if OpenDialog1.Execute then
begin
gpx := TMSFNCMaps1.LoadGPXFromFile(OpenDialog1.FileName, False);

TMSFNCMaps1.BeginUpdate;
if (Length(gpx.Tracks) > 0) and (Length(gpx.Tracks[0].Segments) > 0) then
begin
p := TMSFNCMaps1.AddPolyline(gpx.Tracks[0].Segments[0]);
p.StrokeColor := gcBlack;
p.StrokeWidth := 3;
end;

for I := 0 to Length(gpx.Waypoints) - 1 do
begin
m := TMSFNCmaps1.AddMarker(gpx.WayPoints.WayPoint);
m.DefaultIcon.Enabled := True;

if gpx.WayPoints.WayPointType = 'Castle' then
begin
m.DefaultIcon.Fill := gcBlue;
lb := TMSFNCMaps1.AddLabel(gpx.WayPoints.WayPoint, gpx.WayPoints.Name, gcBlack, gcWhite);
end;
end;
TMSFNCMaps1.ZoomToBounds(gpx.Tracks[0].Segments[0]);
TMSFNCMaps1.EndUpdate;
end;
end;

Conclusion

Importing GPX files with waypoints into

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

is a straightforward process that allows you to leverage the rich features of TMS Software's mapping components. Whether you&#146;re developing an application for outdoor activities, navigation, or any other GPS-related project,

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

provides the tools you need to handle GPX data efficiently.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх