SeatMap

Edit on Github
Open in Playground View Demo

Introduction

This is a sample showing how to implement a seatmap that can be used for theaters, cinemas, airplanes and more. We are showing how to pan & zoom on the seatmap to better select seats, how to keep the availability up to date and how to dynamically select and unselect seats.

Setup

Additionally used AMP components must be imported in the header: amp-pan-zoom for making the seatmap zoomable and scrollable

<script async custom-element="amp-pan-zoom" src="https://cdn.ampproject.org/v0/amp-pan-zoom-0.1.js"></script>

amp-bind for enabling seat selection

<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>

amp-list for showing a list of seats

<script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>

amp-mustache for rendering the amp-list content

<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>

Seatmap

Here we are using an amp-state called selectedSeats to keep a list of selected seat ids.

Example

<amp-state id="selectedSeats">
  <script type="application/json">
    []
  </script>
</amp-state>

We combine amp-list, amp-bind and amp-pan-zoom to implement a seatmap:

  • amp-list is used to keep the availability of the seatmap up to date.
  • amp-bind is used to update the status of the seats: when a seat is selected or unselected we update the color and we add the seat id to the seatmap.selectedSeats variable. amp-pan-zoom is used to make possible to pan & zoom on mobile devices.

Example

Seat map

  <h1>Seat map</h1>
  <div class="list-container">
    <amp-list layout="fill"
      src="/json/seats.json"
      items="."
      single-item
      noloading>
            {{/seats}}
          </svg>
        </amp-pan-zoom>
      </template>
    </amp-list>
  </div>