|
1 | 1 | /*
|
2 |
| -* heatmap.js gmaps overlay |
| 2 | +* heatmap.js Google Maps Overlay |
3 | 3 | *
|
4 |
| -* Copyright (c) 2014, Patrick Wied (http://www.patrick-wied.at) |
| 4 | +* Copyright (c) 2008-2016, Patrick Wied (https://www.patrick-wied.at) |
5 | 5 | * Dual-licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
|
6 | 6 | * and the Beerware (http://en.wikipedia.org/wiki/Beerware) license.
|
7 | 7 | */
|
8 |
| - |
9 |
| -(function (name, context, factory) { |
10 |
| - |
| 8 | +;(function (name, context, factory) { |
11 | 9 | // Supports UMD. AMD, CommonJS/Node.js and browser context
|
12 | 10 | if (typeof module !== "undefined" && module.exports) {
|
13 |
| - module.exports = factory(); |
| 11 | + module.exports = factory( |
| 12 | + require('heatmap.js'), |
| 13 | + require('google-maps') |
| 14 | + ); |
14 | 15 | } else if (typeof define === "function" && define.amd) {
|
15 |
| - define(factory); |
| 16 | + define(['heatmap.js', 'google-maps'], factory); |
16 | 17 | } else {
|
17 |
| - context[name] = factory(); |
| 18 | + // browser globals |
| 19 | + if (typeof window.h337 === 'undefined') { |
| 20 | + throw new Error('heatmap.js must be loaded before the gmaps heatmap plugin'); |
| 21 | + } |
| 22 | + if (typeof window.google === 'undefined') { |
| 23 | + throw new Error('Google Maps must be loaded before the gmaps heatmap plugin'); |
| 24 | + } |
| 25 | + context[name] = factory(window.h337, window.google.maps); |
18 | 26 | }
|
19 | 27 |
|
20 |
| -})("HeatmapOverlay", this, function() { |
| 28 | +})("HeatmapOverlay", this, function(h337, gmaps) { |
| 29 | + 'use strict'; |
21 | 30 |
|
22 | 31 | var HeatmapOverlay = function(map, cfg){
|
23 | 32 | this.setMap(map);
|
24 | 33 | this.initialize(cfg || {});
|
25 | 34 | };
|
26 | 35 |
|
27 |
| - HeatmapOverlay.prototype = new google.maps.OverlayView(); |
28 |
| - |
| 36 | + HeatmapOverlay.prototype = new gmaps.OverlayView(); |
29 | 37 |
|
30 | 38 | HeatmapOverlay.CSS_TRANSFORM = (function() {
|
31 | 39 | var div = document.createElement('div');
|
|
66 | 74 | };
|
67 | 75 |
|
68 | 76 | HeatmapOverlay.prototype.onAdd = function(){
|
69 |
| - var h337 = typeof require !== 'undefined' ? require('heatmap.js') : window.h337; |
70 | 77 | var that = this;
|
71 | 78 |
|
72 | 79 | this.getPanes().overlayLayer.appendChild(this.container);
|
73 | 80 |
|
74 | 81 |
|
75 |
| - this.changeHandler = google.maps.event.addListener( |
| 82 | + this.changeHandler = gmaps.event.addListener( |
76 | 83 | this.map,
|
77 | 84 | 'bounds_changed',
|
78 | 85 | function() { return that.draw(); }
|
|
92 | 99 | this.container.parentElement.removeChild(this.container);
|
93 | 100 |
|
94 | 101 | if (this.changeHandler) {
|
95 |
| - google.maps.event.removeListener(this.changeHandler); |
| 102 | + gmaps.event.removeListener(this.changeHandler); |
96 | 103 | this.changeHandler = null;
|
97 | 104 | }
|
98 | 105 |
|
|
103 | 110 |
|
104 | 111 | var bounds = this.map.getBounds();
|
105 | 112 |
|
106 |
| - var topLeft = new google.maps.LatLng( |
| 113 | + var topLeft = new gmaps.LatLng( |
107 | 114 | bounds.getNorthEast().lat(),
|
108 | 115 | bounds.getSouthWest().lng()
|
109 | 116 | );
|
|
146 | 153 |
|
147 | 154 | bounds = this.map.getBounds();
|
148 | 155 |
|
149 |
| - topLeft = new google.maps.LatLng( |
| 156 | + topLeft = new gmaps.LatLng( |
150 | 157 | bounds.getNorthEast().lat(),
|
151 | 158 | bounds.getSouthWest().lng()
|
152 | 159 | );
|
|
229 | 236 |
|
230 | 237 | while (len--) {
|
231 | 238 | var entry = data[len];
|
232 |
| - var latlng = new google.maps.LatLng(entry[latField], entry[lngField]); |
| 239 | + var latlng = new gmaps.LatLng(entry[latField], entry[lngField]); |
233 | 240 | var dataObj = { latlng: latlng };
|
234 | 241 | dataObj[valueField] = entry[valueField];
|
235 | 242 | if (entry.radius) {
|
|
252 | 259 | var lngField = this.cfg.lngField || 'lng';
|
253 | 260 | var valueField = this.cfg.valueField || 'value';
|
254 | 261 | var entry = pointOrArray;
|
255 |
| - var latlng = new google.maps.LatLng(entry[latField], entry[lngField]); |
| 262 | + var latlng = new gmaps.LatLng(entry[latField], entry[lngField]); |
256 | 263 | var dataObj = { latlng: latlng };
|
257 | 264 |
|
258 | 265 | dataObj[valueField] = entry[valueField];
|
|
0 commit comments