用例
我想创建一个 React Native 应用程序,该应用程序在具有特殊地图投影的世界地图上显示存储在 PostGIS 数据库中的坐标。
到目前为止我做了什么
我成功地将地图加载到我的 Web 版本应用程序的 React 环境中。这是我实现的代码(仅包括保存地图的组件):
import React, { useEffect, useRef } from 'react';
import Aux from '../../../../hoc/Auxiliary';
import styles from './Backmap.module.css';
import * as d3 from "d3";
import { feature } from "topojson-client";
import landmass from "./../../../../land-50m";
const Backmap = (props) => {
const mapContainer = useRef(null);
let width = props.windowSize.windowWidth;
let height = props.windowSize.windowHeight;
useEffect(() => {
const svg = d3.select(mapContainer.current)
.attr("width", width)
.attr("height", height)
const g = svg.append("g")
let features = feature(landmass, landmass.objects.land).features
let projection = d3.geoAzimuthalEqualArea()
.center([180, -180])
.rotate([0, -90])
.fitSize([width, height], { type: "FeatureCollection", features: features })
.clipAngle(150)
let path = d3.geoPath().projection(projection)
g.selectAll("#landmass")
.data(features)
.enter().append("path")
.attr("id", "landmass")
.attr("d", path);
}, [])
return (
<Aux>
<svg
className={styles.Backmap}
width={props.windowSize.windowWidth}
height={props.windowSize.windowHeight}
ref={mapContainer}
>
</svg>
</Aux>
)
}
export default Backmap;
这是上面代码的结果映射:
我还研究了如何实现 SVG 形状,甚至映射到 React Native,并遇到了几种方法:
问题
但是,我无法使用这些解决方案实现任何地图。上面列表中的前两个没有提到任何地图实现,而后一个似乎是一个非常早期的 beta 版本。所以我想知道这在 React Native 中是否可行。有人知道在 React Native 中插入 SVG 地图的方法吗?