{"size": 1836, "ext": "js", "max_stars_repo_path": "src/lib/yahooMap.js", "max_stars_repo_name": "yahoo/react-cartographer", "max_stars_repo_stars_event_min_datetime": "2015-05-27T18:48:24.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-23T11:06:18.000Z", "max_issues_repo_path": "src/lib/yahooMap.js", "max_issues_repo_name": "yahoo/react-cartographer", "max_issues_repo_issues_event_min_datetime": "2015-05-27T19:34:43.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-21T02:13:19.000Z", "max_forks_repo_path": "src/lib/yahooMap.js", "max_forks_repo_name": "ConnectionMaster/react-cartographer", "max_forks_repo_forks_event_min_datetime": "2015-08-25T02:08:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-26T17:13:59.000Z"}
{"max_stars_count": 87, "max_issues_count": 41, "max_forks_count": 15, "avg_line_length": 25.8591549296, "max_line_length": 105, "alphanum_fraction": 0.5539215686}
/**
 * Copyright 2015, Yahoo! Inc.
 * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
 */

'use strict';

/*
 * Yahoo MapImage Service
 * @class GoogleMapService
 */

const _ = {
    // Collection
    pick: require('lodash/pickBy'),
    identity: require('lodash/identity')
};

import {yahoo as config} from '../../config/config.json';
import utils from 'url';

export default class YahooMapService {
    get name() {
        return config.name;
    }

    /**
     * Get the map location details for the address provided in the params
     * Map Location details include: geo coordinates and map url to display
     *
     * @param {Object} params
     * @returns {{mapId: (*|string|string|string|string), data: {locationLink: *, locationText: string}}}
     */
    getMap (params) {
        let location;
        let url;
        const query = _.pick({
            appid: params.providerKey,
            imw: params.width,
            imh: params.height,
            imi: config.imi,
            radius: config.radius,
            zoom: params.zoom
        }, _.identity);

        if (isFinite(params.longitude) && isFinite(params.latitude)) {
            location = [params.latitude, params.longitude].join(',');
            query.clat = params.latitude;
            query.clon = params.longitude;
        } else {
            location = [params.line1, params.line2, params.line3].join(',');
            query.q = location;
        }

        url = utils.format({
            protocol: config.protocol,
            hostname: config.host,
            pathname: config.path,
            query: query
        });

        return {
            mapId: params.mapId,
            data: {
                locationLink: url,
                locationText: location
            }
        };
    }
}
