Skip to content

Commit cc34673

Browse files
committed
docs(maps): improve tile usage examples
1 parent 2a58157 commit cc34673

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

docs/maps.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,61 @@ free and paid subscriptions. See the
66
[official Weather Maps documentation](https://openweathermap.org/api/weathermaps)
77
for API details.
88

9-
## Generate A Tile URL
9+
## Fetch A Tile
1010

11-
Use `tileUrl()` to generate an authenticated URL for a mapping library, image,
12-
or other client that loads the tile directly.
11+
Use `tile()` with a layer, zoom level, and X and Y tile coordinates.
1312

1413
```php
1514
use ProgrammatorDev\OpenWeatherMap\Enum\MapLayer;
1615
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
1716

1817
$api = new OpenWeatherMap($_ENV['OPENWEATHERMAP_API_KEY']);
1918

20-
$url = $api->maps()->tileUrl(
19+
$tile = $api->maps()->tile(
2120
layer: MapLayer::PRECIPITATION,
2221
zoom: 6,
2322
x: 31,
2423
y: 20,
2524
);
2625
```
2726

28-
Generating the URL does not make an HTTP request. It contains the API key passed
29-
to `OpenWeatherMap`, so treat it as a credential and avoid including it in logs
30-
or other unintended output.
27+
`tile()` returns one 256-by-256 PNG overlay as a `MapTile`. The request is made
28+
by the PHP application, so the API key is not included in the returned value.
3129

32-
## Fetch A Tile
30+
```php
31+
header('Content-Type: ' . $tile->contentType());
3332

34-
Use `tile()` with a layer, zoom level, and X and Y tile coordinates.
33+
echo $tile->contents();
34+
```
35+
36+
## Generate A Tile URL
37+
38+
Use `tileUrl()` when an image or another client needs to load one specific tile
39+
directly. Generating the URL does not make an HTTP request.
3540

3641
```php
3742
use ProgrammatorDev\OpenWeatherMap\Enum\MapLayer;
3843
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
3944

4045
$api = new OpenWeatherMap($_ENV['OPENWEATHERMAP_API_KEY']);
4146

42-
$tile = $api->maps()->tile(
47+
$url = $api->maps()->tileUrl(
4348
layer: MapLayer::PRECIPITATION,
4449
zoom: 6,
4550
x: 31,
4651
y: 20,
4752
);
4853
```
4954

50-
`tile()` returns one 256-by-256 PNG overlay as a `MapTile`. The request is made
51-
by the PHP application, so the API key is not included in the returned value.
55+
For example, the URL can be used as an image source:
5256

5357
```php
54-
header('Content-Type: ' . $tile->contentType());
55-
56-
echo $tile->contents();
58+
<img src="<?= $url ?>" alt="Precipitation map tile">
5759
```
5860

61+
The URL contains the API key passed to `OpenWeatherMap`. Treat it as a
62+
credential and expose it only where direct client loading is intended.
63+
5964
## Tile Coordinates
6065

6166
X and Y are tile indexes, not longitude and latitude. Weather Maps uses the

0 commit comments

Comments
 (0)