svgmap 2.7.2 β 2.8.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/demo/es6/package-lock.json +3 -3
- package/demo/html/index.html +4 -2
- package/dist/svgMap.css +19 -0
- package/dist/svgMap.js +168 -27
- package/dist/svgMap.min.css +1 -1
- package/dist/svgMap.min.js +1 -1
- package/package.json +1 -1
- package/src/js/svgMap.js +168 -27
- 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.8.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
|
|
|
@@ -846,13 +953,13 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
846
953
|
}
|
|
847
954
|
|
|
848
955
|
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});
|
|
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 });
|
|
853
960
|
const clickHandler = function (e) {
|
|
854
961
|
if (dragged) {
|
|
855
|
-
|
|
962
|
+
return;
|
|
856
963
|
}
|
|
857
964
|
|
|
858
965
|
const link = countryElement.getAttribute('data-link');
|
|
@@ -981,7 +1088,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
981
1088
|
var flagContainer = this.createElement(
|
|
982
1089
|
'div',
|
|
983
1090
|
'svgMap-tooltip-flag-container svgMap-tooltip-flag-container-' +
|
|
984
|
-
|
|
1091
|
+
this.options.flagType,
|
|
985
1092
|
tooltipContentWrapper
|
|
986
1093
|
);
|
|
987
1094
|
|
|
@@ -1047,6 +1154,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1047
1154
|
this.zoomControlIn.setAttribute('aria-disabled', 'false');
|
|
1048
1155
|
this.zoomControlOut.classList.remove('svgMap-disabled');
|
|
1049
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
|
+
}
|
|
1050
1161
|
|
|
1051
1162
|
if (this.mapPanZoom.getZoom().toFixed(3) <= this.options.minZoom) {
|
|
1052
1163
|
this.zoomControlOut.classList.add('svgMap-disabled');
|
|
@@ -1056,6 +1167,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1056
1167
|
this.zoomControlIn.classList.add('svgMap-disabled');
|
|
1057
1168
|
this.zoomControlIn.setAttribute('aria-disabled', 'true');
|
|
1058
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
|
+
}
|
|
1059
1174
|
};
|
|
1060
1175
|
|
|
1061
1176
|
// Zoom map
|
|
@@ -1068,7 +1183,33 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1068
1183
|
) {
|
|
1069
1184
|
return false;
|
|
1070
1185
|
}
|
|
1071
|
-
|
|
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
|
+
}
|
|
1072
1213
|
};
|
|
1073
1214
|
|
|
1074
1215
|
// Add elements to show the zoom with keys notice
|
|
@@ -1983,15 +2124,15 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1983
2124
|
ratio = parseFloat(ratio).toFixed(1);
|
|
1984
2125
|
var r = Math.ceil(
|
|
1985
2126
|
parseInt(color1.substring(0, 2), 16) * ratio +
|
|
1986
|
-
|
|
2127
|
+
parseInt(color2.substring(0, 2), 16) * (1 - ratio)
|
|
1987
2128
|
);
|
|
1988
2129
|
var g = Math.ceil(
|
|
1989
2130
|
parseInt(color1.substring(2, 4), 16) * ratio +
|
|
1990
|
-
|
|
2131
|
+
parseInt(color2.substring(2, 4), 16) * (1 - ratio)
|
|
1991
2132
|
);
|
|
1992
2133
|
var b = Math.ceil(
|
|
1993
2134
|
parseInt(color1.substring(4, 6), 16) * ratio +
|
|
1994
|
-
|
|
2135
|
+
parseInt(color2.substring(4, 6), 16) * (1 - ratio)
|
|
1995
2136
|
);
|
|
1996
2137
|
return '#' + this.getHex(r) + this.getHex(g) + this.getHex(b);
|
|
1997
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 {
|