@woosmap/ui 3.44.0 → 3.48.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@woosmap/ui",
3
- "version": "3.44.0",
3
+ "version": "3.48.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/WebGeoServices/ui.git"
@@ -2,17 +2,17 @@
2
2
  import React, { Component } from 'react';
3
3
  import axios from 'axios';
4
4
  import cl from 'classnames';
5
- import GoogleMapReact from 'google-map-react';
6
5
  import Demo from './SkeletonDemo';
7
- import AddressAutocomplete from '../Woosmap/AddressAutocomplete';
8
- import Marker from '../Map/Marker';
9
6
  import Constants from '../../Constants';
10
- import { viewpoint } from '../Map/drawOnMap';
7
+ import { createWoosmapMap, WoosmapMapBoundingBox } from '../Map/drawOnMap';
11
8
  import Button from '../Button/Button';
12
9
  import ButtonGroup from '../Button/ButtonGroup';
13
10
  import CountrySelect from '../Select/CountrySelect';
14
11
  import { tr } from '../utils/locale';
15
12
  import Input from '../Input/Input';
13
+ import Script from '../utils/Script';
14
+ import markerIcon from '../../images/marker.png';
15
+ import AddressAutocomplete from '../Woosmap/AddressAutocomplete';
16
16
 
17
17
  const languages = [
18
18
  { value: 'fr', label: 'French' },
@@ -49,6 +49,11 @@ export default class AddressDemo extends Component {
49
49
  this.requestGeocodeUrl = 'https://api.woosmap.com/address/geocode/json';
50
50
  this.inputRef = React.createRef();
51
51
  this.addressAutocompleteRef = React.createRef();
52
+ this.demoRef = React.createRef();
53
+ }
54
+
55
+ componentDidMount() {
56
+ this.displayMap();
52
57
  }
53
58
 
54
59
  componentWillUnmount() {
@@ -80,9 +85,9 @@ export default class AddressDemo extends Component {
80
85
  };
81
86
  if (usecase === 'geocode') {
82
87
  // eslint-disable-next-line prefer-destructuring
83
- state.selectedLocality = response.data.results[0];
88
+ state.selectedAddress = response.data.results[0];
84
89
  }
85
- this.setState(state);
90
+ this.setState(state, this.displayOnMap);
86
91
  }
87
92
  })
