This project has moved. For the latest updates, please go here.

How to link or combine into group a few MapItems

Apr 8, 2016 at 6:20 PM
Hi! My map shows the satellites and their tracks, When I translate the map horizontally, the MapItem of satellite "jumps"separately from the MapPolyline of sattellite track. How to link or combine into group MapItem and MapPolyline, that they move only together?
Thanx!
Coordinator
Apr 8, 2016 at 6:24 PM
No idea what "jumps" separately" means. The MapItem is at a Location that is also an endpoint of the MapPolyline?

Without seeing the relevant parts of your code nobody can tell.
Apr 9, 2016 at 8:47 AM
I captured video to explain my problem, please see. I need that MapItem(satellite) and MapPolyline(track) move together.
Thanks!
Coordinator
Apr 9, 2016 at 9:22 AM
Please post some code (as less as possible) that reproduces this behaviour.
Apr 9, 2016 at 10:17 AM
It's minimum:
<mapControl:Map>
                                <mapControl:MapPolyline Locations="-34.89005,77.27437 -39.84821,76.72670 -44.36630,77.16023 -48.29238,78.77132 -51.43911,81.68127 
                                                        -53.60033,85.82256 -54.59426,90.82731 -54.32471,96.03874 -52.82268,100.72050 -50.23274,104.33077 -46.75639,106.64537 
                                                        -42.59585,107.69722 -37.92348,107.65253 -32.87442,106.71608 -27.55085,105.08301 -22.02944,102.92228 -16.36859,100.37545 
                                                        -10.61406,97.56135 -4.80339,94.58224 1.03071,91.53000 6.85771,88.49181 12.64668,85.55570 18.36386,82.81604 23.96973,80.37935 
                                                        29.41540,78.37049 34.63787,76.93841 39.55398,76.25943 44.05304,76.53222 47.99001,77.95315 51.18398,80.65493 53.43170,84.59986 
                                                        54.54626,89.46546 54.41630,94.63377 53.05204,99.37330 50.58033,103.11192 47.19325,105.58455 43.09108,106.79395 
                                                        38.44838,106.89134 33.40395,106.07712 28.06370,104.54745 22.50779,102.47434 16.79763,100.00285 10.98178,97.25511 
                                                        5.10037,94.33642 -0.81140,91.34140 -6.72044,88.35994 -12.59324,85.48283 -18.39323,82.80753 -24.07782,80.44421 
                                                        -29.59462,78.52206 -34.87651,77.19526 -39.83532,76.64577 -44.35436,77.07693 -48.28176,78.68511 -51.43028,81.59182 
                                                        -53.59381,85.73008 -54.59047,90.73282 -54.32385,95.94388 -52.82462,100.62693 -50.23714,104.23963 -46.76281,106.55707 
                                                        -42.60386,107.61166 -37.93273,107.56941 -32.88463,106.63500 -27.56180,105.00360 -22.04098,102.84421 -16.38058,100.29845 
                                                        -10.62642,97.48517 -4.81604,94.50668 1.01784,91.45486 6.84467,88.41691 12.63353,85.48085 18.35067,82.74102 23.95657,80.30392 
                                                        29.40236,78.29433 34.62510,76.86116 39.54164,76.18061 44.04138,76.45129 47.97937,77.86953 51.17480,80.56820 53.42448,84.51002 
                                                        54.54146,89.37324 54.41419,94.54061 53.05261,99.28082 50.58334,103.02134 47.19833,105.49645 43.09783,106.70840 
                                                        38.45646,106.80812 33.41308,105.99591 28.07367,104.46792 22.51842,102.39620 16.80880,99.92582 10.99337,97.17898 
                                                        5.11230,94.26098 -0.79920,91.26648 -6.70804,88.28535 -12.58070,85.40840 -18.38062,82.73305 -24.06522,80.36944 -29.58211,78.44673"
                                                        Stroke="MediumVioletRed" StrokeThickness="3"/>
                                <mapControl:MapItem mapControl:MapPanel.Location="39.55398,76.25943" VerticalAlignment="Center" HorizontalAlignment="Center">
                                    <mapControl:MapItem.Template>
                                        <ControlTemplate>
                                            <Ellipse Stroke="DarkGreen" StrokeThickness="3" Fill="#99006400" Width="16" Height="16"/>
                                        </ControlTemplate>
                                    </mapControl:MapItem.Template>
                                </mapControl:MapItem>
                            </mapControl:Map>
Thanks!
Coordinator
Apr 9, 2016 at 11:36 AM
Edited Apr 9, 2016 at 6:58 PM
As a quick workaround, go to line 136 in MapPanel.cs and replace the lines
var mapPosition = parentMap.MapTransform.Transform(location, parentMap.Center.Longitude); // nearest to center longitude
viewportPosition = parentMap.ViewportTransform.Transform(mapPosition);
with
viewportPosition = parentMap.LocationToViewportPoint(location);
I'll try to fix this with the next release.
Apr 9, 2016 at 12:07 PM
Oh! This is what I wanted to!
There is small question, I'll create a separate discussion.

