473,384 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,384 software developers and data experts.

Adding hotspots to ImageMap and detecting mouseclicks

Hi All,

I am very new to ASP.NET but have used c# for windows very much.

I would like to display an imagemap which has the background as the map
of a city centre and icons denoting important landmarks.
I would like to have some hotspots on these icons so when the user
clicks on them, I can show a little window with some information on it
about that site.

I have been able to create a imagemap with a map of a city centre and
drawn using GDI some icons.

I need to be able to create some hotspots around these icons.

Can someone please help me???

Here is the code I have so far

protected void Page_Load(object sender, EventArgs e)
{
Bitmap Bmp;
Graphics Gfx;
Font Fnt;

DoDatabaseInitialisation();

Rectangle boundingRect = new Rectangle(0, 0, 50, 50);
string filename;

//path to an image/* type of file
filename = (@"C:\Images\city_map.bmp");
Bmp = new Bitmap(filename);
Gfx = Graphics.FromImage(Bmp);

for (int i = 0; i < drawIconObjs.Count; i++)
{
DrawIconObject iconObj = (DrawIconObject)drawIconObjs[i];
iconObj.Draw(Gfx);
}

Bmp.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);
}

My icon draw method looks like this

public void Draw(Graphics g)
{
Font font = new Font("Verdana", 7, FontStyle.Bold);
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;

LinearGradientBrush myLinearGradientBrush = new
LinearGradientBrush(
boundingRect,
Color.AliceBlue,
Color.Silver,
LinearGradientMode.ForwardDiagonal);

g.FillRectangle(myLinearGradientBrush, boundingRect);

Rectangle rc = boundingRect;
rc.Inflate(-1, -1);

g.DrawRectangle(new Pen(SystemColors.Highlight), rc);

int rowHeight = rc.Height / 2;
int x1 = rc.X;
int y1 = rc.Y + 1;
int x2 = rc.Width;
int y2 = rc.Y + 1;

System.Drawing.Image img =
imgs.Images[ImageIndexFromStatus(cpObject.Status)];
g.DrawImage(img, x1, y1, img.Width, rowHeight - 1);

string sCount = cpObject.CurrentCount.ToString() + "/" +
cpObject.TotalSpaces.ToString();
int strWidth1 = (int)g.MeasureString(sCount, font).Width;
if (strWidth1 48)
boundingRect.Width = strWidth1 + 5;
else
boundingRect.Width = 50;

x1 = rc.X;
y1 = rc.Y + (rowHeight * 1) + 1;
x2 = rc.Width;
y2 = rc.Y + (rowHeight * 1) + 1;

g.DrawString(sCount, font, new SolidBrush(Color.Black), x1, y1);

g.DrawLine(Pens.Black, rc.X, rc.Y, cp.MapXPosition,
cp.MapYPosition);
}

Jul 22 '06 #1
1 2908
A few ideas ...

- My first technology choice here would be Adobe Flash, which excels at
pixel-precise compositing of multiple elements, asynchronous loading of
external data such as XML, and the kind of UI tricks you're going to want to
do.

- If you're determined not to go the route of Flash/Actionscript, a
server-bound graphics component will ease some of the pain of rendering the
dots in the places you want them. You could use a collection of coordinates
and an imagemap and some Javascript (e.g. the "overlib" script) to render
your popups.

Actionscript would make this all so much easier, since it would all be built
up on the client side from data. I would write an ImageDot Actionscript
class that encapsulated the data and behaviors required.

Good luck. If you do this all in .NET/GDI+, I'd love to see your finished
code as a learning thing.

-KF

"jediknight" <wa*****@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Hi All,

I am very new to ASP.NET but have used c# for windows very much.

I would like to display an imagemap which has the background as the map
of a city centre and icons denoting important landmarks.
I would like to have some hotspots on these icons so when the user
clicks on them, I can show a little window with some information on it
about that site.

I have been able to create a imagemap with a map of a city centre and
drawn using GDI some icons.

I need to be able to create some hotspots around these icons.

Can someone please help me???

Here is the code I have so far

