Skip to content

Commit 81c9165

Browse files
authored
Merge pull request #167 from lepirlouit/master
add more options to the components
2 parents 77e565a + a943b95 commit 81c9165

File tree

12 files changed

+257
-54
lines changed

12 files changed

+257
-54
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: 33 additions & 7 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");
@@ -131,23 +157,23 @@
131157
var _props = this.props,
132158
map = _props.map,
133159
google = _props.google,
134-
paths = _props.paths,
160+
path = _props.path,
135161
strokeColor = _props.strokeColor,
136162
strokeOpacity = _props.strokeOpacity,
137-
strokeWeight = _props.strokeWeight;
138-
163+
strokeWeight = _props.strokeWeight,
164+
props = _objectWithoutProperties(_props, ['map', 'google', 'path', 'strokeColor', 'strokeOpacity', 'strokeWeight']);
139165

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

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

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

@@ -185,7 +211,7 @@
185211
}(_react2.default.Component);
186212

187213
Polyline.propTypes = {
188-
paths: _propTypes2.default.array,
214+
path: _propTypes2.default.array,
189215
strokeColor: _propTypes2.default.string,
190216
strokeOpacity: _propTypes2.default.number,
191217
strokeWeight: _propTypes2.default.number

examples/components/withPolylines.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react'
2+
import ReactDOM from 'react-dom'
3+
4+
import Map, {GoogleApiWrapper} from '../../src/index'
5+
import Polyline from '../../src/components/Polyline'
6+
7+
const WithPolylines = React.createClass({
8+
render: function() {
9+
if (!this.props.loaded) {
10+
return <div>Loading...</div>
11+
}
12+
13+
const polyline = [
14+
{ lat: 37.789411, lng: -122.422116 },
15+
{ lat: 37.785757, lng: -122.421333 },
16+
{ lat: 37.789352, lng: -122.415346 }
17+
]
18+
19+
return (
20+
<Map google={this.props.google}
21+
style={{width: '100%', height: '100%', position: 'relative'}}
22+
className={'map'}
23+
zoom={14}>
24+
<Polyline
25+
path={polyline}
26+
strokeColor="#0000FF"
27+
strokeOpacity={0.8}
28+
strokeWeight={2}
29+
fillColor="#0000FF"
30+
fillOpacity={0.35} />
31+
</Map>
32+
)
33+
}
34+
});
35+
36+
export default WithPolylines

examples/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ const routeMap = {
3434
'polygons': {
3535
name: 'Polygon',
3636
component: require('./components/withPolygons').default
37+
},
38+
'polyline': {
39+
name: 'Polyline',
40+
component: require('./components/withPolylines').default
3741
}
3842
}
3943

0 commit comments

Comments
 (0)