diff --git a/components/lazmapviewer/examples/fulldemo/main.pas b/components/lazmapviewer/examples/fulldemo/main.pas index 2dc2adaad..5514f99c3 100644 --- a/components/lazmapviewer/examples/fulldemo/main.pas +++ b/components/lazmapviewer/examples/fulldemo/main.pas @@ -485,38 +485,30 @@ end; procedure TMainForm.MapViewMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); -const - DELTA = 3; var - rArea: TRealArea; - gpsList: TGpsObjList; + objs: TGpsObjArray; L: TStrings; i: Integer; begin UpdateCoords(X, Y); - rArea.TopLeft := MapView.ScreenToLonLat(Point(X-DELTA, Y-DELTA)); - rArea.BottomRight := MapView.ScreenToLonLat(Point(X+DELTA, Y+DELTA)); - gpsList := MapView.GpsItems.GetObjectsInArea(rArea); - try - if gpsList.Count > 0 then begin - L := TStringList.Create; - try - for i:=0 to gpsList.Count-1 do - if gpsList[i] is TGpsPoint then - with TGpsPoint(gpsList[i]) do - L.Add(Format('%s (%s / %s)', [ - Name, LatToStr(Lat, USE_DMS), LonToStr(Lon, USE_DMS) - ])); - GPSPointInfo.Caption := L.Text; - finally - L.Free; - end; - end else - GPSPointInfo.Caption := ''; - finally - gpsList.Free; - end; + objs := MapView.ObjsAtScreenPt(X, Y); + if Length(objs) > 0 then + begin + L := TStringList.Create; + try + for i := 0 to High(objs) do + if objs[i] is TGpsPoint then + with TGpsPoint(objs[i]) do + L.Add(Format('%s (%s / %s)', [ + Name, LatToStr(Lat, USE_DMS), LonToStr(Lon, USE_DMS) + ])); + GPSPointInfo.Caption := L.Text; + finally + L.Free; + end; + end else + GPSPointInfo.Caption := ''; end; procedure TMainForm.MapViewMouseUp(Sender: TObject; Button: TMouseButton; diff --git a/components/lazmapviewer/source/mvmapviewer.pas b/components/lazmapviewer/source/mvmapviewer.pas index 2e5c28545..829a3ab08 100644 --- a/components/lazmapviewer/source/mvmapviewer.pas +++ b/components/lazmapviewer/source/mvmapviewer.pas @@ -122,6 +122,7 @@ Type procedure GetMapProviders(lstProviders: TStrings); function GetVisibleArea: TRealArea; function LonLatToScreen(aPt: TRealPoint): TPoint; + function ObjsAtScreenPt(X, Y: Integer; ATolerance: Integer = -1): TGPSObjarray; procedure SaveToFile(AClass: TRasterImageClass; const AFileName: String); function SaveToImage(AClass: TRasterImageClass): TRasterImage; procedure SaveToStream(AClass: TRasterImageClass; AStream: TStream); @@ -943,6 +944,33 @@ begin Engine.Jobqueue.WaitAllJobTerminated(Engine); end; +function TMapView.ObjsAtScreenPt(X, Y: Integer; ATolerance: Integer = -1): TGPSObjarray; +const + DELTA = 3; +var + rArea: TRealArea; + gpsList: TGPSObjList; + i: Integer; +begin + if ATolerance = -1 then + ATolerance := DELTA; + + // Define area of +/-ATolerance pixels around the screen point + rArea.TopLeft := ScreenToLonLat(Point(X-ATolerance, Y-ATolerance)); + rArea.BottomRight := ScreenToLonLat(Point(X+ATolerance, Y+ATolerance)); + + // Collect Objects in this are + gpsList := FGPSItems.GetObjectsInArea(rArea); + try + SetLength(Result, gpsList.Count); + for i := 0 to gpsList.Count-1 do + if gpsList[i] is TGPSPoint then + Result[i] := gpsList[i]; + finally + gpsList.Free; + end; +end; + procedure TMapView.CenterOnObj(obj: TGPSObj); var Area: TRealArea;