Skip to content

Commit

Permalink
[Maps] prepare for geotile_grid aggregation (elastic#29461) (elastic#…
Browse files Browse the repository at this point in the history
…29485)

* rename geohashgrid to geo_grid

* more stuff

* simplify getSearchFitlers

* rename precision to geogridPrecision

* missed one rename precision to geogridPrecision

* rename funtional test

* fix functional test gis/index import

* fix regression
  • Loading branch information
nreese authored Jan 29, 2019
1 parent 2ffd2db commit 8ba8772
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 80 deletions.
14 changes: 6 additions & 8 deletions x-pack/plugins/gis/public/shared/layers/heatmap_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import React from 'react';
import { AbstractLayer } from './layer';
import { EuiIcon } from '@elastic/eui';
import { HeatmapStyle } from './styles/heatmap_style';
import { getGeohashPrecisionForZoom } from '../utils/zoom_to_precision';

const SCALED_PROPERTY_NAME = '__kbn_heatmap_weight__';//unique name to store scaled value for weighting

Expand Down Expand Up @@ -114,9 +113,8 @@ export class HeatmapLayer extends AbstractLayer {
const sourceDataRequest = this.getSourceDataRequest();
const dataMeta = sourceDataRequest ? sourceDataRequest.getMeta() : {};

const targetPrecisionUnadjusted = getGeohashPrecisionForZoom(dataFilters.zoom);
const targetPrecision = targetPrecisionUnadjusted + this._source.getGeohashPrecisionResolutionDelta();
const isSamePrecision = dataMeta.precision === targetPrecision;
const geogridPrecision = this._source.getGeoGridPrecision(dataFilters.zoom);
const isSamePrecision = dataMeta.geogridPrecision === geogridPrecision;

const isSameTime = _.isEqual(dataMeta.timeFilters, dataFilters.timeFilters);

Expand All @@ -143,21 +141,21 @@ export class HeatmapLayer extends AbstractLayer {

const newDataMeta = {
...dataFilters,
precision: targetPrecision,
geogridPrecision,
metric: metricPropertyKey
};
await this._fetchNewData({ startLoading, stopLoading, onLoadError, dataMeta: newDataMeta });
}

async _fetchNewData({ startLoading, stopLoading, onLoadError, dataMeta }) {
const { precision: geohashPrecision, timeFilters, buffer, query } = dataMeta;
const { geogridPrecision, timeFilters, buffer, query } = dataMeta;
const requestToken = Symbol(`layer-source-refresh: this.getId()`);
startLoading('source', requestToken, dataMeta);
try {
const layerName = await this.getDisplayName();
const data = await this._source.getGeoJsonPoints({ layerName }, {
geohashPrecision: geohashPrecision,
buffer: buffer,
geogridPrecision,
buffer,
timeFilters,
query,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { XYZTMSSource } from './xyz_tms_source';
import { EMSTMSSource } from './ems_tms_source';
import { WMSSource } from './wms_source';
import { KibanaTilemapSource } from './kibana_tilemap_source';
import { ESGeohashGridSource } from './es_geohashgrid_source';
import { ESGeoGridSource } from './es_geo_grid_source';
import { ESSearchSource } from './es_search_source';


export const ALL_SOURCES = [
ESSearchSource,
ESGeohashGridSource,
ESGeoGridSource,
EMSFileSource,
EMSTMSSource,
KibanaRegionmapSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export function convertToGeoJson(tabifiedResponse) {
meta: {
min: min,
max: max,
geohashPrecision: geoAgg && geoAgg.params.precision,
geohashGridDimensionsAtEquator: geoAgg && gridDimensions(geoAgg.params.precision)
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { RENDER_AS } from './render_as';
import { CreateSourceEditor } from './create_source_editor';
import { UpdateSourceEditor } from './update_source_editor';
import { GRID_RESOLUTION } from '../../grid_resolution';
import { getGeohashPrecisionForZoom } from './zoom_to_precision';

const COUNT_PROP_LABEL = 'Count';
const COUNT_PROP_NAME = 'doc_count';
Expand All @@ -48,15 +49,15 @@ const aggSchemas = new Schemas([
}
]);

export class ESGeohashGridSource extends AbstractESSource {
export class ESGeoGridSource extends AbstractESSource {

static type = 'ES_GEOHASH_GRID';
static title = 'Elasticsearch geohash aggregation';
static type = 'ES_GEO_GRID';
static title = 'Elasticsearch grid aggregation';
static description = 'Group geospatial data in grids with metrics for each gridded cell';

static createDescriptor({ indexPatternId, geoField, requestType, resolution }) {
return {
type: ESGeohashGridSource.type,
type: ESGeoGridSource.type,
id: uuid(),
indexPatternId: indexPatternId,
geoField: geoField,
Expand All @@ -67,8 +68,8 @@ export class ESGeohashGridSource extends AbstractESSource {

static renderEditor({ onPreviewSource }) {
const onSelect = (sourceConfig) => {
const sourceDescriptor = ESGeohashGridSource.createDescriptor(sourceConfig);
const source = new ESGeohashGridSource(sourceDescriptor);
const sourceDescriptor = ESGeoGridSource.createDescriptor(sourceConfig);
const source = new ESGeoGridSource(sourceDescriptor);
onPreviewSource(source);
};

Expand All @@ -93,7 +94,7 @@ export class ESGeohashGridSource extends AbstractESSource {
source={this}
geoField={this._descriptor.geoField}
geoFieldType="Point field"
sourceType={ESGeohashGridSource.typeDisplayName}
sourceType={ESGeoGridSource.typeDisplayName}
/>
);
}
Expand All @@ -104,32 +105,38 @@ export class ESGeohashGridSource extends AbstractESSource {
});
}

isGeohashPrecisionAware() {
isGeoGridPrecisionAware() {
return true;
}

getGridResolution() {
return this._descriptor.resolution;
}

getGeohashPrecisionResolutionDelta() {
let refinementFactor;
getGeoGridPrecision(zoom) {
return getGeohashPrecisionForZoom(zoom) + this._getGeoGridPrecisionResolutionDelta();
}

_getGeoGridPrecisionResolutionDelta() {
if (this._descriptor.resolution === GRID_RESOLUTION.COARSE) {
refinementFactor = 0;
} else if (this._descriptor.resolution === GRID_RESOLUTION.FINE) {
refinementFactor = 1;
} else if (this._descriptor.resolution === GRID_RESOLUTION.MOST_FINE) {
refinementFactor = 2;
} else {
throw new Error(`Resolution param not recognized: ${this._descriptor.resolution}`);
return 0;
}

if (this._descriptor.resolution === GRID_RESOLUTION.FINE) {
return 1;
}
return refinementFactor;

if (this._descriptor.resolution === GRID_RESOLUTION.MOST_FINE) {
return 2;
}

throw new Error(`Grid resolution param not recognized: ${this._descriptor.resolution}`);
}

async getGeoJsonWithMeta({ layerName }, searchFilters) {

const featureCollection = await this.getGeoJsonPoints({ layerName }, {
geohashPrecision: searchFilters.geohashPrecision,
geogridPrecision: searchFilters.geogridPrecision,
buffer: searchFilters.buffer,
timeFilters: searchFilters.timeFilters,
query: searchFilters.query,
Expand Down Expand Up @@ -157,11 +164,11 @@ export class ESGeohashGridSource extends AbstractESSource {
}


async getGeoJsonPoints({ layerName }, { geohashPrecision, buffer, timeFilters, query }) {
async getGeoJsonPoints({ layerName }, { geogridPrecision, buffer, timeFilters, query }) {

const indexPattern = await this._getIndexPattern();
const searchSource = await this._makeSearchSource({ buffer, timeFilters, query }, 0);
const aggConfigs = new AggConfigs(indexPattern, this._makeAggConfigs(geohashPrecision), aggSchemas.all);
const aggConfigs = new AggConfigs(indexPattern, this._makeAggConfigs(geogridPrecision), aggSchemas.all);
searchSource.setField('aggs', aggConfigs.toDsl());
const esResponse = await this._runEsQuery(layerName, searchSource, 'Elasticsearch geohash_grid aggregation request');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { ESGeohashGridSource } from './es_geohashgrid_source';
export { ESGeoGridSource } from './es_geo_grid_source';
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { getGeohashPrecisionForZoom } from './zoom_to_precision';

it('getGeohashPrecisionForZoom', () => {
expect(getGeohashPrecisionForZoom(-1)).toEqual(1);
expect(getGeohashPrecisionForZoom(40)).toEqual(12);
expect(getGeohashPrecisionForZoom(20)).toEqual(9);
expect(getGeohashPrecisionForZoom(19)).toEqual(9);
});
6 changes: 5 additions & 1 deletion x-pack/plugins/gis/public/shared/layers/sources/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class AbstractSource {
return false;
}

isGeohashPrecisionAware() {
isGeoGridPrecisionAware() {
return false;
}

Expand All @@ -83,6 +83,10 @@ export class AbstractSource {
getIndexPatternIds() {
return [];
}

getGeoGridPrecision() {
return 0;
}
}


20 changes: 5 additions & 15 deletions x-pack/plugins/gis/public/shared/layers/vector_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { FeatureTooltip } from 'plugins/gis/components/map/feature_tooltip';
import { store } from '../../store/store';
import { getMapColors } from '../../selectors/map_selectors';
import _ from 'lodash';
import { getGeohashPrecisionForZoom } from '../utils/zoom_to_precision';

const EMPTY_FEATURE_COLLECTION = {
type: 'FeatureCollection',
Expand Down Expand Up @@ -170,15 +169,15 @@ export class VectorLayer extends AbstractLayer {
const extentAware = source.isFilterByMapBounds();
const isFieldAware = source.isFieldAware();
const isQueryAware = source.isQueryAware();
const isGeohashPrecisionAware = source.isGeohashPrecisionAware();
const isGeoGridPrecisionAware = source.isGeoGridPrecisionAware();

if (
!timeAware &&
!refreshTimerAware &&
!extentAware &&
!isFieldAware &&
!isQueryAware &&
!isGeohashPrecisionAware
!isGeoGridPrecisionAware
) {
const sourceDataRequest = this._findDataRequestForSource(sourceDataId);
if (sourceDataRequest && sourceDataRequest.hasDataOrRequestInProgress()) {
Expand Down Expand Up @@ -217,8 +216,8 @@ export class VectorLayer extends AbstractLayer {
}

let updateDueToPrecisionChange = false;
if (isGeohashPrecisionAware) {
updateDueToPrecisionChange = !_.isEqual(meta.geohashPrecision, searchFilters.geohashPrecision);
if (isGeoGridPrecisionAware) {
updateDueToPrecisionChange = !_.isEqual(meta.geogridPrecision, searchFilters.geogridPrecision);
}

const updateDueToExtentChange = this.updateDueToExtent(source, meta, searchFilters);
Expand All @@ -231,10 +230,6 @@ export class VectorLayer extends AbstractLayer {
&& !updateDueToPrecisionChange;
}

_getTargetGeohashPrecision(precision) {
return this._source.getGeohashPrecisionResolutionDelta() + precision;
}

async _syncJoin(join, { startLoading, stopLoading, onLoadError, dataFilters }) {

const joinSource = join.getJoinSource();
Expand Down Expand Up @@ -288,15 +283,10 @@ export class VectorLayer extends AbstractLayer {
})
];

let targetPrecision = getGeohashPrecisionForZoom(dataFilters.zoom);

if (this._source.isGeohashPrecisionAware()) {
targetPrecision = this._getTargetGeohashPrecision(targetPrecision);
}
return {
...dataFilters,
fieldNames: _.uniq(fieldNames).sort(),
geohashPrecision: targetPrecision
geogridPrecision: this._source.getGeoGridPrecision(dataFilters.zoom),
};
}

Expand Down
26 changes: 0 additions & 26 deletions x-pack/plugins/gis/public/shared/utils/zoom_to_precision.test.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"title" : "[Logs] Web Traffic",
"description" : "",
"mapStateJSON" : "{\"zoom\":3.92,\"center\":{\"lon\":-83.95443,\"lat\":38.02463},\"timeFilters\":{\"from\":\"now-7d\",\"to\":\"now\"}}",
"layerListJSON" : "[{\"id\":\"0hmz5\",\"sourceDescriptor\":{\"type\":\"EMS_TMS\",\"id\":\"road_map\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"TILE\",\"properties\":{\"alphaValue\":1}},\"type\":\"TILE\",\"alpha\":1,\"minZoom\":0,\"maxZoom\":24},{\"id\":\"ajk2l\",\"label\":\"logs(heatmap)\",\"alpha\":1,\"minZoom\":0,\"maxZoom\":9,\"sourceDescriptor\":{\"resolution\": \"COARSE\", \"type\":\"ES_GEOHASH_GRID\",\"id\":\"60c5dffb-7fca-431c-b1f0-9cc2e6697e8c\",\"indexPatternId\":\"90943e30-9a47-11e8-b64d-95841ca0b247\",\"geoField\":\"geo.coordinates\",\"requestType\":\"heatmap\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"HEATMAP\",\"refinement\":\"coarse\",\"properties\":{\"alphaValue\":0.75},\"previousStyle\":null},\"type\":\"HEATMAP\"},{\"id\":\"6hgh2\",\"label\":\"logs(documents)\",\"alpha\":1,\"minZoom\":7,\"maxZoom\":24,\"sourceDescriptor\":{\"id\":\"541f2ca1-6a0f-4937-8846-a589222b7f28\",\"type\":\"ES_SEARCH\",\"indexPatternId\":\"90943e30-9a47-11e8-b64d-95841ca0b247\",\"geoField\":\"geo.coordinates\",\"limit\":2048,\"filterByMapBounds\":true,\"showTooltip\":true,\"tooltipProperties\":[\"timestamp\",\"clientip\",\"url\"]},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#e6194b\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}},\"alphaValue\":0.75},\"previousStyle\":null},\"type\":\"VECTOR\"}]",
"layerListJSON" : "[{\"id\":\"0hmz5\",\"sourceDescriptor\":{\"type\":\"EMS_TMS\",\"id\":\"road_map\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"TILE\",\"properties\":{\"alphaValue\":1}},\"type\":\"TILE\",\"alpha\":1,\"minZoom\":0,\"maxZoom\":24},{\"id\":\"ajk2l\",\"label\":\"logs(heatmap)\",\"alpha\":1,\"minZoom\":0,\"maxZoom\":9,\"sourceDescriptor\":{\"resolution\": \"COARSE\", \"type\":\"ES_GEO_GRID\",\"id\":\"60c5dffb-7fca-431c-b1f0-9cc2e6697e8c\",\"indexPatternId\":\"90943e30-9a47-11e8-b64d-95841ca0b247\",\"geoField\":\"geo.coordinates\",\"requestType\":\"heatmap\"},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"HEATMAP\",\"refinement\":\"coarse\",\"properties\":{\"alphaValue\":0.75},\"previousStyle\":null},\"type\":\"HEATMAP\"},{\"id\":\"6hgh2\",\"label\":\"logs(documents)\",\"alpha\":1,\"minZoom\":7,\"maxZoom\":24,\"sourceDescriptor\":{\"id\":\"541f2ca1-6a0f-4937-8846-a589222b7f28\",\"type\":\"ES_SEARCH\",\"indexPatternId\":\"90943e30-9a47-11e8-b64d-95841ca0b247\",\"geoField\":\"geo.coordinates\",\"limit\":2048,\"filterByMapBounds\":true,\"showTooltip\":true,\"tooltipProperties\":[\"timestamp\",\"clientip\",\"url\"]},\"visible\":true,\"temporary\":false,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#e6194b\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}},\"alphaValue\":0.75},\"previousStyle\":null},\"type\":\"VECTOR\"}]",
"uiStateJSON" : "{\"isDarkMode\":false}",
"bounds" : {
"type" : "envelope",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function ({ getPageObjects, getService }) {
const inspector = getService('inspector');
const DOC_COUNT_PROP_NAME = 'doc_count';

describe('layer geohashgrid aggregation source', () => {
describe('layer geo grid aggregation source', () => {

const EXPECTED_NUMBER_FEATURES = 6;
const DATA_CENTER_LON = -98;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/gis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function ({ loadTestFile, getService }) {
loadTestFile(require.resolve('./saved_object_management'));
loadTestFile(require.resolve('./sample_data'));
loadTestFile(require.resolve('./es_search_source'));
loadTestFile(require.resolve('./es_geohashgrid_source'));
loadTestFile(require.resolve('./es_geo_grid_source'));
loadTestFile(require.resolve('./joins'));
});
}
Loading

0 comments on commit 8ba8772

Please sign in to comment.