Reputation: 1
My simple application arranges weblinks on the image and depending on the type of image number of weblinks is different. I use ImageMap control and add in code behind hot spots. Coordinates and url are get from the data base. Below there is a code:
protected void ArrangeMapHotSpots(int voivodshipId)
{
PolygonHotSpot hotSpot = new PolygonHotSpot();
DataTable ImageMapDT = EzdrojeDB.ImageMapCoordinates(voivodshipId); // get data form DB
foreach (DataRow dr in ImageMapDT.Rows)
{
hotSpot.HotSpotMode = HotSpotMode.Navigate;
hotSpot.AlternateText = "alt_text";
hotSpot.Coordinates = dr["map_coord"].ToString();
hotSpot.NavigateUrl = "~/resort.aspx?id=" + dr["id"].ToString();
ImageMap1.HotSpots.Add(hotSpot);
}
}
The problem is when I run the app and I have only one link active (but there are 11 rows (links) in this particular DataTable object).
Below html code:
<img id="ContentPlaceHolder1_ImageMap1" src="Images/VoivodMaps/dolnoslaskie.png" usemap="#ImageMapContentPlaceHolder1_ImageMap1" />
<map name="ImageMapContentPlaceHolder1_ImageMap1" id="ImageMapContentPlaceHolder1_ImageMap1"/>
area shape="poly" coords="303,427,444,447" href="resort.aspx?id=11" title="alt_text" alt="alt_text" />
area shape="poly" coords="303,427,444,447" href="resort.aspx?id=11" title="alt_text" alt="alt_text" />
area shape="poly" coords="303,427,444,447" href="resort.aspx?id=11" title="alt_text" alt="alt_text" />
area shape="poly" coords="303,427,444,447" href="resort.aspx?id=11" title="alt_text" alt="alt_text" />
area shape="poly" coords="303,427,444,447" href="resort.aspx?id=11" title="alt_text" alt="alt_text" />
area shape="poly" coords="303,427,444,447" href="resort.aspx?id=11" title="alt_text" alt="alt_text" />
area shape="poly" coords="303,427,444,447" href="resort.aspx?id=11" title="alt_text" alt="alt_text" />
area shape="poly" coords="303,427,444,447" href="resort.aspx?id=11" title="alt_text" alt="alt_text" />
area shape="poly" coords="303,427,444,447" href="resort.aspx?id=11" title="alt_text" alt="alt_text" />
area shape="poly" coords="303,427,444,447" href="resort.aspx?id=11" title="alt_text" alt="alt_text" />
area shape="poly" coords="303,427,444,447" href="resort.aspx?id=11" title="alt_text" alt="alt_text" />
</map>
There have been 11 hot spots added but each of them has the same coordinates and id in url string. Can anyone explain me what has happend and how to add more than one hot spot to ImageMap programmatically.
Upvotes: 0
Views: 3479
Reputation: 4174
You're continually referencing the same PolygonHotSpot
object. You should be creating a new one for each iteration of your loop. i.e. try replacing your function with the following:
protected void ArrangeMapHotSpots(int voivodshipId)
{
PolygonHotSpot hotSpot;
DataTable ImageMapDT = EzdrojeDB.ImageMapCoordinates(voivodshipId); // get data form DB
foreach (DataRow dr in ImageMapDT.Rows)
{
hotSpot = new PolygonHotSpot();
hotSpot.HotSpotMode = HotSpotMode.Navigate;
hotSpot.AlternateText = "alt_text";
hotSpot.Coordinates = dr["map_coord"].ToString();
hotSpot.NavigateUrl = "~/resort.aspx?id=" + dr["id"].ToString();
ImageMap1.HotSpots.Add(hotSpot);
}
}
Upvotes: 2