自动缩小JVECTormap中点击事件的区域



我有澳大利亚的JVECTormap。单击地图中的特定状态,它应在同一地图中缩小该特定状态。有没有任何方法可以在不使用多映射的情况下实现此目标。

是的,当然 - 您的意思是Zoom -In?使用地图对象的 setFocus 方法:

  onRegionClick: function(e,  code,  isSelected,  selectedRegions){
    $('#map').vectorMap('get','mapObject').setFocus({region: code});
  }

编辑:

SetFocus方法在此处记录:JVECTormap API文档 - MAP

这是setFocus的摘录(信用:jvectormap的伟大作者Kirill Lebedev):

  /**
   * setFocus set the map's viewport to the specific point and set zoom of the map 
      to the specific level. Point and zoom level could be defined 
      in two ways: using the code of some region to focus on or a central point
      and zoom level as numbers.
   * @param This method takes a configuration object as the single argument. 
     The options passed to it are the following:
   *   @param {Array} params.regions Array of region codes to zoom to.
   *   @param {String} params.region Region code to zoom to.
   *   @param {Number} params.scale Map scale to set.
   *   @param {Number} params.lat Latitude to set viewport to.
   *   @param {Number} params.lng Longitude to set viewport to.
   *   @param {Number} params.x Number from 0 to 1 specifying the horizontal 
        coordinate of the central point of the viewport.
   *   @param {Number} params.y Number from 0 to 1 specifying the vertical 
        coordinate of the central point of the viewport.
   *   @param {Boolean} params.animate Indicates whether or not to animate 
        the scale change and transition.
   */

某些选项是相互排斥的,例如,如果您提供纬度&经度,显然X&Y值(像素中的MAP坐标)将被忽略。此外:同样,如果您提供了区域代码的区域代码或 ,则Latitude&经度,x&y值,它们都将被忽略。

要获得动画效果,您应该将选项animate: true提供给参数对象。

示例:

$('#map').vectorMap('get','mapObject').setFocus({region: code, animate: true});

要获得一个良好而平滑的效果,您应该使用scale参数,这是因为用户可以放大地图,然后单击一个区域,然后,因此,将缩放效果放到该区域中不要像所需的那样引人注目。或其他任何东西,也取决于您最初的变焦级别。

因此,您可以研究用户界面,计划用户互动,并使用比例选项进行一些测试以获得所需的效果(对不起,我无能为力,因为您尚未提供任何源代码)。

从这里开始,并尝试获得最终所需的动画效果:

// Zoom in to the Eyers Rock:
var zParams = {scale: 5, lat: -25.360790, lng: 131.016800, x: 0.5, y: 0.5, animate: true};
$('#map').vectorMap('get','mapObject').setFocus(zParams);

我找到了FocusOn{scale-在构架选择方面做得很好。您可以按照此命令向前或向后走。

$(function(){
          // var $ = jQuery;
          $('#EUmap').vectorMap({
            map: 'europe_en',
            panOnDrag: true,
            focusOn: {
              x: 0.5,
              y: 0.5,
              scale: 1.5,
              animate: true
            },
            series: {
              regions: [{
                scale: ['#C8EEFF', '#0071A4'],
                normalizeFunction: 'polynomial',
                values: {
                  "BR": 2023.53,
                  "CZ": 195.23,
                  "DM": 0.38,
                  "FR": 2555.44,
                  "DE": 3305.9,
                  "GR": 305.01,
                  "HU": 132.28,
                  "IT": 2036.69
                }
              }]
            }
          });
        })
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jvectormap@2.0.4/jquery-jvectormap.min.css" type="text/css">
<html>
<head>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jvectormap@2.0.4/jquery-jvectormap.min.css" type="text/css">
  <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/jvectormap@2.0.4/jquery-jvectormap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jqvmap/1.5.1/maps/continents/jquery.vmap.europe.js"></script>
</head>
<body>
  <div id="EUmap" style="width: 600px; height: 400px"></div>
</body>
</html>

您可以在生成对象属性focusOn中使用值(country Code),示例:

focusOn: "UA",

最初的缩放工作,用于任何缩放方法setFocus

Zoom上的DOC:https://jvectormap.com/documentation/javascript-api/jvm-map/

最新更新