SeatMap
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>
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 selectedSeats to keep a list of selected seat ids.
<amp-state id="selectedSeats">
<script type="application/json">
[]
</script>
</amp-state>
Seatmap implementation
We combine amp-list, amp-bind, amp-pan-zoom and amp-selector to implement a seatmap:
amp-listis used to keep the availability of the seatmap up to date.amp-bindis used to update the status of the seats: when a seat is selected we add the seat id to theselectedSeatsvariable.amp-pan-zoomis used to enable to pan & zoom on mobile devices.amp-selectoris used to select seats and style selected seats
Seat map
<h1>Seat map</h1>
<div class="seatmap-container">
<amp-list layout="fill" src="/static/samples/json/seats.json" binding="refresh" items="." single-item noloading>
<!--START_HINT_0-->
<template type="amp-mustache">
<amp-pan-zoom layout="fill" class="seatmap">
<amp-selector multiple on="select:AMP.setState({
selectedSeats: event.selectedOptions
})" 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}}" x="{{x}}" y="{{y}}" width="{{width}}" height="{{height}}" rx="{{rx}}" ry="{{ry}}"/>
{{/seats}}
</svg>
</div>
<!--END_HINT-->
</amp-selector>
</amp-pan-zoom>
</template>
<!--START_HINT_1-->
<div placeholder>
<svg class="disabled" viewBox="0 0 " preserveAspectRatio="xMidYMin slice">
</svg>
</div>
<!--END_HINT-->
</amp-list>
</div>
Nếu bạn vẫn còn thắc mắc sau khi đọc hướng dẫn trên trang này, hãy liên hệ với những người dùng AMP khác để thảo luận về trường hợp sử dụng cụ thể của bạn.
Truy cập Stack Overflow Một tính năng chưa được giải thích?Dự án AMP đặc biệt khuyến khích sự tham gia và đóng góp của bạn! Chúng tôi hi vọng bạn sẽ trở thành một người tham gia tích cực trong cộng đồng mã nguồn mở của chúng tôi, nhưng chúng tôi cũng chào mừng các đóng góp đơn lẻ về vấn đề mà bạn đặc biệt quan tâm.
Chỉnh sửa mẫu trên GitHub-
Written by @kul3r4