Resource

Resource Basics

Resource Name Search Nearby Images
Resource Version 2.0
Category Search Scripts
Downloads 708
Release Date 9/20/2021 3:20:23 PM
 

Resource Details

Description This script will return all nearby images for a selected thumbnail, within a distance radius
Installation Instructions n.a.
Usage Instructions 1. Start PSU
2. In the dropdown of the Tabs, select From Repository
3. Select this script
Changes in this version n.a.
Special Requirements
 

Author Information

Author Name IDimager Support
 

Available Attachments

Attachment #1 Search Nearby.png
 

Script

{
  Author: IDimager

  Version 2.1; 26 apr 2022:
    * Stopped support in PSU V7
  Version 2; 17 nov 2021:
    * Now calls native PublicCatalog method

}

var
  ATextBox: TvxTextBox;

  function CreateForm: TvxSceneForm;
  var
    ARoot: TvxVisualObject;
    ALabel: TvxLabel;
  begin
    result := TvxSceneForm.Create(nil);
    result.Caption := UTF8Encode('Enter Distance');
    result.Position := poScreenCenter;
    result.Height := 100 * result.DPIFactor;

    ARoot := result.Root;

    ALabel := TvxLabel.Create(ARoot);
    ALabel.Text := 'Enter the distance (in ' + iif(PublicOptions.MeasurementSystem = msEnglish, 'miles', 'km') + ') to search in:';
    ALabel.TextAlign := vgTextAlignNear;
    ALabel.Padding.Left := 10;
    ALabel.Padding.Top := 10;
    ALabel.Align := vaTop;
    ARoot.AddObject(ALabel);

    ATextBox := TvxTextBox.Create(ARoot)
    ATextBox.Padding.Left := 10;
    ATextBox.Padding.Right := 10;
    ATextBox.Padding.Top := 10;
    ATextBox.Align := vaTop;
    ATextBox.Text := '5' + DecimalSeparator + '0';
    ARoot.AddObject(ATextBox);
  end;

  procedure SearchDistance(ADistanceMeters: Double);
  var
    AData: TidElement;
    AColl: TImageCollection;
    AWhere: WideString;
    ALat, ALon: Double;

    AImage: TImageItem;

    ANearItems: TCatalogItems;
  begin
    AImage := Selected.Items[0];

    ALat := AImage._Latitude;
    ALon := AImage._Longitude;

    ANearItems := TCatalogItems.Create(TCatalogItem, '');
    try
      PublicCatalog.EnumItemsForGeoLocation(ALat, ALon, ADistanceMeters, ANearItems, 0);

      AData := TidElement.Create(nil);
      try
        PublicBroadCast(nil, 'OpenNewTab', nil);
        PublicBroadCastRequest(nil, 'ActiveCollection', AData);
        AColl := AData.Data;
        AColl.Clear;
        if ANearItems.DataSets.Count > 0 then
        begin
          // take over the dataset(s) for extra performance
          AColl.Items.DataSets := ANearItems.DataSets;
          ANearItems._DataSets := TDBXOMDataSets.Create(TDBXOMDataSet, '')
        end;
        PublicBroadCast(nil, 'RefreshActiveCollection', nil);
      finally
        AData.Free;
      end;
    finally
      ANearItems.Free;
    end;
  end;

var
  AForm: TvxSceneForm;
  ADistanceMeters: Double;
begin
  if (not IsAppVersion(6, 6, 0)) then
  begin
    Say('This script requires Photo Supreme 6.6.0 or higher.');
    exit;
  end;

  if (IsAppVersion(7, 0, 0)) then
  begin
    Say2('This script is for Photo Supreme V6 only.', 'You can right click on a thumb and select "Show More->Nearby Images" for the integrated GEO-Fence feature.');
    exit;
  end;

  if Selected.Count <> 1 then
  begin
    Say('Please select one thumbnail to find nearby images for.');
    exit;
  end;

  AForm := CreateForm;
  try
    ATextBox.Text := ReadFromRegistry('', 'scSearchNearby.LastText', ATextBox.Text);
    AForm.PrepareModal([mbOK, mbCancel]);
    AForm.ShowModal;
    if AForm.ModalResult = mrOk then
    begin
      if IsValidNumberString(ATextBox.Text, False, '') then
      begin
        ADistanceMeters := FloatToStr(ATextBox.Text);
        if PublicOptions.MeasurementSystem = msEnglish then
          ADistanceMeters := ADistanceMeters * 1609.344;

        if ADistanceMeters >= 0 then
        begin
          WriteToRegistry('', 'scSearchNearby.LastText', ATextBox.Text);
          SearchDistance(ADistanceMeters);
        end
        else
          Say('Please enter a positive number.');
      end
      else
        Say('No valid number entered.');
    end;
  finally
    AForm.Free;
  end;
end;