OpenLayers ZoomToExtent 无法正确缩放

发布于 2024-12-06 17:22:53 字数 742 浏览 1 评论 0原文

我有一个带有几个 POI 的 openlayers 地图,我想缩放以便这些都适合地图,我使用以下代码执行此操作:

var bbox = new OpenLayers.Bounds(
    <?php echo $this->box->getSmallestLongitude() ?>,
    <?php echo $this->box->getSmallestLatitude() ?>,
    <?php echo $this->box->getLargestLongitude() ?>,
    <?php echo $this->box->getLargestLatitude() ?>
).transform(map.displayProjection, map.projection);
map.zoomToExtent(bbox);
//normally zoom is auto, but for some reason it zooms to 0...
//manual zoom looks like a correct workaround
map.zoomTo(map.getZoomForExtent(bbox));

现在您可能已经注意到:我必须 map.zoomTo手动;因为 map.zoomToExtent 确实设置了正确的中心;但缩放到 0....

关于为什么它第一次不能正确计算缩放的任何想法?

I have an openlayers map with a couple of POI, and I want to zoom so these all fit the map, which I'm doing with the following code:

var bbox = new OpenLayers.Bounds(
    <?php echo $this->box->getSmallestLongitude() ?>,
    <?php echo $this->box->getSmallestLatitude() ?>,
    <?php echo $this->box->getLargestLongitude() ?>,
    <?php echo $this->box->getLargestLatitude() ?>
).transform(map.displayProjection, map.projection);
map.zoomToExtent(bbox);
//normally zoom is auto, but for some reason it zooms to 0...
//manual zoom looks like a correct workaround
map.zoomTo(map.getZoomForExtent(bbox));

Now as you may already have noticed: I have to map.zoomTo manually; since the map.zoomToExtent does set the center correct; but zooms to 0....

Any ideas as to why it won't calculate the zoom correct the first time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文