"use strict";
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var WIDTH, HEIGHT, CoordMap = {};
var d3 = require("d3");
var _ = require("lodash");
var default_1 = /** @class */ (function () {
    function default_1(json, width, height, adjust) {
        var _a, _b, _c, _d;
        if (adjust === void 0) { adjust = [0, 0, 1]; }
        this.left = 0;
        this.top = 0;
        this.right = 0;
        this.bottom = 0;
        this.adjust = [0, 0, 1];
        _a = __read([width, height], 2), WIDTH = _a[0], HEIGHT = _a[1];
        if (adjust.length == 3) {
            if (_.isNumber(adjust[0])) {
                this.adjust[0] = adjust[0];
            }
            if (_.isNumber(adjust[1])) {
                this.adjust[1] = adjust[1];
            }
            if (_.isNumber(adjust[2])) {
                this.adjust[2] = adjust[2];
            }
        }
        _b = __read(d3.geoBounds(json), 2), _c = __read(_b[0], 2), this.left = _c[0], this.top = _c[1], _d = __read(_b[1], 2), this.right = _d[0], this.bottom = _d[1];
        json.features.map(function (item) {
            CoordMap[item.properties.name] = {};
            CoordMap[item.properties.name]['id'] = item.properties.id || item.properties.adcode || item.properties.name;
            // if (item.properties.center) {
            // CoordMap[item.properties.name]['center'] = [item.properties.center.lng, item.properties.center.lat];
            // }
            // else if (item.properties.cp) {		// 旧版cp不是太准
            // 	CoordMap[item.properties.name]['center'] = item.properties.cp;
            // } 
            // else {
            CoordMap[item.properties.name]['center'] = d3.geoCentroid(item);
            // }
        });
    }
    default_1.prototype.resize = function (width, height) {
        var _a;
        _a = __read([width, height], 2), WIDTH = _a[0], HEIGHT = _a[1];
    };
    default_1.prototype.getCoord = function () {
        return [WIDTH, HEIGHT];
    };
    // randomPoint(cityName, size) {
    // 	var points = [];
    // 	size = size || 1;
    // 	if (CoordMap.hasOwnProperty(cityName)) {
    // 		var path = $('#area-' + CoordMap[cityName].id + ' path')[0];
    // 		var rect = path.getBBox();
    // 		for (var i = 0; i < size; i++) {
    // 			if (_.random(0, 1)) {
    // 				points.push({
    // 					x: rect.x + rect.width * 0.2 + _.random(0, rect.width * 0.6),
    // 					y: rect.y + rect.height * 0.4 + _.random(0, rect.height * 0.2),
    // 					in: cityName
    // 				});
    // 			} else {
    // 				points.push({
    // 					x: rect.x + rect.width * 0.4 + _.random(0, rect.width * 0.2),
    // 					y: rect.y + rect.height * 0.2 + _.random(0, rect.height * 0.6),
    // 					in: cityName
    // 				});
    // 			}
    // 		}
    // 	}
    // 	return points;
    // }
    default_1.prototype.getPoint = function (cityName) {
        if (CoordMap.hasOwnProperty(cityName)) {
            return CoordMap[cityName].center;
        }
        return null;
    };
    //获取地图中心点
    default_1.prototype.getCenter = function () {
        return [this.left * 0.5 + this.right * 0.5, this.bottom * 0.5 + this.top * 0.5];
    };
    //获取地图全部显示的比例
    //计算后比例大概是 1:0.017，经纬度只能转换为公里，不能对应成像素，然后使用adJUST参数进行调节
    default_1.prototype.getFullScale = function () {
        var hScale = (WIDTH / (this.right - this.left)) + this.adjust[0];
        var vScale = (HEIGHT / (this.bottom - this.top)) + this.adjust[1];
        return d3.min([hScale, vScale]) * 38 * this.adjust[2];
    };
    return default_1;
}());
exports.default = default_1;
