Пример #1
0
        /// <summary>
        /// Toggles any 'media player' associated with a particular Kml type represented by a tree node.
        /// So far this includes KmlTours (GETourPlayer) and KmlPhotoOverlays (GEPhotoOverlayViewer)
        /// </summary>
        /// <param name="ge">The plug-in instance</param>
        /// <param name="feature">The feature to check</param>
        /// <param name="visible">Value indicating whether the player should be visible or not.</param>
        public static void ToggleMediaPlayer(dynamic ge, dynamic feature, bool visible = true)
        {
            if (!IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            ApiType type = GEHelpers.GetApiType(feature);

            if (visible)
            {
                if (type == ApiType.KmlTour)
                {
                    ge.setBalloon(null);
                    ge.getTourPlayer().setTour(feature);
                }
                else if (type == ApiType.KmlPhotoOverlay)
                {
                    ge.getPhotoOverlayViewer().setPhotoOverlay(feature);
                }
            }
            else
            {
                if (type == ApiType.KmlTour)
                {
                    ge.getTourPlayer().setTour(null);
                }
                else if (type == ApiType.KmlPhotoOverlay)
                {
                    ge.getPhotoOverlayViewer().setPhotoOverlay(null);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Called after a tree node has collapsed
        /// </summary>
        /// <param name="sender">The TreeView</param>
        /// <param name="e">Event Arugments</param>
        private void KmlTreeView_AfterCollapse(object sender, TreeViewEventArgs e)
        {
            try
            {
                dynamic feature = e.Node.Tag;
                if (feature != null)
                {
                    string type = GEHelpers.GetTypeFromRcw(feature);

                    switch (type)
                    {
                    case "KmlDocument":
                    case "KmlFolder":
                        e.Node.ImageKey = "folderClosed";
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (InvalidCastException icex)
            {
                Debug.WriteLine(icex.ToString(), "KmlTreeView");
                ////throw;
            }
        }
        /// <summary>
        /// Creates a KML point
        /// </summary>
        /// <param name="ge">The plug-in instance</param>
        /// <param name="id">Optional placemark Id. Default is empty</param>
        /// <param name="latitude">The placemark latitude in decimal degrees</param>
        /// <param name="longitude">The placemark longitude in decimal degrees</param>
        /// <param name="altitude">Optional placemark altitude in metres. Default is 0</param>
        /// <param name="altitudeMode">Optional altitudeMode. Default is AltitudeMode.RelativeToGround</param>
        /// <returns>A Kml point (or null)</returns>
        public static dynamic CreatePoint(
            dynamic ge,
            string id                 = "",
            double latitude           = 0,
            double longitude          = 0,
            double altitude           = 0,
            AltitudeMode altitudeMode = AltitudeMode.RelativeToGround)
        {
            if (!GEHelpers.IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            dynamic point = null;

            try
            {
                point = ge.createPoint(id);
                point.setLatitude(latitude);
                point.setLongitude(longitude);
                point.setAltitude(altitude);
                point.setAltitudeMode(altitudeMode);
            }
            catch (RuntimeBinderException rbex)
            {
                Debug.WriteLine("CreatePoint: " + rbex.Message, "KmlHelpers");
            }

            return(point);
        }
 /// <summary>
 /// Called when the view in maps button is clicked
 /// </summary>
 /// <param name="sender">The object that raised the event.</param>
 /// <param name="e">Event arguments.</param>
 private void ViewInMapsButton_Click(object sender, EventArgs e)
 {
     if (this.browser.PluginIsReady)
     {
         GEHelpers.ShowCurrentViewInMaps(this.browser.Plugin);
     }
 }
        /// <summary>
        /// Draws a line string between the given place marks or points
        /// </summary>
        /// <param name="ge">The plug-in instance</param>
        /// <param name="start">The first placemark or point</param>
        /// <param name="end">The second placemark or point</param>
        /// <param name="id">Optional ID of the line string placemark. Default is empty</param>
        /// <param name="tessellate">Optionally sets tessellation for the line string. Default is true</param>
        /// <param name="addFeature">Optionally adds the line string directly to the plug-in. Default is true</param>
        /// <param name="width">Optional line string width, default is 1</param>
        /// <param name="color">Optional KmlColor, default is white/opaque</param>
        /// <returns>A line string placemark (or null)</returns>
        public static dynamic CreateLineString(
            dynamic ge,
            dynamic start,
            dynamic end,
            string id       = "",
            bool tessellate = true,
            bool addFeature = true,
            int width       = 1,
            KmlColor color  = new KmlColor())
        {
            if (!GEHelpers.IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            if (GEHelpers.IsApiType(start, ApiType.KmlPlacemark))
            {
                start = start.getGeometry();
            }

            if (GEHelpers.IsApiType(end, ApiType.KmlPlacemark))
            {
                end = end.getGeometry();
            }

            dynamic placemark = null;

            try
            {
                placemark = CreatePlacemark(ge);

                dynamic lineString = ge.createLineString(id);
                lineString.setTessellate(Convert.ToUInt16(tessellate));
                lineString.getCoordinates().pushLatLngAlt(start.getLatitude(), start.getLongitude(), start.getAltitude());
                lineString.getCoordinates().pushLatLngAlt(end.getLatitude(), end.getLongitude(), end.getAltitude());

                if (placemark.getStyleSelector() == null)
                {
                    placemark.setStyleSelector(ge.createStyle(string.Empty));
                }

                dynamic lineStyle = placemark.getStyleSelector().getLineStyle();
                lineStyle.setWidth(width);
                lineStyle.getColor().set(color.ToString());

                placemark.setGeometry(lineString);

                if (addFeature)
                {
                    GEHelpers.AddFeaturesToPlugin(ge, placemark);
                }
            }
            catch (RuntimeBinderException rbex)
            {
                Debug.WriteLine("CreateLineString: " + rbex.Message, "KmlHelpers");
            }

            return(placemark);
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the GETourPlayer class.
        /// </summary>
        /// <param name="ge">the plugin object</param>
        public GETourPlayer(dynamic ge)
        {
            if (!GEHelpers.IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            this.tourPlayer = ge.getTourPlayer();
        }
        /// <summary>
        /// Initializes a new instance of the GEWindow class.
        /// </summary>
        /// <param name="ge">the plug-in object</param>
        public GEWindow(dynamic ge)
        {
            if (!GEHelpers.IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            this.window = ge.getWindow();
        }
        /// <summary>
        /// Called when an item in the layers menu is clicked
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        private void LayersItem_Clicked(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;

            if (this.browser.PluginIsReady)
            {
                GEHelpers.EnableLayer(this.browser.Plugin, (Layer)item.Tag, item.Checked);
            }
        }
        /// <summary>
        /// Called from JavaScript when the plugin is ready
        /// </summary>
        /// <param name="ge">the plugin instance</param>
        public void Ready(dynamic ge)
        {
            if (!GEHelpers.IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            this.OnPluginReady(this, new GEEventArgs("Ready", "None", ge));
        }
        /// <summary>
        /// Initializes a new instance of the GEOptions class.
        /// </summary>
        /// <param name="ge">the plugin object</param>
        public GEOptions(dynamic ge)
        {
            if (!GEHelpers.IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            this.options = ge.getOptions();
        }
Пример #11
0
        /// <summary>
        /// Called when a tree node is double clicked
        /// </summary>
        /// <param name="sender">The TreeView</param>
        /// <param name="e">Event Arugments</param>
        private void KmlTree_DoubleClick(object sender, EventArgs e)
        {
            if (this.SelectedNode != null)
            {
                dynamic feature = SelectedNode.Tag;
                string  type    = string.Empty;

                this.SelectedNode.Checked = true;

                if (null != feature)
                {
                    try
                    {
                        type = feature.getType();
                    }
                    catch (RuntimeBinderException ex)
                    {
                        Debug.WriteLine(ex.ToString(), "KmlTree_DoubleClick");
                        ////throw;
                    }

                    switch (type)
                    {
                    case "KmlPlacemark":
                        if (this.openBalloonOnDoubleClickNode)
                        {
                            dynamic balloon = this.geplugin.createFeatureBalloon(String.Empty);
                            balloon.setMinHeight(this.balloonMinimumHeight);
                            balloon.setMinWidth(this.balloonMinimumWidth);
                            balloon.setFeature(feature);
                            this.geplugin.setBalloon(balloon);
                        }
                        break;

                    case "KmlTour":
                        this.geplugin.getTourPlayer().setTour(feature);
                        this.geplugin.getTourPlayer().play();
                        break;

                    case "KmlPhotoOverlay":
                        this.geplugin.getPhotoOverlayViewer().setPhotoOverlay(feature);
                        break;

                    default:
                        break;
                    }

                    if (this.flyToOnDoubleClickNode)
                    {
                        GEHelpers.LookAt(this.geplugin, feature, this.gewb);
                    }
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KmlViewerOptions"/> class.
        /// Initializes a new instance of the ViewerOptions class.
        /// </summary>
        /// <param name="ge">
        /// The plug-in object
        /// </param>
        public KmlViewerOptions(dynamic ge)
        {
            if (!GEHelpers.IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            this.plugin        = ge;
            this.viewerOptions = this.plugin.createViewerOptions(string.Empty);
            this.camera        = this.plugin.createCamera(string.Empty);
        }
Пример #13
0
        /// <summary>
        /// Remove a features from the plug-in based on the feature IDs
        /// </summary>
        /// <param name="ge">The plug-in instance</param>
        /// <param name="ids">The ids of the features to remove</param>
        public static void RemoveFeatureById(dynamic ge, string[] ids)
        {
            if (!IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            foreach (string id in ids)
            {
                GEHelpers.RemoveFeatureById(ge, id);
            }
        }
Пример #14
0
        /// <summary>
        /// Called when a tree node is checked
        /// </summary>
        /// <param name="sender">A tree node</param>
        /// <param name="e">Event Arugments</param>
        private void KmlTree_AfterCheck(object sender, TreeViewEventArgs e)
        {
            dynamic feature = e.Node.Tag;
            string  type    = string.Empty;

            try
            {
                type = GEHelpers.GetTypeFromRcw(feature);
            }
            catch (RuntimeBinderException ex)
            {
                Debug.WriteLine(ex.ToString(), "KmlTree_AfterCheck");
                ////throw;
            }

            if (feature != null && type != string.Empty)
            {
                if (e.Node.Checked)
                {
                    feature.setVisibility(1);

                    if (e.Action != TreeViewAction.Unknown)
                    {
                        if (this.checkAllChildren)
                        {
                            this.CheckAllChildNodes(e.Node);
                        }

                        this.CheckAllParentNodes(e.Node);
                    }

                    if ("KmlTour" == type)
                    {
                        this.geplugin.getTourPlayer().setTour(feature);
                    }
                }
                else
                {
                    feature.setVisibility(0);
                    this.UncheckAllChildNodes(e.Node);

                    if ("KmlTour" == type)
                    {
                        this.geplugin.getTourPlayer().setTour(null);
                    }
                    else if ("KmlPhotoOverlay" == type)
                    {
                        this.geplugin.getPhotoOverlayViewer().setPhotoOverlay(null);
                    }
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the KmlColor struct from a Google API KmlColor object.
        /// </summary>
        /// <param name="color">A Google API KmlColor object to base the new colour on</param>
        public KmlColor(dynamic color)
            : this()
        {
            if (!GEHelpers.IsApiType(color, ApiType.KmlColor))
            {
                throw new ArgumentException("feature is not of the type KmlColor");
            }

            this.alpha = Convert.ToByte(color.getA());
            this.blue  = Convert.ToByte(color.getB());
            this.green = Convert.ToByte(color.getG());
            this.red   = Convert.ToByte(color.getR());
        }
        /// <summary>
        /// Creates a KML placemark
        /// </summary>
        /// <param name="ge">The plug-in instance</param>
        /// <param name="id">Optional placemark Id. Default is empty</param>
        /// <param name="latitude">The placemark latitude in decimal degrees</param>
        /// <param name="longitude">The placemark longitude in decimal degrees</param>
        /// <param name="altitude">Optional placemark altitude in metres. Default is 0</param>
        /// <param name="altitudeMode">Optional altitudeMode. Default is AltitudeMode.RelativeToGround</param>
        /// <param name="name">Optional name of the placemark. Default is empty</param>
        /// <param name="description">Optional placemark description text. Default is empty</param>
        /// <param name="addFeature">Optionally adds the placemark directly to the plug-in. Default is true</param>
        /// <returns>A placemark (or null)</returns>
        public static dynamic CreatePlacemark(
            dynamic ge,
            string id                 = "",
            double latitude           = 0,
            double longitude          = 0,
            double altitude           = 0,
            AltitudeMode altitudeMode = AltitudeMode.RelativeToGround,
            string name               = "",
            string description        = "",
            bool addFeature           = true)
        {
            if (!GEHelpers.IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            dynamic placemark = null;

            try
            {
                dynamic point = CreatePoint(
                    ge,
                    string.Empty,
                    Maths.FixLatitude(latitude),
                    Maths.FixLongitude(longitude),
                    altitude,
                    altitudeMode);

                placemark = ge.createPlacemark(id);
                placemark.setGeometry(point);
                placemark.setName(name);
                placemark.setDescription(description);

                if (addFeature)
                {
                    GEHelpers.AddFeaturesToPlugin(ge, placemark);
                }
            }
            catch (RuntimeBinderException rbex)
            {
                Debug.WriteLine("CreatePlacemark: " + rbex.Message, "KmlHelpers");
            }
            catch (COMException cex)
            {
                Debug.WriteLine("CreatePlacemark: " + cex.Message, "KmlHelpers");
            }

            return(placemark);
        }
        /// <summary>
        /// Force the plug-in to conform to the tool-strip settings
        /// </summary>
        private void SynchronizeOptions()
        {
            if (!this.browser.PluginIsReady)
            {
                return;
            }

            // checked: t(1)+1=2 = MapType.Sky - unchecked: f(0)+1=1 = MapType.Earth
            this.options.SetMapType((MapType)Convert.ToUInt16(this.skyMenuItem.Checked) + 1);

            this.options.StatusBarVisibility    = this.statusBarMenuItem.Checked;
            this.options.StatusBarVisibility    = this.statusBarMenuItem.Checked;
            this.options.GridVisibility         = this.gridMenuItem.Checked;
            this.options.OverviewMapVisibility  = this.overviewMapMenuItem.Checked;
            this.options.ScaleLegendVisibility  = this.scaleLegendMenuItem.Checked;
            this.options.AtmosphereVisibility   = this.atmosphereMenuItem.Checked;
            this.options.MouseNavigationEnabled = this.mouseNavigationMenuItem.Checked;
            this.options.ScaleLegendVisibility  = this.scaleLegendMenuItem.Checked;
            this.options.OverviewMapVisibility  = this.overviewMapMenuItem.Checked;
            this.options.UnitsFeetMiles         = this.imperialUnitsMenuItem.Checked;
            this.control.Visibility             = (Visibility)Convert.ToUInt16(this.controlsMenuItem.Checked);

            // no wrapper for the sun - so make a direct api call to GEPlugin.getSun().setVisibility()
            this.browser.Plugin.getSun().setVisibility(Convert.ToUInt16(this.sunMenuItem.Checked));

            if (this.browser.ImageryBase != ImageryBase.Earth)
            {
                return;
            }

            GEHelpers.EnableLayer(this.browser.Plugin, Layer.Borders, this.bordersMenuItem.Checked);
            GEHelpers.EnableLayer(this.browser.Plugin, Layer.Buildings, this.buildingsMenuItem.Checked);
            GEHelpers.EnableLayer(this.browser.Plugin, Layer.BuildingsLowRes, this.buildingsGreyMenuItem.Checked);
            GEHelpers.EnableLayer(this.browser.Plugin, Layer.Roads, this.roadsMenuItem.Checked);
            GEHelpers.EnableLayer(this.browser.Plugin, Layer.Terrain, this.terrainMenuItem.Checked);
            GEHelpers.EnableLayer(this.browser.Plugin, Layer.Trees, this.treesMenuItem.Checked);

            foreach (ToolStripMenuItem item in this.imageryDropDownButton.DropDownItems)
            {
                // every imagery item is enabled and unchecked
                item.Enabled = true;
                item.Checked = false;
            }

            // the Earth item is checked and disabled
            this.earthMenuItem.Checked = true;
            this.earthMenuItem.Enabled = false;
        }
        /// <summary>
        /// Tests if a given kml feature is a Kml container
        /// </summary>
        /// <param name="feature">The feature to check</param>
        /// <returns>True if the feature is a Kml container</returns>
        public static bool IsKmlContainer(dynamic feature)
        {
            ApiType type = GEHelpers.GetApiType(feature);

            switch (type)
            {
            case ApiType.KmlDocument:
            case ApiType.KmlFolder:
            case ApiType.KmlLayer:
            case ApiType.KmlLayerRoot:
                return(true);

            default:
                return(false);
            }
        }
        /// <summary>
        /// Called when the 'go' navigation button is clicked
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        private void NavigationButton_Click(object sender, EventArgs e)
        {
            string input = this.navigationTextBox.Text;

            if (input.Length > 1)
            {
                if (this.NavigationAutoCompleteMode == AutoCompleteMode.Append ||
                    this.NavigationAutoCompleteMode == AutoCompleteMode.SuggestAppend)
                {
                    // add the user input to the custom 'per-session' string collection
                    this.navigationTextBoxStringCollection.Add(input);
                }

                if (File.Exists(input))
                {
                    this.browser.FetchKmlLocal(input);
                }
                else if (GEHelpers.IsUri(input, UriKind.Absolute))
                {
                    // input is a remote file...
                    this.browser.FetchKml(input);
                }
                else if (input.Contains(","))
                {
                    // input is possibly decimal coordinates
                    string[] parts = input.Split(',');

                    if (parts.Length == 2)
                    {
                        double latitude;
                        double longitude;

                        if (double.TryParse(parts[0], out latitude) &&
                            double.TryParse(parts[1], out longitude))
                        {
                            KmlHelpers.CreateLookAt(this.browser.Plugin, latitude, longitude);
                        }
                    }
                }
                else
                {
                    // finally attempt to geocode the input
                    // fly to the point here or in javascript?
                    this.browser.InvokeDoGeocode(input);
                }
            }
        }
Пример #20
0
        /// <summary>
        /// Initializes a new instance of the GENavigationControl class.
        /// </summary>
        /// <param name="ge">GEPlugin COM object</param>
        /// <param name="controlType">The control type. default is NavigationControl.Large</param>
        /// <param name="visibility">The visibility of the control. default is Visibility.Show</param>
        /// <param name="streetViewEnabled">Optionally enables the street view features. Default is true</param>
        public GENavigationControl(
            dynamic ge,
            NavigationControl controlType = NavigationControl.Large,
            Visibility visibility         = Visibility.Show,
            bool streetViewEnabled        = true)
        {
            if (!GEHelpers.IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            this.navigation = ge.getNavigationControl();

            this.ControlType       = controlType;
            this.StreetViewEnabled = streetViewEnabled;
            this.Visibility        = visibility;
        }
        /// <summary>
        /// Draws a line string between the given coordinates
        /// </summary>
        /// <param name="ge">The plug-in instance</param>
        /// <param name="coordinates">List of points</param>
        /// <param name="id">Optional ID of the line string placemark. Default is empty</param>
        /// <param name="tessellate">Optionally sets tessellation for the line string. Default is true</param>
        /// <param name="addFeature">Optionally adds the line string directly to the plug-in. Default is true</param>
        /// <param name="width">Optional line string-width, default is 1</param>
        /// <param name="color">Optional KmlColor, default is white/opaque</param>
        /// <returns>A line string placemark (or null)</returns>
        public static dynamic CreateLineString(
            dynamic ge,
            IList <Coordinate> coordinates,
            string id       = "",
            bool tessellate = true,
            bool addFeature = true,
            int width       = 1,
            KmlColor color  = new KmlColor())
        {
            if (!GEHelpers.IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            dynamic placemark = null;

            try
            {
                placemark = CreatePlacemark(ge, addFeature: addFeature);
                dynamic lineString = ge.createLineString(id);
                lineString.setTessellate(Convert.ToUInt16(tessellate));

                foreach (Coordinate c in coordinates)
                {
                    lineString.getCoordinates().pushLatLngAlt(c.Latitude, c.Longitude, c.Altitude);
                }

                if (placemark.getStyleSelector() == null)
                {
                    placemark.setStyleSelector(ge.createStyle(string.Empty));
                }

                dynamic lineStyle = placemark.getStyleSelector().getLineStyle();
                lineStyle.setWidth(width);
                lineStyle.getColor().set(color.ToString());

                placemark.setGeometry(lineString);
            }
            catch (RuntimeBinderException rbex)
            {
                Debug.WriteLine("CreateLineString: " + rbex, "KmlHelpers");
            }

            return(placemark);
        }
        /// <summary>
        /// Raised when a KmlTreeView node is double clicked
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected override void OnNodeMouseDoubleClick(TreeNodeMouseClickEventArgs e)
        {
            base.OnNodeMouseDoubleClick(e);

            // check if the node needs updating...
            // ideally this should be event driven rather than via user interaction
            // but as yet the API does not expose network link events...
            KmlTreeViewNode node =
                UpdateCheck((KmlTreeViewNode)e.Node, this.browser);

            node.Refresh();

            if (node.IsLoading)
            {
                return;
            }

            switch (node.ApiType)
            {
            case ApiType.KmlPlacemark:
            case ApiType.KmlFolder:
            case ApiType.KmlDocument:
            case ApiType.KmlGroundOverlay:
            {
                GEHelpers.OpenFeatureBalloon(this.browser.Plugin, node.ApiObject, setBalloon: node.Checked);
            }

            break;

            case ApiType.KmlTour:
            case ApiType.KmlPhotoOverlay:
            {
                GEHelpers.ToggleMediaPlayer(this.browser.Plugin, node.ApiObject, node.Checked);
            }

                return;       // exit here as the media player handles the view update

            case ApiType.None:
                return;
            }

            GEHelpers.FlyToObject(this.browser.Plugin, node.ApiObject);
        }
        /// <summary>
        /// Set the browser instance for the control to work with
        /// </summary>
        /// <param name="instance">The GEWebBrowser instance</param>
        public void SetBrowserInstance(GEWebBrowser instance)
        {
            this.browser = instance;

            if (!GEHelpers.IsGE(this.browser.Plugin))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            this.Nodes.Clear();
            this.Enabled    = true;
            this.CheckBoxes = true;

            this.browser.PropertyChanged += (o, e) =>
            {
                if (e.PropertyName == "PluginIsReady")
                {
                    this.Enabled = this.browser.PluginIsReady;
                }
            };
        }
Пример #24
0
        /// <summary>
        /// see http://code.google.com/p/winforms-geplugin-control-library/issues/detail?id=66
        /// </summary>
        internal void Refresh()
        {
            if (this.ApiObject == null)
            {
                return;
            }

            try
            {
                this.Name            = this.ApiObject.getId();
                this.ApiType         = GEHelpers.GetApiType(this.ApiObject);
                this.Text            = RemoveScrubbingString(this.ApiObject.getName());
                this.StateImageIndex = this.ApiObjectVisible ? 1 : 0;
                this.Checked         = this.ApiObjectVisible;
                this.SetStyle();
            }
            catch (COMException cex)
            {
                Debug.WriteLine("Refresh" + cex.Message, "KmlTreeViewNode");
            }
        }
Пример #25
0
        /// <summary>
        /// Remove a feature from the plug-in based on the feature ID
        /// </summary>
        /// <param name="ge">The plug-in instance</param>
        /// <param name="id">The id of the feature to remove</param>
        public static void RemoveFeatureById(dynamic ge, string id)
        {
            if (!IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            dynamic feature = GEHelpers.GetElementById(ge, id);

            if (feature != null)
            {
                try
                {
                    ge.getFeatures().removeChild(feature);
                    feature.release();
                }
                catch (RuntimeBinderException rbex)
                {
                    Debug.WriteLine("RemoveFeatureById: " + rbex.Message, "GEHelpers");
                }
            }
        }
        /// <summary>
        /// Look at the given coordinates
        /// </summary>
        /// <param name="ge">the plug-in</param>
        /// <param name="latitude">latitude in decimal degrees</param>
        /// <param name="longitude">longitude in decimal degrees</param>
        /// <param name="id">Optional LookAt Id. Default is empty</param>
        /// <param name="altitude">Optional altitude. Default is 0</param>
        /// <param name="altitudeMode">Optional altitudeMode. Default is AltitudeMode.RelativeToGround</param>
        /// <param name="heading">Optional heading in degrees. Default is 0 (north)</param>
        /// <param name="tilt">Optional tilt in degrees. Default is 0</param>
        /// <param name="range">Optional range in metres. Default is 1000</param>
        /// <param name="setView">Optional set the current view to the lookAt</param>
        /// <returns>a look at object (or null)</returns>
        public static dynamic CreateLookAt(
            dynamic ge,
            double latitude,
            double longitude,
            string id                 = "",
            double altitude           = 0,
            AltitudeMode altitudeMode = AltitudeMode.RelativeToGround,
            double heading            = 0,
            double tilt               = 0,
            double range              = 1000,
            bool setView              = true)
        {
            if (!GEHelpers.IsGE(ge))
            {
                throw new ArgumentException("ge is not of the type GEPlugin");
            }

            dynamic lookat = null;

            try
            {
                lookat = ge.createLookAt(id);
                lookat.set(latitude, longitude, altitude, altitudeMode, heading, tilt, range);

                if (setView)
                {
                    ge.getView().setAbstractView(lookat);
                }
            }
            catch (RuntimeBinderException rbex)
            {
                Debug.WriteLine("CreateLookAt: " + rbex.Message, "KmlHelpers");
            }

            return(lookat);
        }
        /// <summary>
        /// Computes the bounding box for the given object.
        /// Note that this method walks the object's DOM, so may have poor performance for large objects.
        /// </summary>
        /// <param name="kmlFeature">{KmlFeature|KmlGeometry} object The feature or geometry whose bounds should be computed</param>
        /// <returns>A bounds object based on the <paramref name="kmlFeature"/> (or an empty bounds object)</returns>
        /// <remarks>
        /// Based on the methods at:
        /// http://code.google.com/p/earth-api-utility-library/source/browse/trunk/extensions/src/dom/utils.js
        /// </remarks>
        public static Bounds ComputeBounds(dynamic kmlFeature)
        {
            Bounds           bounds   = new Bounds();
            Action <dynamic> eachNode = feature =>
            {
                ApiType type = GEHelpers.GetApiType(feature);
                switch (type)
                {
                case ApiType.KmlGroundOverlay:
                    dynamic llb = feature.getLatLonBox();

                    if (llb != null)
                    {
                        double alt = feature.getAltitude();
                        bounds.Extend(new Coordinate(llb.getNorth(), llb.getEast(), alt));
                        bounds.Extend(new Coordinate(llb.getNorth(), llb.getWest(), alt));
                        bounds.Extend(new Coordinate(llb.getSouth(), llb.getEast(), alt));
                        bounds.Extend(new Coordinate(llb.getSouth(), llb.getWest(), alt));
                    }

                    break;

                case ApiType.KmlModel:
                    bounds.Extend(new Coordinate(feature.getLocation()));
                    break;

                case ApiType.KmlLinearRing:
                case ApiType.KmlLineString:
                    dynamic coords = feature.getCoordinates();

                    if (coords != null)
                    {
                        int count = coords.getLength();
                        for (int i = 0; i < count; i++)
                        {
                            bounds.Extend(new Coordinate(coords.get(i)));
                        }
                    }

                    break;

                case ApiType.KmlCoord:
                case ApiType.KmlLocation:
                case ApiType.KmlPoint:
                    bounds.Extend(new Coordinate(feature));
                    break;

                case ApiType.KmlPlacemark:
                    dynamic geometry = feature.getGeometry();
                    if (GEHelpers.IsApiType(geometry, ApiType.KmlPoint))
                    {
                        bounds.Extend(new Coordinate(geometry));
                    }

                    break;
                }
            };

            KmlHelpers.WalkKmlDom(kmlFeature, eachNode, true, true);

            return(bounds);
        }
        /// <summary>
        /// Based on kmldomwalk.js
        /// see: http://code.google.com/p/earth-api-samples/source/browse/trunk/lib/kmldomwalk.js
        /// </summary>
        /// <param name="feature">The KML object to parse</param>
        /// <param name="callback">A delegate action, each node visited will be passed to this as the single parameter</param>
        /// <param name="walkFeatures">Optionally walk features, default is true</param>
        /// <param name="walkGeometries">Optionally walk geometries, default is false</param>
        /// <remarks>This method is used by <see cref="KmlTreeView"/> to build the nodes</remarks>
        public static void WalkKmlDom(
            dynamic feature,
            Action <dynamic> callback,
            bool walkFeatures   = true,
            bool walkGeometries = false)
        {
            if (feature == null)
            {
                return;
            }

            dynamic objectContainer = null;
            ApiType type            = GEHelpers.GetApiType(feature);

            switch (type)
            {
            // objects that support getFeatures
            case ApiType.KmlDocument:
            case ApiType.KmlFolder:
            case ApiType.KmlLayer:
            case ApiType.KmlLayerRoot:
            {
                if (walkFeatures)
                {
                    objectContainer = feature.getFeatures();          // GESchemaObjectContainer
                }
            }

            break;

            // objects that support getGeometry
            case ApiType.KmlPlacemark:
            {
                if (walkGeometries)
                {
                    WalkKmlDom(feature.getGeometry(), callback, walkFeatures, true);
                }
            }

            break;

            // object that support getInnerBoundaries
            case ApiType.KmlPolygon:
            {
                if (walkGeometries)
                {
                    WalkKmlDom(feature.getOuterBoundary(), callback, walkFeatures, true);
                }
            }

            break;

            // objects that support getGeometries
            case ApiType.KmlMultiGeometry:
            {
                if (walkGeometries)
                {
                    objectContainer = feature.getGeometries();          // GESchemaObjectContainer
                    ////WalkKmlDom(feature.getOuterBoundary(), callback, walkFeatures, walkGeometries);
                }
            }

            break;
            }

            callback(feature);

            if (objectContainer != null && HasChildNodes(objectContainer))
            {
                // 'GetChildNodes' returns null in some circumstances.
                // see: Issue 96
                dynamic childNodes = KmlHelpers.GetChildNodes(objectContainer);
                int     count      = childNodes == null ? 0 : childNodes.getLength();
                for (int i = 0; i < count; i++)
                {
                    dynamic node = childNodes.item(i);
                    WalkKmlDom(node, callback, walkFeatures, walkGeometries);
                    callback(node);
                }
            }
        }
        /// <summary>
        /// Raised when the mouse is clicked on the KmlTreeView
        /// </summary>
        /// <param name="e">The event arguments</param>
        protected override void OnNodeMouseClick(TreeNodeMouseClickEventArgs e)
        {
            base.OnNodeMouseClick(e);
            this.preventChecking = true;

            int space = this.ImageList == null ? 0 : 18;

            if ((e.X > e.Node.Bounds.Left - space ||
                 e.X < e.Node.Bounds.Left - (space + 16)) &&
                e.Button != MouseButtons.None)
            {
                return;
            }

            KmlTreeViewNode treeNode = (KmlTreeViewNode)e.Node;

            if (e.Button == MouseButtons.Left)
            {
                // toggle the check state
                treeNode.Checked          = !treeNode.Checked;
                treeNode.ApiObjectVisible = treeNode.Checked;

                if (!treeNode.Checked)
                {
                    // Turn off the media player for the node if it was unchecked
                    // For example, un-checking a Tour object in the tree exits the tour player
                    GEHelpers.ToggleMediaPlayer(this.browser.Plugin, treeNode.ApiObject, false);
                }
            }

            treeNode.StateImageIndex = treeNode.Checked ? 1 : treeNode.StateImageIndex;

            this.OnAfterCheck(new TreeViewEventArgs(treeNode, TreeViewAction.ByMouse));

            Stack <KmlTreeViewNode> nodes = new Stack <KmlTreeViewNode>(treeNode.Nodes.Count);

            nodes.Push(treeNode);

            do
            {
                treeNode                  = nodes.Pop();
                treeNode.Checked          = e.Node.Checked;
                treeNode.ApiObjectVisible = treeNode.Checked;
                for (int i = 0; i < treeNode.Nodes.Count; i++)
                {
                    nodes.Push((KmlTreeViewNode)treeNode.Nodes[i]);
                }
            }while (nodes.Count > 0);

            bool state = false;

            treeNode = (KmlTreeViewNode)e.Node;

            while (treeNode.Parent != null)
            {
                foreach (KmlTreeViewNode child in treeNode.Parent.Nodes)
                {
                    state |= child.Checked != treeNode.Checked | child.StateImageIndex == 2;
                }

                int index = (int)Convert.ToUInt32(treeNode.Checked);
                treeNode.Parent.Checked = state || (index > 0);

                if (state)
                {
                    treeNode.Parent.ApiObjectVisible = true;
                    treeNode.Parent.StateImageIndex  = 2;
                }
                else
                {
                    treeNode.Parent.StateImageIndex = index;
                }

                treeNode = treeNode.Parent;
            }

            this.preventChecking = false;
        }
Пример #30
0
 /// <summary>
 /// Parses a KmlObject and loads it into the plugin.
 /// </summary>
 /// <param name="kml">kml object to parse</param>
 public void ParseKmlObject(dynamic kml)
 {
     GEHelpers.AddFeaturesToPlugin(this.plugin, kml);
 }