mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
refactor tilemap for isolated testability
This commit is contained in:
parent
d1cd163c72
commit
323a43debc
1 changed files with 50 additions and 34 deletions
|
@ -36,54 +36,24 @@ define(function (require) {
|
|||
this._chartData = chartData || {};
|
||||
_.assign(this, this._chartData);
|
||||
|
||||
// add allmin and allmax to geoJson
|
||||
var geoMinMax = handler.data.getGeoExtents();
|
||||
this.geoJson.properties.allmin = geoMinMax.min;
|
||||
this.geoJson.properties.allmax = geoMinMax.max;
|
||||
this._appendGeoExtents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders tile map
|
||||
* Draws tile map, called on chart render
|
||||
*
|
||||
* @method draw
|
||||
* @return {Function} - function to add a map to a selection
|
||||
*/
|
||||
TileMap.prototype.draw = function () {
|
||||
var self = this;
|
||||
var mapData = this.geoJson;
|
||||
|
||||
// clean up old maps
|
||||
self.destroy();
|
||||
|
||||
// clear maps array
|
||||
self.maps = [];
|
||||
|
||||
return function (selection) {
|
||||
selection.each(function () {
|
||||
var container = $(this).addClass('tilemap');
|
||||
|
||||
var map = new Map(container, self._chartData, {
|
||||
// center: self._attr.mapCenter,
|
||||
// zoom: self._attr.mapZoom,
|
||||
events: self.events,
|
||||
markerType: self._attr.mapType,
|
||||
tooltipFormatter: self.tooltipFormatter,
|
||||
valueFormatter: self.valueFormatter,
|
||||
attr: self._attr
|
||||
});
|
||||
|
||||
// add title for splits
|
||||
if (self.title) {
|
||||
map.addTitle(self.title);
|
||||
}
|
||||
|
||||
// add fit to bounds control
|
||||
if (mapData && mapData.features.length > 0) {
|
||||
map.addFitControl();
|
||||
map.addBoundingControl();
|
||||
}
|
||||
|
||||
self.maps.push(map);
|
||||
self._appendMap(this);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
@ -108,11 +78,57 @@ define(function (require) {
|
|||
* @return {undefined}
|
||||
*/
|
||||
TileMap.prototype.destroy = function () {
|
||||
this.maps.forEach(function (map) {
|
||||
this.maps = this.maps.filter(function (map) {
|
||||
map.destroy();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds allmin and allmax properties to geoJson data
|
||||
*
|
||||
* @method _appendMap
|
||||
* @param selection {Object} d3 selection
|
||||
*/
|
||||
TileMap.prototype._appendGeoExtents = function () {
|
||||
// add allmin and allmax to geoJson
|
||||
var geoMinMax = this.handler.data.getGeoExtents();
|
||||
this.geoJson.properties.allmin = geoMinMax.min;
|
||||
this.geoJson.properties.allmax = geoMinMax.max;
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders map
|
||||
*
|
||||
* @method _appendMap
|
||||
* @param selection {Object} d3 selection
|
||||
*/
|
||||
TileMap.prototype._appendMap = function (selection) {
|
||||
var container = $(selection).addClass('tilemap');
|
||||
|
||||
var map = new Map(container, this._chartData, {
|
||||
// center: this._attr.mapCenter,
|
||||
// zoom: this._attr.mapZoom,
|
||||
events: this.events,
|
||||
markerType: this._attr.mapType,
|
||||
tooltipFormatter: this.tooltipFormatter,
|
||||
valueFormatter: this.valueFormatter,
|
||||
attr: this._attr
|
||||
});
|
||||
|
||||
// add title for splits
|
||||
if (this.title) {
|
||||
map.addTitle(this.title);
|
||||
}
|
||||
|
||||
// add fit to bounds control
|
||||
if (_.get(this.geoJson, 'features.length') > 0) {
|
||||
map.addFitControl();
|
||||
map.addBoundingControl();
|
||||
}
|
||||
|
||||
this.maps.push(map);
|
||||
};
|
||||
|
||||
return TileMap;
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue