Comments (7)
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.
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.
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.
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.
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.
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.
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)
- [Avalonia]: Hovered-event is not available yet HOT 5
- Mapsui.Wpf is incompatible with System.Drawing.Common 8.0.0 HOT 2
- Investigate support for native AOT HOT 1
- Make all sample code copy-paste-able
- Fail in GeoTiffSample unit test HOT 3
- Polygon Drag Not Refreshing Until Map Is Panned HOT 2
- Convert all our scripts to PowerShell
- Add LayerListWidget HOT 5
- Custom IViewportLimiter's Limit function is not called HOT 1
- MAUI Flyout Locks Map (regression) HOT 9
- Make the MapControl disposable and not the Map
- GeometryFeature disappears while panning HOT 9
- BitmapRegistry.Unregister() doesn't remove bitmap from lookup array HOT 3
- Callout not always on top HOT 6
- Drawing order different to map info order HOT 4
- More shared touch/mouse handling over all platforms HOT 7
- When touching and holding a long press, mapControl becomes blank HOT 6
- OSM MapControl does not work in Avalonia Browser when using .NET 8 HOT 8
- Regression tests crash on GeoTiff HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mapsui.