Recommend this page to a friend! |
Classes of Jorge Castro | Gentelella BladeOne | vendors/jqvmap/README.md | Download |
|
Download
This project is a heavily modified version of jVectorMap as it was in April of 2012. I chose to start fresh rather than fork their project as my intentions were to take it in such a different direction that it would become incompatibale with the original source, rendering it near impossible to merge our projects together without extreme complications. jQuery Vector MapTo get started, all you need to do is include the JavaScript and CSS files for the map you want to load ( contained in the Here is a sample HTML page for loading the World Map with default settings:
Making it PrettyWhile initializing a map you can provide parameters to change its look and feel.
More ExamplesYou can see a variety of examples in the Configuration Settingsmap '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. hoverColors Colors of individual map regions when mouse pointer is over it. Keys of the colors objects are country codes according to ISO 3166-1 alpha-2 standard. Keys of colors must be in lower case. 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. selectedColor '#333333' Color for a region when you select it selectedRegions ['MO', 'FL', 'OR'] This is the Region that you are looking to have preselected (two letter ISO code, defaults to null ). See REGIONS.md multiSelectRegion boolean Whether to enable more than one region to be selected at a time. showLabels boolean Whether to show ISO Code Labels ( true or false, defaults to false ) showTooltip boolean Whether to show Tooltips on Mouseover ( true or false, defaults to true ) onLoad function(event, map) Callback function which will be called when map is loading, returning the map event and map details. onLabelShow function(event, 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(event, 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(event, 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(event, 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. This callback may be called while the user is moving the map. If you need to distinguish between a "real" click and a click resulting from moving the map, you can inspect $(event.currentTarget).data('mapObject').isMoving. onRegionSelect function(event, code, region) Callback function which will be called when the selects a region. Country code will be passed to the callback as argument. onRegionDeselect function(event, code, region) Callback function which will be called when the deselects a region. Country code will be passed to the callback as argument. onResize function(event, width, height) Callback function which will be called when the map is resized. Return event, width & height. pins { "pk" : "pk_pin_metadata", "ru" : "ru_pin_metadata", ... } This option defines pins, which will be placed on the regions. The JSON can have only one element against one country code. Elements should be strings containing the HTML or id of the pin (depends on the 'pinMode' option explained next). pinMode content This option defines if the "pins" JSON contains the HTML strings of the pins or the ids of HTML DOM elements which are to be placed as pins. If the pin mode is "content" (or not specified) then the parameter "pins" contains the stringified html content to be placed as the pins. Example:
If the pin mode is "id" then the parameter "pins" contains the value of "id" attribute of the html (DOM) elements to be placed as pins. Example:
Note: 1) The pin is placed at the center of the rectangle bounding the country. So depending on the shape of the country, the pin might not land on the country itself. For instance, the pin for 'US' lands in the center of Alaska and rest of the US, which happens to be in the ocean between them. 2) If the "pinMode" is set to "id", then the html DOM elements having those ids are NOT COPIED to the desired position, they are TRANSFERRED. This means that the elements will be removed from their original positions and placed on the map. Dynamic UpdatingMost of the options can be changed after initialization using the following code:
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:
Or later using standard jQuery mechanism:
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.
Data VisualizationHere 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):
Then connect it to the page and add some code to make visualization:
FunctionsThere are seven functions that can be called on map container: zoomIn() Zoom one step in Usage:
zoomOut() Zoom one step out Usage:
getPinId(cc) Returns the html attribute "id" of the pin placed on the country whose country code is provided in "cc". Usage:
getPin(cc) Returns stringified HTML of the pin placed on the country whose country code is provided in "cc". Usage:
getPins() Returns an associative JSON string containing stringified HTML of all the pins. Usage:
removePin(cc) Removes the pin from the country whose country code is specified in "cc". Usage:
removePins() Removes all the pins from the map. Usage:
EventsThere are three events which you can use to bind your own callbacks to: drag When the map is dragged, this event is triggered. zoomIn When the map is zoomed in, this event is triggered. zoomOut When the map is zoomed out, this event is triggered. You can bind your routines to any of these events by using jQuery on() For example:
Custom MapsSo you want to create your own maps, or change some existing ones. Awesome. Make sure to check out ./create/README.md for details on how to do this. |