How to add the large number of icons in map at once?
Posted: Tue Aug 22, 2017 8:57 am
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 ?
---------------------------------------------------
// 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 ?