Esempio n. 1
0
        public void RemoveByLayerType <T>() where T : ILayer
        {
            this.Layers.RemoveAll(l => l is T && l.LayerName != Current.Instance.Earthwatcher.PlayingRegion + Constants.RegionLawLayerName);

            var currentLayers = layerCollection.Where(l => l is T && !(l is BaseTileLayer) || (l.LayerName.EndsWith(Constants.RegionLawLayerName))).ToList();

            foreach (var layer in currentLayers)
            {
                layerCollection.Remove(layer);
                Current.Instance.LayerHelper.LayerCollection.Remove(layer);
            }
        }
Esempio n. 2
0
        private void AttachMapLayerCollection(LayerCollection layers)
        {
            if (layers == null)
            {
                return;
            }
            layerCollection           = layers;
            layers.LayersInitialized += MapView_LayersInitialized;
            layers.CollectionChanged += Layers_CollectionChanged;
            AttachLayerEventHandler(GetLayers(LayerIDs, layers));
            var initializedLayers = layers.Where(l => l is FeatureLayer && l.IsInitialized);

            if (initializedLayers.Count() > 0)
            {
                setTemplates();
            }
        }
        /// <summary> Event handler for a change of the layers collection. Updates the layer list. </summary>
        /// <param name="sender"> Sender of the CollectionChanged event. </param>
        /// <param name="e"> The event parameters. </param>
        private void Layers_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            // Unregister events for old layers
            if (e.OldItems != null)
            {
                foreach (var layer in e.OldItems)
                {
                    ((ILayer)layer).PropertyChanged -= layer_PropertyChanged;
                }
            }

            // unregister events for existing layers
            foreach (var layer in layers.Where(layer => e.NewItems == null || !e.NewItems.Contains(layer)))
            {
                layer.PropertyChanged -= layer_PropertyChanged;
            }

            UpdateLayerList();
        }
Esempio n. 4
0
        public static MapRectangle GetMapRectangleFromShapeLayers(this LayerCollection layers)
        {
            var shapeLayers = layers.Where(l => l.GetType() == typeof(ShapeLayer)).Select(l => l as ShapeLayer);

            if (shapeLayers.Count() == 0)
            {
                return(null);
            }

            double up = double.MinValue, down = double.MaxValue, left = double.MaxValue, rigth = double.MinValue;

            foreach (var layer in shapeLayers)
            {
                if (layer.Shapes.Count == 0)
                {
                    continue;
                }
                //up = Math.Max(up, layer.Shapes.Where(s => s.GetType().IsSubclassOf(typeof(MapPolylineBase))).Select(l => l as MapPolylineBase).Select(mlb => mlb.GetMaxY()).Max());
                //down = Math.Min(up, layer.Shapes.Where(s => s.GetType().IsSubclassOf(typeof(MapPolylineBase))).Select(l => l as MapPolylineBase).Select(mlb => mlb.GetMinY()).Min());
                //left = Math.Min(up, layer.Shapes.Where(s => s.GetType().IsSubclassOf(typeof(MapPolylineBase))).Select(l => l as MapPolylineBase).Select(mlb => mlb.GetMinX()).Min());
                //rigth = Math.Max(up, layer.Shapes.Where(s => s.GetType().IsSubclassOf(typeof(MapPolylineBase))).Select(l => l as MapPolylineBase).Select(mlb => mlb.GetMaxX()).Max());

                up    = Math.Max(up, layer.Shapes.Select(s => ShapeCanvas.GetLocation(s).Y).Max());
                down  = Math.Min(down, layer.Shapes.Select(s => ShapeCanvas.GetLocation(s).Y).Min());
                left  = Math.Min(left, layer.Shapes.Select(s => ShapeCanvas.GetLocation(s).X).Min());
                rigth = Math.Max(rigth, layer.Shapes.Select(s => ShapeCanvas.GetLocation(s).X).Max());
            }

            if (up == double.MinValue)
            {
                return(null);
            }

            return
                (new Ptv.XServer.Controls.Map.MapRectangle()
            {
                North = up,
                South = down,
                West = left,
                East = rigth,
            }.Inflate(1.05, 1.05));
        }
		private void AttachMapLayerCollection(LayerCollection layers)
		{
			if (layers == null) return;
			layerCollection = layers;
			layers.LayersInitialized += MapView_LayersInitialized;
			layers.CollectionChanged += Layers_CollectionChanged;
			AttachLayerEventHandler(GetLayers(LayerIDs, layers));
			var initializedLayers = layers.Where(l => l is FeatureLayer && l.IsInitialized);
			if (initializedLayers.Count() > 0)
				setTemplates();
		}