public MainViewModel(WpfMap map) { this.map = map; map.MapClick += WpfMap_MapClick; menuItems = new Collection <object>(MenuItemHelper.GetMenus()); LoadMessageHandlers(); SetToolbarMenuItems(); Messenger.Default.Register <ChartMessage>(this, (m) => ChartSelectedItem = new ChartSelectedItem(string.Empty, null)); Messenger.Default.Register <MenuItemMessage>(this, "ShowOpacityPanel", (m) => ShowOpacityPanel = true); Messenger.Default.Register <MenuItemMessage>(this, HandleMenuItemMessage); Messenger.Default.Register <ToolBarMessage>(this, HandleToolBarMessage); Messenger.Default.Register <ChartMessage>(this, "LoadCharts", HandleLoadChartMessage); Messenger.Default.Register <ChartMessage>(this, "UnloadCharts", HandleUnloadChartMessage); Messenger.Default.Register <ChartSelectedItemMessage>(this, HandleChartSelectedItemMessage); Messenger.Default.Register <SafeWaterDepthSettingMessage>(this, HandleSafeWaterDepthMessage); map.MapUnit = GeographyUnit.Meter; map.ZoomLevelSet = new ThinkGeoCloudMapsZoomLevelSet(); // Please input your ThinkGeo Cloud Client ID / Client Secret to enable the background map. //ThinkGeoCloudRasterMapsOverlay baseOverlay = new ThinkGeoCloudRasterMapsOverlay("ThinkGeo Cloud Client ID", "ThinkGeo Cloud Client Secret"); //map.Overlays.Add(ThinkGeoCloudMapsOverlayName, baseOverlay); InitBoundingBoxPreviewOverlay(map); }
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(); } } }
public MainViewModel(WpfMap map) { this.map = map; map.MapClick += WpfMap_MapClick; menuItems = new Collection <object>(MenuItemHelper.GetMenus()); LoadMessageHandlers(); SetToolbarMenuItems(); Messenger.Default.Register <ChartMessage>(this, (m) => ChartSelectedItem = new ChartSelectedItem(string.Empty, null)); Messenger.Default.Register <MenuItemMessage>(this, "ShowOpacityPanel", (m) => ShowOpacityPanel = true); Messenger.Default.Register <MenuItemMessage>(this, HandleMenuItemMessage); Messenger.Default.Register <ToolBarMessage>(this, HandleToolBarMessage); Messenger.Default.Register <ChartMessage>(this, "LoadCharts", HandleLoadChartMessage); Messenger.Default.Register <ChartMessage>(this, "UnloadCharts", HandleUnloadChartMessage); Messenger.Default.Register <ChartSelectedItemMessage>(this, HandleChartSelectedItemMessage); Messenger.Default.Register <SafeWaterDepthSettingMessage>(this, HandleSafeWaterDepthMessage); map.CurrentExtent = new RectangleShape(-130, 40, -30, 5); map.Overlays.Add(WorldMapOverlayName, new WorldMapKitWmsWpfOverlay()); InitBoundingBoxPreviewOverlay(map); }
//private void SetupAnimationForOverlay(LayerOverlay overlay) //{ // overlay.Drawing -= overlay_Drawing; // overlay.Drawing += overlay_Drawing; // overlay.Drawn -= overlay_Drawn; // overlay.Drawn += overlay_Drawn; //} private void WpfMap_MapClick(object sender, MapClickWpfMapEventArgs e) { if (isIdentify) { ThinkGeo.MapSuite.Shapes.PointShape point = e.WorldLocation; if (!map.Overlays.Contains(chartsOverlayName)) { return; } LayerOverlay overlay = map.Overlays[chartsOverlayName] as LayerOverlay; var features = new Collection <Feature>(); NauticalChartsFeatureLayer hydrographyFeatureLayer = null; foreach (var item in overlay.Layers) { NauticalChartsFeatureLayer itemLayer = item as NauticalChartsFeatureLayer; itemLayer.Open(); features = itemLayer.QueryTools.GetFeaturesIntersecting(point.GetBoundingBox(), ReturningColumnsType.AllColumns); if (features.Count > 0) { hydrographyFeatureLayer = itemLayer; break; } } if (features.Count > 0) { List <FeatureInfo> selectedFeatures = new List <FeatureInfo>(); foreach (var item in features) { double area = double.MaxValue; PolygonShape areaShape = item.GetShape() as PolygonShape; if (areaShape != null) { area = areaShape.GetArea(map.MapUnit, AreaUnit.SquareMeters); } selectedFeatures.Add(new FeatureInfo(item, hydrographyFeatureLayer.Name, area)); } if (map.Overlays.Contains(highlightOverlayName)) { map.Overlays.Remove(highlightOverlayName); } IEnumerable <FeatureInfo> featureInfos = selectedFeatures.OrderBy(p => p.Area); SelectedFeatureInfo = featureInfos.FirstOrDefault(); NauticalChartsFeatureSource featureSource = hydrographyFeatureLayer.FeatureSource as NauticalChartsFeatureSource; if (featureSource != null) { ChartSelectedItem = new ChartSelectedItem(featureSource.NauticalChartsPathFilename, featureInfos); } } else { if (map.Overlays.Contains(highlightOverlayName)) { map.Overlays.Remove(highlightOverlayName); } map.Refresh(); } } }
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(); } }
private void HandleClearSelectionCommand() { ChartSelectedItem = new ChartSelectedItem(chartSelectedItem.FullName, new List <FeatureInfo>()); }
public ChartSelectedItemMessage(ChartSelectedItem selectedItem) { chartSelectedItem = selectedItem; }