Skip to content

Commit e717f31

Browse files
committed
refactoring and allow to add all theother options as props to the components, see #166
1 parent 1421f40 commit e717f31

File tree

10 files changed

+211
-48
lines changed

10 files changed

+211
-48
lines changed

dist/components/HeatMap.js

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,32 @@
2828
};
2929
}
3030

31+
var _extends = Object.assign || function (target) {
32+
for (var i = 1; i < arguments.length; i++) {
33+
var source = arguments[i];
34+
35+
for (var key in source) {
36+
if (Object.prototype.hasOwnProperty.call(source, key)) {
37+
target[key] = source[key];
38+
}
39+
}
40+
}
41+
42+
return target;
43+
};
44+
45+
function _objectWithoutProperties(obj, keys) {
46+
var target = {};
47+
48+
for (var i in obj) {
49+
if (keys.indexOf(i) >= 0) continue;
50+
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
51+
target[i] = obj[i];
52+
}
53+
54+
return target;
55+
}
56+
3157
function _classCallCheck(instance, Constructor) {
3258
if (!(instance instanceof Constructor)) {
3359
throw new TypeError("Cannot call a class as a function");
@@ -135,27 +161,30 @@
135161
mapCenter = _props.mapCenter,
136162
icon = _props.icon,
137163
gradient = _props.gradient,
138-
radius = _props.radius,
139-
opacity = _props.opacity;
140-
164+
_props$radius = _props.radius,
165+
radius = _props$radius === undefined ? 20 : _props$radius,
166+
_props$opacity = _props.opacity,
167+
opacity = _props$opacity === undefined ? 0.2 : _props$opacity,
168+
props = _objectWithoutProperties(_props, ['map', 'google', 'positions', 'mapCenter', 'icon', 'gradient', 'radius', 'opacity']);
141169

142170
if (!google) {
143171
return null;
144172
}
145173

146-
positions = positions.map(function (pos) {
174+
var data = positions.map(function (pos) {
147175
return new google.maps.LatLng(pos.lat, pos.lng);
148176
});
149177

150-
var pref = {
178+
var pref = _extends({
151179
map: map,
152-
data: positions
153-
};
180+
gradient: gradient,
181+
radius: radius,
182+
opacity: opacity,
183+
data: data
184+
}, props);
154185

155186
this.heatMap = new google.maps.visualization.HeatmapLayer(pref);
156187

157-
this.heatMap.set('gradient', gradient);
158-
159188
this.heatMap.set('radius', radius === undefined ? 20 : radius);
160189

161190
this.heatMap.set('opacity', opacity === undefined ? 0.2 : opacity);

dist/components/InfoWindow.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,32 @@
3232
};
3333
}
3434

35+
var _extends = Object.assign || function (target) {
36+
for (var i = 1; i < arguments.length; i++) {
37+
var source = arguments[i];
38+
39+
for (var key in source) {
40+
if (Object.prototype.hasOwnProperty.call(source, key)) {
41+
target[key] = source[key];
42+
}
43+
}
44+
}
45+
46+
return target;
47+
};
48+
49+
function _objectWithoutProperties(obj, keys) {
50+
var target = {};
51+
52+
for (var i in obj) {
53+
if (keys.indexOf(i) >= 0) continue;
54+
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
55+
target[i] = obj[i];
56+
}
57+
58+
return target;
59+
}
60+
3561
function _classCallCheck(instance, Constructor) {
3662
if (!(instance instanceof Constructor)) {
3763
throw new TypeError("Cannot call a class as a function");
@@ -128,16 +154,16 @@
128154
var _props2 = this.props,
129155
map = _props2.map,
130156
google = _props2.google,
131-
mapCenter = _props2.mapCenter;
132-
157+
mapCenter = _props2.mapCenter,
158+
props = _objectWithoutProperties(_props2, ['map', 'google', 'mapCenter']);
133159

134160
if (!google || !google.maps) {
135161
return;
136162
}
137163

138-
var iw = this.infowindow = new google.maps.InfoWindow({
164+
var iw = this.infowindow = new google.maps.InfoWindow(_extends({
139165
content: ''
140-
});
166+
}, props));
141167

142168
google.maps.event.addListener(iw, 'closeclick', this.onClose.bind(this));
143169
google.maps.event.addListener(iw, 'domready', this.onOpen.bind(this));

dist/components/Marker.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,32 @@
2828
};
2929
}
3030

31+
var _extends = Object.assign || function (target) {
32+
for (var i = 1; i < arguments.length; i++) {
33+
var source = arguments[i];
34+
35+
for (var key in source) {
36+
if (Object.prototype.hasOwnProperty.call(source, key)) {
37+
target[key] = source[key];
38+
}
39+
}
40+
}
41+
42+
return target;
43+
};
44+
45+
function _objectWithoutProperties(obj, keys) {
46+
var target = {};
47+
48+
for (var i in obj) {
49+
if (keys.indexOf(i) >= 0) continue;
50+
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
51+
target[i] = obj[i];
52+
}
53+
54+
return target;
55+
}
56+
3157
function _classCallCheck(instance, Constructor) {
3258
if (!(instance instanceof Constructor)) {
3359
throw new TypeError("Cannot call a class as a function");
@@ -136,25 +162,26 @@
136162
icon = _props.icon,
137163
label = _props.label,
138164
draggable = _props.draggable,
139-
title = _props.title;
165+
title = _props.title,
166+
props = _objectWithoutProperties(_props, ['map', 'google', 'position', 'mapCenter', 'icon', 'label', 'draggable', 'title']);
140167

141168
if (!google) {
142169
return null;
143170
}
144171

145172
var pos = position || mapCenter;
146173
if (!(pos instanceof google.maps.LatLng)) {
147-
position = new google.maps.LatLng(pos.lat, pos.lng);
174+
pos = new google.maps.LatLng(pos.lat, pos.lng);
148175
}
149176

150-
var pref = {
177+
var pref = _extends({
151178
map: map,
152-
position: position,
179+
position: pos,
153180
icon: icon,
154181
label: label,
155182
title: title,
156183
draggable: draggable
157-
};
184+
}, props);
158185
this.marker = new google.maps.Marker(pref);
159186

160187
evtNames.forEach(function (e) {

dist/components/Polygon.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,32 @@
2828
};
2929
}
3030

31+
var _extends = Object.assign || function (target) {
32+
for (var i = 1; i < arguments.length; i++) {
33+
var source = arguments[i];
34+
35+
for (var key in source) {
36+
if (Object.prototype.hasOwnProperty.call(source, key)) {
37+
target[key] = source[key];
38+
}
39+
}
40+
}
41+
42+
return target;
43+
};
44+
45+
function _objectWithoutProperties(obj, keys) {
46+
var target = {};
47+
48+
for (var i in obj) {
49+
if (keys.indexOf(i) >= 0) continue;
50+
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
51+
target[i] = obj[i];
52+
}
53+
54+
return target;
55+
}
56+
3157
function _classCallCheck(instance, Constructor) {
3258
if (!(instance instanceof Constructor)) {
3359
throw new TypeError("Cannot call a class as a function");
@@ -136,22 +162,22 @@
136162
strokeOpacity = _props.strokeOpacity,
137163
strokeWeight = _props.strokeWeight,
138164
fillColor = _props.fillColor,
139-
fillOpacity = _props.fillOpacity;
140-
165+
fillOpacity = _props.fillOpacity,
166+
props = _objectWithoutProperties(_props, ['map', 'google', 'paths', 'strokeColor', 'strokeOpacity', 'strokeWeight', 'fillColor', 'fillOpacity']);
141167

142168
if (!google) {
143169
return null;
144170
}
145171

146-
var params = {
172+
var params = _extends({
147173
map: map,
148174
paths: paths,
149175
strokeColor: strokeColor,
150176
strokeOpacity: strokeOpacity,
151177
strokeWeight: strokeWeight,
152178
fillColor: fillColor,
153179
fillOpacity: fillOpacity
154-
};
180+
}, props);
155181

156182
this.polygon = new google.maps.Polygon(params);
157183

dist/components/Polyline.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,32 @@
2828
};
2929
}
3030

31+
var _extends = Object.assign || function (target) {
32+
for (var i = 1; i < arguments.length; i++) {
33+
var source = arguments[i];
34+
35+
for (var key in source) {
36+
if (Object.prototype.hasOwnProperty.call(source, key)) {
37+
target[key] = source[key];
38+
}
39+
}
40+
}
41+
42+
return target;
43+
};
44+
45+
function _objectWithoutProperties(obj, keys) {
46+
var target = {};
47+
48+
for (var i in obj) {
49+
if (keys.indexOf(i) >= 0) continue;
50+
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
51+
target[i] = obj[i];
52+
}
53+
54+
return target;
55+
}
56+
3157
function _classCallCheck(instance, Constructor) {
3258
if (!(instance instanceof Constructor)) {
3359
throw new TypeError("Cannot call a class as a function");
@@ -134,20 +160,20 @@
134160
paths = _props.paths,
135161
strokeColor = _props.strokeColor,
136162
strokeOpacity = _props.strokeOpacity,
137-
strokeWeight = _props.strokeWeight;
138-
163+
strokeWeight = _props.strokeWeight,
164+
props = _objectWithoutProperties(_props, ['map', 'google', 'paths', 'strokeColor', 'strokeOpacity', 'strokeWeight']);
139165

140166
if (!google) {
141167
return null;
142168
}
143169

144-
var params = {
170+
var params = _extends({
145171
map: map,
146172
paths: paths,
147173
strokeColor: strokeColor,
148174
strokeOpacity: strokeOpacity,
149175
strokeWeight: strokeWeight
150-
};
176+
}, props);
151177

152178
this.polyline = new google.maps.Polyline(params);
153179

src/components/HeatMap.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,37 @@ export class HeatMap extends React.Component {
4141
}
4242

4343
renderHeatMap() {
44-
let {
45-
map, google, positions, mapCenter, icon, gradient, radius, opacity
44+
const {
45+
map,
46+
google,
47+
positions,
48+
mapCenter,
49+
icon,
50+
gradient,
51+
radius = 20,
52+
opacity = 0.2,
53+
...props
4654
} = this.props;
4755

4856
if (!google) {
4957
return null;
5058
}
5159

52-
positions = positions.map((pos) => {
60+
const data = positions.map((pos) => {
5361
return new google.maps.LatLng(pos.lat, pos.lng);
5462
});
5563

5664
const pref = {
57-
map: map,
58-
data: positions,
65+
map,
66+
gradient,
67+
radius,
68+
opacity,
69+
data,
70+
...props
5971
};
6072

6173
this.heatMap = new google.maps.visualization.HeatmapLayer(pref);
6274

63-
this.heatMap.set('gradient', gradient);
64-
6575
this.heatMap.set('radius', radius === undefined ? 20 : radius);
6676

6777
this.heatMap.set('opacity', opacity === undefined ? 0.2 : opacity);

src/components/InfoWindow.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,20 @@ export class InfoWindow extends React.Component {
3838
}
3939

4040
renderInfoWindow() {
41-
let {map, google, mapCenter} = this.props;
41+
const {
42+
map,
43+
google,
44+
mapCenter,
45+
...props
46+
} = this.props;
4247

4348
if (!google || !google.maps) {
4449
return;
4550
}
4651

4752
const iw = this.infowindow = new google.maps.InfoWindow({
48-
content: ''
53+
content: '',
54+
...props
4955
});
5056

5157
google.maps.event

0 commit comments

Comments
 (0)