コード例 #1
0
        private void moveCameraToKml(KmlLayer kmlLayer)
        {
            if (mIsRestore)
            {
                return;
            }
            try
            {
                //Retrieve the first container in the KML layer
                KmlContainer container = (KmlContainer)kmlLayer.Containers.Iterator().Next();
                //Retrieve a nested container within the first container
                container = (KmlContainer)container.Containers.Iterator().Next();
                //Retrieve the first placemark in the nested container
                KmlPlacemark placemark = (KmlPlacemark)container.Placemarks.Iterator().Next();
                //Retrieve a polygon object in a placemark
                KmlPolygon polygon = (KmlPolygon)placemark.Geometry;
                //Create LatLngBounds of the outer coordinates of the polygon
                LatLngBounds.Builder builder = new LatLngBounds.Builder();
                foreach (LatLng latLng in polygon.OuterBoundaryCoordinates)
                {
                    builder.Include(latLng);
                }

                int width  = Resources.DisplayMetrics.WidthPixels;
                int height = Resources.DisplayMetrics.HeightPixels;
                getMap().MoveCamera(CameraUpdateFactory.NewLatLngBounds(builder.Build(), width, height, 1));
            }
            catch (Java.Lang.Exception e)
            {
                // may fail depending on the KML being shown
                e.PrintStackTrace();
            }
        }
コード例 #2
0
        private void MoveCameraToKml(KmlLayer kmlLayer)
        {
            //Retrieve the first container in the KML layer
            KmlContainer container = kmlLayer.Containers.ToEnumerable <KmlContainer>().FirstOrDefault();

            //Retrieve a nested container within the first container
            container = container.Containers.ToEnumerable <KmlContainer>().FirstOrDefault();
            //Retrieve the first placemark in the nested container
            KmlPlacemark placemark = container.Placemarks.ToEnumerable <KmlPlacemark>().FirstOrDefault();
            //Retrieve a polygon object in a placemark
            KmlPolygon polygon = (KmlPolygon)placemark.Geometry;

            //Create LatLngBounds of the outer coordinates of the polygon
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            foreach (LatLng latLng in polygon.OuterBoundaryCoordinates)
            {
                builder.Include(latLng);
            }

            int width  = Resources.DisplayMetrics.WidthPixels;
            int height = Resources.DisplayMetrics.HeightPixels;

            googleMap.MoveCamera(CameraUpdateFactory.NewLatLngBounds(builder.Build(), width, height, 1));
        }
コード例 #3
0
        private void AddFeatureToTree(KmlFeature feature, LayerUITreeNode parent)
        {
            feature.Dirty = false;
            string text = feature.Name;

            //if (!string.IsNullOrEmpty(feature.description))
            //{
            //    text += Environment.NewLine + feature.description;
            //}
            bool bold = false;

            if (text.Contains("<b>"))
            {
                bold = true;
                text = text.Replace("<b>", "").Replace("</b>", "");
            }

            LayerUITreeNode node = null;

            if (!(feature is KmlNetworkLink))
            {
                node                = parent.Add(text);
                node.Tag            = feature;
                node.Checked        = feature.visibility;
                node.Opened         = feature.open;
                node.NodeChecked   += new LayerUITreeNodeCheckedDelegate(node_NodeChecked);
                node.NodeUpdated   += new LayerUITreeNodeUpdatedDelegate(node_NodeUpdated);
                node.NodeActivated += new LayerUITreeNodeActivatedDelegate(node_NodeActivated);
                node.NodeSelected  += new LayerUITreeNodeSelectedDelegate(node_NodeSelected);
                if (bold)
                {
                    node.Bold = true;
                }
            }

            if (feature is KmlContainer)
            {
                KmlContainer container = (KmlContainer)feature;
                if (container.children != null)
                {
                    //  if (feature.Style.GetStyle(false).ListStyle.ListItemType != KmlListItemTypes.CheckHideChildren)
                    {
                        foreach (KmlFeature child in container.children)
                        {
                            AddFeatureToTree(child, node);
                        }
                    }
                }
            }
            else
            {
                if (feature is KmlNetworkLink)
                {
                    KmlNetworkLink netLink = (KmlNetworkLink)feature;
                    if (netLink.LinkRoot != null)
                    {
                        AddRootToTree(netLink.LinkRoot, parent);
                    }
                }
            }
        }
