Skip to content

Commit 177a56e

Browse files
committed
refactor(base-map): handle non-retina displays
1 parent 1c79460 commit 177a56e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Diff for: lib/components/map/base-map.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -298,20 +298,29 @@ class BaseMap extends Component {
298298
<LayersControl position='topright'>
299299
{/* base layers */
300300
baseLayers && baseLayers.map((layer, i) => {
301-
// Fix tile size/zoom offset: https://stackoverflow.com/a/37043490/915811
302-
const retinaProps = L.Browser.retina && layer.hasRetinaSupport
301+
// If layer supports retina tiles, set tileSize and zoomOffset
302+
// (see https://stackoverflow.com/a/37043490/915811).
303+
// Otherwise, use detectRetina to request more tiles (scaled down):
304+
// https://leafletjs.com/reference-1.6.0.html#tilelayer-detectretina
305+
const retinaProps = layer.hasRetinaSupport
303306
? { tileSize: 512, zoomOffset: -1 }
304-
: {}
307+
: { detectRetina: true }
308+
// If Browser doesn't support retina, remove @2x from URL so that
309+
// retina tiles are not requested.
310+
const url = L.Browser.retina
311+
? layer.url
312+
: layer.url.replace('@2x', '')
305313
return (
306314
<LayersControl.BaseLayer
307315
name={layer.name}
308316
checked={i === 0}
309317
key={i}>
310318
<TileLayer
311-
url={layer.url}
319+
url={url}
312320
attribution={layer.attribution}
313321
maxZoom={layer.maxZoom}
314-
{...retinaProps} />
322+
{...retinaProps}
323+
/>
315324
</LayersControl.BaseLayer>
316325
)
317326
})

0 commit comments

Comments
 (0)