【发布时间】:2020-04-15 01:52:54
【问题描述】:
我在 React Native 中使用 react-native-maps,我想使用 OpenStreetMap(因为 Google 地图对于商业项目来说非常昂贵)。 MapView 给出的图块分辨率很低,图块和标签非常模糊(见下图)。
此代码与 Google 地图完美配合:
import MapView, {
MAP_TYPES,
PROVIDER_DEFAULT,
PROVIDER_GOOGLE,
} from "react-native-maps";
...
<MapView
ref={(map) => (currentMap = map)}
initialRegion={location}
showsUserLocation
style={{
height: Globals.Layout.window.height,
width: Globals.Layout.window.width,
}}
></MapView>
改为使用 OpenStreetMap,您会得到正确的图块,但一切都模糊且分辨率低:
import MapView, {
MAP_TYPES,
PROVIDER_DEFAULT,
PROVIDER_GOOGLE,
} from "react-native-maps";
...
<MapView
ref={(map) => (currentMap = map)}
initialRegion={location}
showsUserLocation
provider={PROVIDER_DEFAULT}
mapType={MAP_TYPES.NONE}
style={{
height: Globals.Layout.window.height,
width: Globals.Layout.window.width,
}}
>
<MapView.UrlTile
urlTemplate={"http://a.tile.openstreetmap.org/{z}/{x}/{y}.png"}
shouldReplaceMapContent={true}
/>
</MapView>
OpenStreetMap result (very blurry)
环境信息:
- 反应:~16.9.0 => 16.9.0
- 反应原生:0.61.4
- react-native-maps: 0.26.1
如何使图块的分辨率更高(或模拟缩小?)
【问题讨论】:
-
您需要使用支持high-resolution tiles 的不同图块源,也称为视网膜图块。
-
我不知道它是否有帮助,但是 OSM 鼓励用户运行他们自己的 tile 服务器 - 也许这样可以解决 res 问题?
标签: react-native openstreetmap resolution react-native-maps blurry