Fr0sT-Brutal / Delphi_OSMMap

Visual control for Delphi and Lazarus to display OSM map
Mozilla Public License 2.0
61 stars 23 forks source link

Import KLM file for add polygones by tracks #21

Open ClubACNews opened 8 months ago

ClubACNews commented 8 months ago

Good morning, I use KLM files to represent specific companies. they are drawn under geoportal (https://www.geoportail.gouv.fr/) in a 'Web mercator' coordinate format. Would it be possible to add an import of these coordinates to display them as a polygon with tracks? I have a component that creates filled polygons but I don't know how to pass it to you. THANKS

Fr0sT-Brutal commented 8 months ago

Hello, currently reading KML files is beyond my TODO but if you find a reader that provides you with coordinates you should easily add tracks and polygons (see Demo actions under btnAddRouteClick for tracks and mMapDrawLayer for polygon)

limelect commented 8 months ago

I communicating with [Fr0sT-Brutal with my KML reader and allowing him to add it to his source I am using his source to change from Google to open street this is the application I am changing https://limelect.com/downloads/kml-reader/ I can send you a demo although [Fr0sT-Brutal has my source

ClubACNews commented 8 months ago

Hi,for me , it's not possible to load a KML file in the software. I've a error windows :

I give you a KML file that I useThanksFrançois

Je pense ENVIRONNEMENT: ai-je vraiment besoin d'imprimer ce message ? Please consider the environment before printing this email.

Le mardi 24 octobre 2023 à 10:05:34 UTC+2, limelect ***@***.***> a écrit :  

I communicating with [Fr0sT-Brutal with my KML reader and allowing him to add it to his source I am using his source to change from Google to open street this is the application I am changing https://limelect.com/downloads/kml-reader/

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

Fr0sT-Brutal commented 8 months ago

@ClubACNews what exact error do you have?

I made a VERY quick, dirty and dumb KML loader and it works (loads from fixed-named 'route.kml' file near the EXE)

procedure TMainForm.Button1Click(Sender: TObject);
var
  sl: TStringList;
  i: Integer;
  s: string;
  fs: TFormatSettings;
  Track: TTrack;
  coords: TStringDynArray;
begin
  sl := TStringList.Create;
  sl.LoadFromFile('route.kml', TEncoding.UTF8);

  // look for first '<coordinates>' line, then consider next line as space-separated series of geo points
  for i := 0 to sl.Count - 1 do
    if Trim(LowerCase(sl[i])) = '<coordinates>' then
    begin
      s := sl[i + 1];
      Break;
    end;
  if s = '' then Exit;

  sl.Delimiter := ' ';
  sl.DelimitedText := s;
  fs := TFormatSettings.Create(LOCALE_NEUTRAL);
  fs.DecimalSeparator := '.';
  Track := TTrack.Create;
  SetLength(Track.Points, sl.Count);
  for i := 0 to sl.Count - 1 do
  begin
    coords := SplitString(sl[i], ',');
    Track.Points[i] := TGeoPoint.Create(StrToFloat(coords[0], fs), StrToFloat(coords[1], fs));
  end;
  Track.LineDrawProps := DefLineDrawProps;
  Track.LineDrawProps.Color := RandomColor;
  mMap.Tracks.Add(Track);
  FreeAndNil(sl);
end;
ClubACNews commented 8 months ago

Hi, I give you a kml file and it's representation on a map. Now, i use an release 2.26 of Lazarus and I don't know how to use this component if I need the latest version in development. I don't want to break what it works Croquis E1-E5.zip

Fr0sT-Brutal commented 8 months ago

image

Built with trunk FPC/Laz, 1st region is OK (but had to modify the KML as the loading code is DUMB and expects coords on a separate line. Also FPC has no TFormatSettings.Create so modification is needed:

{$IFDEF DCC} fs := TFormatSettings.Create(LOCALE_NEUTRAL); {$ELSE} fs := DefaultFormatSettings; {$ENDIF}

ClubACNews commented 8 months ago

excellent ! In the example, there are 5 zones denoted E1 to E5. Is it possible to load them all at once? I'm going to create a virtual machine and install a Lazarus trunk in it. I have an example source for creating filled polygons. How can I give them to you without going through an attachment from this github? This is a licensed component. I create my kml from a French government site "geoportal" allowing you to select different base maps to easily locate and delimit the area that the archaeologists are going to excavate. The KML format is imposed during registration by the site.

Fr0sT-Brutal commented 8 months ago

It is possible of course - just use proper XML reader to find all the coord nodes. Lazarus has it built-in.

If you need filled regions, tracks likely won't fit - you'll have to draw the regions by yourself. See the mMapDrawLayer method in Demo for example and read TCanvas' reference (namely Polygon). ATM I have no plans of adding regions but who knows... maybe if you succeed in this, you'll contribute the code for others ;)

jmgias commented 6 months ago

Hello everyone

I rarely enter GitHub, but looking for an application to monitor maps, I found this one that seemed like a fantastic job, so I decided to collaborate

I am Spanish and I am translating into English with Google, so forgive my English

I see that among the pending tasks is being able to view Track and Waypoint in different formats, although this thread talks about KML

I have prepared a Unit to load Track and Waypoint files in Kml, Gpx, Csv, Txt formats called OSM.TracksAndMarks

For Waypoints or Marks, I have added two new icon formats, gshRectangle and gshEllipse, so I have modified the OSM.MapControl unit to add them. In the header of the unit is the description of the changes, which were made on the latest version v.0.11.4

To load the Track and Waipoint, just add two buttons to the MainForm, one for the Marks and one for the Tracks, along with a TComboBox to define the color of the Track. The necessary code is put in the header of OSM.TracksAndMarks

As this is the first time I collaborate on Github and contribute code, I don't really know how to proceed, so you can download the two units OSM.TracksAndMarks and OSM.MapControl from my DropBox in this link

https://www.dropbox.com/scl/fo/1plv13h8alqkl0nfrzye1/h?rlkey=6uml3vf7hw4o9kpxbpu6xqaaq&dl=0

The code explains the necessary format for .Csv and .Txt files

To load the marks, I have added some standard configuration procedures for each drawing form, which must be executed before loading the files

The only problem I have encountered is that the Track lines always overlap the Waypoint / Marks, and I can't find anywhere to do a BringToFront to be able to leave the Tracks below

Track y Wp

Also missing is the ability to load Google orthophotos, although I see that you are working on it

Regards

limelect commented 6 months ago

I already used this component https://limelect.com/downloads/kml-reader/https://limelect.com/downloads/kml-reader/

Check kml files as there are strange one put a test program here as I have many odd kml or gpx my program read them all or send it to me to check

Fr0sT-Brutal commented 5 months ago

Hello everyone

Hello, thanks for contribution! I'll try to examine it in near time