├── README.md ├── index.html ├── jquery-jvectormap-2.0.1.css ├── LICENSE └── jquery-jvectormap-2.0.1.min.js /README.md: -------------------------------------------------------------------------------- 1 | jVectorMap-Turkey 2 | ================= 3 | 4 | jVectorMap Türkiye Haritası Eklentisi / jVectorMap Turkey Map Plugin 5 | #Javascript, #jQuery 6 | 7 | jVectorMap Sayfası: 8 | http://jvectormap.com 9 | 10 | İlk Esin Kaynağı: 11 | http://avpar.blogspot.com.tr/2014/03/jvector-map-turkiye.html 12 | 13 | 14 | ```javascript 15 | $('#world-map').vectorMap( 16 | { 17 | map: 'turkey_1_mill_en' 18 | }); 19 | ``` 20 | 21 | Diğer alternatifleri; 22 | https://github.com/aytacsunar/turkey-map-jquery-with-jqvmap 23 | 24 | Canbey Bilgili 25 | http://www.emanova.com 26 | http://www.xanbei.com 27 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | jVectorMap Turkey demo 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 18 | 19 | -------------------------------------------------------------------------------- /jquery-jvectormap-2.0.1.css: -------------------------------------------------------------------------------- 1 | .jvectormap-container { 2 | width: 100%; 3 | height: 100%; 4 | position: relative; 5 | overflow: hidden; 6 | } 7 | 8 | .jvectormap-tip { 9 | position: absolute; 10 | display: none; 11 | border: solid 1px #CDCDCD; 12 | border-radius: 3px; 13 | background: #292929; 14 | color: white; 15 | font-family: sans-serif, Verdana; 16 | font-size: smaller; 17 | padding: 3px; 18 | } 19 | 20 | .jvectormap-zoomin, .jvectormap-zoomout, .jvectormap-goback { 21 | position: absolute; 22 | left: 10px; 23 | border-radius: 3px; 24 | background: #292929; 25 | padding: 3px; 26 | color: white; 27 | cursor: pointer; 28 | line-height: 10px; 29 | text-align: center; 30 | } 31 | 32 | .jvectormap-zoomin, .jvectormap-zoomout { 33 | width: 10px; 34 | height: 10px; 35 | } 36 | 37 | .jvectormap-zoomin { 38 | top: 10px; 39 | } 40 | 41 | .jvectormap-zoomout { 42 | top: 30px; 43 | } 44 | 45 | .jvectormap-goback { 46 | bottom: 10px; 47 | z-index: 1000; 48 | padding: 6px; 49 | } 50 | 51 | .jvectormap-spinner { 52 | position: absolute; 53 | left: 0; 54 | top: 0; 55 | right: 0; 56 | bottom: 0; 57 | background: center no-repeat url(data:image/gif;base64,R0lGODlhIAAgAPMAAP///wAAAMbGxoSEhLa2tpqamjY2NlZWVtjY2OTk5Ly8vB4eHgQEBAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAIAAgAAAE5xDISWlhperN52JLhSSdRgwVo1ICQZRUsiwHpTJT4iowNS8vyW2icCF6k8HMMBkCEDskxTBDAZwuAkkqIfxIQyhBQBFvAQSDITM5VDW6XNE4KagNh6Bgwe60smQUB3d4Rz1ZBApnFASDd0hihh12BkE9kjAJVlycXIg7CQIFA6SlnJ87paqbSKiKoqusnbMdmDC2tXQlkUhziYtyWTxIfy6BE8WJt5YJvpJivxNaGmLHT0VnOgSYf0dZXS7APdpB309RnHOG5gDqXGLDaC457D1zZ/V/nmOM82XiHRLYKhKP1oZmADdEAAAh+QQJCgAAACwAAAAAIAAgAAAE6hDISWlZpOrNp1lGNRSdRpDUolIGw5RUYhhHukqFu8DsrEyqnWThGvAmhVlteBvojpTDDBUEIFwMFBRAmBkSgOrBFZogCASwBDEY/CZSg7GSE0gSCjQBMVG023xWBhklAnoEdhQEfyNqMIcKjhRsjEdnezB+A4k8gTwJhFuiW4dokXiloUepBAp5qaKpp6+Ho7aWW54wl7obvEe0kRuoplCGepwSx2jJvqHEmGt6whJpGpfJCHmOoNHKaHx61WiSR92E4lbFoq+B6QDtuetcaBPnW6+O7wDHpIiK9SaVK5GgV543tzjgGcghAgAh+QQJCgAAACwAAAAAIAAgAAAE7hDISSkxpOrN5zFHNWRdhSiVoVLHspRUMoyUakyEe8PTPCATW9A14E0UvuAKMNAZKYUZCiBMuBakSQKG8G2FzUWox2AUtAQFcBKlVQoLgQReZhQlCIJesQXI5B0CBnUMOxMCenoCfTCEWBsJColTMANldx15BGs8B5wlCZ9Po6OJkwmRpnqkqnuSrayqfKmqpLajoiW5HJq7FL1Gr2mMMcKUMIiJgIemy7xZtJsTmsM4xHiKv5KMCXqfyUCJEonXPN2rAOIAmsfB3uPoAK++G+w48edZPK+M6hLJpQg484enXIdQFSS1u6UhksENEQAAIfkECQoAAAAsAAAAACAAIAAABOcQyEmpGKLqzWcZRVUQnZYg1aBSh2GUVEIQ2aQOE+G+cD4ntpWkZQj1JIiZIogDFFyHI0UxQwFugMSOFIPJftfVAEoZLBbcLEFhlQiqGp1Vd140AUklUN3eCA51C1EWMzMCezCBBmkxVIVHBWd3HHl9JQOIJSdSnJ0TDKChCwUJjoWMPaGqDKannasMo6WnM562R5YluZRwur0wpgqZE7NKUm+FNRPIhjBJxKZteWuIBMN4zRMIVIhffcgojwCF117i4nlLnY5ztRLsnOk+aV+oJY7V7m76PdkS4trKcdg0Zc0tTcKkRAAAIfkECQoAAAAsAAAAACAAIAAABO4QyEkpKqjqzScpRaVkXZWQEximw1BSCUEIlDohrft6cpKCk5xid5MNJTaAIkekKGQkWyKHkvhKsR7ARmitkAYDYRIbUQRQjWBwJRzChi9CRlBcY1UN4g0/VNB0AlcvcAYHRyZPdEQFYV8ccwR5HWxEJ02YmRMLnJ1xCYp0Y5idpQuhopmmC2KgojKasUQDk5BNAwwMOh2RtRq5uQuPZKGIJQIGwAwGf6I0JXMpC8C7kXWDBINFMxS4DKMAWVWAGYsAdNqW5uaRxkSKJOZKaU3tPOBZ4DuK2LATgJhkPJMgTwKCdFjyPHEnKxFCDhEAACH5BAkKAAAALAAAAAAgACAAAATzEMhJaVKp6s2nIkolIJ2WkBShpkVRWqqQrhLSEu9MZJKK9y1ZrqYK9WiClmvoUaF8gIQSNeF1Er4MNFn4SRSDARWroAIETg1iVwuHjYB1kYc1mwruwXKC9gmsJXliGxc+XiUCby9ydh1sOSdMkpMTBpaXBzsfhoc5l58Gm5yToAaZhaOUqjkDgCWNHAULCwOLaTmzswadEqggQwgHuQsHIoZCHQMMQgQGubVEcxOPFAcMDAYUA85eWARmfSRQCdcMe0zeP1AAygwLlJtPNAAL19DARdPzBOWSm1brJBi45soRAWQAAkrQIykShQ9wVhHCwCQCACH5BAkKAAAALAAAAAAgACAAAATrEMhJaVKp6s2nIkqFZF2VIBWhUsJaTokqUCoBq+E71SRQeyqUToLA7VxF0JDyIQh/MVVPMt1ECZlfcjZJ9mIKoaTl1MRIl5o4CUKXOwmyrCInCKqcWtvadL2SYhyASyNDJ0uIiRMDjI0Fd30/iI2UA5GSS5UDj2l6NoqgOgN4gksEBgYFf0FDqKgHnyZ9OX8HrgYHdHpcHQULXAS2qKpENRg7eAMLC7kTBaixUYFkKAzWAAnLC7FLVxLWDBLKCwaKTULgEwbLA4hJtOkSBNqITT3xEgfLpBtzE/jiuL04RGEBgwWhShRgQExHBAAh+QQJCgAAACwAAAAAIAAgAAAE7xDISWlSqerNpyJKhWRdlSAVoVLCWk6JKlAqAavhO9UkUHsqlE6CwO1cRdCQ8iEIfzFVTzLdRAmZX3I2SfZiCqGk5dTESJeaOAlClzsJsqwiJwiqnFrb2nS9kmIcgEsjQydLiIlHehhpejaIjzh9eomSjZR+ipslWIRLAgMDOR2DOqKogTB9pCUJBagDBXR6XB0EBkIIsaRsGGMMAxoDBgYHTKJiUYEGDAzHC9EACcUGkIgFzgwZ0QsSBcXHiQvOwgDdEwfFs0sDzt4S6BK4xYjkDOzn0unFeBzOBijIm1Dgmg5YFQwsCMjp1oJ8LyIAACH5BAkKAAAALAAAAAAgACAAAATwEMhJaVKp6s2nIkqFZF2VIBWhUsJaTokqUCoBq+E71SRQeyqUToLA7VxF0JDyIQh/MVVPMt1ECZlfcjZJ9mIKoaTl1MRIl5o4CUKXOwmyrCInCKqcWtvadL2SYhyASyNDJ0uIiUd6GGl6NoiPOH16iZKNlH6KmyWFOggHhEEvAwwMA0N9GBsEC6amhnVcEwavDAazGwIDaH1ipaYLBUTCGgQDA8NdHz0FpqgTBwsLqAbWAAnIA4FWKdMLGdYGEgraigbT0OITBcg5QwPT4xLrROZL6AuQAPUS7bxLpoWidY0JtxLHKhwwMJBTHgPKdEQAACH5BAkKAAAALAAAAAAgACAAAATrEMhJaVKp6s2nIkqFZF2VIBWhUsJaTokqUCoBq+E71SRQeyqUToLA7VxF0JDyIQh/MVVPMt1ECZlfcjZJ9mIKoaTl1MRIl5o4CUKXOwmyrCInCKqcWtvadL2SYhyASyNDJ0uIiUd6GAULDJCRiXo1CpGXDJOUjY+Yip9DhToJA4RBLwMLCwVDfRgbBAaqqoZ1XBMHswsHtxtFaH1iqaoGNgAIxRpbFAgfPQSqpbgGBqUD1wBXeCYp1AYZ19JJOYgH1KwA4UBvQwXUBxPqVD9L3sbp2BNk2xvvFPJd+MFCN6HAAIKgNggY0KtEBAAh+QQJCgAAACwAAAAAIAAgAAAE6BDISWlSqerNpyJKhWRdlSAVoVLCWk6JKlAqAavhO9UkUHsqlE6CwO1cRdCQ8iEIfzFVTzLdRAmZX3I2SfYIDMaAFdTESJeaEDAIMxYFqrOUaNW4E4ObYcCXaiBVEgULe0NJaxxtYksjh2NLkZISgDgJhHthkpU4mW6blRiYmZOlh4JWkDqILwUGBnE6TYEbCgevr0N1gH4At7gHiRpFaLNrrq8HNgAJA70AWxQIH1+vsYMDAzZQPC9VCNkDWUhGkuE5PxJNwiUK4UfLzOlD4WvzAHaoG9nxPi5d+jYUqfAhhykOFwJWiAAAIfkECQoAAAAsAAAAACAAIAAABPAQyElpUqnqzaciSoVkXVUMFaFSwlpOCcMYlErAavhOMnNLNo8KsZsMZItJEIDIFSkLGQoQTNhIsFehRww2CQLKF0tYGKYSg+ygsZIuNqJksKgbfgIGepNo2cIUB3V1B3IvNiBYNQaDSTtfhhx0CwVPI0UJe0+bm4g5VgcGoqOcnjmjqDSdnhgEoamcsZuXO1aWQy8KAwOAuTYYGwi7w5h+Kr0SJ8MFihpNbx+4Erq7BYBuzsdiH1jCAzoSfl0rVirNbRXlBBlLX+BP0XJLAPGzTkAuAOqb0WT5AH7OcdCm5B8TgRwSRKIHQtaLCwg1RAAAOwAAAAAAAAAAAA==); 58 | } 59 | 60 | .jvectormap-legend-title { 61 | font-weight: bold; 62 | font-size: 14px; 63 | text-align: center; 64 | } 65 | 66 | .jvectormap-legend-cnt { 67 | position: absolute; 68 | } 69 | 70 | .jvectormap-legend-cnt-h { 71 | bottom: 0; 72 | right: 0; 73 | } 74 | 75 | .jvectormap-legend-cnt-v { 76 | top: 0; 77 | right: 0; 78 | } 79 | 80 | .jvectormap-legend { 81 | background: black; 82 | color: white; 83 | border-radius: 3px; 84 | } 85 | 86 | .jvectormap-legend-cnt-h .jvectormap-legend { 87 | float: left; 88 | margin: 0 10px 10px 0; 89 | padding: 3px 3px 1px 3px; 90 | } 91 | 92 | .jvectormap-legend-cnt-h .jvectormap-legend .jvectormap-legend-tick { 93 | float: left; 94 | } 95 | 96 | .jvectormap-legend-cnt-v .jvectormap-legend { 97 | margin: 10px 10px 0 0; 98 | padding: 3px; 99 | } 100 | 101 | .jvectormap-legend-cnt-h .jvectormap-legend-tick { 102 | width: 40px; 103 | } 104 | 105 | .jvectormap-legend-cnt-h .jvectormap-legend-tick-sample { 106 | height: 15px; 107 | } 108 | 109 | .jvectormap-legend-cnt-v .jvectormap-legend-tick-sample { 110 | height: 20px; 111 | width: 20px; 112 | display: inline-block; 113 | vertical-align: middle; 114 | } 115 | 116 | .jvectormap-legend-tick-text { 117 | font-size: 12px; 118 | } 119 | 120 | .jvectormap-legend-cnt-h .jvectormap-legend-tick-text { 121 | text-align: center; 122 | } 123 | 124 | .jvectormap-legend-cnt-v .jvectormap-legend-tick-text { 125 | display: inline-block; 126 | vertical-align: middle; 127 | line-height: 20px; 128 | padding-left: 3px; 129 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /jquery-jvectormap-2.0.1.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * jVectorMap version 2.0.1 3 | * 4 | * Copyright 2011-2014, Kirill Lebedev 5 | * 6 | */ 7 | 8 | (function( $ ){ 9 | var apiParams = { 10 | set: { 11 | colors: 1, 12 | values: 1, 13 | backgroundColor: 1, 14 | scaleColors: 1, 15 | normalizeFunction: 1, 16 | focus: 1 17 | }, 18 | get: { 19 | selectedRegions: 1, 20 | selectedMarkers: 1, 21 | mapObject: 1, 22 | regionName: 1 23 | } 24 | }; 25 | 26 | $.fn.vectorMap = function(options) { 27 | var map, 28 | methodName, 29 | map = this.children('.jvectormap-container').data('mapObject'); 30 | 31 | if (options === 'addMap') { 32 | jvm.Map.maps[arguments[1]] = arguments[2]; 33 | } else if ((options === 'set' || options === 'get') && apiParams[options][arguments[1]]) { 34 | methodName = arguments[1].charAt(0).toUpperCase()+arguments[1].substr(1); 35 | return map[options+methodName].apply(map, Array.prototype.slice.call(arguments, 2)); 36 | } else { 37 | options = options || {}; 38 | options.container = this; 39 | map = new jvm.Map(options); 40 | } 41 | 42 | return this; 43 | }; 44 | })( jQuery ); 45 | /*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh) 46 | * Licensed under the MIT License (LICENSE.txt). 47 | * 48 | * Version: 3.1.9 49 | * 50 | * Requires: jQuery 1.2.2+ 51 | */ 52 | 53 | (function (factory) { 54 | if ( typeof define === 'function' && define.amd ) { 55 | // AMD. Register as an anonymous module. 56 | define(['jquery'], factory); 57 | } else if (typeof exports === 'object') { 58 | // Node/CommonJS style for Browserify 59 | module.exports = factory; 60 | } else { 61 | // Browser globals 62 | factory(jQuery); 63 | } 64 | }(function ($) { 65 | 66 | var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'], 67 | toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ? 68 | ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'], 69 | slice = Array.prototype.slice, 70 | nullLowestDeltaTimeout, lowestDelta; 71 | 72 | if ( $.event.fixHooks ) { 73 | for ( var i = toFix.length; i; ) { 74 | $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks; 75 | } 76 | } 77 | 78 | var special = $.event.special.mousewheel = { 79 | version: '3.1.9', 80 | 81 | setup: function() { 82 | if ( this.addEventListener ) { 83 | for ( var i = toBind.length; i; ) { 84 | this.addEventListener( toBind[--i], handler, false ); 85 | } 86 | } else { 87 | this.onmousewheel = handler; 88 | } 89 | // Store the line height and page height for this particular element 90 | $.data(this, 'mousewheel-line-height', special.getLineHeight(this)); 91 | $.data(this, 'mousewheel-page-height', special.getPageHeight(this)); 92 | }, 93 | 94 | teardown: function() { 95 | if ( this.removeEventListener ) { 96 | for ( var i = toBind.length; i; ) { 97 | this.removeEventListener( toBind[--i], handler, false ); 98 | } 99 | } else { 100 | this.onmousewheel = null; 101 | } 102 | }, 103 | 104 | getLineHeight: function(elem) { 105 | return parseInt($(elem)['offsetParent' in $.fn ? 'offsetParent' : 'parent']().css('fontSize'), 10); 106 | }, 107 | 108 | getPageHeight: function(elem) { 109 | return $(elem).height(); 110 | }, 111 | 112 | settings: { 113 | adjustOldDeltas: true 114 | } 115 | }; 116 | 117 | $.fn.extend({ 118 | mousewheel: function(fn) { 119 | return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel'); 120 | }, 121 | 122 | unmousewheel: function(fn) { 123 | return this.unbind('mousewheel', fn); 124 | } 125 | }); 126 | 127 | 128 | function handler(event) { 129 | var orgEvent = event || window.event, 130 | args = slice.call(arguments, 1), 131 | delta = 0, 132 | deltaX = 0, 133 | deltaY = 0, 134 | absDelta = 0; 135 | event = $.event.fix(orgEvent); 136 | event.type = 'mousewheel'; 137 | 138 | // Old school scrollwheel delta 139 | if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; } 140 | if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; } 141 | if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; } 142 | if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; } 143 | 144 | // Firefox < 17 horizontal scrolling related to DOMMouseScroll event 145 | if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) { 146 | deltaX = deltaY * -1; 147 | deltaY = 0; 148 | } 149 | 150 | // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy 151 | delta = deltaY === 0 ? deltaX : deltaY; 152 | 153 | // New school wheel delta (wheel event) 154 | if ( 'deltaY' in orgEvent ) { 155 | deltaY = orgEvent.deltaY * -1; 156 | delta = deltaY; 157 | } 158 | if ( 'deltaX' in orgEvent ) { 159 | deltaX = orgEvent.deltaX; 160 | if ( deltaY === 0 ) { delta = deltaX * -1; } 161 | } 162 | 163 | // No change actually happened, no reason to go any further 164 | if ( deltaY === 0 && deltaX === 0 ) { return; } 165 | 166 | // Need to convert lines and pages to pixels if we aren't already in pixels 167 | // There are three delta modes: 168 | // * deltaMode 0 is by pixels, nothing to do 169 | // * deltaMode 1 is by lines 170 | // * deltaMode 2 is by pages 171 | if ( orgEvent.deltaMode === 1 ) { 172 | var lineHeight = $.data(this, 'mousewheel-line-height'); 173 | delta *= lineHeight; 174 | deltaY *= lineHeight; 175 | deltaX *= lineHeight; 176 | } else if ( orgEvent.deltaMode === 2 ) { 177 | var pageHeight = $.data(this, 'mousewheel-page-height'); 178 | delta *= pageHeight; 179 | deltaY *= pageHeight; 180 | deltaX *= pageHeight; 181 | } 182 | 183 | // Store lowest absolute delta to normalize the delta values 184 | absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) ); 185 | 186 | if ( !lowestDelta || absDelta < lowestDelta ) { 187 | lowestDelta = absDelta; 188 | 189 | // Adjust older deltas if necessary 190 | if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) { 191 | lowestDelta /= 40; 192 | } 193 | } 194 | 195 | // Adjust older deltas if necessary 196 | if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) { 197 | // Divide all the things by 40! 198 | delta /= 40; 199 | deltaX /= 40; 200 | deltaY /= 40; 201 | } 202 | 203 | // Get a whole, normalized value for the deltas 204 | delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta); 205 | deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta); 206 | deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta); 207 | 208 | // Add information to the event object 209 | event.deltaX = deltaX; 210 | event.deltaY = deltaY; 211 | event.deltaFactor = lowestDelta; 212 | // Go ahead and set deltaMode to 0 since we converted to pixels 213 | // Although this is a little odd since we overwrite the deltaX/Y 214 | // properties with normalized deltas. 215 | event.deltaMode = 0; 216 | 217 | // Add event and delta to the front of the arguments 218 | args.unshift(event, delta, deltaX, deltaY); 219 | 220 | // Clearout lowestDelta after sometime to better 221 | // handle multiple device types that give different 222 | // a different lowestDelta 223 | // Ex: trackpad = 3 and mouse wheel = 120 224 | if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); } 225 | nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200); 226 | 227 | return ($.event.dispatch || $.event.handle).apply(this, args); 228 | } 229 | 230 | function nullLowestDelta() { 231 | lowestDelta = null; 232 | } 233 | 234 | function shouldAdjustOldDeltas(orgEvent, absDelta) { 235 | // If this is an older event and the delta is divisable by 120, 236 | // then we are assuming that the browser is treating this as an 237 | // older mouse wheel event and that we should divide the deltas 238 | // by 40 to try and get a more usable deltaFactor. 239 | // Side note, this actually impacts the reported scroll distance 240 | // in older browsers and can cause scrolling to be slower than native. 241 | // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false. 242 | return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0; 243 | } 244 | 245 | }));/** 246 | * @namespace jvm Holds core methods and classes used by jVectorMap. 247 | */ 248 | var jvm = { 249 | 250 | /** 251 | * Inherits child's prototype from the parent's one. 252 | * @param {Function} child 253 | * @param {Function} parent 254 | */ 255 | inherits: function(child, parent) { 256 | function temp() {} 257 | temp.prototype = parent.prototype; 258 | child.prototype = new temp(); 259 | child.prototype.constructor = child; 260 | child.parentClass = parent; 261 | }, 262 | 263 | /** 264 | * Mixes in methods from the source constructor to the target one. 265 | * @param {Function} target 266 | * @param {Function} source 267 | */ 268 | mixin: function(target, source){ 269 | var prop; 270 | 271 | for (prop in source.prototype) { 272 | if (source.prototype.hasOwnProperty(prop)) { 273 | target.prototype[prop] = source.prototype[prop]; 274 | } 275 | } 276 | }, 277 | 278 | min: function(values){ 279 | var min = Number.MAX_VALUE, 280 | i; 281 | 282 | if (values instanceof Array) { 283 | for (i = 0; i < values.length; i++) { 284 | if (values[i] < min) { 285 | min = values[i]; 286 | } 287 | } 288 | } else { 289 | for (i in values) { 290 | if (values[i] < min) { 291 | min = values[i]; 292 | } 293 | } 294 | } 295 | return min; 296 | }, 297 | 298 | max: function(values){ 299 | var max = Number.MIN_VALUE, 300 | i; 301 | 302 | if (values instanceof Array) { 303 | for (i = 0; i < values.length; i++) { 304 | if (values[i] > max) { 305 | max = values[i]; 306 | } 307 | } 308 | } else { 309 | for (i in values) { 310 | if (values[i] > max) { 311 | max = values[i]; 312 | } 313 | } 314 | } 315 | return max; 316 | }, 317 | 318 | keys: function(object){ 319 | var keys = [], 320 | key; 321 | 322 | for (key in object) { 323 | keys.push(key); 324 | } 325 | return keys; 326 | }, 327 | 328 | values: function(object){ 329 | var values = [], 330 | key, 331 | i; 332 | 333 | for (i = 0; i < arguments.length; i++) { 334 | object = arguments[i]; 335 | for (key in object) { 336 | values.push(object[key]); 337 | } 338 | } 339 | return values; 340 | }, 341 | 342 | whenImageLoaded: function(url){ 343 | var deferred = new jvm.$.Deferred(), 344 | img = jvm.$(''); 345 | 346 | img.error(function(){ 347 | deferred.reject(); 348 | }).load(function(){ 349 | deferred.resolve(img); 350 | }); 351 | img.attr('src', url); 352 | 353 | return deferred; 354 | }, 355 | 356 | isImageUrl: function(s){ 357 | return /\.\w{3,4}$/.test(s); 358 | } 359 | }; 360 | 361 | jvm.$ = jQuery; 362 | 363 | /** 364 | * indexOf polyfill for IE < 9 365 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf 366 | */ 367 | if (!Array.prototype.indexOf) { 368 | Array.prototype.indexOf = function (searchElement, fromIndex) { 369 | 370 | var k; 371 | 372 | // 1. Let O be the result of calling ToObject passing 373 | // the this value as the argument. 374 | if (this == null) { 375 | throw new TypeError('"this" is null or not defined'); 376 | } 377 | 378 | var O = Object(this); 379 | 380 | // 2. Let lenValue be the result of calling the Get 381 | // internal method of O with the argument "length". 382 | // 3. Let len be ToUint32(lenValue). 383 | var len = O.length >>> 0; 384 | 385 | // 4. If len is 0, return -1. 386 | if (len === 0) { 387 | return -1; 388 | } 389 | 390 | // 5. If argument fromIndex was passed let n be 391 | // ToInteger(fromIndex); else let n be 0. 392 | var n = +fromIndex || 0; 393 | 394 | if (Math.abs(n) === Infinity) { 395 | n = 0; 396 | } 397 | 398 | // 6. If n >= len, return -1. 399 | if (n >= len) { 400 | return -1; 401 | } 402 | 403 | // 7. If n >= 0, then Let k be n. 404 | // 8. Else, n<0, Let k be len - abs(n). 405 | // If k is less than 0, then let k be 0. 406 | k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); 407 | 408 | // 9. Repeat, while k < len 409 | while (k < len) { 410 | // a. Let Pk be ToString(k). 411 | // This is implicit for LHS operands of the in operator 412 | // b. Let kPresent be the result of calling the 413 | // HasProperty internal method of O with argument Pk. 414 | // This step can be combined with c 415 | // c. If kPresent is true, then 416 | // i. Let elementK be the result of calling the Get 417 | // internal method of O with the argument ToString(k). 418 | // ii. Let same be the result of applying the 419 | // Strict Equality Comparison Algorithm to 420 | // searchElement and elementK. 421 | // iii. If same is true, return k. 422 | if (k in O && O[k] === searchElement) { 423 | return k; 424 | } 425 | k++; 426 | } 427 | return -1; 428 | }; 429 | }/** 430 | * Basic wrapper for DOM element. 431 | * @constructor 432 | * @param {String} name Tag name of the element 433 | * @param {Object} config Set of parameters to initialize element with 434 | */ 435 | jvm.AbstractElement = function(name, config){ 436 | /** 437 | * Underlying DOM element 438 | * @type {DOMElement} 439 | * @private 440 | */ 441 | this.node = this.createElement(name); 442 | 443 | /** 444 | * Name of underlying element 445 | * @type {String} 446 | * @private 447 | */ 448 | this.name = name; 449 | 450 | /** 451 | * Internal store of attributes 452 | * @type {Object} 453 | * @private 454 | */ 455 | this.properties = {}; 456 | 457 | if (config) { 458 | this.set(config); 459 | } 460 | }; 461 | 462 | /** 463 | * Set attribute of the underlying DOM element. 464 | * @param {String} name Name of attribute 465 | * @param {Number|String} config Set of parameters to initialize element with 466 | */ 467 | jvm.AbstractElement.prototype.set = function(property, value){ 468 | var key; 469 | 470 | if (typeof property === 'object') { 471 | for (key in property) { 472 | this.properties[key] = property[key]; 473 | this.applyAttr(key, property[key]); 474 | } 475 | } else { 476 | this.properties[property] = value; 477 | this.applyAttr(property, value); 478 | } 479 | }; 480 | 481 | /** 482 | * Returns value of attribute. 483 | * @param {String} name Name of attribute 484 | */ 485 | jvm.AbstractElement.prototype.get = function(property){ 486 | return this.properties[property]; 487 | }; 488 | 489 | /** 490 | * Applies attribute value to the underlying DOM element. 491 | * @param {String} name Name of attribute 492 | * @param {Number|String} config Value of attribute to apply 493 | * @private 494 | */ 495 | jvm.AbstractElement.prototype.applyAttr = function(property, value){ 496 | this.node.setAttribute(property, value); 497 | }; 498 | 499 | jvm.AbstractElement.prototype.remove = function(){ 500 | jvm.$(this.node).remove(); 501 | };/** 502 | * Implements abstract vector canvas. 503 | * @constructor 504 | * @param {HTMLElement} container Container to put element to. 505 | * @param {Number} width Width of canvas. 506 | * @param {Number} height Height of canvas. 507 | */ 508 | jvm.AbstractCanvasElement = function(container, width, height){ 509 | this.container = container; 510 | this.setSize(width, height); 511 | this.rootElement = new jvm[this.classPrefix+'GroupElement'](); 512 | this.node.appendChild( this.rootElement.node ); 513 | this.container.appendChild(this.node); 514 | } 515 | 516 | /** 517 | * Add element to the certain group inside of the canvas. 518 | * @param {HTMLElement} element Element to add to canvas. 519 | * @param {HTMLElement} group Group to add element into or into root group if not provided. 520 | */ 521 | jvm.AbstractCanvasElement.prototype.add = function(element, group){ 522 | group = group || this.rootElement; 523 | group.add(element); 524 | element.canvas = this; 525 | } 526 | 527 | /** 528 | * Create path and add it to the canvas. 529 | * @param {Object} config Parameters of path to create. 530 | * @param {Object} style Styles of the path to create. 531 | * @param {HTMLElement} group Group to add path into. 532 | */ 533 | jvm.AbstractCanvasElement.prototype.addPath = function(config, style, group){ 534 | var el = new jvm[this.classPrefix+'PathElement'](config, style); 535 | 536 | this.add(el, group); 537 | return el; 538 | }; 539 | 540 | /** 541 | * Create circle and add it to the canvas. 542 | * @param {Object} config Parameters of path to create. 543 | * @param {Object} style Styles of the path to create. 544 | * @param {HTMLElement} group Group to add circle into. 545 | */ 546 | jvm.AbstractCanvasElement.prototype.addCircle = function(config, style, group){ 547 | var el = new jvm[this.classPrefix+'CircleElement'](config, style); 548 | 549 | this.add(el, group); 550 | return el; 551 | }; 552 | 553 | /** 554 | * Create circle and add it to the canvas. 555 | * @param {Object} config Parameters of path to create. 556 | * @param {Object} style Styles of the path to create. 557 | * @param {HTMLElement} group Group to add circle into. 558 | */ 559 | jvm.AbstractCanvasElement.prototype.addImage = function(config, style, group){ 560 | var el = new jvm[this.classPrefix+'ImageElement'](config, style); 561 | 562 | this.add(el, group); 563 | return el; 564 | }; 565 | 566 | /** 567 | * Create text and add it to the canvas. 568 | * @param {Object} config Parameters of path to create. 569 | * @param {Object} style Styles of the path to create. 570 | * @param {HTMLElement} group Group to add circle into. 571 | */ 572 | jvm.AbstractCanvasElement.prototype.addText = function(config, style, group){ 573 | var el = new jvm[this.classPrefix+'TextElement'](config, style); 574 | 575 | this.add(el, group); 576 | return el; 577 | }; 578 | 579 | /** 580 | * Add group to the another group inside of the canvas. 581 | * @param {HTMLElement} group Group to add circle into or root group if not provided. 582 | */ 583 | jvm.AbstractCanvasElement.prototype.addGroup = function(parentGroup){ 584 | var el = new jvm[this.classPrefix+'GroupElement'](); 585 | 586 | if (parentGroup) { 587 | parentGroup.node.appendChild(el.node); 588 | } else { 589 | this.node.appendChild(el.node); 590 | } 591 | el.canvas = this; 592 | return el; 593 | };/** 594 | * Abstract shape element. Shape element represents some visual vector or raster object. 595 | * @constructor 596 | * @param {String} name Tag name of the element. 597 | * @param {Object} config Set of parameters to initialize element with. 598 | * @param {Object} style Object with styles to set on element initialization. 599 | */ 600 | jvm.AbstractShapeElement = function(name, config, style){ 601 | this.style = style || {}; 602 | this.style.current = this.style.current || {}; 603 | this.isHovered = false; 604 | this.isSelected = false; 605 | this.updateStyle(); 606 | }; 607 | 608 | /** 609 | * Set element's style. 610 | * @param {Object|String} property Could be string to set only one property or object to set several style properties at once. 611 | * @param {String} value Value to set in case only one property should be set. 612 | */ 613 | jvm.AbstractShapeElement.prototype.setStyle = function(property, value){ 614 | var styles = {}; 615 | 616 | if (typeof property === 'object') { 617 | styles = property; 618 | } else { 619 | styles[property] = value; 620 | } 621 | jvm.$.extend(this.style.current, styles); 622 | this.updateStyle(); 623 | }; 624 | 625 | 626 | jvm.AbstractShapeElement.prototype.updateStyle = function(){ 627 | var attrs = {}; 628 | 629 | jvm.AbstractShapeElement.mergeStyles(attrs, this.style.initial); 630 | jvm.AbstractShapeElement.mergeStyles(attrs, this.style.current); 631 | if (this.isHovered) { 632 | jvm.AbstractShapeElement.mergeStyles(attrs, this.style.hover); 633 | } 634 | if (this.isSelected) { 635 | jvm.AbstractShapeElement.mergeStyles(attrs, this.style.selected); 636 | if (this.isHovered) { 637 | jvm.AbstractShapeElement.mergeStyles(attrs, this.style.selectedHover); 638 | } 639 | } 640 | this.set(attrs); 641 | }; 642 | 643 | jvm.AbstractShapeElement.mergeStyles = function(styles, newStyles){ 644 | var key; 645 | 646 | newStyles = newStyles || {}; 647 | for (key in newStyles) { 648 | if (newStyles[key] === null) { 649 | delete styles[key]; 650 | } else { 651 | styles[key] = newStyles[key]; 652 | } 653 | } 654 | }/** 655 | * Wrapper for SVG element. 656 | * @constructor 657 | * @extends jvm.AbstractElement 658 | * @param {String} name Tag name of the element 659 | * @param {Object} config Set of parameters to initialize element with 660 | */ 661 | 662 | jvm.SVGElement = function(name, config){ 663 | jvm.SVGElement.parentClass.apply(this, arguments); 664 | } 665 | 666 | jvm.inherits(jvm.SVGElement, jvm.AbstractElement); 667 | 668 | jvm.SVGElement.svgns = "http://www.w3.org/2000/svg"; 669 | 670 | /** 671 | * Creates DOM element. 672 | * @param {String} tagName Name of element 673 | * @private 674 | * @returns DOMElement 675 | */ 676 | jvm.SVGElement.prototype.createElement = function( tagName ){ 677 | return document.createElementNS( jvm.SVGElement.svgns, tagName ); 678 | }; 679 | 680 | /** 681 | * Adds CSS class for underlying DOM element. 682 | * @param {String} className Name of CSS class name 683 | */ 684 | jvm.SVGElement.prototype.addClass = function( className ){ 685 | this.node.setAttribute('class', className); 686 | }; 687 | 688 | /** 689 | * Returns constructor for element by name prefixed with 'VML'. 690 | * @param {String} ctr Name of basic constructor to return 691 | * proper implementation for. 692 | * @returns Function 693 | * @private 694 | */ 695 | jvm.SVGElement.prototype.getElementCtr = function( ctr ){ 696 | return jvm['SVG'+ctr]; 697 | }; 698 | 699 | jvm.SVGElement.prototype.getBBox = function(){ 700 | return this.node.getBBox(); 701 | };jvm.SVGGroupElement = function(){ 702 | jvm.SVGGroupElement.parentClass.call(this, 'g'); 703 | } 704 | 705 | jvm.inherits(jvm.SVGGroupElement, jvm.SVGElement); 706 | 707 | jvm.SVGGroupElement.prototype.add = function(element){ 708 | this.node.appendChild( element.node ); 709 | };jvm.SVGCanvasElement = function(container, width, height){ 710 | this.classPrefix = 'SVG'; 711 | jvm.SVGCanvasElement.parentClass.call(this, 'svg'); 712 | 713 | this.defsElement = new jvm.SVGElement('defs'); 714 | this.node.appendChild( this.defsElement.node ); 715 | 716 | jvm.AbstractCanvasElement.apply(this, arguments); 717 | } 718 | 719 | jvm.inherits(jvm.SVGCanvasElement, jvm.SVGElement); 720 | jvm.mixin(jvm.SVGCanvasElement, jvm.AbstractCanvasElement); 721 | 722 | jvm.SVGCanvasElement.prototype.setSize = function(width, height){ 723 | this.width = width; 724 | this.height = height; 725 | this.node.setAttribute('width', width); 726 | this.node.setAttribute('height', height); 727 | }; 728 | 729 | jvm.SVGCanvasElement.prototype.applyTransformParams = function(scale, transX, transY) { 730 | this.scale = scale; 731 | this.transX = transX; 732 | this.transY = transY; 733 | this.rootElement.node.setAttribute('transform', 'scale('+scale+') translate('+transX+', '+transY+')'); 734 | };jvm.SVGShapeElement = function(name, config, style){ 735 | jvm.SVGShapeElement.parentClass.call(this, name, config); 736 | jvm.AbstractShapeElement.apply(this, arguments); 737 | }; 738 | 739 | jvm.inherits(jvm.SVGShapeElement, jvm.SVGElement); 740 | jvm.mixin(jvm.SVGShapeElement, jvm.AbstractShapeElement); 741 | 742 | jvm.SVGShapeElement.prototype.applyAttr = function(attr, value){ 743 | var patternEl, 744 | imageEl, 745 | that = this; 746 | 747 | if (attr === 'fill' && jvm.isImageUrl(value)) { 748 | if (!jvm.SVGShapeElement.images[value]) { 749 | jvm.whenImageLoaded(value).then(function(img){ 750 | imageEl = new jvm.SVGElement('image'); 751 | imageEl.node.setAttributeNS('http://www.w3.org/1999/xlink', 'href', value); 752 | imageEl.applyAttr('x', '0'); 753 | imageEl.applyAttr('y', '0'); 754 | imageEl.applyAttr('width', img[0].width); 755 | imageEl.applyAttr('height', img[0].height); 756 | 757 | patternEl = new jvm.SVGElement('pattern'); 758 | patternEl.applyAttr('id', 'image'+jvm.SVGShapeElement.imageCounter); 759 | patternEl.applyAttr('x', 0); 760 | patternEl.applyAttr('y', 0); 761 | patternEl.applyAttr('width', img[0].width / 2); 762 | patternEl.applyAttr('height', img[0].height / 2); 763 | patternEl.applyAttr('viewBox', '0 0 '+img[0].width+' '+img[0].height); 764 | patternEl.applyAttr('patternUnits', 'userSpaceOnUse'); 765 | patternEl.node.appendChild( imageEl.node ); 766 | 767 | that.canvas.defsElement.node.appendChild( patternEl.node ); 768 | 769 | jvm.SVGShapeElement.images[value] = jvm.SVGShapeElement.imageCounter++; 770 | 771 | that.applyAttr('fill', 'url(#image'+jvm.SVGShapeElement.images[value]+')'); 772 | }); 773 | } else { 774 | this.applyAttr('fill', 'url(#image'+jvm.SVGShapeElement.images[value]+')'); 775 | } 776 | } else { 777 | jvm.SVGShapeElement.parentClass.prototype.applyAttr.apply(this, arguments); 778 | } 779 | }; 780 | 781 | jvm.SVGShapeElement.imageCounter = 1; 782 | jvm.SVGShapeElement.images = {};jvm.SVGPathElement = function(config, style){ 783 | jvm.SVGPathElement.parentClass.call(this, 'path', config, style); 784 | this.node.setAttribute('fill-rule', 'evenodd'); 785 | } 786 | 787 | jvm.inherits(jvm.SVGPathElement, jvm.SVGShapeElement);jvm.SVGCircleElement = function(config, style){ 788 | jvm.SVGCircleElement.parentClass.call(this, 'circle', config, style); 789 | }; 790 | 791 | jvm.inherits(jvm.SVGCircleElement, jvm.SVGShapeElement);jvm.SVGImageElement = function(config, style){ 792 | jvm.SVGImageElement.parentClass.call(this, 'image', config, style); 793 | }; 794 | 795 | jvm.inherits(jvm.SVGImageElement, jvm.SVGShapeElement); 796 | 797 | jvm.SVGImageElement.prototype.applyAttr = function(attr, value){ 798 | var that = this; 799 | 800 | if (attr == 'image') { 801 | jvm.whenImageLoaded(value).then(function(img){ 802 | that.node.setAttributeNS('http://www.w3.org/1999/xlink', 'href', value); 803 | that.width = img[0].width; 804 | that.height = img[0].height; 805 | that.applyAttr('width', that.width); 806 | that.applyAttr('height', that.height); 807 | 808 | that.applyAttr('x', that.cx - that.width / 2); 809 | that.applyAttr('y', that.cy - that.height / 2); 810 | 811 | jvm.$(that.node).trigger('imageloaded', [img]); 812 | }); 813 | } else if(attr == 'cx') { 814 | this.cx = value; 815 | if (this.width) { 816 | this.applyAttr('x', value - this.width / 2); 817 | } 818 | } else if(attr == 'cy') { 819 | this.cy = value; 820 | if (this.height) { 821 | this.applyAttr('y', value - this.height / 2); 822 | } 823 | } else { 824 | jvm.SVGImageElement.parentClass.prototype.applyAttr.apply(this, arguments); 825 | } 826 | };jvm.SVGTextElement = function(config, style){ 827 | jvm.SVGTextElement.parentClass.call(this, 'text', config, style); 828 | } 829 | 830 | jvm.inherits(jvm.SVGTextElement, jvm.SVGShapeElement); 831 | 832 | jvm.SVGTextElement.prototype.applyAttr = function(attr, value){ 833 | if (attr === 'text') { 834 | this.node.textContent = value; 835 | } else { 836 | jvm.SVGTextElement.parentClass.prototype.applyAttr.apply(this, arguments); 837 | } 838 | };/** 839 | * Wrapper for VML element. 840 | * @constructor 841 | * @extends jvm.AbstractElement 842 | * @param {String} name Tag name of the element 843 | * @param {Object} config Set of parameters to initialize element with 844 | */ 845 | 846 | jvm.VMLElement = function(name, config){ 847 | if (!jvm.VMLElement.VMLInitialized) { 848 | jvm.VMLElement.initializeVML(); 849 | } 850 | 851 | jvm.VMLElement.parentClass.apply(this, arguments); 852 | }; 853 | 854 | jvm.inherits(jvm.VMLElement, jvm.AbstractElement); 855 | 856 | /** 857 | * Shows if VML was already initialized for the current document or not. 858 | * @static 859 | * @private 860 | * @type {Boolean} 861 | */ 862 | jvm.VMLElement.VMLInitialized = false; 863 | 864 | /** 865 | * Initializes VML handling before creating the first element 866 | * (adds CSS class and creates namespace). Adds one of two forms 867 | * of createElement method depending of support by browser. 868 | * @static 869 | * @private 870 | */ 871 | 872 | // The following method of VML handling is borrowed from the 873 | // Raphael library by Dmitry Baranovsky. 874 | 875 | jvm.VMLElement.initializeVML = function(){ 876 | try { 877 | if (!document.namespaces.rvml) { 878 | document.namespaces.add("rvml","urn:schemas-microsoft-com:vml"); 879 | } 880 | /** 881 | * Creates DOM element. 882 | * @param {String} tagName Name of element 883 | * @private 884 | * @returns DOMElement 885 | */ 886 | jvm.VMLElement.prototype.createElement = function (tagName) { 887 | return document.createElement(''); 888 | }; 889 | } catch (e) { 890 | /** 891 | * @private 892 | */ 893 | jvm.VMLElement.prototype.createElement = function (tagName) { 894 | return document.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">'); 895 | }; 896 | } 897 | document.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)"); 898 | jvm.VMLElement.VMLInitialized = true; 899 | }; 900 | 901 | /** 902 | * Returns constructor for element by name prefixed with 'VML'. 903 | * @param {String} ctr Name of basic constructor to return 904 | * proper implementation for. 905 | * @returns Function 906 | * @private 907 | */ 908 | jvm.VMLElement.prototype.getElementCtr = function( ctr ){ 909 | return jvm['VML'+ctr]; 910 | }; 911 | 912 | /** 913 | * Adds CSS class for underlying DOM element. 914 | * @param {String} className Name of CSS class name 915 | */ 916 | jvm.VMLElement.prototype.addClass = function( className ){ 917 | jvm.$(this.node).addClass(className); 918 | }; 919 | 920 | /** 921 | * Applies attribute value to the underlying DOM element. 922 | * @param {String} name Name of attribute 923 | * @param {Number|String} config Value of attribute to apply 924 | * @private 925 | */ 926 | jvm.VMLElement.prototype.applyAttr = function( attr, value ){ 927 | this.node[attr] = value; 928 | }; 929 | 930 | /** 931 | * Returns boundary box for the element. 932 | * @returns {Object} Boundary box with numeric fields: x, y, width, height 933 | * @override 934 | */ 935 | jvm.VMLElement.prototype.getBBox = function(){ 936 | var node = jvm.$(this.node); 937 | 938 | return { 939 | x: node.position().left / this.canvas.scale, 940 | y: node.position().top / this.canvas.scale, 941 | width: node.width() / this.canvas.scale, 942 | height: node.height() / this.canvas.scale 943 | }; 944 | };jvm.VMLGroupElement = function(){ 945 | jvm.VMLGroupElement.parentClass.call(this, 'group'); 946 | 947 | this.node.style.left = '0px'; 948 | this.node.style.top = '0px'; 949 | this.node.coordorigin = "0 0"; 950 | }; 951 | 952 | jvm.inherits(jvm.VMLGroupElement, jvm.VMLElement); 953 | 954 | jvm.VMLGroupElement.prototype.add = function(element){ 955 | this.node.appendChild( element.node ); 956 | };jvm.VMLCanvasElement = function(container, width, height){ 957 | this.classPrefix = 'VML'; 958 | jvm.VMLCanvasElement.parentClass.call(this, 'group'); 959 | jvm.AbstractCanvasElement.apply(this, arguments); 960 | this.node.style.position = 'absolute'; 961 | }; 962 | 963 | jvm.inherits(jvm.VMLCanvasElement, jvm.VMLElement); 964 | jvm.mixin(jvm.VMLCanvasElement, jvm.AbstractCanvasElement); 965 | 966 | jvm.VMLCanvasElement.prototype.setSize = function(width, height){ 967 | var paths, 968 | groups, 969 | i, 970 | l; 971 | 972 | this.width = width; 973 | this.height = height; 974 | this.node.style.width = width + "px"; 975 | this.node.style.height = height + "px"; 976 | this.node.coordsize = width+' '+height; 977 | this.node.coordorigin = "0 0"; 978 | if (this.rootElement) { 979 | paths = this.rootElement.node.getElementsByTagName('shape'); 980 | for(i = 0, l = paths.length; i < l; i++) { 981 | paths[i].coordsize = width+' '+height; 982 | paths[i].style.width = width+'px'; 983 | paths[i].style.height = height+'px'; 984 | } 985 | groups = this.node.getElementsByTagName('group'); 986 | for(i = 0, l = groups.length; i < l; i++) { 987 | groups[i].coordsize = width+' '+height; 988 | groups[i].style.width = width+'px'; 989 | groups[i].style.height = height+'px'; 990 | } 991 | } 992 | }; 993 | 994 | jvm.VMLCanvasElement.prototype.applyTransformParams = function(scale, transX, transY) { 995 | this.scale = scale; 996 | this.transX = transX; 997 | this.transY = transY; 998 | this.rootElement.node.coordorigin = (this.width-transX-this.width/100)+','+(this.height-transY-this.height/100); 999 | this.rootElement.node.coordsize = this.width/scale+','+this.height/scale; 1000 | };jvm.VMLShapeElement = function(name, config){ 1001 | jvm.VMLShapeElement.parentClass.call(this, name, config); 1002 | 1003 | this.fillElement = new jvm.VMLElement('fill'); 1004 | this.strokeElement = new jvm.VMLElement('stroke'); 1005 | this.node.appendChild(this.fillElement.node); 1006 | this.node.appendChild(this.strokeElement.node); 1007 | this.node.stroked = false; 1008 | 1009 | jvm.AbstractShapeElement.apply(this, arguments); 1010 | }; 1011 | 1012 | jvm.inherits(jvm.VMLShapeElement, jvm.VMLElement); 1013 | jvm.mixin(jvm.VMLShapeElement, jvm.AbstractShapeElement); 1014 | 1015 | jvm.VMLShapeElement.prototype.applyAttr = function(attr, value){ 1016 | switch (attr) { 1017 | case 'fill': 1018 | this.node.fillcolor = value; 1019 | break; 1020 | case 'fill-opacity': 1021 | this.fillElement.node.opacity = Math.round(value*100)+'%'; 1022 | break; 1023 | case 'stroke': 1024 | if (value === 'none') { 1025 | this.node.stroked = false; 1026 | } else { 1027 | this.node.stroked = true; 1028 | } 1029 | this.node.strokecolor = value; 1030 | break; 1031 | case 'stroke-opacity': 1032 | this.strokeElement.node.opacity = Math.round(value*100)+'%'; 1033 | break; 1034 | case 'stroke-width': 1035 | if (parseInt(value, 10) === 0) { 1036 | this.node.stroked = false; 1037 | } else { 1038 | this.node.stroked = true; 1039 | } 1040 | this.node.strokeweight = value; 1041 | break; 1042 | case 'd': 1043 | this.node.path = jvm.VMLPathElement.pathSvgToVml(value); 1044 | break; 1045 | default: 1046 | jvm.VMLShapeElement.parentClass.prototype.applyAttr.apply(this, arguments); 1047 | } 1048 | };jvm.VMLPathElement = function(config, style){ 1049 | var scale = new jvm.VMLElement('skew'); 1050 | 1051 | jvm.VMLPathElement.parentClass.call(this, 'shape', config, style); 1052 | 1053 | this.node.coordorigin = "0 0"; 1054 | 1055 | scale.node.on = true; 1056 | scale.node.matrix = '0.01,0,0,0.01,0,0'; 1057 | scale.node.offset = '0,0'; 1058 | 1059 | this.node.appendChild(scale.node); 1060 | }; 1061 | 1062 | jvm.inherits(jvm.VMLPathElement, jvm.VMLShapeElement); 1063 | 1064 | jvm.VMLPathElement.prototype.applyAttr = function(attr, value){ 1065 | if (attr === 'd') { 1066 | this.node.path = jvm.VMLPathElement.pathSvgToVml(value); 1067 | } else { 1068 | jvm.VMLShapeElement.prototype.applyAttr.call(this, attr, value); 1069 | } 1070 | }; 1071 | 1072 | jvm.VMLPathElement.pathSvgToVml = function(path) { 1073 | var cx = 0, cy = 0, ctrlx, ctrly; 1074 | 1075 | path = path.replace(/(-?\d+)e(-?\d+)/g, '0'); 1076 | return path.replace(/([MmLlHhVvCcSs])\s*((?:-?\d*(?:\.\d+)?\s*,?\s*)+)/g, function(segment, letter, coords, index){ 1077 | coords = coords.replace(/(\d)-/g, '$1,-') 1078 | .replace(/^\s+/g, '') 1079 | .replace(/\s+$/g, '') 1080 | .replace(/\s+/g, ',').split(','); 1081 | if (!coords[0]) coords.shift(); 1082 | for (var i=0, l=coords.length; i= 0) { 1290 | value -= lengthes[i]; 1291 | i++; 1292 | } 1293 | 1294 | if (i == this.scale.length - 1) { 1295 | value = this.vectorToNum(this.scale[i]) 1296 | } else { 1297 | value = ( 1298 | this.vectorToNum( 1299 | this.vectorAdd(this.scale[i], 1300 | this.vectorMult( 1301 | this.vectorSubtract(this.scale[i+1], this.scale[i]), 1302 | (value) / (lengthes[i]) 1303 | ) 1304 | ) 1305 | ) 1306 | ); 1307 | } 1308 | 1309 | return value; 1310 | }, 1311 | 1312 | vectorToNum: function(vector) { 1313 | var num = 0, 1314 | i; 1315 | 1316 | for (i = 0; i < vector.length; i++) { 1317 | num += Math.round(vector[i])*Math.pow(256, vector.length-i-1); 1318 | } 1319 | return num; 1320 | }, 1321 | 1322 | vectorSubtract: function(vector1, vector2) { 1323 | var vector = [], 1324 | i; 1325 | 1326 | for (i = 0; i < vector1.length; i++) { 1327 | vector[i] = vector1[i] - vector2[i]; 1328 | } 1329 | return vector; 1330 | }, 1331 | 1332 | vectorAdd: function(vector1, vector2) { 1333 | var vector = [], 1334 | i; 1335 | 1336 | for (i = 0; i < vector1.length; i++) { 1337 | vector[i] = vector1[i] + vector2[i]; 1338 | } 1339 | return vector; 1340 | }, 1341 | 1342 | vectorMult: function(vector, num) { 1343 | var result = [], 1344 | i; 1345 | 1346 | for (i = 0; i < vector.length; i++) { 1347 | result[i] = vector[i] * num; 1348 | } 1349 | return result; 1350 | }, 1351 | 1352 | vectorLength: function(vector) { 1353 | var result = 0, 1354 | i; 1355 | for (i = 0; i < vector.length; i++) { 1356 | result += vector[i] * vector[i]; 1357 | } 1358 | return Math.sqrt(result); 1359 | }, 1360 | 1361 | /* Derived from d3 implementation https://github.com/mbostock/d3/blob/master/src/scale/linear.js#L94 */ 1362 | getTicks: function(){ 1363 | var m = 5, 1364 | extent = [this.clearMinValue, this.clearMaxValue], 1365 | span = extent[1] - extent[0], 1366 | step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)), 1367 | err = m / span * step, 1368 | ticks = [], 1369 | tick, 1370 | v; 1371 | 1372 | if (err <= .15) step *= 10; 1373 | else if (err <= .35) step *= 5; 1374 | else if (err <= .75) step *= 2; 1375 | 1376 | extent[0] = Math.floor(extent[0] / step) * step; 1377 | extent[1] = Math.ceil(extent[1] / step) * step; 1378 | 1379 | tick = extent[0]; 1380 | while (tick <= extent[1]) { 1381 | if (tick == extent[0]) { 1382 | v = this.clearMinValue; 1383 | } else if (tick == extent[1]) { 1384 | v = this.clearMaxValue; 1385 | } else { 1386 | v = tick; 1387 | } 1388 | ticks.push({ 1389 | label: tick, 1390 | value: this.getValue(v) 1391 | }); 1392 | tick += step; 1393 | } 1394 | 1395 | return ticks; 1396 | } 1397 | }; 1398 | jvm.ColorScale = function(colors, normalizeFunction, minValue, maxValue) { 1399 | jvm.ColorScale.parentClass.apply(this, arguments); 1400 | } 1401 | 1402 | jvm.inherits(jvm.ColorScale, jvm.NumericScale); 1403 | 1404 | jvm.ColorScale.prototype.setScale = function(scale) { 1405 | var i; 1406 | 1407 | for (i = 0; i < scale.length; i++) { 1408 | this.scale[i] = jvm.ColorScale.rgbToArray(scale[i]); 1409 | } 1410 | }; 1411 | 1412 | jvm.ColorScale.prototype.getValue = function(value) { 1413 | return jvm.ColorScale.numToRgb(jvm.ColorScale.parentClass.prototype.getValue.call(this, value)); 1414 | }; 1415 | 1416 | jvm.ColorScale.arrayToRgb = function(ar) { 1417 | var rgb = '#', 1418 | d, 1419 | i; 1420 | 1421 | for (i = 0; i < ar.length; i++) { 1422 | d = ar[i].toString(16); 1423 | rgb += d.length == 1 ? '0'+d : d; 1424 | } 1425 | return rgb; 1426 | }; 1427 | 1428 | jvm.ColorScale.numToRgb = function(num) { 1429 | num = num.toString(16); 1430 | 1431 | while (num.length < 6) { 1432 | num = '0' + num; 1433 | } 1434 | 1435 | return '#'+num; 1436 | }; 1437 | 1438 | jvm.ColorScale.rgbToArray = function(rgb) { 1439 | rgb = rgb.substr(1); 1440 | return [parseInt(rgb.substr(0, 2), 16), parseInt(rgb.substr(2, 2), 16), parseInt(rgb.substr(4, 2), 16)]; 1441 | };/** 1442 | * Represents map legend. 1443 | * @constructor 1444 | * @param {Object} params Configuration parameters. 1445 | * @param {String} params.cssClass Additional CSS class to apply to legend element. 1446 | * @param {Boolean} params.vertical If true legend will be rendered as vertical. 1447 | * @param {String} params.title Legend title. 1448 | * @param {Function} params.labelRender Method to convert series values to legend labels. 1449 | */ 1450 | jvm.Legend = function(params) { 1451 | this.params = params || {}; 1452 | this.map = this.params.map; 1453 | this.series = this.params.series; 1454 | this.body = jvm.$('
'); 1455 | this.body.addClass('jvectormap-legend'); 1456 | if (this.params.cssClass) { 1457 | this.body.addClass(this.params.cssClass); 1458 | } 1459 | 1460 | if (params.vertical) { 1461 | this.map.legendCntVertical.append( this.body ); 1462 | } else { 1463 | this.map.legendCntHorizontal.append( this.body ); 1464 | } 1465 | 1466 | this.render(); 1467 | } 1468 | 1469 | jvm.Legend.prototype.render = function(){ 1470 | var ticks = this.series.scale.getTicks(), 1471 | i, 1472 | inner = jvm.$('
').addClass('jvectormap-legend-inner'), 1473 | tick, 1474 | sample, 1475 | label; 1476 | 1477 | this.body.html(''); 1478 | if (this.params.title) { 1479 | this.body.append( 1480 | jvm.$('
').addClass('jvectormap-legend-title').html(this.params.title) 1481 | ); 1482 | } 1483 | this.body.append(inner); 1484 | 1485 | for (i = 0; i < ticks.length; i++) { 1486 | tick = jvm.$('
').addClass('jvectormap-legend-tick'); 1487 | sample = jvm.$('
').addClass('jvectormap-legend-tick-sample'); 1488 | 1489 | switch (this.series.params.attribute) { 1490 | case 'fill': 1491 | if (jvm.isImageUrl(ticks[i].value)) { 1492 | sample.css('background', 'url('+ticks[i].value+')'); 1493 | } else { 1494 | sample.css('background', ticks[i].value); 1495 | } 1496 | break; 1497 | case 'stroke': 1498 | sample.css('background', ticks[i].value); 1499 | break; 1500 | case 'image': 1501 | sample.css('background', 'url('+ticks[i].value+') no-repeat center center'); 1502 | break; 1503 | case 'r': 1504 | jvm.$('
').css({ 1505 | 'border-radius': ticks[i].value, 1506 | border: this.map.params.markerStyle.initial['stroke-width']+'px '+ 1507 | this.map.params.markerStyle.initial['stroke']+' solid', 1508 | width: ticks[i].value * 2 + 'px', 1509 | height: ticks[i].value * 2 + 'px', 1510 | background: this.map.params.markerStyle.initial['fill'] 1511 | }).appendTo(sample); 1512 | break; 1513 | } 1514 | tick.append( sample ); 1515 | label = ticks[i].label; 1516 | if (this.params.labelRender) { 1517 | label = this.params.labelRender(label); 1518 | } 1519 | tick.append( jvm.$('
'+label+'
').addClass('jvectormap-legend-tick-text') ); 1520 | inner.append(tick); 1521 | } 1522 | inner.append( jvm.$('
').css('clear', 'both') ); 1523 | }/** 1524 | * Creates data series. 1525 | * @constructor 1526 | * @param {Object} params Parameters to initialize series with. 1527 | * @param {Array} params.values The data set to visualize. 1528 | * @param {String} params.attribute Numberic or color attribute to use for data visualization. This could be: fill, stroke, fill-opacity, stroke-opacity for markers and regions and r (radius) for markers only. 1529 | * @param {Array} params.scale Values used to map a dimension of data to a visual representation. The first value sets visualization for minimum value from the data set and the last value sets visualization for the maximum value. There also could be intermidiate values. Default value is ['#C8EEFF', '#0071A4'] 1530 | * @param {Function|String} params.normalizeFunction The function used to map input values to the provided scale. This parameter could be provided as function or one of the strings: 'linear' or 'polynomial', while 'linear' is used by default. The function provided takes value from the data set as an input and returns corresponding value from the scale. 1531 | * @param {Number} params.min Minimum value of the data set. Could be calculated automatically if not provided. 1532 | * @param {Number} params.min Maximum value of the data set. Could be calculated automatically if not provided. 1533 | */ 1534 | jvm.DataSeries = function(params, elements, map) { 1535 | var scaleConstructor; 1536 | 1537 | params = params || {}; 1538 | params.attribute = params.attribute || 'fill'; 1539 | 1540 | this.elements = elements; 1541 | this.params = params; 1542 | this.map = map; 1543 | 1544 | if (params.attributes) { 1545 | this.setAttributes(params.attributes); 1546 | } 1547 | 1548 | if (jvm.$.isArray(params.scale)) { 1549 | scaleConstructor = (params.attribute === 'fill' || params.attribute === 'stroke') ? jvm.ColorScale : jvm.NumericScale; 1550 | this.scale = new scaleConstructor(params.scale, params.normalizeFunction, params.min, params.max); 1551 | } else if (params.scale) { 1552 | this.scale = new jvm.OrdinalScale(params.scale); 1553 | } else { 1554 | this.scale = new jvm.SimpleScale(params.scale); 1555 | } 1556 | 1557 | this.values = params.values || {}; 1558 | this.setValues(this.values); 1559 | 1560 | if (this.params.legend) { 1561 | this.legend = new jvm.Legend($.extend({ 1562 | map: this.map, 1563 | series: this 1564 | }, this.params.legend)) 1565 | } 1566 | }; 1567 | 1568 | jvm.DataSeries.prototype = { 1569 | setAttributes: function(key, attr){ 1570 | var attrs = key, 1571 | code; 1572 | 1573 | if (typeof key == 'string') { 1574 | if (this.elements[key]) { 1575 | this.elements[key].setStyle(this.params.attribute, attr); 1576 | } 1577 | } else { 1578 | for (code in attrs) { 1579 | if (this.elements[code]) { 1580 | this.elements[code].element.setStyle(this.params.attribute, attrs[code]); 1581 | } 1582 | } 1583 | } 1584 | }, 1585 | 1586 | /** 1587 | * Set values for the data set. 1588 | * @param {Object} values Object which maps codes of regions or markers to values. 1589 | */ 1590 | setValues: function(values) { 1591 | var max = -Number.MAX_VALUE, 1592 | min = Number.MAX_VALUE, 1593 | val, 1594 | cc, 1595 | attrs = {}; 1596 | 1597 | if (!(this.scale instanceof jvm.OrdinalScale) && !(this.scale instanceof jvm.SimpleScale)) { 1598 | // we have a color scale as an array 1599 | if (typeof this.params.min === 'undefined' || typeof this.params.max === 'undefined') { 1600 | // min and/or max are not defined, so calculate them 1601 | for (cc in values) { 1602 | val = parseFloat(values[cc]); 1603 | if (val > max) max = val; 1604 | if (val < min) min = val; 1605 | } 1606 | } 1607 | 1608 | if (typeof this.params.min === 'undefined') { 1609 | this.scale.setMin(min); 1610 | this.params.min = min; 1611 | } else { 1612 | this.scale.setMin(this.params.min); 1613 | } 1614 | 1615 | if (typeof this.params.max === 'undefined') { 1616 | this.scale.setMax(max); 1617 | this.params.max = max; 1618 | } else { 1619 | this.scale.setMax(this.params.max); 1620 | } 1621 | 1622 | for (cc in values) { 1623 | if (cc != 'indexOf') { 1624 | val = parseFloat(values[cc]); 1625 | if (!isNaN(val)) { 1626 | attrs[cc] = this.scale.getValue(val); 1627 | } else { 1628 | attrs[cc] = this.elements[cc].element.style.initial[this.params.attribute]; 1629 | } 1630 | } 1631 | } 1632 | } else { 1633 | for (cc in values) { 1634 | if (values[cc]) { 1635 | attrs[cc] = this.scale.getValue(values[cc]); 1636 | } else { 1637 | attrs[cc] = this.elements[cc].element.style.initial[this.params.attribute]; 1638 | } 1639 | } 1640 | } 1641 | 1642 | this.setAttributes(attrs); 1643 | jvm.$.extend(this.values, values); 1644 | }, 1645 | 1646 | clear: function(){ 1647 | var key, 1648 | attrs = {}; 1649 | 1650 | for (key in this.values) { 1651 | if (this.elements[key]) { 1652 | attrs[key] = this.elements[key].element.shape.style.initial[this.params.attribute]; 1653 | } 1654 | } 1655 | this.setAttributes(attrs); 1656 | this.values = {}; 1657 | }, 1658 | 1659 | /** 1660 | * Set scale of the data series. 1661 | * @param {Array} scale Values representing scale. 1662 | */ 1663 | setScale: function(scale) { 1664 | this.scale.setScale(scale); 1665 | if (this.values) { 1666 | this.setValues(this.values); 1667 | } 1668 | }, 1669 | 1670 | /** 1671 | * Set normalize function of the data series. 1672 | * @param {Function|String} normilizeFunction. 1673 | */ 1674 | setNormalizeFunction: function(f) { 1675 | this.scale.setNormalizeFunction(f); 1676 | if (this.values) { 1677 | this.setValues(this.values); 1678 | } 1679 | } 1680 | }; 1681 | /** 1682 | * Contains methods for transforming point on sphere to 1683 | * Cartesian coordinates using various projections. 1684 | * @class 1685 | */ 1686 | jvm.Proj = { 1687 | degRad: 180 / Math.PI, 1688 | radDeg: Math.PI / 180, 1689 | radius: 6381372, 1690 | 1691 | sgn: function(n){ 1692 | if (n > 0) { 1693 | return 1; 1694 | } else if (n < 0) { 1695 | return -1; 1696 | } else { 1697 | return n; 1698 | } 1699 | }, 1700 | 1701 | /** 1702 | * Converts point on sphere to the Cartesian coordinates using Miller projection 1703 | * @param {Number} lat Latitude in degrees 1704 | * @param {Number} lng Longitude in degrees 1705 | * @param {Number} c Central meridian in degrees 1706 | */ 1707 | mill: function(lat, lng, c){ 1708 | return { 1709 | x: this.radius * (lng - c) * this.radDeg, 1710 | y: - this.radius * Math.log(Math.tan((45 + 0.4 * lat) * this.radDeg)) / 0.8 1711 | }; 1712 | }, 1713 | 1714 | /** 1715 | * Inverse function of mill() 1716 | * Converts Cartesian coordinates to point on sphere using Miller projection 1717 | * @param {Number} x X of point in Cartesian system as integer 1718 | * @param {Number} y Y of point in Cartesian system as integer 1719 | * @param {Number} c Central meridian in degrees 1720 | */ 1721 | mill_inv: function(x, y, c){ 1722 | return { 1723 | lat: (2.5 * Math.atan(Math.exp(0.8 * y / this.radius)) - 5 * Math.PI / 8) * this.degRad, 1724 | lng: (c * this.radDeg + x / this.radius) * this.degRad 1725 | }; 1726 | }, 1727 | 1728 | /** 1729 | * Converts point on sphere to the Cartesian coordinates using Mercator projection 1730 | * @param {Number} lat Latitude in degrees 1731 | * @param {Number} lng Longitude in degrees 1732 | * @param {Number} c Central meridian in degrees 1733 | */ 1734 | merc: function(lat, lng, c){ 1735 | return { 1736 | x: this.radius * (lng - c) * this.radDeg, 1737 | y: - this.radius * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360)) 1738 | }; 1739 | }, 1740 | 1741 | /** 1742 | * Inverse function of merc() 1743 | * Converts Cartesian coordinates to point on sphere using Mercator projection 1744 | * @param {Number} x X of point in Cartesian system as integer 1745 | * @param {Number} y Y of point in Cartesian system as integer 1746 | * @param {Number} c Central meridian in degrees 1747 | */ 1748 | merc_inv: function(x, y, c){ 1749 | return { 1750 | lat: (2 * Math.atan(Math.exp(y / this.radius)) - Math.PI / 2) * this.degRad, 1751 | lng: (c * this.radDeg + x / this.radius) * this.degRad 1752 | }; 1753 | }, 1754 | 1755 | /** 1756 | * Converts point on sphere to the Cartesian coordinates using Albers Equal-Area Conic 1757 | * projection 1758 | * @see Albers Equal-Area Conic projection 1759 | * @param {Number} lat Latitude in degrees 1760 | * @param {Number} lng Longitude in degrees 1761 | * @param {Number} c Central meridian in degrees 1762 | */ 1763 | aea: function(lat, lng, c){ 1764 | var fi0 = 0, 1765 | lambda0 = c * this.radDeg, 1766 | fi1 = 29.5 * this.radDeg, 1767 | fi2 = 45.5 * this.radDeg, 1768 | fi = lat * this.radDeg, 1769 | lambda = lng * this.radDeg, 1770 | n = (Math.sin(fi1)+Math.sin(fi2)) / 2, 1771 | C = Math.cos(fi1)*Math.cos(fi1)+2*n*Math.sin(fi1), 1772 | theta = n*(lambda-lambda0), 1773 | ro = Math.sqrt(C-2*n*Math.sin(fi))/n, 1774 | ro0 = Math.sqrt(C-2*n*Math.sin(fi0))/n; 1775 | 1776 | return { 1777 | x: ro * Math.sin(theta) * this.radius, 1778 | y: - (ro0 - ro * Math.cos(theta)) * this.radius 1779 | }; 1780 | }, 1781 | 1782 | /** 1783 | * Converts Cartesian coordinates to the point on sphere using Albers Equal-Area Conic 1784 | * projection 1785 | * @see Albers Equal-Area Conic projection 1786 | * @param {Number} x X of point in Cartesian system as integer 1787 | * @param {Number} y Y of point in Cartesian system as integer 1788 | * @param {Number} c Central meridian in degrees 1789 | */ 1790 | aea_inv: function(xCoord, yCoord, c){ 1791 | var x = xCoord / this.radius, 1792 | y = yCoord / this.radius, 1793 | fi0 = 0, 1794 | lambda0 = c * this.radDeg, 1795 | fi1 = 29.5 * this.radDeg, 1796 | fi2 = 45.5 * this.radDeg, 1797 | n = (Math.sin(fi1)+Math.sin(fi2)) / 2, 1798 | C = Math.cos(fi1)*Math.cos(fi1)+2*n*Math.sin(fi1), 1799 | ro0 = Math.sqrt(C-2*n*Math.sin(fi0))/n, 1800 | ro = Math.sqrt(x*x+(ro0-y)*(ro0-y)), 1801 | theta = Math.atan( x / (ro0 - y) ); 1802 | 1803 | return { 1804 | lat: (Math.asin((C - ro * ro * n * n) / (2 * n))) * this.degRad, 1805 | lng: (lambda0 + theta / n) * this.degRad 1806 | }; 1807 | }, 1808 | 1809 | /** 1810 | * Converts point on sphere to the Cartesian coordinates using Lambert conformal 1811 | * conic projection 1812 | * @see Lambert Conformal Conic Projection 1813 | * @param {Number} lat Latitude in degrees 1814 | * @param {Number} lng Longitude in degrees 1815 | * @param {Number} c Central meridian in degrees 1816 | */ 1817 | lcc: function(lat, lng, c){ 1818 | var fi0 = 0, 1819 | lambda0 = c * this.radDeg, 1820 | lambda = lng * this.radDeg, 1821 | fi1 = 33 * this.radDeg, 1822 | fi2 = 45 * this.radDeg, 1823 | fi = lat * this.radDeg, 1824 | n = Math.log( Math.cos(fi1) * (1 / Math.cos(fi2)) ) / Math.log( Math.tan( Math.PI / 4 + fi2 / 2) * (1 / Math.tan( Math.PI / 4 + fi1 / 2) ) ), 1825 | F = ( Math.cos(fi1) * Math.pow( Math.tan( Math.PI / 4 + fi1 / 2 ), n ) ) / n, 1826 | ro = F * Math.pow( 1 / Math.tan( Math.PI / 4 + fi / 2 ), n ), 1827 | ro0 = F * Math.pow( 1 / Math.tan( Math.PI / 4 + fi0 / 2 ), n ); 1828 | 1829 | return { 1830 | x: ro * Math.sin( n * (lambda - lambda0) ) * this.radius, 1831 | y: - (ro0 - ro * Math.cos( n * (lambda - lambda0) ) ) * this.radius 1832 | }; 1833 | }, 1834 | 1835 | /** 1836 | * Converts Cartesian coordinates to the point on sphere using Lambert conformal conic 1837 | * projection 1838 | * @see Lambert Conformal Conic Projection 1839 | * @param {Number} x X of point in Cartesian system as integer 1840 | * @param {Number} y Y of point in Cartesian system as integer 1841 | * @param {Number} c Central meridian in degrees 1842 | */ 1843 | lcc_inv: function(xCoord, yCoord, c){ 1844 | var x = xCoord / this.radius, 1845 | y = yCoord / this.radius, 1846 | fi0 = 0, 1847 | lambda0 = c * this.radDeg, 1848 | fi1 = 33 * this.radDeg, 1849 | fi2 = 45 * this.radDeg, 1850 | n = Math.log( Math.cos(fi1) * (1 / Math.cos(fi2)) ) / Math.log( Math.tan( Math.PI / 4 + fi2 / 2) * (1 / Math.tan( Math.PI / 4 + fi1 / 2) ) ), 1851 | F = ( Math.cos(fi1) * Math.pow( Math.tan( Math.PI / 4 + fi1 / 2 ), n ) ) / n, 1852 | ro0 = F * Math.pow( 1 / Math.tan( Math.PI / 4 + fi0 / 2 ), n ), 1853 | ro = this.sgn(n) * Math.sqrt(x*x+(ro0-y)*(ro0-y)), 1854 | theta = Math.atan( x / (ro0 - y) ); 1855 | 1856 | return { 1857 | lat: (2 * Math.atan(Math.pow(F/ro, 1/n)) - Math.PI / 2) * this.degRad, 1858 | lng: (lambda0 + theta / n) * this.degRad 1859 | }; 1860 | } 1861 | };jvm.MapObject = function(config){}; 1862 | 1863 | jvm.MapObject.prototype.getLabelText = function(key){ 1864 | var text; 1865 | 1866 | if (this.config.label) { 1867 | if (typeof this.config.label.render === 'function') { 1868 | text = this.config.label.render(key); 1869 | } else { 1870 | text = key; 1871 | } 1872 | } else { 1873 | text = null; 1874 | } 1875 | return text; 1876 | } 1877 | 1878 | jvm.MapObject.prototype.getLabelOffsets = function(key){ 1879 | var offsets; 1880 | 1881 | if (this.config.label) { 1882 | if (typeof this.config.label.offsets === 'function') { 1883 | offsets = this.config.label.offsets(key); 1884 | } else if (typeof this.config.label.offsets === 'object') { 1885 | offsets = this.config.label.offsets[key]; 1886 | } 1887 | } 1888 | return offsets || [0, 0]; 1889 | } 1890 | 1891 | /** 1892 | * Set hovered state to the element. Hovered state means mouse cursor is over element. Styles will be updates respectively. 1893 | * @param {Boolean} isHovered true to make element hovered, false otherwise. 1894 | */ 1895 | jvm.MapObject.prototype.setHovered = function(isHovered){ 1896 | if (this.isHovered !== isHovered) { 1897 | this.isHovered = isHovered; 1898 | this.shape.isHovered = isHovered; 1899 | this.shape.updateStyle(); 1900 | if (this.label) { 1901 | this.label.isHovered = isHovered; 1902 | this.label.updateStyle(); 1903 | } 1904 | } 1905 | }; 1906 | 1907 | /** 1908 | * Set selected state to the element. Styles will be updates respectively. 1909 | * @param {Boolean} isSelected true to make element selected, false otherwise. 1910 | */ 1911 | jvm.MapObject.prototype.setSelected = function(isSelected){ 1912 | if (this.isSelected !== isSelected) { 1913 | this.isSelected = isSelected; 1914 | this.shape.isSelected = isSelected; 1915 | this.shape.updateStyle(); 1916 | if (this.label) { 1917 | this.label.isSelected = isSelected; 1918 | this.label.updateStyle(); 1919 | } 1920 | jvm.$(this.shape).trigger('selected', [isSelected]); 1921 | } 1922 | }; 1923 | 1924 | jvm.MapObject.prototype.setStyle = function(){ 1925 | this.shape.setStyle.apply(this.shape, arguments); 1926 | }; 1927 | 1928 | jvm.MapObject.prototype.remove = function(){ 1929 | this.shape.remove(); 1930 | if (this.label) { 1931 | this.label.remove(); 1932 | } 1933 | };jvm.Region = function(config){ 1934 | var bbox, 1935 | text, 1936 | offsets, 1937 | labelDx, 1938 | labelDy; 1939 | 1940 | this.config = config; 1941 | this.map = this.config.map; 1942 | 1943 | this.shape = config.canvas.addPath({ 1944 | d: config.path, 1945 | 'data-code': config.code 1946 | }, config.style, config.canvas.rootElement); 1947 | this.shape.addClass('jvectormap-region jvectormap-element'); 1948 | 1949 | bbox = this.shape.getBBox(); 1950 | 1951 | text = this.getLabelText(config.code); 1952 | if (this.config.label && text) { 1953 | offsets = this.getLabelOffsets(config.code); 1954 | this.labelX = bbox.x + bbox.width / 2 + offsets[0]; 1955 | this.labelY = bbox.y + bbox.height / 2 + offsets[1]; 1956 | this.label = config.canvas.addText({ 1957 | text: text, 1958 | 'text-anchor': 'middle', 1959 | 'alignment-baseline': 'central', 1960 | x: this.labelX, 1961 | y: this.labelY, 1962 | 'data-code': config.code 1963 | }, config.labelStyle, config.labelsGroup); 1964 | this.label.addClass('jvectormap-region jvectormap-element'); 1965 | } 1966 | }; 1967 | 1968 | jvm.inherits(jvm.Region, jvm.MapObject); 1969 | 1970 | jvm.Region.prototype.updateLabelPosition = function(){ 1971 | if (this.label) { 1972 | this.label.set({ 1973 | x: this.labelX * this.map.scale + this.map.transX * this.map.scale, 1974 | y: this.labelY * this.map.scale + this.map.transY * this.map.scale 1975 | }); 1976 | } 1977 | };jvm.Marker = function(config){ 1978 | var text, 1979 | offsets; 1980 | 1981 | this.config = config; 1982 | this.map = this.config.map; 1983 | 1984 | this.isImage = !!this.config.style.initial.image; 1985 | this.createShape(); 1986 | 1987 | text = this.getLabelText(config.index); 1988 | if (this.config.label && text) { 1989 | this.offsets = this.getLabelOffsets(config.index); 1990 | this.labelX = config.cx / this.map.scale - this.map.transX; 1991 | this.labelY = config.cy / this.map.scale - this.map.transY; 1992 | this.label = config.canvas.addText({ 1993 | text: text, 1994 | 'data-index': config.index, 1995 | dy: "0.6ex", 1996 | x: this.labelX, 1997 | y: this.labelY 1998 | }, config.labelStyle, config.labelsGroup); 1999 | 2000 | this.label.addClass('jvectormap-marker jvectormap-element'); 2001 | } 2002 | }; 2003 | 2004 | jvm.inherits(jvm.Marker, jvm.MapObject); 2005 | 2006 | jvm.Marker.prototype.createShape = function(){ 2007 | var that = this; 2008 | 2009 | if (this.shape) { 2010 | this.shape.remove(); 2011 | } 2012 | this.shape = this.config.canvas[this.isImage ? 'addImage' : 'addCircle']({ 2013 | "data-index": this.config.index, 2014 | cx: this.config.cx, 2015 | cy: this.config.cy 2016 | }, this.config.style, this.config.group); 2017 | 2018 | this.shape.addClass('jvectormap-marker jvectormap-element'); 2019 | 2020 | if (this.isImage) { 2021 | jvm.$(this.shape.node).on('imageloaded', function(){ 2022 | that.updateLabelPosition(); 2023 | }); 2024 | } 2025 | }; 2026 | 2027 | jvm.Marker.prototype.updateLabelPosition = function(){ 2028 | if (this.label) { 2029 | this.label.set({ 2030 | x: this.labelX * this.map.scale + this.offsets[0] + 2031 | this.map.transX * this.map.scale + 5 + (this.isImage ? (this.shape.width || 0) / 2 : this.shape.properties.r), 2032 | y: this.labelY * this.map.scale + this.map.transY * this.map.scale + this.offsets[1] 2033 | }); 2034 | } 2035 | }; 2036 | 2037 | jvm.Marker.prototype.setStyle = function(property, value){ 2038 | var isImage; 2039 | 2040 | jvm.Marker.parentClass.prototype.setStyle.apply(this, arguments); 2041 | 2042 | if (property === 'r') { 2043 | this.updateLabelPosition(); 2044 | } 2045 | 2046 | isImage = !!this.shape.get('image'); 2047 | if (isImage != this.isImage) { 2048 | this.isImage = isImage; 2049 | this.config.style = jvm.$.extend(true, {}, this.shape.style); 2050 | this.createShape(); 2051 | } 2052 | };/** 2053 | * Creates map, draws paths, binds events. 2054 | * @constructor 2055 | * @param {Object} params Parameters to initialize map with. 2056 | * @param {String} params.map Name of the map in the format territory_proj_lang where territory is a unique code or name of the territory which the map represents (ISO 3166 standard is used where possible), proj is a name of projection used to generate representation of the map on the plane (projections are named according to the conventions of proj4 utility) and lang is a code of the language, used for the names of regions. 2057 | * @param {String} params.backgroundColor Background color of the map in CSS format. 2058 | * @param {Boolean} params.zoomOnScroll When set to true map could be zoomed using mouse scroll. Default value is true. 2059 | * @param {Boolean} params.panOnDrag When set to true, the map pans when being dragged. Default value is true. 2060 | * @param {Number} params.zoomMax Indicates the maximum zoom ratio which could be reached zooming the map. Default value is 8. 2061 | * @param {Number} params.zoomMin Indicates the minimum zoom ratio which could be reached zooming the map. Default value is 1. 2062 | * @param {Number} params.zoomStep Indicates the multiplier used to zoom map with +/- buttons. Default value is 1.6. 2063 | * @param {Boolean} params.zoomAnimate Indicates whether or not to animate changing of map zoom with zoom buttons. 2064 | * @param {Boolean} params.regionsSelectable When set to true regions of the map could be selected. Default value is false. 2065 | * @param {Boolean} params.regionsSelectableOne Allow only one region to be selected at the moment. Default value is false. 2066 | * @param {Boolean} params.markersSelectable When set to true markers on the map could be selected. Default value is false. 2067 | * @param {Boolean} params.markersSelectableOne Allow only one marker to be selected at the moment. Default value is false. 2068 | * @param {Object} params.regionStyle Set the styles for the map's regions. Each region or marker has four states: initial (default state), hover (when the mouse cursor is over the region or marker), selected (when region or marker is selected), selectedHover (when the mouse cursor is over the region or marker and it's selected simultaneously). Styles could be set for each of this states. Default value for that parameter is: 2069 |
{
2070 |   initial: {
2071 |     fill: 'white',
2072 |     "fill-opacity": 1,
2073 |     stroke: 'none',
2074 |     "stroke-width": 0,
2075 |     "stroke-opacity": 1
2076 |   },
2077 |   hover: {
2078 |     "fill-opacity": 0.8,
2079 |     cursor: 'pointer'
2080 |   },
2081 |   selected: {
2082 |     fill: 'yellow'
2083 |   },
2084 |   selectedHover: {
2085 |   }
2086 | }
2087 | * @param {Object} params.regionLabelStyle Set the styles for the regions' labels. Each region or marker has four states: initial (default state), hover (when the mouse cursor is over the region or marker), selected (when region or marker is selected), selectedHover (when the mouse cursor is over the region or marker and it's selected simultaneously). Styles could be set for each of this states. Default value for that parameter is: 2088 |
{
2089 |   initial: {
2090 |     'font-family': 'Verdana',
2091 |     'font-size': '12',
2092 |     'font-weight': 'bold',
2093 |     cursor: 'default',
2094 |     fill: 'black'
2095 |   },
2096 |   hover: {
2097 |     cursor: 'pointer'
2098 |   }
2099 | }
2100 | * @param {Object} params.markerStyle Set the styles for the map's markers. Any parameter suitable for regionStyle could be used as well as numeric parameter r to set the marker's radius. Default value for that parameter is: 2101 |
{
2102 |   initial: {
2103 |     fill: 'grey',
2104 |     stroke: '#505050',
2105 |     "fill-opacity": 1,
2106 |     "stroke-width": 1,
2107 |     "stroke-opacity": 1,
2108 |     r: 5
2109 |   },
2110 |   hover: {
2111 |     stroke: 'black',
2112 |     "stroke-width": 2,
2113 |     cursor: 'pointer'
2114 |   },
2115 |   selected: {
2116 |     fill: 'blue'
2117 |   },
2118 |   selectedHover: {
2119 |   }
2120 | }
2121 | * @param {Object} params.markerLabelStyle Set the styles for the markers' labels. Default value for that parameter is: 2122 |
{
2123 |   initial: {
2124 |     'font-family': 'Verdana',
2125 |     'font-size': '12',
2126 |     'font-weight': 'bold',
2127 |     cursor: 'default',
2128 |     fill: 'black'
2129 |   },
2130 |   hover: {
2131 |     cursor: 'pointer'
2132 |   }
2133 | }
2134 | * @param {Object|Array} params.markers Set of markers to add to the map during initialization. In case of array is provided, codes of markers will be set as string representations of array indexes. Each marker is represented by latLng (array of two numeric values), name (string which will be show on marker's tip) and any marker styles. 2135 | * @param {Object} params.series Object with two keys: markers and regions. Each of which is an array of series configs to be applied to the respective map elements. See DataSeries description for a list of parameters available. 2136 | * @param {Object|String} params.focusOn This parameter sets the initial position and scale of the map viewport. See setFocus docuemntation for possible parameters. 2137 | * @param {Object} params.labels Defines parameters for rendering static labels. Object could contain two keys: regions and markers. Each key value defines configuration object with the following possible options: 2138 |
    2139 |
  • render {Function} - defines method for converting region code or marker index to actual label value.
  • 2140 |
  • offsets {Object|Function} - provides method or object which could be used to define label offset by region code or marker index.
  • 2141 |
2142 | Plase note: static labels feature is not supported in Internet Explorer 8 and below. 2143 | * @param {Array|Object|String} params.selectedRegions Set initially selected regions. 2144 | * @param {Array|Object|String} params.selectedMarkers Set initially selected markers. 2145 | * @param {Function} params.onRegionTipShow (Event e, Object tip, String code) Will be called right before the region tip is going to be shown. 2146 | * @param {Function} params.onRegionOver (Event e, String code) Will be called on region mouse over event. 2147 | * @param {Function} params.onRegionOut (Event e, String code) Will be called on region mouse out event. 2148 | * @param {Function} params.onRegionClick (Event e, String code) Will be called on region click event. 2149 | * @param {Function} params.onRegionSelected (Event e, String code, Boolean isSelected, Array selectedRegions) Will be called when region is (de)selected. isSelected parameter of the callback indicates whether region is selected or not. selectedRegions contains codes of all currently selected regions. 2150 | * @param {Function} params.onMarkerTipShow (Event e, Object tip, String code) Will be called right before the marker tip is going to be shown. 2151 | * @param {Function} params.onMarkerOver (Event e, String code) Will be called on marker mouse over event. 2152 | * @param {Function} params.onMarkerOut (Event e, String code) Will be called on marker mouse out event. 2153 | * @param {Function} params.onMarkerClick (Event e, String code) Will be called on marker click event. 2154 | * @param {Function} params.onMarkerSelected (Event e, String code, Boolean isSelected, Array selectedMarkers) Will be called when marker is (de)selected. isSelected parameter of the callback indicates whether marker is selected or not. selectedMarkers contains codes of all currently selected markers. 2155 | * @param {Function} params.onViewportChange (Event e, Number scale) Triggered when the map's viewport is changed (map was panned or zoomed). 2156 | */ 2157 | jvm.Map = function(params) { 2158 | var map = this, 2159 | e; 2160 | 2161 | this.params = jvm.$.extend(true, {}, jvm.Map.defaultParams, params); 2162 | 2163 | if (!jvm.Map.maps[this.params.map]) { 2164 | throw new Error('Attempt to use map which was not loaded: '+this.params.map); 2165 | } 2166 | 2167 | this.mapData = jvm.Map.maps[this.params.map]; 2168 | this.markers = {}; 2169 | this.regions = {}; 2170 | this.regionsColors = {}; 2171 | this.regionsData = {}; 2172 | 2173 | this.container = jvm.$('
').addClass('jvectormap-container'); 2174 | if (this.params.container) { 2175 | this.params.container.append( this.container ); 2176 | } 2177 | this.container.data('mapObject', this); 2178 | 2179 | this.defaultWidth = this.mapData.width; 2180 | this.defaultHeight = this.mapData.height; 2181 | 2182 | this.setBackgroundColor(this.params.backgroundColor); 2183 | 2184 | this.onResize = function(){ 2185 | map.updateSize(); 2186 | } 2187 | jvm.$(window).resize(this.onResize); 2188 | 2189 | for (e in jvm.Map.apiEvents) { 2190 | if (this.params[e]) { 2191 | this.container.bind(jvm.Map.apiEvents[e]+'.jvectormap', this.params[e]); 2192 | } 2193 | } 2194 | 2195 | this.canvas = new jvm.VectorCanvas(this.container[0], this.width, this.height); 2196 | 2197 | if ( ('ontouchstart' in window) || (window.DocumentTouch && document instanceof DocumentTouch) ) { 2198 | if (this.params.bindTouchEvents) { 2199 | this.bindContainerTouchEvents(); 2200 | } 2201 | } 2202 | this.bindContainerEvents(); 2203 | this.bindElementEvents(); 2204 | this.createTip(); 2205 | if (this.params.zoomButtons) { 2206 | this.bindZoomButtons(); 2207 | } 2208 | 2209 | this.createRegions(); 2210 | this.createMarkers(this.params.markers || {}); 2211 | 2212 | this.updateSize(); 2213 | 2214 | if (this.params.focusOn) { 2215 | if (typeof this.params.focusOn === 'string') { 2216 | this.params.focusOn = {region: this.params.focusOn}; 2217 | } else if (jvm.$.isArray(this.params.focusOn)) { 2218 | this.params.focusOn = {regions: this.params.focusOn}; 2219 | } 2220 | this.setFocus(this.params.focusOn); 2221 | } 2222 | 2223 | if (this.params.selectedRegions) { 2224 | this.setSelectedRegions(this.params.selectedRegions); 2225 | } 2226 | if (this.params.selectedMarkers) { 2227 | this.setSelectedMarkers(this.params.selectedMarkers); 2228 | } 2229 | 2230 | this.legendCntHorizontal = jvm.$('
').addClass('jvectormap-legend-cnt jvectormap-legend-cnt-h'); 2231 | this.legendCntVertical = jvm.$('
').addClass('jvectormap-legend-cnt jvectormap-legend-cnt-v'); 2232 | this.container.append(this.legendCntHorizontal); 2233 | this.container.append(this.legendCntVertical); 2234 | 2235 | if (this.params.series) { 2236 | this.createSeries(); 2237 | } 2238 | }; 2239 | 2240 | jvm.Map.prototype = { 2241 | transX: 0, 2242 | transY: 0, 2243 | scale: 1, 2244 | baseTransX: 0, 2245 | baseTransY: 0, 2246 | baseScale: 1, 2247 | 2248 | width: 0, 2249 | height: 0, 2250 | 2251 | /** 2252 | * Set background color of the map. 2253 | * @param {String} backgroundColor Background color in CSS format. 2254 | */ 2255 | setBackgroundColor: function(backgroundColor) { 2256 | this.container.css('background-color', backgroundColor); 2257 | }, 2258 | 2259 | resize: function() { 2260 | var curBaseScale = this.baseScale; 2261 | if (this.width / this.height > this.defaultWidth / this.defaultHeight) { 2262 | this.baseScale = this.height / this.defaultHeight; 2263 | this.baseTransX = Math.abs(this.width - this.defaultWidth * this.baseScale) / (2 * this.baseScale); 2264 | } else { 2265 | this.baseScale = this.width / this.defaultWidth; 2266 | this.baseTransY = Math.abs(this.height - this.defaultHeight * this.baseScale) / (2 * this.baseScale); 2267 | } 2268 | this.scale *= this.baseScale / curBaseScale; 2269 | this.transX *= this.baseScale / curBaseScale; 2270 | this.transY *= this.baseScale / curBaseScale; 2271 | }, 2272 | 2273 | /** 2274 | * Synchronize the size of the map with the size of the container. Suitable in situations where the size of the container is changed programmatically or container is shown after it became visible. 2275 | */ 2276 | updateSize: function(){ 2277 | this.width = this.container.width(); 2278 | this.height = this.container.height(); 2279 | this.resize(); 2280 | this.canvas.setSize(this.width, this.height); 2281 | this.applyTransform(); 2282 | }, 2283 | 2284 | /** 2285 | * Reset all the series and show the map with the initial zoom. 2286 | */ 2287 | reset: function() { 2288 | var key, 2289 | i; 2290 | 2291 | for (key in this.series) { 2292 | for (i = 0; i < this.series[key].length; i++) { 2293 | this.series[key][i].clear(); 2294 | } 2295 | } 2296 | this.scale = this.baseScale; 2297 | this.transX = this.baseTransX; 2298 | this.transY = this.baseTransY; 2299 | this.applyTransform(); 2300 | }, 2301 | 2302 | applyTransform: function() { 2303 | var maxTransX, 2304 | maxTransY, 2305 | minTransX, 2306 | minTransY; 2307 | 2308 | if (this.defaultWidth * this.scale <= this.width) { 2309 | maxTransX = (this.width - this.defaultWidth * this.scale) / (2 * this.scale); 2310 | minTransX = (this.width - this.defaultWidth * this.scale) / (2 * this.scale); 2311 | } else { 2312 | maxTransX = 0; 2313 | minTransX = (this.width - this.defaultWidth * this.scale) / this.scale; 2314 | } 2315 | 2316 | if (this.defaultHeight * this.scale <= this.height) { 2317 | maxTransY = (this.height - this.defaultHeight * this.scale) / (2 * this.scale); 2318 | minTransY = (this.height - this.defaultHeight * this.scale) / (2 * this.scale); 2319 | } else { 2320 | maxTransY = 0; 2321 | minTransY = (this.height - this.defaultHeight * this.scale) / this.scale; 2322 | } 2323 | 2324 | if (this.transY > maxTransY) { 2325 | this.transY = maxTransY; 2326 | } else if (this.transY < minTransY) { 2327 | this.transY = minTransY; 2328 | } 2329 | if (this.transX > maxTransX) { 2330 | this.transX = maxTransX; 2331 | } else if (this.transX < minTransX) { 2332 | this.transX = minTransX; 2333 | } 2334 | 2335 | this.canvas.applyTransformParams(this.scale, this.transX, this.transY); 2336 | 2337 | if (this.markers) { 2338 | this.repositionMarkers(); 2339 | } 2340 | 2341 | this.repositionLabels(); 2342 | 2343 | this.container.trigger('viewportChange', [this.scale/this.baseScale, this.transX, this.transY]); 2344 | }, 2345 | 2346 | bindContainerEvents: function(){ 2347 | var mouseDown = false, 2348 | oldPageX, 2349 | oldPageY, 2350 | map = this; 2351 | 2352 | if (this.params.panOnDrag) { 2353 | this.container.mousemove(function(e){ 2354 | if (mouseDown) { 2355 | map.transX -= (oldPageX - e.pageX) / map.scale; 2356 | map.transY -= (oldPageY - e.pageY) / map.scale; 2357 | 2358 | map.applyTransform(); 2359 | 2360 | oldPageX = e.pageX; 2361 | oldPageY = e.pageY; 2362 | } 2363 | return false; 2364 | }).mousedown(function(e){ 2365 | mouseDown = true; 2366 | oldPageX = e.pageX; 2367 | oldPageY = e.pageY; 2368 | return false; 2369 | }); 2370 | 2371 | this.onContainerMouseUp = function(){ 2372 | mouseDown = false; 2373 | }; 2374 | jvm.$('body').mouseup(this.onContainerMouseUp); 2375 | } 2376 | 2377 | if (this.params.zoomOnScroll) { 2378 | this.container.mousewheel(function(event, delta, deltaX, deltaY) { 2379 | var offset = jvm.$(map.container).offset(), 2380 | centerX = event.pageX - offset.left, 2381 | centerY = event.pageY - offset.top, 2382 | zoomStep = Math.pow(1.003, event.deltaY); 2383 | 2384 | map.tip.hide(); 2385 | 2386 | map.setScale(map.scale * zoomStep, centerX, centerY); 2387 | event.preventDefault(); 2388 | }); 2389 | } 2390 | }, 2391 | 2392 | bindContainerTouchEvents: function(){ 2393 | var touchStartScale, 2394 | touchStartDistance, 2395 | map = this, 2396 | touchX, 2397 | touchY, 2398 | centerTouchX, 2399 | centerTouchY, 2400 | lastTouchesLength, 2401 | handleTouchEvent = function(e){ 2402 | var touches = e.originalEvent.touches, 2403 | offset, 2404 | scale, 2405 | transXOld, 2406 | transYOld; 2407 | 2408 | if (e.type == 'touchstart') { 2409 | lastTouchesLength = 0; 2410 | } 2411 | 2412 | if (touches.length == 1) { 2413 | if (lastTouchesLength == 1) { 2414 | transXOld = map.transX; 2415 | transYOld = map.transY; 2416 | map.transX -= (touchX - touches[0].pageX) / map.scale; 2417 | map.transY -= (touchY - touches[0].pageY) / map.scale; 2418 | map.applyTransform(); 2419 | map.tip.hide(); 2420 | if (transXOld != map.transX || transYOld != map.transY) { 2421 | e.preventDefault(); 2422 | } 2423 | } 2424 | touchX = touches[0].pageX; 2425 | touchY = touches[0].pageY; 2426 | } else if (touches.length == 2) { 2427 | if (lastTouchesLength == 2) { 2428 | scale = Math.sqrt( 2429 | Math.pow(touches[0].pageX - touches[1].pageX, 2) + 2430 | Math.pow(touches[0].pageY - touches[1].pageY, 2) 2431 | ) / touchStartDistance; 2432 | map.setScale( 2433 | touchStartScale * scale, 2434 | centerTouchX, 2435 | centerTouchY 2436 | ) 2437 | map.tip.hide(); 2438 | e.preventDefault(); 2439 | } else { 2440 | offset = jvm.$(map.container).offset(); 2441 | if (touches[0].pageX > touches[1].pageX) { 2442 | centerTouchX = touches[1].pageX + (touches[0].pageX - touches[1].pageX) / 2; 2443 | } else { 2444 | centerTouchX = touches[0].pageX + (touches[1].pageX - touches[0].pageX) / 2; 2445 | } 2446 | if (touches[0].pageY > touches[1].pageY) { 2447 | centerTouchY = touches[1].pageY + (touches[0].pageY - touches[1].pageY) / 2; 2448 | } else { 2449 | centerTouchY = touches[0].pageY + (touches[1].pageY - touches[0].pageY) / 2; 2450 | } 2451 | centerTouchX -= offset.left; 2452 | centerTouchY -= offset.top; 2453 | touchStartScale = map.scale; 2454 | touchStartDistance = Math.sqrt( 2455 | Math.pow(touches[0].pageX - touches[1].pageX, 2) + 2456 | Math.pow(touches[0].pageY - touches[1].pageY, 2) 2457 | ); 2458 | } 2459 | } 2460 | 2461 | lastTouchesLength = touches.length; 2462 | }; 2463 | 2464 | jvm.$(this.container).bind('touchstart', handleTouchEvent); 2465 | jvm.$(this.container).bind('touchmove', handleTouchEvent); 2466 | }, 2467 | 2468 | bindElementEvents: function(){ 2469 | var map = this, 2470 | mouseMoved; 2471 | 2472 | this.container.mousemove(function(){ 2473 | mouseMoved = true; 2474 | }); 2475 | 2476 | /* Can not use common class selectors here because of the bug in jQuery 2477 | SVG handling, use with caution. */ 2478 | this.container.delegate("[class~='jvectormap-element']", 'mouseover mouseout', function(e){ 2479 | var baseVal = jvm.$(this).attr('class').baseVal || jvm.$(this).attr('class'), 2480 | type = baseVal.indexOf('jvectormap-region') === -1 ? 'marker' : 'region', 2481 | code = type == 'region' ? jvm.$(this).attr('data-code') : jvm.$(this).attr('data-index'), 2482 | element = type == 'region' ? map.regions[code].element : map.markers[code].element, 2483 | tipText = type == 'region' ? map.mapData.paths[code].name : (map.markers[code].config.name || ''), 2484 | tipShowEvent = jvm.$.Event(type+'TipShow.jvectormap'), 2485 | overEvent = jvm.$.Event(type+'Over.jvectormap'); 2486 | 2487 | if (e.type == 'mouseover') { 2488 | map.container.trigger(overEvent, [code]); 2489 | if (!overEvent.isDefaultPrevented()) { 2490 | element.setHovered(true); 2491 | } 2492 | 2493 | map.tip.text(tipText); 2494 | map.container.trigger(tipShowEvent, [map.tip, code]); 2495 | if (!tipShowEvent.isDefaultPrevented()) { 2496 | map.tip.show(); 2497 | map.tipWidth = map.tip.width(); 2498 | map.tipHeight = map.tip.height(); 2499 | } 2500 | } else { 2501 | element.setHovered(false); 2502 | map.tip.hide(); 2503 | map.container.trigger(type+'Out.jvectormap', [code]); 2504 | } 2505 | }); 2506 | 2507 | /* Can not use common class selectors here because of the bug in jQuery 2508 | SVG handling, use with caution. */ 2509 | this.container.delegate("[class~='jvectormap-element']", 'mousedown', function(){ 2510 | mouseMoved = false; 2511 | }); 2512 | 2513 | /* Can not use common class selectors here because of the bug in jQuery 2514 | SVG handling, use with caution. */ 2515 | this.container.delegate("[class~='jvectormap-element']", 'mouseup', function(){ 2516 | var baseVal = jvm.$(this).attr('class').baseVal ? jvm.$(this).attr('class').baseVal : jvm.$(this).attr('class'), 2517 | type = baseVal.indexOf('jvectormap-region') === -1 ? 'marker' : 'region', 2518 | code = type == 'region' ? jvm.$(this).attr('data-code') : jvm.$(this).attr('data-index'), 2519 | clickEvent = jvm.$.Event(type+'Click.jvectormap'), 2520 | element = type == 'region' ? map.regions[code].element : map.markers[code].element; 2521 | 2522 | if (!mouseMoved) { 2523 | map.container.trigger(clickEvent, [code]); 2524 | if ((type === 'region' && map.params.regionsSelectable) || (type === 'marker' && map.params.markersSelectable)) { 2525 | if (!clickEvent.isDefaultPrevented()) { 2526 | if (map.params[type+'sSelectableOne']) { 2527 | map.clearSelected(type+'s'); 2528 | } 2529 | element.setSelected(!element.isSelected); 2530 | } 2531 | } 2532 | } 2533 | }); 2534 | }, 2535 | 2536 | bindZoomButtons: function() { 2537 | var map = this; 2538 | 2539 | jvm.$('
').addClass('jvectormap-zoomin').text('+').appendTo(this.container); 2540 | jvm.$('
').addClass('jvectormap-zoomout').html('−').appendTo(this.container); 2541 | 2542 | this.container.find('.jvectormap-zoomin').click(function(){ 2543 | map.setScale(map.scale * map.params.zoomStep, map.width / 2, map.height / 2, false, map.params.zoomAnimate); 2544 | }); 2545 | this.container.find('.jvectormap-zoomout').click(function(){ 2546 | map.setScale(map.scale / map.params.zoomStep, map.width / 2, map.height / 2, false, map.params.zoomAnimate); 2547 | }); 2548 | }, 2549 | 2550 | createTip: function(){ 2551 | var map = this; 2552 | 2553 | this.tip = jvm.$('
').addClass('jvectormap-tip').appendTo(jvm.$('body')); 2554 | 2555 | this.container.mousemove(function(e){ 2556 | var left = e.pageX-15-map.tipWidth, 2557 | top = e.pageY-15-map.tipHeight; 2558 | 2559 | if (left < 5) { 2560 | left = e.pageX + 15; 2561 | } 2562 | if (top < 5) { 2563 | top = e.pageY + 15; 2564 | } 2565 | 2566 | if (map.tip.is(':visible')) { 2567 | map.tip.css({ 2568 | left: left, 2569 | top: top 2570 | }) 2571 | } 2572 | }); 2573 | }, 2574 | 2575 | setScale: function(scale, anchorX, anchorY, isCentered, animate) { 2576 | var viewportChangeEvent = jvm.$.Event('zoom.jvectormap'), 2577 | interval, 2578 | that = this, 2579 | i = 0, 2580 | count = Math.abs(Math.round((scale - this.scale) * 60 / Math.max(scale, this.scale))), 2581 | scaleStart, 2582 | scaleDiff, 2583 | transXStart, 2584 | transXDiff, 2585 | transYStart, 2586 | transYDiff, 2587 | transX, 2588 | transY, 2589 | deferred = new jvm.$.Deferred(); 2590 | 2591 | if (scale > this.params.zoomMax * this.baseScale) { 2592 | scale = this.params.zoomMax * this.baseScale; 2593 | } else if (scale < this.params.zoomMin * this.baseScale) { 2594 | scale = this.params.zoomMin * this.baseScale; 2595 | } 2596 | 2597 | if (typeof anchorX != 'undefined' && typeof anchorY != 'undefined') { 2598 | zoomStep = scale / this.scale; 2599 | if (isCentered) { 2600 | transX = anchorX + this.defaultWidth * (this.width / (this.defaultWidth * scale)) / 2; 2601 | transY = anchorY + this.defaultHeight * (this.height / (this.defaultHeight * scale)) / 2; 2602 | } else { 2603 | transX = this.transX - (zoomStep - 1) / scale * anchorX; 2604 | transY = this.transY - (zoomStep - 1) / scale * anchorY; 2605 | } 2606 | } 2607 | 2608 | if (animate && count > 0) { 2609 | scaleStart = this.scale; 2610 | scaleDiff = (scale - scaleStart) / count; 2611 | transXStart = this.transX * this.scale; 2612 | transYStart = this.transY * this.scale; 2613 | transXDiff = (transX * scale - transXStart) / count; 2614 | transYDiff = (transY * scale - transYStart) / count; 2615 | interval = setInterval(function(){ 2616 | i += 1; 2617 | that.scale = scaleStart + scaleDiff * i; 2618 | that.transX = (transXStart + transXDiff * i) / that.scale; 2619 | that.transY = (transYStart + transYDiff * i) / that.scale; 2620 | that.applyTransform(); 2621 | if (i == count) { 2622 | clearInterval(interval); 2623 | that.container.trigger(viewportChangeEvent, [scale/that.baseScale]); 2624 | deferred.resolve(); 2625 | } 2626 | }, 10); 2627 | } else { 2628 | this.transX = transX; 2629 | this.transY = transY; 2630 | this.scale = scale; 2631 | this.applyTransform(); 2632 | this.container.trigger(viewportChangeEvent, [scale/this.baseScale]); 2633 | deferred.resolve(); 2634 | } 2635 | 2636 | return deferred; 2637 | }, 2638 | 2639 | /** 2640 | * Set the map's viewport to the specific point and set zoom of the map to the specific level. Point and zoom level could be defined in two ways: using the code of some region to focus on or a central point and zoom level as numbers. 2641 | * @param This method takes a configuration object as the single argument. The options passed to it are the following: 2642 | * @param {Array} params.regions Array of region codes to zoom to. 2643 | * @param {String} params.region Region code to zoom to. 2644 | * @param {Number} params.scale Map scale to set. 2645 | * @param {Number} params.lat Latitude to set viewport to. 2646 | * @param {Number} params.lng Longitude to set viewport to. 2647 | * @param {Number} params.x Number from 0 to 1 specifying the horizontal coordinate of the central point of the viewport. 2648 | * @param {Number} params.y Number from 0 to 1 specifying the vertical coordinate of the central point of the viewport. 2649 | * @param {Boolean} params.animate Indicates whether or not to animate the scale change and transition. 2650 | */ 2651 | setFocus: function(config){ 2652 | var bbox, 2653 | itemBbox, 2654 | newBbox, 2655 | codes, 2656 | i, 2657 | point; 2658 | 2659 | config = config || {}; 2660 | 2661 | if (config.region) { 2662 | codes = [config.region]; 2663 | } else if (config.regions) { 2664 | codes = config.regions; 2665 | } 2666 | 2667 | if (codes) { 2668 | for (i = 0; i < codes.length; i++) { 2669 | if (this.regions[codes[i]]) { 2670 | itemBbox = this.regions[codes[i]].element.shape.getBBox(); 2671 | if (itemBbox) { 2672 | if (typeof bbox == 'undefined') { 2673 | bbox = itemBbox; 2674 | } else { 2675 | newBbox = { 2676 | x: Math.min(bbox.x, itemBbox.x), 2677 | y: Math.min(bbox.y, itemBbox.y), 2678 | width: Math.max(bbox.x + bbox.width, itemBbox.x + itemBbox.width) - Math.min(bbox.x, itemBbox.x), 2679 | height: Math.max(bbox.y + bbox.height, itemBbox.y + itemBbox.height) - Math.min(bbox.y, itemBbox.y) 2680 | } 2681 | bbox = newBbox; 2682 | } 2683 | } 2684 | } 2685 | } 2686 | return this.setScale( 2687 | Math.min(this.width / bbox.width, this.height / bbox.height), 2688 | - (bbox.x + bbox.width / 2), 2689 | - (bbox.y + bbox.height / 2), 2690 | true, 2691 | config.animate 2692 | ); 2693 | } else { 2694 | if (config.lat && config.lng) { 2695 | point = this.latLngToPoint(config.lat, config.lng); 2696 | config.x = this.transX - point.x / this.scale; 2697 | config.y = this.transY - point.y / this.scale; 2698 | } else if (config.x && config.y) { 2699 | config.x *= -this.defaultWidth; 2700 | config.y *= -this.defaultHeight; 2701 | } 2702 | return this.setScale(config.scale * this.baseScale, config.x, config.y, true, config.animate); 2703 | } 2704 | }, 2705 | 2706 | getSelected: function(type){ 2707 | var key, 2708 | selected = []; 2709 | 2710 | for (key in this[type]) { 2711 | if (this[type][key].element.isSelected) { 2712 | selected.push(key); 2713 | } 2714 | } 2715 | return selected; 2716 | }, 2717 | 2718 | /** 2719 | * Return the codes of currently selected regions. 2720 | * @returns {Array} 2721 | */ 2722 | getSelectedRegions: function(){ 2723 | return this.getSelected('regions'); 2724 | }, 2725 | 2726 | /** 2727 | * Return the codes of currently selected markers. 2728 | * @returns {Array} 2729 | */ 2730 | getSelectedMarkers: function(){ 2731 | return this.getSelected('markers'); 2732 | }, 2733 | 2734 | setSelected: function(type, keys){ 2735 | var i; 2736 | 2737 | if (typeof keys != 'object') { 2738 | keys = [keys]; 2739 | } 2740 | 2741 | if (jvm.$.isArray(keys)) { 2742 | for (i = 0; i < keys.length; i++) { 2743 | this[type][keys[i]].element.setSelected(true); 2744 | } 2745 | } else { 2746 | for (i in keys) { 2747 | this[type][i].element.setSelected(!!keys[i]); 2748 | } 2749 | } 2750 | }, 2751 | 2752 | /** 2753 | * Set or remove selected state for the regions. 2754 | * @param {String|Array|Object} keys If String or Array the region(s) with the corresponding code(s) will be selected. If Object was provided its keys are codes of regions, state of which should be changed. Selected state will be set if value is true, removed otherwise. 2755 | */ 2756 | setSelectedRegions: function(keys){ 2757 | this.setSelected('regions', keys); 2758 | }, 2759 | 2760 | /** 2761 | * Set or remove selected state for the markers. 2762 | * @param {String|Array|Object} keys If String or Array the marker(s) with the corresponding code(s) will be selected. If Object was provided its keys are codes of markers, state of which should be changed. Selected state will be set if value is true, removed otherwise. 2763 | */ 2764 | setSelectedMarkers: function(keys){ 2765 | this.setSelected('markers', keys); 2766 | }, 2767 | 2768 | clearSelected: function(type){ 2769 | var select = {}, 2770 | selected = this.getSelected(type), 2771 | i; 2772 | 2773 | for (i = 0; i < selected.length; i++) { 2774 | select[selected[i]] = false; 2775 | }; 2776 | 2777 | this.setSelected(type, select); 2778 | }, 2779 | 2780 | /** 2781 | * Remove the selected state from all the currently selected regions. 2782 | */ 2783 | clearSelectedRegions: function(){ 2784 | this.clearSelected('regions'); 2785 | }, 2786 | 2787 | /** 2788 | * Remove the selected state from all the currently selected markers. 2789 | */ 2790 | clearSelectedMarkers: function(){ 2791 | this.clearSelected('markers'); 2792 | }, 2793 | 2794 | /** 2795 | * Return the instance of Map. Useful when instantiated as a jQuery plug-in. 2796 | * @returns {Map} 2797 | */ 2798 | getMapObject: function(){ 2799 | return this; 2800 | }, 2801 | 2802 | /** 2803 | * Return the name of the region by region code. 2804 | * @returns {String} 2805 | */ 2806 | getRegionName: function(code){ 2807 | return this.mapData.paths[code].name; 2808 | }, 2809 | 2810 | createRegions: function(){ 2811 | var key, 2812 | region, 2813 | map = this; 2814 | 2815 | this.regionLabelsGroup = this.regionLabelsGroup || this.canvas.addGroup(); 2816 | 2817 | for (key in this.mapData.paths) { 2818 | region = new jvm.Region({ 2819 | map: this, 2820 | path: this.mapData.paths[key].path, 2821 | code: key, 2822 | style: jvm.$.extend(true, {}, this.params.regionStyle), 2823 | labelStyle: jvm.$.extend(true, {}, this.params.regionLabelStyle), 2824 | canvas: this.canvas, 2825 | labelsGroup: this.regionLabelsGroup, 2826 | label: this.canvas.mode != 'vml' ? (this.params.labels && this.params.labels.regions) : null 2827 | }); 2828 | 2829 | jvm.$(region.shape).bind('selected', function(e, isSelected){ 2830 | map.container.trigger('regionSelected.jvectormap', [jvm.$(this.node).attr('data-code'), isSelected, map.getSelectedRegions()]); 2831 | }); 2832 | this.regions[key] = { 2833 | element: region, 2834 | config: this.mapData.paths[key] 2835 | }; 2836 | } 2837 | }, 2838 | 2839 | createMarkers: function(markers) { 2840 | var i, 2841 | marker, 2842 | point, 2843 | markerConfig, 2844 | markersArray, 2845 | map = this; 2846 | 2847 | this.markersGroup = this.markersGroup || this.canvas.addGroup(); 2848 | this.markerLabelsGroup = this.markerLabelsGroup || this.canvas.addGroup(); 2849 | 2850 | if (jvm.$.isArray(markers)) { 2851 | markersArray = markers.slice(); 2852 | markers = {}; 2853 | for (i = 0; i < markersArray.length; i++) { 2854 | markers[i] = markersArray[i]; 2855 | } 2856 | } 2857 | 2858 | for (i in markers) { 2859 | markerConfig = markers[i] instanceof Array ? {latLng: markers[i]} : markers[i]; 2860 | point = this.getMarkerPosition( markerConfig ); 2861 | 2862 | if (point !== false) { 2863 | marker = new jvm.Marker({ 2864 | map: this, 2865 | style: jvm.$.extend(true, {}, this.params.markerStyle, {initial: markerConfig.style || {}}), 2866 | labelStyle: jvm.$.extend(true, {}, this.params.markerLabelStyle), 2867 | index: i, 2868 | cx: point.x, 2869 | cy: point.y, 2870 | group: this.markersGroup, 2871 | canvas: this.canvas, 2872 | labelsGroup: this.markerLabelsGroup, 2873 | label: this.canvas.mode != 'vml' ? (this.params.labels && this.params.labels.markers) : null 2874 | }); 2875 | 2876 | jvm.$(marker.shape).bind('selected', function(e, isSelected){ 2877 | map.container.trigger('markerSelected.jvectormap', [jvm.$(this.node).attr('data-index'), isSelected, map.getSelectedMarkers()]); 2878 | }); 2879 | if (this.markers[i]) { 2880 | this.removeMarkers([i]); 2881 | } 2882 | this.markers[i] = {element: marker, config: markerConfig}; 2883 | } 2884 | } 2885 | }, 2886 | 2887 | repositionMarkers: function() { 2888 | var i, 2889 | point; 2890 | 2891 | for (i in this.markers) { 2892 | point = this.getMarkerPosition( this.markers[i].config ); 2893 | if (point !== false) { 2894 | this.markers[i].element.setStyle({cx: point.x, cy: point.y}); 2895 | } 2896 | } 2897 | }, 2898 | 2899 | repositionLabels: function() { 2900 | var key; 2901 | 2902 | for (key in this.regions) { 2903 | this.regions[key].element.updateLabelPosition(); 2904 | } 2905 | 2906 | for (key in this.markers) { 2907 | this.markers[key].element.updateLabelPosition(); 2908 | } 2909 | }, 2910 | 2911 | getMarkerPosition: function(markerConfig) { 2912 | if (jvm.Map.maps[this.params.map].projection) { 2913 | return this.latLngToPoint.apply(this, markerConfig.latLng || [0, 0]); 2914 | } else { 2915 | return { 2916 | x: markerConfig.coords[0]*this.scale + this.transX*this.scale, 2917 | y: markerConfig.coords[1]*this.scale + this.transY*this.scale 2918 | }; 2919 | } 2920 | }, 2921 | 2922 | /** 2923 | * Add one marker to the map. 2924 | * @param {String} key Marker unique code. 2925 | * @param {Object} marker Marker configuration parameters. 2926 | * @param {Array} seriesData Values to add to the data series. 2927 | */ 2928 | addMarker: function(key, marker, seriesData){ 2929 | var markers = {}, 2930 | data = [], 2931 | values, 2932 | i, 2933 | seriesData = seriesData || []; 2934 | 2935 | markers[key] = marker; 2936 | 2937 | for (i = 0; i < seriesData.length; i++) { 2938 | values = {}; 2939 | if (typeof seriesData[i] !== 'undefined') { 2940 | values[key] = seriesData[i]; 2941 | } 2942 | data.push(values); 2943 | } 2944 | this.addMarkers(markers, data); 2945 | }, 2946 | 2947 | /** 2948 | * Add set of marker to the map. 2949 | * @param {Object|Array} markers Markers to add to the map. In case of array is provided, codes of markers will be set as string representations of array indexes. 2950 | * @param {Array} seriesData Values to add to the data series. 2951 | */ 2952 | addMarkers: function(markers, seriesData){ 2953 | var i; 2954 | 2955 | seriesData = seriesData || []; 2956 | 2957 | this.createMarkers(markers); 2958 | for (i = 0; i < seriesData.length; i++) { 2959 | this.series.markers[i].setValues(seriesData[i] || {}); 2960 | }; 2961 | }, 2962 | 2963 | /** 2964 | * Remove some markers from the map. 2965 | * @param {Array} markers Array of marker codes to be removed. 2966 | */ 2967 | removeMarkers: function(markers){ 2968 | var i; 2969 | 2970 | for (i = 0; i < markers.length; i++) { 2971 | this.markers[ markers[i] ].element.remove(); 2972 | delete this.markers[ markers[i] ]; 2973 | }; 2974 | }, 2975 | 2976 | /** 2977 | * Remove all markers from the map. 2978 | */ 2979 | removeAllMarkers: function(){ 2980 | var i, 2981 | markers = []; 2982 | 2983 | for (i in this.markers) { 2984 | markers.push(i); 2985 | } 2986 | this.removeMarkers(markers) 2987 | }, 2988 | 2989 | /** 2990 | * Converts coordinates expressed as latitude and longitude to the coordinates in pixels on the map. 2991 | * @param {Number} lat Latitide of point in degrees. 2992 | * @param {Number} lng Longitude of point in degrees. 2993 | */ 2994 | latLngToPoint: function(lat, lng) { 2995 | var point, 2996 | proj = jvm.Map.maps[this.params.map].projection, 2997 | centralMeridian = proj.centralMeridian, 2998 | inset, 2999 | bbox; 3000 | 3001 | if (lng < (-180 + centralMeridian)) { 3002 | lng += 360; 3003 | } 3004 | 3005 | point = jvm.Proj[proj.type](lat, lng, centralMeridian); 3006 | 3007 | inset = this.getInsetForPoint(point.x, point.y); 3008 | if (inset) { 3009 | bbox = inset.bbox; 3010 | 3011 | point.x = (point.x - bbox[0].x) / (bbox[1].x - bbox[0].x) * inset.width * this.scale; 3012 | point.y = (point.y - bbox[0].y) / (bbox[1].y - bbox[0].y) * inset.height * this.scale; 3013 | 3014 | return { 3015 | x: point.x + this.transX*this.scale + inset.left*this.scale, 3016 | y: point.y + this.transY*this.scale + inset.top*this.scale 3017 | }; 3018 | } else { 3019 | return false; 3020 | } 3021 | }, 3022 | 3023 | /** 3024 | * Converts cartesian coordinates into coordinates expressed as latitude and longitude. 3025 | * @param {Number} x X-axis of point on map in pixels. 3026 | * @param {Number} y Y-axis of point on map in pixels. 3027 | */ 3028 | pointToLatLng: function(x, y) { 3029 | var proj = jvm.Map.maps[this.params.map].projection, 3030 | centralMeridian = proj.centralMeridian, 3031 | insets = jvm.Map.maps[this.params.map].insets, 3032 | i, 3033 | inset, 3034 | bbox, 3035 | nx, 3036 | ny; 3037 | 3038 | for (i = 0; i < insets.length; i++) { 3039 | inset = insets[i]; 3040 | bbox = inset.bbox; 3041 | 3042 | nx = x - (this.transX*this.scale + inset.left*this.scale); 3043 | ny = y - (this.transY*this.scale + inset.top*this.scale); 3044 | 3045 | nx = (nx / (inset.width * this.scale)) * (bbox[1].x - bbox[0].x) + bbox[0].x; 3046 | ny = (ny / (inset.height * this.scale)) * (bbox[1].y - bbox[0].y) + bbox[0].y; 3047 | 3048 | if (nx > bbox[0].x && nx < bbox[1].x && ny > bbox[0].y && ny < bbox[1].y) { 3049 | return jvm.Proj[proj.type + '_inv'](nx, -ny, centralMeridian); 3050 | } 3051 | } 3052 | 3053 | return false; 3054 | }, 3055 | 3056 | getInsetForPoint: function(x, y){ 3057 | var insets = jvm.Map.maps[this.params.map].insets, 3058 | i, 3059 | bbox; 3060 | 3061 | for (i = 0; i < insets.length; i++) { 3062 | bbox = insets[i].bbox; 3063 | if (x > bbox[0].x && x < bbox[1].x && y > bbox[0].y && y < bbox[1].y) { 3064 | return insets[i]; 3065 | } 3066 | } 3067 | }, 3068 | 3069 | createSeries: function(){ 3070 | var i, 3071 | key; 3072 | 3073 | this.series = { 3074 | markers: [], 3075 | regions: [] 3076 | }; 3077 | 3078 | for (key in this.params.series) { 3079 | for (i = 0; i < this.params.series[key].length; i++) { 3080 | this.series[key][i] = new jvm.DataSeries( 3081 | this.params.series[key][i], 3082 | this[key], 3083 | this 3084 | ); 3085 | } 3086 | } 3087 | }, 3088 | 3089 | /** 3090 | * Gracefully remove the map and and all its accessories, unbind event handlers. 3091 | */ 3092 | remove: function(){ 3093 | this.tip.remove(); 3094 | this.container.remove(); 3095 | jvm.$(window).unbind('resize', this.onResize); 3096 | jvm.$('body').unbind('mouseup', this.onContainerMouseUp); 3097 | } 3098 | }; 3099 | 3100 | jvm.Map.maps = {}; 3101 | jvm.Map.defaultParams = { 3102 | map: 'world_mill_en', 3103 | backgroundColor: '#505050', 3104 | zoomButtons: true, 3105 | zoomOnScroll: true, 3106 | panOnDrag: true, 3107 | zoomMax: 8, 3108 | zoomMin: 1, 3109 | zoomStep: 1.6, 3110 | zoomAnimate: true, 3111 | regionsSelectable: false, 3112 | markersSelectable: false, 3113 | bindTouchEvents: true, 3114 | regionStyle: { 3115 | initial: { 3116 | fill: 'white', 3117 | "fill-opacity": 1, 3118 | stroke: 'none', 3119 | "stroke-width": 0, 3120 | "stroke-opacity": 1 3121 | }, 3122 | hover: { 3123 | "fill-opacity": 0.8, 3124 | cursor: 'pointer' 3125 | }, 3126 | selected: { 3127 | fill: 'yellow' 3128 | }, 3129 | selectedHover: { 3130 | } 3131 | }, 3132 | regionLabelStyle: { 3133 | initial: { 3134 | 'font-family': 'Verdana', 3135 | 'font-size': '12', 3136 | 'font-weight': 'bold', 3137 | cursor: 'default', 3138 | fill: 'black' 3139 | }, 3140 | hover: { 3141 | cursor: 'pointer' 3142 | } 3143 | }, 3144 | markerStyle: { 3145 | initial: { 3146 | fill: 'grey', 3147 | stroke: '#505050', 3148 | "fill-opacity": 1, 3149 | "stroke-width": 1, 3150 | "stroke-opacity": 1, 3151 | r: 5 3152 | }, 3153 | hover: { 3154 | stroke: 'black', 3155 | "stroke-width": 2, 3156 | cursor: 'pointer' 3157 | }, 3158 | selected: { 3159 | fill: 'blue' 3160 | }, 3161 | selectedHover: { 3162 | } 3163 | }, 3164 | markerLabelStyle: { 3165 | initial: { 3166 | 'font-family': 'Verdana', 3167 | 'font-size': '12', 3168 | 'font-weight': 'bold', 3169 | cursor: 'default', 3170 | fill: 'black' 3171 | }, 3172 | hover: { 3173 | cursor: 'pointer' 3174 | } 3175 | } 3176 | }; 3177 | jvm.Map.apiEvents = { 3178 | onRegionTipShow: 'regionTipShow', 3179 | onRegionOver: 'regionOver', 3180 | onRegionOut: 'regionOut', 3181 | onRegionClick: 'regionClick', 3182 | onRegionSelected: 'regionSelected', 3183 | onMarkerTipShow: 'markerTipShow', 3184 | onMarkerOver: 'markerOver', 3185 | onMarkerOut: 'markerOut', 3186 | onMarkerClick: 'markerClick', 3187 | onMarkerSelected: 'markerSelected', 3188 | onViewportChange: 'viewportChange' 3189 | }; 3190 | /** 3191 | * Creates map with drill-down functionality. 3192 | * @constructor 3193 | * @param {Object} params Parameters to initialize map with. 3194 | * @param {Number} params.maxLevel Maximum number of levels user can go through 3195 | * @param {Object} params.main Config of the main map. See jvm.Map for more information. 3196 | * @param {Function} params.mapNameByCode Function go generate map name by region code. Default value is: 3197 |
3198 | function(code, multiMap) {
3199 |   return code.toLowerCase()+'_'+
3200 |          multiMap.defaultProjection+'_en';
3201 | }
3202 | 
3203 | * @param {Function} params.mapUrlByCode Function to generate map url by region code. Default value is: 3204 |
3205 | function(code, multiMap){
3206 |   return 'jquery-jvectormap-data-'+
3207 |          code.toLowerCase()+'-'+
3208 |          multiMap.defaultProjection+'-en.js';
3209 | }
3210 | 
3211 | */ 3212 | jvm.MultiMap = function(params) { 3213 | var that = this; 3214 | 3215 | this.maps = {}; 3216 | this.params = jvm.$.extend(true, {}, jvm.MultiMap.defaultParams, params); 3217 | this.params.maxLevel = this.params.maxLevel || Number.MAX_VALUE; 3218 | this.params.main = this.params.main || {}; 3219 | this.params.main.multiMapLevel = 0; 3220 | this.history = [ this.addMap(this.params.main.map, this.params.main) ]; 3221 | this.defaultProjection = this.history[0].mapData.projection.type; 3222 | this.mapsLoaded = {}; 3223 | 3224 | this.params.container.css({position: 'relative'}); 3225 | this.backButton = jvm.$('
').addClass('jvectormap-goback').text('Back').appendTo(this.params.container); 3226 | this.backButton.hide(); 3227 | this.backButton.click(function(){ 3228 | that.goBack(); 3229 | }); 3230 | 3231 | this.spinner = jvm.$('
').addClass('jvectormap-spinner').appendTo(this.params.container); 3232 | this.spinner.hide(); 3233 | }; 3234 | 3235 | jvm.MultiMap.prototype = { 3236 | addMap: function(name, config){ 3237 | var cnt = jvm.$('
').css({ 3238 | width: '100%', 3239 | height: '100%' 3240 | }); 3241 | 3242 | this.params.container.append(cnt); 3243 | 3244 | this.maps[name] = new jvm.Map(jvm.$.extend(config, {container: cnt})); 3245 | if (this.params.maxLevel > config.multiMapLevel) { 3246 | this.maps[name].container.on('regionClick.jvectormap', {scope: this}, function(e, code){ 3247 | var multimap = e.data.scope, 3248 | mapName = multimap.params.mapNameByCode(code, multimap); 3249 | 3250 | if (!multimap.drillDownPromise || multimap.drillDownPromise.state() !== 'pending') { 3251 | multimap.drillDown(mapName, code); 3252 | } 3253 | }); 3254 | } 3255 | 3256 | 3257 | return this.maps[name]; 3258 | }, 3259 | 3260 | downloadMap: function(code){ 3261 | var that = this, 3262 | deferred = jvm.$.Deferred(); 3263 | 3264 | if (!this.mapsLoaded[code]) { 3265 | jvm.$.get(this.params.mapUrlByCode(code, this)).then(function(){ 3266 | that.mapsLoaded[code] = true; 3267 | deferred.resolve(); 3268 | }, function(){ 3269 | deferred.reject(); 3270 | }); 3271 | } else { 3272 | deferred.resolve(); 3273 | } 3274 | return deferred; 3275 | }, 3276 | 3277 | drillDown: function(name, code){ 3278 | var currentMap = this.history[this.history.length - 1], 3279 | that = this, 3280 | focusPromise = currentMap.setFocus({region: code, animate: true}), 3281 | downloadPromise = this.downloadMap(code); 3282 | 3283 | focusPromise.then(function(){ 3284 | if (downloadPromise.state() === 'pending') { 3285 | that.spinner.show(); 3286 | } 3287 | }); 3288 | downloadPromise.always(function(){ 3289 | that.spinner.hide(); 3290 | }); 3291 | this.drillDownPromise = jvm.$.when(downloadPromise, focusPromise); 3292 | this.drillDownPromise.then(function(){ 3293 | currentMap.params.container.hide(); 3294 | if (!that.maps[name]) { 3295 | that.addMap(name, {map: name, multiMapLevel: currentMap.params.multiMapLevel + 1}); 3296 | } else { 3297 | that.maps[name].params.container.show(); 3298 | } 3299 | that.history.push( that.maps[name] ); 3300 | that.backButton.show(); 3301 | }); 3302 | }, 3303 | 3304 | goBack: function(){ 3305 | var currentMap = this.history.pop(), 3306 | prevMap = this.history[this.history.length - 1], 3307 | that = this; 3308 | 3309 | currentMap.setFocus({scale: 1, x: 0.5, y: 0.5, animate: true}).then(function(){ 3310 | currentMap.params.container.hide(); 3311 | prevMap.params.container.show(); 3312 | prevMap.updateSize(); 3313 | if (that.history.length === 1) { 3314 | that.backButton.hide(); 3315 | } 3316 | prevMap.setFocus({scale: 1, x: 0.5, y: 0.5, animate: true}); 3317 | }); 3318 | } 3319 | }; 3320 | 3321 | jvm.MultiMap.defaultParams = { 3322 | mapNameByCode: function(code, multiMap){ 3323 | return code.toLowerCase()+'_'+multiMap.defaultProjection+'_en'; 3324 | }, 3325 | mapUrlByCode: function(code, multiMap){ 3326 | return 'jquery-jvectormap-data-'+code.toLowerCase()+'-'+multiMap.defaultProjection+'-en.js'; 3327 | } 3328 | } 3329 | --------------------------------------------------------------------------------