svgmap 2.7.2 β 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/assets/create-map-paths.html +1 -2
- package/assets/map-optimized.svg +1 -1
- package/demo/es6/package-lock.json +438 -421
- package/demo/es6/package.json +2 -2
- package/demo/html/index.html +4 -2
- package/dist/svgMap.css +19 -0
- package/dist/svgMap.js +182 -36
- package/dist/svgMap.min.css +1 -1
- package/dist/svgMap.min.js +1 -1
- package/package.json +4 -4
- package/src/js/svgMap.js +182 -36
- package/src/scss/map.scss +24 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svgmap",
|
|
3
3
|
"description": "svgMap is a JavaScript library that lets you easily create an interactable world map comparing customizable data for each country.",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.10.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/svgMap.min.js",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"gulp-concat": "^2.6.1",
|
|
21
21
|
"gulp-header": "^2.0.9",
|
|
22
22
|
"gulp-rename": "^2.0.0",
|
|
23
|
-
"gulp-sass": "^5.
|
|
23
|
+
"gulp-sass": "^5.1.0",
|
|
24
24
|
"gulp-sourcemaps": "^3.0.0",
|
|
25
25
|
"gulp-uglify": "^3.0.2",
|
|
26
|
-
"jest": "^
|
|
27
|
-
"sass": "^1.
|
|
26
|
+
"jest": "^28.1.1",
|
|
27
|
+
"sass": "^1.53.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"svg-pan-zoom": "^3.6.1"
|
package/src/js/svgMap.js
CHANGED
|
@@ -56,6 +56,9 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
56
56
|
|
|
57
57
|
// Decide whether to show the flag option or not
|
|
58
58
|
hideFlag: false,
|
|
59
|
+
|
|
60
|
+
// Whether attributes with no data should be displayed
|
|
61
|
+
hideMissingData: false,
|
|
59
62
|
|
|
60
63
|
// The default text to be shown when no data is present
|
|
61
64
|
noDataText: 'No data available',
|
|
@@ -63,6 +66,9 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
63
66
|
// Set to true to open the link on mobile devices, set to false (default) to show the tooltip
|
|
64
67
|
touchLink: false,
|
|
65
68
|
|
|
69
|
+
// Set to true to show the to show a zoom reset button
|
|
70
|
+
showZoomReset: false,
|
|
71
|
+
|
|
66
72
|
// Called when a tooltip is created to custimize the tooltip content
|
|
67
73
|
onGetTooltip: function (tooltipDiv, countryID, countryValues) {
|
|
68
74
|
return null;
|
|
@@ -75,7 +81,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
75
81
|
|
|
76
82
|
// Crimea: Set to 'RU' to make the Crimea part of Russia, by default it is part of the Ukraine
|
|
77
83
|
Crimea: 'UA'
|
|
78
|
-
}
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
// Set to true to show a drop down menu with the continents
|
|
87
|
+
showContinentSelector: false,
|
|
79
88
|
};
|
|
80
89
|
|
|
81
90
|
this.options = Object.assign({}, defaultOptions, options || {});
|
|
@@ -678,6 +687,69 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
678
687
|
ZW: 'πΏπΌ'
|
|
679
688
|
};
|
|
680
689
|
|
|
690
|
+
svgMap.prototype.continents = {
|
|
691
|
+
"EA": {
|
|
692
|
+
"iso": "EA",
|
|
693
|
+
"name": "World"
|
|
694
|
+
},
|
|
695
|
+
"AF": {
|
|
696
|
+
"iso": "AF",
|
|
697
|
+
"name": "Africa",
|
|
698
|
+
"pan": {
|
|
699
|
+
x: 454, y: 250
|
|
700
|
+
},
|
|
701
|
+
"zoom": 1.90
|
|
702
|
+
},
|
|
703
|
+
"AS": {
|
|
704
|
+
"iso": "AS",
|
|
705
|
+
"name": "Asia",
|
|
706
|
+
"pan": {
|
|
707
|
+
x: 904, y: 80
|
|
708
|
+
},
|
|
709
|
+
"zoom": 1.8
|
|
710
|
+
},
|
|
711
|
+
"EU": {
|
|
712
|
+
"iso": "EU",
|
|
713
|
+
"name": "Europe",
|
|
714
|
+
"pan": {
|
|
715
|
+
x: 404, y: 80
|
|
716
|
+
},
|
|
717
|
+
"zoom": 5
|
|
718
|
+
},
|
|
719
|
+
"NA": {
|
|
720
|
+
"iso": "NA",
|
|
721
|
+
"name": "North America",
|
|
722
|
+
"pan": {
|
|
723
|
+
x: 104, y: 55
|
|
724
|
+
},
|
|
725
|
+
"zoom": 2.6
|
|
726
|
+
},
|
|
727
|
+
|
|
728
|
+
"MA": {
|
|
729
|
+
"iso": "MA",
|
|
730
|
+
"name": "Middle America",
|
|
731
|
+
"pan": {
|
|
732
|
+
x: 104, y: 200
|
|
733
|
+
},
|
|
734
|
+
"zoom": 2.6
|
|
735
|
+
},
|
|
736
|
+
"SA": {
|
|
737
|
+
"iso": "SA",
|
|
738
|
+
"name": "South America",
|
|
739
|
+
"pan": {
|
|
740
|
+
x: 104, y: 340
|
|
741
|
+
},
|
|
742
|
+
"zoom": 2.2
|
|
743
|
+
},
|
|
744
|
+
"OC": {
|
|
745
|
+
"iso": "OC",
|
|
746
|
+
"name": "Oceania",
|
|
747
|
+
"pan": {
|
|
748
|
+
x: 954, y: 350
|
|
749
|
+
},
|
|
750
|
+
"zoom": 1.90
|
|
751
|
+
},
|
|
752
|
+
}
|
|
681
753
|
// Create the SVG map
|
|
682
754
|
|
|
683
755
|
svgMap.prototype.createMap = function () {
|
|
@@ -698,6 +770,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
698
770
|
this.mapImage.classList.add('svgMap-map-image');
|
|
699
771
|
this.mapWrapper.appendChild(this.mapImage);
|
|
700
772
|
|
|
773
|
+
|
|
701
774
|
// Add controls
|
|
702
775
|
var mapControlsWrapper = this.createElement(
|
|
703
776
|
'div',
|
|
@@ -709,25 +782,27 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
709
782
|
'svgMap-map-controls-zoom',
|
|
710
783
|
mapControlsWrapper
|
|
711
784
|
);
|
|
712
|
-
['in', 'out'].forEach(
|
|
785
|
+
['in', 'out', 'reset'].forEach(
|
|
713
786
|
function (item) {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
787
|
+
if (item === 'reset' && this.options.showZoomReset || item !== 'reset') {
|
|
788
|
+
var zoomControlName =
|
|
789
|
+
'zoomControl' + item.charAt(0).toUpperCase() + item.slice(1);
|
|
790
|
+
this[zoomControlName] = this.createElement(
|
|
791
|
+
'button',
|
|
792
|
+
'svgMap-control-button svgMap-zoom-button svgMap-zoom-' +
|
|
719
793
|
item +
|
|
720
794
|
'-button',
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
795
|
+
zoomContainer
|
|
796
|
+
);
|
|
797
|
+
this[zoomControlName].type = 'button';
|
|
798
|
+
this[zoomControlName].addEventListener(
|
|
799
|
+
'click',
|
|
800
|
+
function () {
|
|
801
|
+
this.zoomMap(item);
|
|
802
|
+
}.bind(this),
|
|
803
|
+
{ passive: true }
|
|
804
|
+
);
|
|
805
|
+
}
|
|
731
806
|
}.bind(this)
|
|
732
807
|
);
|
|
733
808
|
|
|
@@ -735,6 +810,41 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
735
810
|
this.zoomControlIn.setAttribute('aria-label', 'Zoom in');
|
|
736
811
|
this.zoomControlOut.setAttribute('aria-label', 'Zoom out');
|
|
737
812
|
|
|
813
|
+
if (this.options.showContinentSelector) {
|
|
814
|
+
// Add continent controls
|
|
815
|
+
var mapContinentControlsWrapper = this.createElement(
|
|
816
|
+
'div',
|
|
817
|
+
'svgMap-map-continent-controls-wrapper',
|
|
818
|
+
this.mapWrapper
|
|
819
|
+
);
|
|
820
|
+
this["continentSelect"] = this.createElement(
|
|
821
|
+
'select',
|
|
822
|
+
'svgMap-continent-select',
|
|
823
|
+
mapContinentControlsWrapper
|
|
824
|
+
);
|
|
825
|
+
var that = this;
|
|
826
|
+
Object.keys(svgMap.prototype.continents).forEach(
|
|
827
|
+
function (item) {
|
|
828
|
+
let element = that.createElement(
|
|
829
|
+
'option',
|
|
830
|
+
'svgMap-continent-option svgMap-continent-iso-' + svgMap.prototype.continents[item].iso,
|
|
831
|
+
that["continentSelect"],
|
|
832
|
+
svgMap.prototype.continents[item].name
|
|
833
|
+
);
|
|
834
|
+
element.value = item
|
|
835
|
+
}
|
|
836
|
+
);
|
|
837
|
+
|
|
838
|
+
this.continentSelect.addEventListener(
|
|
839
|
+
'change',
|
|
840
|
+
function (e) {
|
|
841
|
+
const continent = e.target.value;
|
|
842
|
+
if (continent) this.zoomContinent(e.target.value);
|
|
843
|
+
}.bind(that),
|
|
844
|
+
{ passive: true }
|
|
845
|
+
);
|
|
846
|
+
mapContinentControlsWrapper.setAttribute('aria-label', 'Select continent');
|
|
847
|
+
}
|
|
738
848
|
// Fix countries
|
|
739
849
|
var mapPaths = Object.assign({}, this.mapPaths);
|
|
740
850
|
|
|
@@ -846,13 +956,13 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
846
956
|
}
|
|
847
957
|
|
|
848
958
|
let dragged = false;
|
|
849
|
-
countryElement.addEventListener('mousedown', function(){dragged = false});
|
|
850
|
-
countryElement.addEventListener('touchstart', function(){dragged = false});
|
|
851
|
-
countryElement.addEventListener('mousemove', function(){dragged = true});
|
|
852
|
-
countryElement.addEventListener('touchmove', function(){dragged = true});
|
|
959
|
+
countryElement.addEventListener('mousedown', function () { dragged = false });
|
|
960
|
+
countryElement.addEventListener('touchstart', function () { dragged = false });
|
|
961
|
+
countryElement.addEventListener('mousemove', function () { dragged = true });
|
|
962
|
+
countryElement.addEventListener('touchmove', function () { dragged = true });
|
|
853
963
|
const clickHandler = function (e) {
|
|
854
964
|
if (dragged) {
|
|
855
|
-
|
|
965
|
+
return;
|
|
856
966
|
}
|
|
857
967
|
|
|
858
968
|
const link = countryElement.getAttribute('data-link');
|
|
@@ -981,7 +1091,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
981
1091
|
var flagContainer = this.createElement(
|
|
982
1092
|
'div',
|
|
983
1093
|
'svgMap-tooltip-flag-container svgMap-tooltip-flag-container-' +
|
|
984
|
-
|
|
1094
|
+
this.options.flagType,
|
|
985
1095
|
tooltipContentWrapper
|
|
986
1096
|
);
|
|
987
1097
|
|
|
@@ -1024,14 +1134,16 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1024
1134
|
function (key) {
|
|
1025
1135
|
var item = this.options.data.data[key];
|
|
1026
1136
|
var value = this.options.data.values[countryID][key];
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1137
|
+
if ((value !== undefined && this.options.hideMissingData === true) || this.options.hideMissingData === false) {
|
|
1138
|
+
item.floatingNumbers && (value = value.toFixed(1));
|
|
1139
|
+
item.thousandSeparator &&
|
|
1140
|
+
(value = this.numberWithCommas(value, item.thousandSeparator));
|
|
1141
|
+
value = item.format
|
|
1142
|
+
? item.format.replace('{0}', '<span>' + value + '</span>')
|
|
1143
|
+
: '<span>' + value + '</span>';
|
|
1144
|
+
tooltipContentTable +=
|
|
1145
|
+
'<tr><td>' + (item.name || '') + '</td><td>' + value + '</td></tr>';
|
|
1146
|
+
}
|
|
1035
1147
|
}.bind(this)
|
|
1036
1148
|
);
|
|
1037
1149
|
tooltipContentTable += '</table>';
|
|
@@ -1047,6 +1159,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1047
1159
|
this.zoomControlIn.setAttribute('aria-disabled', 'false');
|
|
1048
1160
|
this.zoomControlOut.classList.remove('svgMap-disabled');
|
|
1049
1161
|
this.zoomControlOut.setAttribute('aria-disabled', 'false');
|
|
1162
|
+
if (this.options.showZoomReset) {
|
|
1163
|
+
this.zoomControlReset.classList.remove('svgMap-disabled');
|
|
1164
|
+
this.zoomControlReset.setAttribute('aria-disabled', 'false');
|
|
1165
|
+
}
|
|
1050
1166
|
|
|
1051
1167
|
if (this.mapPanZoom.getZoom().toFixed(3) <= this.options.minZoom) {
|
|
1052
1168
|
this.zoomControlOut.classList.add('svgMap-disabled');
|
|
@@ -1056,6 +1172,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1056
1172
|
this.zoomControlIn.classList.add('svgMap-disabled');
|
|
1057
1173
|
this.zoomControlIn.setAttribute('aria-disabled', 'true');
|
|
1058
1174
|
}
|
|
1175
|
+
if (this.options.showZoomReset && this.mapPanZoom.getZoom().toFixed(3) == this.options.initialZoom) {
|
|
1176
|
+
this.zoomControlReset.classList.add('svgMap-disabled');
|
|
1177
|
+
this.zoomControlReset.setAttribute('aria-disabled', 'true');
|
|
1178
|
+
}
|
|
1059
1179
|
};
|
|
1060
1180
|
|
|
1061
1181
|
// Zoom map
|
|
@@ -1068,7 +1188,33 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1068
1188
|
) {
|
|
1069
1189
|
return false;
|
|
1070
1190
|
}
|
|
1071
|
-
|
|
1191
|
+
if (direction === 'reset') {
|
|
1192
|
+
this.mapPanZoom.reset();
|
|
1193
|
+
if (this.options.initialPan.x != 0 || this.options.initialPan.y != 0) {
|
|
1194
|
+
// Init zoom and pan
|
|
1195
|
+
this.mapPanZoom.zoomAtPointBy(this.options.initialZoom, {
|
|
1196
|
+
x: this.options.initialPan.x,
|
|
1197
|
+
y: this.options.initialPan.y
|
|
1198
|
+
});
|
|
1199
|
+
} else {
|
|
1200
|
+
// Init zoom
|
|
1201
|
+
this.mapPanZoom.zoom(this.options.initialZoom);
|
|
1202
|
+
}
|
|
1203
|
+
} else {
|
|
1204
|
+
this.mapPanZoom[direction == 'in' ? 'zoomIn' : 'zoomOut']();
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1208
|
+
// Zoom to Contient
|
|
1209
|
+
|
|
1210
|
+
svgMap.prototype.zoomContinent = function (contientIso) {
|
|
1211
|
+
|
|
1212
|
+
const continent = this.continents[contientIso];
|
|
1213
|
+
if (continent.iso == "EA") this.mapPanZoom.reset()
|
|
1214
|
+
else if (continent.pan) {
|
|
1215
|
+
this.mapPanZoom.reset()
|
|
1216
|
+
this.mapPanZoom.zoomAtPoint(continent.zoom, continent.pan);
|
|
1217
|
+
}
|
|
1072
1218
|
};
|
|
1073
1219
|
|
|
1074
1220
|
// Add elements to show the zoom with keys notice
|
|
@@ -1369,7 +1515,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1369
1515
|
d: 'M487.2,487l0.6-2.5l-0.7-0.7l-1.1-0.5l-2.5,0.8l-0.1-0.9l-1.6-1l-1.1-1.3l-1.5-0.5l-1.4,0.4l0.2,0.7l-1.1,0.7 l-2.1,1.6l-0.2,1l1.4,1.3l3.1,0.4l2.2,1.3l1.9,0.6l3.3,0.1L487.2,487L487.2,487z'
|
|
1370
1516
|
},
|
|
1371
1517
|
'GQ': {
|
|
1372
|
-
d: '
|
|
1518
|
+
d: 'M 1040.1 557.8 l -9.2 -0.2 l -1.9 7.2 l 1 0.9 l 1.9 -0.3 h 8.2 V 557.8 L 1040.1 557.8 z M 1023 551 L 1023.6 550.2 L 1023.6 549.8 L 1024.6 548.25 L 1024.45 547.5 L 1023.04 547.4 L 1022.5 548.2 L 1022.55 548.55 L 1022.25 549.36 L 1021.55 549.5 L 1021.25 550.15 L 1021.5 550.7 L 1023 551 M 1003.8 580.2 L 1003.9 580.44 L 1003.82 580.62 L 1003.65 580.55 L 1003.63 580.232 L 1003.8 580.2'
|
|
1373
1519
|
},
|
|
1374
1520
|
'ER': {
|
|
1375
1521
|
d: 'M1198.1,474l-3.2-3.1l-1.8-5.9l-3.7-7.3l-2.6,3.6l-4,1l-1.6,2l-0.4,4.2l-1.9,9.4l0.7,2.5l6.5,1.3l1.5-4.7l3.5,2.9 l3.2-1.5l1.4,1.3l3.9,0.1l4.9,2.5l1.6,2.2l2.5,2.1l2.5,3.7l2,2.1l2.4,0.5l1.6-1.5l-2.8-1.9l-1.9-2.2l-3.2-3.7l-3.2-3.6L1198.1,474z'
|
|
@@ -1983,15 +2129,15 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1983
2129
|
ratio = parseFloat(ratio).toFixed(1);
|
|
1984
2130
|
var r = Math.ceil(
|
|
1985
2131
|
parseInt(color1.substring(0, 2), 16) * ratio +
|
|
1986
|
-
|
|
2132
|
+
parseInt(color2.substring(0, 2), 16) * (1 - ratio)
|
|
1987
2133
|
);
|
|
1988
2134
|
var g = Math.ceil(
|
|
1989
2135
|
parseInt(color1.substring(2, 4), 16) * ratio +
|
|
1990
|
-
|
|
2136
|
+
parseInt(color2.substring(2, 4), 16) * (1 - ratio)
|
|
1991
2137
|
);
|
|
1992
2138
|
var b = Math.ceil(
|
|
1993
2139
|
parseInt(color1.substring(4, 6), 16) * ratio +
|
|
1994
|
-
|
|
2140
|
+
parseInt(color2.substring(4, 6), 16) * (1 - ratio)
|
|
1995
2141
|
);
|
|
1996
2142
|
return '#' + this.getHex(r) + this.getHex(g) + this.getHex(b);
|
|
1997
2143
|
};
|
package/src/scss/map.scss
CHANGED
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
&.svgMap-zoom-button {
|
|
112
112
|
&:before,
|
|
113
113
|
&:after {
|
|
114
|
-
content:
|
|
114
|
+
content: "";
|
|
115
115
|
position: absolute;
|
|
116
116
|
top: 50%;
|
|
117
117
|
left: 50%;
|
|
@@ -124,6 +124,12 @@
|
|
|
124
124
|
width: 11px;
|
|
125
125
|
height: 3px;
|
|
126
126
|
}
|
|
127
|
+
&.svgMap-zoom-reset-button::before {
|
|
128
|
+
width: 11px;
|
|
129
|
+
height: 11px;
|
|
130
|
+
background: none;
|
|
131
|
+
border: 2px solid #666;
|
|
132
|
+
}
|
|
127
133
|
|
|
128
134
|
@media (hover: hover) {
|
|
129
135
|
&:hover {
|
|
@@ -147,6 +153,12 @@
|
|
|
147
153
|
background: #ccc;
|
|
148
154
|
}
|
|
149
155
|
}
|
|
156
|
+
&.svgMap-zoom-reset-button {
|
|
157
|
+
&.svgMap-disabled:before {
|
|
158
|
+
border: 2px solid #ccc;
|
|
159
|
+
background: none;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
150
162
|
}
|
|
151
163
|
|
|
152
164
|
&.svgMap-zoom-in-button {
|
|
@@ -163,6 +175,17 @@
|
|
|
163
175
|
}
|
|
164
176
|
}
|
|
165
177
|
|
|
178
|
+
// Contient controls
|
|
179
|
+
.svgMap-map-continent-controls-wrapper{
|
|
180
|
+
position: absolute;
|
|
181
|
+
top: 10px;
|
|
182
|
+
right: 10px;
|
|
183
|
+
z-index: 1;
|
|
184
|
+
display: flex;
|
|
185
|
+
border-radius: 2px;
|
|
186
|
+
box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
|
|
187
|
+
}
|
|
188
|
+
|
|
166
189
|
// Countries
|
|
167
190
|
|
|
168
191
|
.svgMap-country {
|