diff --git a/components/lazmapviewer/examples/fulldemo/main.lfm b/components/lazmapviewer/examples/fulldemo/main.lfm index 1c2ff4c82..6a69db37b 100644 --- a/components/lazmapviewer/examples/fulldemo/main.lfm +++ b/components/lazmapviewer/examples/fulldemo/main.lfm @@ -18,7 +18,6 @@ object MainForm: TMainForm Top = 0 Width = 608 Align = alClient - CachePath = '../../../../cache/' Cyclic = True DefaultTrackColor = clBlue DefaultTrackWidth = 3 diff --git a/components/lazmapviewer/examples/fulldemo/main.pas b/components/lazmapviewer/examples/fulldemo/main.pas index 5ae6b689f..5ba67d2f8 100644 --- a/components/lazmapviewer/examples/fulldemo/main.pas +++ b/components/lazmapviewer/examples/fulldemo/main.pas @@ -145,12 +145,10 @@ type const MAX_LOCATIONS_HISTORY = 50; MAP_PROVIDER_FILENAME = 'map-providers.xml'; - HOMEDIR = '../../../../'; USE_DMS = true; var PointFormatSettings: TFormatsettings; - CacheDir: String = HOMEDIR + 'cache/'; // share the cache in both example projects function CalcIniName: String; begin @@ -438,6 +436,8 @@ end; procedure TMainForm.FormCreate(Sender: TObject); var + homeDir: String; + cacheDir: String; fn: String; begin cInputQueryEditSizePercents := 0; @@ -454,15 +454,16 @@ begin POIImage.LoadFromFile(fn); end; - CacheDir := HOMEDIR + 'cache/'; - if not ForceDirectories(CacheDir) then + homeDir := Application.Location + '../../../'; // this should be the "examples" folder + cacheDir := homeDir + 'cache/'; + if not ForceDirectories(cacheDir) then begin - CacheDir := GetAppConfigDir(false) + 'cache/'; - ForceDirectories(CacheDir); + cacheDir := GetAppConfigDir(false) + 'cache/'; + ForceDirectories(cacheDir); end; - MapView.CachePath := CacheDir; + MapView.CachePath := cacheDir; MapView.GetMapProviders(CbProviders.Items); - CbProviders.ItemIndex := CbProviders.Items.Indexof(MapView.MapProvider); + CbProviders.ItemIndex := CbProviders.Items.IndexOf(MapView.MapProvider); MapView.DoubleBuffered := true; MapView.Zoom := 1; CbZoomToCursor.Checked := MapView.ZoomToCursor; diff --git a/components/lazmapviewer/examples/fulldemo_with_addons/main.pas b/components/lazmapviewer/examples/fulldemo_with_addons/main.pas index 0efc63cf2..ee5f2ed4e 100644 --- a/components/lazmapviewer/examples/fulldemo_with_addons/main.pas +++ b/components/lazmapviewer/examples/fulldemo_with_addons/main.pas @@ -151,7 +151,6 @@ type const MAX_LOCATIONS_HISTORY = 50; - HOMEDIR = '../../../../../'; // share the cache in both fulldemo projects MAP_PROVIDER_FILENAME = 'map-providers.xml'; USE_DMS = true; @@ -409,6 +408,8 @@ end; procedure TMainForm.FormCreate(Sender: TObject); var fn: String; + homeDir: String; + cacheDir: String; begin cInputQueryEditSizePercents := 0; @@ -424,8 +425,14 @@ begin POIImage.LoadFromFile(fn); end; - ForceDirectories(HOMEDIR + 'cache/'); - MapView.CachePath := HOMEDIR + 'cache/'; + homeDir := Application.Location + '../../../'; // this should be the "examples" folder + cacheDir := homeDir + 'cache/'; + if not ForceDirectories(cacheDir) then + begin + cacheDir := GetAppConfigDir(false) + 'cache/'; + ForceDirectories(cacheDir); + end; + MapView.CachePath := cacheDir; MapView.GetMapProviders(CbProviders.Items); CbProviders.ItemIndex := CbProviders.Items.IndexOf(MapView.MapProvider); MapView.DoubleBuffered := true; @@ -593,9 +600,11 @@ begin HERE_AppID := ini.ReadString('HERE', 'APP_ID', ''); HERE_AppCode := ini.ReadString('HERE', 'APP_CODE', ''); OpenWeatherMap_ApiKey := ini.ReadString('OpenWeatherMap', 'API_Key', ''); + ThunderForest_ApiKey := ini.ReadString('ThunderForest', 'API_Key', ''); if ((HERE_AppID <> '') and (HERE_AppCode <> '')) or - (OpenWeatherMap_ApiKey <> '') then + (OpenWeatherMap_ApiKey <> '') or + (ThunderForest_ApiKey <> '') then begin MapView.Engine.ClearMapProviders; MapView.Engine.RegisterProviders; @@ -766,6 +775,9 @@ begin if OpenWeatherMap_ApiKey <> '' then ini.WriteString('OpenWeatherMap', 'API_Key', OpenWeatherMap_ApiKey); + if ThunderForest_ApiKey <> '' then + ini.WriteString('ThunderForest', 'API_Key', ThunderForest_ApiKey); + ini.EraseSection('Locations'); for i := 0 to CbLocations.Items.Count-1 do ini.WriteString('Locations', 'Item'+IntToStr(i), CbLocations.Items[i]); diff --git a/components/lazmapviewer/source/mvengine.pas b/components/lazmapviewer/source/mvengine.pas index 4c6ca3f63..93ba6787a 100644 --- a/components/lazmapviewer/source/mvengine.pas +++ b/components/lazmapviewer/source/mvengine.pas @@ -1282,6 +1282,11 @@ begin if FActive = AValue then Exit; FActive := AValue; + // One problem at designtime is that the control is creating cache directories + // at unexpected places when Cache.BasePath is relative + if csDesigning in ComponentState then + exit; + if not FActive then Queue.CancelAllJob(self) else begin @@ -1305,7 +1310,6 @@ end; procedure TMapViewerEngine.SetCachePath(AValue: String); begin - ForceDirectories(aValue); Cache.BasePath := aValue; end;