image map not working on iOS devices, with large i

2019-02-16 08:12发布

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?

10条回答
看我几分像从前
2楼-- · 2019-02-16 08:49

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();
查看更多
家丑人穷心不美
3楼-- · 2019-02-16 08:55
<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

查看更多
在下西门庆
4楼-- · 2019-02-16 08:56

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)

查看更多
成全新的幸福
5楼-- · 2019-02-16 08:56

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

查看更多
爷的心禁止访问
6楼-- · 2019-02-16 09:00

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

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

查看更多
冷血范
7楼-- · 2019-02-16 09:03

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.

查看更多
登录 后发表回答