leaflet - 如何使用 Leaflet open street map in angular 将地图中心位置更改为顶部位置
问题描述
在我的角度应用程序中,我创建了传单地图,在传单地图上,我以重叠的方式创建了另外两个面板数据,并且我在地图上创建了半径为 5 公里的圆圈。但我的问题是面板覆盖了传单地图上的圆圈
所以我的要求是将地图的中心位置,即圆圈移动到顶部位置(顶部中间),而不是只有圆圈可见,否则它将被地图上的面板覆盖。
组件.ts
map = L.map('map').setView([13.0827, 80.2707], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.control.zoom({
position: 'bottomright',
}).addTo(map);
我是传单地图的新手,任何人都可以帮助我解决这个问题。
解决方案
You can let the map fit the circle bounds, like:
var circle = L.circle() // Your circle
map.fitBounds(circle.getBounds())
To show the circle on the left side of the map:
map.setView(circle.getLatLng(),map.getZoom(),{animate: false})
sw = map.getBounds().getSouthWest();
psw = map.latLngToContainerPoint(sw);
center = map.getCenter();
pc = map.latLngToContainerPoint(center);
dis = pc.x - psw.x;
middle = dis / 2
pnewCenter = L.point(pc.x+middle,pc.y)
center2 = map.containerPointToLatLng(pnewCenter);
map.setView(center2,map.getZoom(),{animate: true})
推荐阅读
- javascript - 如何从 Typescript 中的对象内联解构嵌套的可选属性?
- tsql - 如何查看一个表是否为空?
- flutter - 如何每隔 x 秒更新一次来自手机状态的文本数据
- spring - 为什么 Spring Boot 应用启动时会出现异常?
- airflow - 如何使用气流声明复杂的依赖关系
- reactjs - 在 nextjs 中实现实时网络通知推送器
- functional-programming - 如何用像 Kind-Lang 这样的纯函数语言用代数数据类型对 Int 类型进行编码?
- scala - 有没有办法引用被内联类字段隐藏的函数参数?
- python - 用于 wav 文件的 torchaudio“RuntimeError:加载音频文件时出错:打开文件失败”
- javascript - 建议:使用 JQuery mousemove 进行鼠标跟踪