@@ -5,7 +5,7 @@ editor.session.setMode("ace/mode/javascript");
5
5
const editableCode = `
6
6
async function initializeMap() {
7
7
const htmlTemplate = await ProbableFuturesMapsHTMLGenerator.generateEmbedMap({
8
- datasetId: 40101 ,
8
+ datasetId: 40104 ,
9
9
viewState: { zoom: 4 },
10
10
scenario: 2,
11
11
});
@@ -32,8 +32,25 @@ function saveAndRunCode() {
32
32
document . getElementById ( "map-container" ) . innerHTML = "" ;
33
33
34
34
try {
35
+ const scenarioMatch = newCode . match ( / s c e n a r i o : \s * ( [ \d . ] + ) / ) ;
36
+ let scenarioValue = scenarioMatch ? parseFloat ( scenarioMatch [ 1 ] ) : null ;
37
+
35
38
eval ( newCode ) ;
36
39
initializeMap ( ) ;
40
+
41
+ document . querySelectorAll ( ".change-scenario-button" ) . forEach ( button => {
42
+ button . classList . remove ( "selected-scenario" ) ;
43
+ } ) ;
44
+
45
+ // Find and add "active" class to the button with the matching scenario value
46
+ if ( scenarioValue !== null ) {
47
+ const matchingButton = [ ...document . querySelectorAll ( ".change-scenario-button" ) ]
48
+ . find ( button => button . textContent . includes ( `${ scenarioValue } °C` ) ) ;
49
+
50
+ if ( matchingButton ) {
51
+ matchingButton . classList . add ( "selected-scenario" ) ;
52
+ }
53
+ }
37
54
} catch ( error ) {
38
55
console . error ( "Error executing the new code:" , error ) ;
39
56
}
@@ -46,7 +63,7 @@ window.onload = async function () {
46
63
}
47
64
48
65
const htmlTemplate = await ProbableFuturesMapsHTMLGenerator . generateEmbedMap ( {
49
- datasetId : 40101 ,
66
+ datasetId : 40104 ,
50
67
viewState : { zoom : 4 } ,
51
68
scenario : 2 ,
52
69
} ) ;
@@ -65,8 +82,15 @@ window.onload = async function () {
65
82
iframeDoc . close ( ) ;
66
83
} ;
67
84
68
- function changeScenario ( degree ) {
85
+ function changeScenario ( event , degree ) {
69
86
const iframe = document . querySelector ( "#map-container iframe" ) ;
87
+
88
+ document . querySelectorAll ( ".change-scenario-button" ) . forEach ( button => {
89
+ button . classList . remove ( "selected-scenario" ) ;
90
+ } ) ;
91
+
92
+ event . target . classList . add ( "selected-scenario" ) ;
93
+
70
94
if ( iframe ) {
71
95
iframe . contentWindow . postMessage (
72
96
{ action : "onDegreeChanged" , degree } ,
0 commit comments