PageSourceSearch

https://uzs.ru/bitrix/templates/universelite_s1/js/jquery.vmap.js

js uzs.ru collected 2026-10-09 22:42:31 UTC 31,579 bytes, 1,104 lines download raw bytes

vendor: 15,651 bytes, lines 1-533
1/*!
2 * jQVMap Version 1.0
3 *
4 * http://jqvmap.com
5 *
6 * Copyright 2012, Peter Schmalfeldt <[email protected]>
7 * Copyright 2011-2012, Kirill Lebedev
8 * Licensed under the MIT license.
9 *
10 * Fork Me @ https://github.com/manifestinteractive/jqvmap
11 */
12
13
14(function ($) {
15
16  var apiParams = {
17    colors: 1,
18    values: 1,
19    backgroundColor: 1,
20    scaleColors: 1,
21    normalizeFunction: 1,
22    enableZoom: 1,
23    showTooltip: 1,
24    borderColor: 1,
25    borderWidth: 1,
26    borderOpacity: 1,
27    selectedRegions: 1,
28    multiSelectRegion: 1
29  };
30
31  var apiEvents = {
32    onLabelShow: 'labelShow',
33    onRegionOver: 'regionMouseOver',
34    onRegionOut: 'regionMouseOut',
35    onRegionClick: 'regionClick',
36    onRegionSelect: 'regionSelect',
37    onRegionDeselect: 'regionDeselect'
38  };
39
40  $.fn.vectorMap = function (options) {
41
42    var defaultParams = {
43      map: 'world_en',
44      backgroundColor: '#a5bfdd',
45      color: '#f4f3f0',
46      hoverColor: '#c9dfaf',
47      selectedColor: '#c9dfaf',
48      scaleColors: ['#b6d6ff', '#005ace'],
49      normalizeFunction: 'linear',
50      enableZoom: true,
51      showTooltip: true,
52      borderColor: '#818181',
53      borderWidth: 1,
54      borderOpacity: 0.25,
55      selectedRegions: null,
56      multiSelectRegion: false
57    }, map = this.data('mapObject');
58
59    if (options === 'addMap') {
60      WorldMap.maps[arguments[1]] = arguments[2];
61    } else if (options === 'set' && apiParams[arguments[1]]) {
62      map['set' + arguments[1].charAt(0).toUpperCase() + arguments[1].substr(1)].apply(map, Array.prototype.slice.call(arguments, 2));
63    } else if (typeof options === 'string' &&
64               typeof map[options] === 'function') {
65      return map[options].apply(map, Array.prototype.slice.call(arguments, 1));
66    } else {
67      $.extend(defaultParams, options);
68      defaultParams.container = this;
69      this.css({ position: 'relative', overflow: 'hidden' });
70
71      map = new WorldMap(defaultParams);
72
73      this.data('mapObject', map);
74
75      for (var e in apiEvents) {
76        if (defaultParams[e]) {
77          this.bind(apiEvents[e] + '.jqvmap', defaultParams[e]);
78        }
79      }
80    }
81  };
82
83  var VectorCanvas = function (width, height, params) {
84    this.mode = window.SVGAngle ? 'svg' : 'vml';
85    this.params = params;
86
87    if (this.mode == 'svg') {
88      this.createSvgNode = function (nodeName) {
89        return document.createElementNS(this.svgns, nodeName);
90      };
91    } else {
92      try {
93        if (!document.namespaces.rvml) {
94          document.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
95        }
96        this.createVmlNode = function (tagName) {
97          return document.createElement('<rvml:' + tagName + ' class="rvml">');
98        };
99      } catch (e) {
100        this.createVmlNode = function (tagName) {
101          return document.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
102        };
103      }
104
105      document.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
106    }
107
108    if (this.mode == 'svg') {
109      this.canvas = this.createSvgNode('svg');
110    } else {
111      this.canvas = this.createVmlNode('group');
112      this.canvas.style.position = 'absolute';
113    }
114
115    this.setSize(width, height);
116  };
117
118  VectorCanvas.prototype = {
119    svgns: "http://www.w3.org/2000/svg",
120    mode: 'svg',
121    width: 0,
122    height: 0,
123    canvas: null,
124
125    setSize: function (width, height) {
126      if (this.mode == 'svg') {
127        this.canvas.setAttribute('width', width);
128        this.canvas.setAttribute('height', height);
129      } else {
130        this.canvas.style.width = width + "px";
131        this.canvas.style.height = height + "px";
132        this.canvas.coordsize = width + ' ' + height;
133        this.canvas.coordorigin = "0 0";
134        if (this.rootGroup) {
135          var pathes = this.rootGroup.getElementsByTagName('shape');
136          for (var i = 0, l = pathes.length; i < l; i++) {
137            pathes[i].coordsize = width + ' ' + height;
138            pathes[i].style.width = width + 'px';
139            pathes[i].style.height = height + 'px';
140          }
141          this.rootGroup.coordsize = width + ' ' + height;
142          this.rootGroup.style.width = width + 'px';
143          this.rootGroup.style.height = height + 'px';
144        }
145      }
146      this.width = width;
147      this.height = height;
148    },
149
150    createPath: function (config) {
151      var node;
152      if (this.mode == 'svg') {
153        node = this.createSvgNode('path');
154        node.setAttribute('d', config.path);
155
156        if (this.params.borderColor !== null) {
157          node.setAttribute('stroke', this.params.borderColor);
158        }
159        if (this.params.borderWidth > 0) {
160          node.setAttribute('stroke-width', this.params.borderWidth);
161          node.setAttribute('stroke-linecap', 'round');
162          node.setAttribute('stroke-linejoin', 'round');
163        }
164        if (this.params.borderOpacity > 0) {
165          node.setAttribute('stroke-opacity', this.params.borderOpacity);
166        }
167
168        node.setFill = function (color) {
169          this.setAttribute("fill", color);
170          if (this.getAttribute("original") === null) {
171            this.setAttribute("original", color);
172          }
173        };
174
175        node.getFill = function (color) {
176          return this.getAttribute("fill");
177        };
178
179        node.getOriginalFill = function () {
180          return this.getAttribute("original");
181        };
182
183        node.setOpacity = function (opacity) {
184          this.setAttribute('fill-opacity', opacity);
185        };
186      } else {
187        node = this.createVmlNode('shape');
188        node.coordorigin = "0 0";
189        node.coordsize = this.width + ' ' + this.height;
190        node.style.width = this.width + 'px';
191        node.style.height = this.height + 'px';
192        node.fillcolor = WorldMap.defaultFillColor;
193        node.stroked = false;
194        node.path = VectorCanvas.pathSvgToVml(config.path);
195
196        var scale = this.createVmlNode('skew');
197        scale.on = true;
198        scale.matrix = '0.01,0,0,0.01,0,0';
199        scale.offset = '0,0';
200
201        node.appendChild(scale);
202
203        var fill = this.createVmlNode('fill');
204        node.appendChild(fill);
205
206        node.setFill = function (color) {
207          this.getElementsByTagName('fill')[0].color = color;
208          if (this.getAttribute("original") === null) {
209            this.setAttribute("original", color);
210          }
211        };
212
213        node.getFill = function (color) {
214          return this.getElementsByTagName('fill')[0].color;
215        };
216        node.getOriginalFill = function () {
217          return this.getAttribute("original");
218        };
219        node.setOpacity = function (opacity) {
220          this.getElementsByTagName('fill')[0].opacity = parseInt(opacity * 100, 10) + '%';
221        };
222      }
223      return node;
224    },
225
226    createGroup: function (isRoot) {
227      var node;
228      if (this.mode == 'svg') {
229        node = this.createSvgNode('g');
230      } else {
231        node = this.createVmlNode('group');
232        node.style.width = this.width + 'px';
233        node.style.height = this.height + 'px';
234        node.style.left = '0px';
235        node.style.top = '0px';
236        node.coordorigin = "0 0";
237        node.coordsize = this.width + ' ' + this.height;
238      }
239
240      if (isRoot) {
241        this.rootGroup = node;
242      }
243      return node;
244    },
245
246    applyTransformParams: function (scale, transX, transY) {
247      if (this.mode == 'svg') {
248        this.rootGroup.setAttribute('transform', 'scale(' + scale + ') translate(' + transX + ', ' + transY + ')');
249      } else {
250        this.rootGroup.coordorigin = (this.width - transX) + ',' + (this.height - transY);
251        this.rootGroup.coordsize = this.width / scale + ',' + this.height / scale;
252      }
253    }
254  };
255
256  VectorCanvas.pathSvgToVml = function (path) {
257    var result = '';
258    var cx = 0, cy = 0, ctrlx, ctrly;
259
260    return path.replace(/([MmLlHhVvCcSs])((?:-?(?:\d+)?(?:\.\d+)?,?\s?)+)/g, function (segment, letter, coords, index) {
261      coords = coords.replace(/(\d)-/g, '$1,-').replace(/\s+/g, ',').split(',');
262      if (!coords[0]) {
263        coords.shift();
264      }
265
266      for (var i = 0, l = coords.length; i < l; i++) {
267        coords[i] = Math.round(100 * coords[i]);
268      }
269
270      switch (letter) {
271      case 'm':
272        cx += coords[0];
273        cy += coords[1];
274        return 't' + coords.join(',');
275        break;
276
277      case 'M':
278        cx = coords[0];
279        cy = coords[1];
280        return 'm' + coords.join(',');
281        break;
282
283      case 'l':
284        cx += coords[0];
285        cy += coords[1];
286        return 'r' + coords.join(',');
287        break;
288
289      case 'L':
290        cx = coords[0];
291        cy = coords[1];
292        return 'l' + coords.join(',');
293        break;
294
295      case 'h':
296        cx += coords[0];
297        return 'r' + coords[0] + ',0';
298        break;
299
300      case 'H':
301        cx = coords[0];
302        return 'l' + cx + ',' + cy;
303        break;
304
305      case 'v':
306        cy += coords[0];
307        return 'r0,' + coords[0];
308        break;
309
310      case 'V':
311        cy = coords[0];
312        return 'l' + cx + ',' + cy;
313        break;
314
315      case 'c':
316        ctrlx = cx + coords[coords.length - 4];
317        ctrly = cy + coords[coords.length - 3];
318        cx += coords[coords.length - 2];
319        cy += coords[coords.length - 1];
320        return 'v' + coords.join(',');
321        break;
322
323      case 'C':
324        ctrlx = coords[coords.length - 4];
325        ctrly = coords[coords.length - 3];
326        cx = coords[coords.length - 2];
327        cy = coords[coords.length - 1];
328        return 'c' + coords.join(',');
329        break;
330
331      case 's':
332        coords.unshift(cy - ctrly);
333        coords.unshift(cx - ctrlx);
334        ctrlx = cx + coords[coords.length - 4];
335        ctrly = cy + coords[coords.length - 3];
336        cx += coords[coords.length - 2];
337        cy += coords[coords.length - 1];
338        return 'v' + coords.join(',');
339        break;
340
341      case 'S':
342        coords.unshift(cy + cy - ctrly);
343        coords.unshift(cx + cx - ctrlx);
344        ctrlx = coords[coords.length - 4];
345        ctrly = coords[coords.length - 3];
346        cx = coords[coords.length - 2];
347        cy = coords[coords.length - 1];
348        return 'c' + coords.join(',');
349        break;
350
351      default:
352        return false;
353        break;
354      }
355
356      return '';
357
358    }).replace(/z/g, '');
359  };
360
361  var WorldMap = function (params) {
362    params = params || {};
363    var map = this;
364    var mapData = WorldMap.maps[params.map];
365
366    this.selectedRegions = [];
367    this.multiSelectRegion = params.multiSelectRegion;
368
369    this.container = params.container;
370
371    this.defaultWidth = mapData.width;
372    this.defaultHeight = mapData.height;
373
374    this.color = params.color;
375    this.selectedColor = params.selectedColor;
376    this.hoverColor = params.hoverColor;
377    this.hoverOpacity = params.hoverOpacity;
378    this.setBackgroundColor(params.backgroundColor);
379
380    this.width = params.container.width();
381    this.height = params.container.height();
382
383    this.resize();
384
385    jQuery(window).resize(function () {
386      map.width = params.container.width();
387      map.height = params.container.height();
388      map.resize();
389      map.canvas.setSize(map.width, map.height);
390      map.applyTransform();
391    });
392
393    this.canvas = new VectorCanvas(this.width, this.height, params);
394    params.container.append(this.canvas.canvas);
395
396    this.makeDraggable();
397
398    this.rootGroup = this.canvas.createGroup(true);
399
400    this.index = WorldMap.mapIndex;
401    this.label = jQuery('<div/>').addClass('jqvmap-label').appendTo(jQuery('body')).hide();
402
403    if (params.enableZoom) {
404      jQuery('<div/>').addClass('jqvmap-zoomin').text('+').appendTo(params.container);
405      jQuery('<div/>').addClass('jqvmap-zoomout').html('&#x2212;').appendTo(params.container);
406    }
407
408    map.countries = [];
409
410    for (var key in mapData.pathes) {
411      var path = this.canvas.createPath({
412        path: mapData.pathes[key].path
413      });
414
415      path.setFill(this.color);
416      path.id = map.getCountryId(key);
417      map.countries[key] = path;
418
419      if (this.canvas.mode == 'svg') {
420        path.setAttribute('class', 'jvectormap-region');
421      } else {
422        jQuery(path).addClass('jvectormap-region');
423      }
424
425      jQuery(this.rootGroup).append(path);
426    }
427
428    jQuery(params.container).delegate(this.canvas.mode == 'svg' ? 'path' : 'shape', 'mouseover mouseout', function (e) {
429      var path = e.target,
430      code = e.target.id.split('_').pop(),
431      labelShowEvent = $.Event('labelShow.jqvmap'),
432      regionMouseOverEvent = $.Event('regionMouseOver.jqvmap');
433
434      if (e.type == 'mouseover') {
435        jQuery(params.container).trigger(regionMouseOverEvent, [code, mapData.pathes[code].name]);
436        if (!regionMouseOverEvent.isDefaultPrevented()) {
437          map.highlight(code, path);
438        }
439        if (params.showTooltip) {
440          map.label.text(mapData.pathes[code].name);
441          jQuery(params.container).trigger(labelShowEvent, [map.label, code]);
442
443          if (!labelShowEvent.isDefaultPrevented()) {
444            map.label.show();
445            map.labelWidth = map.label.width();
446            map.labelHeight = map.label.height();
447          }
448        }
449      } else {
450        map.unhighlight(code, path);
451
452        map.label.hide();
453        jQuery(params.container).trigger('regionMouseOut.jqvmap', [code, mapData.pathes[code].name]);
454      }
455    });
456
457    jQuery(params.container).delegate(this.canvas.mode == 'svg' ? 'path' : 'shape', 'click', function (e) {
458      if (!params.multiSelectRegion) {
459        for (var key in mapData.pathes) {
460          map.countries[key].currentFillColor = map.countries[key].getOriginalFill();
461          map.countries[key].setFill(map.countries[key].getOriginalFill());
462        }
463      }
464
465      var path = e.target;
466      var code = e.target.id.split('_').pop();
467
468      jQuery(params.container).trigger('regionClick.jqvmap', [code, mapData.pathes[code].name]);
469      if (!regionClickEvent.isDefaultPrevented()) {
470        if (map.selectedRegions.indexOf(code) !== -1) {
471          map.deselect(code, path);
472        } else {
473          map.select(code, path);
474        }
475      }
476
477      //console.log(selectedRegions);
478
479    });
480
481    if (params.showTooltip) {
482      params.container.mousemove(function (e) {
483        if (map.label.is(':visible')) {
484            var left = e.pageX - 15 - map.labelWidth;
485            var top = e.pageY - 15 - map.labelHeight;
486            
487            if(left < 0)
488               left = e.pageX + 15;
489            if(top < 0)
490                top = e.pageY + 15;
491            
492            map.label.css({
493                left: left,
494                top: top
495          });
496        }
497      });
498    }
499
500    this.setColors(params.colors);
501
502    this.canvas.canvas.appendChild(this.rootGroup);
503
504    this.applyTransform();
505
506    this.colorScale = new ColorScale(params.scaleColors, params.normalizeFunction, params.valueMin, params.valueMax);
507
508    if (params.values) {
509      this.values = params.values;
510      this.setValues(params.values);
511    }
512
513    if (params.selectedRegions) {
514      if (params.selectedRegions instanceof Array) {
515        for(var k in params.selectedRegions) {
516          this.select(params.selectedRegions[k].toLowerCase());
517        }
518      } else {
519        this.select(params.selectedRegions.toLowerCase());
520      }
521    }
522
523    this.bindZoomButtons();
524    
525    if(params.pins) {
526      /*if(params.pinMode) {
527          if(params.pinMode != "id" && params.pinMode != "content") {
528              params.pinMode = "content";
529          }
530      } else {
531          params.pinMode = "content";
532      }*/
533      this.pinHandlers = false;
534      this.placePins(params.pins, params.pinMode);
535    }
536
537    WorldMap.mapIndex++;
538  };
539
540  WorldMap.prototype = {
541    transX: 0,
542    transY: 0,
543    scale: 1,
544    baseTransX: 0,
545    baseTransY: 0,
546    baseScale: 1,
547    width: 0,
548    height: 0,
549    countries: {},
550    countriesColors: {},
551    countriesData: {},
552    zoomStep: 1.4,
553    zoomMaxStep: 4,
554    zoomCurStep: 1,
555
556    setColors: function (key, color) {
557      if (typeof key == 'string') {
558        this.countries[key].setFill(color);
559        this.countries[key].setAttribute("original", color);
560      } else {
561        var colors = key;
562
563        for (var code in colors) {
564          if (this.countries[code]) {
565            this.countries[code].setFill(colors[code]);
566            this.countries[code].setAttribute("original", colors[code]);
567          }
568        }
569      }
570    },
571
572    setValues: function (values) {
573      var max = 0,
574      min = Number.MAX_VALUE,
575      val;
576
577      for (var cc in values) {
578        val = parseFloat(values[cc]);
579        if (val > max) {
580          max = values[cc];
581        }
582        if (val && val < min) {
583          min = val;
584        }
585      }
586
587      this.colorScale.setMin(min);
588      this.colorScale.setMax(max);
589
590      var colors = {};
591      for (cc in values) {
592        val = parseFloat(values[cc]);
593        if (val) {
594          colors[cc] = this.colorScale.getColor(val);
595        } else {
596          colors[cc] = this.color;
597        }
598      }
599      this.setColors(colors);
600      this.values = values;
601    },
602
603    setBackgroundColor: function (backgroundColor) {
604      this.container.css('background-color', backgroundColor);
605    },
606
607    setScaleColors: function (colors) {
608      this.colorScale.setColors(colors);
609
610      if (this.values) {
611        this.setValues(this.values);
612      }
613    },
614
615    setNormalizeFunction: function (f) {
616      this.colorScale.setNormalizeFunction(f);
617
618      if (this.values) {
619        this.setValues(this.values);
620      }
621    },
622
623    highlight: function (cc, path) {
624      path = path || $('#' + this.getCountryId(cc))[0];
625      if (this.hoverOpacity) {
626        path.setOpacity(this.hoverOpacity);
627      } else if (this.hoverColor) {
628        path.currentFillColor = path.getFill() + '';
629        path.setFill(this.hoverColor);
630      }
631    },
632
633    unhighlight: function (cc, path) {
634      path = path || $('#' + this.getCountryId(cc))[0];
635      path.setOpacity(1);
636      if (path.currentFillColor) {
637        path.setFill(path.currentFillColor);
638      }
639    },
640
641    select: function (cc, path) {
642      path = path || $('#' + this.getCountryId(cc))[0];
643      if(this.selectedRegions.indexOf(cc) < 0) {
644        if (this.multiSelectRegion) {
645          this.selectedRegions.push(cc);
646        } else {
647          this.selectedRegions = [cc];
648        }
649        // MUST BE after the change of selectedRegions
650        // Otherwise, we might loop
651        $(this.container).trigger('regionSelect.jqvmap', [cc]);
652        if (this.selectedColor) {
653          path.currentFillColor = this.selectedColor;
654          path.setFill(this.selectedColor);
655        }
656      }
657    },
658
659    deselect: function (cc, path) {
660      path = path || $('#' + this.getCountryId(cc))[0];
661      if(this.selectedRegions.indexOf(cc) >= 0) {
662        this.selectedRegions.splice(this.selectedRegions.indexOf(cc), 1);
663        // MUST BE after the change of selectedRegions
664        // Otherwise, we might loop
665        $(this.container).trigger('regionDeselect.jqvmap', [cc]);
666        path.currentFillColor = path.getOriginalFill();
667        path.setFill(path.getOriginalFill());
668      }
669    },
670
671    isSelected: function(cc) {
672      return this.selectedRegions.indexOf(cc) >= 0;
673    },
674
675    resize: function () {
676      var curBaseScale = this.baseScale;
677      if (this.width / this.height > this.defaultWidth / this.defaultHeight) {
678        this.baseScale = this.height / this.defaultHeight;
679        this.baseTransX = Math.abs(this.width - this.defaultWidth * this.baseScale) / (2 * this.baseScale);
680      } else {
681        this.baseScale = this.width / this.defaultWidth;
682        this.baseTransY = Math.abs(this.height - this.defaultHeight * this.baseScale) / (2 * this.baseScale);
683      }
684      this.scale *= this.baseScale / curBaseScale;
685      this.transX *= this.baseScale / curBaseScale;
686      this.transY *= this.baseScale / curBaseScale;
687    },
688
689    reset: function () {
690      this.countryTitle.reset();
691      for (var key in this.countries) {
692        this.countries[key].setFill(WorldMap.defaultColor);
693      }
694      this.scale = this.baseScale;
695      this.transX = this.baseTransX;
696      this.transY = this.baseTransY;
697      this.applyTransform();
698    },
699
700    applyTransform: function () {
701      var maxTransX, maxTransY, minTransX, minTransY;
702      if (this.defaultWidth * this.scale <= this.width) {
703        maxTransX = (this.width - this.defaultWidth * this.scale) / (2 * this.scale);
704        minTransX = (this.width - this.defaultWidth * this.scale) / (2 * this.scale);
705      } else {
706        maxTransX = 0;
707        minTransX = (this.width - this.defaultWidth * this.scale) / this.scale;
708      }
709
710      if (this.defaultHeight * this.scale <= this.height) {
711        maxTransY = (this.height - this.defaultHeight * this.scale) / (2 * this.scale);
712        minTransY = (this.height - this.defaultHeight * this.scale) / (2 * this.scale);
713      } else {
714        maxTransY = 0;
715        minTransY = (this.height - this.defaultHeight * this.scale) / this.scale;
716      }
717
718      if (this.transY > maxTransY) {
719        this.transY = maxTransY;
720      }
721      else if (this.transY < minTransY) {
722        this.transY = minTransY;
723      }
724      if (this.transX > maxTransX) {
725        this.transX = maxTransX;
726      }
727      else if (this.transX < minTransX) {
728        this.transX = minTransX;
729      }
730
731      this.canvas.applyTransformParams(this.scale, this.transX, this.transY);
732    },
733
734    makeDraggable: function () {
735      var mouseDown = false;
736      var oldPageX, oldPageY;
737      var self = this;
738
739      self.isMoving = false;
740      self.isMovingTimeout = false;
741
742      this.container.mousemove(function (e) {
743
744        if (mouseDown) {
745          var curTransX = self.transX;
746          var curTransY = self.transY;
747
748          self.transX -= (oldPageX - e.pageX) / self.scale;
749          self.transY -= (oldPageY - e.pageY) / self.scale;
750
751          self.applyTransform();
752
753          oldPageX = e.pageX;
754          oldPageY = e.pageY;
755
756          self.isMoving = true;
757          if (self.isMovingTimeout) {
758            clearTimeout(self.isMovingTimeout);
759          }
760
761          self.container.trigger('drag');
762        }
763
764        return false;
765
766      }).mousedown(function (e) {
767
768        mouseDown = true;
769        oldPageX = e.pageX;
770        oldPageY = e.pageY;
771
772        return false;
773
774      }).mouseup(function () {
775
776        mouseDown = false;
777
778        self.isMovingTimeout = setTimeout(function () {
779          self.isMoving = false;
780        }, 100);
781
782        return false;
783
784      });
785    },
786
787    bindZoomButtons: function () {
788      var map = this;
789      this.container.find('.jqvmap-zoomin').click(function(){
790        map.zoomIn();
791      });
792      this.container.find('.jqvmap-zoomout').click(function(){
793        map.zoomOut();
794      });
795    },
796    
797    zoomIn: function () {
798      var map = this;
799      var sliderDelta = (jQuery('#zoom').innerHeight() - 6 * 2 - 15 * 2 - 3 * 2 - 7 - 6) / (this.zoomMaxStep - this.zoomCurStep);
800
801      if (map.zoomCurStep < map.zoomMaxStep) {
802        var curTransX = map.transX;
803        var curTransY = map.transY;
804        var curScale = map.scale;
805
806        map.transX -= (map.width / map.scale - map.width / (map.scale * map.zoomStep)) / 2;
807        map.transY -= (map.height / map.scale - map.height / (map.scale * map.zoomStep)) / 2;
808        map.setScale(map.scale * map.zoomStep);
809        map.zoomCurStep++;
810
811        jQuery('#zoomSlider').css('top', parseInt(jQuery('#zoomSlider').css('top'), 10) - sliderDelta);
812        
813        map.container.trigger("zoomIn");
814      }
815    },
816    
817    zoomOut: function () {
818      var map = this;
819      var sliderDelta = (jQuery('#zoom').innerHeight() - 6 * 2 - 15 * 2 - 3 * 2 - 7 - 6) / (this.zoomMaxStep - this.zoomCurStep);
820
821      if (map.zoomCurStep > 1) {
822        var curTransX = map.transX;
823        var curTransY = map.transY;
824        var curScale = map.scale;
825
826        map.transX += (map.width / (map.scale / map.zoomStep) - map.width / map.scale) / 2;
827        map.transY += (map.height / (map.scale / map.zoomStep) - map.height / map.scale) / 2;
828        map.setScale(map.scale / map.zoomStep);
829        map.zoomCurStep--;
830
831        jQuery('#zoomSlider').css('top', parseInt(jQuery('#zoomSlider').css('top'), 10) + sliderDelta);
832        
833        map.container.trigger("zoomOut");
834      }
835    },
836
837    setScale: function (scale) {
838      this.scale = scale;
839      this.applyTransform();
840    },
841
842    getCountryId: function (cc) {
843      return 'jqvmap' + this.index + '_' + cc;
844    },
845
846    getPinId: function (cc) {
847      return this.getCountryId(cc)+'_pin';
848    },
849    
850    placePins: function(pins, pinMode){
851      var map = this;
852
853      if(!pinMode || (pinMode != "content" && pinMode != "id")) {
854        pinMode = "content";
855      }
856
857      if(pinMode == "content") {//treat pin as content
858        jQuery.each(pins, function(index, pin){
859          if(jQuery('#'+map.getCountryId(index)).length == 0){
860              return;
861          }
862          //mapData.pathes[code].name
863          var pinIndex = map.getPinId(index);
864          if(jQuery('#'+pinIndex).length > 0){
865            jQuery('#'+pinIndex).remove();
866          }
867          map.container.append('<div id="' + pinIndex + '" for="'+index+'" class="jqvmap_pin" style="position:absolute">' + pin + '</div>');
868        });
869      } else { //treat pin as id of an html content
870        jQuery.each(pins, function(index, pin){
871          if(jQuery('#'+map.getCountryId(index)).length == 0){
872              return;
873          }
874          var pinIndex = map.getPinId(index);
875          if(jQuery('#'+pinIndex).length > 0){
876            jQuery('#'+pinIndex).remove();
877          }
878          map.container.append('<div id="' + pinIndex + '" for="'+index+'" class="jqvmap_pin" style="position:absolute"></div>');
879          jQuery('#'+pinIndex).append(jQuery('#'+pin));
880        });
881      }
882
883      this.positionPins();
884      if(!this.pinHandlers){
885        this.pinHandlers = true;//do only once
886        var positionFix = function(){
887          map.positionPins();
888        };
889        this.container.bind('zoomIn', positionFix)
890        .bind('zoomOut', positionFix)
891        .bind('drag', positionFix);
892      }
893    },
894
895    positionPins: function(){
896      var map = this;
897      var pins = this.container.find('.jqvmap_pin');
898      jQuery.each(pins, function(index, pinObj){
899        pinObj = jQuery(pinObj);
900        var countryId = map.getCountryId(pinObj.attr('for'));
901        var countryObj = jQuery('#' + countryId);
902
903        var bbox = document.getElementById(countryId).getBBox();
904        var position = countryObj.position();
905
906        var scale = map.scale;
907
908        var left = position.left + (bbox.width / 2) * scale - pinObj.width() / 2,
909        top = position.top + (bbox.height / 2) * scale - pinObj.height() / 2;
910
911        pinObj.css('left',left).css('top',top);
912      });
913     },
914
915     getPin: function(cc){
916       var pinObj = jQuery('#'+this.getPinId(cc));
917       return pinObj.html();
918     },
919
920     getPins: function(){
921       var pins = this.container.find('.jqvmap_pin');
922       var ret = new Object();
923       jQuery.each(pins, function(index, pinObj){
924         pinObj = jQuery(pinObj);
925         var cc = pinObj.attr('for');
926         var pinContent = pinObj.html();
927         eval("ret." + cc + "=pinContent");
928       });
929       return JSON.stringify(ret);
930     },
931
932     removePin: function(cc) {
933       jQuery('#'+this.getPinId(cc)).remove();
934     },
935
936     removePins: function(){
937       this.container.find('.jqvmap_pin').remove();
938     }
939  };
940
941  WorldMap.xlink = "http://www.w3.org/1999/xlink";
942  WorldMap.mapIndex = 1;
943  WorldMap.maps = {};
944
945  var ColorScale = function (colors, normalizeFunction, minValue, maxValue) {
946    if (colors) {
947      this.setColors(colors);
948    }
949    if (normalizeFunction) {
950      this.setNormalizeFunction(normalizeFunction);
951    }
952    if (minValue) {
953      this.setMin(minValue);
954    }
955    if (minValue) {
956      this.setMax(maxValue);
957    }
958  };
959
960  ColorScale.prototype = {
961    colors: [],
962
963    setMin: function (min) {
964      this.clearMinValue = min;
965
966      if (typeof this.normalize === 'function') {
967        this.minValue = this.normalize(min);
968      } else {
969        this.minValue = min;
970      }
971    },
972
vendor: 3,298 bytes, lines 973-1104
973    setMax: function (max) {
974      this.clearMaxValue = max;
975      if (typeof this.normalize === 'function') {
976        this.maxValue = this.normalize(max);
977      } else {
978        this.maxValue = max;
979      }
980    },
981
982    setColors: function (colors) {
983      for (var i = 0; i < colors.length; i++) {
984        colors[i] = ColorScale.rgbToArray(colors[i]);
985      }
986      this.colors = colors;
987    },
988
989    setNormalizeFunction: function (f) {
990      if (f === 'polynomial') {
991        this.normalize = function (value) {
992          return Math.pow(value, 0.2);
993        };
994      }
995      else if (f === 'linear') {
996        delete this.normalize;
997      } else {
998        this.normalize = f;
999      }
1000      this.setMin(this.clearMinValue);
1001      this.setMax(this.clearMaxValue);
1002    },
1003
1004    getColor: function (value) {
1005      if (typeof this.normalize === 'function') {
1006        value = this.normalize(value);
1007      }
1008
1009      var lengthes = [];
1010      var fullLength = 0;
1011      var l;
1012
1013      for (var i = 0; i < this.colors.length - 1; i++) {
1014        l = this.vectorLength(this.vectorSubtract(this.colors[i + 1], this.colors[i]));
1015        lengthes.push(l);
1016        fullLength += l;
1017      }
1018
1019      var c = (this.maxValue - this.minValue) / fullLength;
1020
1021      for (i = 0; i < lengthes.length; i++) {
1022        lengthes[i] *= c;
1023      }
1024
1025      i = 0;
1026      value -= this.minValue;
1027
1028      while (value - lengthes[i] >= 0) {
1029        value -= lengthes[i];
1030        i++;
1031      }
1032
1033      var color;
1034      if (i == this.colors.length - 1) {
1035        color = this.vectorToNum(this.colors[i]).toString(16);
1036      } else {
1037        color = (this.vectorToNum(this.vectorAdd(this.colors[i], this.vectorMult(this.vectorSubtract(this.colors[i + 1], this.colors[i]), (value) / (lengthes[i]))))).toString(16);
1038      }
1039
1040      while (color.length < 6) {
1041        color = '0' + color;
1042      }
1043      return '#' + color;
1044    },
1045
1046    vectorToNum: function (vector) {
1047      var num = 0;
1048      for (var i = 0; i < vector.length; i++) {
1049        num += Math.round(vector[i]) * Math.pow(256, vector.length - i - 1);
1050      }
1051      return num;
1052    },
1053
1054    vectorSubtract: function (vector1, vector2) {
1055      var vector = [];
1056      for (var i = 0; i < vector1.length; i++) {
1057        vector[i] = vector1[i] - vector2[i];
1058      }
1059      return vector;
1060    },
1061
1062    vectorAdd: function (vector1, vector2) {
1063      var vector = [];
1064      for (var i = 0; i < vector1.length; i++) {
1065        vector[i] = vector1[i] + vector2[i];
1066      }
1067      return vector;
1068    },
1069
1070    vectorMult: function (vector, num) {
1071      var result = [];
1072      for (var i = 0; i < vector.length; i++) {
1073        result[i] = vector[i] * num;
1074      }
1075      return result;
1076    },
1077
1078    vectorLength: function (vector) {
1079      var result = 0;
1080      for (var i = 0; i < vector.length; i++) {
1081        result += vector[i] * vector[i];
1082      }
1083      return Math.sqrt(result);
1084    }
1085  };
1086
1087  ColorScale.arrayToRgb = function (ar) {
1088    var rgb = '#';
1089    var d;
1090    for (var i = 0; i < ar.length; i++) {
1091      d = ar[i].toString(16);
1092      rgb += d.length == 1 ? '0' + d : d;
1093    }
1094    return rgb;
1095  };
1096
1097  ColorScale.rgbToArray = function (rgb) {
1098    rgb = rgb.substr(1);
1099    return [parseInt(rgb.substr(0, 2), 16), parseInt(rgb.substr(2, 2), 16), parseInt(rgb.substr(4, 2), 16)];
1100  };
1101
1102})(jQuery);
1103
1104

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.