AMP
  • websites

SeatMap Multiple Selection

Introduction

This sample allows to multiple select seats in a seatmap with one click: this is useful when an user wants to book adjacent seats without clicking multiple times; go here for the basic seatmap sample.

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>

amp-selector for selecting seats on the seatmap

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

Seatmap state

Here we are using an amp-state called seatMultiSelection to keep all the useful information for the seat selection.

  • we load a list of neighbours seats from the server
  • selectedSeats contains a list of selected seat ids
  • numberOfSeats contains the number of seats we want automatically select
<amp-state id="seatMultiSelection" src="https://amp.dev/static/samples/json/seatmap-neighbours.json">
  <script type="application/json">
  {
    "selectedSeats": [],
    "numberOfSeats": 3
  }
  </script>
</amp-state>

Seatmap with multiple selection

Everytime a seat is selected, we automatically select the 2 seats on the right of it. In case the number of seats on the right of the selected one are less than 2, we only select the remaining on the line.

Seat map

<div class="seatmap-container">
 <h1>Seat map</h1>
 <amp-list layout="fill" src="https://amp.dev/static/samples/json/seats.json" binding="refresh" items="." single-item noloading>
   <template type="amp-mustache">
     <amp-pan-zoom layout="fill" class="seatmap">
       <amp-selector on="select:AMP.setState({
         seatMultiSelection: {
           selectedSeats: event.selectedOptions.concat(
                         seatMultiSelection.neighbours[event.selectedOptions[0]].slice(0, seatMultiSelection.numberOfSeats-1))
           }
         })" layout="fill">
         <div class="svg-container">
           <svg preserveAspectRatio="xMidYMin slice" viewBox="0 0 {{width}} {{height}}">
           {{#seats}}
             <rect option="{{id}}" role="button" tabindex="0" class="seat {{unavailable}}" [class]="seatMultiSelection.selectedSeats.indexOf('{{id}}') != -1 ? 'selected seat {{unavailable}}' : 'seat {{unavailable}}'" x="{{x}}" y="{{y}}" width="{{width}}" height="{{height}}" rx="{{rx}}" ry="{{ry}}">
         </rect>
           {{/seats}}
           </svg>
         </div>
       </amp-selector>
     </amp-pan-zoom>
   </template>
   <div placeholder>
     <svg class="disabled" viewBox="0 0  " preserveAspectRatio="xMidYMin slice">
       </svg>
     </div>
 </amp-list>
 </div>
Daha fazla açıklamaya mı ihtiyacınız var?

Bu sayfadaki açıklamalar tüm sorularınıza yanıt vermiyorsa, özgün kullanım durumunuzu tartışmak üzere diğer AMP kullanıcılarına ulaşmaktan çekinmeyin.

Stack Overflow'a git
Açıklanmayan bir özellik mi var?

AMP projesi, katılımınızı ve katkılarınızı güçlü bir şekilde teşvik ediyor! Açık kaynak topluluğumuzun devamlı bir katılımcısı olacağınızı umuyoruz ancak özel olarak ilgilendiğiniz konularla ilgili tek seferlik katkıları da memnuniyetle karşılıyoruz.

Örneği GitHub'ta düzenle