-
-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I render a tile from a .pbf or .osm file (OSM) ? #590
Comments
You didn‘t say, what you want to do with the data. Draw only the lines? Draw a rendered map? |
@charlenni: I know that this are only the lines (as i said: along the lines of this). |
OsmSharp.UI has been discontinued because building a rendering library for OSM data was a bit too much for the project to handle let alone maintain. I would be better fit for mapsui. Feel free to reuse anything you can still find there but I wouldn't recommend using it in anything but experiments. The current OsmSharp just focuses on processing and reading/writing OSM data. |
@xivk: So it has been discontinued in OsmSharp, but with no replacement ins Mapsui. |
Ok, than I understand you correct. You want to use vector offline maps and render them on the fly. Mapsui couldn‘t do this. It sounds easy, but it isn‘t. You need first a theme style, which determin, how things are rendered. This is the easy part. The difficult part is to render the labels. Perhaps you could use MBTiles for offline usage. They can contain tiles as PNG. You could download them from different sites. |
@xivk Do you have an idea what should be done to support this in Mapsui? Which libraries te use? |
@pauldendulk: In all C# rendering projects, I either see SkiaSharp or WPF. |
In OsmSharp.UI I built everything myself on top of whatever rendering capability was there on Android/iOS. I think when using SkiaSharp it is doable to get it fast enough. There is also the issue of data management, how to manage the offline map data, but I guess nowadays that can be solved with vector tiles. On top of that there is the styling language, a good idea could be to just reuse something that already exists, this has the added advantage that users can just reuse existing styles or use other tools to design the style. Building something like this can be a lot of work and then maintaining it is also very difficult. There are so many things to consider when rendering a base map from vector data. |
@ststeiger I assume, that Paul talks about libraries to draw vector map data, not a library to use for drawing. There Mapsui uses Skia, one of the fastes library, which could be used on many different platforms (Windows, Android, iOS, Mac and so on). @xivk I made such a thing for MapboxGL style files and Mapbox vector data (see here). I transfered them from the native vector data to Mapsui features with style from the MapboxGL style file. This features than are added to a normal layer. Got it up to 3 fps. Problem of MapboxGL style is, that the style could change with the zoom factor. Not only with integers, but with float zoom level too. So much time is wasted with getting the right style for the feature (checking for the filters with tags from feature). And I stopped, when I get to the labels. As I mentioned, this isn't an easy job. Now I do a redesign of this part. I think, the Mapsui feature approach isn't fast enough. So I use the SKPicture from Skia and create the tile recording the drawing commands. There are some advantages:
It should be designed in a way, that it could not only handle MapboxGL styles and Mapbox vector data, but others too, like Mapsforge and its style file format. For the labels there are some articles in literature. There is even a implementation in C#: MapSurfer.NET (see here), but it isn't open source. So, it should be possible to visualize vector map data in C#, but there isn't any library up to now. |
I remember in OsmSharp.UI that I calculated everything that had to with the styling once per 'feature' and the styling was not done every frame but only once when the data was loaded or zoom level changed and crossed a boundary where the style also changes. |
Also in OsmSharp.UI I was alone in working on most of this, mapsui seems to have a good core of contributors, perhaps it will be easier to maintain things. |
Yes, thats the correct way. But be carefull, sometimes one feature has different styles. So you have to add the feature twice or more, because the order, in which the features with special styles are drawn, is important.
No, I assume not. Most come and want a special function or want to mention, that their app don't work as expected. Than they want help. Even if they have full access to the complete source code. I assume, that this is the case in most small projects as OsmSharp or Mapsui. |
@xivk: For offline storage, either Firebird or SQLite. On the web, there is WebSQL or IndexedDB. |
Yes, I would like to know what you would use to read the .pbf or .osm. Translating that to Mapsui.Geometries with a default style might be relatively easy. Getting proper styles and good performance will be hard. |
@pauldendulk: OsmSharp and OsmSharp.IO.Binary are pretty much the only thing in C# for that. I don't think parsing CSS, and putting that style-info in a struct/class and using that during rendering would be that much of a problem. Microsoft's GDI renderer would certainly be an epic fail in the readability department when rotating fonts by x old-degrees. |
Translating OSM data into renderable data is non-trivial when doing for example country boundaries or coastlines but for most data using OsmSharp should be sufficient. OsmSharp.IO.Binary is a custom format The |
@ststeiger How do you need BruTile if you translate to vector? Store it as vector tiles? |
@xivk: Yes, I know - i understand some data is also scattered in shapefiles there for some reason that i don't know... @pauldendulk: Don't need BruTile for rendering/translating vector data. Just to read the MbTiles file format if you don't want to render vector data and instead use a pre-rendered tile. To get the right tile for lat/long or X/Y/Z. Never mind, I think I get the hint with vector tiles now. |
I am glad you found a solution. If we ever what to render sm.pbf's we should not render then directly to canvas but instead translate them to vectors and styling and render it in the regular way. There may be performance issues with a such a solution but we should fix those issues to make Mapsui more performant in general. |
@pauldendulk: |
Mapsui uses SkiaSharp which has itself support to render svg. However, it will still need to translate the svg to native skia features. So for performance we will probably keep a cached skia native feature, like SKPicture. |
I need to render the tiles of the OSM map for Switzerland for offline use on demand in IIS.
I'm using the pbf for monaco, because it's a lot smaller, for testing.
I figured simple code to do that with MapsUI looks appx. somthing along the lines of this
However, I cannot figure out how to load the contents of monaco-latest.osm.pbf into a MemoryProvider.
There is a sample that produces GeoJSON, and a sample that reads a pbf.
I get a NetTopologySuite.Features.FeatureCollection and I somehow need IEnumerable<Mapsui.Providers.IFeature> for the memory provider.
This is the test-code i have:
https://github.com/ststeiger/OsmTilePrerenderer/blob/master/OsmTilePrerenderer/Program.cs
The text was updated successfully, but these errors were encountered: