我是Gmaps编程的初学者。
我想创建一个包含两个标签的InfoWindow,其中一个只有信息,另一个标有一些HTML格式(按钮和文本)。
http://gmaps-samples-v3.googlecode.com/svn/trunk/infowindow/tabs.html
var checkText = "Coordinates";
var content = [
'<div id="tabs">',
'<ul>',
'<li><a href="#tab_1"><span>One</span></a></li>',
'<li><a href="#tab_2"><span>Two</span></a></li>',
'</ul>',
'<div id="tab_1">',
'<p>Marker i:"</p>'+
'<form id='button'>'+
'<div>'+
'<input type='submit' value='Submit' />'+
'</div>'+
'</form>',
'</div>',
'<div id="tab_2">',
'<p>Info: '+checkText+'</p>',
'</div>',
'</div>'
].join('');
然后,事件监听器:
google.maps.event.addListener(infoWindow, 'domready', function() {
$("#tabs").tabs();
});
google.maps.event.addListener(marker, 'click', function(event) {
infoWindow.setContent(content);
infoWindow.open(map, marker);
});
选项卡完美展示,也是按钮,但我不知道如何将其与动作相关联,例如:
marker.draggrable = true; // letting the marker to move
checkText = marker.getPosition(); // changing the tab info whenever marker moves
我猜这个问题与jquery-tabs无关,但内部有一个html-form的infowindow。 感谢。
// -------------------------
我会简化我的问题。
我准备了这个例子,你可以在infowindow中找到一个“按钮”: http://www.sipa.es/prueba_fer/index_prueba.html
如何将操作与该按钮相关联? 例如,更改缩放,打开新窗口等
由于
答案 0 :(得分:0)
标记对象有drag events:
然后在事件触发时更新您的内容
google.maps.event.addListener(marker, 'dragend', function(event) {
checkText = this.getPosition();
content = [
'<div id="tabs">',
'<ul>',
'<li><a href="#tab_1"><span>One</span></a></li>',
'<li><a href="#tab_2"><span>Two</span></a></li>',
'</ul>',
'<div id="tab_1">',
'<p>Marker i:"</p>'+
'<form id="button">'+
'<div>'+
'<input type="submit" value="Submit" />'+
'</div>'+
'</form>',
'</div>',
'<div id="tab_2">',
'<p>Info: '+checkText+'</p>',
'</div>',
'</div>'
].join('');
});
<强>更新强>
好的,你需要确保在连接到DOM时捕获infowindow中的元素。 Infowindows有一个domready
事件。我更新了您的示例中的函数以显示此信息。此外,请记住回发将重置地图。你没有说你是否需要回复帖子,所以我使用e.preventDefault();
(function () {
var marker = new google.maps.Marker({
map: map,
draggable: false,
position: new google.maps.LatLng(40.30, -3.71)
});
var content = "<div id='tabs'>" +
"<form id='button'>" +
"<div>" +
"<input id='btn' type='submit' value='Submit'/>" +
"</div>" +
"</form>" +
"</div>";
google.maps.event.addListener(marker, 'click', function (event) {
infoWindow.setContent(content);
infoWindow.open(map, this);
map.setCenter(this.getPosition());
});
google.maps.event.addListener(infoWindow, 'domready', function (e) {
//attach the click event to the button.
document.forms.button.btn.onclick = function (e) {
e.preventDefault(); //cancels the post back.
var currentZoomLevel = map.getZoom();
map.setZoom(currentZoomLevel - 2); //zoom out two levels
};
});
})();