Coder Social home page Coder Social logo

Add MapBuilder about mapsui HOT 7 OPEN

pauldendulk avatar pauldendulk commented on May 29, 2024
Add MapBuilder

from mapsui.

Comments (7)

charlenni avatar charlenni commented on May 29, 2024 1

Yes, but if you want to add e.g. an OSM map, you need Mapsui.Tiling, which doesn't exist in Mapsui. Or you copy-paste all the code and have it twice. The same with other things, that don't exist in Mapsui.

from mapsui.

charlenni avatar charlenni commented on May 29, 2024

Sounds good, but where to store this? Mapsui isn't enough, Mapsui.Extensions too. So this should be a new library with its own NuGet.

from mapsui.

pauldendulk avatar pauldendulk commented on May 29, 2024

I was thinking of making this a class in the Mapsui project. It is basically a class and a number of extension methods.

from mapsui.

pauldendulk avatar pauldendulk commented on May 29, 2024

Good point, I did not properly think this through!

The MapBuilder itself should be in the Mapsui project.

Configuration of specific components

The methods to add specific components, like AddScaleBar(), are often extension methods of the builder. I had not decided if that would be necessary here, but this would solve the problem you mention. So, the AddOpenStreetMapLayer() extension should be in the Mapsui.Tiling/Extensions/MapBuilderExtensions.cs. And could look something like this:

public static MapBuilder AddOpenStreetMapLayer(this MapBuilder mapBuilder)
{
    var layer = OpenStreetMap.CreateTileLayer();
    // todo: Add the layer to the builder
    return mapBuilder;
}

So, the rule would be that the extension method is in the class that defines the component it configures.

I did not think at all about how the builder should hold the state of the added components. I would first need to look into how others do this nowadays.

Create methods

The MapProfile.NavigationApp that I mention above will not be an option because the enum should have all options, and that is not possible if those options are spread out over various projects. So, I guess they should be methods, like MapBuilder.CreateNavigationProfile(). They depend on multiple components. Perhaps they should be Mapsui.UI.Shared, which included in the UI projects and those have dependencies on Mapsui and Mapsui.Tiling. Not on Mapsui.Nts, but maybe they should.

from mapsui.

charlenni avatar charlenni commented on May 29, 2024

But the MapBuilder should not return a MapBuilder, but a Map. With that, the function from above looks like

public static Map CreateMap()
{
    return new Map();
}

public static Map AddOpenStreetMapLayer(this Map map)
{
    var layer = OpenStreetMap.CreateTileLayer();
    map.Layers.Add(layer);
    return map;
}

Then the next extension method could add something else to the Map. Would be then

var map = MapBuild.CreateMap()
            .AddOpenStreetMapLayer()
            .AddScaleBar(position);

from mapsui.

pauldendulk avatar pauldendulk commented on May 29, 2024

There are different options which I did not have completely clear. Now I think the best option would be to first configure the MapBuilder and when that is done create it. In that solution there should be a single mapBuilder.Create() method with no options. Or perhaps better a mapBuilder.Build() instead of Create(). The 'profiles' should be like configure methods. This is like the WebApplicationBuilder.Build() https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.webapplicationbuilder.build?view=aspnetcore-7.0

var map = mapBuilder.AddNavigationProfile()
      .AddOpenStreetMapLayer()
      .AddScaleBar(position).
      .Build();           

The best way is to look at how they do things and try to adopt their naming conventions.

The WebApplicationBuilder has a Services field.

builder.Services.AddRazorPages();

Perhaps our MapBuilder should have a Layers fields.

mapBuilder.Layers.AddOpenStreetMapLayer();

I have also seen Configure in their naming a lot.

from mapsui.

pauldendulk avatar pauldendulk commented on May 29, 2024

I updated the original post to my latest insights.

Also, we should see this as a proposal (I just added the design/roadmap label), we could also decide not to do it. If we need to add functions for all the functionality we have this may be too much. Perhaps the focus should be on the Configure methods, and we should create fluent Add and Set functions only for the most common cases. There should be general methods to allow adding just any widget or layer.

from mapsui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.