Exemple #1
0
        protected async override void OnClick()
        {
            MapView mapView = MapView.Active;
            Map     map     = mapView.Map;

            #region initial setup
            if ((_rtCursor != null) && (_rtCursor.GetState() == RealtimeCursorState.Subscribed))
            {
                _rtCursor.Unsubscribe();
                foreach (var vs in mapView.GetExploratoryAnalysisCollection())
                {
                    await mapView.RemoveExploratoryAnalysis(vs);
                }

                _vwDict = null;
                return;
            }

            _vwDict = new Dictionary <int, Viewshed>()
            {
                { 1, null }, { 2, null }
            };
            StreamLayer streamFLyr = map.Layers[0] as StreamLayer;
            //FeatureLayer vehicleFLyr = map.Layers[1] as FeatureLayer;//.Where(x => x.Name.Equals("Vehicles", StringComparison.InvariantCultureIgnoreCase)) as FeatureLayer;
            MapPoint searchPoint = null;
            #endregion

            await QueuedTask.Run(async() =>
            {
                RealtimeFeatureClass reatltimeFeatureClass = streamFLyr.GetFeatureClass();

                //RealtimeCursor
                _rtCursor = streamFLyr.Subscribe(null, true);

                //Waiting for new streamed features
                while (await _rtCursor.WaitForRowsAsync())
                {
                    while (_rtCursor.MoveNext())
                    {
                        using (var rtFeature = _rtCursor.Current)
                        {
                            switch (rtFeature.GetRowSource())
                            {
                            case RealtimeRowSource.EventInsert:
                                var featureId = (int)rtFeature["TrackID"];
                                searchPoint   = await ShowViewshed(mapView, featureId);
                                continue;

                            case RealtimeRowSource.EventDelete:
                            default:
                                continue;
                            }
                            ;
                        }
                    }
                }
            });
        }
        protected async override void OnClick()
        {
            Map map = MapView.Active.Map;

            if ((_rtCursor != null) && (_rtCursor.GetState() == RealtimeCursorState.Subscribed))
            {
                _rtCursor.Unsubscribe();
                return;
            }

            StreamLayer        streamFLyr = map.Layers[0] as StreamLayer;
            SpatialQueryFilter sf         = new SpatialQueryFilter();

            sf.SpatialRelationship = SpatialRelationship.Intersects;

            FeatureLayer countiesFLyr = map.Layers[1] as FeatureLayer;

            //var serviceConnectionProperties =
            //  new RealtimeServiceConnectionProperties(new Uri("https://zihans.esri.com:6443/arcgis/rest/services/Florence-Polygon-Out/StreamServer"), RealtimeDatastoreType.StreamService);
            //RealtimeDatastore realtimeDatastore = null;
            //string tableName = "";
            RealtimeFeatureClass realTimeFC = null;
            await QueuedTask.Run(async() =>
            {
                realTimeFC = streamFLyr.GetFeatureClass();
                _rtCursor  = realTimeFC.SearchAndSubscribe(null, true);

                while (await _rtCursor.WaitForRowsAsync())
                {
                    while (_rtCursor.MoveNext())
                    {
                        using (var rtFeature = _rtCursor.Current as RealtimeFeature)
                        {
                            switch (rtFeature.GetRowSource())
                            {
                            case RealtimeRowSource.EventInsert:
                                Polygon searchGeom = rtFeature.GetShape() as Polygon;
                                sf.FilterGeometry  = searchGeom;
                                countiesFLyr.Select(sf);
                                continue;

                            default:
                                continue;
                            }
                        }
                    }
                }
            });
        }
