Map changes

AndrewMobileAndrewMobile USMember ✭✭✭✭
edited October 16 in Xamarin.Forms Evolution

1. Don't move Map by default to Rome

Current Map implementation moves map to Rome by default (albeit Rome, Italy is a cool city), but many times you want to move it to a different and specific position.
Which means the control will be updated twice instead of just once, wasting draw cycles.
Making the control not go to the default location requires some work and investigation which is completely unnecessary.
I don't understand the decision to have a default location.

2. Add 'animate' parameter to MoveToRegion(MapSpan mapSpan)

On all platforms the native map control has a way to animate when moving the map position. All current renderers in Xamarin Forms already use an animation value when moving the position on the native map.
The Xamarin.Forms.Map control should have the bool animate parameter in the MoveToRegion(MapSpan mapSpan):

void MoveToRegion(MapSpan mapSpan, bool animate = true)

0
0 votes

Open · Last Updated

Posts

  • seanydaseanyda GBMember ✭✭✭✭✭
    edited October 16

    +1 to this, I have implemented maps into a recent application and I find the loading time is a little slow and I'm looking into ways to speed it up.

    If a user is displaying the map, chances are they are wanting to show a specific region so would it not make sense to make a mandatory parameter to pass in the location you want the map to display? Just a suggestion

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    @seanyda Both can be a reason for a slower loading time. If someone from Xamarin team approves this, I could make a PR.

    There's also a bug I found with Map, MoveToRegion is buggy.

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    It doesn't make sense to start working on a PR without having OK from the XF team first, otherwise I risk working in vain.
    I hope Xamarin team really looks at this forum...

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    I wish this forum had a way to vote so people could give their votes ...

  • I am facing the same problem... Any fix for this ? i do not want to center my map in Rome !

  • seanydaseanyda GBMember ✭✭✭✭✭
    edited October 17

    @GeorgiosAnthopoulos said:
    I am facing the same problem... Any fix for this ? i do not want to center my map in Rome !

    You don't have to. There is a method to move it:

    Map test = new Map();
    test.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(37.797534, -122.401827), Distance.FromMiles(1)));
    

    Just replace the above latitude and longitude in the position parameter.

    This thread is discussing how to improve the maps.

  • ChaseFlorellChaseFlorell CAInsider, University mod

    note: you can also set the start-up map location in XAML if you need that

    <Map>
        <x:Arguments>
            <Position>
                <x:Arguments>
                    <x:Double>54.2</x:Double>
                    <x:Double>-114.2</x:Double>
                </x:Arguments>
            </Position>
            <x:Double>12</x:Double>
            <x:Double>12</x:Double>
        </x:Arguments>
    </Map>
    
  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    @ChaseFlorell Correct, but that is very very ugly. Why would I need to do that in any place, any project where I need a Map control?

  • ChaseFlorellChaseFlorell CAInsider, University mod

    @AndrewMobile said:
    @ChaseFlorell Correct, but that is very very ugly. Why would I need to do that in any place, any project where I need a Map control?

    because the Map Constructor is the only place to set a different "initial location". This makes it so that you don't have to use MoveToRegion after the map is constructed. If you don't do it in the constructor, then you have to move the map away from Rome.

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    @ChaseFlorell So you do not agree with not having the Map take a default location?
    99.999% of the Xamarin Forms apps which use the Map control will not want to have Rome, Italy as default location.
    Do you think it's nice to ask every developer to write that ugly XAML to initialize the map to something else?
    Another issue is you can't even bind the start position.

  • NMackayNMackay GBInsider, University ✭✭✭✭✭

    To get round it (as the geopos data is resfful and can be slow to come from our provider), I only create the map when the data arrives.

    Been able to set a default and bindable would be very nice.

  • ChaseFlorellChaseFlorell CAInsider, University mod

    @AndrewMobile said:
    @ChaseFlorell So you do not agree with not having the Map take a default location?
    99.999% of the Xamarin Forms apps which use the Map control will not want to have Rome, Italy as default location.
    Do you think it's nice to ask every developer to write that ugly XAML to initialize the map to something else?
    Another issue is you can't even bind the start position.

    I personally like the constructor, and even with the "ugly XAML", I feel it's a perfectly acceptable approach. Basically, if you need a start position on your map, that's what you use. If nothing else, I wish the VisibleRegion property were set to TwoWay binding instead of OneWayFromSource.

    As for having it Bindable, I've written my own Map Renderer, and have made the VisibleRegion work exactly like that. Under the covers, I use MoveToRegion(VisibleRegion); when the binding updates. This now allows the developer to update the VisibleRegion from the ViewModel, but also get the VisibleRegion back from the map if the user moves the map.

  • NMackayNMackay GBInsider, University ✭✭✭✭✭

    @ChaseFlorell said:

    @AndrewMobile said:
    @ChaseFlorell So you do not agree with not having the Map take a default location?
    99.999% of the Xamarin Forms apps which use the Map control will not want to have Rome, Italy as default location.
    Do you think it's nice to ask every developer to write that ugly XAML to initialize the map to something else?
    Another issue is you can't even bind the start position.

    I personally like the constructor, and even with the "ugly XAML", I feel it's a perfectly acceptable approach. Basically, if you need a start position on your map, that's what you use. If nothing else, I wish the VisibleRegion property were set to TwoWay binding instead of OneWayFromSource.

    As for having it Bindable, I've written my own Map Renderer, and have made the VisibleRegion work exactly like that. Under the covers, I use MoveToRegion(VisibleRegion); when the binding updates. This now allows the developer to update the VisibleRegion from the ViewModel, but also get the VisibleRegion back from the map if the user moves the map.

    We're pondering investing the time in doing something similar as we don't want to add more nugets but it should be bindable out of the box quite honestly. The map has had very little features added since Forms 1.3.

  • ChaseFlorellChaseFlorell CAInsider, University mod

    @NMackay said:
    We're pondering investing the time in doing something similar as we don't want to add more nugets but it should be bindable out of the box quite honestly. The map has had very little features added since Forms 1.3.

    It was pretty straight forward actually. I just made the VisibleRegion property new and changed it's binding to TwoWay`

    Then I detect which way the binding is coming from, blocking the infinite loop when you bind from the property.

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    @ChaseFlorell said:
    I personally like the constructor, and even with the "ugly XAML", I feel it's a perfectly acceptable approach. Basically, if you need a start position on your map, that's what you use. If nothing else, I wish the VisibleRegion property were set to TwoWay binding instead of OneWayFromSource.

    The native Map controls do not have a default position.
    And beside that, can you give me an example in the whole XAML platform where a control has such a "personal" default value? This isn't something like text color with the default to Black or background color.

    As for having it Bindable, I've written my own Map Renderer, and have made the VisibleRegion work exactly like that. Under the covers, I use MoveToRegion(VisibleRegion); when the binding updates. This now allows the developer to update the VisibleRegion from the ViewModel, but also get the VisibleRegion back from the map if the user moves the map.

    I wish there shouldn't be a need to write custom renders for such basic things.

  • ChaseFlorellChaseFlorell CAInsider, University mod

    @AndrewMobile said:
    The native Map controls do not have a default position.
    And beside that, can you give me an example in the whole XAML platform where a control has such a "personal" default value? This isn't something like text color with the default to Black or background color.

    In our scenario, our business services a specific region. So constructing the map with a specific location works well for us. We show the boundaries of our service area by default and move the map if necessary after the fact. (using the User's GPS location).

    If your service area is larger, then I suggest using that.. IE: if you service the entire USA, then use the entire USA as your starting point, and MoveToRegion(loc); from there. Similarly, if you service the entire planet, you can start with a top view of the entire planet and MoveToRegion(loc); from there.

  • ChaseFlorellChaseFlorell CAInsider, University mod

    At any rate, I think the conversation is off topic now. Let's leave it for the X.F team to decide.

    -1 from me.

  • seanydaseanyda GBMember ✭✭✭✭✭

    @AndrewMobile said:

    1. Don't move Map by default to Rome

    Current Map implementation moves map to Rome by default (albeit Rome, Italy is a cool city), but many times you want to move it to a different and specific position.
    Which means the control will be updated twice instead of just once, wasting draw cycles.
    Making the control not go to the default location requires some work and investigation which is completely unnecessary.
    I don't understand the decision to have a default location.

    @ChaseFlorell My understanding of this proposal is there is a very slim chance that you want the location of your map to be on Rome, so the chances are you will be passing in the location you want it to display... So the map has to do multiple draw cycles instead of a single one. What's the disadvantage of creating a mandatory parameter to make the user provide the location they want the map to display which will improve performance because it won't have to go to Rome then elsewhere every time?

    Or am I misunderstanding the proposal?

  • ChaseFlorellChaseFlorell CAInsider, University mod
    edited October 25

    @seanyda said:

    @AndrewMobile said:

    1. Don't move Map by default to Rome

    Current Map implementation moves map to Rome by default (albeit Rome, Italy is a cool city), but many times you want to move it to a different and specific position.
    Which means the control will be updated twice instead of just once, wasting draw cycles.
    Making the control not go to the default location requires some work and investigation which is completely unnecessary.
    I don't understand the decision to have a default location.

    @ChaseFlorell My understanding of this proposal is there is a very slim chance that you want the location of your map to be on Rome, so the chances are you will be passing in the location you want it to display... So the map has to do multiple draw cycles instead of a single one. What's the disadvantage of creating a mandatory parameter to make the user provide the location they want the map to display which will improve performance because it won't have to go to Rome then elsewhere every time?

    Or am I misunderstanding the proposal?

    The misunderstanding is that the map already has this. It's part of the constructor and you can set the initial load location to anywhere you want. The OP says that it's "ugly XAML", so if the proposal is to make it prettier, then maybe I misunderstood, but as it stands, #1 in the list already exists.

    There are two constructors for a map

    // https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Maps/Map.cs#L24
    public Map(MapSpan region)
    {
        LastMoveToRegion = region;
    
        VerticalOptions = HorizontalOptions = LayoutOptions.FillAndExpand;
    
        _pins.CollectionChanged += PinsOnCollectionChanged;
    }
    
    // center on Rome by default
    public Map() : this(new MapSpan(new Position(41.890202, 12.492049), 0.1, 0.1))
    {
    }
    

    If you don't want to center on Rome, you don't have to... you can center on anything you like.

  • AndrewMobileAndrewMobile USMember ✭✭✭✭
    edited October 26

    @seanyda said:

    Or am I misunderstanding the proposal?

    You got it right Sean. But Chase keeps arguing it's perfectly fine to have Rome, Italy (why Rome and not Tokyo or New York?) , so I surrender.

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    @ChaseFlorell said:
    At any rate, I think the conversation is off topic now. Let's leave it for the X.F team to decide.

    -1 from me.

    Should I hold my breath? :)

  • dapugdapug USMember ✭✭
    edited October 27

    Xamarin/MS should just invest in GoogleMaps https://github.com/amay077/Xamarin.Forms.GoogleMaps

    X.F Maps is woefully inadequate for even basic things like working with pins. For example, pins need an ID, otherwise I have no idea which pin is being used when tapped. Sure, the pins Clicked() event can be wired up, but now which pin was clicked, exactly? Even if I get the whole object from the sender, I have no idea which is which if I have a collection that came from a programmtic list with IDs. And where are other events on the map, such as pins being selected, camera moving, etc.?

    Digging in the forums, people have been asking for a simple pin ID property since at least 2013!

    Speaking of programmatic, I need to be able to select pins programmatically too. All this is already in amay077 GoogleMaps. HOWEVER, even that project suffers because UWP support is not par (and desperately needs to be).

    Mapbox for Xamarin is superior to all of this in terms of features, but with no UWP or macOS support at all, that is a dead, unusable map too IMO.

    Maps should also support macOS apps now that Mac can be targeted with X.F. X.F is all about all supported platforms, not a subset.

    All things considering, mapping of any kind on Xamarin Forms is leaving us all wanting more. Much more!

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    @dapug Instead of each of us doing islands of implementations, there should be pull-requests. But unfortunately Xamarin doesn't encourage participating, they look very late at PRs, so someone working on a PR could end up doing work in vain.

Sign In or Register to comment.