using System;
using System.Web.UI;

namespace ExWeb
{
    public partial class Mod_Maps : Mod
    {
        public static string Help_Description =
            "Anzeige einer Landkarte"
            + "\r\n"
            + "Höchste Zoomstufen nicht immer verfügbar";

        public static string[][] Help_Attributes = new string[][]
        {
            // Attribut, Wert, DefaultWert, Optional, Hilfe
            new string[] {"Address", "string", "Siccardsburggasse 4, 1100 Wien, Österreich","opt","Adresse","Address=\"Olympiastadion,Berlin, Deutschland\""},
            // new string[] {"ShowLabel", "0 1", "1","opt","Zeigt Adresse mit Marker","ShowLabel=\"0\""},
            new string[] {"Zoom", "1..20", "14","opt","Zoom-Level","Zoom=\"16\""},
        };
        protected string _Address = "Siccardsburggasse 4, 1100 Wien, Österreich";
        public string Address
        {
            set
            {
                if (value != "") _Address = value;
            }
        }
        protected bool _ShowLabel = true;
        public string ShowLabel
        {
            set
            {
                _ShowLabel = (value == "1" ? true : false);
            }
        }
        protected int _Zoom = 14;
        public string Zoom
        {
            set
            {
                int.TryParse(value, out _Zoom);
            }
        }
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            SetPanelLayout(this.Controls);
        }
        protected new void Page_Load(object sender, EventArgs e)
        {
            Page.LoadComplete += new EventHandler(Page_LoadComplete);
            int dWidth = (_Cap=="" ? 0 : 30);
            int dHeight = (_Cap == "" ? 50 : 70);
            string Link =
                "https://maps.google.com/maps?f=q&source=s_q&hl=de&geocode="
                + "&q=" + Server.UrlEncode(_Address)
                + "&aq=&ie=UTF8&hq="
                + "&hnear=" + Server.UrlEncode(_Address) // (_ShowLabel ? : "")
                + "&t=m"
                + "&z=" + _Zoom
                + "&iwloc=A";
            string Code = 
                "<iframe "
                + " width=\"" + (_Width - dWidth) + "\""
                + " height=\"" + (_Height - dHeight) + "\"" 
                + " frameborder=\"0\""
                + " scrolling=\"no\""
                + " marginheight=\"0\""
                + " marginwidth=\"0\""
                + " src=\""+Link+ "&output=embed\">"
                + "</iframe>"
                + "<br />"
                + "<small>"
                + "<a href=\"" + Link +"\"" 
                + " style=\"color:#0000FF;text-align:left\">Größere Kartenansicht</a></small>";
            Panel_Module.Controls.Add(new LiteralControl(Code));
        }
    }
}