Page 1 of 1

How to add the large number of icons in map at once?

Posted: Tue Aug 22, 2017 8:57 am
by webdirekt
Code snippet :
---------------------------------------------------
// We are having shape layer in which we are going to add map icons
ShapeLayer _globalMapIconLayer = new ShapeLayer("IconLayer") { Caption = "IconLayer" };

// adding layer in map
wpfMapControl.Layers.Add(_globalMapIconLayer);

// We are adding map icon one by one using list i.e mapIconList
// each item in list contains geo-coordinates i.e X-coordinate and Y-coordinate
for(mapIconListIndex = 0 ; mapIconListIndex < mapIconList.Count ; mapIconListIndex ++)
{
// We are calling separate method to add each map icon in shape layer one by one
AddIcon(new Point(mapIconList[(mapIconListIndex].X, mapIconList[(mapIconListIndex].Y)
}

// method used to add map icon
public void AddIcon(Point point)
{
// We are creating map icons using the user control
// Icon is user control name
// 52 is width and 44 is height of icon
Icon icon = new Icon(52, 44);

// We are creating the map icon using the image of user control Icon
MapIcon mapIcon = new MapIcon(icon.GetImage())
{
ToolTip = new ToolTip()
{
Content = "Icon ToolTip",
Foreground = new SolidColorBrush(Colors.LightGray),
Background = new SolidColorBrush(Colors.Black),
}
};

// We are adding right click event handler to each map icon
mapIcon.MouseRightButtonDown += pin_MouseRightButtonDown;

// Add the shape to our shape layer
_globalMapIconLayer.Shapes.Add(mapIcon);

// We are setting location of map icon on shape canvas
ShapeCanvas.SetLocation(mapIcon, point);
ShapeCanvas.SetAnchor(mapIcon, LocationAnchor.Center);
}


In our application issue is that suppose we are having 20000 map icons in the list, it is very slow to add those number of icons one by one.

Is there any optimized way to add large number of icons in the map ?

Re: How to add the large number of icons in map at once?

Posted: Tue Aug 22, 2017 9:10 am
by Bernd Welter
Hello Chris, Paul,

how about this example from the Demo center? Usually an aggregation of 20.000 objects into various grouped icons is a valid approach.
XServer.NET Demo Center<br />Usecase Clustering (maps)
XServer.NET Demo Center
Usecase Clustering (maps)
Or would you really like to see 20.000 different objects on the same map?

Best regards,
Bernd

Re: How to add the large number of icons in map at once?

Posted: Tue Aug 22, 2017 9:50 am
by webdirekt
Hi Bernd, we can not use clustering in our scenario, is there any alternate solution ?

Re: How to add the large number of icons in map at once?

Posted: Tue Aug 22, 2017 10:05 am
by Bernd Welter
Then we need the WIZZARD OF GUI!
I'll ask Oli for it ;-)

Re: How to add the large number of icons in map at once?

Posted: Tue Aug 22, 2017 10:53 am
by Oliver Heilig
Generally that's a tough problem, and there's no simple answer for it. But you can classify the solutions bythese three categories:
  • Use POI-Clustering
    This handles the problem by reducing the total count of elements which have to be created. But this may be not appropriate for every use case.
  • Optimize the Shape-Layer Rendering
    See https://github.com/ptv-logistics/xserve ... erformance for examples how this affects the performance, especially for VDI (= virtual desktop infrastructure) environments.
  • Use a custom GDI Renderer
    This doesn't create individual wpf elements for every icon, but renders a single image for all icons, and overlays that on the map. We have a sample that uses SharpMap (https://sharpmap.codeplex.com/) for rendering the objects, see https://github.com/ptv-logistics/SharpMap.Widgets. A caveat is that you have to implement the hit-testing (e.g. for clicking) by yourself. A nice benefit is that this code can also be reused for web applications.
Oli