88
93
  .catch((error) => {
@@ -107,12 +112,15 @@ export default class AddressDemo extends Component {
107
112
  })
108
113
  .then((response) => {
109
114
  if (this.mounted) {
110
- this.setState({
111
- error: null,
112
- showDetails: true,
113
- response: response.data.result,
114
- selectedLocality: response.data.result,
115
- });
115
+ this.setState(
116
+ {
117
+ error: null,
118
+ showDetails: true,
119
+ response: response.data.result,
120
+ selectedAddress: response.data.result,
121
+ },
122
+ this.displayOnMap
123
+ );
116
124
  }
117
125
  })
118
126
  .catch((error) => {
@@ -122,12 +130,10 @@ export default class AddressDemo extends Component {
122
130
  };
123
131
 
124
132
  getRequestparams = () => {
125
- const { input, geocodeInput, selectedLocality, language, countries, showDetails, usecase, geometry } =
126
- this.state;
133
+ const { input, geocodeInput, language, countries, showDetails, usecase, geometry } = this.state;
127
134
  if (showDetails) {
128
135
  const detailsParam = {
129
136
  key: Constants.woosmapKey,
130
- public_id: selectedLocality.public_id,
131
137
  };
132
138
  if (geometry) {
133
139
  detailsParam.fields = 'geometry';
@@ -154,14 +160,37 @@ export default class AddressDemo extends Component {
154
160
 
155
161
  displayOnMap = () => {
156
162
  const { selectedAddress } = this.state;
157
- if (this.viewport) {
158
- this.viewport.setMap(null);
159
- }
160
- if (this.map && selectedAddress) {
161
- if (selectedAddress.viewpoint) {
162
- this.viewport = viewpoint(this.map, selectedAddress.viewpoint);
163
- this.map.fitBounds(selectedAddress.viewpoint.bounds, 10);
163
+
164
+ if (this.map && selectedAddress?.geometry.location) {
165
+ if (this.marker) {
166
+ this.marker.setMap(null);
167
+ this.marker = null;
168
+ }
169
+
170
+ if (this.overlay) {
171
+ this.overlay.setMap(null);
172
+ this.overlay = null;
173
+ }
174
+
175
+ this.marker = new window.woosmap.map.Marker({
176
+ icon: { url: markerIcon, scaledSize: { height: 46, width: 30 } },
177
+ position: selectedAddress.geometry.location,
178
+ map: this.map,
179
+ });
180
+
181
+ if (selectedAddress.geometry.viewport) {
182
+ const { northeast, southwest } = selectedAddress.geometry.viewport;
183
+ const bounds = {
184
+ north: northeast.lat,
185
+ east: northeast.lng,
186
+ south: southwest.lat,
187
+ west: southwest.lng,
188
+ };
189
+ this.overlay = new WoosmapMapBoundingBox(bounds);
190
+ this.overlay.setMap(this.map);
191
+ this.map.fitBounds(bounds, { top: 70, bottom: 70, left: 70, right: 70 });
164
192
  } else {
193
+ this.map.setCenter(selectedAddress.geometry.location);
165
194
  this.map.setZoom(10);
166
195
  }
167
196
  }
@@ -171,7 +200,7 @@ export default class AddressDemo extends Component {
171
200
  this.setState(
172
201
  {
173
202
  error: null,
174
- selectedLocality: address,
203
+ selectedAddress: address,
175
204
  },
176
205
  this.requestAddress
177
206
  );
@@ -194,7 +223,7 @@ export default class AddressDemo extends Component {
194
223
  key="autocomplete"
195
224
  active={usecase === 'autocomplete'}
196
225
  onClick={() => {
197
- this.setState({ usecase: 'autocomplete', selectedLocality: null, showDetails: false });
226
+ this.setState({ usecase: 'autocomplete', selectedAddress: null, showDetails: false });
198
227
  }}
199
228
  label={tr('Autocomplete')}
200
229
  />
@@ -203,7 +232,7 @@ export default class AddressDemo extends Component {
203
232
  key="geocode"
204
233
  active={usecase === 'geocode'}
205
234
  onClick={() => {
206
- this.setState({ usecase: 'geocode', selectedLocality: null, showDetails: false });
235
+ this.setState({ usecase: 'geocode', selectedAddress: null, showDetails: false });
207
236
  }}
208
237
  label={tr('Geocode')}
209
238
  />
@@ -296,14 +325,14 @@ export default class AddressDemo extends Component {
296
325
  };
297
326
 
298
327
  renderAddress = () => {
299
- const { selectedLocality, geometry } = this.state;
328
+ const { selectedAddress, geometry } = this.state;
300
329
  if (geometry) {
301
330
  return null;
302
331
  }
303
332
  let addressComponents = [];
304
- const hasComponents = selectedLocality && selectedLocality.address_components;
333
+ const hasComponents = selectedAddress && selectedAddress.address_components;
305
334
  if (hasComponents) {
306
- addressComponents = selectedLocality.address_components;
335
+ addressComponents = selectedAddress.address_components;
307
336
  }
308
337
  let shippingAddress = '';
309
338
  let shippingAddress2 = '';
@@ -393,29 +422,17 @@ export default class AddressDemo extends Component {
393
422
  );
394
423
  };
395
424
 
396
- renderMap = () => {
397
- const { selectedLocality } = this.state;
425
+ displayMap = () => {
426
+ if (this.timeoutMap) {
427
+ clearTimeout(this.timeoutMap);
428
+ }
398
429
 
399
- const location =
400
- selectedLocality && selectedLocality.geometry
401
- ? selectedLocality.geometry.location
402
- : { lat: 48.863350992156306, lng: 2.3484066674237796 };
403
- const marker =
404
- selectedLocality && selectedLocality.geometry ? <Marker lat={location.lat} lng={location.lng} /> : null;
405
- return (
406
- <GoogleMapReact
407
- defaultZoom={10}
408
- center={[location.lat, location.lng]}
409
- bootstrapURLKeys={{ key: Constants.gmapKey, libraries: ['geometry', 'places'] }}
410
- yesIWantToUseGoogleMapApiInternals
411
- onGoogleApiLoaded={({ map }) => {
412
- this.map = map;
413
- this.displayOnMap();
414
- }}
415
- >
416
- {marker}
417
- </GoogleMapReact>
418
- );
430
+ if (window.woosmap && window.woosmap.map && this.demoRef.current) {
431
+ window.woosmap.map.config.setApiKey(Constants.woosmapKey);
432
+ this.map = createWoosmapMap(this.demoRef.current.getMap());
433
+ } else {
434
+ this.timeoutMap = setTimeout(this.displayMap, 300);
435
+ }
419
436
  };
420
437
 
421
438
  render() {
@@ -429,19 +446,23 @@ export default class AddressDemo extends Component {
429
446
  }
430
447
  }
431
448
  return (
432
- <Demo
433
- noheader
434
- id="address-demo"
435
- className="demo--address"
436
- footerFilters={this.renderFooterFilters()}
437
- headerFilters={this.renderHeaderFilters()}
438
- request={request}
439
- params={this.getRequestparams()}
440
- referer="http://localhost/"
441
- response={error || response}
442
- result={this.renderAddress()}
443
- map={this.renderMap()}
444
- />
449
+ <>
450
+ <Script url="https://sdk.woosmap.com/map/map.js" />
451
+ <Demo
452
+ noheader
453
+ id="address-demo"
454
+ className="demo--address"
455
+ footerFilters={this.renderFooterFilters()}
456
+ headerFilters={this.renderHeaderFilters()}
457
+ request={request}
458
+ params={this.getRequestparams()}
459
+ referer="http://localhost/"
460
+ response={error || response}
461
+ result={this.renderAddress()}
462
+ ref={this.demoRef}
463
+ withMap
464
+ />
465
+ </>
445
466
  );
446
467
  }
447
468
  }
@@ -1,8 +1,8 @@
1
1
  // Common styles - Don't change order
2
+ @import "./website/fonts.styl"
2
3
  @import "./commons/reset.styl"
3
4
 
4
5
  // Specicif style - Do not change order
5
- @import "./website/fonts.styl"
6
6
  @import "./website/mixins.styl"
7
7
  @import "./website/variables.styl"
8
8
  @import "./website/colors.styl"