A Style defines an addressable style group that can be referenced by StyleMaps and Features. Styles affect how Geometry is presented in the 3D viewer and how Features appear in the Places panel of the List view. Shared styles are collected in a and must have an id defined for them so that they can be referenced by the individual Features that use them.
Inheritance: geStyleSelector
Ejemplo n.º 1
0
        public static geKML RunExample(string FileName)
        {
            // Use a Document as the root of the KML
            geDocument doc = new geDocument();
            doc.Name = "My Root Document";

            // Create a new style to be added the doc
            geStyle myStyle = new geStyle("myStyle");

            //add a new IconStyle to the style
            myStyle.IconStyle = new geIconStyle();
            myStyle.IconStyle.Icon = new geIcon("Example2.png");
            myStyle.IconStyle.Scale = 2F; //or (float)2

            //Add the style
            doc.StyleSelectors.Add(myStyle);

            //Create a Placemark to put in the document
            //This placemark is going to be a point
            //but it could be anything in the Geometry class
            gePlacemark pm = new gePlacemark();

            //Create some coordinates for the point at which
            //this placemark will sit. (Lat / Lon)
            geCoordinates coords = new geCoordinates(
                new geAngle90(37.422067),
            new geAngle180(-122.084437));

            //Create a point with these new coordinates
            gePoint point = new gePoint(coords);

            //Assign the point to the Geometry property of the
            //placemark.
            pm.Geometry = point;

            //Set the placemark's style to the style we created above
            pm.StyleUrl = "#myStyle";

            //Now lets add some other properties to our placemark
            pm.Name = "My Placemark";
            pm.Snippet = "This is where I put my Placemark";
            pm.Description =
                "I wonder where this is...GOOGLE!";

            //Finally, add the placemark to the document
            doc.Features.Add(pm);

            //Now that we have our document, lets create our KML
            geKML kml = new geKML(doc);

            //Add supporting files to the KMZ (assuming it's going to be rendered as KMZ
            byte[] myFile = File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "\\images\\Example2.png");
            kml.Files.Add("Example2.png", myFile);

            return kml;
        }
Ejemplo n.º 2
0
        public static geKML RunExample(string FileName)
        {
            // Use a Document as the root of the KML
            geDocument doc = new geDocument();
            doc.Name = "My Root Document";

            gePlacemark pm = new gePlacemark();

            //Always complete the boundary by adding an end point that matches your beginning point

            List<geCoordinates> outerCoords = new List<geCoordinates>();
            outerCoords.Add(new geCoordinates(new geAngle90(37), new geAngle180(-114)));
            outerCoords.Add(new geCoordinates(new geAngle90(37), new geAngle180(-108)));
            outerCoords.Add(new geCoordinates(new geAngle90(31), new geAngle180(-108)));
            outerCoords.Add(new geCoordinates(new geAngle90(31), new geAngle180(-114)));
            outerCoords.Add(new geCoordinates(new geAngle90(37), new geAngle180(-114)));

            List<geCoordinates> innerCoords1 = new List<geCoordinates>();
            innerCoords1.Add(new geCoordinates(new geAngle90(36), new geAngle180(-113)));
            innerCoords1.Add(new geCoordinates(new geAngle90(36), new geAngle180(-112)));
            innerCoords1.Add(new geCoordinates(new geAngle90(35), new geAngle180(-112)));
            innerCoords1.Add(new geCoordinates(new geAngle90(35), new geAngle180(-113)));
            innerCoords1.Add(new geCoordinates(new geAngle90(36), new geAngle180(-113)));

            List<geCoordinates> innerCoords2 = new List<geCoordinates>();
            innerCoords2.Add(new geCoordinates(new geAngle90(34), new geAngle180(-113)));
            innerCoords2.Add(new geCoordinates(new geAngle90(34), new geAngle180(-112)));
            innerCoords2.Add(new geCoordinates(new geAngle90(33), new geAngle180(-112)));
            innerCoords2.Add(new geCoordinates(new geAngle90(33), new geAngle180(-113)));
            innerCoords2.Add(new geCoordinates(new geAngle90(34), new geAngle180(-113)));

            geOuterBoundaryIs outer = new geOuterBoundaryIs(new geLinearRing(outerCoords));

            gePolygon poly = new gePolygon(outer);

            geInnerBoundaryIs inner1 = new geInnerBoundaryIs(new geLinearRing(innerCoords1));
            geInnerBoundaryIs inner2 = new geInnerBoundaryIs(new geLinearRing(innerCoords2));
            poly.InnerBoundaries.Add(inner1);
            poly.InnerBoundaries.Add(inner2);

            pm.Geometry = poly;

            doc.Features.Add(pm);

            //Lets add a Line somewhere too...
            geStyle myLineStyle = new geStyle("myLineStyle");
            myLineStyle.LineStyle = new geLineStyle();
            myLineStyle.LineStyle.Color.SysColor = Color.Yellow;
            myLineStyle.LineStyle.Width = 4;  //This may or may not work, depends on the end user's video card

            doc.StyleSelectors.Add(myLineStyle);

            gePlacemark pmLine = new gePlacemark();
            pmLine.StyleUrl = "#myLineStyle";
            pmLine.Name = "Example Line";
            pmLine.Description = "Some description";

            List<geCoordinates> lineCoords = new List<geCoordinates>();
            lineCoords.Add(new geCoordinates(new geAngle90(35),new geAngle180(-117)));
            lineCoords.Add(new geCoordinates(new geAngle90(35),new geAngle180(-106)));

            geLineString line = new geLineString(lineCoords);

            pmLine.Geometry = line;

            doc.Features.Add(pmLine);

            //Now that we have our document, lets create our KML
            geKML kml = new geKML(doc);

            return kml;
        }
