@@ -109,29 +109,46 @@ class CMap extends React.PureComponent {
109
109
}
110
110
}
111
111
112
- initializeMap ( ) {
113
- if ( ! this . props . changeset ) {
114
- return ;
115
- }
112
+ async initializeMap ( ) {
113
+ if ( ! this . props . changeset ) return ;
116
114
117
115
let container = document . getElementById ( 'container' ) ;
118
116
119
117
if ( this . map ) {
120
118
this . map . remove ( ) ;
121
119
}
122
120
123
- let style = BING_AERIAL_IMAGERY_STYLE ;
121
+ let style ;
124
122
125
- if ( this . props . style === 'carto' ) {
123
+ const styleType = 'ohm' ;
124
+
125
+ if ( styleType === 'carto' ) {
126
126
style = OPENSTREETMAP_CARTO_STYLE ;
127
+ } else if ( styleType === 'ohm' ) {
128
+ try {
129
+ const response = await fetch (
130
+ 'https://www.openhistoricalmap.org/map-styles/main/main.json'
131
+ ) ;
132
+ style = await response . json ( ) ;
133
+ } catch ( err ) {
134
+ console . error ( 'Failed to load OHM style:' , err ) ;
135
+ this . props . modal ( {
136
+ kind : 'error' ,
137
+ title : 'Failed to load map style' ,
138
+ description : 'Could not load OpenHistoricalMap style.'
139
+ } ) ;
140
+ return ;
141
+ }
142
+ } else {
143
+ style = BING_AERIAL_IMAGERY_STYLE ;
127
144
}
128
145
129
146
let map = new maplibre . Map ( {
130
147
container,
131
148
style,
132
149
maxZoom : 22 ,
133
150
hash : false ,
134
- attributionControl : false // we're moving this to the other corner
151
+ attributionControl : false
135
152
} ) ;
136
153
137
154
map . addControl ( new maplibre . AttributionControl ( ) , 'bottom-left' ) ;
@@ -142,9 +159,9 @@ class CMap extends React.PureComponent {
142
159
map . keyboard . disableRotation ( ) ;
143
160
144
161
let { adiff } = this . props . changeset ;
145
- // HACK: override attribution string (the string Overpass sends is wordier and doesn't have a hyperlink)
146
162
adiff . note =
147
163
'Map data from <a href=https://openstreetmap.org/copyright>OpenStreetMap</a>' ;
164
+
148
165
const adiffViewer = new MapLibreAugmentedDiffViewer ( adiff , {
149
166
onClick : this . handleClick ,
150
167
showElements : this . props . showElements ,
@@ -181,8 +198,6 @@ class CMap extends React.PureComponent {
181
198
this . map = map ;
182
199
this . adiffViewer = adiffViewer ;
183
200
184
- // Store the map and adiffViewer in the ref passed from the parent component
185
- // (this allows other components to imperatively update the map state)
186
201
if ( this . props . mapRef ) {
187
202
this . props . mapRef . current = {
188
203
map : this . map ,
0 commit comments