Questions tagged [jqvmap]

JQVMap is a jQuery plugin that renders Vector Maps. It uses resizable Scalable Vector Graphics (SVG) for modern browsers like Firefox, Safari, Chrome, Opera and Internet Explorer 9. Legacy support for older versions of Internet Explorer 6-8 is provided via VML.

While initializing a map you can provide parameters to change its look and feel.

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);
    }
});

map - world_en Map you want to load. Must include the javascript file with the name of the map you want. Available maps with this library are world_en, usa_en, europe_en and germany_en

backgroundColor - #a5bfdd Background color of map container in any CSS compatible format.

borderColor - #818181 Border Color to use to outline map objects

borderOpacity - 0.5 Border Opacity to use to outline map objects ( use anything from 0-1, e.g. 0.5, defaults to 0.25 )

borderWidth - 3 Border Width to use to outline map objects ( defaults to 1 )

color - #f4f3f0 Color of map regions.

colors Colors of individual map regions. Keys of the colors objects are country codes according to ISO 3166-1 alpha-2 standard. Keys of colors must be in lower case.

enableZoom - boolean Whether to Enable Map Zoom ( true or false, defaults to true)

hoverColor - #c9dfaf Color of the region when mouse pointer is over it.

hoverOpacity - 0.5 Opacity of the region when mouse pointer is over it.

normalizeFunction - 'linear' This function can be used to improve results of visualizations for data with non-linear nature. Function gets raw value as the first parameter and should return value which will be used in calculations of color, with which particular region will be painted.

scaleColors - ['#b6d6ff', '#005ace'] This option defines colors, with which regions will be painted when you set option values. Array scaleColors can have more then two elements. Elements should be strings representing colors in RGB hex format.

selectedRegion - mo This is the Region that you are looking to have preselected (two letter ISO code, defaults to null )

Region Names & Codes

showTooltip - boolean Whether to show Tooltips on Mouseover ( true or false, defaults to true)

onLabelShow - function(element, label, code) Callback function which will be called before label is shown. Label DOM object and country code will be passed to the callback as arguments.

onRegionOver - function(element, code, region) Callback function which will be called when the mouse cursor enters the region path. Country code will be passed to the callback as argument.

onRegionOut - function(element, code, region) Callback function which will be called when the mouse cursor leaves the region path. Country code will be passed to the callback as argument.

onRegionClick - function(element, code, region) Callback function which will be called when the user clicks the region path. Country code will be passed to the callback as argument.

Dynamic Updating

Most of the options can be changed after initialization using the following code:

jQuery('#vmap').vectorMap('set', 'colors', {us: '#0000ff'});

Instead of colors can be used any parameter except callbacks. Callbacks can be added and deleted using standard jQuery patterns of working with events.

You can define callback function when you initialize JQVMap:

jQuery('#vmap').vectorMap(
{
    onLabelShow: function(event, label, code)
    {

    },
    onRegionOver: function(event, code, region)
    {

    },
    onRegionOut: function(event, code, region)
    {

    },
    onRegionClick: function(event, code, region)
    {

    }
});

Or later using standard jQuery mechanism:

jQuery('#vmap').bind('labelShow.jqvmap', 
    function(event, label, code)
    {

    }
);
jQuery('#vmap').bind('regionMouseOver.jqvmap', 
    function(event, code, region)
    {

    }
);
jQuery('#vmap').bind('regionMouseOut.jqvmap',
    function(event, code, region)
    {

    }
);
jQuery('#vmap').bind('regionClick.jqvmap',
    function(event, code, region)
    {

    }
);

Consider that fact that you can use standard features of jQuery events like event.preventDefault() or returning false from the callback to prevent default behavior of JQVMap (showing label or changing country color on hover). In the following example, when user moves mouse cursor over Canada label won't be shown and color of country won't be changed. At the same label for Russia will have custom text.

jQuery('#vmap').vectorMap(
{
    onLabelShow: function(event, label, code)
    {
        if (code == 'ca')
        {
            event.preventDefault();
        }
        else if (code == 'ru')
        {
            label.text('Bears, vodka, balalaika');
        }
    },
    onRegionOver: function(event, code)
    {
        if (code == 'ca')
        {
            event.preventDefault();
        }
    },
});

Data Visualization

Here I want to demonstrate how visualization of some geographical-related data can be done using JQVMap. Let's visualize information about GDP in 2010 for every country. At first we need some data. Let it be site of International Monetary Fond. There we can get information in xsl format, which can be converted first to csv and then to json with any scripting language. Now we have file gdp-data.js with such content (globals are evil, I know, but just for the sake of simplification):

var sample_data = {"af":16.63,"al":11.58,"dz":158.97,...};

Then connect it to the page and add some code to make visualization:

    var max = 0,
        min = Number.MAX_VALUE,
        cc,
        startColor = [200, 238, 255],
        endColor = [0, 100, 145],
        colors = {},
        hex;

//find maximum and minimum values
for (cc in gdpData)
{
    if (parseFloat(gdpData[cc]) > max)
    {
        max = parseFloat(gdpData[cc]);
    }
    if (parseFloat(gdpData[cc]) < min)
    {
        min = parseFloat(gdpData[cc]);
    }
}

