public void HandleOkCommand()
        {
            ChartMessage message = new ChartMessage(selectedItems);

            Messenger.Default.Send <WindowStateMessage>(new WindowStateMessage(S57WindowState.Close));
            Messenger.Default.Send <ChartMessage>(message, "LoadCharts");
            selectedItems.Clear();
        }
        private void HandleDoubleClickCommand()
        {
            if (SelectedItem == null)
            {
                return;
            }

            ChartMessage message = new ChartMessage(new[] { SelectedItem });

            Messenger.Default.Send <ChartMessage>(message, "LoadCharts");
        }
        private void HandleUnloadChartMessage(ChartMessage message)
        {
            if (message.Charts != null)
            {
                if (map.Overlays.Contains(chartsOverlayName))
                {
                    LayerOverlay overlay = ((LayerOverlay)map.Overlays[chartsOverlayName]);
                    foreach (ChartItem item in message.Charts)
                    {
                        for (int i = overlay.Layers.Count - 1; i >= 0; i--)
                        {
                            Layer layer = overlay.Layers[i];
                            if (item.FileName == layer.Name)
                            {
                                overlay.Layers.Remove(layer);

                                boundingBoxPreviewLayer.InternalFeatures.Remove(layer.GetHashCode().ToString());
                                break;
                            }
                        }
                        if (ChartSelectedItem != null && ChartSelectedItem.FullName == item.FileName)
                        {
                            ChartSelectedItem = new ChartSelectedItem(string.Empty, null);
                        }
                    }

                    RectangleShape boundingBox = null;
                    foreach (Layer layer in overlay.Layers)
                    {
                        layer.Open();
                        if (boundingBox == null)
                        {
                            boundingBox = layer.GetBoundingBox();
                        }
                        else
                        {
                            boundingBox.ExpandToInclude(layer.GetBoundingBox());
                        }
                        layer.Close();
                    }
                    if (boundingBox != null)
                    {
                        map.CurrentExtent = boundingBox;
                    }

                    map.Refresh();
                }
            }
        }
        private void HandleUnloadCommand()
        {
            MessageBoxResult result = MessageBox.Show("Are you sure remove selected charts?", string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                ChartMessage message = new ChartMessage(selectedItems);
                Messenger.Default.Send <ChartMessage>(message, "UnloadCharts");
                for (int i = selectedItems.Count - 1; i >= 0; i--)
                {
                    ChartItem chart = selectedItems[i];
                    Charts.Remove(chart);
                }
            }
        }
        public override void Handle(Window owner, MapView map, MenuItemMessage message)
        {
            switch (message.MenuItem.Action.ToLowerInvariant())
            {
            case "loadcharts":
            {
                var window = new ChartsManagmentWindow();
                window.Owner = owner;
                window.ShowDialog();
            }
            break;

            case "unloadcharts":
            {
                if (map.Overlays.Contains(chartsOverlayName))
                {
                    if (MessageBox.Show("Do you want to unload all the charts?", string.Empty, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        if (map.Overlays.Contains(chartsOverlayName))
                        {
                            GeoCollection <Layer> layers = (map.Overlays[chartsOverlayName] as LayerOverlay).Layers;
                            foreach (Layer layer in layers)
                            {
                                layer.Close();
                            }
                            layers.Clear();

                            ChartMessage chartMessage = new ChartMessage(ChartsManagmentViewModel.Instance.Charts);
                            Messenger.Default.Send <ChartMessage>(chartMessage, "UnloadCharts");
                            ChartsManagmentViewModel.Instance.Charts.Clear();
                            ChartsManagmentViewModel.Instance.SelectedItem = null;
                            ChartsManagmentViewModel.Instance.SelectedItems.Clear();
                        }

                        if (map.Overlays.Contains(boundingBoxPreviewOverlayName))
                        {
                            ((InMemoryFeatureLayer)((LayerOverlay)map.Overlays[boundingBoxPreviewOverlayName]).Layers[0]).InternalFeatures.Clear();
                        }
                        map.Refresh();
                    }
                }
            }
            break;
            }
        }
        private void HandleLoadChartMessage(ChartMessage message)
        {
            LayerOverlay overlay = null;

            if (message.Charts != null)
            {
                if (map.Overlays.Contains(chartsOverlayName))
                {
                    overlay = ((LayerOverlay)map.Overlays[chartsOverlayName]);
                }
                else
                {
                    overlay = new LayerOverlay()
                    {
                        TileType = TileType.SingleTile,
                    };
                    map.Overlays.Insert(1, chartsOverlayName, overlay);
                }

                overlay.Layers.Clear();
                ChartSelectedItem = new ChartSelectedItem(string.Empty, null);
                IEnumerable <ChartItem> charts      = message.Charts;
                RectangleShape          boundingBox = null;
                foreach (ChartItem item in charts)
                {
                    if (!File.Exists(item.IndexFileName))
                    {
                        NauticalChartsFeatureSource.BuildIndexFile(item.FileName, BuildIndexMode.DoNotRebuild);
                    }
                    NauticalChartsFeatureLayer layer = new NauticalChartsFeatureLayer(item.FileName);
                    if (map.MapUnit == GeographyUnit.Meter)
                    {
                        layer.FeatureSource.Projection = new Proj4Projection(4326, 3857);
                    }

                    layer.DrawingFeatures += hydrographyLayer_DrawingFeatures;

                    layer.IsDepthContourTextVisible = Globals.IsDepthContourTextVisible;
                    layer.IsLightDescriptionVisible = Globals.IsLightDescriptionVisible;
                    layer.IsSoundingTextVisible     = Globals.IsSoundingTextVisible;
                    layer.SymbolTextDisplayMode     = Globals.SymbolTextDisplayMode;
                    layer.DisplayCategory           = Globals.DisplayMode;
                    layer.DefaultColorSchema        = Globals.CurrentColorSchema;
                    layer.SymbolDisplayMode         = Globals.CurrentSymbolDisplayMode;
                    layer.BoundaryDisplayMode       = Globals.CurrentBoundaryDisplayMode;

                    layer.SafetyDepthInMeter        = NauticalChartsFeatureLayer.ConvertDistanceToMeters(Globals.SafetyDepth, Globals.CurrentDepthUnit);
                    layer.ShallowDepthInMeter       = NauticalChartsFeatureLayer.ConvertDistanceToMeters(Globals.ShallowDepth, Globals.CurrentDepthUnit);
                    layer.DeepDepthInMeter          = NauticalChartsFeatureLayer.ConvertDistanceToMeters(Globals.DeepDepth, Globals.CurrentDepthUnit);
                    layer.SafetyContourDepthInMeter = NauticalChartsFeatureLayer.ConvertDistanceToMeters(Globals.SafetyContour, Globals.CurrentDepthUnit);

                    layer.DrawingMode            = Globals.CurrentDrawingMode;
                    layer.IsFullLightLineVisible = Globals.IsFullLightLineVisible;
                    layer.IsMetaObjectsVisible   = Globals.IsMetaObjectsVisible;
                    layer.Name = item.FileName;
                    layer.Open();
                    if (boundingBox == null)
                    {
                        boundingBox = layer.GetBoundingBox();
                    }
                    else
                    {
                        boundingBox.ExpandToInclude(layer.GetBoundingBox());
                    }

                    boundingBoxPreviewLayer.InternalFeatures.Add(layer.GetHashCode().ToString(), new Feature(layer.GetBoundingBox()));

                    layer.Close();
                    overlay.Layers.Add(item.FileName, layer);
                }
                if (boundingBox != null)
                {
                    map.CurrentExtent = boundingBox;
                }

                //SetupAnimationForOverlay(overlay);

                ApplyOverlayOpacity();

                map.Refresh();
            }
        }