放大/缩小图像映射后,Maphilight()停止正常工作

KuK*_*KeC 10 javascript jquery imagemap zoom maphilight

我有一个图像地图有300-400个多边形区域,在事件"onclick"上突出显示该区域并获取一些数据等...当页面加载时(我的图像有点大,3-5MB)所以我调整了这些图像地图的大小davidjbradshaw/image-map-resizer插件.当我开始实现高光方法时,一切工作正常,但在放大/缩小图像后,我的聚合线被搞砸了.如果我删除高亮显示选项并放大/缩小,我的多边形线会调整为适当的图像尺寸.

调整大小的JS代码(正常工作)

 $( document ).ready(function() {
    imageMapResize();
  });

  function ZoomIn () {
    $("img").animate({
      height: '+=200',
      width: '+=200'
    }, 1000, function() {
      imageMapResize();
    });    
  }

  function  ZoomOut () {
    $("img").animate({
      height: '-=200',
      width: '-=200'
    }, 1000, function() {
      imageMapResize();
    });
  }
Run Code Online (Sandbox Code Playgroud)

用于调整大小/突出显示(无法正常工作)的JS代码

$( document ).ready(function() {
    imageMapResize();
    $('img[usemap]').maphilight();
  });

  function ZoomIn () {
    $("img").animate({
      height: '+=200',
      width: '+=200'
    }, 1000, function() {
      imageMapResize();
      $('img[usemap]').maphilight();
    });
  }

  function  ZoomOut () {
    $("img").animate({
      height: '-=200',
      width: '-=200'
    }, 1000, function() {
      imageMapResize();
      $('img[usemap]').maphilight();
    });
  }
Run Code Online (Sandbox Code Playgroud)

没有放大/缩小imageresizer和高亮度工作完美.

初始图片

放大/缩小后

缺少多线的图像

我究竟做错了什么?

Sal*_* CJ 1

我究竟做错了什么?

没什么,因为我可以看到代码。

我认为问题在于插件本身,它显然jQuery.maphilight()不支持响应式缩放。

因此,您可能需要考虑使用jQuery.mapster().

工作示例

$( document ).ready(function() {
  $('img[usemap]').mapster({
    fill: true,
    fillColor: '000000',
    fillOpacity: 0.2,
    stroke: true,
    strokeColor: 'ff0000',
    strokeOpacity: 1,
    strokeWidth: 1,
    fade: true
  });
});

function ZoomIn() {
  $("img").animate({
    height: '+=200',
    width: '+=200'
  }, 1000, function() {
    $(this).mapster('resize', $(this).width(), $(this).height());
  });
}

function ZoomOut() {
  $("img").animate({
    height: '-=200',
    width: '-=200'
  }, 1000, function() {
    $(this).mapster('resize', $(this).width(), $(this).height());
  });
}
Run Code Online (Sandbox Code Playgroud)

演示: http: //jsfiddle.net/mt5pynn8/
演示:http://jsfiddle.net/mt5pynn8/1/

补充笔记

jQuery.mapster()不支持 jQuery 版本 3,其次,该插件上次更新是在 2013 年。(但它仍然工作得很好。)

更新

jQuery.mapster()具有调整大小功能;因此imageMapResize()没有必要。但请注意,正如我测试的那样,调整大小功能并不完美。既不imageMapResize()也不jQuery.mapster()