简体   繁体   English

jqvmap RegionClick on iphone / ipad

[英]jqvmap RegionClick on iphone/ipad

There is an opensource vector maps for sites called jqvmap 有一个名为jqvmap的网站的开源矢量地图

The problem is that using ipad or iphone browser it handles clicks incorrectly. 问题是使用ipad或iphone浏览器它会错误地处理点击。 First touch causes onRegionOver event. 第一次触摸会导致onRegionOver事件。 Second touch causes onRegionClick event. 第二次触摸会导致onRegionClick事件。

How can we modify onRegionOver to make it work on ios as click? 我们如何修改onRegionOver以使其在ios上作为点击工作?

jQuery('#vmap').vectorMap(
{
    map: 'world_en',
    backgroundColor: '#a5bfdd',
    borderColor: '#818181',
    borderOpacity: 0.25,
    borderWidth: 1,
    color: '#f4f3f0',
    enableZoom: true,
    hoverColor: '#c9dfaf',
    hoverOpacity: null,
    normalizeFunction: 'linear',
    scaleColors: ['#b6d6ff', '#005ace'],
    selectedColor: '#c9dfaf',
    selectedRegion: null,
    showTooltip: true,
    onRegionClick: function(element, code, region)
    {
        var message = 'You clicked "'
            + region
            + '" which has the code: '
            + code.toUpperCase();

        alert(message);
    }
});

This is how I would go about it. 我就是这样做的。

First, start by creating a function that detects the type of device being used (Ipad, Iphone, Droid, etc). 首先,首先创建一个检测所用设备类型的功能(Ipad,Iphone,Droid等)。

function testDevice(){
    if(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
        return true;
    }else{
        return false;
    }
}

Next, setup both a regionClick & regionOver event. 接下来,设置regionClick和regionOver事件。

jQuery('#vmap').vectorMap(
{
    map: 'world_en',
    backgroundColor: '#a5bfdd',
    borderColor: '#818181',
    borderOpacity: 0.25,
    borderWidth: 1,
    color: '#f4f3f0',
    enableZoom: true,
    hoverColor: '#c9dfaf',
    hoverOpacity: null,
    normalizeFunction: 'linear',
    scaleColors: ['#b6d6ff', '#005ace'],
    selectedColor: '#c9dfaf',
    selectedRegion: null,
    showTooltip: true,
    onRegionClick: function(element, code, region)
    {
        if(!testDevice()){ //not mobile device
            var message = 'You clicked "'
            + region
            + '" which has the code: '
            + code.toUpperCase();

            alert(message);
        }
    },
    onRegionOver: function(element, code, region)
    {
        if(testDevice()){ //mobile device
            var message = 'You clicked "'
            + region
            + '" which has the code: '
            + code.toUpperCase();

            alert(message);
        }
    }
});

DEMO: DEMO:

http://jsfiddle.net/V79hw/5/ http://jsfiddle.net/V79hw/5/

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM