在Google Maps API v3中切换平移和标记移动锁定

3
我有一个接口,用户可以管理他们的业务多个位置,添加额外的位置和删除不再需要的位置。
在我的界面中,我显示了一个位置列表,每个位置都有自己的地图。
我的问题是如何锁定地图,防止用户在点击“编辑位置”按钮之前移动地图或移动标记?
是否有任何切换MapLock功能的函数?
到目前为止,我有以下两种方法。lock()方法很好用,但unlock()方法由于某种原因无法使用。
lock: function() {
  this.map.disableDoubleClickZoom = true;
  this.map.draggable = false;
  this.map.keyboardShortcuts = false;
  this.map.navigationControl = false;
  this.map.scaleControl = false;
  this.map.scrollwheel = false;
  this.map.streetViewControl = false;
  this.marker.draggable = false;
},

unlock: function() {
  this.map.disableDoubleClickZoom = false;
  this.map.draggable = true;
  this.map.keyboardShortcuts = true;
  this.map.navigationControl = true;
  this.map.scaleControl = true;
  this.map.scrollwheel = true;
  this.map.streetViewControl = true;
  this.marker.draggable = true;
  console.log("unlock");  
},
1个回答

4

disableDoubleClickZoom(以及其他列出的属性)不是Map类的公共属性,它们是MapOptions类的属性。要更改它们的值,您需要类似以下方式:

lock: function() {
  this.map.setOptions({
    disableDoubleClickZoom: true,
    draggable: false
  });
},

unlock: function() {
  this.map.setOptions({
    disableDoubleClickZoom: false,
    draggable: true
  });
}

这段代码创建了一个MapOptions对象(在{}中),并将其传递给SetOptions函数,该函数根据传入的值更新地图的当前状态。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接