<commit_before>/*
 * @author     <NAME> <<EMAIL>>
 * @copyright  2013-2018 MapCentia ApS
 * @license    http://www.gnu.org/licenses/#AGPL  GNU AFFERO GENERAL PUBLIC LICENSE 3
 */

'use strict';

/**
 *
 * @type {*|exports|module.exports}
 */
var cloud;

/**
 *
 * @type {*|exports|module.exports}
 */
var utils;

/**
 *
 * @type {*|exports|module.exports}
 */
var backboneEvents;

/**
 *
 */
var transformPoint;


/**
 *
 * @type {string}
 */
var exId = "streetview";

/**
 *
 */
var clicktimer;

/**
 *
 */
var mapObj;


/**
 *
 * @type {{set: module.exports.set, init: module.exports.init}}
 */

module.exports = {

    /**
     *
     * @param o
     * @returns {exports}
     */
    set: function (o) {
        cloud = o.cloud;
        utils = o.utils;
        transformPoint = o.transformPoint;
        backboneEvents = o.backboneEvents;
        return this;
    },

    /**
     *
     */
    init: function () {

        var parentThis = this;

        /**
         *
         * Native Leaflet object
         */
        mapObj = cloud.get().map;

        /**
         *
         */
        var React = require('react');

        /**
         *
         */
        var ReactDOM = require('react-dom');

        /**
         *
         * @type {{Info: {da_DK: string, en_US: string}, Street View: {da_DK: string, en_US: string}, Choose service: {da_DK: string, en_US: string}, Activate: {da_DK: string, en_US: string}}}
         */
        var dict = {

            "Info": {
                "da_DK": "Start Google Street View eller Mapillary op fra hvor du klikker i kortet. Servicen starter i et nyt browser vindue.",
                "en_US": "Start Google Street View or Mapillary from where you click on the map. The service starts in a new browser window."
            },

            "Street View": {
                "da_DK": "Gadefoto",
                "en_US": "Street View"
            },

            "Choose service": {
                "da_DK": "Vælg service",
                "en_US": "Choose service"
            },

            "Activate": {
                "da_DK": "Aktiver",
                "en_US": "Activate"
            }
        };

        /**
         *
         * @param txt
         * @returns {*}
         * @private
         */
        var __ = function (txt) {
            if (dict[txt][window._vidiLocale]) {
                return dict[txt][window._vidiLocale];
            } else {
                return txt;
            }
        };

        /**
         *
         */
        class Streetview extends React.Component {
            constructor(props) {
                super(props);

                this.state = {
                    active: false,
                    selectedOption: "google"
                };

                this.onActive = this.onActive.bind(this);
                this.onChange = this.onChange.bind(this);
            }

            /**
             *
             * @param e
             */
            onActive(e) {
                this.setState({
                    active: e.target.checked
                });

                if (e.target.checked) {

                    // Turn info click off
                    //====================
                    backboneEvents.get().trigger("off:infoClick");

                    // Emit "on" event
                    //================
                    backboneEvents.get().trigger("on:" + exId);

                    utils.cursorStyle().crosshair();

                } else {

                    // Turn info click on again
                    //=========================
                    backboneEvents.get().trigger("on:infoClick");

                    // Emit "off" event
                    //=================
                    backboneEvents.get().trigger("off:" + exId);

                    utils.cursorStyle().reset();

                }

            }

            onChange(changeEvent) {
                this.setState({
                    selectedOption: changeEvent.target.value
                });
            }

            /**
             *
             */
            componentDidMount() {
                var me = this;

                // Listen and reacting to the global Reset ALL event
                backboneEvents.get().on("reset:all", function () {
                    me.setState({
                        active: false
                    });
                    utils.cursorStyle().reset();
                });

                // Handle click events on map
                // ==========================

                mapObj.on("dblclick", function () {
                    clicktimer = undefined;
                });
                mapObj.on("click", function (e) {
                    var event = new geocloud.clickEvent(e, cloud);
                    if (clicktimer) {
                        clearTimeout(clicktimer);
                    }
                    else {
                        if (me.state.active === false) {
                            return;
                        }

                        clicktimer = setTimeout(function (e) {

                            var coords = event.getCoordinate(), p, url;
                            p = utils.transform("EPSG:3857", "EPSG:4326", coords);
                            clicktimer = undefined;

                            switch (me.state.selectedOption) {
                                case "google":
                                    url = "http://maps.google.com/maps?q=&layer=c&cbll=" + p.y + "," + p.x + "&cbp=11,0,0,0,0";
                                    break;

                                case "mapillary":
                                    url = "https://www.mapillary.com/app/?lat=" + p.y + "&lng=" + p.x + "&z=17";
                                    break;
                            }

                            parentThis.callBack(url);

                        }, 250);
                    }
                });
            }

            /**
             *
             * @returns {XML}
             */
            render() {
                return (

                    <div role="tabpanel">
                        <div className="form-group">
                            <div className="togglebutton">
                                <label><input id="streetview-btn" type="checkbox"
                                              checked={this.state.active}
                                              onChange={this.onActive}/>{__("Activate")}
                                </label>

                            </div>
                            <h3>{__("Choose service")}</h3>
                            <div className="radio">
                                <label>
                                    <input type="radio" id="streetview-service-google" name="streetview-service"
                                           value="google" checked={this.state.selectedOption === 'google'}
                                           onChange={this.onChange}/>
                                    Google Street View
                                </label>
                            </div>

                            <div className="radio">
                                <label>
                                    <input type="radio" id="streetview-service-mapillary"
                                           name="streetview-service" value="mapillary"
                                           checked={this.state.selectedOption === 'mapillary'}
                                           onChange={this.onChange}/>
                                    Mapillary
                                </label>
                            </div>

                        </div>
                    </div>
                );
            }
        }

        utils.createMainTab(exId, __("Street View"), __("Info"), require('./../../../browser/modules/height')().max, "photo_camera");

        // Append to DOM<commit_msg>added danish oblique photo to streetview extension<commit_after>/*
 * @author     <NAME> <<EMAIL>>
 * @copyright  2013-2018 MapCentia ApS
 * @license    http://www.gnu.org/licenses/#AGPL  GNU AFFERO GENERAL PUBLIC LICENSE 3
 */

'use strict';

/**
 *
 * @type {*|exports|module.exports}
 */
var cloud;

/**
 *
 * @type {*|exports|module.exports}
 */
var utils;

/**
 *
 * @type {*|exports|module.exports}
 */
var backboneEvents;

/**
 *
 */
var transformPoint;


/**
 *
 * @type {string}
 */
var exId = "streetview";

/**
 *
 */
var clicktimer;

/**
 *
 */
var mapObj;


/**
 *
 * @type {{set: module.exports.set, init: module.exports.init}}
 */

module.exports = {

    /**
     *
     * @param o
     * @returns {exports}
     */
    set: function (o) {
        cloud = o.cloud;
        utils = o.utils;
        transformPoint = o.transformPoint;
        backboneEvents = o.backboneEvents;
        return this;
    },

    /**
     *
     */
    init: function () {

        var parentThis = this;

        /**
         *
         * Native Leaflet object
         */
        mapObj = cloud.get().map;

        /**
         *
         */
        var React = require('react');

        /**
         *
         */
        var ReactDOM = require('react-dom');

        /**
         *
         * @type {{Info: {da_DK: string, en_US: string}, Street View: {da_DK: string, en_US: string}, Choose service: {da_DK: string, en_US: string}, Activate: {da_DK: string, en_US: string}}}
         */
        var dict = {

            "Info": {
                "da_DK": "Start Google Street View, Mapillary eller skråfoto op fra hvor du klikker i kortet. Servicen starter i et nyt browser vindue.",
                "en_US": "Start Google Street View, Mapillary or Oblique Photo from where you click on the map. The service starts in a new browser window."
            },

            "Street View": {
                "da_DK": "Gadefoto",
                "en_US": "Street View"
            },

            "Choose service": {
                "da_DK": "Vælg service",
                "en_US": "Choose service"
            },

            "Activate": {
                "da_DK": "Aktiver",
                "en_US": "Activate"
            }
        };

        /**
         *
         * @param txt
         * @returns {*}
         * @private
         */
        var __ = function (txt) {
            if (dict[txt][window._vidiLocale]) {
                return dict[txt][window._vidiLocale];
            } else {
                return txt;
            }
        };

        /**
         *
         */
        class Streetview extends React.Component {
            constructor(props) {
                super(props);

                this.state = {
                    active: false,
                    selectedOption: "google"
                };

                this.onActive = this.onActive.bind(this);
                this.onChange = this.onChange.bind(this);
            }

            /**
             *
             * @param e
             */
            onActive(e) {
                this.setState({
                    active: e.target.checked
                });

                if (e.target.checked) {

                    // Turn info click off
                    //====================
                    backboneEvents.get().trigger("off:infoClick");

                    // Emit "on" event
                    //================
                    backboneEvents.get().trigger("on:" + exId);

                    utils.cursorStyle().crosshair();

                } else {

                    // Turn info click on again
                    //=========================
                    backboneEvents.get().trigger("on:infoClick");

                    // Emit "off" event
                    //=================
                    backboneEvents.get().trigger("off:" + exId);

                    utils.cursorStyle().reset();

                }

            }

            onChange(changeEvent) {
                this.setState({
                    selectedOption: changeEvent.target.value
                });
            }

            /**
             *
             */
            componentDidMount() {
                var me = this;

                // Listen and reacting to the global Reset ALL event
                backboneEvents.get().on("reset:all", function () {
                    me.setState({
                        active: false
                    });
                    utils.cursorStyle().reset();
                });

                // Handle click events on map
                // ==========================

                mapObj.on("dblclick", function () {
                    clicktimer = undefined;
                });
                mapObj.on("click", function (e) {
                    var event = new geocloud.clickEvent(e, cloud);
                    if (clicktimer) {
                        clearTimeout(clicktimer);
                    }
                    else {
                        if (me.state.active === false) {
                            return;
                        }

                        clicktimer = setTimeout(function (e) {

                            var coords = event.getCoordinate(), p, url;
                            p = utils.transform("EPSG:3857", "EPSG:4326", coords);
                            clicktimer = undefined;

                            switch (me.state.selectedOption) {
                                case "google":
                                    url = "http://maps.google.com/maps?q=&layer=c&cbll=" + p.y + "," + p.x + "&cbp=11,0,0,0,0";
                                    break;

                                case "mapillary":
                                    url = "https://www.mapillary.com/app/?lat=" + p.y + "&lng=" + p.x + "&z=17";
                                    break;

                                case "skraafoto":
                                    url = "https://skraafoto.kortforsyningen.dk/oblivisionjsoff/index.aspx?project=Denmark&lon=" + p.x + "&lat=" + p.y;
                                    break;
                            }

                            parentThis.callBack(url);

                        }, 250);
                    }
                });
            }

            /**
             *
             * @returns {XML}
             */
            render() {
                return (

                    <div role="tabpanel">
                        <div className="form-group">
                            <div className="togglebutton">
                                <label><input id="streetview-btn" type="checkbox"
                                              checked={this.state.active}
                                              onChange={this.onActive}/>{__("Activate")}
                                </label>

                            </div>
                            <h3>{__("Choose service")}</h3>
                            <div className="radio">
                                <label>
                                    <input type="radio" id="streetview-service-google" name="streetview-service"
                                           value="google" checked={this.state.selectedOption === 'google'}
                                           onChange={this.onChange}/>
                                    Google Street View
                                </label>
                            </div>

                            <div className="radio">
                                <label>
                                    <input type="radio" id="streetview-service-mapillary"
                                           name="streetview-service" value="mapillary"
                                           checked={this.state.selectedOption === 'mapillary'}
                                           onChange={this.onChange}/>
                                    Mapillary
                                </label>
                            </div>

                            <div className="radio">
                                <label>
                                    <input type="radio" id="streetview-service-skraafoto"
                                           name="streetview-service" value="skraafoto"
                                           checked={this.state.selectedOption === 'skraafoto'}
                                           onChange={this.onChange}/>
                                    Skråfoto
                                </label>
                            </div>

                        </div>
                    </div>
                );
            }
        }

        utils.createMainTab(exId, __("Street View"), __("Info"), require('./../../../browser/modules/height')().max, "photo_camera");

        // Append to DOM
{'fraction_non_alphanumeric': 0.12875281832206004, 'fraction_numerical': 0.00355998576005696, 'mean_word_length': 0.9045197740112995, 'pattern_counts': {'":': 29, '<': 56, '<?xml version=': 0, '>': 56, 'https://': 3, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 54, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6704381', 'n_tokens_mistral': 4273, 'n_tokens_neox': 3885, 'n_words': 776}