我有一个定义如下所示的基本地图(伪代码)。
在 map.addLayers 调用之后,有一个我想从 html 文档的主体调用的 displayData(theid) ,问题是我无法调用该方法。如果我将 onclick 事件绑定到 <a> 标记的 id,我可以实现我所追求的,但是将有太多链接无法绑定到每个 <a> 标记
单击下面的超链接之一会导致未定义方法 displayData()。
谢谢阅读!
<script>
Ext.onReady(function() {
map = new OpenLayers.Map();
basemap = new OpenLayers.Layer.WMS(...);
mylines = new OpenLayers.Layer.WMS(...);
selected_items = new OpenLayers.Layer.Vector(...);
map.addLayers([basemap, mylines, selected_items]);
//attach an onclick even for the button on the search results page
function displayData(theid) {
OpenLayers.Request.GET({
url: 'http://1.1.1.1:8080/geoserver/wfs?service=WFS&version=1.0.0&request=GetFeature&featureId='+theid,
proxy: "../gis/geoserver.seam?url=",
success: function(response) {
//if were successful then add the returned features to the map and zoom to the extent
var gmlReader = new OpenLayers.Format.GML({ extractAttributes: true });
selected_items.removeAllFeatures();
selected_items.addFeatures(gmlReader.read(response.responseText));
map.zoomToExtent(selected_items.getDataExtent());
}
});
}
}
</script>
<body>
<div id="map" class="smallmap"></div>
<br/><a href="" onlick="displayData('feature1');">View on map</a>
<br/><a href="" onlick="displayData('feature2');">View on map</a>
<br/><a href="" onlick="displayData('feature3');">View on map</a>
<br/><a href="" onlick="displayData('feature4');">View on map</a>
</body>