当我向北移动时,地图就出来了,我看到了我的HTML的白色背景。我想垂直平移地图,当地图到达顶部(或底部)时,将其分块。
我试过设置边界,但是这个解决方案也是水平地设置边界。我希望能够无限向左或向右平移,但限制上下平移。
我怎么能这样做呢?
谢谢
编辑1:我不喜欢扩展OpenLayers核心。我想要的解决方案涵盖所有的平移,拖动,缩放的情况。我想,一个通用的解决方案就可以了。我听说在地图初始化中有一个选项,它只限制垂直的范围。你对它有什么了解吗?

发布于 2014-08-06 19:24:40
我通过覆盖OpenLayers.Control.PanZoom的buttonDown函数实现了这一点,该函数如下所示:
buttonDown: function (evt) {
if (!OpenLayers.Event.isLeftClick(evt)) {
return;
}
switch (this.action) {
case "panup":
this.map.pan(0, -this.getSlideFactor("h"));
break;
switch (this.action) {
case "pandown":
this.map.pan(0, this.getSlideFactor("h"));
break;
... etc所以你可以这样做,而不是这样:
OpenLayes.Control.PanZoom.prototype.buttonDown = function (evt){
if (!OpenLayers.Event.isLeftClick(evt)) {
return;
}
//get map bounds
var mapBounds=map.getExtent();
switch (this.action) {
case "panup":
//add you code here to check extents
if (mapBounds.top < some_number){
this.map.pan(0, -this.getSlideFactor("h"));
break;
}
switch (this.action) {
case "pandown":
//add you code here to check extents
if (mapBounds.bottom > some_number){
this.map.pan(0, this.getSlideFactor("h"));
break;
}
//leave this as it was, as you don't care about left/right
case "panleft":
this.map.pan(-this.getSlideFactor("w"), 0);
break;
....请注意,您必须像以前一样填写函数的其余部分,因为您正在覆盖它。您希望确保在OpenLayers.js加载之后添加此函数。
https://stackoverflow.com/questions/25150022
复制相似问题