コード例 #1
0
ファイル: FrmMain.cs プロジェクト: epiclm/geotomap
        /// <summary>
        /// Genera el mapa de eventos sobre google maps para ver en un navegador web
        /// </summary>
        private void generaGoogleMaps()
        {
            try
            {
                if (items.Count == 0)
                {
                    MessageBox.Show(Resources.No_Existen_Registros, Resources.Error, MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                    return;
                }

                if (!String.IsNullOrEmpty(txtCarpetaSalida.Text))
                {
                    if ((Directory.Exists(txtCarpetaSalida.Text)))
                    {
                        var htmlsb = new StringBuilder();

                        LatLon centroLatLong = LatLongCentro();

                        htmlsb.Append(
                            "<!DOCTYPE html>\n<html>\n<head>\n<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\">\n<meta charset=\"utf-8\">\n<title>Simple markers</title>\n<link href=\"/maps/documentation/javascript/examples/default.css\" rel=\"stylesheet\">\n<script src=\"https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false\">\n</script>\n");

                        htmlsb.AppendLine(
                            "<style>\n\t.todo {    border: 2px solid silver;    bottom: 0;    left: 0;    overflow: auto;    position: absolute;    right: 0;    top: 0;}</style>");

                        htmlsb.AppendLine("<script>\nfunction initialize() {");
                        htmlsb.AppendFormat("var myLatlng = new google.maps.LatLng({0},{1});\n",
                                            centroLatLong.Lat.ToString(CultureInfo.InvariantCulture),
                                            centroLatLong.Lon.ToString(CultureInfo.InvariantCulture));
                        htmlsb.AppendLine(
                            "var mapOptions = { zoom:8, center:myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP }");
                        htmlsb.AppendLine(
                            "var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);");

                        int i = 0;

                        foreach (var dp in items)
                        {
                            i++;
                            htmlsb.AppendFormat("var marca{0} = new google.maps.LatLng({1},{2});\n",
                                                i.ToString(CultureInfo.InvariantCulture),
                                                dp.Value.Latitud.ToString(CultureInfo.InvariantCulture),
                                                dp.Value.Longitud.ToString(CultureInfo.InvariantCulture));
                            htmlsb.AppendLine("var marker = new google.maps.Marker({      position: marca" +
                                              i.ToString(CultureInfo.InvariantCulture) +
                                              ",      map: map,      title: '" + dp.Value.Direccion + "'  });\n");
                        }

                        htmlsb.AppendLine("}\ngoogle.maps.event.addDomListener(window, 'load', initialize);");
                        htmlsb.AppendLine("</script>");
                        htmlsb.AppendLine(
                            "</head>\n\t\t<body>\n\t\t\t<div id=\"map-canvas\" class=\"todo\"></div>\n\t\t</body>\n</html>");

                        //richTextBox1.AppendText(htmlsb.ToString());

                        var file =
                            new StreamWriter(txtCarpetaSalida.Text + "\\" + "googlemaps.html");
                        file.Write(htmlsb.ToString());
                        file.Close();

                        Process.Start(txtCarpetaSalida.Text + "\\" + "googlemaps.html");
                    }
                    else
                    {
                        MessageBox.Show(Resources.El_directorio_no_existe, Resources.Error, MessageBoxButtons.OK,
                                        MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    MessageBox.Show(
                        Resources.FrmBuscaDireccion_btnGoogleMaps_Click_Tiene_que_seleccionar_una_carpeta_de_salida,
                        Resources.Error, MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
            }
        }