//set colors according to values of GDP
for (cc in gdpData)
{
    if (gdpData[cc] > 0)
    {
        colors[cc] = '#';
        for (var i = 0; i<3; i++)
        {
            hex = Math.round(startColor[i] 
                + (endColor[i] 
                - startColor[i])
                * (gdpData[cc] / (max - min))).toString(16);

            if (hex.length == 1)
            {
                hex = '0'+hex;
            }

            colors[cc] += (hex.length == 1 ? '0' : '') + hex;
        }
    }
}

//initialize JQVMap
jQuery('#vmap').vectorMap(
{
    colors: colors,
    hoverOpacity: 0.7,
    hoverColor: false
});

Custom Maps

For information on building your own custom maps to use with this library, check out our Github project at https://github.com/manifestinteractive/jqvmap

97 questions
1
vote
0 answers

JQVmap with custom region

I need to create a map of a region that doesn't exist in the standard jqvMap, so I need to create that new region and I can't find any article on the internet on how to do this. The region I need is "Baixada Santista", there are a total of 9 cities…
1
vote
1 answer

Jqvmap Select Region dynamically

I have a map with Jqvmap plugin, and if we want to select a region by its code, we do: $('#vmap').vectorMap('set', 'colors', {us: '#ffffff'}); $('#vmap').vectorMap('set', 'colors', {fr: '#ffffff'}); ... But when this code comes from a variable, I…
zanzibar
  • 45
  • 1
  • 7
1
vote
1 answer

JQVMap Hover reveal

At the moment when I mouseover a country on JQVMap I get the country name. The code sources that name from the SVG file. In the SVG file the name is shown as: "path":".93z","name":"Uruguay", And in the JQVmap source code it is shown as if…
Alec Davies
  • 127
  • 11
1
vote
1 answer

How to use use JQVmap with Angular-CLI?

I've made an Angular-CLI project which works well. But I need to draw an interactive map with jQvmap (here). In my angular-cli.json file I include the path of jqvmap.js and jqvmap.css : { "project": { "version": "1.0.0-beta.25.5", "name":…
1
vote
3 answers

I want to add a link to certain countries in JQVMap

JQVMap - World Map
user3303871
  • 25
  • 1
  • 8
1
vote
1 answer

Add Puerto Rico to JQV Map (Countries)

Using the JQVMaps plugin with the World Map (by Countries) data, and need to be able to select Puerto Rico individually (right now it is bunched in with the US). Have been trying to look through the US' path points, but cannot make sense of them.…
user2521295
  • 823
  • 2
  • 12
  • 23
1
vote
0 answers

JQVMAP : mapping after zoom issue

http://s16.postimg.org/99hve381x/anatomy.png I'm trying to zoom after clicking on the path,is it possible to allow another mapping after zooming ? This is the code i'm trying, var showAll = false; jQuery(document).ready(function () { …
1
vote
1 answer

I need to make jqvmap disappear on mobile view

This is my site in progress http://www.wearemovingto.com I am using a template as an example but I want the map to disappear on mobile view and have a dropdown list take its place, just wondering what code to use? Thanks.
Jason
  • 23
  • 4
1
vote
1 answer

How to change tooltip style in jQuery vmap?

I created a map with jQuery.vmap and set the showTooltip: true setting. By default, this tooltip has a black background and white font; I can't inspect element tooltip in Chrome in order to change css style for it. How can I change the tooltip style…
Mahmoud.Eskandari
  • 1,460
  • 3
  • 20
  • 32
1
vote
3 answers

JQVMaps in WordPress

I'm using JQVMaps to render a map in a WordPress site. Testing the code outside of WordPress, everything runs perfectly. When I added it to WordPress I got this console error: [Error] TypeError: 'undefined' is not a function (evaluating…
jadle
  • 147
  • 2
  • 13
1
vote
1 answer

How can I fill ng-model query for filtering data using a javascript?

I use AngularJS for storing data in JSON and want to filter shown on the page items. Each item includes country code as a property: [ { "id": "1", "code": "us" }, { "id": "2", "code": "ca" } ] I want to use Jquery VMap to filter…
1
vote
1 answer

How to resolve a promise for a vector map datasource in Angularjs

Right so I'm fairly new to angular and really enjoying the experience and I'm slowly but successfully running through a few gotchas that keep cropping up, however this one has be stumped. I'm loading a version of the Jquery Vector map and everything…
Antony Smith
  • 620
  • 7
  • 13
1
vote
2 answers

JqvMap onRegionClick (bootstrap) PopOver fires only clicking twice

I am using JqvMap and I want to click on a region and this shall prompt a (bootstrap) popover with the name of the country as title, and the content should be some html links. This is my code:
Manuel Maestrini
  • 409
  • 6
  • 15
1
vote
1 answer

JQVMap Event (Mouse Position)

How to Get the mouse position, in "onRegionOver:function(event,code,region)" in jqvmap??? The event object in the function, doesn't have the properties from mouse position. I need show a div, with extra country information, when the mouse overs the…
1
vote
1 answer

Data Visualization with jVectorMap/JQVMap

I'am trying to make a Jquery Vector Map (for this i tryied out jVectorMap and now i'am "playing" around with JQVMap but i simply can't make any data visualization. I simply want to include my "accountbalanceData" and visualize the data like -20(%) =…
dnepro
  • 87
  • 2
  • 9