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

Within this forum we want to offer discussions all around our .NET based Map control including all .Net-language specific questions concerning calls of the xServer-API. Attention: xServer-relevant concepts can be found in further forums such as xRoute or xTour.
Post Reply
User avatar
webdirekt
Posts: 28
Joined: Wed Jul 15, 2015 10:18 am

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

Post 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 ?
User avatar
Bernd Welter
Site Admin
Posts: 2564
Joined: Mon Apr 14, 2014 10:28 am
Contact:

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

Post 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
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
User avatar
webdirekt
Posts: 28
Joined: Wed Jul 15, 2015 10:18 am

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

Post by webdirekt »

Hi Bernd, we can not use clustering in our scenario, is there any alternate solution ?
User avatar
Bernd Welter
Site Admin
Posts: 2564
Joined: Mon Apr 14, 2014 10:28 am
Contact:

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

Post by Bernd Welter »

Then we need the WIZZARD OF GUI!
I'll ask Oli for it ;-)
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
User avatar
Oliver Heilig
Posts: 154
Joined: Tue May 13, 2014 12:10 pm
Location: Karlsruhe, Germany
Contact:

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

Post 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
Oliver Heilig
Chief Developer Logistic Services
PTV GROUP - Germany

https://github.com/oliverheilig/
Post Reply