コード例 #4
0
        private void AddFeatureToDisplay(KmlFeature feature, bool sky)
        {
            KmlDocument doc = feature as KmlDocument;

            if (doc != null)
            {
                sky = doc.sky;
            }
            if (!(feature is KmlNetworkLink))
            {
                if (feature.visibility == false)
                {
                    return;
                }
                else if (feature is KmlPlacemark)
                {
                    KmlPlacemark placemark = (KmlPlacemark)feature;
                    KmlStyle     style     = placemark.Style.GetStyle(placemark.Selected);
                    Color        lineColor = Color.White;
                    if (style != null)
                    {
                        lineColor = style.LineStyle.Color;
                    }
                    if (placemark.geometry is KmlPoint)
                    {
                        placemark.Point = (KmlPoint)placemark.geometry;
                        AddPlacemark(placemark);
                    }
                    else if (placemark.geometry is KmlMultiGeometry)
                    {
                        KmlMultiGeometry geo = (KmlMultiGeometry)placemark.geometry;
                        AddMultiGeometry(sky, placemark, (float)style.LineStyle.Width, style.PolyStyle.Color, lineColor, geo);
                    }
                    else if (placemark.geometry is KmlPolygon)
                    {
                        KmlPolygon geo = (KmlPolygon)placemark.geometry;
                        if (geo.OuterBoundary != null)
                        {
                            AddLines(sky, geo.OuterBoundary as KmlLineList, (float)style.LineStyle.Width, style.PolyStyle.Color, lineColor, geo.extrude);
                            // to do 3d work and subtract inner rings
                        }
                    }
                    else if (placemark.geometry is KmlLineString)
                    {
                        KmlLineString geo = (KmlLineString)placemark.geometry;

                        List <Vector3d> vertexList = new List <Vector3d>();
                        for (int i = 0; i < (geo.PointList.Count); i++)
                        {
                            vertexList.Add(Coordinates.GeoTo3dDouble(geo.PointList[i].Lat, geo.PointList[i].Lng, 1 + (geo.PointList[i].Alt / geo.MeanRadius)));
                        }
                        for (int i = 0; i < (geo.PointList.Count - 1); i++)
                        {
                            if (sky)
                            {
                                lines.AddLine(Coordinates.RADecTo3d(-(180.0 - geo.PointList[i].Lng) / 15 + 12, geo.PointList[i].Lat, 1), Coordinates.RADecTo3d(-(180.0 - geo.PointList[i + 1].Lng) / 15 + 12, geo.PointList[i + 1].Lat, 1), lineColor, new Dates());
                            }
                            else
                            {
                                lines.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates());
                            }
                        }
                    }
                }
                if (feature is KmlGroundOverlay && feature.visibility)
                {
                    AddGroundOverlay(feature as KmlGroundOverlay);
                }

                if (feature is KmlScreenOverlay && feature.visibility)
                {
                    AddScreenOverlay(feature as KmlScreenOverlay);
                }
            }
            if (feature.visibility)
            {
                if (feature is KmlContainer)
                {
                    KmlContainer container = (KmlContainer)feature;
                    if (container.children != null)
                    {
                        foreach (KmlFeature child in container.children)
                        {
                            AddFeatureToDisplay(child, sky);
                        }
                    }
                }
                else
                {
                    if (feature is KmlNetworkLink)
                    {
                        KmlNetworkLink netLink = (KmlNetworkLink)feature;
                        if (netLink.LinkRoot != null)
                        {
                            foreach (KmlFeature child in netLink.LinkRoot.children)
                            {
                                AddFeatureToDisplay(child, sky);
                            }
                        }
                    }
                }
            }
        }