This is a migrated thread and some comments may be shown as answers.

LocationRect confusion

13 Answers 128 Views
Map
This is a migrated thread and some comments may be shown as answers.
Clint Singer
Top achievements
Rank 1
Clint Singer asked on 03 Mar 2010, 05:49 PM
Hi,

I am really having problems with the way that the LocationRect constructors.

The first one is:

public LocationRect(Location northEast, Location southWest);  
 

It seems very counter intuitive to go from TopRight to BottomLeft as we (at least I am) conditioned to work from TopLeft to BottomRight. 

The Microsoft LocationRect is fairly neat in that it lets you specify two diagnally opposite corners and then resolves the rectangle for you.  That style allows people to work in whatever system suits them.  Perhaps you could consider that as an option?

It would also be beneficial if there was a constructor that took the "north, west, south, east" as parameters instead of "north, west, width, height".

It would also be great to be able to create a LocationRect using a center location to define it along with its width and height.

Cheers,
Clint

13 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 04 Mar 2010, 09:08 AM
Hi Clint,

Thank you for the feedback.
We are planning to have this for the 2010.Q2.

Greetings,
Andrey Murzov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Tom
Top achievements
Rank 1
answered on 10 Jan 2014, 01:46 PM
Hi,

Bumped on this old topic after looking up more info about LocationRect. The reason I wanted more info was because in debug mode, in the watch-window in Visual Studio, I see strange results: Everey LocationRect I create like:

LocationRect r = new LocationRect(
new Location(1, 1), new Location(2, 2));
I see in the watch window as value for this instance:
{2; 1; NaN; NaN}

When passing a LocationRect to the SetView method of the RadMap, I sometimes get the view I expected, but sometimes the map zooms out to level 1 (or 0) and the whole world is visible. Like the Rect isn't recognized... Any idea how this comes? There are no errors thrown when creating Rect or setting the view...

Also, I nowhere see information about what corners are expected in the contructor. Are any 2 opposite corners ok? Or is it still required to pass northEast and soutWest corners? 

Regards,
Tom
0
Andrey
Telerik team
answered on 14 Jan 2014, 07:29 AM

Hi Tom,

You can use any 2 opposite corners in the constructor of the LocationRect structure.

It's expected result when the Width and Height properties are not calculated immediately after you create new LocationRect. You should specify the MapControl property for calculating of all properties of this structure.

LocationRect rect = new LocationRect(location1, location2);
rect.MapControl = this.radMap;

The zoom level could be set to level 1 by the SetView method when the width or height of LocationRect is zero.

Regards,
Andrey Murzov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.

Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.

Sign up for Free application insights >>
0
Tom
Top achievements
Rank 1
answered on 14 Jan 2014, 10:54 AM
Hi,

Thank you for the feedback. 

Strangly, when setting the MapControl property of the LocationRect, a zoomlevel of about -2000000 is calculated. This is obviously not good, I believe this is because my map (Actual)height and (Actual)width properties are not set yet?

I will take a look at it and see if I can attach a handler which sets the view once the map is loaded.

Regards,
Tom
0
Andrey
Telerik team
answered on 14 Jan 2014, 05:08 PM
Hi Tom,

It's hard to say without your code, but it looks like the RadMap has not been initialized at the moment when the LocationRect has been calculated.

This is why you can definitely try to handle the RadMap.InitializeCompleted event to avoid this problem.

Regards,
Andrey Murzov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.

Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.

Sign up for Free application insights >>
0
Tom
Top achievements
Rank 1
answered on 15 Jan 2014, 09:50 AM
Hello Andrey,

Setting the Mapcontrol property after the map has been initialized did indeed (almost) the trick! The zoomlevel stays at a decent level, and I get the view I expected.
However this is not always the case (with the same map on same page, with same objects on the map): I only get a normal zoomlevel when debugging the code. Here's my test code:

// initial set of the map center:
            map.map1.Center = Utilities.GetLocationRect(locations).Center;

            // trying to attach the map when it's loaded to get the propper zoomlevel 
            map.map1.InitializeCompleted += new EventHandler(delegate
            {
                var rect = Utilities.GetLocationRect(locations); // => first breakpoint
                rect.MapControl = map.map1;  
                map.map1.SetView(rect);  // => second breakpoint
            });

Utilities.GetLocationRect(locations) returns a LocationRect based on the List<Location> locations param.
map is the usercontrol I have a radMap in, map1 is the RadMap.

If I place breakpoints on the lines indicated (in the eventHandler delegate), I see some strange result on the zoomlevel: When navigating from breakpoint to breakpoint (pressing f5), the zoomlevel still changes from 1 to -2147483648.
If I slowly navigate from one line to another, The zoomlevel becomes 9. When running the code without breakpoints, the result is also a zoomlevel of -2147483648.
So it seems to me another thing needs to be loaded before I can attach the map to the rect, is that correct? How can I do this so the zoomlevel always gets calculated correctly?

