Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/map zoom #6835

Merged
merged 14 commits into from
May 27, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 46 additions & 29 deletions src/plugins/kbn_vislib_vis_types/public/tile_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@ export default function TileMapVisType(Private, getAppState, courier, config) {
const Schemas = Private(VisSchemasProvider);
const geoJsonConverter = Private(AggResponseGeoJsonGeoJsonProvider);

// zoomPrecision maps event.zoom to a geohash precision value
// event.limit is the configurable max geohash precision
// default max precision is 7, configurable up to 12
const zoomPrecision = {
1: 2,
2: 2,
3: 2,
4: 3,
5: 3,
6: 4,
7: 4,
8: 5,
9: 5,
10: 6,
11: 6,
12: 7,
13: 7,
14: 8,
15: 9,
16: 10,
17: 11,
18: 12
};

return new VislibVisType({
name: 'tile_map',
title: 'Tile map',
Expand All @@ -27,6 +51,8 @@ export default function TileMapVisType(Private, getAppState, courier, config) {
heatRadius: 25,
heatBlur: 15,
heatNormalizeData: true,
mapZoom: 2,
mapCenter: [15, 5],
wms: config.get('visualization:tileMap:WMSdefaults')
},
mapTypes: ['Scaled Circle Markers', 'Shaded Circle Markers', 'Shaded Geohash Grid', 'Heatmap'],
Expand All @@ -46,49 +72,40 @@ export default function TileMapVisType(Private, getAppState, courier, config) {

pushFilter(filter, false, indexPatternName);
},
mapMoveEnd: function (event) {
mapMoveEnd: function (event, uiState) {
const mapPrecision = zoomPrecision[event.zoom];
uiState.set('vis.params.mapCenter', event.center);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why vis.params? these can just be 'mapCenter', 'mapZoom', and 'mapPrecision' I think. Otherwise it's confusing.

uiState.set('vis.params.mapZoom', event.zoom);
uiState.set('vis.params.mapPrecision', mapPrecision);

const agg = _.get(event, 'chart.geohashGridAgg');
Copy link
Contributor

@w33ble w33ble May 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just _.get(event, 'chart.geohashGridAgg.params.autoPrecision') here? It's safer and easier to understand because it's the only parameter you are using.

As it is, if agg.params is undefined, this will error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change.

if (!agg) return;

agg.params.mapZoom = event.zoom;
agg.params.mapCenter = [event.center.lat, event.center.lng];
agg.params.mapCenter = event.center;

const editableVis = agg.vis.getEditableVis();
if (!editableVis) return;

// editableVis.params.mapCenter = event.center;
// editableVis.params.mapZoom = event.zoom;

const editableAgg = editableVis.aggs.byId[agg.id];
if (editableAgg) {
editableAgg.params.mapZoom = event.zoom;
editableAgg.params.mapCenter = [event.center.lat, event.center.lng];
editableAgg.params.mapCenter = event.center;
editableAgg.params.mapPrecision = mapPrecision;
}
},
mapZoomEnd: function (event) {
mapZoomEnd: function (event, uiState) {
const agg = _.get(event, 'chart.geohashGridAgg');
if (!agg || !agg.params.autoPrecision) return;
const mapPrecision = zoomPrecision[event.zoom];
uiState.set('vis.params.mapZoom', event.zoom);
uiState.set('vis.params.mapPrecision', mapPrecision);

// zoomPrecision maps event.zoom to a geohash precision value
// event.limit is the configurable max geohash precision
// default max precision is 7, configurable up to 12
const zoomPrecision = {
1: 2,
2: 2,
3: 2,
4: 3,
5: 3,
6: 4,
7: 4,
8: 5,
9: 5,
10: 6,
11: 6,
12: 7,
13: 7,
14: 8,
15: 9,
16: 10,
17: 11,
18: 12
};
if (!agg) return;
agg.params.mapZoom = event.zoom;

if (!agg || !agg.params.autoPrecision) return;

const precision = config.get('visualization:tileMap:maxPrecision');
agg.params.precision = Math.min(zoomPrecision[event.zoom], precision);
Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana/public/visualize/editor/agg.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ uiModules
template: aggTemplate,
require: 'form',
link: function ($scope, $el, attrs, kbnForm) {
$scope.$bind('outputAgg', 'outputVis.aggs.byId[agg.id]', $scope);
$scope.editorOpen = !!$scope.agg.brandNew;

$scope.$watch('editorOpen', function (open) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/kibana/public/visualize/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ uiModules
$scope.indexPattern = vis.indexPattern;
$scope.editableVis = editableVis;
$scope.state = $state;
$scope.uiState = $state.makeStateful('uiState');
$scope.uiState = vis.uiState = $state.makeStateful('uiState');
$scope.timefilter = timefilter;
$scope.opts = _.pick($scope, 'doSave', 'savedVis', 'shareData', 'timefilter');

Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana/public/visualize/editor/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ uiModules
controllerAs: 'sidebar',
controller: function ($scope) {
$scope.$bind('vis', 'editableVis');
$scope.$bind('outputVis', 'vis');
$scope.$watch('vis.type', (visType) => {
if (visType) {
this.showData = visType.schemas.buckets || visType.schemas.metrics;
Expand Down
38 changes: 30 additions & 8 deletions src/ui/public/agg_types/buckets/geo_hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ export default function GeoHashAggDefinition(Private, config) {
var BucketAggType = Private(AggTypesBucketsBucketAggTypeProvider);
var defaultPrecision = 2;

// zoomPrecision maps event.zoom to a geohash precision value
// event.limit is the configurable max geohash precision
// default max precision is 7, configurable up to 12
const zoomPrecision = {
1: 2,
2: 2,
3: 2,
4: 3,
5: 3,
6: 4,
7: 4,
8: 5,
9: 5,
10: 6,
11: 6,
12: 7,
13: 7,
14: 8,
15: 9,
16: 10,
17: 11,
18: 12
};

function getPrecision(precision) {
var maxPrecision = _.parseInt(config.get('visualization:tileMap:maxPrecision'));

Expand Down Expand Up @@ -45,19 +69,17 @@ export default function GeoHashAggDefinition(Private, config) {
},
{
name: 'precision',
default: defaultPrecision,
editor: precisionTemplate,
controller: function ($scope) {
$scope.$watchMulti([
'agg.params.autoPrecision',
'outputAgg.params.precision'
], function (cur, prev) {
if (cur[1]) $scope.agg.params.precision = cur[1];
});
},
deserialize: getPrecision,
write: function (aggConfig, output) {
output.params.precision = getPrecision(aggConfig.params.precision);
let currZoom = aggConfig.vis.params.mapZoom;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of this function. I have to figure out whether the aggConfig, vis, or uiState has the proper zoom, to base the precision off of. This happens differently whether you load up the dashboard with the same vis, refresh on the vis page, or set it by zooming or panning on the map

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the proper solution is to fix the dashboard and ensure the vis gets it uiState on the dashboard.

if (aggConfig.params.mapZoom || aggConfig.vis.uiState) { // First iteration
currZoom = aggConfig.vis.uiState ? aggConfig.vis.uiState.get('vis.params.mapZoom') : aggConfig.params.mapZoom;
}
const autoPrecisionVal = zoomPrecision[currZoom];
output.params.precision = aggConfig.params.autoPrecision ? autoPrecisionVal : getPrecision(aggConfig.params.precision);
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/vislib/lib/handler/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function HandlerBaseClass(Private) {
this.getProxyHandler = _.memoize(function (event) {
var self = this;
return function (e) {
self.vis.emit(event, e);
self.vis.emit(event, e, vis.uiState);
};
});
}
Expand Down
9 changes: 4 additions & 5 deletions src/ui/public/vislib/visualizations/_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export default function MapFactory(Private) {
this._valueFormatter = params.valueFormatter || _.identity;
this._tooltipFormatter = params.tooltipFormatter || _.identity;
this._geoJson = _.get(this._chartData, 'geoJson');
this._mapZoom = params.zoom || defaultMapZoom;
this._mapCenter = params.center || defaultMapCenter;
this._attr = params.attr || {};

var mapOptions = {
Expand Down Expand Up @@ -211,7 +213,8 @@ export default function MapFactory(Private) {
this.map.on('moveend', function setZoomCenter(ev) {
if (!self.map) return;
// update internal center and zoom references
self._mapCenter = self.map.getCenter();
const uglyCenter = self.map.getCenter();
self._mapCenter = [uglyCenter.lat, uglyCenter.lng];
self._mapZoom = self.map.getZoom();
self._addMarkers();

Expand Down Expand Up @@ -264,10 +267,6 @@ export default function MapFactory(Private) {
TileMapMap.prototype._createMap = function (mapOptions) {
if (this.map) this.destroy();

// get center and zoom from mapdata, or use defaults
this._mapCenter = _.get(this._geoJson, 'properties.center') || defaultMapCenter;
this._mapZoom = _.get(this._geoJson, 'properties.zoom') || defaultMapZoom;

// add map tiles layer, using the mapTiles object settings
if (this._attr.wms && this._attr.wms.enabled) {
this._tileLayer = L.tileLayer.wms(this._attr.wms.url, this._attr.wms.options);
Expand Down
13 changes: 11 additions & 2 deletions src/ui/public/vislib/visualizations/tile_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,19 @@ export default function TileMapFactory(Private) {
*/
TileMap.prototype._appendMap = function (selection) {
var container = $(selection).addClass('tilemap');
// Lol couldn't think of another way to access this object...
const uiStateParams = {
mapCenter: this.handler.vis.uiState.get('vis.params.mapCenter'),
mapZoom: this.handler.vis.uiState.get('vis.params.mapZoom')
};

const params = _.assign({}, this._chartData.geohashGridAgg.vis.params, uiStateParams);

// this.handler.vis.uiState

var map = new TileMapMap(container, this._chartData, {
// center: this._attr.mapCenter,
// zoom: this._attr.mapZoom,
center: params.mapCenter,
zoom: params.mapZoom,
events: this.events,
markerType: this._attr.mapType,
tooltipFormatter: this.tooltipFormatter,
Expand Down