function addDoctorLocation(lat,longt)
{
var myLatlng = new google.maps.LatLng(parseFloat(lat), parseFloat(longt));
var myOptions = {
zoom: 10,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
//var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: myLatlng,
title:"Hello World!"
});
// To add the marker to the map, call setMap();
var map = Ext.getCmp('mygooglemap');
marker.setMap(map);
}
var btn= Ext.getCmp('button');
btn.on('onclick', function(){
addDoctorLocation(3.951941,102.052002);
})
mygooglemap 是一个 GMappanel
如何单击按钮,然后 gmappanel 将添加一个带有坐标的标记3.951941,102.052002
?我已经尝试过这段代码,但仍然无法工作?
更新
在复选框上怎么样?
tree.on('checkchange', function(node){
var data = node.data;
if (data.checked = true){
var options = {
lat:3.951941,
lng:-102.052002,
marker: {title:"Hello World!"},
listeners: {
click: function(e){
}
}
}
addDoctorLocation(options);
}
})
地图创作
var layout = Ext.create('Ext.panel.Panel', {
//renderTo: 'layout',
width: window.innerWidth,
height: window.innerHeight,
//title: 'Border Layout', //no title will be blank
layout: 'border',
items: [{
title: 'Message List',
region: 'south', // position for region
xtype: 'panel',
height: 100,
split: true, // enable resizing
collapsible: true,
margins: '0 5 5 5',
collapsed: true
},tree,{
xtype: 'gmappanel',
id : 'mygooglemap',
gmapType: 'map',
zoomLevel: 7,
mapConfOpts: ['enableScrollWheelZoom','enableDoubleClickZoom','enableDragging'],
mapControls: ['GSmallMapControl','GMapTypeControl','NonExistantControl'],
setCenter: {
lat: 3.951941,
lng: 102.052002,
}
}],
renderTo: Ext.getBody() //get the body and display Layout at there
});
});
在我检查了 fireBug 之后,错误是:
ReferenceError: GLatLng is not defined
[Break On This Error]
var mpoint = new GLatLng(options.lat,options.lng);
我已经编辑了如下代码,工作正常
function addDoctorLocation(options)
{
var gm = Ext.getCmp('mygooglemap');
var mpoint = new google.maps.LatLng(options.lat,options.lng);
gm.addMarker(mpoint,options.marker,false,false, options.listeners);
}