See also screenshot to see the strange zoomlevel result.

Thank you,
Regards,
Tom
0
Tom
Top achievements
Rank 1
answered on 15 Jan 2014, 09:52 AM
forgot to attach the screesnhot, here it is
0
Andrey
Telerik team
answered on 15 Jan 2014, 03:52 PM

Hi Tom,

It is very complicated and it is hard to reproduce the issue without runnable solution. Could you, please, provide us with your solution or with a small sample solution which reproduces the reported behavior? By doing so we will be able to further investigate the reasons behind the issue.

Thank you for your cooperation.

Regards,
Andrey Murzov
Telerik

TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.

Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.

Sign up for Free application insights >>
0
Tom
Top achievements
Rank 1
answered on 15 Jan 2014, 04:32 PM
I have created a small project which reproduces the problem. It's only file (main.xaml), so I can post it here. Only now, the problem doesn't occur only in the previously mentioned cases. In this test project I've created, I Always get a zoomlevel of (about) -2000000000 using the same code I posted earlier:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Resources;
using Telerik.Windows.Controls.Map;
 
namespace TestRadMap
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
 
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
 
        private void MainPage_Loaded(Object sender, RoutedEventArgs e)
        {
            this.radMap.Provider = new BingMapProvider(MapMode.Road, true, "MY_BINGMAPS_KEY");
             
            InformationLayer layer = new InformationLayer();
            Random r = new Random();
            List<Location> locs = new List<Location>();
            for (int i = 0; i < 200; i++)
            {
                Pushpin pin = new Pushpin();
 
                // add several pushpins located near eachother (around Belgium here:)
                Location loc = new Location(r.NextDouble() + 51, r.NextDouble() + 3);
                locs.Add(loc);
                layer.Items.Add(pin);
                MapLayer.SetLocation(pin, loc);
            }
 
            radMap.Items.Add(layer);
 
 
            //map.map1.SetView(Utilities.GetLocationRect(c));
            radMap.Center = GetLocationRect(locs).Center;
 
            // trying to attach the map when it's loaded to get the propper zoomlevel
            radMap.InitializeCompleted += new EventHandler(delegate
            {
                var rect = GetLocationRect(locs);
                rect.MapControl = radMap;
                radMap.SetView(rect);
            });
 
        }
        internal LocationRect GetLocationRect(List<Location> locs)
        {
            double x1 = double.MaxValue;
            double x2 = 0;
            double y1 = double.MaxValue;
            double y2 = 0;
 
            foreach (Location loc in locs)
            {
                if (x1 > loc.Longitude)
                    x1 = loc.Longitude;
                if (x2 < loc.Longitude)
                    x2 = loc.Longitude;
                if (y1 > loc.Latitude)
                    y1 = loc.Latitude;
                if (y2 < loc.Latitude)
                    y2 = loc.Latitude;
            }
            LocationRect r = new LocationRect(
                new Location(y1, x1),
                new Location(y2, x2));
 
            //r.MapControl = m;
            return r;
        }
    }
}

xaml:
<UserControl x:Class="TestRadMap.MainPage"
    mc:Ignorable="d"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"            
    d:DesignHeight="300" d:DesignWidth="400">
 
    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadMap x:Name="radMap" UseSpringAnimations="True" />
             
    </Grid>
</UserControl>

0
Tina Stancheva
Telerik team
answered on 16 Jan 2014, 09:13 AM
Hi Tom,

At this point it would be best to open a separate support ticket and attach in it a sample project, which demonstrates the problem.  This would allow us to test your implementation locally and provide you with further assistance.

Regards,
Tina Stancheva
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.

Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.

Sign up for Free application insights >>
0
Tom
Top achievements
Rank 1
answered on 16 Jan 2014, 09:25 AM
Now you also have the possibility to take this locally and test it yourself? Could you do it like this?

Thank you,
Tom
0
Andrey
Telerik team
answered on 20 Jan 2014, 04:11 PM
Hello Tom,

You can invoke the SetView functionality via Dispatcher. In this case it will be invoked after the initial rendering is completed and the actual size of the map control is not zero.

The sample code is below.

radMap.InitializeCompleted += new EventHandler(delegate
{
    this.Dispatcher.BeginInvoke(new Action(() =>
    {
        var rect = GetLocationRect(locs);
        rect.MapControl = radMap;
        radMap.SetView(rect);
    }));
});

Please give it a try and let us know if it helps.

Regards,
Andrey Murzov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.

Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.

Sign up for Free application insights >>
0
Tom
Top achievements
Rank 1
answered on 22 Jan 2014, 08:39 AM
Hello Andrey,

I tried the code with the dispatcher, this works nicely!
Thank you for your time and great help.

Regards,
Tom
Tags
Map
Asked by
Clint Singer
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Tom
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or