Mapsui: Please add support for Xamarin forms

Created on 29 Oct 2015  ·  47Comments  ·  Source: Mapsui/Mapsui

Please add a support for Xamarin forms.

enhancement

Most helpful comment

I made the last days a Xamarin.Forms package to use Mapsui, called Mapsui.Forms. It works and can used with Android, iOS and Uwp. Perhaps someone is interested.

You could find it on NuGet and on GitHub GitHub

All 47 comments

It has no priority but I will take a look if I run into it.

For anyone wanting to use MapsUI in Xamarin Forms it is easy enough to make a custom control with custom renderers, please see attached for a simple Forms & Android Native implementation. I will add WinPhone and iOS when I get to them.

MapsUIXamarinForms.txt
MapsUIAndroid.txt

Thanks a lot NickCZA. I have to work on other things first but this is definitely something I want to support properly at some point. In the mean time users may be able to use their own solutions based on your samples.

Pasted above code in comments to make it a little more accessible:

    public class MapsUI : View
    {
        private Map map;
        public Map Map
        {
            get { return map; }
        }
        public List<CustomPin> CustomPins { get; set; }

        public MapsUI()
        {
            map = new Map();
        }

        public void SetBaseLayer()
        {
            map.Layers.Add(new TileLayer(KnownTileSources.Create()) { Name = "OSM" });
            map.Viewport.RenderResolutionMultiplier = 2;
        }
    }
    public class MapsUIAndroid : ViewRenderer<Controls.MapsUI, Mapsui.UI.Android.MapControl>
    {
        Mapsui.UI.Android.MapControl mapControl;
        Controls.MapsUI formsMapControl;

        protected override void OnElementChanged(ElementChangedEventArgs<Controls.MapsUI> e)
        {
            base.OnElementChanged(e);

            if (formsMapControl == null && e.NewElement != null)
            {
                // Custom Forms control
                formsMapControl = e.NewElement as Controls.MapsUI;
            }

            if (mapControl == null)
            {
                // Native android implementation
                mapControl = new Mapsui.UI.Android.MapControl(Context, null);
                // Link to map object
                mapControl.Map = formsMapControl.Map;
                // Set native app
                SetNativeControl(mapControl);
            }
        }
    }

Attached is a working example project for MapsUI with Xamarin Forms. I have tested it on Android, iOS and WinPhone 8.1+ projects on real devices, and it works. You will need to restore nuget packages.

MapsUIFormsExample.zip

Fantastic! thanks a lot. Jus tried it on my Android. No time right now to integrate it yet. Thanks.

I used the suggestions of NickCZA to integrate Mapsui (btw. fantastic project) into Xamarin.Forms (see my Xamarin.Forms branch). Up to now it works for Android and iOS. The UWP part crashes and I don't know why. Perhaps someone, knowing UWP better, has an idea.

It is only a frame for further enhancements. There aren't any bindings or so. For testing, there are samples with XAML integration for this.

If you think it is ok, I could create a PR.

I have a question: do you think it is better to mimik the Xamarin.Forms.Map behavior or to create an independent implementation?

hi @charlenni, Thank you!

Unfortunately I have no time at all for Mapsui this week, so cant' look at your code. A few reactions.

I investigate the UWP crash next week.

I had not thought about mimicking the Xamarin.Forms.Map behavior. I have to take a closer look to make a decision about it. It sounds like a good idea, or at least a good starting point. Mapsui may need to be more generic since it should support alternative coordinate systems.

Does your solution wrap the platform specific MapControls? Because actually I was thinking about a new MapControl for Xamarin.Forms which uses the PCL version of SkiaSharp as a renderer. Perhaps more code from the MapControl should be moved to other shared components.

I had planned to start a new repository for the Xamarin.Forms project. It will have an MIT license and contributors should agree to share their copyright. This will allow changes to the copyright, like sharing it with the .NET foundation.

These plans slightly complicate this, but maybe I should move a bit quicker with all this.

