javascript - 当我单击一个标记时,我需要放大两个级别才能看到位置
问题描述
- 我正在使用标记集群组。
- 使用它我可以显示两个标记。
- 当您单击红色的第二个数字时,您将看到两个标记。
- 之后,当我单击一个标记时,我需要放大两个级别才能看到该位置
- 我为此写了一个标记单击,并在其中添加了缩放并尝试使用 fitbounds,但它没有放大。
- 我们使用了mapcenter然后它也没有工作`
- 你能告诉我如何解决它。
- 在下面提供我的代码片段和沙箱。
https://codesandbox.io/s/20756jrz8p
MarkerClick = e => {
console.log("e----->", e);
this.setState({
viewport: { center: [20, 6], zoom: 7 }
});
//this.refs.mymap.leafletElement.setZoom(8);
//let bounds = this.refs.mymap.leafletElement.fitBounds();
//console.log("bounds----->", bounds);
console.log(
"after setting state zoomlevel bounds showCard--->",
this.state.zoom
);
// this.setState({ zoom: 18 });
//this.setState({ zoomLevel: 7 });
};
解决方案
您在MarkerClick()中使用的缩放值低于当前缩放值 ( zoom = 8 )。因此,您没有得到适当的缩放。使用Zoom = 14 或 16和一组不同的坐标而不是 [20,6]。
例如:
MarkerClick = e => {
...
this.setState({
viewport: { center: [43.39528702235596, 6.294845731267186], zoom: 16 }
});
...
}
推荐阅读
- css - “溢出:自动”不会阻止宽 div 破坏表格布局
- python - 防止在加载、连接和重新保存 CSV 文件时更改浮点值
- c++ - 为什么我的输出没有以正确的值打印?
- r - R:提取数据集的语法相似条目
- arrays - 如何解决这个任务?在字符串中查找子字符串。C语言
- grafana - 限制对分配的命名空间的 Grafana 仪表板访问
- amazon-web-services - AWS RDS - 如何将快照设为私有
- javascript - 有没有办法在本地主机上实时更新/重新加载我的 php 页面?
- c++ - 在模板之外定义函数模板类
- django - 部署 Django + Next JS