iticket-seatingplan-dev 1.2.0 → 1.2.2

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.
@@ -287,8 +287,25 @@ const SeatingPlan = _ref => {
287
287
  }));
288
288
  }
289
289
  }, [chosenSeat, processing]);
290
+ const calculateCenterOfMap = (height, seats) => {
291
+ const filteredSeats = seats.filter(price => price.psId === priceSectionId);
292
+ const avgY = filteredSeats.reduce((acc, val) => {
293
+ return acc + val.y / filteredSeats.length;
294
+ }, 0);
295
+ const avgX = filteredSeats.reduce((acc, val) => {
296
+ return acc + val.x / filteredSeats.length;
297
+ }, 0);
298
+ return [height * 0.05 - avgY / (height > 800 ? height > 999 ? 3.5 : 3.3 : 3.35) - (height > 800 ? height > 999 ? height * 0.0201 : height * 0.0198 : height * 0.0206), avgX * 0.3 + 0.15];
299
+ };
300
+ const determineZoom = seats => {
301
+ const filteredSeats = seats.filter(price => price.psId === priceSectionId);
302
+ const x = filteredSeats.map(fs => fs.x);
303
+ const y = filteredSeats.map(fs => fs.y);
304
+ const maxX = Math.max(...x) - Math.min(...x);
305
+ const maxY = Math.max(...y) - Math.min(...y);
306
+ if (maxY > 67.5) return 4;else return 6;
307
+ };
290
308
 
291
- // console.log(height, width)
292
309
  // return seating plan
293
310
  return /*#__PURE__*/_react.default.createElement("div", {
294
311
  style: {
@@ -297,10 +314,14 @@ const SeatingPlan = _ref => {
297
314
  }
298
315
  }, error ? /*#__PURE__*/_react.default.createElement("div", {
299
316
  className: "loading"
300
- }, /*#__PURE__*/_react.default.createElement("h1", null, "OOPS!"), /*#__PURE__*/_react.default.createElement("div", null, error.response.data.message)) : position && area === areaId ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, height, "xxx", width / height * 0.01, /*#__PURE__*/_react.default.createElement(_reactLeaflet.MapContainer, {
301
- whenReady: setMap,
302
- center: [height * 0.015, width * 0.015],
303
- zoom: 6,
317
+ }, /*#__PURE__*/_react.default.createElement("h1", null, "OOPS!"), /*#__PURE__*/_react.default.createElement("div", null, error.response.data.message)) : position && area === areaId ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactLeaflet.MapContainer, {
318
+ whenReady: setMap
319
+ // center={[height * 0.015, width * 0.015]}
320
+ ,
321
+ center: calculateCenterOfMap(height, seats.seats)
322
+ // zoom={6}
323
+ ,
324
+ zoom: determineZoom(seats.seats),
304
325
  zoomControl: true,
305
326
  scrollWheelZoom: true,
306
327
  style: {
@@ -381,7 +402,7 @@ const SeatingPlan = _ref => {
381
402
  }
382
403
  }, /*#__PURE__*/_react.default.createElement("button", {
383
404
  title: "Re-centre Seating Plan",
384
- onClick: () => map.target.setView([height * 0.015, width * 0.015], 6),
405
+ onClick: () => map.target.setView(calculateCenterOfMap(height, seats.seats), determineZoom(seats.seats)),
385
406
  className: "leaflet-control-zoom-in",
386
407
  style: {
387
408
  border: 'none',
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "iticket-seatingplan-dev",
3
3
  "description": "Seating plan with FLEXi pricing",
4
4
  "author": "gedwyne",
5
- "version": "1.2.0",
5
+ "version": "1.2.2",
6
6
  "private": false,
7
7
  "keywords": [
8
8
  "iticket",