Skip to content

Commit 7a837d5

Browse files
feat: update map api page (#54)
* feat: update map api page * feat: add compare maps --------- Co-authored-by: Moustafa <[email protected]>
1 parent b1a871b commit 7a837d5

File tree

4 files changed

+52
-56
lines changed

4 files changed

+52
-56
lines changed

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ GEM
2020
ffi (1.16.3)
2121
forwardable-extended (2.6.0)
2222
google-protobuf (3.25.1-arm64-darwin)
23+
google-protobuf (3.25.1-x86_64-darwin)
2324
http_parser.rb (0.8.0)
2425
i18n (1.14.1)
2526
concurrent-ruby (~> 1.0)
@@ -66,13 +67,16 @@ GEM
6667
safe_yaml (1.0.5)
6768
sass-embedded (1.69.5-arm64-darwin)
6869
google-protobuf (~> 3.23)
70+
sass-embedded (1.69.5-x86_64-darwin)
71+
google-protobuf (~> 3.23)
6972
terminal-table (3.0.2)
7073
unicode-display_width (>= 1.1.1, < 3)
7174
unicode-display_width (2.5.0)
7275
webrick (1.8.1)
7376

7477
PLATFORMS
7578
arm64-darwin-22
79+
x86_64-darwin-23
7680

7781
DEPENDENCIES
7882
bundler (>= 2.3.5)

assets/css/pf-maps.css

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.generate-maps-button {
1+
.generate-maps-button, .change-scenario-button {
22
background-color: #851fff;
33
color: white;
44
border: none;
@@ -10,36 +10,12 @@
1010
transition: background 0.3s ease, transform 0.2s;
1111
}
1212

13-
.generate-maps-button:hover {
13+
.generate-maps-button:hover, .change-scenario-button:hover, .selected-scenario {
1414
background-color: #6a17cc;
15-
transform: scale(1.05);
1615
}
1716

18-
.generate-maps-button:active {
17+
.generate-maps-button:active, .change-scenario-button:active {
1918
background-color: #5a14a8;
20-
transform: scale(0.98);
21-
}
22-
23-
.change-scenario-button {
24-
background-color: #DA2E80;
25-
color: white;
26-
border: none;
27-
padding: 8px 16px;
28-
font-size: 12px;
29-
font-weight: bold;
30-
border-radius: 4px;
31-
cursor: pointer;
32-
transition: background 0.3s ease, transform 0.2s;
33-
}
34-
35-
.change-scenario-button:hover, .selected-scenario {
36-
background-color: #cc1717;
37-
transform: scale(1.05);
38-
}
39-
40-
.change-scenario-button:active {
41-
background-color: #a81414;
42-
transform: scale(0.98);
4319
}
4420

4521
#map-code-editor {

assets/js/pf-maps.js

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const editableCode = `
66
async function initializeMap() {
77
const htmlTemplate = await ProbableFuturesMapsHTMLGenerator.generateEmbedMap({
88
datasetId: 40104,
9-
viewState: { zoom: 4 },
9+
viewState: { zoom: 4, latitude: 3.8, longitude: -70.4},
1010
scenario: 2,
1111
});
1212
@@ -56,15 +56,10 @@ function saveAndRunCode() {
5656
}
5757
}
5858

59-
window.onload = async function () {
60-
if (typeof ProbableFuturesMapsHTMLGenerator === "undefined") {
61-
console.error("ProbableFuturesMapsHTMLGenerator is not loaded. Check the script URL.");
62-
return;
63-
}
64-
59+
async function generateSimpleMap() {
6560
const htmlTemplate = await ProbableFuturesMapsHTMLGenerator.generateEmbedMap({
6661
datasetId: 40104,
67-
viewState: { zoom: 4 },
62+
viewState: { zoom: 4, latitude: 3.8, longitude: -70.4},
6863
scenario: 2,
6964
});
7065

@@ -80,6 +75,40 @@ window.onload = async function () {
8075
iframeDoc.open();
8176
iframeDoc.write(htmlTemplate);
8277
iframeDoc.close();
78+
}
79+
80+
async function generateCompareMap() {
81+
const htmlTemplate = await ProbableFuturesMapsHTMLGenerator.generateEmbedMap({
82+
datasetId: 40702,
83+
viewState: { zoom: 4, latitude: 3.8, longitude: -70.4},
84+
compare: {
85+
scenarioBefore: 1,
86+
scenarioAfter: 3,
87+
},
88+
});
89+
90+
// Create an iframe
91+
const iframe = document.createElement("iframe");
92+
iframe.style.width = "100%";
93+
iframe.style.height = "600px";
94+
iframe.style.border = "none";
95+
document.getElementById("compare-map-container").appendChild(iframe);
96+
97+
// Write the generated HTML template inside the iframe
98+
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
99+
iframeDoc.open();
100+
iframeDoc.write(htmlTemplate);
101+
iframeDoc.close();
102+
}
103+
104+
window.onload = async function () {
105+
if (typeof ProbableFuturesMapsHTMLGenerator === "undefined") {
106+
console.error("ProbableFuturesMapsHTMLGenerator is not loaded. Check the script URL.");
107+
return;
108+
}
109+
110+
generateSimpleMap();
111+
generateCompareMap();
83112
};
84113

85114
function changeScenario(event, degree) {

map-api.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@ parent: Maps
77

88
# Map APIs and embeds
99

10-
This section is for people who want to integrate the Probable Futures maps into their own websites or applications. It is possible to achieve this in three ways:
10+
This section describes how to integrate the Probable Futures maps into any website or application. Typically, there are two ways people prefer to do this. If a map will be added to an article, embeddable maps downloaded directly from the Probable Futures website are a simple and efficient option. If the maps will be used in an application, where the maps will change dynamically, one of the two map API packages work best. For more customization options, see the [map customizations page](/map-customization).
1111

12-
1. Use the map APIs (npm packages) to integrate the maps into your own application, for example if you are creating an application where you will display more than one map.
13-
2. Download an embeddable map, for example to display a map in an article.
14-
3. Customize, restyle, and host the maps with your own Mapbox account, for example if you would like to use different colors or bins on the maps.
12+
## Embeddable maps - downloaded from probablefutures.org
1513

16-
### Use cases
14+
1. On [probablefutures.org/maps](https://probablefutures.org/maps), position the map location and zoom level exactly as you would like it to appear in the embed.
15+
2. Click the download button on the right side. In the pop-up, select between either a standard embeddable map or embeddable comparison map. When you are done choosing your options, click the download button to download the embeddable map as an HTML file.
16+
3. Add the file to any website. Typically, it's best to do this by placing the contents of the HTML file inside an `<iframe>` element.
1717

18-
These maps APIs can be used to:
19-
20-
- Add clear and compelling visual maps of our changing climate to any website, article, story, or app
21-
- Show any place in the world, at any zoom level
22-
- Do the above for a single warming scenario or multiple, in comparison or sequentially
18+
<div id="compare-map-container"></div>
2319

2420
## Embeddable maps API - using React
2521

@@ -42,18 +38,9 @@ This package offers an HTML generator that creates pure HTML versions of the Pro
4238

4339
Learn more about this package and find installation instruction in [the npm registry: @probable-futures/probable-futures-maps-html-generator](https://www.npmjs.com/package/@probable-futures/probable-futures-maps-html-generator).
4440

45-
## Embeddable maps - direct download
46-
47-
1. Go to [probablefutures.org/maps](https://probablefutures.org/maps).
48-
2. Navigate the map to a place in the world that you would like to show in the embeddable map.
49-
3. Click the download button on the top right.
50-
4. Select "Download as embeddable map" or "Download as embeddable comparison map". If selecting a standard embeddable map, the warming scenario you are viewing will be shown in the embeddable map. If selecting a comparison map, choose the warming scenarios you would like to include in the embeddable map in the next step.
51-
5. Click the download button to download the embeddable map file.
52-
6. Add the file to any website, application, or article.
53-
54-
## Demo
41+
### Demo: Generating a climate map using a map API package
5542

56-
### Generating climate map using `@probable-futures/probable-futures-html-generator` package
43+
The code below uses the `@probable-futures/probable-futures-html-generator` package to generate a map. You can edit the code and click the "Save and Run Code" button to change the map. For example, change the `datasetID` to change the type of map being shown, change the `zoom` to change the zoom of the map, and change the `latitude` or `longitude` to change the center focus of the map.
5744

5845
<div id="map-code-editor" style="height: 300px; width: 100%; border: 1px solid #ccc;"></div>
5946
<button class="generate-maps-button" onclick="saveAndRunCode()">Save and Run Code</button>

0 commit comments

Comments
 (0)