Exemple #3
0
        private async void StreamLayerSubscribe()
        {
            if (_rtCursor?.GetState() == RealtimeCursorState.Subscribed)
            {
                _rtCursor.Unsubscribe();
                return;
            }

            Map map = MapView.Active.Map;

            if (map == null)
            {
                return;
            }

            StreamLayer streamLayer = map.Layers[0] as StreamLayer;

            await QueuedTask.Run(async() => {
                var rtFC  = streamLayer.GetFeatureClass();
                _rtCursor = rtFC.Subscribe(null, true);
                while (await _rtCursor.WaitForRowsAsync())
                {
                    while (_rtCursor.MoveNext())
                    {
                        using (var _rtFeature = _rtCursor.Current as RealtimeFeature)
                        {
                            switch (_rtFeature.GetRowSource())
                            {
                            case RealtimeRowSource.EventInsert:
                                var point            = _rtFeature.GetShape() as MapPoint;
                                Module1.Current.Long = point.X;
                                Module1.Current.Lat  = point.Y;
                                var pane             = FrameworkApplication.DockPaneManager.Find(BingSearchResultViewModel._dockPaneID) as BingSearchResultViewModel;
                                pane?.DoSearch();
                                continue;

                            default:
                                continue;
                            }
                        }
                    }
                }
                ;
            });
        }
Exemple #4
0
        private async void Foo()
        {
            RealtimeCursor rc = null;
            bool           SomeConditionForCancel = false;

            #region Explicitly Cancel WaitForRowsAsync
            //somewhere in our code we create a CancellationTokenSource
            var cancel = new CancellationTokenSource();
            //...

            //call cancel on the CancellationTokenSource anywhere in
            //the add-in, assuming the CancellationTokenSource is in scope
            if (SomeConditionForCancel)
            {
                cancel.Cancel();//<-- will cancel the token
            }
            //Within QueuedTask we are subscribed! streamLayer.Subscribe() or SearchAndSubscribe()
            try
            {
                //TaskCanceledException will be thrown when the token is cancelled
                while (await rc.WaitForRowsAsync(cancel.Token))
                {
                    //check for row events
                    while (rc.MoveNext())
                    {
                        using (var row = rc.Current)
                        {
                            //etc
                        }
                    }
                }
            }
            catch (TaskCanceledException tce)
            {
                //Handle cancellation as needed
            }
            cancel.Dispose();

            #endregion
        }
Exemple #5
0
        protected async override void OnClick()
        {
            #region initial setup
            if ((_rtfc != null) && (_rtfc.GetState() == RealtimeCursorState.Subscribed))
            {
                _rtfc.Unsubscribe();
                _featuresGeoFenced = null;
                return;
            }

            Map     map      = MapView.Active.Map;
            Polygon geofence = null;
            _featuresGeoFenced = new Dictionary <int, bool> {
                { 1, false }, { 2, false }
            };
            #endregion

            #region getting geofence geometry
            FeatureLayer flyr = map.Layers[1] as FeatureLayer;
            await QueuedTask.Run(() =>
            {
                RowCursor rc = flyr.Search(null);
                rc.MoveNext();
                using (Feature f = rc.Current as Feature)
                {
                    geofence = f.GetShape().Clone() as Polygon;
                }
            });

            #endregion

            #region Setting geo-fencing using a spatial filter
            StreamLayer        streamLayer = map.Layers[0] as StreamLayer;
            SpatialQueryFilter sf          = new SpatialQueryFilter
            {
                SpatialRelationship = SpatialRelationship.Intersects,
                FilterGeometry      = geofence
            };

            await QueuedTask.Run(async() =>
            {
                RealtimeFeatureClass rtfcls = streamLayer.GetFeatureClass();

                //Subscribing with a spatial filter
                _rtfc = rtfcls.Subscribe(sf, true);

                while (await _rtfc.WaitForRowsAsync())
                {
                    while (_rtfc.MoveNext())
                    {
                        using (var rtFeature = _rtfc.Current)
                        {
                            switch (rtFeature.GetRowSource())
                            {
                            case RealtimeRowSource.EventInsert:
                                RealtimeFeature rtfeat = rtFeature as RealtimeFeature;
                                int featureID          = (int)rtfeat["TrackID"];
                                if (!_featuresGeoFenced[featureID])
                                {
                                    _featuresGeoFenced[featureID] = true;
                                    ShowAlert(featureID.ToString());
                                }
                                continue;

                            default:
                                continue;
                            }
                        }
                    }
                }
            });

            #endregion
        }