protected void Page_Load(object sender, EventArgs e)
{
Bitmap Bmp;
Graphics Gfx;
Font Fnt;

DoDatabaseInitialisation();

Rectangle boundingRect = new Rectangle(0, 0, 50, 50);
string filename;

//path to an image/* type of file
filename = (@"C:\Images\city_map.bmp");
Bmp = new Bitmap(filename);
Gfx = Graphics.FromImage(Bmp);

for (int i = 0; i < drawIconObjs.Count; i++)
{
DrawIconObject iconObj = (DrawIconObject)drawIconObjs[i];
iconObj.Draw(Gfx);
}

Bmp.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);
}

My icon draw method looks like this

public void Draw(Graphics g)
{
Font font = new Font("Verdana", 7, FontStyle.Bold);
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;

LinearGradientBrush myLinearGradientBrush = new
LinearGradientBrush(
boundingRect,
Color.AliceBlue,
Color.Silver,
LinearGradientMode.ForwardDiagonal);

g.FillRectangle(myLinearGradientBrush, boundingRect);

Rectangle rc = boundingRect;
rc.Inflate(-1, -1);

g.DrawRectangle(new Pen(SystemColors.Highlight), rc);

int rowHeight = rc.Height / 2;
int x1 = rc.X;
int y1 = rc.Y + 1;
int x2 = rc.Width;
int y2 = rc.Y + 1;

System.Drawing.Image img =
imgs.Images[ImageIndexFromStatus(cpObject.Status)];
g.DrawImage(img, x1, y1, img.Width, rowHeight - 1);

string sCount = cpObject.CurrentCount.ToString() + "/" +
cpObject.TotalSpaces.ToString();
int strWidth1 = (int)g.MeasureString(sCount, font).Width;
if (strWidth1 48)
boundingRect.Width = strWidth1 + 5;
else
boundingRect.Width = 50;

x1 = rc.X;
y1 = rc.Y + (rowHeight * 1) + 1;
x2 = rc.Width;
y2 = rc.Y + (rowHeight * 1) + 1;

g.DrawString(sCount, font, new SolidBrush(Color.Black), x1, y1);

g.DrawLine(Pens.Black, rc.X, rc.Y, cp.MapXPosition,
cp.MapYPosition);
}

Jul 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lovely Angel | last post by:
Dear Friends Hope you all doing great. There is this thing which to me looks possible, but when I searched over the net I couldnt find anything. Any ideas about this please do let m eknow. I...
3
by: Holden Caulfield | last post by:
Does anyone know how to detect if a user has pasted code using the right mouse button into a textarea? I have fields in a form that autoupdate when text is changed in a textarea, but if it is...
0
by: theintrepidfox | last post by:
Dear Group Perhaps it's my ignorance but it seems that Framework 2 lacks of 'Add Range' for various objects. Any idea how I can assign a HotSpotCollection in one go to an ImageMap control? ...
1
by: Mad Scientist Jr | last post by:
I found some info on creating an imagemap in .NET at http://msconline.maconstate.edu/Tutorials/ASPNET2/ASPNET05/aspnet05-04.aspx but in VS.NET I don't see any ImageMap object under...
9
by: Nathan Sokalski | last post by:
I am using ASP.NET 2.0's ImageMap Control to create 2 imagemaps, one directly below the other. When I do this a thin blank space appears between them. After several days of frustration I realized...
1
by: Jeff | last post by:
ASP.NET 2.0 I've got problems with the Width of the ImageMap below. The problem is that the ImageMap's Width doesn't have any effect in my GridView, the width are determine by width of the...
1
by: BP | last post by:
Hi all! I want to generate hotspots in an ImageMap "programatically" (not using a graphical editor), ie I have a world map and a database containing city coordinates, and I'd like to create a...
0
by: Aaron Smith | last post by:
Does anyone know of a component where a end user can import a picture and then draw out hotspots on that image but then be able to save the sizes and locations of those hotspots relative to their...
3
by: corinne david | last post by:
I am developping a wesite. I am new at it. I usually program scientific program. I am using ImageMap and circleHotSpot. In the ContentPlaceHolder1 I have BigImageA In the ContentPlaceHolder2 I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.