timelapse.xhtml 5.14 KB
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
      xmlns:map="http://java.sun.com/jsf/composite/cditools/map"
      xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.org/ui">
<h:body>
    <ui:composition template="#{sessionHandler.template}">
        <f:metadata>
            <f:viewParam name="mapId" value="#{timelapseMapView.mapId}"/>
            <f:event type="preRenderView" listener="#{timelapseMapView.init}"/>
        </f:metadata>
        <ui:define name="content">


            <script type="text/javascript">
                //<![CDATA[

                var datetimeFormat = '#{sessionHandler.datetimeFormat}';

                var firstTime = new Date(#{timelapseMapView.firstTime.time});
                var lastTime = new Date(#{timelapseMapView.lastTime.time});
                var varDiff = #{timelapseMapView.lastTime.time - timelapseMapView.firstTime.time};
                var imgurl = "#{request.contextPath}/PlaceMap?mapid=#{timelapseMapView.mapId}&timestamp=";

                function changeStamp(i) {
                    var ts = $('#timestamp');
                    setStamp(parseInt(ts.val()) + parseInt(i));

                }


                function updateTsDate() {
                    var d = new Date(getTimelapseStamp());
                    var tsDate = $('#timelapseDate');
                    tsDate.val(d.toJSON());
                    reloadImage();
                }

                function reloadImage() {
                    var img = $('#tsimage');
                    img.attr('src', imgurl + getTimelapseStamp());
                }

                function getTimelapseStamp() {
                    var ret = firstTime.getTime() + getOffsetMs();
                    if (ret > lastTime.getTime()) {
                        ret = lastTime.getTime()
                    } else if (ret < firstTime.getTime()) {
                        ret = firstTime.getTime();
                    }
                    return ret;
                }

                function setStamp(stamp){
                    $('#timestamp').val(stamp);

                    updateTsDate();
                    PF('slider').setValue(stamp);
                }

                function getOffsetMs() {
                    return parseInt($('#timestamp').val())*1000;
                }

                function loadDateString(entry) {
                    console.log(entry);
                    var d = new Date($('#timelapseDate').val());
                    var ts = $('#timestamp').val(d.getTime());
                    updateTsDate();
                }

                $().ready(function () {
                    $('#TimelapseDate').val(firstTime.toJSON());
                    updateTsDate();

                });
                //]]>

            </script>
            <div>
                <h:outputText value="#{i18n['map.timelapse.startTime']}" />
                <h:outputText value="#{timelapseMapView.firstTime}">
                    <f:convertDateTime pattern="#{sessionHandler.datetimeFormat}"
                                       timeZone="#{sessionHandler.timezone}"/>
                </h:outputText></div>
            <div>
                <h:outputText value="#{i18n['map.timelapse.endTime']}" />
                <h:outputText value="#{timelapseMapView.lastTime}">
                    <f:convertDateTime pattern="#{sessionHandler.datetimeFormat}"
                                       timeZone="#{sessionHandler.timezone}"/>
                </h:outputText>
            </div>
            <div>
                <button onclick="setStamp(0)">&lt;-</button>
                <button onclick="changeStamp(-604800)">-7d</button>
                <button onclick="changeStamp(-86400)">-1d</button>
                <button onclick="changeStamp(-21600)">-6h</button>
                <button onclick="changeStamp(-300)">-5min</button>
                <input id="timelapseDate" onchange="loadDateString(this);" type="text"/>
                <button onclick="changeStamp(300)">+5min</button>
                <button onclick="changeStamp(21600)">+6h</button>
                <button onclick="changeStamp(86400)">+1d</button>
                <button onclick="changeStamp(604800)">+7d</button>
                <button onclick="setStamp(#{(timelapseMapView.lastTime.time - timelapseMapView.firstTime.time)/1000})">-&gt;</button>


            </div>

            <h:inputText id="timestamp" value="#{timelapseMapView.timestampValue}"/>
            <p:slider widgetVar="slider" style="width: 200px;" for="timestamp" onSlideEnd="updateTsDate()"
                      maxValue="#{(timelapseMapView.lastTime.time - timelapseMapView.firstTime.time)/1000}"/>
            <img id="tsimage" alt="Timelapse image"
                 src="#{request.contextPath}/PlaceMap?mapid=#{timelapseMapView.mapId}&amp;timestamp=#{timelapseMapView.firstTime.time}"/>

        </ui:define>
    </ui:composition>
</h:body>
</html>