|
| 1 | +# J4JMapWinLibrary: J4JMapControl |
| 2 | + |
| 3 | +## Basic usage |
| 4 | + |
| 5 | +- [Basic usage](#basic-usage) |
| 6 | +- Properties |
| 7 | + - [Projection properties](#projection-properties) |
| 8 | + - [Map region properties](#map-region-properties) |
| 9 | + - [Overlay control properties](#overlay-control-properties) |
| 10 | + - [Caching properties](#caching-properties) |
| 11 | + - [Miscellaneous proeprties](#miscellaneous-properties) |
| 12 | + |
| 13 | +*The test project `WinAppTest`, also contained in this repository, is a working example of using `J4JMapControl`.* |
| 14 | + |
| 15 | +`J4JMapControl` supports: |
| 16 | + |
| 17 | +- clicking and dragging to move the center point horizontally/vertically. |
| 18 | +- rotating the map around a point by holding down the *control* key while clicking and dragging. |
| 19 | +- using the mouse wheel to change the scale of the map |
| 20 | + |
| 21 | +Using the control involves two steps. First, you must add it to an XAML file and set at least some of its properties: |
| 22 | + |
| 23 | +```xml |
| 24 | +<map:J4JMapControl x:Name="mapControl" |
| 25 | + Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" |
| 26 | + MapProjection="BingMaps" |
| 27 | + MapScale="13" |
| 28 | + Heading="45" |
| 29 | + Center="37.5072N,122.2605W"> |
| 30 | +``` |
| 31 | + |
| 32 | +Second, in the code behind you must set the control's `ProjectionFactory` property: |
| 33 | + |
| 34 | +```csharp |
| 35 | +mapControl.ProjectionFactory = J4JDeusEx.ServiceProvider.GetService<ProjectionFactory>(); |
| 36 | + |
| 37 | +if( mapControl.ProjectionFactory == null ) |
| 38 | + _logger?.LogCritical( "ProjectionFactory is not defined" ); |
| 39 | +``` |
| 40 | + |
| 41 | +This example uses my `J4JDeuxEx` generalized view model locator, but you can create a `MapFactory` instance in other ways. Consult the [`J4JMapLibrary` documentation](https://github.com/markolbert/J4JMapControl/tree/main/J4JMapLibrary) for details. |
| 42 | + |
| 43 | +You may also want to set the control's `LoggerFactory` property if you want logging to occur: |
| 44 | + |
| 45 | +```csharp |
| 46 | +var loggerFactory = ( (App) Application.Current ).LoggerFactory; |
| 47 | + |
| 48 | +mapControl.LoggerFactory = loggerFactory; |
| 49 | +``` |
| 50 | + |
| 51 | +Again, this example uses my `J4JDeuxEx` generalized view model locator, but you can create an `ILoggerFactory` instance in other ways. |
| 52 | + |
| 53 | +[return to top](#basic-usage) |
| 54 | + |
| 55 | +## Projection properties |
| 56 | + |
| 57 | +There are two properties which define the mapping service the control uses: |
| 58 | + |
| 59 | +|Property|Type|Comments| |
| 60 | +|--------|----|--------| |
| 61 | +|`MapProjection`|`string`|the name of the mapping projection to use| |
| 62 | +|`MapStyle`|`string`|the specific style of map projection to use (only applies to certain mapping services; **not yet implemented**)| |
| 63 | + |
| 64 | +If the map projection name is not recognized by `MapFactory` the control's projection is undefined and no imagery will display. |
| 65 | + |
| 66 | +[return to top](#basic-usage) |
| 67 | + |
| 68 | +## Map region properties |
| 69 | + |
| 70 | +The region displayed by the control is defined by three properties: |
| 71 | + |
| 72 | +|Property|Type|Comments| |
| 73 | +|--------|----|--------| |
| 74 | +|`Center`|`string`|must be a parseable latitude/longitude string; see below| |
| 75 | +|`Heading`|`double`|can be any value, but is adjusted to be within the range 0 to 360| |
| 76 | +|`MapScale`|`double`|converted to an integer internally. The value is adjusted internally if it falls outside the projection's supported range.| |
| 77 | + |
| 78 | +Latitude/longitude strings must be in the following format: |
| 79 | + |
| 80 | +- latitude numeric value (`double`) |
| 81 | +- latitude direction (`char`; optional - valid values are **N** or **S**, case doesn't matter) |
| 82 | +- comma |
| 83 | +- longitude numeric value (`double`) |
| 84 | +- longitude direction (`char`; optional - valid values are **E** or **W**, case doesn't matter) |
| 85 | + |
| 86 | +If the latitude direction component is not provided the parser assumes *positive* latitudes are *north* while *negative* latitudes are *south*. Similarly, if the longitude direction component is not provided the parser assumes *positive* longitudes are *east* while *negative* longitudes are *west*. |
| 87 | + |
| 88 | +The map's heading can also be set by calling the `SetHeadingByText()` method, supplying one of the following compass rose directions: N, E, S, W, NE, SE, SW, NW, NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW. Any other values are ignored. |
| 89 | + |
| 90 | +[return to top](#basic-usage) |
| 91 | + |
| 92 | +## Overlay control properties |
| 93 | + |
| 94 | +`J4JMapControl` can display two controls above the map imagery, a compass rose showing the map's heading, and a slider control which can be used to adjust the map's scale. |
| 95 | + |
| 96 | +There are a variety of properties which can be used to fine-tune these controls: |
| 97 | + |
| 98 | +|Property|Type|Comments| |
| 99 | +|--------|----|--------| |
| 100 | +|`ControlVisibility`|`bool`|`true` displays the overlay controls, `false` hides them| |
| 101 | +|`HorizontalControlAlignment`|`HorizontalAlignment`|controls where the compass rose and map scale control are displayed horizontally within the map control. Default is `Right`.| |
| 102 | +|`VerticalControlAlignment`|`VerticalAlignment`|controls where the compass rose and map scale control are displayed vertically within the map control. Default is `Top`.| |
| 103 | +|`CompassRoseImage`|`BitmapImage`|the image used for the compass rose. It should be square so that scaling does not distort it.| |
| 104 | +|`CompassRoseHeightWidth`|`double`|the height/width of the compass rose control.| |
| 105 | +|`ControlBackground`|`Color`|the color of the `Brush` used to fill the overlay controls' background. Default is ARGB(255, 128, 128, 128).| |
| 106 | +|`ControlBackgroundOpacity`|`double`|the opacity of the overlay controls' background. Valid values are 0 to 1.0.| |
| 107 | +|`ControlVerticalMargin`|`double`|controls the vertical spacing between the compass rose and the map scale slider controls| |
| 108 | +|`LargeMapScaleChange`|`double`|defines what constitutes a "large" map scale change for the map scale slider control| |
| 109 | + |
| 110 | +[return to top](#basic-usage) |
| 111 | + |
| 112 | +## Caching properties |
| 113 | + |
| 114 | +Many, but not all, projections support caching the retrieved imagery. There are a variety of properties available to define how caching works: |
| 115 | + |
| 116 | +|Property|Type|Default|Comments| |
| 117 | +|--------|----|-------|--------| |
| 118 | +|`UseMemoryCache`|`bool`|`true`|controls whether or not in-memory caching is used when possible| |
| 119 | +|`MemoryCacheEntries`|`int`|`DefaultMemoryCacheEntries`|defines how many entries the in-memory cache will retain before it begins purging expired ones| |
| 120 | +|`MemoryCacheRetention`|`string`|`string.Empty`|defines how long entries are retained in the in-memory cache. **Not yet implemented**| |
| 121 | +|`MemoryCacheSize`|`int`|`DefaultMemoryCacheSize`|defines the maximum size, in bytes, the in-memory cache can be before it begins purging expired entries| |
| 122 | +|`FileSystemCachePath`|`string`|`string.Empty`|sets the folder where the `FileSystemCache` stores its files. If undefined, empty or an invalid location file system caching is disabled.| |
| 123 | +|`FileSystemCacheEntries`|`int`|`DefaultFileSystemCacheEntries`|defines how many files the file system cache will retain before it begins purging expired ones| |
| 124 | +|`FileSystemCacheRetention`|`string`|`string.Empty`|defines how long entries are retained in the file system cache. **Not yet implemented**| |
| 125 | +|`FileSystemCacheSize`|`int`|`DefaultFileSystemCacheSize`|defines the maximum size, in bytes, the file system cache can store in files be before it begins purging expired entries| |
| 126 | + |
| 127 | +[return to top](#basic-usage) |
| 128 | + |
| 129 | +## Miscellaneous properties |
| 130 | + |
| 131 | +|Property|Type|Comments| |
| 132 | +|--------|----|--------| |
| 133 | +|`Annotations`|`List<FrameworkElement>`|holds the FrameworkElements which are displayed above the map as annotations. See the [`MapPin` documentation](map-pin.md) for details.| |
| 134 | +|`ShowRotationHints`|`bool`|shows (`true`) or hides (`false`) hints showing how a map's heading is being changed while using click-and-drag to rotate it| |
| 135 | +|`MinMapScale`|`double`|sets the minimum map scale allowed. Values outside the range of what the projection supports are adjusted automatically.| |
| 136 | +|`MaxMapScale`|`double`|sets the maximum map scale allowed. Values outside the range of what the projection supports are adjusted automatically.| |
| 137 | +|`UpdateEventInterval`|`int`|sets the throttling window, in milliseconds, controlling how UI adjustments to map properties are processed, to reduce unnecessary processing and image retrieval. If the supplied value is less than 0 it is set to `DefaultUpdateEventInterval`| |
| 138 | + |
| 139 | +[return to top](#basic-usage) |
0 commit comments