-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathMapControl.cs
More file actions
806 lines (674 loc) · 23.2 KB
/
Copy pathMapControl.cs
File metadata and controls
806 lines (674 loc) · 23.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using MapWinGIS;
using MW5.Api.Concrete;
using MW5.Api.Enums;
using MW5.Api.Events;
using MW5.Api.Helpers;
using MW5.Api.Interfaces;
using MW5.Shared;
namespace MW5.Api.Map
{
//MW5.CoreApi.
//internal class ResFinder { }
// https ://social.msdn.microsoft.com/Forums/en-US/4bd5a9cd-4730-41f6-a123-cb49b9ea420b/toolboxbitmap-problem?forum=Vsexpressvcs
[ToolboxBitmap(typeof (MapControl), "Resources.Map.bmp")]
public partial class MapControl : UserControl
{
private Guid _selectionModeClientId;
public MapControl()
{
InitializeComponent();
_map.SendSelectBoxFinal = true;
_map.SendMouseDown = true;
_map.SendMouseUp = true;
_map.SendMouseMove = true;
_map.TrapRMouseDown = false;
_map.PreviewKeyDown += OnMapPreviewKeyDown;
AllowDrop = true;
ExpandLayersOnAdding = true;
DragEnter += MapControl_DragEnter;
DragDrop += MapControl_DragDrop;
AttachHandlers();
}
private void OnMapPreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Left:
case Keys.Right:
case Keys.Up:
case Keys.Down:
e.IsInputKey = true;
return;
}
// this shortcut must be passed to MapWinGIS directly
if (e.KeyCode == Keys.Z | e.KeyCode == Keys.Control)
{
e.IsInputKey = true;
return;
}
}
public event EventHandler<EventArgs> MapCursorChanged;
public event EventHandler<AfterShapeEditEventArgs> AfterShapeEdit;
public event EventHandler<BackgroundLoadingFinishedEventArgs> BackgroundLoadingFinished;
public event EventHandler<BackgroundLoadingStartedEventArgs> BackgroundLoadingStarted;
public event EventHandler<BeforeDeleteShapeEventArgs> BeforeDeleteShape;
public event EventHandler<BeforeShapeEditEventArgs> BeforeShapeEdit;
public event EventHandler<ChooseLayerEventArgs> ChooseLayer;
public event EventHandler<EventArgs> ExtentsChanged;
public event EventHandler<FileDroppedEventArgs> FileDropped;
public event EventHandler<GridOpenedEventArgs> GridOpened;
public event EventHandler<LayerProjectionIsEmptyEventArgs> LayerProjectionIsEmpty;
public event EventHandler<LayerReprojectedEventArgs> LayerReprojected;
public event EventHandler<MeasuringChangedEventArgs> MeasuringChanged;
public event EventHandler<EventArgs> ProjectionChanged;
public event EventHandler<ProjectionMismatchEventArgs> ProjectionMismatch;
public event EventHandler<SelectBoxFinalEventArgs> SelectBoxFinal;
public event EventHandler<SelectionChangedEventArgs> SelectionChanged;
public event EventHandler<ShapeHightlightedEventArgs> ShapeHighlighted;
public event EventHandler<ShapeIdentifiedEventArgs> ShapeIdentified;
public event EventHandler<ShapeValidationFailedEventArgs> ShapeValidationFailed;
public event EventHandler<TilesLoadedEventArgs> TilesLoaded;
public event EventHandler<EventArgs> HistoryChanged;
public event EventHandler<ValidateShapeEventArgs> ValidateShape;
public event EventHandler<BeforeVertexDigitizedEventArgs> BeforeVertexDigitized;
public event EventHandler<SnapPointRequestedEventArgs> SnapPointRequested;
public event EventHandler<SnapPointFoundEventArgs> SnapPointFound;
public event EventHandler<LockedEventArgs> MapLocked;
public event EventHandler<EventArgs> TmsProviderChanged;
// overriding default handlers for user control
public new event EventHandler<MouseEventArgs> MouseDown;
public new event EventHandler<MouseEventArgs> MouseMove;
public new event EventHandler<MouseEventArgs> MouseUp;
public new event EventHandler<EventArgs> MouseDoubleClick;
#region Hiding Properties from PropertyGrid
/// <summary>
/// Don't use this property. Use MapControl.BackGroundColor instead.
/// </summary>
[Browsable(false)]
public override Color BackColor
{
get { return base.BackColor; }
set { base.BackColor = value; }
}
[Browsable(false)]
public override System.Drawing.Image BackgroundImage
{
get { return base.BackgroundImage; }
set { base.BackgroundImage = value; }
}
[Browsable(false)]
public override ImageLayout BackgroundImageLayout
{
get { return base.BackgroundImageLayout; }
set { base.BackgroundImageLayout = value; }
}
[Browsable(false)]
public override bool AutoScroll
{
get { return base.AutoScroll; }
set { base.AutoScroll = value; }
}
[Browsable(false)]
public override bool AutoSize
{
get { return base.AutoSize; }
set { base.AutoSize = value; }
}
[Browsable(false)]
public override Cursor Cursor
{
get { return base.Cursor; }
set { base.Cursor = value; }
}
[Browsable(false)]
public override RightToLeft RightToLeft
{
get { return base.RightToLeft; }
set { base.RightToLeft = value; }
}
#endregion
#region IMuteMap Members
[Browsable(false)]
public IShapesList IdentifiedShapes
{
get { return new ShapesList(_map.IdentifiedShapes); }
}
[Browsable(false)]
public HistoryList History
{
get { return new HistoryList(_map.UndoList); }
}
[Browsable(false)]
public DrawingLayers Drawing
{
get { return new DrawingLayers(_map); }
}
public AutoToggle AnimationOnZooming
{
get { return (AutoToggle) _map.AnimationOnZooming; }
set { _map.AnimationOnZooming = (tkCustomState) value; }
}
public int ExtentHistory
{
get { return _map.ExtentHistory; }
set { _map.ExtentHistory = value; }
}
public double ExtentPad
{
get { return _map.ExtentPad; }
set { _map.ExtentPad = value; }
}
public bool GrabProjectionFromData
{
get { return _map.GrabProjectionFromData; }
set { _map.GrabProjectionFromData = value; }
}
public AutoToggle InertiaOnPanning
{
get { return (AutoToggle) _map.InertiaOnPanning; }
set { _map.InertiaOnPanning = (tkCustomState) value; }
}
public bool IsLocked
{
get { return _map.IsLocked == tkLockMode.lmLock; }
}
public ResizeBehavior ResizeBehavior
{
get { return (ResizeBehavior) _map.MapResizeBehavior; }
set { _map.MapResizeBehavior = (tkResizeBehavior) value; }
}
public LengthUnits MapUnits
{
get { return (LengthUnits) _map.MapUnits; }
set { _map.MapUnits = (tkUnitsOfMeasure) value; }
}
[Browsable(false)]
public IEnvelope MaxExtents
{
get { return new Envelope(_map.MaxExtents); }
}
public double MouseWheelSpeed
{
get { return _map.MouseWheelSpeed; }
set { _map.MouseWheelSpeed = value; }
}
public bool ReuseTileBuffer
{
get { return _map.ReuseTileBuffer; }
set { _map.ReuseTileBuffer = value; }
}
public ZoomBehavior ZoomBehavior
{
get { return (ZoomBehavior) _map.ZoomBehavior; }
set { _map.ZoomBehavior = (tkZoomBehavior) value; }
}
public double ZoomPercent
{
get { return _map.ZoomPercent; }
set { _map.ZoomPercent = value; }
}
public CoordinatesDisplay ShowCoordinates
{
get { return (CoordinatesDisplay) _map.ShowCoordinates; }
set { _map.ShowCoordinates = (tkCoordinatesDisplay) value; }
}
public bool ShowRedrawTime
{
get { return _map.ShowRedrawTime; }
set { _map.ShowRedrawTime = value; }
}
public bool ShowVersionNumber
{
get { return _map.ShowVersionNumber; }
set { _map.ShowVersionNumber = value; }
}
public int UdCursorHandle
{
get { return _map.UDCursorHandle; }
set { _map.UDCursorHandle = value; }
}
public bool UseSeamlessPan
{
get { return _map.UseSeamlessPan; }
set { _map.UseSeamlessPan = value; }
}
public string VersionNumber
{
get { return _map.VersionNumber; }
}
public IEnvelope GetKnownExtents(KnownExtents extents)
{
return new Envelope(_map.GetKnownExtents((tkKnownExtents) extents));
}
public void Lock()
{
bool locked = IsLocked;
_map.LockWindow(tkLockMode.lmLock);
if (!locked)
{
FireMapLocked(this, new LockedEventArgs(true));
}
}
public bool Unlock()
{
_map.LockWindow(tkLockMode.lmUnlock);
if (!IsLocked)
{
FireMapLocked(this, new LockedEventArgs(false));
}
return IsLocked;
}
public void Redraw(RedrawType redrawType = RedrawType.All)
{
_map.Redraw2((tkRedrawType) redrawType);
}
public void Redraw(RedrawType redrawType, bool reloadTiles)
{
_map.Redraw3((tkRedrawType)redrawType, reloadTiles);
}
public void Clear()
{
_map.Clear();
}
public void Undo()
{
_map.Undo();
}
public bool FindSnapPoint(double tolerance, double xScreen, double yScreen, ref double xFound, ref double yFound)
{
return _map.FindSnapPoint(tolerance, xScreen, yScreen, ref xFound, ref yFound);
}
public double GeodesicArea(IGeometry polygon)
{
return _map.GeodesicArea(polygon.GetInternal());
}
public double GeodesicDistance(double projX1, double projY1, double projX2, double projY2)
{
return _map.GeodesicDistance(projX1, projY1, projX2, projY2);
}
public double GeodesicLength(IGeometry polyline)
{
return _map.GeodesicLength(polyline.GetInternal());
}
public IImageSource SnapShot(IEnvelope boundBox)
{
var img = _map.SnapShot(boundBox.GetInternal());
return BitmapSource.Wrap(img);
}
public IImageSource SnapShot(IEnvelope boundBox, int width)
{
if (boundBox == null)
{
throw new ArgumentNullException("boundBox");
}
var img = _map.SnapShot3(boundBox.MinX, boundBox.MaxX, boundBox.MaxY, boundBox.MinY, width);
return BitmapSource.Wrap(img);
}
public IImageSource SnapShot(int clippingLayerHandle, double zoom, int width)
{
var img = _map.SnapShot2(clippingLayerHandle, zoom, width);
return BitmapSource.Wrap(img);
}
[Browsable(false)]
public MeasuringTool Measuring
{
get { return new MeasuringTool(_map.Measuring); }
}
[Browsable(false)]
public IdentifierSettings Identifier
{
get { return new IdentifierSettings(_map.Identifier); }
}
[Browsable(false)]
public SimpleLayerCollection Layers
{
get { return new SimpleLayerCollection(this); }
}
public MapProjection MapProjection
{
get { return (MapProjection) _map.Projection; }
set { _map.Projection = (tkMapProjection) value; }
}
public ZoomBarSettings ZoomBar
{
get { return new ZoomBarSettings(_map); }
}
public ScalebarUnits ScalebarUnits
{
get { return (ScalebarUnits) _map.ScalebarUnits; }
set { _map.ScalebarUnits = (tkScalebarUnits) value; }
}
public bool ScalebarVisible
{
get { return _map.ScalebarVisible; }
set { _map.ScalebarVisible = value; }
}
public double CurrentScale
{
get { return _map.CurrentScale; }
set { _map.CurrentScale = value; }
}
public int CurrentZoom
{
get { return _map.CurrentZoom; }
set { _map.CurrentZoom = value; }
}
[Browsable(false)]
public IEnvelope Extents
{
get { return new Envelope(_map.Extents as Extents); }
set
{
if (value == null) throw new ArgumentNullException("");
_map.Extents = value.GetInternal();
}
}
[Browsable(false)]
public IEnvelope GeographicExtents
{
get { return new Envelope(_map.GeographicExtents); }
}
public bool SetGeographicExtents(IEnvelope boundingBox)
{
return _map.SetGeographicExtents(boundingBox.GetInternal());
}
public bool SetGeographicExtents2(double xLongitude, double yLatitude, double widthKilometers)
{
return _map.SetGeographicExtents2(xLongitude, yLatitude, widthKilometers);
}
[Browsable(false)]
public ISpatialReference Projection
{
get { return new SpatialReference(_map.GeoProjection); }
set { _map.GeoProjection = value.GetInternal(); }
}
public KnownExtents KnownExtents
{
get { return (KnownExtents) _map.KnownExtents; }
set { _map.KnownExtents = (tkKnownExtents) value; }
}
public float Latitude
{
get { return _map.Latitude; }
set { _map.Latitude = value; }
}
public float Longitude
{
get { return _map.Longitude; }
set { _map.Longitude = value; }
}
[Browsable(false)]
public SystemCursor SystemCursor
{
get { return (SystemCursor) _map.MapCursor; }
set { _map.MapCursor = (tkCursor) value; }
}
public MapCursor MapCursor
{
get { return (MapCursor) _map.CursorMode; }
set
{
_map.CursorMode = (tkCursorMode) value;
StopCustomSelectionMode();
FireMapCursorChanged(this, new EventArgs());
}
}
public void StartCustomSelectionMode(Guid clientId)
{
_selectionModeClientId = clientId;
FireMapCursorChanged(this, new EventArgs());
}
public void StopCustomSelectionMode()
{
_selectionModeClientId = default(Guid);
}
public bool IsCustomSelectionMode
{
get
{
return _selectionModeClientId != default(Guid) && MapCursor == MapCursor.Selection;
}
}
public bool GetIsCustomSelectionMode(Guid clientId)
{
return IsCustomSelectionMode && clientId == _selectionModeClientId;
}
public TileProvider TileProvider
{
get { return (TileProvider) _map.TileProvider; }
set
{
SetTileProvider((int)value);
}
}
public void SetTileProvider(int providerId)
{
var tiles = _map.Tiles;
bool changed = providerId != tiles.ProviderId;
tiles.ProviderId = providerId;
if (changed)
{
DelegateHelper.FireEvent(this, TmsProviderChanged, new EventArgs());
}
}
public AngleFormat ShowCoordinatesFormat
{
get { return (AngleFormat)_map.ShowCoordinatesFormat; }
set { _map.ShowCoordinatesFormat = (tkAngleFormat)value; }
}
public void ZoomIn()
{
_map.ZoomIn(0.3);
}
public void ZoomOut()
{
_map.ZoomOut(0.3);
}
public void ZoomIn(double percent)
{
_map.ZoomIn(percent);
}
public void ZoomOut(double percent)
{
_map.ZoomOut(percent);
}
public void ZoomToLayer(int layerHandle)
{
_map.ZoomToLayer(layerHandle);
}
public void ZoomToMaxExtents()
{
_map.ZoomToMaxExtents();
}
public void ZoomToMaxVisibleExtents()
{
_map.ZoomToMaxVisibleExtents();
}
public int ZoomToPrev()
{
return _map.ZoomToPrev();
}
public int ZoomToNext()
{
return _map.ZoomToNext();
}
public bool ZoomToSelected(int layerHandle)
{
return _map.ZoomToSelected(layerHandle);
}
public void ZoomToShape(int layerHandle, int shape)
{
_map.ZoomToShape(layerHandle, shape);
}
public bool ZoomToTileLevel(int zoom)
{
return _map.ZoomToTileLevel(zoom);
}
public bool ZoomToWorld()
{
return _map.ZoomToWorld();
}
public bool PixelToDegrees(double pixelX, double pixelY, out double degreesLngX, out double degreesLatY)
{
degreesLngX = degreesLatY = 0.0;
return _map.PixelToDegrees(pixelX, pixelY, ref degreesLngX, ref degreesLatY);
}
public void PixelToProj(double pixelX, double pixelY, out double projX, out double projY)
{
projX = projY = 0.0;
_map.PixelToProj(pixelX, pixelY, ref projX, ref projY);
}
public ICoordinate PixelToProj(ICoordinate pixel)
{
double projX = 0.0;
double projY = 0.0;
_map.PixelToProj(pixel.X, pixel.Y, ref projX, ref projY);
return new Coordinate(projX, projY);
}
public bool ProjToDegrees(double projX, double projY, out double degreesLngX, out double degreesLatY)
{
degreesLngX = degreesLatY = 0.0;
return _map.ProjToDegrees(projX, projY, ref degreesLngX, ref degreesLatY);
}
public void ProjToPixel(double projX, double projY, out double pixelX, out double pixelY)
{
pixelX = pixelY = 0.0;
_map.ProjToPixel(projX, projY, ref pixelX, ref pixelY);
}
public ICoordinate ProjToPixel(ICoordinate projected)
{
double pixelX = 0.0;
double pixelY = 0.0;
_map.ProjToPixel(projected.X, projected.Y, ref pixelX, ref pixelY);
return new Coordinate(pixelX, pixelY);
}
public bool DegreesToPixel(double degreesLngX, double degreesLatY, out double pixelX, out double pixelY)
{
pixelX = pixelY = 0.0;
return _map.DegreesToPixel(degreesLngX, degreesLatY, ref pixelX, ref pixelY);
}
public bool DegreesToProj(double degreesLngX, double degreesLatY, out double projX, out double projY)
{
projX = projY = 0.0;
return _map.DegreesToProj(degreesLngX, degreesLatY, ref projX, ref projY);
}
[Browsable(false)]
public IGeometryEditor GeometryEditor
{
get { return new GeometryEditor(_map.ShapeEditor); }
}
[Browsable(false)]
public TileManager Tiles
{
get { return new TileManager(_map.Tiles); }
}
#endregion
[Browsable(false)]
public object InternalObject
{
get { return _map; }
}
public string LastError
{
get { return _map.get_ErrorMsg(_map.LastErrorCode); }
}
// TODO: fix it
public new string Tag
{
get { return ""; //_map.Tag.ToString();
}
set
{
//_map.Tag = value;
}
}
public void SetDefaultExtents()
{
_map.Projection = tkMapProjection.PROJECTION_NONE;
var ext = new Extents();
ext.SetBounds(0.0, 0.0, 0.0, 100.0, 100.0, 0.0);
_map.Extents = ext;
}
public new IntPtr Handle
{
get { return _map.Handle; }
}
public DecorationRectangle FocusRectangle
{
get { return new DecorationRectangle(_map.FocusRectangle); }
}
public bool LoadMapState(string filename)
{
return _map.LoadMapState(filename, null);
}
private void MapControl_DragEnter(object sender, DragEventArgs e)
{
e.Effect = (GetFilename(e) != null) ? DragDropEffects.Copy : DragDropEffects.None;
}
private void MapControl_DragDrop(object sender, DragEventArgs e)
{
string filename = GetFilename(e);
var handler = FileDropped;
if (handler != null)
{
handler(sender, new FileDroppedEventArgs(filename));
}
}
private string GetFilename(DragEventArgs e)
{
var filename = e.Data.GetData(DataFormats.StringFormat) as string;
if (!string.IsNullOrWhiteSpace(filename))
{
return filename;
}
return null;
}
public void ZoomToExtents(IEnvelope extents)
{
if (extents != null)
{
_map.Extents = extents.GetInternal();
}
}
public ZoomBoxStyle ZoomBoxStyle
{
get { return (ZoomBoxStyle) _map.ZoomBoxStyle; }
set { _map.ZoomBoxStyle = (tkZoomBoxStyle)value; }
}
public Color BackgroundColor
{
get { return _map.CtlbackColor; }
set { _map.CtlbackColor = value; }
}
public int ExtentHistoryUndoCount
{
get { return _map.ExtentHistoryUndoCount; }
}
public int ExtentHistoryRedoCount
{
get { return _map.ExtentHistoryRedoCount; }
}
public void ClearExtentHistory()
{
_map.ClearExtentHistory();
}
public bool LoadTilesForSnapshot(IEnvelope envelope, int width, string key)
{
return _map.LoadTilesForSnapshot(envelope.GetInternal(), width, key);
}
public bool IsEmpty
{
get { return _map.NumLayers == 0 && (Projection.IsEmpty || Tiles.Visible == false); }
}
/// <summary>
/// Gets or sets a value indicating whether a layer should be expanded on adding to the legend.
/// </summary>
public bool ExpandLayersOnAdding { get; set; }
}
}