GoogleMapsStaticAsyncLayer¶
Namespace: ThinkGeo.Core
Represents a web layer that retrieves imagery from the Google Static Maps API.
public class GoogleMapsStaticAsyncLayer : WebBasedAsyncLayer, IHttpRequestService
Inheritance object → LayerBase → AsyncLayer → WebBasedAsyncLayer → GoogleMapsStaticAsyncLayer
Implements IHttpRequestService
Remarks:
This class issues Google Static Maps requests on demand to display Google imagery.
Google validates every request against the restrictions configured on the API key. An HTTP referrer restriction, which the Google Cloud console calls a Websites restriction, is validated against the Referer header of the request, and a desktop or server application sends no such header, so a key carrying that restriction does not suit this layer. Restrict the key by IP address where the deployment has a fixed outbound address; otherwise leave it without an application restriction and limit it to the Maps Static API.
A key that has to keep its HTTP referrer restriction can be served by supplying the header from WebBasedAsyncLayer.SendingHttpRequest:
layer.SendingHttpRequest += (s, e) => e.HttpRequestMessage.Headers.Referrer = new Uri("https://www.example.com/");
The caller writes that header itself, so it keeps such a key working but protects nothing.
GoogleMapsStaticAsyncLayer.UriSigningSecret signs the request URL, which is a mechanism separate from the key restrictions: a signature does not satisfy a restriction, and a restriction signs nothing.
GoogleMapTilesAsyncLayer serves a new Google integration from the Map Tiles API instead. This layer remains the one that prints, caches tiles, and targets a projection other than spherical mercator, and the one to use where no Map Tiles overlay exists.
Properties¶
PictureFormat¶
Gets or sets the image format used for Google Static Maps responses.
public GoogleMapsPictureFormat PictureFormat { get; set; }
Property Value¶
MapType¶
Gets or sets the requested Google map type (for example, road, terrain, or hybrid).
public GoogleMapsMapType MapType { get; set; }
Property Value¶
RequestLanguage¶
Gets or sets the BCP-47 language code supplied to the Google Static Maps API.
public string RequestLanguage { get; set; }
Property Value¶
ClientId¶
Gets or sets the Google Maps Platform client identifier (gme-*).
public string ClientId { get; set; }
Property Value¶
PrivateKey¶
Gets or sets the private signing key associated with the client identifier.
public string PrivateKey { get; set; }
Property Value¶
UriSigningSecret¶
Gets or sets the optional signing secret applied when generating URLs.
public string UriSigningSecret { get; set; }
Property Value¶
ApiKey¶
Gets or sets the Google Maps API key used for authentication.
public string ApiKey { get; set; }
Property Value¶
CustomParameters¶
Gets the additional query-string parameters appended to Google Static Maps requests.
public Dictionary<string, string> CustomParameters { get; }
Property Value¶
TargetProjection¶
Gets or sets the projection that map imagery should be warped into while drawing.
public Projection TargetProjection { get; set; }
Property Value¶
HttpClient¶
Gets or sets the HTTP client reused for outbound requests.
public HttpClient HttpClient { get; set; }
Property Value¶
Remarks:
Use this property when the caller needs full control over the entire WebBasedAsyncLayer.HttpClient instance, including its handler pipeline and default headers. When assigned before OpenAsyncCore, this property takes precedence over WebBasedAsyncLayer.HttpMessageHandler; the handler property is ignored.
Ownership remains with the caller. The layer reuses the supplied client rather than creating its own. The current implementation also applies WebBasedAsyncLayer.TimeoutInSeconds to HttpClient.Timeout during open, even when the client is caller-supplied. This can affect shared WebBasedAsyncLayer.HttpClient instances.
HttpMessageHandler¶
Gets or sets an optional HttpMessageHandler used to construct the internal WebBasedAsyncLayer.HttpClient at open time. Useful for Blazor WASM (injecting a browser-compatible handler), DelegatingHandler chains (Polly retry, OpenTelemetry, custom auth), or unit tests with mock handlers.
public HttpMessageHandler HttpMessageHandler { get; set; }
Property Value¶
Remarks:
Prefer this property over WebBasedAsyncLayer.HttpClient when the caller wants to control the transport pipeline but still allow the layer to create and own its runtime WebBasedAsyncLayer.HttpClient instance.
If both WebBasedAsyncLayer.HttpClient and WebBasedAsyncLayer.HttpMessageHandler are assigned before opening, WebBasedAsyncLayer.HttpClient wins and this property is ignored.
Behavior: Read once during OpenAsyncCore. Setting it after the layer is opened has no effect.Ignored when has already been assigned.When supplied, , , and automatic decompression are NOT applied — the caller owns the full handler chain.The handler is not disposed by this layer. Caller retains ownership (intended for singletons from IHttpClientFactory or DI).Not serialized; deserialized layers will fall back to the default handler.
WebProxy¶
Gets or sets the proxy through which all HTTP requests should be routed.
public IWebProxy WebProxy { get; set; }
Property Value¶
TimeoutInSeconds¶
Gets or sets the request timeout, in seconds.
public int TimeoutInSeconds { get; set; }
Property Value¶
Credentials¶
Gets or sets the credential provider used when authenticating HTTP requests.
public ICredentials Credentials { get; set; }
Property Value¶
UserAgent¶
This property allows you to specify a custom user-agent request header when making requests to a Web server. This header provides information about the client application or device and can be useful for server-side logging and analytics.
public string UserAgent { get; set; }
Property Value¶
UpperScale¶
This property gets and sets the upper threshold in the scale at which to display the image.
public double UpperScale { get; set; }
Property Value¶
double
This property gets the upper threshold in the scale at which to display the image.
Remarks:
Above the upper threshold in scale, the image will not be displayed. This, in conjunction with the LowerThreshold property, allows you to create a band in which it is suitable to display the image source. By default, the upper threshold is double.max and lower threshold is 0. This means the image should always display.
LowerScale¶
This property gets and sets the lower threshold in the scale at which to display the image.
public double LowerScale { get; set; }
Property Value¶
double
This property gets the lower threshold in the scale at which to display the image.
Remarks:
Below the lower threshold in scale, the image will not be displayed. This, in conjunction with the UpperThreshold property, allows you to create a band in which it is suitable to display the image source. By default, the upper threshold is double.max and lower threshold is 0. This means the image should always display.
Name¶
Gets or sets the display name for the layer.
public string Name { get; set; }
Property Value¶
string
The name used to identify the layer within UI components such as legends.
Remarks:
The name is user defined. Assign a descriptive value so tooling such as legends and layer lists can surface a meaningful label to end users.
IsOpen¶
Gets a value indicating whether the layer is currently open.
public bool IsOpen { get; }
Property Value¶
bool
true if the layer has completed its open routine; otherwise, false.
Remarks:
This method is the concrete wrapper for the abstract method IsOpenCore. Various methods on the Layer require that it be in an open state. If one of those methods is called when the state is not open, then the method will throw an exception. To enter the open state, you must call the Layer Open method. The method will raise an exception if the current Layer is already open.
As this is a concrete public method that wraps a Core method, we reserve the right to add events and other logic to pre- or post-process data returned by the Core version of the method. In this way, we leave our framework open on our end, but also allow you the developer to extend our logic to suit your needs. If you have questions about this, please contact our support team as we would be happy to work with you on extending our framework.
IsVisible¶
Gets or sets a value indicating whether the layer is visible.
public bool IsVisible { get; set; }
Property Value¶
bool
true to draw the layer; otherwise, false.
Remarks:
If this property is set to false, the layer will not draw. We ensure this in the Draw method. This is useful for legends and other controls that control the visibility of layers.
Projection¶
Gets the projection of the layer.
public Projection Projection { get; set; }
Property Value¶
DrawingExceptionMode¶
Gets or sets how drawing exceptions are handled when the layer renders.
public DrawingExceptionMode DrawingExceptionMode { get; set; }
Property Value¶
Background¶
Gets or sets the background color used when rendering the layer.
public GeoColor Background { get; set; }
Property Value¶
GeoColor
The fill applied to areas not covered by layer content.
Transparency¶
Gets or sets the amount of transparency applied to the rendered image.
public float Transparency { get; set; }
Property Value¶
float
A value between 0 (fully transparent) and 255 (fully opaque).
Opacity¶
Gets or sets the opacity applied to the rendered image.
public float Opacity { get; set; }
Property Value¶
float
A value between 0.0 (fully transparent) and 1.0 (fully opaque).
BlueTranslation¶
Gets or sets the intensity adjustment applied to the blue channel.
public float BlueTranslation { get; set; }
Property Value¶
float
A value between -255 and 255 representing the blue channel translation.
RedTranslation¶
Gets or sets the intensity adjustment applied to the red channel.
public float RedTranslation { get; set; }
Property Value¶
float
A value between -255 and 255 representing the red channel translation.
GreenTranslation¶
Gets or sets the intensity adjustment applied to the green channel.
public float GreenTranslation { get; set; }
Property Value¶
float
A value between -255 and 255 representing the green channel translation.
KeyColors¶
Gets the collection of key colors that should be rendered as transparent.
public Collection<GeoColor> KeyColors { get; }
Property Value¶
Remarks:
Attempting to access this collection when the associated GeoCanvas does not support key colors (see GeoCanvas.SupportKeyColor) results in an exception. Add colors to this collection to ensure they render as transparent.
IsNegative¶
Gets or sets a value indicating whether the image should be rendered with inverted colors.
public bool IsNegative { get; set; }
Property Value¶
bool
true to invert the color channels; otherwise, false.
IsGrayscale¶
Gets or sets a value indicating whether the image should be converted to grayscale prior to rendering.
public bool IsGrayscale { get; set; }
Property Value¶
bool
true to apply a grayscale filter; otherwise, false.
HasBoundingBox¶
Gets a value indicating whether the layer supports retrieving its bounding box.
public bool HasBoundingBox { get; }
Property Value¶
Remarks:
When this property is false, calls to or GetFullExtent throw an exception. The default implementation returns false.
ConcurrentAccess¶
Gets or sets how this layer behaves when more than one thread wants to draw it at once, and what a caller who wants concurrency should therefore do with it.
public ConcurrentAccess ConcurrentAccess { get; set; }
Property Value¶
ConcurrentAccess
unless the layer says otherwise: callers take turns on the one instance, which is what the screen renderer has done with a layer that did not say otherwise since this question was first asked.
Remarks:
A FeatureLayer that is not given a value of its own answers with its FeatureLayer.FeatureSource's, so a layer and the source it reads through cannot disagree about this.
ThreadSafe¶
Gets or sets the threading guarantees provided by the layer implementation.
public ThreadSafetyLevel ThreadSafe { get; set; }
Property Value¶
ThreadSafetyLevel
The level of thread safety that callers can expect when interacting with the layer.
Remarks:
Replaced by LayerBase.ConcurrentAccess and kept only so that code written against it is told, by name, what to use instead. It does not compile, so there is never a question of which of the two a caller meant: there is one value, and it is the other one. That matters because the translation was lossy in one direction - writing ThreadSafetyLevel.Unsafe could only pick ConcurrentAccess.UnsafeLock, and would silently undo a layer or source that had said ConcurrentAccess.UnsafeClone.
ColorMappings¶
Gets the color translation map that will be applied when rendering the layer.
public Dictionary<GeoColor, GeoColor> ColorMappings { get; }
Property Value¶
Dictionary<GeoColor, GeoColor>
WrappingMode¶
Gets or sets how the layer wraps when the map extent crosses world boundaries.
public WrappingMode WrappingMode { get; set; }
Property Value¶
WrappingExtent¶
Gets or sets the geographic extent to use when wrapping is enabled.
public RectangleShape WrappingExtent { get; set; }
Property Value¶
Constructors¶
GoogleMapsStaticAsyncLayer()¶
Initializes a new instance of the GoogleMapsStaticAsyncLayer class.
public GoogleMapsStaticAsyncLayer()
GoogleMapsStaticAsyncLayer(string)¶
Initializes a new instance of the GoogleMapsStaticAsyncLayer class using the specified API key.
public GoogleMapsStaticAsyncLayer(string apiKey)
Parameters¶
apiKey string
The API key used to authenticate Google Static Maps requests.
GoogleMapsStaticAsyncLayer(string, string)¶
Initializes a new instance of the GoogleMapsStaticAsyncLayer class using the specified API key and signing secret.
public GoogleMapsStaticAsyncLayer(string apiKey, string uriSigningSecret)
Parameters¶
apiKey string
The API key used to authenticate Google Static Maps requests.
uriSigningSecret string
The secret used to sign requests for Google Maps Platform Premium.
Methods¶
OpenAsyncCore(CancellationToken)¶
Opens the layer, preparing projections and ensuring the base Web layer is initialized.
protected Task OpenAsyncCore(CancellationToken cancellationToken)
Parameters¶
cancellationToken CancellationToken
The cancellation token used for the asynchronous operation.
Returns¶
CloseAsyncCore(CancellationToken)¶
Closes the layer and cleans up projection resources.
protected Task CloseAsyncCore(CancellationToken cancellationToken)
Parameters¶
cancellationToken CancellationToken
The cancellation token used for the asynchronous operation.
Returns¶
DrawAsyncCore(GeoCanvas, Collection<SimpleCandidate>)¶
Draws imagery from Google Static Maps onto the specified canvas.
protected Task DrawAsyncCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)
Parameters¶
canvas GeoCanvas
The canvas on which the layer is drawn.
labelsInAllLayers Collection<SimpleCandidate>
Label candidates used for collision detection.
Returns¶
DownloadImageAsyncCore(double, double, double, RectangleShape, GeographyUnit, CancellationToken)¶
Downloads a Google Static Maps image for the specified extent and viewport size.
protected Task<Byte[]> DownloadImageAsyncCore(double width, double height, double scaleFactor, RectangleShape extent, GeographyUnit mapUnit, CancellationToken cancellationToken)
Parameters¶
width double
The viewport width in device-independent pixels.
height double
The viewport height in device-independent pixels.
scaleFactor double
The device scale factor used for high-DPI requests.
extent RectangleShape
The geographic extent to request.
mapUnit GeographyUnit
The map unit of the provided extent.
cancellationToken CancellationToken
The cancellation token used for the asynchronous operation.
Returns¶
Task<Byte[]>
A task that returns the raw image bytes, or null if the download fails.
GetRasterContentTypeCore()¶
Returns a content hint based on the selected Google map type.
protected RasterContentType GetRasterContentTypeCore()
Returns¶
GetPictureFormat()¶
Gets the Google Static Maps format string that corresponds to the current GoogleMapsStaticAsyncLayer.PictureFormat.
public string GetPictureFormat()
Returns¶
string
The request format string (for example, png32).
Events¶
SendingHttpRequest¶
Occurs before an HTTP request is dispatched so callers can inspect or cancel it.
public event EventHandler<SendingHttpRequestMessageEventArgs> SendingHttpRequest;
ReceivedHttpResponse¶
Occurs after an HTTP response is received.
public event EventHandler<ReceivedHttpResponseMessageEventArgs> ReceivedHttpResponse;
DrawingException¶
Occurs when the DrawingException event is raised.
public event EventHandler<DrawingExceptionLayerEventArgs> DrawingException;
DrawnException¶
Occurs when the DrawnException event is raised.
public event EventHandler<DrawnExceptionLayerEventArgs> DrawnException;