svgmap 2.7.1 β 2.9.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/LICENSE +1 -1
- 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 +29 -13
- package/demo/es6/package.json +1 -1
- package/demo/html/index.html +4 -2
- package/dist/svgMap.css +19 -0
- package/dist/svgMap.js +179 -25
- package/dist/svgMap.min.css +1 -1
- package/dist/svgMap.min.js +1 -1
- package/package.json +1 -1
- package/src/js/svgMap.js +179 -25
- 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.9.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/svgMap.min.js",
|
package/src/js/svgMap.js
CHANGED
|
@@ -63,6 +63,9 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
63
63
|
// Set to true to open the link on mobile devices, set to false (default) to show the tooltip
|
|
64
64
|
touchLink: false,
|
|
65
65
|
|
|
66
|
+
// Set to true to show the to show a zoom reset button
|
|
67
|
+
showZoomReset: false,
|
|
68
|
+
|
|
66
69
|
// Called when a tooltip is created to custimize the tooltip content
|
|
67
70
|
onGetTooltip: function (tooltipDiv, countryID, countryValues) {
|
|
68
71
|
return null;
|
|
@@ -75,7 +78,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
75
78
|
|
|
76
79
|
// Crimea: Set to 'RU' to make the Crimea part of Russia, by default it is part of the Ukraine
|
|
77
80
|
Crimea: 'UA'
|
|
78
|
-
}
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
// Set to true to show a drop down menu with the continents
|
|
84
|
+
showContinentSelector: false,
|
|
79
85
|
};
|
|
80
86
|
|
|
81
87
|
this.options = Object.assign({}, defaultOptions, options || {});
|
|
@@ -678,6 +684,69 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
678
684
|
ZW: 'πΏπΌ'
|
|
679
685
|
};
|
|
680
686
|
|
|
687
|
+
svgMap.prototype.continents = {
|
|
688
|
+
"EA": {
|
|
689
|
+
"iso": "EA",
|
|
690
|
+
"name": "World"
|
|
691
|
+
},
|
|
692
|
+
"AF": {
|
|
693
|
+
"iso": "AF",
|
|
694
|
+
"name": "Africa",
|
|
695
|
+
"pan": {
|
|
696
|
+
x: 454, y: 250
|
|
697
|
+
},
|
|
698
|
+
"zoom": 1.90
|
|
699
|
+
},
|
|
700
|
+
"AS": {
|
|
701
|
+
"iso": "AS",
|
|
702
|
+
"name": "Asia",
|
|
703
|
+
"pan": {
|
|
704
|
+
x: 904, y: 80
|
|
705
|
+
},
|
|
706
|
+
"zoom": 1.8
|
|
707
|
+
},
|
|
708
|
+
"EU": {
|
|
709
|
+
"iso": "EU",
|
|
710
|
+
"name": "Europe",
|
|
711
|
+
"pan": {
|
|
712
|
+
x: 404, y: 80
|
|
713
|
+
},
|
|
714
|
+
"zoom": 5
|
|
715
|
+
},
|
|
716
|
+
"NA": {
|
|
717
|
+
"iso": "NA",
|
|
718
|
+
"name": "North America",
|
|
719
|
+
"pan": {
|
|
720
|
+
x: 104, y: 55
|
|
721
|
+
},
|
|
722
|
+
"zoom": 2.6
|
|
723
|
+
},
|
|
724
|
+
|
|
725
|
+
"MA": {
|
|
726
|
+
"iso": "MA",
|
|
727
|
+
"name": "Middle America",
|
|
728
|
+
"pan": {
|
|
729
|
+
x: 104, y: 200
|
|
730
|
+
},
|
|
731
|
+
"zoom": 2.6
|
|
732
|
+
},
|
|
733
|
+
"SA": {
|
|
734
|
+
"iso": "SA",
|
|
735
|
+
"name": "South America",
|
|
736
|
+
"pan": {
|
|
737
|
+
x: 104, y: 340
|
|
738
|
+
},
|
|
739
|
+
"zoom": 2.2
|
|
740
|
+
},
|
|
741
|
+
"OC": {
|
|
742
|
+
"iso": "OC",
|
|
743
|
+
"name": "Oceania",
|
|
744
|
+
"pan": {
|
|
745
|
+
x: 954, y: 350
|
|
746
|
+
},
|
|
747
|
+
"zoom": 1.90
|
|
748
|
+
},
|
|
749
|
+
}
|
|
681
750
|
// Create the SVG map
|
|
682
751
|
|
|
683
752
|
svgMap.prototype.createMap = function () {
|
|
@@ -698,6 +767,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
698
767
|
this.mapImage.classList.add('svgMap-map-image');
|
|
699
768
|
this.mapWrapper.appendChild(this.mapImage);
|
|
700
769
|
|
|
770
|
+
|
|
701
771
|
// Add controls
|
|
702
772
|
var mapControlsWrapper = this.createElement(
|
|
703
773
|
'div',
|
|
@@ -709,25 +779,27 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
709
779
|
'svgMap-map-controls-zoom',
|
|
710
780
|
mapControlsWrapper
|
|
711
781
|
);
|
|
712
|
-
['in', 'out'].forEach(
|
|
782
|
+
['in', 'out', 'reset'].forEach(
|
|
713
783
|
function (item) {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
784
|
+
if (item === 'reset' && this.options.showZoomReset || item !== 'reset') {
|
|
785
|
+
var zoomControlName =
|
|
786
|
+
'zoomControl' + item.charAt(0).toUpperCase() + item.slice(1);
|
|
787
|
+
this[zoomControlName] = this.createElement(
|
|
788
|
+
'button',
|
|
789
|
+
'svgMap-control-button svgMap-zoom-button svgMap-zoom-' +
|
|
719
790
|
item +
|
|
720
791
|
'-button',
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
792
|
+
zoomContainer
|
|
793
|
+
);
|
|
794
|
+
this[zoomControlName].type = 'button';
|
|
795
|
+
this[zoomControlName].addEventListener(
|
|
796
|
+
'click',
|
|
797
|
+
function () {
|
|
798
|
+
this.zoomMap(item);
|
|
799
|
+
}.bind(this),
|
|
800
|
+
{ passive: true }
|
|
801
|
+
);
|
|
802
|
+
}
|
|
731
803
|
}.bind(this)
|
|
732
804
|
);
|
|
733
805
|
|
|
@@ -735,6 +807,41 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
735
807
|
this.zoomControlIn.setAttribute('aria-label', 'Zoom in');
|
|
736
808
|
this.zoomControlOut.setAttribute('aria-label', 'Zoom out');
|
|
737
809
|
|
|
810
|
+
if (this.options.showContinentSelector) {
|
|
811
|
+
// Add continent controls
|
|
812
|
+
var mapContinentControlsWrapper = this.createElement(
|
|
813
|
+
'div',
|
|
814
|
+
'svgMap-map-continent-controls-wrapper',
|
|
815
|
+
this.mapWrapper
|
|
816
|
+
);
|
|
817
|
+
this["continentSelect"] = this.createElement(
|
|
818
|
+
'select',
|
|
819
|
+
'svgMap-continent-select',
|
|
820
|
+
mapContinentControlsWrapper
|
|
821
|
+
);
|
|
822
|
+
var that = this;
|
|
823
|
+
Object.keys(svgMap.prototype.continents).forEach(
|
|
824
|
+
function (item) {
|
|
825
|
+
let element = that.createElement(
|
|
826
|
+
'option',
|
|
827
|
+
'svgMap-continent-option svgMap-continent-iso-' + svgMap.prototype.continents[item].iso,
|
|
828
|
+
that["continentSelect"],
|
|
829
|
+
svgMap.prototype.continents[item].name
|
|
830
|
+
);
|
|
831
|
+
element.value = item
|
|
832
|
+
}
|
|
833
|
+
);
|
|
834
|
+
|
|
835
|
+
this.continentSelect.addEventListener(
|
|
836
|
+
'change',
|
|
837
|
+
function (e) {
|
|
838
|
+
const continent = e.target.value;
|
|
839
|
+
if (continent) this.zoomContinent(e.target.value);
|
|
840
|
+
}.bind(that),
|
|
841
|
+
{ passive: true }
|
|
842
|
+
);
|
|
843
|
+
mapContinentControlsWrapper.setAttribute('aria-label', 'Select continent');
|
|
844
|
+
}
|
|
738
845
|
// Fix countries
|
|
739
846
|
var mapPaths = Object.assign({}, this.mapPaths);
|
|
740
847
|
|
|
@@ -844,7 +951,17 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
844
951
|
this.options.data.values[countryID]['linkTarget']
|
|
845
952
|
);
|
|
846
953
|
}
|
|
847
|
-
|
|
954
|
+
|
|
955
|
+
let dragged = false;
|
|
956
|
+
countryElement.addEventListener('mousedown', function () { dragged = false });
|
|
957
|
+
countryElement.addEventListener('touchstart', function () { dragged = false });
|
|
958
|
+
countryElement.addEventListener('mousemove', function () { dragged = true });
|
|
959
|
+
countryElement.addEventListener('touchmove', function () { dragged = true });
|
|
960
|
+
const clickHandler = function (e) {
|
|
961
|
+
if (dragged) {
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
|
|
848
965
|
const link = countryElement.getAttribute('data-link');
|
|
849
966
|
const target = countryElement.getAttribute('data-link-target');
|
|
850
967
|
|
|
@@ -853,7 +970,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
853
970
|
} else {
|
|
854
971
|
window.location.href = link;
|
|
855
972
|
}
|
|
856
|
-
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
countryElement.addEventListener('click', clickHandler);
|
|
976
|
+
countryElement.addEventListener('touchend', clickHandler);
|
|
857
977
|
}
|
|
858
978
|
|
|
859
979
|
// Hide tooltip when mouse leaves the country area
|
|
@@ -968,7 +1088,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
968
1088
|
var flagContainer = this.createElement(
|
|
969
1089
|
'div',
|
|
970
1090
|
'svgMap-tooltip-flag-container svgMap-tooltip-flag-container-' +
|
|
971
|
-
|
|
1091
|
+
this.options.flagType,
|
|
972
1092
|
tooltipContentWrapper
|
|
973
1093
|
);
|
|
974
1094
|
|
|
@@ -1034,6 +1154,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1034
1154
|
this.zoomControlIn.setAttribute('aria-disabled', 'false');
|
|
1035
1155
|
this.zoomControlOut.classList.remove('svgMap-disabled');
|
|
1036
1156
|
this.zoomControlOut.setAttribute('aria-disabled', 'false');
|
|
1157
|
+
if (this.options.showZoomReset) {
|
|
1158
|
+
this.zoomControlReset.classList.remove('svgMap-disabled');
|
|
1159
|
+
this.zoomControlReset.setAttribute('aria-disabled', 'false');
|
|
1160
|
+
}
|
|
1037
1161
|
|
|
1038
1162
|
if (this.mapPanZoom.getZoom().toFixed(3) <= this.options.minZoom) {
|
|
1039
1163
|
this.zoomControlOut.classList.add('svgMap-disabled');
|
|
@@ -1043,6 +1167,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1043
1167
|
this.zoomControlIn.classList.add('svgMap-disabled');
|
|
1044
1168
|
this.zoomControlIn.setAttribute('aria-disabled', 'true');
|
|
1045
1169
|
}
|
|
1170
|
+
if (this.options.showZoomReset && this.mapPanZoom.getZoom().toFixed(3) == this.options.initialZoom) {
|
|
1171
|
+
this.zoomControlReset.classList.add('svgMap-disabled');
|
|
1172
|
+
this.zoomControlReset.setAttribute('aria-disabled', 'true');
|
|
1173
|
+
}
|
|
1046
1174
|
};
|
|
1047
1175
|
|
|
1048
1176
|
// Zoom map
|
|
@@ -1055,7 +1183,33 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1055
1183
|
) {
|
|
1056
1184
|
return false;
|
|
1057
1185
|
}
|
|
1058
|
-
|
|
1186
|
+
if (direction === 'reset') {
|
|
1187
|
+
this.mapPanZoom.reset();
|
|
1188
|
+
if (this.options.initialPan.x != 0 || this.options.initialPan.y != 0) {
|
|
1189
|
+
// Init zoom and pan
|
|
1190
|
+
this.mapPanZoom.zoomAtPointBy(this.options.initialZoom, {
|
|
1191
|
+
x: this.options.initialPan.x,
|
|
1192
|
+
y: this.options.initialPan.y
|
|
1193
|
+
});
|
|
1194
|
+
} else {
|
|
1195
|
+
// Init zoom
|
|
1196
|
+
this.mapPanZoom.zoom(this.options.initialZoom);
|
|
1197
|
+
}
|
|
1198
|
+
} else {
|
|
1199
|
+
this.mapPanZoom[direction == 'in' ? 'zoomIn' : 'zoomOut']();
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
|
|
1203
|
+
// Zoom to Contient
|
|
1204
|
+
|
|
1205
|
+
svgMap.prototype.zoomContinent = function (contientIso) {
|
|
1206
|
+
|
|
1207
|
+
const continent = this.continents[contientIso];
|
|
1208
|
+
if (continent.iso == "EA") this.mapPanZoom.reset()
|
|
1209
|
+
else if (continent.pan) {
|
|
1210
|
+
this.mapPanZoom.reset()
|
|
1211
|
+
this.mapPanZoom.zoomAtPoint(continent.zoom, continent.pan);
|
|
1212
|
+
}
|
|
1059
1213
|
};
|
|
1060
1214
|
|
|
1061
1215
|
// Add elements to show the zoom with keys notice
|
|
@@ -1356,7 +1510,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1356
1510
|
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'
|
|
1357
1511
|
},
|
|
1358
1512
|
'GQ': {
|
|
1359
|
-
d: '
|
|
1513
|
+
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'
|
|
1360
1514
|
},
|
|
1361
1515
|
'ER': {
|
|
1362
1516
|
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'
|
|
@@ -1970,15 +2124,15 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1970
2124
|
ratio = parseFloat(ratio).toFixed(1);
|
|
1971
2125
|
var r = Math.ceil(
|
|
1972
2126
|
parseInt(color1.substring(0, 2), 16) * ratio +
|
|
1973
|
-
|
|
2127
|
+
parseInt(color2.substring(0, 2), 16) * (1 - ratio)
|
|
1974
2128
|
);
|
|
1975
2129
|
var g = Math.ceil(
|
|
1976
2130
|
parseInt(color1.substring(2, 4), 16) * ratio +
|
|
1977
|
-
|
|
2131
|
+
parseInt(color2.substring(2, 4), 16) * (1 - ratio)
|
|
1978
2132
|
);
|
|
1979
2133
|
var b = Math.ceil(
|
|
1980
2134
|
parseInt(color1.substring(4, 6), 16) * ratio +
|
|
1981
|
-
|
|
2135
|
+
parseInt(color2.substring(4, 6), 16) * (1 - ratio)
|
|
1982
2136
|
);
|
|
1983
2137
|
return '#' + this.getHex(r) + this.getHex(g) + this.getHex(b);
|
|
1984
2138
|
};
|
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 {
|