Skip to content

Move functionality from MapControl to Map to allow MVVM #1731

Closed

Description

@pauldendulk

This is relevant for MVVM support. You do not want to need access to the IMapControl in the ViewModel

Activity

  1. pauldendulk commented on Oct 12, 2022

    @pauldendulk
    MemberAuthor

    @pauldendulk As I said before: it would be helpful to define, what Map should contain. I suggested, that Map only contains things, that belong to the pure map data like layers. Nothing else.

    I think the best solution (the simplest solution, for us and for our users) is to have a single field that represents the ViewModel of the MapControl which would contain everything else. It may be a good idea to introduce some object that contains all map data, but that would be another object.

    How these things are named is a separate question. I don't like to use the phrase 'ViewModel' because I don't want to buy into MVVM that explicitly. It should be possible to use Mapsui in MVVM and if you don't you should not be confronted with MVVM.

    And about a possible MapData/Map object. Not sure how much more this would contain apart from the layers.

    Either way, these high over ideas are interesting to get our thoughts started, but if we actually start moving classes around we will have new insights. Also, building samples can give new insights. That way we can better understand how it affects our users.

  2. pauldendulk commented on Oct 17, 2022

    @pauldendulk
    MemberAuthor

    This is a list of all the fields in the IMapControl.

    • INFO
      • event EventHandler Info;
      • MapInfo? GetMapInfo(MPoint screenPosition, int margin = 0); // Check, if a feature at a given screen position is hit
    • DATA STATE CHANGE
      • event EventHandler? ViewportInitialized;
      • void RefreshGraphics();
      • void RefreshData(ChangeType changeType = ChangeType.Discrete);
      • void Refresh(ChangeType changeType = ChangeType.Discrete);
    • VIEWPORT
      • double UnSnapRotationDegrees
      • double ReSnapRotationDegrees
      • INavigator? Navigator
      • IReadOnlyViewport Viewport
    • RENDERER
      • IRenderer Renderer
      • MPoint ToDeviceIndependentUnits(MPoint coordinateInPixels); // Converts pixel to device independent units
      • MPoint ToPixels(MPoint coordinateInDeviceIndependentUnits); // Converts device independent units to pixels.
      • Performance? Performance
    • OTHER
      • void OpenBrowser(string url); //todo: Perhaps remove
      • float PixelDensity //The number of pixel per device independent unit
      • byte[]? GetSnapshot(IEnumerable? layers = null); // Create a snapshot form map as PNG image
      • Map? Map
  3. pauldendulk commented on Oct 17, 2022

    @pauldendulk
    MemberAuthor

    List of fields in Map

    • DATA
      • LayerCollection Layers
      • MRect? Extent. Perhaps can be an extension method on the LayerCollection.
    • DATA STATE CHANGE
      • void RefreshData(FetchInfo fetchInfo). Could also be an extension method of the LayerCollection.
      • event DataChangedEventHandler? DataChanged;
      • bool Initialized. Not a very clear concept. There are two parts.
        1. The UI needs to be initialized. Mostly size set of MapControl.
        2. The data needs to be loaded. However, the data can change later on when the users start panning/zooming. Perhaps the data loading should not be a requirement for the initialized state. Perhaps we should assume that the startup/default extent is explicitly set. If the users want the extent to be determined by the data extent this is considered a special scenario.
      • void AbortFetch();
      • void ClearCache(); Perhaps this should be removed. I think it was once added for a scenario where the source of a tile layer was changed.
    • WIDGETS
      • ConcurrentQueue Widgets
      • IEnumerable GetWidgetsOfMapAndLayers();
    • DISPLAY
      • string? CRS
      • Color BackColor
    • VIEWPORT
      • IViewportLimiter Limiter
      • bool RotationLock
      • bool ZoomLock
      • bool PanLock
      • IReadOnlyList Resolutions
    • NAVIGATION
      • Action Home
    • INFO
      • event EventHandler? Info;
      • void OnInfo(MapInfoEventArgs? mapInfoEventArgs);
    • OTHER
      • void Dispose();
      • event PropertyChangedEventHandler? PropertyChanged;
      • bool UpdateAnimations();
  4. pauldendulk commented on Oct 18, 2022

    @pauldendulk
    MemberAuthor

    I am now considering to have one class that controls all changes to the Viewport. Things in that class would be:

    • RotationLock
    • ZoomLock
    • PanLock
    • UnSnapRotationDegrees and ReSnapRotationDegrees (not sure if possible)
    • The Home extent (the default map extent). This extent can be determined by the data, so unfortunately there is a relation between data and viewport here, but I don't see a better solution. It would mean that if a user would want the extent to be determined by the data the default map extent should be updated if the data in the layers changes or when a layer is added or removed. We could also decide this is up to the user to manage.
    • The PanLimits. This is often the same as the default Home extent but does not have to be.
    • The ZoomLimits
    • Resolutions (Levels). Mapsui viewport allows values in between the resolutions. The resolutions are used with the +/- buttons and mouse wheel, but not when using finger pinch, or navigate to extent.
    • Viewport limiter logic
  5. changed the title [-]Move everything in the MapControl that is needed in the IMapControlSample to the Map so that only a Map is needed[/-] [+]Move thing out of MapControl to Map to allow Map [/+] on Oct 19, 2022
  6. pauldendulk commented on Oct 19, 2022

    @pauldendulk
    MemberAuthor

    @pauldendulk As I said before: it would be helpful to define, what Map should contain. I suggested, that Map only contains things, that belong to the pure map data like layers. Nothing else.

    I think the best solution (the simplest solution, for us and for our users) is to have a single field that represents the ViewModel of the MapControl which would contain everything else. It may be a good idea to introduce some object that contains all map data, but that would be another object.

    My current plan is to use existing Map to represent the ViewModel. So, I will start fields like Viewport to Map.

    One scenario to take into account is to allow users to switch the map data while keeping the viewport the same. With the current setup it would be possible by assigning a new Map, which would not change the Viewport. This won't work if the Viewport is a member of the Map. An alternative is that user would replace the LayerCollection instead, but currently this has a private setter. Perhaps could be made public, but perhaps we could introduce a Data object.

  7. inforithmics commented on Oct 20, 2022

    @inforithmics
    Contributor

    I like the idea of having a Mapping Object Model (Map).
    To the topic of Viewport there are two parts. One is the Display part moving and zooming and the other is the Limiting part. So the limiting part belongs to the Map Configuration while the Currently Displayed part belongs to the Map Control. This is only a personal opinion I can life with other solutions too.
    Maybe there could be an initial position Configuration on the Map which the Viewport reads for initial Position.

  8. inforithmics commented on Oct 20, 2022

    @inforithmics
    Contributor

    I like the idea of having a Mapping Object Model (Map).
    To the topic of Viewport there are two parts. One is the Display part moving and zooming and the other is the Limiting part. So the limiting part belongs to the Map Configuration while the Currently Displayed part belongs to the Map Control. This is only a personal opinion I can life with other solutions too.
    Maybe there could be an initial position Configuration on the Map which the Viewport reads for initial Position.

    I thought about it. The Map is not really an Object Model because it has active parts like Providers and Layers. So my comments are not valid. So it makes sense to have the Vieport on the Map, because it influences the Loading of the Data.

  9. charlenni commented on Oct 24, 2022

    @charlenni
    Member

    For me, the separation looks a little bit different. There is a MapControl, which handles all platform related things, like graphics control and touch events. This control holds 3 different objects:

    1. The map data with the different layers
    2. The part of the map, that should be shown
    3. The renderer, which render the features, that are provided by the map data to the screen.

    The first would be our Map object. It doesn't need to know which part is shown. The MapControl only asks for data in a given range, and the Map object delivers it. Ideally, it could be used for more than one MapControl (if you want an overview and a detail map from the same data).

    The second is the Viewport (called Camera in other libraries), which decide about the part of the map data that is shown in the viewable area of the MapControl. It could be moved with a Navigator. This Navigator knows about limits and if it could zoom, pan or rotated the Viewport.

    Widgets are for me Overlay, layers, that are fixed to the MapControl (like center cross, scale bar or performance values), which so belong to the MapControl, not the Map. With this, you could create two MapControls, side by side, pointing to the same Map data, but different Viewports and different Widgets.

  10. pauldendulk commented on Oct 26, 2022

    @pauldendulk
    MemberAuthor

    To the topic of Viewport there are two parts. One is the Display part moving and zooming and the other is the Limiting part. So the limiting part belongs to the Map Configuration while the Currently Displayed part belongs to the Map Control.

    But limiting is strongly related to moving and zooming. Within our code we like to have a direct relation there. I think talking about 'belonging too' is too general. There are a lot of separate concerns we should take into account.

    Make it discoverable

    This makes it easier for the user to to find the functionality he/she is looking for. This is primarily important in the first phase of a project.

    Make it easy to use

    Where and when do users need some functionality? In MVVM most of the VM code will not deal with the MapControl. If you need to change something from the VM it should not be on the MapControl. Whether it 'belongs' to the MapControl for some general reason is not that interesting. What should be on the MapControl are the things that need to be setup in the view (a Maui ContentPage or ContentView). In the project I now work on there is very little that is actually needed in the view. Mostly things related to touch.

    Make it possible to use

    As charlenni mentions, users may want to reuse the map data in an overview map, but in that case they probably do not want to use the same widgets. This should be possible.

    Maintainability of Mapsui

    We want a modular design where the things that change together are gathered together. If components need to communicate a lot they need to be in the same module.

  11. pauldendulk commented on Oct 26, 2022

    @pauldendulk
    MemberAuthor

    For me, the separation looks a little bit different. There is a MapControl, which handles all platform related things, like graphics control and touch events. This control holds 3 different objects:

    1. The map data with the different layers
    2. The part of the map, that should be shown
    3. The renderer, which render the features, that are provided by the map data to the screen.

    The first would be our Map object. It doesn't need to know which part is shown. The MapControl only asks for data in a given range, and the Map object delivers it. Ideally, it could be used for more than one MapControl (if you want an overview and a detail map from the same data).

    I prefer to introduce a single class that can be seen as the view model of the MapControl. I think this is the best option from the 'ease of use' perspective. Users add a MapControl and then bind the object in their viewmodel, and after that primarily need to work with only that object. I think simply calling it 'Map' is the best option. Because of this all the naming becomes different. What you call the Map I would prefer to call the MapData or just Data (access would look like Map.Data.Layers). But then again, after looking into the fields that would be needed in Data, I so far came up only with one field for that Data class, which is the Layers. If this it it would be better to treat the Layers field itself as the map data.

    The second is the Viewport (called Camera in other libraries), which decide about the part of the map data that is shown in the viewable area of the MapControl. It could be moved with a Navigator. This Navigator knows about limits and if it could zoom, pan or rotated the Viewport.

    If the Navigator is used by the user, does the user still access the viewport? Should it perhaps be a private field? A general question wrt the organization is if we do it for code design or for the user.

    Widgets are for me Overlay, layers, that are fixed to the MapControl (like center cross, scale bar or performance values), which so belong to the MapControl, not the Map. With this, you could create two MapControls, side by side, pointing to the same Map data, but different Viewports and different Widgets.

    Yes, we do not want to tie the widgets to the map data. Users need to be able to use them separately. But if users want to change anything in the widgets they should be allowed to do that in the ViewModel. Separating widgets and data can be done by making the Layers settable (but I am not sure yet if that is the best solution).

  12. changed the title [-]Move thing out of MapControl to Map to allow Map [/-] [+]Move things out of MapControl to Map to allow MVVM[/+] on Feb 21, 2023
  13. changed the title [-]Move things out of MapControl to Map to allow MVVM[/-] [+]Move functionality from MapControl to Map to allow MVVM[/+] on Feb 22, 2023
  14. pauldendulk commented on Oct 15, 2023

    @pauldendulk
    MemberAuthor

    In 4.0 the idea that the Map property is used in the view and nothing else should be used. Binding was implemented for MAUI, but may need to be implemented for other platforms. Please open a new issue for additional requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions