clickable Layer fields

7/14/2014 8:25:17 AM
Total Posts 28

clickable Layer fields

How to make different location name render through layer clickable.

7/15/2014 2:04:34 AM
MVP
Total Posts 323

Re: clickable Layer fields

Could you please provide more details.

7/15/2014 2:34:06 AM
Total Posts 28

Re: clickable Layer fields

we can use database layer..to show infowindow when mouse point goes to particular label.,as shown in InfoWindowForPoint samples.,can I do the same for shapeFiles layer added through tile layers method.

 

actually i have a shape file that display metro station name..,and i want when it mouse pointer goes to metro station name..,it display some information on infowindow

7/15/2014 3:15:16 AM
MVP
Total Posts 323

Re: clickable Layer fields

Labels are not map features, thereby you cannot identify them by clicking on them etc.
Layers added to a tilelayer cannot be accessed outside of the tilelayer because of thread safety (tile layers are shared objects).
You may open a layer and add tooltips:

void Page_PreRender(object sender, System.EventArgs e)
{
  AddTooltips();
}

void AddTooltips()
{

map.Hotspots.Clear();

Layer layer = Layer.Open(MapPath("MAPS/capitals.shp"));
if (layer == null) return;

Recordset records = layer.SearchShape(map.Extent, SearchMethod.Inside);

while (!records.EOF)
{

  map.Hotspots.Add(records.RecordExtent.Center, 9, records["CITY_NAME"].ToString(), records["ID"].ToString());

  records.MoveNext();
}

layer.Dispose();
}

If you want also to display info windows(Hotspots.AddInfo), do the same as in InfoWindowForPoint, but open the layer as shown above

void map_HotspotInfoClick(object sender, HotspotClickEventArgs e)
{

Layer layer = Layer.Open(MapPath("MAPS/capitals.shp"));
if (layer == null) return;

Recordset records = layer.SearchExpression("ID = " + e.Argument);

...

 

It is also possible to show an info window on click

void map_InfoTool(object sender, InfoToolEventArgs e)
{

Layer layer = Layer.Open(MapPath("MAPS/capitals.shp"));
if (layer == null) return;

Recordset rs = layer.SearchNearest(e.InfoPoint, map.ToMapDistance(9));
if (rs.EOF) return;

InfoWindow info = new InfoWindow(rs.RecordExtent.Center);
info.Content = rs["CITY_NAME"];
map.ShowInfoWindow(info);

}