Skip to content

Commit

Permalink
GMap.NET.Core: added function ForceBasicHttpAuthentication for GMapPr…
Browse files Browse the repository at this point in the history
…ovider
  • Loading branch information
radioman committed May 13, 2015
1 parent 60e678c commit 1126c04
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
24 changes: 23 additions & 1 deletion GMap.NET.Core/GMap.NET.MapProviders/GMapProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,18 @@ protected virtual bool CheckTileImageHttpResponse(WebResponse response)
//Debug.WriteLine(response.StatusCode + "/" + response.StatusDescription + "/" + response.ContentType + " -> " + response.ResponseUri);
return response.ContentType.Contains(responseContentType);
}

string Authorization = string.Empty;

/// <summary>
/// http://blog.kowalczyk.info/article/at3/Forcing-basic-http-authentication-for-HttpWebReq.html
/// </summary>
/// <param name="userName"></param>
/// <param name="userPassword"></param>
public void ForceBasicHttpAuthentication(string userName, string userPassword)
{
Authorization = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(userName + ":" + userPassword));
}

protected PureImage GetTileImageUsingHttp(string url)
{
Expand All @@ -400,7 +412,12 @@ protected PureImage GetTileImageUsingHttp(string url)
request.PreAuthenticate = true;
request.Credentials = Credential;
}


if(!string.IsNullOrEmpty(Authorization))
{
request.Headers.Set("Authorization", Authorization);
}

if (request is HttpWebRequest)
{
var r = request as HttpWebRequest;
Expand Down Expand Up @@ -490,6 +507,11 @@ protected string GetContentUsingHttp(string url)
request.PreAuthenticate = true;
request.Credentials = Credential;
}

if(!string.IsNullOrEmpty(Authorization))
{
request.Headers.Set("Authorization", Authorization);
}

if (request is HttpWebRequest)
{
Expand Down
18 changes: 16 additions & 2 deletions GMap.NET.Core/GMap.NET.MapProviders/NearMap/NearMapProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ namespace GMap.NET.MapProviders
using System;
using GMap.NET.Projections;
using System.Net;
using System.Text;

/// <summary>
/// http://en.wikipedia.org/wiki/NearMap
/// nearmap originally allowed personal use of images for free for non-enterprise users.
/// However this free access ended in December 2012, when the company modified its business model to user-pay
/// </summary>
public abstract class NearMapProviderBase : GMapProvider
{
public NearMapProviderBase()
{
// credentials doesn't work ;/
//Credential = new NetworkCredential("greatmaps", "greatmaps");
}

//try ForceBasicHttpAuthentication(...);
}

#region GMapProvider Members
public override Guid Id
Expand Down Expand Up @@ -161,7 +169,13 @@ string MakeTileImageUrl(GPoint pos, int zoom, string language)
{
// http://web1.nearmap.com/maps/hl=en&x=18681&y=10415&z=15&nml=Map_&nmg=1&s=kY8lZssipLIJ7c5
// http://web1.nearmap.com/kh/v=nm&hl=en&x=20&y=8&z=5&nml=Map_&s=55KUZ


//http://maps.au.nearmap.com/api/0/authentication/checkticket?nmf=json&return200=true&callback=jQuery110206126813754172529_1431499242400&_=1431499242401
//jQuery110206126813754172529_1431499242400({"IncidentId":null,"AccountContext":{"AccountId":"account2574457","Username":"demo"},"Result":{"Ticket":{"Ticket":"1637726D061CB8B8A28BC98064443C96FB07008C16531B2F5100F98B9EBFE69C4083C88C920D3BF4C0768A27ADE9ECADF324A380DBF80C3C0982DC83374FE8EBF0F70868735351FC7","Expires":"\/Date(1432103400000)\/","CookieName":"nearmap_web3_app"},"Status":"Ok","Username":"demo","AccountId":"account2574457"}})

// http://web1.au.nearmap.com/maps/hl=en&x=1855837&y=1265913&z=21&nml=V&httpauth=false&version=2
// http://web2.au.nearmap.com/maps/hl=en&x=231977&y=158238&z=18&nml=Dem&httpauth=false&version=2

return string.Format(UrlFormat, GetServerNum(pos, 3), pos.X, pos.Y, zoom, GetSafeString(pos));
}

Expand Down

0 comments on commit 1126c04

Please sign in to comment.