所以,我正在编写一个代码,当用户点击地图时。它检索坐标值,并尝试将其绑定(显示其值)在 texbox 中。我已经对其进行了测试,坐标和单击事件有效,但我想将其绑定到文本框存在问题。对于如何解决这个问题,有任何的建议吗?
编码:
<script type="text/javascript" src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
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");
$('#latlon').value = lonlat;
}
});
</script>
以及我如何定义文本框:
<input type="text" name="coordinates" id="latlon" value="" Font-Names="Tahoma" Font-Size="10pt" Width="95%" />
错误信息:
Uncaught TypeError: Cannot set property 'value' of null
OpenLayers.Control.Click.OpenLayers.Class.trigger