OpenLayers ZoomToExtent 无法正确缩放
我有一个带有几个 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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论