﻿function initGMap(element, lat, lng, zoom, msid, address, width, height) 
{
    if (GBrowserIsCompatible()) 
    {
        var map;
        if (width > 0 && height > 0)
            map = new GMap2(element, { size: new GSize(width, height) });
        else
            map = new GMap2(element);
        map.setCenter(new GLatLng(lat, lng), zoom);
        map.setUIToDefault();

        var baseIcon = new GIcon(G_DEFAULT_ICON);
        baseIcon.shadow = "https://egyutt.hu/images/map_shadow.png";
        baseIcon.iconSize = new GSize(40, 35);
        baseIcon.shadowSize = new GSize(62, 35);
        baseIcon.iconAnchor = new GPoint(20, 34);
        baseIcon.infoWindowAnchor = new GPoint(13, 48);

        function createMarker(point, address) 
        {
            var marker = new GIcon(baseIcon);
            marker.image = "https://egyutt.hu/images/map_marker.png";
            markerOptions = {
                icon: marker
            };
            var marker = new GMarker(point, markerOptions);
            GEvent.addListener(marker, "click", function() {
                marker.openInfoWindowHtml(address);
              });
            return marker;
        }

        if (msid != null && msid != "") {
            var xml = executeSyncronRequest("/Ajax/GetCoordinates?msid=" + msid);
            var points = xml.getElementsByTagName("point");
            for (var i = 0; i < points.length; i++) {
                var latitude = parseFloat(points.item(i).getElementsByTagName(
						"latitude").item(0).firstChild.nodeValue);
                var longitude = parseFloat(points.item(i).getElementsByTagName(
						"longitude").item(0).firstChild.nodeValue);
                var address = points.item(i).getElementsByTagName("address")
						.item(0).firstChild.nodeValue;
                var point = new GLatLng(latitude, longitude);
                map.addOverlay(createMarker(point, address));
            }
        }
        else 
        {
            var point = new GLatLng(lat, lng);
            map.addOverlay(createMarker(point, address));
        }
    }
}


