使用openlayers,我如何确保显示两个图层中的标记

时间:2010-11-15 15:34:43

标签: javascript mapping openlayers

我在两个标记层中有标记,我需要将它们分开,所以我可以在应用程序中清除其中一个。

确保显示所有标记的最佳方法是什么。使用zoomToExtent可以轻松地为一个图层执行此操作。但是怎么做多于一层?

2 个答案:

答案 0 :(得分:3)

从第1层获取边界,使用.extend(第2层边界),然后在扩展边界上使用zoomToExtent。

http://dev.openlayers.org/releases/OpenLayers-2.10/doc/apidocs/files/OpenLayers/BaseTypes/Bounds-js.html#OpenLayers.Bounds.extend

是边界上的extend方法。

粗略,快速,对不起....

答案 1 :(得分:0)

使用新的bounds对象并使用Bounds.extend。

var myNewBounds = Layer1.zoomToExtent.getExtent();
myNewBounds.extend(Layer2.zoomToExtent.getExtent());

使用新的bounds变量设置地图上的边界。语法错误,但这是你想要的方向。