diff --git a/public/utils.js b/public/utils.js index 90577b2..b63a337 100644 --- a/public/utils.js +++ b/public/utils.js @@ -38,6 +38,12 @@ define(function (require) { } return { + getGeoExtents: function(visData) { + return { + min: visData.geoJson.properties.min, + max: visData.geoJson.properties.max + } + }, /* * @param bounds {LatLngBounds} * @param scale {number} diff --git a/public/visController.js b/public/visController.js index 3a9bb7e..06dccba 100644 --- a/public/visController.js +++ b/public/visController.js @@ -24,6 +24,7 @@ define(function (require) { const ResizeChecker = Private(require('ui/vislib/lib/resize_checker')); let map = null; let collar = null; + let chartData = null; appendMap(); modifyToDsl(); @@ -46,8 +47,13 @@ define(function (require) { } }); console.log("geogrids: " + numGeoBuckets); - if(numGeoBuckets === 0) return; - return this.buildChartData(resp); + if(numGeoBuckets === 0) return null; + + const chartData = this.buildChartData(resp); + const geoMinMax = utils.getGeoExtents(chartData); + chartData.geoJson.properties.allmin = geoMinMax.min; + chartData.geoJson.properties.allmax = geoMinMax.max; + return chartData; }, vis: $scope.vis } @@ -83,42 +89,21 @@ define(function (require) { return filter; } - function getGeoExtents(visData) { - return { - min: visData.geoJson.properties.min, - max: visData.geoJson.properties.max + $scope.$watch('vis.aggs', function (resp) { + //'apply changes' creates new vis.aggs object - ensure toDsl is overwritten again + if(!_.has($scope.vis.aggs, "origToDsl")) { + modifyToDsl(); } - } + }); + + $scope.$watch('vis.params', function (resp) { + draw(); + }); $scope.$watch('esResponse', function (resp) { if(_.has(resp, 'aggregations')) { - /* - * 'apply changes' creates new vis.aggs object - * Modify toDsl function and refetch data. - */ - if(!_.has($scope.vis.aggs, "origToDsl")) { - modifyToDsl(); - courier.fetch(); - return; - } - const chartData = respProcessor.process(resp); - if(!chartData) return; - const geoMinMax = getGeoExtents(chartData); - chartData.geoJson.properties.allmin = geoMinMax.min; - chartData.geoJson.properties.allmax = geoMinMax.max; - const agg = _.get(chartData, 'geohashGridAgg'); - if (agg) { - map.addFilters(getGeoFilters(agg.fieldName())); - } - if (_.get($scope.vis.params, 'overlay.wms.enabled')) { - addWmsOverlays(); - } - map.addMarkers( - chartData, - $scope.vis.params, - Private(require('ui/agg_response/geo_json/_tooltip_formatter')), - _.get(chartData, 'valueFormatter', _.identity), - collar); + chartData = respProcessor.process(resp); + draw(); } }); @@ -128,6 +113,23 @@ define(function (require) { if (map) map.destroy(); }); + function draw() { + if(!chartData) return; + const agg = _.get(chartData, 'geohashGridAgg'); + if (agg) { + map.addFilters(getGeoFilters(agg.fieldName())); + } + if (_.get($scope.vis.params, 'overlay.wms.enabled')) { + addWmsOverlays(); + } + map.addMarkers( + chartData, + $scope.vis.params, + Private(require('ui/agg_response/geo_json/_tooltip_formatter')), + _.get(chartData, 'valueFormatter', _.identity), + collar); + } + function getGeoFilters(field) { let filters = []; _.flatten([queryFilter.getAppFilters(), queryFilter.getGlobalFilters()]).forEach(function (it) {