function onLoad() {
map = new GMap2(document.getElementById("div_map"),
{ size: new GSize(640,580) } );
map.addControl(new GLargeMapControl3D());
//map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(13.7, 100.6), 11);
getMarkers();
GEvent.addListener(map, "click", function(overlay, point) {
if (overlay){ // การคลิ๊ก หรือ Mark Click
overlay.openInfoWindowHtml(overlay.infowindow); // open InfoWindow
} else if (point) { // พื้นหลัง
}
});
}
function getMarkers(){
var urlstr="read.php";
var request = GXmlHttp.create();
request.open('GET', urlstr , true); // request XML from PHP with AJAX call
request.onreadystatechange = function () {
if (request.readyState == 4) {
var xmlDoc = request.responseXML;
locations = xmlDoc.documentElement.getElementsByTagName("location");
markers = [];
if (locations.length){
var image = 'beachflag.png';
for (var i = 0; i < locations.length; i++) { // cycle thru locations
markers[i] = new GMarker(new GLatLng(locations[i].getAttribute("lat"),locations[i].getAttribute("long")));
// Add attributes to the marker so we can poll them later.
// When clicked, an overlay will have these properties.
markers[i].infowindow = "This is "+locations[i].getAttribute("name")+" "+locations[i].getAttribute("address");
// Useful things to store on a marker (Not needed for this example, could be removed)
// Tells you what index in the markers[] array an overlay is
markers[i].markerindex = i;
// Store the location_id of the location the marker represents.
// Very useful to know the true id of a marker, you could then make
// AJAX calls to the database to update the information if you had it's location_id
markers[i].db_id = locations[i].getAttribute("location_id");