Skip to content

Commit b86f541

Browse files
authored
Merge pull request #18 from OpenHistoricalMap/1ec5-globe
Add globe control
2 parents 9af8722 + 815eebb commit b86f541

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@ Visit the map directly at [embed.openhistoricalmap.org](https://embed.openhistor
66

77
## URL parameters
88

9+
### Viewport
10+
911
The URL has typical z/x/y parameters for map zoom and center.
1012

1113
So a parameter like `#map=10/43.9367/12.5528` is zoom 10 showing San Marino in Italy, which is at `43.9367/12.5528` in `lon,lat` format of decimal degrees. [See the map.](https://embed.openhistoricalmap.org/#map=10/43.9367/12.5528)
1214

1315
An embedded map is typically of a different size and aspect ratio from the original and thus must be scaled in order to cover a comparable area. This is accomplished by passing the original map's bounding box in the hash as `&bbox=minlon,minlat,maxlon,maxlat`. Once the embedded map gets its initial framing from the `bbox` the normal hash mechanism takes over. The San Marino example could be bounded by appending `&bbox=12.321338653564453,43.86782687726672,12.58037567138672,44.008373185063874` to the URL. [See this map.](https://embed.openhistoricalmap.org/#map=10/43.9367/12.5528&bbox=12.321338653564453,43.86782687726672,12.58037567138672,44.008373185063874)
1416

17+
### Projection
18+
19+
The `projection` parameter accepts the following values:
20+
21+
* `mercator`, Web Mercator projection, represents the world as a square. It allows you to view both hemispheres at the same time but with extreme area distortion at the upper latitudes. This is the default projection.
22+
* `vertical-perspective`, Vertical Perspective projection, resembles a globe. It avoids area distortion but only shows one hemisphere at a time.
23+
* `globe` is a hybrid of `vertical-perspective` at low zoom levels and `mercator` at high zoom levels where the Web Mercator projection’s distortions matter much less.
24+
25+
The 🌐 button at the upper-left corner toggles between `mercator` and `globe` projection.
26+
1527
### Dates
1628

1729
Without a date parameter, the map shows everything in the OHM tiles for which there is a style specified.

index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ addEventListener('load', function () {
4242
});
4343

4444
map.addControl(new maplibregl.NavigationControl(), 'top-left');
45+
map.addControl(new maplibregl.GlobeControl(), 'top-left');
4546
map.addControl(new maplibregl.FullscreenControl(), 'top-left');
4647

4748
let languageCode = params.get('language');
@@ -82,6 +83,12 @@ addEventListener('load', function () {
8283
}
8384

8485
map.once('styledata', function (event) {
86+
if (params.get('projection')) {
87+
map.setProjection({
88+
type: params.get('projection'),
89+
});
90+
}
91+
8592
if (params.get('start_date') || params.get('end_date')) {
8693
animate(map, params.get('start_date'), params.get('end_date'));
8794
return;
@@ -108,6 +115,12 @@ addEventListener('load', function () {
108115
map.setStyle(newStyle, { diff: false });
109116
}
110117

118+
if (oldParams.get('projection') !== newParams.get('projection')) {
119+
map.setProjection({
120+
type: newParams.get('projection') || 'mercator',
121+
});
122+
}
123+
111124
if (newParams.get('start_date') || newParams.get('end_date')) {
112125
if (oldParams.get('start_date') !== newParams.get('start_date') ||
113126
oldParams.get('end_date') !== newParams.get('end_date')) {

0 commit comments

Comments
 (0)