Thank you very much!
Best regards, baraban11
Coordinator
Apr 19, 2016 at 7:12 PM
Edited Apr 19, 2016 at 7:12 PM
Please take a look at the current version 2.9.0. You are now able to set the MapPanel.Location attached property also on MapPath-derived elements like MapPolyline to make them move to a viewport position with minimum distance to the map center. They will therefore "jump" in the same way as other elements where `MapPanel.Location is set.
<mapControl:MapPolyline ...
    Locations="..."
    mapControl:MapPanel.Location="39.55398,76.25943" />
Jun 1, 2016 at 2:31 PM
ClemensF wrote:
Please take a look at the current version 2.9.0. You are now able to set the MapPanel.Location attached property also on MapPath-derived elements like MapPolyline to make them move to a viewport position with minimum distance to the map center. They will therefore "jump" in the same way as other elements where `MapPanel.Location is set.
<mapControl:MapPolyline ...
    Locations="..."
    mapControl:MapPanel.Location="39.55398,76.25943" />
Hi!
And what about the previous solution (replace the lines in MapPanel.cs)? This new feature in version 2.9.0 solves the problem of "jump"? How to combine multiple items (MapItem, PushPin, mapPolyline) into a group like this: Image
Thank you very much!
Best regards, baraban11
Coordinator
Jun 4, 2016 at 7:47 AM
Please try the newest MapControl version 2.10.0. It has a slightly improved strategy for positioning map items, where an item is only placed nearest to the map center when the default position is outside the currently visible viewport.

My test code:
for (double lon = -180; lon < 180; lon += 10)
{
    var pushpin = new Pushpin { Content = lon };
    MapPanel.SetLocation(pushpin, new Location(50, lon));
    map.Children.Add(pushpin);

    var path = new MapPath
    {
        Data = new EllipseGeometry(new Point(lon, 60), 10, 10),
        Stroke = Brushes.Black
    };
    MapPanel.SetLocation(path, new Location(50, lon));
    map.Children.Add(path);
}
Coordinator
Aug 8, 2016 at 8:33 PM
MapPath now has an own Location property for adjusting the viewport position. It replaces the behaviour that was previously achieved by setting MapPanel.Location.
Sep 7, 2016 at 5:09 PM
Thanx for answer!
Your code work perfect! But my code don't work.
My simplified test code:
var panel = new MapPanel();
            var mpl = new List<MapPolyline>();
            var ppl = new List<Pushpin>();
            for (double i = 10; i < 80; i += 10)
            {
                var line = new MapPolyline
                {
                    Stroke = Brushes.Black,
                    Locations = new [] { new Location(i, -i * 2), new Location(i, i * 2), new Location(-i, i * 2), new Location(-i, -i * 2) },
                    IsClosed = true
                };
                mpl.Add(line);
                var pushpin = new Pushpin { Content = i };
                MapPanel.SetLocation(pushpin, new Location(0, -i * 2));
                ppl.Add(pushpin);
            }
            foreach (var mp in mpl)
            {
                panel.Children.Add(mp);
            }
            foreach (var pp in ppl)
            {
                panel.Children.Add(pp);
            }
            map.Children.Add(panel);
Coordinator
Sep 8, 2016 at 10:55 AM
Not sure what "my code don't work" means exactly. But you never set a MapPolyline's Location property.
Sep 8, 2016 at 1:28 PM
Sorry!
This my test:
for (double i = 10; i < 80; i += 10)
            {
                var line = new MapPolyline
                {
                    Stroke = Brushes.Black,
                    Locations = new[] { new Location(i, -i * 2), new Location(i, i * 2), new Location(-i, i * 2), new Location(-i, -i * 2) },
                    IsClosed = true
                };
                map.Children.Add(line);
                var pushpin = new Pushpin { Content = i };
                MapPanel.SetLocation(pushpin, new Location(0, -i * 2));
                map.Children.Add(pushpin);
            }
And my captured video. This behavior depends on zoom.
I want the MapPolyline's and Pushpin's moved simultaneously.

Thanx!
Coordinator
Sep 10, 2016 at 6:04 AM
Edited Sep 10, 2016 at 6:05 AM
This is getting a little ridiculous now. You still don't set the MapPolyline's Location property.

Something like:
var location = new Location(0, -i * 2);

var line = new MapPolyline
{
    Locations = ...,
    Location = location,
    Stroke = Brushes.Black,
    IsClosed = true
};

var pushpin = new Pushpin
{
    Location = location,
    Content = i
};

map.Children.Add(line);
map.Children.Add(pushpin);
Sep 12, 2016 at 4:00 PM
ClemensF wrote:
This is getting a little ridiculous now. You still don't set the MapPolyline's Location property.

Something like:
var location = new Location(0, -i * 2);

var line = new MapPolyline
{
    Locations = ...,
    Location = location,
    Stroke = Brushes.Black,
    IsClosed = true
};

var pushpin = new Pushpin
{
    Location = location,
    Content = i
};

map.Children.Add(line);
map.Children.Add(pushpin);
If set MapPolyline's Location property as in your example, then MapPolyline's change their behavior and do not move simultaneously.
I want that all items, and all Pushpin's, and all MapPolyline's has moved simultaneously. All Pushpin's and all MapPolyline's are like a one whole.

Thanx!