Ejemplo n.º 3
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            //creates kml file if selected.
            String path = txtFileName.Text;

            if ((path != null) &&(path != "" ))
            if (Directory.Exists(Path.GetDirectoryName(path)))
                //diretorul exista. Si acum fisierul are extensie kml?
                if (Path.GetFileName(path).EndsWith(".kml"))
                       //si e fisier kml. BUn...
                {
                    KMLGenerator generator = new KMLGenerator(layers);
                    //create style in generator
                    #region Create kml style

                    geStyle style = new geStyle("Shape2KMLGeneratedStyle");
                    //style.ID = "Shape2KMLGeneratedStyle";

                    //should use booleans for these, but for now checking the controls is ok...

                    if (grpIcon.Visible)
                    {
                        //icon style
                        style.IconStyle = new geIconStyle();
                        style.IconStyle.Color.SysColor = pbIcon.BackColor;
                        //style.IconStyle.ColorMode =
                        style.IconStyle.Icon = new geIcon(pbSelectedIcon.ImageLocation);
                    }

                    if (grpLine.Visible)
                    {
                        //line style, if we have lines
                        style.LineStyle = new geLineStyle();
                        style.LineStyle.Color.SysColor = pbLine.BackColor;
                        style.LineStyle.Width = (float)numLineWidth.Value;
                    }

                    //polygon style, only if we have polygons
                    if (grpPoly.Visible)
                    {
                        style.PolyStyle = new gePolyStyle();
                        style.PolyStyle.Color.SysColor = pbFill.BackColor;

                    }

                    generator.DefaultStyle = style;
                    #endregion

                    pnlMain.Visible = false;
                    pnlProgress.Visible = true;
                    //IMxDocument activeDoc = m_application.Document as IMxDocument;
                    //MessageBox.Show (activeDoc.ToString);

                    //get active document name
                    String docPath = GetActiveDocumentPath(m_application);
                    generator.KmlDocument.Name = Path.GetFileName(docPath);
                    generator.KmlDocument.Description = docPath;
                    generator.Generate(path,pbarDone);

                    MessageBox.Show("Creat document "+ path);
                    pnlMain.Visible = true;
                    pnlProgress.Visible = false;

                }
               // MessageBox.Show("not ok");
        }
        public geFeature GetExportKML(IList<Graphic> Graphics,
            string featureName,
            string featureId,
            List<Symbol> usedSymbols)
        {
            geDocument dt;
              geStyle st;
              Random random;
              Color color;

              mFeatureName = featureName;
              mFeatureId = featureId;
              mObjects = Graphics;
              mUsedSymbols = usedSymbols;

              dt = new geDocument();

              dt.Name = mFeatureName;

              if(mObjects.Count > 0)
              {
            mStyleName = mFeatureId + "styleid";
            mSchemaName = mFeatureId + "schemaid";

            foreach(Graphic graphic in mObjects)
            {
              dt.Schemas.Add(CreateKMLPlacemarkSchema(graphic));

            }
            dt.Features.AddRange(CreateKMLPlacemarks());
              }

              mUsedSymbols = usedSymbols;

              dt.StyleSelectors = new List<geStyleSelector>();

              dt.StyleSelectors.AddRange(CreateKMLStyles());

              st = new geStyle(mStyleName);

              random = new Random();
              color = Color.FromArgb(255, (byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255));

              st.PolyStyle = new gePolyStyle();

              st.PolyStyle.Color.SysColor = color;
              st.PolyStyle.Fill = true;
              st.LineStyle = new geLineStyle();
              st.LineStyle.Color.SysColor = color;

              dt.StyleSelectors.Add(st);

              return dt;
        }
        private static geStyle ConvertToPolyStyle(FillSymbol fillSym)
        {
            gePolyStyle polyStyle;
              geLineStyle border;
              geStyle style;
              string hashId;

              hashId = fillSym.GetHashCode().ToString();
              style = new geStyle(hashId);

              polyStyle = new gePolyStyle();
              geColor color = new geColor();
              color.SysColor = ((SolidColorBrush)fillSym.Fill).Color;
              polyStyle.Color = color;

              border = new geLineStyle();
              geColor borderColor = new geColor();
              borderColor.SysColor = ((SolidColorBrush)fillSym.BorderBrush).Color;
              border.Color = borderColor;

              style.LineStyle = border;
              style.PolyStyle = polyStyle;
              return style;
        }
        private static geStyle ConvertToPointStyle(MarkerSymbol pointSym)
        {
            geIconStyle iconStyle;
              geStyle style;
              string hashId;
              string href;

              hashId = pointSym.GetHashCode().ToString();
              href = string.Format("files/{0}.png", hashId);

              style = new geStyle(hashId);

              iconStyle = new geIconStyle();
              iconStyle.Icon = new geIcon(href);
              iconStyle.Scale = 0.8F;
              iconStyle.HotSpot = new geVec2();
              iconStyle.HotSpot.xunits = geUnitsEnum.insetPixels;
              iconStyle.HotSpot.yunits = geUnitsEnum.insetPixels;
              iconStyle.HotSpot.x = pointSym.OffsetX;
              iconStyle.HotSpot.y = pointSym.OffsetY;

              style.IconStyle = iconStyle;

              return style;
        }
        private static geStyle ConvertToLineStyle(LineSymbol lineSym)
        {
            geLineStyle lineStyle;
              geStyle style;
              string hashId;

              hashId = lineSym.GetHashCode().ToString();
              style = new geStyle(hashId);

              lineStyle = new geLineStyle();
              geColor color = new geColor();
              color.SysColor = ((SolidColorBrush)lineSym.Color).Color;
              lineStyle.Color = color;
              lineStyle.Width = (float)lineSym.Width;

              style.LineStyle = lineStyle;

              return style;
        }
        // This method is to be called once all the targets
        // are loaded via AddNewTarget. Once KML is created the list
        // will be emptied.
        public void BuildKML()
        {
            string exampleFileName = "";
            string exampleFileExt = "kmz";
            string file_name = "ASTX_TO_KML";

            // Use a Document as the root of the KML
            geDocument doc = new geDocument();
            doc.Name = "Asterix to KML";

            // Create a new style to be added the doc
            geStyle myStyle = new geStyle("myStyle");

            //add a new IconStyle to the style
            myStyle.IconStyle = new geIconStyle();
            myStyle.IconStyle.Icon = new geIcon("ac_image.png");
            myStyle.IconStyle.Scale = 1.0F; //or (float)1

            myStyle.LabelStyle = new geLabelStyle();
            myStyle.LabelStyle.Color.SysColor = Color.White;

            myStyle.LineStyle = new geLineStyle();
            myStyle.LineStyle.Color.SysColor = Color.Black;
            myStyle.LineStyle.Width = 4;

            //Add the style
            doc.StyleSelectors.Add(myStyle);

            foreach (DynamicDisplayBuilder.TargetType Target in TargetList)
            {
                //Create a Placemark to put in the document
                //This placemark is going to be a point
                //but it could be anything in the Geometry class
                gePlacemark pm = new gePlacemark();

                //Create some coordinates for the point at which
                //this placemark will sit. (Lat / Lon)
                geCoordinates coords = new geCoordinates(
                    new geAngle90(Target.Lat),
                new geAngle180(Target.Lon));

                double LevelInMeeters = 0.0;

                // Assign the altitude
                if (Target.ModeC != null)
                {
                    if (Target.ModeC != "---")
                        LevelInMeeters = (double.Parse(Target.ModeC) * 100.00) * SharedData.FeetToMeeters;
                }

                coords.Altitude = (float)LevelInMeeters;

                //Create a point with these new coordinates
                gePoint point = new gePoint(coords);
                point.AltitudeMode = geAltitudeModeEnum.absolute;
                point.Extrude = true;

                //Assign the point to the Geometry property of the
                //placemark.
                pm.Geometry = point;

                //Set the placemark's style to the style we created above
                pm.StyleUrl = "#myStyle";

                if (Properties.Settings.Default.GE_Show_ModeA)
                    pm.Name = Target.ModeA;

                if (Properties.Settings.Default.GE_Show_ModeC)
                {
                    if (Properties.Settings.Default.Show_ModeC_as_FL)
                        pm.Name = pm.Name + "  " + "FL:" + Target.ModeC;
                    else
                        pm.Name = pm.Name + "  " + LevelInMeeters.ToString() + "m";
                }

                if (Properties.Settings.Default.GE_Show_ModeC)
                {
                    pm.Name = pm.Name + " " + Target.ACID_Mode_S;
                }

                pm.Snippet = "Snipet Test";
                pm.Description = "Blaa Bla Blaaaa";

                //Finally, add the placemark to the document
                doc.Features.Add(pm);
            }

            geKML kml = new geKML(doc);

            //Add supporting files to the KMZ (assuming it's going to be rendered as KMZ
            byte[] myFile = File.ReadAllBytes(@"C:\ASTERIX\GE\ac_image.png");
            kml.Files.Add("ac_image.png", myFile);

            exampleFileName = Properties.Settings.Default.GE_Dest_Path + "\\" + file_name + "." + exampleFileExt;
            File.WriteAllBytes(exampleFileName, kml.ToKMZ());

            // Clear the list
            TargetList.Clear();
        }