homeflowjs 0.11.9 → 0.11.10

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": "homeflowjs",
3
- "version": "0.11.9",
3
+ "version": "0.11.10",
4
4
  "description": "JavaScript toolkit for Homeflow themes",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -58,7 +58,7 @@ export default class DraggableMap {
58
58
  this.render();
59
59
  this.buildPolygon();
60
60
  this.setMarkers();
61
- if (this.noLocationfound) { this.setToMarkeredBounds(); }
61
+ if (this.noLocationfound || Homeflow.get('breadcrumbs_map')) { this.setToMarkeredBounds(); }
62
62
  if (Homeflow.get('custom_map_zoom') !== null) {
63
63
  this.map.setZoom(Homeflow.get('custom_map_zoom'));
64
64
  }
@@ -123,7 +123,10 @@ export default class DraggableMap {
123
123
  }
124
124
 
125
125
  generateMarker(property) {
126
- const marker = L.marker([property.lat, property.lng], { icon: Homeflow.get('custom_property_pin')(property) });
126
+ const marker = L.marker(
127
+ [property.lat, property.lng],
128
+ { title: property.name, icon: Homeflow.get('custom_property_pin')(property) }
129
+ );
127
130
 
128
131
  // add the property to marker attributes so they can be accessed on click
129
132
  marker.property = property;
@@ -139,7 +142,6 @@ export default class DraggableMap {
139
142
 
140
143
  if (Homeflow.get('pop_up_on_mouseover')) {
141
144
  marker.on("mouseover", e => marker.openPopup());
142
-
143
145
  marker.on("mouseout", e => setTimeout((() => marker.closePopup()), 4000));
144
146
  }
145
147
  }
@@ -260,14 +262,16 @@ export default class DraggableMap {
260
262
 
261
263
  if (!this.properties && !this.breadcrumbs) { return null }
262
264
 
263
- this.properties?.map(property => this.setPropertyMarker(property));
264
- this.breadcrumbs?.map(breadcrumb => this.setBreadcrumbMarker(breadcrumb));
265
+
266
+ if (this.isDisplayProperties()) {
267
+ this.properties?.map(property => this.setPropertyMarker(property));
268
+ } else {
269
+ this.breadcrumbs?.map(breadcrumb => this.setBreadcrumbMarker(breadcrumb));
270
+ }
271
+
265
272
  this.clusteringMarkerLayer.addTo(this.map);
266
273
  this.nonClusteringMarkerLayer.addTo(this.map);
267
274
 
268
- // TODO: Combine bounds.
269
- this.bounds = this.clusteringMarkerLayer.getBounds() || this.nonClusteringMarkerLayer.getBounds();
270
-
271
275
  return this.bounds;
272
276
  }
273
277
 
@@ -288,18 +292,60 @@ export default class DraggableMap {
288
292
  }
289
293
 
290
294
  setToMarkeredBounds() {
291
- if (this.bounds != null) {
292
- if (Homeflow.get('custom_map_bounds_padding')) {
293
- this.map.fitBounds(this.bounds, Homeflow.get('custom_map_bounds_padding'));
294
- } else {
295
- this.map.fitBounds(this.bounds);
296
- }
295
+ const options = Homeflow.get('custom_map_bounds_padding');
296
+ const bounds = this.getMarkerBounds();
297
297
 
298
- if (Homeflow.get('custom_map_centre_lat') && Homeflow.get('custom_map_centre_lng')) {
299
- this.map.setView([Homeflow.get('custom_map_centre_lat'), Homeflow.get('custom_map_centre_lng')], 7);
300
- }
298
+ if (!bounds || !bounds.isValid()) return;
299
+
300
+ this.map.fitBounds(bounds, options);
301
+
302
+ if (Homeflow.get('custom_map_centre_lat') && Homeflow.get('custom_map_centre_lng')) {
303
+ this.map.setView([Homeflow.get('custom_map_centre_lat'), Homeflow.get('custom_map_centre_lng')], 7);
304
+ }
305
+
306
+ Homeflow.kickEvent('non_standard_zoom', this.map, 4);
307
+ }
301
308
 
302
- return Homeflow.kickEvent('non_standard_zoom', this.map, 4);
309
+ getMarkerBounds() {
310
+ if (this.bounds && this.bounds.isValid()) {
311
+ return this.bounds;
312
+ } else {
313
+ const bounds = [this.getTopLeftMarkerCoordinates(), this.getBottomRightMarkerCoordinates()];
314
+ if (bounds.flat().find(coordinate => coordinate === Infinity)) return null;
315
+
316
+ return L.latLngBounds(...bounds.map(bound => L.latLng(...bound)));
317
+ }
318
+ }
319
+
320
+ getTopLeftMarkerCoordinates() {
321
+ return [
322
+ Math.min(...this.parseCoordinateArray([this.properties, this.breadcrumbs].flat(), 'lat')),
323
+ Math.min(...this.parseCoordinateArray([this.properties, this.breadcrumbs].flat(), 'lng'))
324
+ ];
325
+ }
326
+
327
+ getBottomRightMarkerCoordinates() {
328
+ return [
329
+ Math.max(...this.parseCoordinateArray([this.properties, this.breadcrumbs].flat(), 'lat')),
330
+ Math.max(...this.parseCoordinateArray([this.properties, this.breadcrumbs].flat(), 'lng'))
331
+ ];
332
+ }
333
+
334
+ parseCoordinateArray(items, coordinateType) {
335
+ if (!items) return [];
336
+
337
+ return items.filter(item => item).map(item => parseFloat(item[coordinateType])).filter(Number);
338
+ }
339
+
340
+ isDisplayProperties() {
341
+ const { properties: { pagination: { total_count: totalCount } } } = store.getState();
342
+
343
+ if (!this.breadcrumbs || !Homeflow.get('breadcrumbs_map')) {
344
+ return true;
345
+ } else if (this.properties && totalCount <= this.properties.length) {
346
+ return true;
347
+ } else {
348
+ return false;
303
349
  }
304
350
  }
305
351