I started by importing the base classes from Xamarin.Forms.Maps (Position, Distance, MapSpan) with their original namespace. I did this, because other libraries like the location plugin from James Montemagno use them too. And the name Point is used allready in Xamarin.Forms :(.

The solution uses the MapControls in the renderers for the different platforms, but there are no differences between the renderers up to now.

I don't have any problems with either LGPL nor MIT. Both are ok.

I've tried it, but it is still a nightmarish performance on my iPad 3(A1416).
It's like each moving of the map cost about 10 to 40+ seconds to refresh the view.
Waiting to get back my iPhone to test again :|

@YordanYanakiev: What is a nightmare? Mapsui with Xamarin.Forms or Mapsui with iPad 3?

yes, but some reason unknown the Forms implementation run very slow on iPad 3.

Is it the same for other Xamarin.Forms apps? Or only for Mapsui?

I created a specific issue for performance on iPad 3: https://github.com/pauldendulk/Mapsui/issues/133

@YordanYanakiev Is the performance problem with the Forms implementation? Did you test the Mapsui.Samples.iOS sample as is?

Back ( was in a move a bit .. :( Sorry. )
Well ... I got iPhone 6 - everything is smooth in there, just iPad 3 seems like making the issues.

@YordanYanakiev is the Mapsui.Samples.iOS sample app as slow as the Xamarin.Forms version?

Unfortunately any of the Form apps acting unreasonable slow in this iPad 3.
All of them anyway working perfect on iPhone 6.
( got none other Apple devices to test with currently ).

the PCL one just a bit faster. but that's all. seems like iPad 3 is the issue.

@yordanyanakiev You mention all forms apps. My question was if the non-forms Mapsui.Samles.iOS app that is part of the main fork also has the problem.

well. It is slow. faster than the forms implementation, but still slow.
But spend not much time on this now. I am as well trying to find an
explanation, and will report if find something.

On Tue, Mar 14, 2017 at 3:43 PM, Paul den Dulk notifications@github.com
wrote:

@yordanyanakiev https://github.com/yordanyanakiev You mention all
forms apps. My question was if the non-forms Mapsui.Samles.iOS app that
is part of the main fork also has the problem.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/pauldendulk/Mapsui/issues/59#issuecomment-286424625,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGO0N5dXFFKaR7kKwNWHNhR0I2StDJX0ks5rlpmDgaJpZM4GYWB6
.

--
Yordan Yanakiev
design & software architectures

Should we create an extra Nuget package for this? Perhaps this is much better than integrate Xamarin.Forms implementation into Mapsui. If yes, where should this package be stored on GitHub?

I have this plan to gradually migrate everything to an MIT license. Not everything in Mapsui is my own code so I have to replace the parts that can not be changed to MIT. Most of the frontend is new so could easily be moved. I was thinking to move that first. Maybe this forms implementation should be the first step. I created a repository for it this part:
https://github.com/Mapogee/Mapogee
So we should work towards a Mapogee.Forms package.

Ups, do you think it is good to start another project?

Where are the problems with the license?

I made a new project for the Mapsui wrapper for Xamarin.Forms. It is at https://github.com/charlenni/Mapsui.Forms. At the end, it should be a separat NuGet packages. I think, that is the best. And if you change the project name and license, this project could follow.

I get one small problem: each time, I build the NuGet package, I get an error.

.\Mapsui.Forms\Mapsui.Forms.sln.metaproj : error MSB4126: Die angegebene Projektmappenkonfiguration "Release|AnyCPU" ist ungültig...

I copied your scripts and project files and changed them.

Do you have any idea, what's getting wrong?

To cleanup the sln and csprojs i renamed some of the build configuration names. One of the rename was "Release|Any CPU" to "Release|AnyCPU" perhaps it is related to that.

About the license. LGPL is a more restricted license. That makes it less popular. Also, I personally prefer a more permissive license.

Another thing is that at some point I would like to join the .NET foundation:
https://dotnetfoundation.org/

This is the checklist:
https://github.com/dotnet/home/blob/master/guidance/new-projects.md

One point is that all contributors needs to sign the contribution license agreement. I have not done this so far. In a new repository I can add this from the start.

Ah, you are right. It was a problem with "AnyCPU" instead of "Any CPU".

Thank you. Now the NuGet compilation works :). But my normal compilation not :(. But it seems the same reason.

maybe only change it in the nuspec.

@pauldendulk You mentioned at #144 the project XamarinForms from @tebben (which is a very good idea) and said, that it is "noticeably slower on Android". I don't understand this. It uses the same Skia renderer as the native controls. So where does the speed reduction come from? Is it while drawing the map? Or while zooming? Or while moving around? It would be nice, if you could explain your problems a little bit better.

As you see, the interesst in a map control for Xamarin.Forms is huge. Many programmers are looking for a map control, which doesn't use Google Play and work the same way on iOS, Android and UWP.

PS: I thought, answering on this thread is better :)

Well I don't know why it is slower. I just noticed that that sample is slower than Mapsui.Samples.Android. It could be:

  1. Some difference in how the Skia renderer works for Xamarin.Forms.
  2. Slower touch manipulation. I think this is the most likely. You can not access the native touch points and need to use the gestures. In the past I often had problems with gestures on various platforms. I have seen touch take a lot of resource, often more than screen wide graphics, which is quite surprising.
  3. Something else in the logic of the Xamarin.Forms controls. Could be too much event handling or something like that.

I agree that a Xamarin.Forms could have a big impact. The exact same rendering on all platforms, no hassle with api keys you need to register. I would be a big improvement. My highest priority right now is to fix all the bugs that are mentioned (none open at the moment) and release 1.0. That could be real soon.

@tebben The XamarinForms compiles only in Debug (deploy and run) BUT not in Release (Win10M, ARM), any suggestion?

@pauldendulk I think it's a good idea to migrate and professionalize the project 👍 with Mapogee

You are going to keep mapsui around for now right? Because I'm referring some people here... :-)

Yes, Mapsui 1.0 will stay here and will be supported.

@pauldendulk The @tebben XmarinForms branch is 27 commits ahead, 67 commits behind pauldendulk:master. Is it a good idea combine so we get the best of both Worlds [branch and mater]?

@JimSEOW It will at some point. One step at time.

I want to bring up this again. Perhaps you have now time to look into this.

Perhaps @Sebastian1989101 has a good and working implementation forXamarin.Forms and could publish this?

@charlenni Just take a look at my OpenGeoDB repository. There is an full implementation for Forms with custom renderers. It work's pretty well but it would need a few more adjustments to make it an own library. Currently it is an implementation per App.

https://github.com/Sebastian1989101/OpenGeoDB-App

Ah, I see. You made an easy integration like I.

I looked at the project from tebben, and saw, that he used gestures in his code. I thought, all this would be handled by the native MapsUI implementations. Isn't this correct?

@charlenni In my case everything is handled by the native Mapsui Control. My Control is just a wrapper for the PCL/Shared project.

Thank you @Sebastian1989101.

The question is then, if we need to mimic the Xamarin.Forms.Maps component or if we handle all things in the way Mapsui handle them (by access to native map)? Or if we adapt another Xamarin.Forms library like Xamarin.Forms.GoogleMaps? Any suggestions?

I made the last days a Xamarin.Forms package to use Mapsui, called Mapsui.Forms. It works and can used with Android, iOS and Uwp. Perhaps someone is interested.

You could find it on NuGet and on GitHub GitHub

@charlenni Great initiative! There are so many requests for a Xamarin.Forms solution.

I do expect that at some point Mapsui will itself have a Xamarin.Forms MapControl though. Probably one that is not a wrapper around the native controls but a direct implementation. I did a test with this last year. It used the SkiaSharp.Forms classes. Once we have more code re-use of the MapControl this will be fairly easy to build.

@pauldendulk I thought about your suggestion to implement a native MapControl for Xamarin.Forms. I tried this today. You could find the result at Github. The implementation has gesture recognizers for single, long single, double and multiple tap. Pinch and pan works too.I tested it only on Android. Have to to this on iOS too.

Was that, what you had in mind?

@pauldendulk Regarding the new MapControl for Forms. If we want to have this, than you should add it to your NuGet package, because MapControl.Forms uses the shared MapControl code. For this, it should be handled as all other MapControls. And you create the other NuGet packages, so it would be the best, if you do the same for MapControl.Forms. Do you think, this is possible?

It probably should be an additional package, released with the main ones and versioned identically. I.e there'd be a new package called Mapsui.Forms which would inherit Mapsui and be available on ios/droid and UWP. This would be a great improvement. I'll try to spend some time on the shared library initiative and do a pull request sometime this week which you could implement with your Xamarin.Forms version if you'd like to standardise.

Sure, an additional package. But the question is, if this package is hosted with Mapsui or outside.

Btw. Mapsui.Forms (PCL) has no dependencies, so it should be working on all platforms that are supported by SkiaSharp.Views.Forms ;)

Well not entirely, as Mapsui.Forms inherits Mapsui right? So there could be version mismatches that could cause issues to some users of different versions of SkiaSharp.Views but so long as users keep up to date it should be fine. This is however a common issue with Mapsui itself.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YordanYanakiev picture YordanYanakiev  ·  6Comments

ricardoboss picture ricardoboss  ·  5Comments

lukaszpitulski picture lukaszpitulski  ·  3Comments

TarasParashchuk picture TarasParashchuk  ·  4Comments

charlenni picture charlenni  ·  3Comments