var
  i,j : integer;
  sat: string;
  Chart_ID: string;
  Chart_Year: string;
  PointMap, Successor: string;
  Debug: string;
  Lat: Double;
  Long: Double;
 VResponseCode                 : Cardinal  ;
  VResponseHeader, VResponseData: AnsiString;
  VRequestUrl, VRequestHeader   : AnsiString;
begin
  Debug := '' 



	// Need to find the correct Chart for this area/tile
	
	//Get the Chart ID from the Database
	Long := (GetLLon + GetRLon) /2
    	Lat:= (GetTLat + GetBLat) /2
			   // https://nvcharts.com/Wildenradt-Media/postgres/productapi.php?todo=getpointmaps&lat=17.00&lng=-62.1
	VRequestUrl     := 'https://nvcharts.com/Wildenradt-Media/postgres/productapi.php?todo=getpointmaps&lat=' + FloatToStr(lat) + '&lng=' + FloatToStr(long);
    	VRequestHeader  := '';
     	VResponseHeader := '';
	VResponseData   := '';
     	VResponseCode   := Downloader.DoHttpRequest(VRequestUrl, VRequestHeader, '', VResponseHeader, VResponseData);
	PointMap := VResponseData 
	//Debug := VResponseData + '&&&&&' + GetBetween(VResponseData, 'nvdata_id":', ',')     
	
	// Should check the ResponseCode... 	

	//Get the Updated Chart ID from the Database
			//	https://app.nv-data.de/ajax3.php?getsuccessor=319
	
	VRequestUrl     := 'https://app.nv-data.de/ajax3.php?getsuccessor='+GetBetween(VResponseData, 'nvdata_id":', ',');
    	VRequestHeader  := '';
     	VResponseHeader := '';
	VResponseData   := '';
     	VResponseCode   := Downloader.DoHttpRequest(VRequestUrl, VRequestHeader, '', VResponseHeader, VResponseData);
	Successor := VResponseData
	// Find the last pid entry..
	i:=0;
        j:=1;
  	while j > 0 do
        begin
	    j:=PosEx('pid',VResponseData,i+1);
	    //Debug := Debug + '&&' + VResponseData + '--' + inttostr(j);
	    if j<>0 then
	      begin

		Chart_ID  := GetBetween(VResponseData, '"pid":',',');
		Chart_Year := GetBetween(VResponseData, '"year":',',');
		j:=PosEx('year":',VResponseData,i+1);		
		VResponseData := copy(VResponseData, j+8,Length(VResponseData))
		//Debug := Debug + 'ZZZ' + VResponseData  +'-' + Chart_ID + '-' + Chart_Year + '-' + inttostr(j);
		
		
	      end;
	    i:=0;
	end;
	//Debug := Debug + '&&&' + VResponseData + '&&&' + Chart_ID;     
	//Debug := Debug + '&&&' + Chart_ID + Chart_Year;     
	
	// Should check the ResponseCode...


// https://app.nv-data.de/navipack.php?tiles=2018,530,9,231,168

// default for world is Chart 410, Year 2016
// Since other's don't do upper, force 410/2016
 if (GetZ-1) < 8 then   // make 9??
   begin
   Chart_ID := '410'
   Chart_Year := '2016'
   end;

 if (GetZ-1) < 4 then
 begin
	// No charts to get.
	ResultURL := ''
 end else
 begin
   sat := GetURLBase + '?tiles=' + Chart_Year + ',' + Chart_ID  +','
 	ResultURL := sat  + inttostr(GetZ-1) +',' + inttostr(GetY)+',' +inttostr(GetX); 
 end;
end.