<commit_before>'use strict';

import React from 'react/addons';
import {GoogleMaps, Marker} from "react-google-maps";
var GeoObjectsAction = require('actions/GeoObjectActionCreators');
var _ = require('underscore');
const {update} = React.addons;
var geoCoder = new google.maps.Geocoder();
var Modal = require('components/Modal');

require('styles/GeoObjectEditor.less');

function getEmptyObjectState() {
    return {
        markers: [],
        isVisible: false,
        closable: false,
        zoomLevel: 3,
        mapCenter: {lat: -34.397, lng: 150.644},
        address: '',
        category: 'Без категории',
        latitude: '',
        longitude: '',
        id: Date.now(),
        name: ''
    };
}

var GeoObjectEditor = React.createClass({

    getInitialState: function () {
        return getEmptyObjectState();
    },

    show: function () {
        this.setState({isVisible: true});
    },

    /**
     * Set geo object editor address
     * @param latLng
     * @private
     */
    _setAddressFromLatLng: function (latLng) {
        geoCoder.geocode({'latLng': latLng}, this._getAddressCallback);
    },

    /**
     * Geo coder callback
     * @param results
     * @param status
     * @private
     */
    _getAddressCallback: function (results, status) {
        if (status === google.maps.GeocoderStatus.OK) {
            if (results[0]) {
                this.setState({address: results[0].formatted_address});
            }
            else {
                this.setState({address: ''});
            }
        }
    },

    /**
     * Get marker with marker raw data
     * @param {object} marker The marker raw data
     * @param {int} index
     * @returns {XML}
     * @private
     */
    _getMarkerComponent: function (marker, index) {
        //var pinColor = "413316";
        //var pinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + pinColor,
        //    new google.maps.Size(21, 34),
        //    new google.maps.Point(0,0),
        //    new google.maps.Point(10, 34));
        //var pinShadow = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
        //    new google.maps.Size(40, 37),
        //    new google.maps.Point(0, 0),
        //    new google.maps.Point(12, 35));
        return (
            <Marker position={marker.position}
                    key={marker.key}
                    onRightclick={this._handle_marker_rightClick.bind(this, index)}
                //icon={pinImage}
                />
        );
    },
    /**
     * Set map marker to given lat & lng coordinates
     * @param lat
     * @param lng
     * @private
     */
    _setMarkerFromLatLng: function (lat, lng) {
        if (!isNaN(parseInt(lat)) && !isNaN(parseInt(lng))) {
            var {markers} = this.state;
            markers = [{
                position: new google.maps.LatLng(lat, lng),
                key: Date.now()
            }];
            this.setState({markers});
            this.refs.editorMap.panTo(new google.maps.LatLng(lat, lng));
        }

    },

    /**
     * Editor map click handler
     * @param event
     * @private
     */
    _handleMapClick: function (event) {
        this._setMarkerFromLatLng(event.latLng.lat(), event.latLng.lng());
        this.setState({
            latitude: event.latLng.lat(),
            longitude: event.latLng.lng()
        });
        this._setAddressFromLatLng(event.latLng);
    },

    /**<commit_msg>fix google map pan to marker<commit_after>'use strict';

import React from 'react/addons';
import {GoogleMaps, Marker} from "react-google-maps";
var GeoObjectsAction = require('actions/GeoObjectActionCreators');
var _ = require('underscore');
const {update} = React.addons;
var geoCoder = new google.maps.Geocoder();
var Modal = require('components/Modal');

require('styles/GeoObjectEditor.less');

function getEmptyObjectState() {
    return {
        markers: [],
        isVisible: false,
        closable: false,
        zoomLevel: 3,
        mapCenter: {lat: -34.397, lng: 150.644},
        address: '',
        category: 'Без категории',
        latitude: '',
        longitude: '',
        id: Date.now(),
        name: ''
    };
}

var GeoObjectEditor = React.createClass({

    getInitialState: function () {
        return getEmptyObjectState();
    },

    show: function () {
        this.setState({isVisible: true});
    },

    /**
     * Set geo object editor address
     * @param latLng
     * @private
     */
    _setAddressFromLatLng: function (latLng) {
        geoCoder.geocode({'latLng': latLng}, this._getAddressCallback);
    },

    /**
     * Geo coder callback
     * @param results
     * @param status
     * @private
     */
    _getAddressCallback: function (results, status) {
        if (status === google.maps.GeocoderStatus.OK) {
            if (results[0]) {
                this.setState({address: results[0].formatted_address});
            }
            else {
                this.setState({address: ''});
            }
        }
    },

    /**
     * Get marker with marker raw data
     * @param {object} marker The marker raw data
     * @param {int} index
     * @returns {XML}
     * @private
     */
    _getMarkerComponent: function (marker, index) {
        //var pinColor = "413316";
        //var pinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + pinColor,
        //    new google.maps.Size(21, 34),
        //    new google.maps.Point(0,0),
        //    new google.maps.Point(10, 34));
        //var pinShadow = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
        //    new google.maps.Size(40, 37),
        //    new google.maps.Point(0, 0),
        //    new google.maps.Point(12, 35));
        return (
            <Marker position={marker.position}
                    key={marker.key}
                    onRightclick={this._handle_marker_rightClick.bind(this, index)}
                //icon={pinImage}
                />
        );
    },
    /**
     * Set map marker to given lat & lng coordinates
     * @param lat
     * @param lng
     * @private
     */
    _setMarkerFromLatLng: function (lat, lng) {
        if (!isNaN(parseInt(lat)) && !isNaN(parseInt(lng))) {
            var {markers} = this.state;
            var mapCenter = new google.maps.LatLng(lat, lng);
            markers = [{
                position: mapCenter,
                key: Date.now()
            }];
            this.setState({markers, mapCenter});
            this.refs.editorMap.panTo(mapCenter);
        }

    },

    /**
     * Editor map click handler
     * @param event
     * @private
     */
    _handleMapClick: function (event) {
        this._setMarkerFromLatLng(event.latLng.lat(), event.latLng.lng());
        this.setState({
            latitude: event.latLng.lat(),
            longitude: event.latLng.lng()
        });
        this._setAddressFromLatLng(event.latLng);
    },

    /**
{'fraction_non_alphanumeric': 0.1405940594059406, 'fraction_numerical': 0.012446958981612447, 'mean_word_length': 1.9450229071220324, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1536776', 'n_tokens_mistral': 2247, 'n_tokens_neox': 2156, 'n_words': 423}