Skip to content

Commit

Permalink
Update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
alextts627 committed Jul 21, 2022
1 parent a89d6a4 commit 2ade62b
Show file tree
Hide file tree
Showing 25 changed files with 871 additions and 31 deletions.
14 changes: 11 additions & 3 deletions sdk/maps/azure-maps-render/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ The following sections provide several code snippets covering some of the most c

- [Get Maps Attribution](#get-maps-attribution)

### Get Maps Attr
### Get Maps Attribution

Get Maps Attr
Get Maps Attribution

```python
from azure.maps.render import MapsRenderClient

render_result = client.render_address("400 Broad, Seattle");
result = maps_render_client.get_map_attribution(tileset_id=TilesetID.MICROSOFT_BASE, zoom=6, bounds=BoundingBox(bottom_left=(LatLon(42.982261, 24.980233)), top_right=(LatLon(56.526017, 1.355233))))
```

## Troubleshooting
Expand Down Expand Up @@ -166,6 +166,14 @@ set AZURE_SUBSCRIPTION_KEY="<RealSubscriptionKey>"
pip install azure-maps-render --pre

python samples/sample_authentication.py
python sample/sample_get_copyright_caption.py
python sample/sample_get_copyright_for_tile.py
python sample/sample_get_copyright_for_world.py
python sample/sample_get_copyright_from_bounding_box.py
python sample/sample_get_map_attribution.py
python sample/sample_get_map_static_image.py
python sample/sample_get_map_tile.py
python sample/sample_get_map_tileset.py
```

> Notes: `--pre` flag can be optionally added, it is to include pre-release and development versions for `pip install`. By default, `pip` only finds stable versions.
Expand Down
4 changes: 2 additions & 2 deletions sdk/maps/azure-maps-render/azure/maps/render/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from azure.core.pipeline.policies import AzureKeyCredentialPolicy
from azure.core.credentials import AzureKeyCredential
from ._generated import RenderClient as _MapsRenderClient
from ._version import VERSION
from ._version import API_VERSION
if TYPE_CHECKING:
from azure.core.credentials import TokenCredential

Expand Down Expand Up @@ -38,7 +38,7 @@ def __init__(

self._maps_client = _MapsRenderClient(
credential=credential, # type: ignore
api_version=kwargs.pop("api_version", VERSION),
api_version=kwargs.pop("api_version", API_VERSION),
authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential)),
**kwargs
)
Expand Down
18 changes: 12 additions & 6 deletions sdk/maps/azure-maps-render/azure/maps/render/_render_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def get_map_tile(
z=tile_index_z,
x=tile_index_x,
y=tile_index_y,
tile_size=kwargs.pop("tile_size", "256")
**kwargs
)

Expand Down Expand Up @@ -153,12 +152,19 @@ def get_map_attribution(
:param bounds:
The string that represents the rectangular area of a bounding box. The bounds
parameter is defined by the 4 bounding box coordinates, with WGS84 longitude and latitude of
the southwest corner followed by WGS84 longitude and latitude of the northeast corner.
the southwest corner which is "bottom_left" followed by WGS84 longitude and latitude of the northeast corner which is "top_right".
:type bounds: BoundingBox
:return: MapAttribution
:rtype: ~azure.maps.render.models.MapAttribution
:raises ~azure.core.exceptions.HttpResponseError:
"""
bounds=[
bounds.bottom_left.lat,
bounds.bottom_left.lon,
bounds.top_right.lat,
bounds.top_right.lon
]

return self._render_client.get_map_attribution(
tileset_id=tileset_id,
zoom=zoom,
Expand Down Expand Up @@ -230,7 +236,7 @@ def get_copyright_caption(
@distributed_trace
def get_map_static_image(
self,
_format, # type Union[str, "models.RasterTileFormat"]
format, # type Union[str, "models.RasterTileFormat"]
**kwargs # type: Any
):
# type: (...) -> Iterator[bytes]
Expand Down Expand Up @@ -287,7 +293,7 @@ def get_map_static_image(
:raises ~azure.core.exceptions.HttpResponseError:
"""
return self._render_client.get_map_static_image(
format=_format,
format=format,
**kwargs
)

Expand Down Expand Up @@ -316,8 +322,8 @@ def get_copyright_from_bounding_box(
_include_text=kwargs.pop("include_text", True)

return self._render_client.get_copyright_from_bounding_box(
south_west=bounding_box.bottom_left,
north_east=bounding_box.top_right,
south_west=(bounding_box.bottom_left.lat,bounding_box.bottom_left.lon),
north_east=(bounding_box.top_right.lat,bounding_box.top_right.lon),
include_text= "yes" if _include_text else "no",
**kwargs
)
Expand Down
1 change: 1 addition & 0 deletions sdk/maps/azure-maps-render/azure/maps/render/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
# --------------------------------------------------------------------------

VERSION = "1.0.0b1"
API_VERSION = "2.1"
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from azure.core.pipeline.policies import AzureKeyCredentialPolicy
from azure.core.credentials import AzureKeyCredential
from .._generated.aio import RenderClient as _MapsRenderClient
from .._version import VERSION
from .._version import API_VERSION
if TYPE_CHECKING:
from azure.core.credentials_async import AsyncTokenCredential

Expand Down Expand Up @@ -37,7 +37,7 @@ def __init__(

self._maps_client = _MapsRenderClient(
credential=credential, # type: ignore
api_version=kwargs.pop("api_version", VERSION),
api_version=kwargs.pop("api_version", API_VERSION),
authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential)),
**kwargs
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ async def get_map_tile(
z=tile_index_z,
x=tile_index_x,
y=tile_index_y,
tile_size=kwargs.pop("tile_size", "256")
**kwargs
)

Expand Down Expand Up @@ -157,6 +156,13 @@ async def get_map_attribution(
:rtype: ~azure.maps.render.models.MapAttribution
:raises ~azure.core.exceptions.HttpResponseError:
"""
bounds=[
bounds.bottom_left.lat,
bounds.bottom_left.lon,
bounds.top_right.lat,
bounds.top_right.lon
]

return await self._render_client.get_map_attribution(
tileset_id=tileset_id,
zoom=zoom,
Expand Down Expand Up @@ -226,7 +232,7 @@ async def get_copyright_caption(
@distributed_trace_async
async def get_map_static_image(
self,
_format, # type Union[str, "models.RasterTileFormat"]
format, # type Union[str, "models.RasterTileFormat"]
**kwargs # type: Any
):
# type: (...) -> Iterator[bytes]
Expand Down Expand Up @@ -283,7 +289,7 @@ async def get_map_static_image(
:raises ~azure.core.exceptions.HttpResponseError:
"""
return await self._render_client.get_map_static_image(
format=_format,
format=format,
**kwargs
)

Expand Down Expand Up @@ -312,8 +318,8 @@ async def get_copyright_from_bounding_box(

return await self._render_client.get_copyright_from_bounding_box(
include_text= "yes" if _include_text else "no",
south_west=bounding_box.bottom_left,
north_east=bounding_box.top_right,
south_west=(bounding_box.bottom_left.lat,bounding_box.bottom_left.lon),
north_east=(bounding_box.top_right.lat,bounding_box.top_right.lon),
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class BoundingBox(object):

def __init__(
self,
top_left: LatLon = None,
bottom_right: LatLon = None,
top_right: LatLon = None,
bottom_left: LatLon = None
top_left: LatLon = LatLon(),
bottom_right: LatLon = LatLon(),
top_right: LatLon = LatLon(),
bottom_left: LatLon = LatLon()
):
self.top_left = top_left
self.bottom_right = bottom_right
Expand Down
18 changes: 16 additions & 2 deletions sdk/maps/azure-maps-render/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@ Authenticate the client with a Azure Maps Render [API Key Credential](https://do

Then for common Azure Maps Render operations:

* Perform fuzzy render: [sample_fuzzy_render.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/sample_fuzzy_render.py) ([async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/async_samples/sample_fuzzy_render_async.py))
* Perform Get Map tile: [sample_get_map_tile.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/sample_get_map_tile.py) ([async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/async_samples/sample_get_map_tile_async.py))

* Perform Get Map tileset: [sample_get_map_tileset.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/sample_get_map_tileset.py) ([async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/async_samples/sample_get_map_tileset_async.py))

* Perform Get Map static image: [sample_get_map_static_image.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/sample_get_map_static_image.py) ([async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/async_samples/sample_get_map_static_image_async.py))

* Perform Get Map Attribution: [sample_get_map_attribution.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/sample_get_map_attribution.py) ([async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/async_samples/sample_get_map_attribution_async.py))

* Perform Get Copyright from bounding box: [sample_get_copyright_from_bounding_box.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/sample_get_copyright_from_bounding_box.py) ([async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/async_samples/sample_get_copyright_from_bounding_box_async.py))

* Perform Get Copyright fpr world: [sample_get_copyright_for_world.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/sample_get_copyright_for_world.py) ([async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/async_samples/sample_get_copyright_for_world_async.py))

* Perform Get Copyright for tile: [sample_get_copyright_for_tile.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/sample_get_copyright_for_tile.py) ([async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/async_samples/sample_get_copyright_for_tile_async.py))

* Perform Get Copyright caption: [sample_get_copyright_caption.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/sample_get_copyright_caption.py) ([async version](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/maps/azure-maps-render/samples/async_samples/sample_get_copyright_caption_async.py))

## Prerequisites

Expand All @@ -40,7 +54,7 @@ Then for common Azure Maps Render operations:

1. Open a terminal window and `cd` to the directory that the samples are saved in.
2. Set the environment variables specified in the sample file you wish to run.
3. Follow the usage described in the file, e.g. `python sample_fuzzy_render.py`
3. Follow the usage described in the file, e.g. `python sample_get_map_tile.py`

## Next steps

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# coding: utf-8

# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

"""
FILE: sample_get_copyright_caption_async.py
DESCRIPTION:
This sample demonstrates how to serve copyright information for Render Tile
service. In addition to basic copyright for the whole map, API is serving
specific groups of copyrights for some countries.
USAGE:
python sample_get_copyright_caption_async.py
Set the environment variables with your own values before running the sample:
- AZURE_SUBSCRIPTION_KEY - your subscription key
"""

import asyncio
import os
import json

def to_json(self):
return json.dumps(
self,
default=lambda o: o.__dict__,
sort_keys=True,
indent=4
)

subscription_key = os.getenv("AZURE_SUBSCRIPTION_KEY")

async def get_copyright_caption_async():
# [START get_copyright_caption_async]
from azure.core.credentials import AzureKeyCredential
from azure.maps.render.aio import MapsRenderClient

maps_render_client = MapsRenderClient(credential=AzureKeyCredential(subscription_key))

async with maps_render_client:
result = await maps_render_client.get_copyright_caption()

print("Get copyright caption result:")
print(result)
print("------------------------------")
print("Get copyright caption result in Json format:")
print(to_json(result))
# [END get_copyright_caption_async]

if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(get_copyright_caption_async())
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# coding: utf-8

# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

"""
FILE: sample_get_copyright_for_tile_async.py
DESCRIPTION:
This sample demonstrates how to serve copyright information for Render Tile service.
In addition to basic copyright for the whole map, API is serving specific groups of copyrights for some countries.
Returns the copyright information for a given tile. To obtain the copyright information for a
particular tile, the request should specify the tile's zoom level and x and y coordinates (see:
Zoom Levels and Tile Grid).
USAGE:
python sample_get_copyright_for_tile_async.py
Set the environment variables with your own values before running the sample:
- AZURE_SUBSCRIPTION_KEY - your subscription key
"""
import asyncio
import os
import json

def to_json(self):
return json.dumps(
self,
default=lambda o: o.__dict__,
sort_keys=True,
indent=4
)

subscription_key = os.getenv("AZURE_SUBSCRIPTION_KEY")

async def get_copyright_for_tile_async():
# [START get_copyright_for_tile_async]
from azure.core.credentials import AzureKeyCredential
from azure.maps.render.aio import MapsRenderClient

maps_render_client = MapsRenderClient(credential=AzureKeyCredential(subscription_key))

async with maps_render_client:
result = await maps_render_client.get_copyright_for_tile(tile_index_z=6, tile_index_x=9, tile_index_y=22)

print("Get copyright for tile result:")
print(result)
print("------------------------------")
print("Get copyright for tile result in Json format:")
print(to_json(result))
# [END get_copyright_for_tile_async]

if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(get_copyright_for_tile_async())
Loading

0 comments on commit 2ade62b

Please sign in to comment.