@woosmap/ui 2.35.0 → 2.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,15 +2,14 @@
2
2
  import React, { Component } from 'react';
3
3
  import axios from 'axios';
4
4
  import PropTypes from 'prop-types';
5
- import GoogleMapReact from 'google-map-react';
6
5
  import Demo from './SkeletonDemo';
7
6
  import AddressAutocomplete from '../Woosmap/AddressAutocomplete';
8
- import Marker from '../Map/Marker';
9
7
  import Constants from '../../Constants';
10
- import { viewpoint } from '../Map/drawOnMap';
11
8
  import CountrySelect from '../Select/CountrySelect';
12
9
  import { tr } from '../utils/locale';
13
10
  import Input from '../Input/Input';
11
+ import markerIcon from '../../images/marker.png';
12
+ import Script from '../utils/Script';
14
13
 
15
14
  export default class LocalitiesAddressDemo extends Component {
16
15
  constructor(props) {
@@ -31,6 +30,11 @@ export default class LocalitiesAddressDemo extends Component {
31
30
  this.requestDetailsUrl = 'https://api.woosmap.com/localities/details';
32
31
  this.inputRef = React.createRef();
33
32
  this.addressAutocompleteRef = React.createRef();
33
+ this.mapDivRef = React.createRef();
34
+ }
35
+
36
+ componentDidMount() {
37
+ this.displayMap();
34
38
  }
35
39
 
36
40
  componentWillUnmount() {
@@ -83,12 +87,15 @@ export default class LocalitiesAddressDemo extends Component {
83
87
  })
84
88
  .then((response) => {
85
89
  if (this.mounted) {
86
- this.setState({
87
- error: null,
88
- showDetails: true,
89
- response: response.data.result,
90
- selectedLocality: response.data.result,
91
- });
90
+ this.setState(
91
+ {
92
+ error: null,
93
+ showDetails: true,
94
+ response: response.data.result,
95
+ selectedLocality: response.data.result,
96
+ },
97
+ this.displayOnMap
98
+ );
92
99
  }
93
100
  })
94
101
  .catch((error) => {
@@ -124,14 +131,23 @@ export default class LocalitiesAddressDemo extends Component {
124
131
  };
125
132
 
126
133
  displayOnMap = () => {
127
- const { selectedAddress } = this.state;
128
- if (this.viewport) {
129
- this.viewport.setMap(null);
130
- }
131
- if (this.map && selectedAddress) {
132
- if (selectedAddress.viewpoint) {
133
- this.viewport = viewpoint(this.map, selectedAddress.viewpoint);
134
- this.map.fitBounds(selectedAddress.viewpoint.bounds, 10);
134
+ if (this.map) {
135
+ const { selectedLocality } = this.state;
136
+
137
+ if (selectedLocality?.geometry?.location) {
138
+ this.map.setCenter(selectedLocality.geometry.location);
139
+ this.map.setZoom(17);
140
+
141
+ if (this.marker) {
142
+ this.marker.setMap(null);
143
+ this.marker = null;
144
+ }
145
+
146
+ this.marker = new window.woosmap.map.Marker({
147
+ icon: { url: markerIcon, scaledSize: { height: 46, width: 30 } },
148
+ position: selectedLocality.geometry.location,
149
+ map: this.map,
150
+ });
135
151
  } else {
136
152
  this.map.setZoom(10);
137
153
  }
@@ -304,31 +320,21 @@ export default class LocalitiesAddressDemo extends Component {
304
320
  );
305
321
  };
306
322
 
307
- renderMap = () => {
308
- const { selectedLocality } = this.state;
323
+ displayMap = () => {
324
+ if (this.timeoutMap) {
325
+ clearTimeout(this.timeoutMap);
326
+ }
309
327
 
310
- const location =
311
- selectedLocality && selectedLocality.geometry
312
- ? selectedLocality.geometry.location
313
- : { lat: 48.863350992156306, lng: 2.3484066674237796 };
314
- const marker =
315
- selectedLocality && selectedLocality.geometry ? <Marker lat={location.lat} lng={location.lng} /> : null;
316
- return (
317
- <GoogleMapReact
318
- defaultZoom={10}
319
- center={[location.lat, location.lng]}
320
- bootstrapURLKeys={{ key: Constants.gmapKey, libraries: ['geometry', 'places'] }}
321
- yesIWantToUseGoogleMapApiInternals
322
- onGoogleApiLoaded={({ map }) => {
323
- this.map = map;
324
- this.displayOnMap();
325
- }}
326
- >
327
- {marker}
328
- </GoogleMapReact>
329
- );
328
+ if (window.woosmap && window.woosmap.map && this.mapDivRef.current) {
329
+ this.map = new window.woosmap.map.Map(this.mapDivRef.current);
330
+ this.requestAddress();
331
+ } else {
332
+ this.timeoutMap = setTimeout(this.displayMap, 300);
333
+ }
330
334
  };
331
335
 
336
+ renderMap = () => <div className="map" ref={this.mapDivRef} />;
337
+
332
338
  render() {
333
339
  const { response, error, showDetails } = this.state;
334
340
  const { noheader, headerLabels, subHeader } = this.props;
@@ -337,21 +343,24 @@ export default class LocalitiesAddressDemo extends Component {
337
343
  request = this.requestDetailsUrl;
338
344
  }
339
345
  return (
340
- <Demo
341
- noheader={noheader}
342
- header={headerLabels}
343
- subHeader={subHeader}
344
- id="localities-demo"
345
- className="demo--localitiesaddress"
346
- footerFilters={this.renderFooterFilters()}
347
- headerFilters={this.renderHeaderFilters()}
348
- request={request}
349
- params={this.getRequestparams()}
350
- referer="http://localhost/"
351
- response={error || response}
352
- result={this.renderAddress()}
353
- map={this.renderMap()}
354
- />
346
+ <>
347
+ <Script url={`https://sdk.woosmap.com/map/map.js?key=${Constants.woosmapKey}`} />
348
+ <Demo
349
+ noheader={noheader}
350
+ header={headerLabels}
351
+ subHeader={subHeader}
352
+ id="localities-demo"
353
+ className="demo--localitiesaddress"
354
+ footerFilters={this.renderFooterFilters()}
355
+ headerFilters={this.renderHeaderFilters()}
356
+ request={request}
357
+ params={this.getRequestparams()}
358
+ referer="http://localhost/"
359
+ response={error || response}
360
+ result={this.renderAddress()}
361
+ map={this.renderMap()}
362
+ />
363
+ </>
355
364
  );
356
365
  }
357
366
  }
@@ -3,17 +3,17 @@ import axios from 'axios';
3
3
  import cl from 'classnames';
4
4
  import React, { Component } from 'react';
5
5
  import PropTypes from 'prop-types';
6
- import GoogleMapReact from 'google-map-react';
7
6
  import Demo from './SkeletonDemo';
8
- import Marker from '../Map/Marker';
9
7
  import Input from '../Input/Input';
10
8
  import Select from '../Select/Select';
11
9
  import Button from '../Button/Button';
12
10
  import ButtonGroup from '../Button/ButtonGroup';
13
11
  import CountrySelect from '../Select/CountrySelect';
14
- import { viewpoint } from '../Map/drawOnMap';
15
12
  import Constants from '../../Constants';
16
13
  import { tr } from '../utils/locale';
14
+ import markerIcon from '../../images/marker.png';
15
+ import Script from '../utils/Script';
16
+ import { WoosmapMapBoundingBox } from '../Map/drawOnMap';
17
17
 
18
18
  const languages = [
19
19
  { value: 'fr', label: 'French' },
@@ -64,10 +64,12 @@ export default class LocalitiesDemo extends Component {
64
64
  this.marker = null;
65
65
  this.viewport = null;
66
66
  this.requestUrl = 'https://api.woosmap.com/localities/autocomplete/';
67
+ this.mapDivRef = React.createRef();
68
+ this.overlay = null;
67
69
  }
68
70
 
69
71
  componentDidMount() {
70
- this.requestLocalities();
72
+ this.displayMap();
71
73
  }
72
74
 
73
75
  componentWillUnmount() {
@@ -114,14 +116,31 @@ export default class LocalitiesDemo extends Component {
114
116
 
115
117
  displayOnMap = () => {
116
118
  const { selectedLocality } = this.state;
117
- if (this.viewport) {
118
- this.viewport.setMap(null);
119
- }
120
- if (this.map && selectedLocality) {
119
+
120
+ if (this.map && selectedLocality?.location) {
121
+ if (this.marker) {
122
+ this.marker.setMap(null);
123
+ this.marker = null;
124
+ }
125
+
126
+ if (this.overlay) {
127
+ this.overlay.setMap(null);
128
+ this.overlay = null;
129
+ }
130
+
131
+ this.marker = new window.woosmap.map.Marker({
132
+ icon: { url: markerIcon, scaledSize: { height: 46, width: 30 } },
133
+ position: selectedLocality.location,
134
+ map: this.map,
135
+ });
136
+
121
137
  if (selectedLocality.viewpoint) {
122
- this.viewport = viewpoint(this.map, selectedLocality.viewpoint);
123
- this.map.fitBounds(selectedLocality.viewpoint.bounds, 10);
138
+ this.overlay = new WoosmapMapBoundingBox(selectedLocality.viewpoint.bounds);
139
+ this.overlay.setMap(this.map);
140
+
141
+ this.map.fitBounds(selectedLocality.viewpoint.bounds, { top: 70, bottom: 70, left: 70, right: 70 });
124
142
  } else {
143
+ this.map.setCenter(selectedLocality.location);
125
144
  this.map.setZoom(10);
126
145
  }
127
146
  }
@@ -170,28 +189,21 @@ export default class LocalitiesDemo extends Component {
170
189
  return <ul>{result}</ul>;
171
190
  };
172
191
 
173
- renderMap = () => {
174
- const { selectedLocality } = this.state;
175
- const location = selectedLocality ? selectedLocality.location : {};
176
- const marker = selectedLocality ? (
177
- <Marker lat={selectedLocality.location.lat} lng={selectedLocality.location.lng} />
178
- ) : null;
179
- return (
180
- <GoogleMapReact
181
- defaultZoom={10}
182
- center={[location.lat, location.lng]}
183
- bootstrapURLKeys={{ key: Constants.gmapKey, libraries: ['geometry', 'places'] }}
184
- yesIWantToUseGoogleMapApiInternals
185
- onGoogleApiLoaded={({ map }) => {
186
- this.map = map;
187
- this.displayOnMap();
188
- }}
189
- >
190
- {marker}
191
- </GoogleMapReact>
192
- );
192
+ displayMap = () => {
193
+ if (this.timeoutMap) {
194
+ clearTimeout(this.timeoutMap);
195
+ }
196
+
197
+ if (window.woosmap && window.woosmap.map && this.mapDivRef.current) {
198
+ this.map = new window.woosmap.map.Map(this.mapDivRef.current);
199
+ this.requestLocalities();
200
+ } else {
201
+ this.timeoutMap = setTimeout(this.displayMap, 300);
202
+ }
193
203
  };
194
204
 
205
+ renderMap = () => <div className="map" ref={this.mapDivRef} />;
206
+
195
207
  renderHeaderFilters = () => {
196
208
  const { input } = this.state;
197
209
  const { usecaseFilter } = this.props;
@@ -259,22 +271,25 @@ export default class LocalitiesDemo extends Component {
259
271
  const { localities, error } = this.state;
260
272
  const { noheader, headerLabels, subHeader } = this.props;
261
273
  return (
262
- <Demo
263
- id="localities-demo"
264
- header={headerLabels}
265
- subHeader={subHeader}
266
- docLink="https://developers.woosmap.com/products/localities/get-started/"
267
- className="demo--localities"
268
- footerFilters={this.renderFooterFilters()}
269
- headerFilters={this.renderHeaderFilters()}
270
- request={this.requestUrl}
271
- noheader={noheader}
272
- params={this.getRequestparams()}
273
- referer="http://localhost/"
274
- response={error || localities}
275
- result={this.renderAutocompleteList()}
276
- map={this.renderMap()}
277
- />
274
+ <>
275
+ <Script url={`https://sdk.woosmap.com/map/map.js?key=${Constants.woosmapKey}`} />
276
+ <Demo
277
+ id="localities-demo"
278
+ header={headerLabels}
279
+ subHeader={subHeader}
280
+ docLink="https://developers.woosmap.com/products/localities/get-started/"
281
+ className="demo--localities"
282
+ footerFilters={this.renderFooterFilters()}
283
+ headerFilters={this.renderHeaderFilters()}
284
+ request={this.requestUrl}
285
+ noheader={noheader}
286
+ params={this.getRequestparams()}
287
+ referer="http://localhost/"
288
+ response={error || localities}
289
+ result={this.renderAutocompleteList()}
290
+ map={this.renderMap()}
291
+ />
292
+ </>
278
293
  );
279
294
  }
280
295
  }
@@ -2,14 +2,15 @@ import axios from 'axios';
2
2
  import cl from 'classnames';
3
3
  import React, { Component } from 'react';
4
4
  import PropTypes from 'prop-types';
5
- import GoogleMapReact, { fitBounds } from 'google-map-react';
6
5
  import Demo from './SkeletonDemo';
7
- import Marker from '../Map/Marker';
8
6
  import Input from '../Input/Input';
9
7
  import Constants from '../../Constants';
10
8
  import FilterSelect from '../Select/FilterSelect';
11
9
  import LocalitiesAutocomplete from '../Woosmap/LocalitiesAutocomplete';
12
10
  import { tr } from '../utils/locale';
11
+ import markerIcon from '../../images/marker.png';
12
+ import markerIconAlt from '../../images/marker-alt.png';
13
+ import Script from '../utils/Script';
13
14
 
14
15
  export default class SearchDemo extends Component {
15
16
  constructor(props) {
@@ -31,8 +32,13 @@ export default class SearchDemo extends Component {
31
32
  };
32
33
  this.mounted = true;
33
34
  this.map = null;
34
- this.marker = null;
35
+ this.markers = [];
35
36
  this.requestUrl = 'https://api.woosmap.com/stores/search/';
37
+ this.mapDivRef = React.createRef();
38
+ }
39
+
40
+ componentDidMount() {
41
+ this.displayMap();
36
42
  }
37
43
 
38
44
  componentWillUnmount() {
@@ -70,38 +76,6 @@ export default class SearchDemo extends Component {
70
76
  };
71
77
  };
72
78
 
73
- getZoomAndCenter = (stores) => {
74
- if (!this.map) {
75
- return { center: null, zoom: null };
76
- }
77
- const bounds = new google.maps.LatLngBounds();
78
-
79
- const { selectedLocality } = this.state;
80
- const locality = selectedLocality && selectedLocality.localion ? selectedLocality : this.defaultLocality;
81
- if (locality && locality.location) {
82
- bounds.extend(new google.maps.LatLng(locality.location.lat, locality.location.lng));
83
- }
84
- if (stores && stores.length > 0) {
85
- stores.forEach((store) => {
86
- bounds.extend(new google.maps.LatLng(store.geometry.coordinates[1], store.geometry.coordinates[0]));
87
- });
88
- }
89
-
90
- return fitBounds(
91
- {
92
- ne: {
93
- lat: bounds.getNorthEast().lat(),
94
- lng: bounds.getNorthEast().lng(),
95
- },
96
- sw: {
97
- lat: bounds.getSouthWest().lat(),
98
- lng: bounds.getSouthWest().lng(),
99
- },
100
- },
101
- { height: 360, width: 400 }
102
- );
103
- };
104
-
105
79
  requestSearch = () => {
106
80
  axios
107
81
  .get(this.requestUrl, {
@@ -110,10 +84,13 @@ export default class SearchDemo extends Component {
110
84
  .then((response) => {
111
85
  if (this.mounted) {
112
86
  const { data } = response;
113
- this.setState({
114
- data: data || [],
115
- error: null,
116
- });
87
+ this.setState(
88
+ {
89
+ data: data || [],
90
+ error: null,
91
+ },
92
+ this.displayOnMap
93
+ );
117
94
  }
118
95
  })
119
96
  .catch((error) => {
@@ -164,50 +141,62 @@ export default class SearchDemo extends Component {
164
141
  return <ul>{result}</ul>;
165
142
  };
166
143
 
167
- renderMarkers = () => {
168
- const { data, selectedLocality } = this.state;
169
- const stores = data.features || [];
170
- const markers = stores.map((store) => (
171
- <Marker
172
- key={store.properties.store_id}
173
- lat={store.geometry.coordinates[1]}
174
- lng={store.geometry.coordinates[0]}
175
- />
176
- ));
177
- if (selectedLocality && selectedLocality.location) {
178
- markers.push(
179
- <Marker
180
- isSecondaryColor
181
- key="current_location"
182
- lat={selectedLocality.location.lat}
183
- lng={selectedLocality.location.lng}
184
- />
185
- );
144
+ displayOnMap = () => {
145
+ if (this.map) {
146
+ const { data, selectedLocality } = this.state;
147
+ const { features } = data;
148
+
149
+ const bounds = new window.woosmap.map.LatLngBounds();
150
+
151
+ if (this.markers.length > 0) {
152
+ this.markers.forEach((marker) => marker.setMap(null));
153
+ this.markers = [];
154
+ }
155
+
156
+ if (features && features.length > 0) {
157
+ features.forEach((store) => {
158
+ const [lng, lat] = store.geometry.coordinates;
159
+ bounds.extend(new window.woosmap.map.LatLng(lat, lng));
160
+ this.markers.push(
161
+ new window.woosmap.map.Marker({
162
+ icon: { url: markerIcon, scaledSize: { height: 46, width: 30 } },
163
+ position: { lat, lng },
164
+ map: this.map,
165
+ })
166
+ );
167
+ });
168
+
169
+ const location = selectedLocality?.location || this.defaultLocality.location;
170
+ if (location) bounds.extend(new window.woosmap.map.LatLng(location.lat, location.lng));
171
+ }
172
+
173
+ if (selectedLocality && selectedLocality.location) {
174
+ this.markers.push(
175
+ new window.woosmap.map.Marker({
176
+ icon: { url: markerIconAlt, scaledSize: { height: 46, width: 30 } },
177
+ position: selectedLocality.location,
178
+ map: this.map,
179
+ })
180
+ );
181
+ }
182
+
183
+ this.map.fitBounds(bounds, { top: 70, bottom: 70, left: 70, right: 70 });
186
184
  }
187
- return markers;
188
185
  };
189
186
 
190
- renderMap = () => {
191
- const { selectedLocality, data } = this.state;
192
- const { center, zoom } = this.getZoomAndCenter(data.features);
193
- const location = selectedLocality ? selectedLocality.location : {};
194
- return (
195
- <GoogleMapReact
196
- defaultZoom={10}
197
- zoom={zoom}
198
- center={center || [location.lat, location.lng]}
199
- bootstrapURLKeys={{ key: Constants.gmapKey, libraries: ['geometry', 'places'] }}
200
- yesIWantToUseGoogleMapApiInternals
201
- onGoogleApiLoaded={({ map }) => {
202
- this.map = map;
203
- this.requestSearch();
204
- }}
205
- >
206
- {this.renderMarkers()}
207
- </GoogleMapReact>
208
- );
187
+ displayMap = () => {
188
+ if (this.timeoutMap) clearTimeout(this.timeoutMap);
189
+
190
+ if (window.woosmap && window.woosmap.map && this.mapDivRef.current) {
191
+ this.map = new window.woosmap.map.Map(this.mapDivRef.current);
192
+ this.requestSearch();
193
+ } else {
194
+ this.timeoutMap = setTimeout(this.displayMap, 300);
195
+ }
209
196
  };
210
197
 
198
+ renderMap = () => <div className="map" ref={this.mapDivRef} />;
199
+
211
200
  renderHeaderFilters = () => {
212
201
  const { selectedLocality } = this.state;
213
202
  const originInputs = {
@@ -320,21 +309,24 @@ export default class SearchDemo extends Component {
320
309
  ),
321
310
  };
322
311
  return (
323
- <Demo
324
- id="search-demo"
325
- className="demo--search"
326
- docLink="https://developers.woosmap.com/products/search-api/get-started/"
327
- header={headerLabels}
328
- footerFilters={this.renderFooterFilters()}
329
- headerFilters={this.renderHeaderFilters()}
330
- request={this.requestUrl}
331
- params={this.getRequestparams(true)}
332
- referer="http://localhost/"
333
- response={error || data}
334
- noheader={noheader}
335
- result={this.renderStoreList()}
336
- map={this.renderMap()}
337
- />
312
+ <>
313
+ <Script url={`https://sdk.woosmap.com/map/map.js?key=${Constants.woosmapKey}`} />
314
+ <Demo
315
+ id="search-demo"
316
+ className="demo--search"
317
+ docLink="https://developers.woosmap.com/products/search-api/get-started/"
318
+ header={headerLabels}
319
+ footerFilters={this.renderFooterFilters()}
320
+ headerFilters={this.renderHeaderFilters()}
321
+ request={this.requestUrl}
322
+ params={this.getRequestparams(true)}
323
+ referer="http://localhost/"
324
+ response={error || data}
325
+ noheader={noheader}
326
+ result={this.renderStoreList()}
327
+ map={this.renderMap()}
328
+ />
329
+ </>
338
330
  );
339
331
  }
340
332
  }
@@ -55,21 +55,29 @@
55
55
  sq($buttonHeightNano)
56
56
  padding 0
57
57
  min-height unset
58
+ &--LOCALITIES
58
59
  &--localities
59
60
  background-color $localities
61
+ &--GEOLOCATION
60
62
  &--geolocation
61
63
  background-color $geolocation
64
+ &--DISTANCE
62
65
  &--distance
63
66
  background-color $distance
67
+ &--STORES
64
68
  &--stores
65
69
  background-color $stores
70
+ &--ADDRESS
66
71
  &--address
67
72
  background-color $address
73
+ &--MAP
68
74
  &--map
69
75
  background-color $map
76
+ &--MERCHANTS
70
77
  &--merchants
71
78
  background-color $merchant
72
- &--traffic
79
+ &--TRAFFIC
80
+ &--merchant
73
81
  background-color $traffic
74
82
  &--free
75
83
  background-color $free
@@ -8,8 +8,8 @@ export default class Marker extends Component {
8
8
  return (
9
9
  <div
10
10
  className={cl({
11
- marker: true,
12
- 'marker--alt': isSecondaryColor,
11
+ 'ui-marker': true,
12
+ 'ui-marker--alt': isSecondaryColor,
13
13
  })}
14
14
  />
15
15
  );
@@ -6,9 +6,9 @@ import Marker from './Marker';
6
6
 
7
7
  it('renders a marker', () => {
8
8
  const { container } = render(<Marker />);
9
- expect(container.firstChild).toHaveClass('marker');
9
+ expect(container.firstChild).toHaveClass('ui-marker');
10
10
  });
11
11
  it('renders a marker with seondary color', () => {
12
12
  const { container } = render(<Marker isSecondaryColor />);
13
- expect(container.firstChild).toHaveClass('marker--alt');
13
+ expect(container.firstChild).toHaveClass('ui-marker--alt');
14
14
  });