我试图让 OpenLayers 的功能只有在用户打开它的情况下才能工作。我制作了调用函数的 html 按钮,将布尔变量clickSearch
变为 true 或 false。如何使该功能仅适用于clicksearch = true
?它是某种 if 语句吗?
这是运行我要打开和关闭的功能的代码:
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, {
'click': this.trigger
}, this.handlerOptions
);
},
trigger: function(e) {
var lonlat = map.getLonLatFromPixel(e.xy);
alert("You clicked near " + lonlat.lat + " N, " +
+ lonlat.lon + " E");
}
});
clickSearch
这些函数打开和关闭布尔值
var clickSearch= false;
function turnOn(){ clickSearch=true};
function turnOff(){ clickSearch=false};
这些按钮调用函数来打开clickSearch
/关闭:
<button onclick="turnOn()">Turn on click-to-search</button>
<button onclick="turnOff()">Turn off click-to-search</button>