Merge pull request #4044 from w33ble/tilemap-options-reset
Tilemap - Prevent reset zoom/center on option changes
This commit is contained in:
commit
006e6507e5
|
@ -33,7 +33,9 @@ define(function (require) {
|
|||
features: features,
|
||||
properties: {
|
||||
min: _.min(values),
|
||||
max: _.max(values)
|
||||
max: _.max(values),
|
||||
zoom: _.deepGet(geoAgg, 'params.mapZoom'),
|
||||
center: _.deepGet(geoAgg, 'params.mapCenter')
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -34,6 +34,14 @@ define(function (require) {
|
|||
default: true,
|
||||
write: _.noop
|
||||
},
|
||||
{
|
||||
name: 'mapZoom',
|
||||
write: _.noop
|
||||
},
|
||||
{
|
||||
name: 'mapCenter',
|
||||
write: _.noop
|
||||
},
|
||||
{
|
||||
name: 'precision',
|
||||
default: defaultPrecision,
|
||||
|
|
|
@ -86,6 +86,14 @@ define(function (require) {
|
|||
};
|
||||
};
|
||||
|
||||
Vis.prototype.createEditableVis = function () {
|
||||
return this._editableVis || (this._editableVis = this.clone());
|
||||
};
|
||||
|
||||
Vis.prototype.getEditableVis = function () {
|
||||
return this._editableVis || undefined;
|
||||
};
|
||||
|
||||
Vis.prototype.clone = function () {
|
||||
return new Vis(this.indexPattern, this.getState());
|
||||
};
|
||||
|
|
|
@ -5,13 +5,11 @@ define(function (require) {
|
|||
var L = require('leaflet');
|
||||
require('leaflet-heat');
|
||||
require('leaflet-draw');
|
||||
|
||||
var Chart = Private(require('components/vislib/visualizations/_chart'));
|
||||
|
||||
require('css!components/vislib/styles/main');
|
||||
|
||||
var defaultMapCenter = [15, 5];
|
||||
var Chart = Private(require('components/vislib/visualizations/_chart'));
|
||||
var defaultMapZoom = 2;
|
||||
var defaultMapCenter = [15, 5];
|
||||
|
||||
// Convenience function to turn around the LngLat recieved from ES
|
||||
function cloneAndReverse(arr) {
|
||||
|
@ -37,11 +35,15 @@ define(function (require) {
|
|||
|
||||
TileMap.Super.apply(this, arguments);
|
||||
|
||||
|
||||
// track the map objects
|
||||
this.maps = [];
|
||||
this.originalConfig = chartData || {};
|
||||
_.assign(this, this.originalConfig);
|
||||
|
||||
this._attr.mapZoom = _.deepGet(this.geoJson, 'properties.zoom') || defaultMapZoom;
|
||||
this._attr.mapCenter = _.deepGet(this.geoJson, 'properties.center') || defaultMapCenter;
|
||||
|
||||
// add allmin and allmax to geoJson
|
||||
var allMinMax = this.getMinMax(handler.data.data);
|
||||
this.geoJson.properties.allmin = allMinMax.min;
|
||||
|
@ -68,9 +70,6 @@ define(function (require) {
|
|||
var worldBounds = L.latLngBounds([-90, -220], [90, 220]);
|
||||
|
||||
return function (selection) {
|
||||
self._attr.mapZoom = self._attr.mapZoom || defaultMapZoom;
|
||||
self._attr.mapCenter = self._attr.mapCenter || defaultMapCenter;
|
||||
|
||||
selection.each(function () {
|
||||
// add leaflet latLngs to properties for tooltip
|
||||
self.addLatLng(self.geoJson);
|
||||
|
@ -130,6 +129,12 @@ define(function (require) {
|
|||
self._attr.mapZoom = map.getZoom();
|
||||
self._attr.mapCenter = map.getCenter();
|
||||
|
||||
self.events.emit('mapMoveEnd', {
|
||||
chart: self.originalConfig,
|
||||
zoom: self._attr.mapZoom,
|
||||
center: self._attr.mapCenter
|
||||
});
|
||||
|
||||
map.removeLayer(featureLayer);
|
||||
|
||||
featureLayer = self.markerType(map).addTo(map);
|
||||
|
|
|
@ -40,6 +40,22 @@ define(function (require) {
|
|||
|
||||
pushFilter(filter, false, indexPatternName);
|
||||
},
|
||||
mapMoveEnd: function (event) {
|
||||
var agg = _.deepGet(event, 'chart.geohashGridAgg');
|
||||
if (!agg) return;
|
||||
|
||||
agg.params.mapZoom = event.zoom;
|
||||
agg.params.mapCenter = [event.center.lat, event.center.lng];
|
||||
|
||||
var editableVis = agg.vis.getEditableVis();
|
||||
if (!editableVis) return;
|
||||
|
||||
var editableAgg = editableVis.aggs.byId[agg.id];
|
||||
if (editableAgg) {
|
||||
editableAgg.params.mapZoom = event.zoom;
|
||||
editableAgg.params.mapCenter = [event.center.lat, event.center.lng];
|
||||
}
|
||||
},
|
||||
mapZoomEnd: function (event) {
|
||||
var agg = _.deepGet(event, 'chart.geohashGridAgg');
|
||||
if (!agg || !agg.params.autoPrecision) return;
|
||||
|
|
|
@ -68,7 +68,7 @@ define(function (require) {
|
|||
var savedVis = $route.current.locals.savedVis;
|
||||
|
||||
var vis = savedVis.vis;
|
||||
var editableVis = vis.clone();
|
||||
var editableVis = vis.createEditableVis();
|
||||
vis.requesting = function () {
|
||||
var requesting = editableVis.requesting;
|
||||
requesting.call(vis);
|
||||
|
|
|
@ -86,7 +86,7 @@ define(function (require) {
|
|||
|
||||
// props
|
||||
expect(props).to.be.an('object');
|
||||
expect(props).to.only.have.keys('min', 'max');
|
||||
expect(props).to.have.keys('min', 'max');
|
||||
|
||||
// props.min
|
||||
expect(props.min).to.be.a('number');
|
||||
|
|
|
@ -1839,7 +1839,9 @@ define(function (require) {
|
|||
],
|
||||
'properties': {
|
||||
'min': 1,
|
||||
'max': 608
|
||||
'max': 608,
|
||||
'zoom': 2,
|
||||
'center': [5, 15]
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -25,7 +25,6 @@ define(function (require) {
|
|||
mapType: type
|
||||
};
|
||||
|
||||
|
||||
module('TileMapFactory');
|
||||
inject(function (Private) {
|
||||
vis = Private(require('vislib_fixtures/_vis_fixture'))(visLibParams);
|
||||
|
|
Loading…
Reference in a new issue