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
1 answer

Using qTip2 with jQuery Vector Maps (jqvmap)

I am trying to disable the default tool tip used in jqvmap and want to use qTip2 instead. Is there anyway to achieve this? Here is the fiddle. jquery code: jQuery('#vmap').vectorMap({ map: 'world_en', backgroundColor: null, color:…
Konstant
  • 2,179
  • 16
  • 32
1
vote
1 answer

jQueryvmap with Bootstrap Popover Content

I am trying to implement Bootstrap Popover in jqueryVmap region click event. jsFiddle with Default hello message :- http://jsfiddle.net/perlfanatic/KD6fm/6/ jsFiddle with "message" variable :- http://jsfiddle.net/perlfanatic/KD6fm/7/ I am trying to…
Perl Fanatic
  • 109
  • 2
  • 12
1
vote
1 answer

creating choropleth map of Arizona with counties and an excel file of data about the counties

I am fairly new to data visualization using javascript and its various libraries and plugins. I am trying to create an interactive state map of Arizone with all its counties, I have data pertaining to schools within these counties that I would be…
Yaba
  • 304
  • 1
  • 3
  • 15
1
vote
1 answer

JQVMap - How do I set a state color in the USA Map?

My question is larger than the title. I want to apply transparency to most of the states and highlight about 6 states with a color. The instructions on the github page are definitely written from a programmers POV. Can someone help me understand how…
Kapitol
  • 153
  • 1
  • 5
  • 15
1
vote
1 answer

Add live time with name of countries in JQVMAPS

I want to add the current time to the country name in JQVMAP. Like this: Eqypt-05:30 AM By default, when we hover the mouse over a country, it only shows the country name in world map. I also want to add the current time. Please help me.
1
vote
1 answer

How does one dynamically set a color of a country through a var?

Anyone used http://github.com/manifestinteractive/jqvmap/ ? These work: $('#map').vectorMap('set', 'colors', { us: '#8EE5EE' }); $('#map').vectorMap('set', 'colors', { 'us': '#8EE5EE' }); But, this doesnt: country_name =…
Christian Fazzini
  • 19,613
  • 21
  • 110
  • 215
0
votes
0 answers

How to connect React Select and JQVMap to highlight selected regions

I have integrated a jqvmap in my Reactjs project and also have a Select from react-select. Now, I want to connect the two components so that when I select a region in the Select, the corresponding region is highlighted on the map. The jqvmap…
Dani
  • 1
  • 2
0
votes
2 answers

Select multiple classes with attr. with jQuery

I have a function that I use for an interactive map, where I hover an element to show a specific region based on class that matches a country suffix. Im trying to figure out how to select multiple classes to show multiple regions. Code: var mapObj =…
Jerry
  • 1,069
  • 2
  • 13
  • 31
0
votes
1 answer

svg shown in edge , not in chrome or firefox

i recently decided to develop opencart , the opencart dashboard has a global map for orders i want to change the world map to the iran map this map uses jquery and jqvmap i changed the codes of the map and its changed. but it is not showing in…
0
votes
2 answers

Retrieve Data From Google Scripts

I wrote a custom Google Script which outputs an object for me and I would like to be able to call it and assign it to a variable which is then used to display data on a website. Currently, I have figured out to access the data using another Google…
0
votes
1 answer

Flask fails to import custom jQuery

I've setup a Flask server with a simple form. I'd like to add a map so that users can select by region. I found JQVMap and have been trying to get this example to work with Flask. I downloaded the dist directory. Stuck it in my static Flask…
C1ARK
  • 1
0
votes
1 answer

Jvectormap clear previous data from map in AJAX load

I'm using jvectormap and I noticed that map data is actually accumulating on each call. For example, if there was 1 from spain, and on next load there is 1 from Italy, on 2nd map load it show 1 Spain and 1 Italy and so on. var singlemap =…
user3399805
  • 39
  • 1
  • 9
0
votes
1 answer

How can I set a Session using Javascript with Jquery Vector Map

Im using a jQuery Vector Map Library with name jqvmap. Anyone knows a way to Set a Session in Javascript instead of setting a Cookie?: My code: function getCountryName(code) { var path = JQVMap.maps["world_en"].paths[code]; return path &&…
s_h
  • 1,476
  • 2
  • 27
  • 61
0
votes
1 answer

JQVMAP Reset all settings

i am using the map to select countries via a button. once clicked the countries are highlighted. $(".mp-cyprus-A").click(function(){ $('#vmap').vectorMap('select', 'us'); $('#vmap').vectorMap('select', 'gb'); }); There are ways to set the…
happycoding
  • 458
  • 1
  • 5
  • 13
0
votes
1 answer

Angular 6 Importing JQVMap - Property 'vectorMap' does not exist on type 'JQuery'

I am trying to import a clickable map, JQVMap and therefore JQuery into my Angular 6 project and I am having some teething problems. Exception: error TS2339: Property 'vectorMap' does not exist on type 'JQuery'. My component: import {AfterViewInit,…