Q&A - Question

OnPassword event in TGIS_LayerWMS

Question
Lars asked on January 02, 2017, keyword: Developer Kernel
I am trying to connect to a WMS service that requires a username and password. The service works fine in both the DK and Editor when username/password is embedded in the path. However, I don't want to embed the login information in the path. I need the user to login but I can't make it work with templates and OnPassword event as described in the documentation. The Editor shows a login box when using the template but fails to open the service. Can you please provide an example of how to do this in the DK from code?
Answers
Artur Redzko (TatukGIS) replied September 09, 2016
For WMS servers that require authentication it is possible to embed into Path additional parameters USER, PASS like :

layer.Path := 'http://wms.jpl.nasa.gov/wms.cgi?SERVICE=WMS&USER=test&PASS=test' 

or use templates format instead of real parameter values and the OnPassword event for secured decoding like :
     
layer.Path := 'http://wms.jpl.nasa.gov/wms.cgi?SERVICE=WMS&USER=<#USER#>&PASS=<#PASS#>' 

So simple code using templates can look like :

var
  wms : TGIS_LayerWMS ;
begin
  wms := TGIS_LayerWMS( GisCreateLayer( 'WMS' , 'http://wms.jpl.nasa.gov/wms.cgi?SERVICE=WMS&USER=<#USER#>&PASS=<#PASS#>' ) );
  try
    if Assigned( wms ) then begin
      GIS.OnPassword := doPassword ;
      GIS.Add( wms ) ;
    end ;
  except
    wms.Free ;
  end ;


function doPassword(const _sender: TObject; const _token: String): String;
begin
  if _token = '
USER' then
    Result := 'test'
  else if _token = '
PASS' then
    Result := 'test'
  else
    Result := _token ;
end;

 
Lars replied September 09, 2016
Well, thanks, but I still can't make it work. I will send you a demo project in a moment that should make it easier to pinpoint the problem.
SeanP replied December 23, 2016
I got the template method to work for me in DK10 for a single WMS layer but what happens if you have multiple WMS layers with different passwords for each?
Danv replied January 02, 2017
For each WMS layer to load in the project you can set its own OnPassword event OnPasswordWMS_A OnPasswordWMS_B etc...

Then each function has its own implementation.

 
If you would like to answer the question please Sign In.
*
*
Please review our recent Privacy Policy.
If you have any questions or requests, please contact us.
Rules
The Questions and Answers (Q & A) is intended to provide a means of communication between TatukGIS customers.
 
  1. Licensed users (with active maintenance play) of TatukGIS products may contribute to the Q & A content. Read-only access is available to anyone.
  2. Keep the content positive and professional.
  3. Be courteous to others by posting information when a question or issue asked on the Q & A is answered or resolved by other means (such as with help from TatukGIS technical support). Offer others at least a hint how the posted question was answered or the issue was resolved.
  4. The Q & A is not a replacement for TatukGIS technical support. TatukGIS team may or may not regularly follow or contribute content.