reactjs - D3 + 带有反应 js 的传单地图
问题描述
我正在尝试制作地图并在同一张地图中使用 d3 绘制图钉,但不知何故,图钉没有出现,我也没有收到任何错误,但有时会出现此错误。
我的代码基本上从 api 获取数据,从 lat 和 long 获取数据以放入传单地图。
g.selectAll(...).data(...).enter is not a function
这是我的代码
React.useEffect(() => {
async function getWellheadf() {
const getWellhead = await ApiService.getWellhead();
const svg = d3.select(mapref.current).select("svg"),
g = svg.append("g");
getWellhead.data.forEach(function (d) {
d.LatLng = new L.latLng(d.Latitude, d.Longitude);
setWellhead(d.LatLng)
})
if (map) {
L.tileLayer('https://services.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Base/MapServer/tile/{z}/{y}/{x}.png', {
id: 'mapbox/streets-v11',
}).addTo(map);
console.log(wellhead)
const feature = g.selectAll("circle")
.data(wellhead)
.join("circle")
.enter().append("circle")
.style("stroke", "black")
.style("opacity", .6)
.style("fill", "red")
.attr("r", 20);
const update = () => {
feature.attr("transform",
function (d) {
return "translate(" +
map.latLngToLayerPoint(d.LatLng).x + "," +
map.latLngToLayerPoint(d.LatLng).y + ")";
}
)
}
map.on("viewreset", update);
// L.circle(wellhead, {
// color: 'black',
// fillColor: '#f03',
// fillOpacity: 0.5,
// radius: 500
// }).addTo(map);
}
}
getWellheadf();
}, [map]);
解决方案
推荐阅读
- sql - Sql中存在操作数
- python - 文本不显示 Pygame 2.0.1
- javascript - 是否可以编写一个可以在一个页面上打开所有链接但在新窗口中运行脚本的脚本?
- swift - 文件无法解析为字符串文件 [R.swift]
- javascript - 如何复制图像并将其保存在电子的新文件夹中
- html - iPhone 上没有自动生成 Safari 的新密码字段
- firemonkey - 如何检查是否满足 Firemonkey 平台先决条件?
- linux - 打印相当于经纪人 id 号码的 kafka 机器名称的 kafka 命令是什么
- python - 我不能接受 selenium python 中的警报
- flutter - 无法启动守护进程。此问题可能是由于守护程序配置不正确造成的