/// <summary> /// Occurs when the user click inside the globe /// </summary> /// <param name="Button"></param> /// <param name="Shift"></param> /// <param name="X"></param> /// <param name="Y"></param> public override void OnMouseDown(int Button, int Shift, int X, int Y) { //make sure that the weatherlayer and the featureclass exists if (null == m_weatherLayer || null == m_featureClass) { return; } //get the current point (convert the mouse coordinate into geographics coordinate) double lat, lon, alt; m_globeViewUtil.WindowToGeographic(m_globeDsp, m_globeDsp.ActiveViewer, X, Y, true, out lon, out lat, out alt); IPoint point = new PointClass(); ((IZAware)point).ZAware = true; point.PutCoords(lon, lat); //Set a default elevation of 1000M. Alternatively, the user can get the //elevation from the globesurface (ISurface) point.Z = 1000.0; //create the spatial filter in order to select the relevant zipCode ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = point as IGeometry; spatialFilter.GeometryField = m_featureClass.ShapeFieldName; //The spatial filter supposed to filter all the polygons containing the point spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin; //query the featureclass for the containing features IFeatureCursor featureCursor = m_featureClass.Search(spatialFilter, true); IFeature feature = featureCursor.NextFeature(); if (null == feature) { return; } //get the zip code from the containing feature long zipCode = Convert.ToInt64(feature.get_Value(feature.Fields.FindField("ZIP"))); //add the weather item to the layer m_weatherLayer.AddItem(zipCode, lat, lon); //release the featurecursor Marshal.ReleaseComObject(featureCursor); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { try { //get the weather layer IEnumLayer layers = m_scene.get_Layers(null, false); layers.Reset(); ILayer layer = layers.Next(); while (layer != null) { if (layer is RSSWeatherLayer3DClass) { m_weatherLayer = (RSSWeatherLayer3DClass)layer; break; } layer = layers.Next(); } //in case that the layer exists if (null != m_weatherLayer) { //launch the zipCode input dialog ZipCodeDlg dlg = new ZipCodeDlg(); if (DialogResult.OK == dlg.ShowDialog()) { long zipCode = dlg.ZipCode; if (0 != zipCode) { //add the weather item to the layer m_weatherLayer.AddItem(zipCode); //if the user checked the 'ZoomTo' checkbox, zoom to the item if (dlg.ZoomToItem) { m_weatherLayer.ZoomTo(zipCode); } } } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } }