14

I'm developing an internal web app on our company intranet using PHP. One section of the app displays a couple of high resolution images to the user. These images are in the region of 5000x3500 pixels. Each image has an image map (using rectangular areas), and all works fine in the desktop browsers I've tried.

The problem I'm finding, is that when users access the site via their iOS devices, the images are being rescaled by safari on the device, however the image map coordinates are not being adjusted to match.

An example of the HTML being generated by my PHP is as follows:

<img src="largeimage.jpg" width="5000" height="3500" usemap="#examplemap">
<map name="examplemap">
  <area shape="rect" coords="0,0,5000,500" href="blah1"/>
  <area shape="rect" coords="0,500,2500,3500" href="blah2"/>
  <area shape="rect" coords="2500,500,5000,3500" href="blah3"/>
</map>

(The actual rectangle coordinates in the image map are calculated as a percentage of the image size).

I know that safari is resizing the image due to memory constraints on the device, but I need to either find a way of scaling the image map to suit, or replacing the image map with something else that will do the same job. Can anyone offer any advise?

Bryan
  • 3,224
  • 9
  • 41
  • 58
  • I'm actually experiencing the same thing. Is this a known bug you think? I don't know if it helps, but on the iPhone my maps work correctly when I hold it land-scape style. Trying to load the page portrait style breaks the maps. In either style, rotating to the opposite breaks it as well. – Will D. White Sep 07 '11 at 20:49
  • Started a bounty to get this. I have even tried width="100%" - I do not know what to do with it. – TheBlackBenzKid Mar 29 '12 at 08:36
  • Rescaling the image with php is an option? – whtlnv Mar 29 '12 at 08:40
  • Bit of a stab in the dark, but does adding to your help at all? – Nathan Gaskin Mar 29 '12 at 08:55
  • I tried this. I am sending an email out and iPhone IOS devices scale image maps - tried using webkit-text-size-adjust: none; amd a;sp the viewport but no luck. – TheBlackBenzKid Mar 29 '12 at 09:11
  • Also read this, http://stackoverflow.com/questions/2721843/trouble-with-image-maps-safari-and-gmail-for-html-email - but still no luck. – TheBlackBenzKid Mar 29 '12 at 09:15
  • I ended up resolving this problem by changing the way my web app worked, so didn't manage to find a solution. Maybe worth talking to Apple to fix the underlying bug in their browser? – Bryan Mar 29 '12 at 09:22
  • How can you submit a bug to them? – TheBlackBenzKid Mar 29 '12 at 11:44
  • @TheBlackBenzKid I'm not able to test any solution easily now, (due to me using a different approach). If any of the answers posted here work, let me know and I'll accept the answer. - I'm assuming you can't accept an answer even though you've added a bounty? – Bryan Mar 30 '12 at 14:21
  • 1
    @TheBlackBenzKid It's not a bug, but a [documented limitation](http://developer.apple.com/library/ios/#DOCUMENTATION/AppleApplications/Reference/SafariWebContent/CreatingContentforSafarioniPhone/CreatingContentforSafarioniPhone.html) in Mobile Safari. – steveax Apr 01 '12 at 17:39
  • is there a solution that works for non-rectangular image maps? – benedict_w Nov 12 '12 at 20:00
  • I'm seeing the same issues with chrome on Android devices. :( – SMBiggs Jun 29 '18 at 06:25

11 Answers11

6

This topic was solved here on stackoverflow: jquery-image-map-alternative

The best idea is to use absolutely positioned anchors (also as suggested by steveax) instead of imagemap.

Update

As this is an old question, you might consider using SVG maps these days. They are supported in all modern browsers, works responsively and are as easy to use as image maps. (thanks to user vladkras for reminder)

Community
  • 1
  • 1
Marakoss
  • 588
  • 1
  • 10
  • 24
  • Appreciate the link and comments to the article + repped. – TheBlackBenzKid Apr 03 '12 at 08:22
  • The article links to several sources. I think this combination is good as it depends on the client/scenario. I would also consider HTML5 canvas - map canvas cords around the image and have links on canvas elements. – TheBlackBenzKid Apr 03 '12 at 08:24
  • the best part of this link is unnoticed unvoted [answer](http://stackoverflow.com/a/26632053/1713660) with article about [SVG](http://thenewcode.com/696) – vladkras Oct 21 '15 at 19:14
5

Why don't you use Responsive Image Maps instead. This way you can still use poly maps for oddly shaped items.

http://mattstow.com/experiment/responsive-image-maps/rwd-image-maps.html

It's as easy as adding the script. And one line of javascript:

$('img[usemap]').rwdImageMaps();
tsdexter
  • 2,911
  • 4
  • 36
  • 59
  • This only works to resize your coordinates according to screen size. It doesn't make it work on touch devices. – Ty Bailey Sep 26 '13 at 18:48
  • It works really well for me. I'm in the same boat. I needed large desktop images with maps to scale the image maps along with the safari image scaling in mobile safari and mobile chrome. Added rwd and they work just fine. – tsdexter Oct 03 '13 at 16:09
  • This method was not working on chrome for iOS. It was working safari mobile and chrome for android. I ended up falling back on absolutely position anchor elements with percentage values for positioning and and size. – Shwaydogg Apr 30 '14 at 16:32
  • 2
    @Shwaydogg it may not have been working on chrome for iOS because you didn't set the "width" and "height" attributes of the img tag explicitly to the images native width/height and then use CSS to set the actual width/height you want. That was the issue for me. – tsdexter May 02 '14 at 02:00
2

Nathan's comment is correct. You need to fix the viewport to prevent scaling. Basically, either specify a fixed pixel width, or set the scale to 1.0 and set user-scalable=no

See this document for reference:

http://developer.apple.com/library/ios/#DOCUMENTATION/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html

An alternative to using the area tag is to use javascript with events x/y & bounds for your hit areas.

Alexander Holsgrove
  • 1,795
  • 3
  • 25
  • 54
  • I actually just created the PSD as a TABLE - made those cells link images and did it this way. Also adding display:block and border-collaspe to the table cells - rather than a map. I tried all of this but no luck. I would recommend this for future use for others: http://econsultancy.com/uk/blog/9443-mobile-email-best-practice-ask-the-experts – TheBlackBenzKid Mar 30 '12 at 15:02
  • FWIW this worked for me: `` (my page width is 1000px) – benedict_w Nov 12 '12 at 20:16
2

I ran into this limitation recently on a project where we needed to be able to zoom and this is what I did to solve it:

  • Split the image up into 4 quadrants

  • Placed the 4 images into divs with width and height set to 50% and position: absolute;

  • Absolutely positioned <a> elements within the quadrant's parent element using percentage values and a high z-index

Like this:

CSS

#map-frame { position: relative; }
.map {
    display: block;
    position: absolute;
    width: 5%;
    height: 3%;
    z-index: 99;
}
.q {
    position: absolute;
    width: 50%;
    height: 50%;
}
.q img {
    display: block;
    max-width: 100%;
}
.q1 {
    top: 0;
    left: 0;
}
.q2 {
    top: 0;
    right: 0;
}
.q3 {
    bottom: 0;
    left: 0;
}
.q4 {
    bottom: 0;
    right: 0;
}

HTML

<div id="map-frame">
    <a class="map" href="foo.html" style="top: 20%; left: 20%;">
    <a class="map" href="foo.html" style="top: 40%; left: 20%;">
    <a class="map" href="foo.html" style="top: 20%; left: 40%;">
    <a class="map" href="foo.html" style="top: 40%; left: 40%;">
    <div id="q1" class="q">
        <img alt="" src="q1.jpg" />
    </div>
    <div id="q2" class="q">
        <img alt="" src="q2.jpg" />
    </div>
    <div id="q3" class="q">
        <img alt="" src="q3.jpg" />
    </div>
    <div id="q4" class="q">
        <img alt="" src="q4.jpg" />
    </div>
</div>
steveax
  • 17,527
  • 6
  • 44
  • 59
1

Put all the content INSIDE A TABLE. Set to 100% width. The iphone doesnt seem to scale tables... I was struggling with this problem as i had my images just lose, or inside a div. none of the rect coords links were working. But when i put the whole lot inside a table... Well, just try it and see :)

Steve
  • 11
  • 1
0

I dig out this post because I've just found a solution to get image map working on iOS.

Put your map within an anchor and listen click/tap events on it, to check if the target element matches with a map's area.

HTML

<a id="areas" href="#">
    <img src="example.jpg" usemap="#mymap" width="1024" height="768">
    <map name="mymap">
        <area id="area1" shape="poly" coords="X1,Y1,X2,Y2...">
        <area id="area2" shape="poly" coords="X1,Y1,X2,Y2...">
        <area id="area3" shape="poly" coords="X1,Y1,X2,Y2...">
    </map>
</a>

JAVASCRIPT

$("#areas").on("click tap", function (evt) {
    evt.preventDefault();
    if (evt.target.tagName.toLowerCase() == "area") {
        console.log("Shape " + evt.target.id.replace("area", "") + " clicked!");
    }
});

Tested on iPad4 with mobile safari 6.0

Dabi
  • 11
  • 4
0

Do not use Default <img usemap="#map"> and <map name="map"> change it. Like <img usemap="#mapLink"> and <map name="mapLink">. It's working !!!

leolee10
  • 3
  • 3
0

Simply using a # in the usemap attribute appears to solve the problem on iPhone.

For example <img usemap="#mapLink"> and <map name="mapLink">

mike nelson
  • 21,218
  • 14
  • 66
  • 75
0

My solution was easy. I just assigned a height and width in the DIV's css to match the size of the image and everything worked fine. Original image size was 825 x 1068, so

    <div style= width: 825px; height: 1068px;">
    ...
    </div>

Hope it helps.

0

I solved this with only 1 line of code, no JavaScript. Only CSS, you need to use zoom property to scale your image and everything will work fine, just like this

img {
    zoom: 0.3;
}
Nadeem
  • 37
  • 2
-3
<img src="largeimage.jpg" width="5000" height="3500" usemap="#examplemap">
<map name="examplemap">
  <area shape="rect" coords="0,0,100%,10%" href="blah1"/>
  <area shape="rect" coords="0,10%,50%,70%" href="blah2"/>
  <area shape="rect" coords="50%,10%,100%,70%" href="blah3"/>
</map>

please try using percentage values inside coordinates

Bryan
  • 3,224
  • 9
  • 41
  • 58
J S Rodrigues
  • 471
  • 4
  • 8