TMSFNCMaps offline with a local maptile server

I require offline FNCMaps functionality with the OpenLayers service. I had this operational in the previously-used TMS WebOSMaps component.

To do this with FNCMaps, I have

  1. saved maptiles to disk and host them on a local server
  2. point TMSFNCOpenLayers to the local maptileserver by setting the TMSFNCOpenLayers.Options.TileServer to 'http://localhost:4001/services/CapeTown/tiles/{z}/{x}/{y}.png'.

I have found that this works only when there is an active internet connection. This obviously cancels out the beneft of having a local maptile server in the first place.

Looking at the HTML of the TMSFNCOpenLayers object I see that it requires a javascript and a style file from:
https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v6.1.1/css/ol.css
https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v6.1.1/build/ol.js

I have attempted to edit the HTML and to load it into the TMSFNCOpenLayers object using the TMSFNCOpenLayers.LoadHTML method, but this only works when the original URLs to the online files are used.

Any advice/assistance with how to read map tiles from a local tileserver, without an active internet connection, would be most appreciated!

Thanks

1 Like

Hi Andrew,

We are currently investigating this issue and will report back as soon as possible.

Hi,

We have investigated this here, you can override the GetHeadLinks and provide an URL to a local file:

type
  TTMSFNCOpenLayersOffline = class(TTMSFNCOpenLayers)
    procedure GetHeadLinks(AList: TTMSFNCMapsLinksList; ACheckReady: Boolean = True); override;
  end;

implementation

{ TTMSFNCOpenLayersOffline }

procedure TTMSFNCOpenLayersOffline.GetHeadLinks(AList: TTMSFNCMapsLinksList;
  ACheckReady: Boolean);
begin
  inherited;
  AList.Clear;
  AList.Add(TTMSFNCMapsLink.CreateLink('file://E:\Offline\OpenLayers\ol.css', 'text/css', 'stylesheet'));
  AList.Add(TTMSFNCMapsLink.CreateScript('file://E:\Offline\OpenLayers\ol.js', 'text/javascript'));
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  ol: TTMSFNCOpenLayersOffline;
begin
  ol := TTMSFNCOpenLayersOffline.Create(Self);
  ol.Parent := Self;
  ol.LocalFileAccess := True;
end;

Thanks for the assistance - this worked!

In the latest update, you can now override the links in the OnCustomizeHeadLinks event. This avoids having to implement your own class.


procedure TForm1.TMSFNCOpenLayers1CustomizeHeadLinks(Sender: TObject; AList: TTMSFNCMapsLinksList);
begin
  inherited;
  AList.Clear;
  AList.Add(TTMSFNCMapsLink.CreateLink('file://E:\Offline\OpenLayers\ol.css', 'text/css', 'stylesheet'));
  AList.Add(TTMSFNCMapsLink.CreateScript('file://E:\Offline\OpenLayers\ol.js', 'text/javascript'));
end;