homeflowjs 0.12.12 → 0.12.13

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.
@@ -26,6 +26,8 @@ export const setPropertyLinksAsync = () => (dispatch) => {
26
26
  fetch(searchURL)
27
27
  .then((response) => response.json())
28
28
  .then(({ properties }) => {
29
+ if (!properties) return;
30
+
29
31
  const index = properties.findIndex((prop) => prop.property_id === Homeflow.get('property').property_id);
30
32
  // if there is a next and previous property in page, set those
31
33
  if (properties[index + 1] && properties[index - 1]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.12.12",
3
+ "version": "0.12.13",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",
@@ -29,8 +29,8 @@ export default class DraggableMap {
29
29
  this.selectedMarker = null;
30
30
  store.subscribe(() => {
31
31
  const newSelectedMarker = store.getState().properties.selectedMarker;
32
- const newSelectedPropertyID = newSelectedMarker ? newSelectedMarker.property.property_id : null;
33
- const stateSelectedPropertyID = this.selectedMarker ? this.selectedMarker.property.property_id : null;
32
+ const newSelectedPropertyID = this.markerPropertyIdOrGeonameId(newSelectedMarker);
33
+ const stateSelectedPropertyID = this.markerPropertyIdOrGeonameId(this.selectedMarker);
34
34
 
35
35
  if (newSelectedPropertyID !== stateSelectedPropertyID) {
36
36
  this.activateMarker(newSelectedMarker);
@@ -75,7 +75,7 @@ export default class DraggableMap {
75
75
  // }
76
76
 
77
77
  this.generateMap();
78
- if (!Homeflow.get('free_text_search') && !Homeflow.get('breadcrumbs_map')) {
78
+ if (!Homeflow.get('free_text_search')) {
79
79
  this.map.on('zoomend', () => (this.onMapDrag()));
80
80
  }
81
81
  this.map.on('dragend', () => (this.onMapDrag()));
@@ -97,6 +97,12 @@ export default class DraggableMap {
97
97
  }
98
98
  this.selectedMarker = marker;
99
99
  if (this.selectedMarker) this.selectedMarker.setIcon(this.generateMarkerIcon(marker.property));
100
+
101
+ if (marker.property.geoname_id && marker.property.viewport) {
102
+ this.bounds = this.getViewportBounds(marker.property.viewport);
103
+ this.map.fitBounds(this.bounds, Homeflow.get('custom_map_bounds_padding'));
104
+ this.onMapDrag();
105
+ }
100
106
  }
101
107
 
102
108
  generateMarkerIcon(property) {
@@ -331,8 +337,9 @@ export default class DraggableMap {
331
337
  }
332
338
  }
333
339
 
334
- getViewportBounds() {
335
- return [...this.viewport[0].filter((coords, index) => index === 0 || index === 2).map(coords => [...coords.toReversed()])];
340
+ getViewportBounds(viewport) {
341
+ viewport = viewport || this.viewport;
342
+ return [...viewport[0].filter((coords, index) => index === 0 || index === 2).map(coords => [...coords.toReversed()])];
336
343
  }
337
344
 
338
345
  getTopRightMarkerCoordinates() {
@@ -453,49 +460,57 @@ export default class DraggableMap {
453
460
 
454
461
 
455
462
  onMapDrag() {
456
- if (!Homeflow.get('disable_draggable_map')) {
457
- let url;
458
- const bounds = this.getSearchableBounds();
459
- const has_expanded = this.getSearch().expandedPolygon;
460
- if (this.mapLoadedTimes === 1 || has_expanded ) {
461
- url = `/search.ljson?${buildQueryString(this.getSearch())}/view-${bounds.toBBoxString()}&count=50`;
462
- } else {
463
- // unset place
464
- // Leaving this commented as it may be needed
465
- // It is causing issues as the place state is never reset after the request
466
- // so the place is just empty
467
- // Not sure it has to be set to null for the request to work
468
- // store.dispatch(setPlace(null));
469
- const newSearch = this.getSearch();
470
- url = `/search.ljson?${buildQueryString(newSearch)}/view-${bounds.toBBoxString()}&count=50`;
471
- }
472
- if (Homeflow.get('get_geo_features')) {
473
- const geo_url = Homeflow.get('root_url') + `geo_features.ljson?${Ctesius.getSearch().toGetParams(false)}/view-${bounds.toBBoxString()}&count=50`;
474
- $.get(geo_url, (res, status, xhr) => {
475
- this._running_update = false;
476
- if (this.geo_marker_layer != null) { this.map.removeLayer(this.geo_marker_layer); }
477
- return this.addGeoMarkers(res);
478
- });
479
- }
480
- if (Homeflow.get('map_branch_id') != null) {
481
- url = url + "&branch_id=" + Homeflow.get('map_branch_id');
482
- }
483
- Homeflow.kickEvent('before_draggable_map_updated');
484
- return fetch(url)
485
- .then((response) => response.json())
486
- .then(json => {
487
- Homeflow.kickEvent('draggable_map_updated', json);
488
- store.dispatch(setProperties(json.properties))
489
- this._running_update = false;
463
+ if (Homeflow.get('disable_draggable_map') || this.drawableMapInitialized) return;
490
464
 
491
- this.properties = json.properties;
492
- // TODO: figure out what 'tile view' is
493
- // if (this.tile_view != null) {
494
- // this.tile_view = new Ctesius.Views.Tiles({ collection: this.collection });
495
- // }
496
- return this.setMarkers();
497
- });
465
+ let url;
466
+ const bounds = this.getSearchableBounds();
467
+ const has_expanded = this.getSearch().expandedPolygon;
468
+ if (this.mapLoadedTimes === 1 || has_expanded ) {
469
+ url = `/search.ljson?${buildQueryString(this.getSearch())}/view-${bounds.toBBoxString()}&count=50`;
470
+ } else {
471
+ // unset place
472
+ // Leaving this commented as it may be needed
473
+ // It is causing issues as the place state is never reset after the request
474
+ // so the place is just empty
475
+ // Not sure it has to be set to null for the request to work
476
+ // store.dispatch(setPlace(null));
477
+ const newSearch = this.getSearch();
478
+ url = `/search.ljson?${buildQueryString(newSearch)}/view-${bounds.toBBoxString()}&count=50`;
479
+ }
480
+ if (Homeflow.get('get_geo_features')) {
481
+ const geo_url = Homeflow.get('root_url') + `geo_features.ljson?${Ctesius.getSearch().toGetParams(false)}/view-${bounds.toBBoxString()}&count=50`;
482
+ $.get(geo_url, (res, status, xhr) => {
483
+ this._running_update = false;
484
+ if (this.geo_marker_layer != null) { this.map.removeLayer(this.geo_marker_layer); }
485
+ return this.addGeoMarkers(res);
486
+ });
487
+ }
488
+ if (Homeflow.get('map_branch_id') != null) {
489
+ url = url + "&branch_id=" + Homeflow.get('map_branch_id');
498
490
  }
491
+ Homeflow.kickEvent('before_draggable_map_updated');
492
+ url = url + '&zoom_level=' + this.map.getZoom();
493
+
494
+ return fetch(url)
495
+ .then((response) => response.json())
496
+ .then(json => {
497
+ Homeflow.kickEvent('draggable_map_updated', json);
498
+ store.dispatch(setProperties(json.properties))
499
+ this._running_update = false;
500
+
501
+ if (json.breadcrumbs) {
502
+ this.breadcrumbs = this.concatenateDistinctObjects('geoname_id', this.breadcrumbs, json.breadcrumbs);
503
+ this.properties = [];
504
+ } else if (json.properties) {
505
+ this.properties = this.concatenateDistinctObjects('property_id', this.properties, json.properties);
506
+ this.breadcrumbs = [];
507
+ }
508
+ // TODO: figure out what 'tile view' is
509
+ // if (this.tile_view != null) {
510
+ // this.tile_view = new Ctesius.Views.Tiles({ collection: this.collection });
511
+ // }
512
+ return this.setMarkers();
513
+ });
499
514
  }
500
515
 
501
516
  // this method was copied directly from transpiled ES5 from the browser as it's the only
@@ -708,21 +723,9 @@ export default class DraggableMap {
708
723
  return new L.LatLng(y, x);
709
724
  }
710
725
 
711
- propertiesOrBreadcrumbs() {
712
- const breadcrumbs = this.breadcrumbs;
713
- const properties = this.properties;
714
- if (breadcrumbs && breadcrumbs.length) {
715
- return breadcrumbs;
716
- } else if (breadcrumbs && !breadcrumbs.length) {
717
- return properties;
718
- } else if (properties !== null && !Homeflow.get('breadcrumbs_map')) {
719
- return properties;
720
- } else {
721
- return null;
722
- }
723
- }
724
-
725
726
  handleBreadcrumbsInit() {
727
+ if (this.breadcrumbsInitialized) return;
728
+
726
729
  const { properties: { breadcrumbs } } = store.getState();
727
730
 
728
731
  if (breadcrumbs && this.breadcrumbs !== breadcrumbs) {
@@ -730,5 +733,19 @@ export default class DraggableMap {
730
733
  this.setMarkers();
731
734
  this.setToMarkeredBounds();
732
735
  }
736
+
737
+ this.breadcrumbsInitialized = true;
738
+ }
739
+
740
+ concatenateDistinctObjects(key, array, otherArray) {
741
+ return [...new Map((array || []).concat(otherArray || []).map((object) => [object[key], object])).values()];
742
+ }
743
+
744
+ markerPropertyIdOrGeonameId(marker) {
745
+ if (!marker) return null;
746
+ if (marker?.property?.property_id) return marker.property.property_id;
747
+ if (marker?.property?.geoname_id) return marker.property.geoname_id;
748
+
749
+ return null;
733
750
  }
734
751
  }
@@ -146,11 +146,6 @@ export default class DrawableMap extends DraggableMap {
146
146
  if (!this.first) { return this.onMapDrag(); }
147
147
  });
148
148
 
149
- this.map.on('dragend', () => {
150
- return this.onMapDrag();
151
- });
152
-
153
-
154
149
  this.map.on("draw:drawstart", e => {
155
150
  this.first = false;
156
151
  this.map.removeLayer(this.marker_layer);