123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- var zrUtil = require("zrender/lib/core/util");
- var BoundingRect = require("zrender/lib/core/BoundingRect");
- var View = require("../View");
- var geoSourceManager = require("./geoSourceManager");
- function Geo(name, map, nameMap, invertLongitute) {
- View.call(this, name);
-
- this.map = map;
- var source = geoSourceManager.load(map, nameMap);
- this._nameCoordMap = source.nameCoordMap;
- this._regionsMap = source.regionsMap;
- this._invertLongitute = invertLongitute == null ? true : invertLongitute;
-
- this.regions = source.regions;
-
- this._rect = source.boundingRect;
- }
- Geo.prototype = {
- constructor: Geo,
- type: 'geo',
-
- dimensions: ['lng', 'lat'],
-
- containCoord: function (coord) {
- var regions = this.regions;
- for (var i = 0; i < regions.length; i++) {
- if (regions[i].contain(coord)) {
- return true;
- }
- }
- return false;
- },
-
- transformTo: function (x, y, width, height) {
- var rect = this.getBoundingRect();
- var invertLongitute = this._invertLongitute;
- rect = rect.clone();
- if (invertLongitute) {
-
- rect.y = -rect.y - rect.height;
- }
- var rawTransformable = this._rawTransformable;
- rawTransformable.transform = rect.calculateTransform(new BoundingRect(x, y, width, height));
- rawTransformable.decomposeTransform();
- if (invertLongitute) {
- var scale = rawTransformable.scale;
- scale[1] = -scale[1];
- }
- rawTransformable.updateTransform();
- this._updateTransform();
- },
-
- getRegion: function (name) {
- return this._regionsMap.get(name);
- },
- getRegionByCoord: function (coord) {
- var regions = this.regions;
- for (var i = 0; i < regions.length; i++) {
- if (regions[i].contain(coord)) {
- return regions[i];
- }
- }
- },
-
- addGeoCoord: function (name, geoCoord) {
- this._nameCoordMap.set(name, geoCoord);
- },
-
- getGeoCoord: function (name) {
- return this._nameCoordMap.get(name);
- },
-
- getBoundingRect: function () {
- return this._rect;
- },
-
- dataToPoint: function (data, noRoam, out) {
- if (typeof data === 'string') {
-
- data = this.getGeoCoord(data);
- }
- if (data) {
- return View.prototype.dataToPoint.call(this, data, noRoam, out);
- }
- },
-
- convertToPixel: zrUtil.curry(doConvert, 'dataToPoint'),
-
- convertFromPixel: zrUtil.curry(doConvert, 'pointToData')
- };
- zrUtil.mixin(Geo, View);
- function doConvert(methodName, ecModel, finder, value) {
- var geoModel = finder.geoModel;
- var seriesModel = finder.seriesModel;
- var coordSys = geoModel ? geoModel.coordinateSystem : seriesModel ? seriesModel.coordinateSystem
- || (seriesModel.getReferringComponents('geo')[0] || {}).coordinateSystem : null;
- return coordSys === this ? coordSys[methodName](value) : null;
- }
- var _default = Geo;
- module.exports = _default;
|