Skip to content

Commit d43d8a3

Browse files
committed
fix(map): fix tile size for retina-enabled tiles
fix #109
1 parent f490da1 commit d43d8a3

File tree

3 files changed

+42
-25
lines changed

3 files changed

+42
-25
lines changed

Diff for: example-config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ map:
3333
subdomains: 'abcd'
3434
attribution: 'Map tiles: &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, &copy; <a href="https://carto.com/attributions">CARTO</a>'
3535
maxZoom: 20
36+
hasRetinaSupport: true
3637
- name: Stamen Toner Lite
3738
url: http://tile.stamen.com/toner-lite/{z}/{x}/{y}.png
3839
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.'

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

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import L from 'leaflet'
12
import React, { Component } from 'react'
23
import { LayersControl, TileLayer } from 'react-leaflet'
34
import { connect } from 'react-redux'
@@ -8,16 +9,23 @@ class BaseLayers extends Component {
89
const { BaseLayer, Overlay } = LayersControl
910
return (
1011
<LayersControl>
11-
{baseLayers && baseLayers.map((l, i) => (
12-
<BaseLayer
13-
name={l.name}
14-
checked={i === 0}
15-
key={i}>
16-
<TileLayer
17-
{...l}
18-
detectRetina />
19-
</BaseLayer>
20-
))}
12+
{baseLayers && baseLayers.map((l, i) => {
13+
// Fix tile size/zoom offset: https://stackoverflow.com/a/37043490/915811
14+
const retinaProps = L.Browser.retina && l.hasRetinaSupport
15+
? { tileSize: 512, zoomOffset: -1 }
16+
: {}
17+
return (
18+
<BaseLayer
19+
name={l.name}
20+
checked={i === 0}
21+
key={i}>
22+
<TileLayer
23+
{...l}
24+
{...retinaProps}
25+
detectRetina />
26+
</BaseLayer>
27+
)
28+
})}
2129
{overlays && overlays.map((l, i) => (
2230
<Overlay
2331
name={l.name}

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

+23-15
Original file line numberDiff line numberDiff line change
@@ -283,25 +283,33 @@ class BaseMap extends Component {
283283
{/* Create the layers control, including base map layers and any
284284
* user-controlled overlays. */}
285285
<LayersControl position='topright'>
286-
{ /* base layers */
287-
baseLayers && baseLayers.map((l, i) => (
288-
<LayersControl.BaseLayer
289-
name={l.name}
290-
checked={i === 0}
291-
key={i}>
292-
<TileLayer
293-
url={l.url}
294-
attribution={l.attribution}
295-
maxZoom={l.maxZoom}
296-
detectRetina />
297-
</LayersControl.BaseLayer>
298-
))
286+
{/* base layers */
287+
baseLayers && baseLayers.map((layer, i) => {
288+
// Fix tile size/zoom offset: https://stackoverflow.com/a/37043490/915811
289+
const retinaProps = L.Browser.retina && layer.hasRetinaSupport
290+
? { tileSize: 512, zoomOffset: -1 }
291+
: {}
292+
return (
293+
<LayersControl.BaseLayer
294+
name={layer.name}
295+
checked={i === 0}
296+
key={i}>
297+
<TileLayer
298+
url={layer.url}
299+
attribution={layer.attribution}
300+
maxZoom={layer.maxZoom}
301+
{...retinaProps}
302+
detectRetina />
303+
</LayersControl.BaseLayer>
304+
)
305+
})
299306
}
300307

301-
{ /* user-controlled overlay layers (e.g., vehicle locations, stops) */
308+
{/* user-controlled overlay layers (e.g., vehicle locations, stops) */
302309
userControlledOverlays.map((child, i) => {
303310
return (
304-
<LayersControl.Overlay key={i}
311+
<LayersControl.Overlay
312+
key={i}
305313
name={child.props.name}
306314
checked={child.props.visible}
307315
>

0 commit comments

Comments
 (0)