VDS Technologies

 

Legends

7/9/2014 7:04:52 AM
Total Posts 28

Legends

How to add legends (their symbol + name) on map at particular position.?

7/9/2014 9:01:27 AM
MVP
Total Posts 323

Re: Legends

The Map.DrawString / Map.DrawPoint and other DrawX methods can be used to draw symbols/text on the map directly.

If you want to add the Legend control over the Map control, use the following code:

    protected void Page_PreRender(object sender, EventArgs e)
    {
        AspMap.Web.Legend legend = new AspMap.Web.Legend();

        // set legend properties
        legend.AutoSize = true;
        legend.Add("Legend:"); // title
        legend.LegendFont.Name = "Arial";
        legend.LegendFont.Size = 16;
        legend.LegendFont.Bold = true;

        // populate the legend from the map layers collection
        // see also the Legend.Populate method
        for (int i = 0; i < map.LayerCount; i++)
        {
            if (map.IsLayerVisible(i))
            {
                AspMap.Layer layer = map[i];
                legend.Add(layer.Name, layer.LayerType, layer.Symbol);
            }
        }

        legend.CssClass = "legend";
        map.Controls.Add(legend);
   }

Add the following style to the aspx file:

<style>
.legend
{ position:absolute;left:20px;top:20px;z-index:2000; }    
</style>

 

 

7/9/2014 9:09:11 AM
Total Posts 28

Re: Legends

but i don't have any layer for lagends. I want to add them like an external image on map.

7/9/2014 11:07:04 AM
MVP
Total Posts 323

Re: Legends

Please provide more details, it is unclear what you are trying to do.
Raster images can be added as layers via the Map.AddLayer method as described in the documentation.

7/10/2014 12:48:11 AM
Total Posts 28

Re: Legends

first,..thanx for response guys ..:)

actually I have a map that show live traffic similar to what Google map show. that is if traffic is moving fast it shows it with green color and if it is moving slow it shows it with black color. I just want  to provide this information through legends or by just  mapping an external image on it in which i display green color for fast and black for slow.

7/10/2014 3:08:21 AM
MVP
Total Posts 323

Re: Legends

Traffic usually is depicted by highlighting road segments which are vector lines, not images.

If you have coordinates of lines, you may add them dynamically to the Map.MapShapes collection as lines and assign them a color. See the CreateLine.aspx.cs sample.

If you need to highlight existing road segments, see 'Using FeatureRenderer (unique values)' in the AspMap Tutorial.
If you have feature IDs of road segments, you may highlight them as demonstrated in the RenderingByIDs.aspx.cs

7/11/2014 1:25:02 AM
Total Posts 28

Re: Legends

 actually I don't hv permission for external software .,that's why I doesn't able to see these samples.

plz just tell me,,hw to implement below function.., specially symbol..,bcz am able to display text..,but in place of symbol nothing display

public LegendItem Add(string text, LayerType type, Symbol symbol);

7/11/2014 4:06:40 AM
MVP
Total Posts 323

Re: Legends

Please send a screenshot or an image of what you are trying to do, to give an idea.


To draw text and symbols, use the Map.DrawString, Map.DrawPoint, DrawLine, DrawRectangle etc. methods.

symbol = new AspMap.Symbol();
symbol.PointStyle = PointStyle.Circle;
symbol.FillColor = Color.Green;
symbol.Size = 20;
map.DrawPoint(mapX, mapY, symbol);

font = new AspMap.Font();
font.Size = 12;
map.DrawString(mapX, mapY, "text", font);

 

The LegendItem Add is already implemented by the Legend control, a sample on how to add a Legend to a Map was provided above.

 

7/11/2014 4:29:59 AM
Total Posts 28

Re: Legends

bro.., am nt allowed to share 

plz just give me an example or implementation of this function

  public LegendItem Add(string text, LayerType type, Symbol symbol);

7/11/2014 4:55:08 AM
MVP
Total Posts 323

Re: Legends

Sorry, I do not have access to the implementation of this function.
I have been told that it uses Map.DrawPoint/DrawLine/DrawRectangle to draw icons of symbols and Map.DrawString to draw the text. So, you have all the necessary functionality to draw anything you need.
Set Map.DrawingUnits to pixels in you need to draw in non-cartesian (screen) coordinates.

7/11/2014 6:19:36 AM
Total Posts 28

Re: Legends

k...just tell me how to add image at specific position on map

7/11/2014 6:28:20 AM
MVP
Total Posts 323

Re: Legends

MarkerSymbol symbol = new MarkerSymbol("symbols/vehicle.gif", 20, 20, 10, 10);
AspMap.Point point = new AspMap.Point(2.35099, 48.85676); // longitude, latitude
Marker marker = new Marker(point, symbol, "Vehicle");
map.Markers.Add(marker);

or

symbol = new AspMap.Symbol();
symbol.PointStyle = PointStyle.Bitmap;
symbol.Bitmap = MapPath("symbols/vehicle.gif");
symbol.Size = 20;
map.DrawPoint(2.35099, 48.85676, symbol);

or

mapShape = map.MapShapes.Add(new AspMap.Point(2.35099, 48.85676), "text")
mapShape.Symbol.PointStyle = PointStyle.Bitmap;
mapShape.Symbol.Bitmap = MapPath("symbols/vehicle.gif");
mapShape.Symbol.Size = 20;

Hope this helps.
 

7/14/2014 12:42:58 AM
Total Posts 28

Re: Legends

Thanx bro..:)

nd sorry fr delay response