From 7a445423d9f937628cf5d6c5e5842b1a4b7da13f Mon Sep 17 00:00:00 2001 From: Joongho Date: Tue, 21 Jul 2015 12:37:04 -0700 Subject: [PATCH] better map auto fit option / icon betterMap automatically fit when data is reloaded but, sometimes don't want to be fit So, add option for that, and add icon head panel for manual fitting. --- src/app/directives/kibanaPanel.js | 4 ++++ src/app/panels/bettermap/editor.html | 21 +++++++++++++++++++++ src/app/panels/bettermap/module.js | 22 ++++++++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/app/directives/kibanaPanel.js b/src/app/directives/kibanaPanel.js index 08affd648..d6393fdde 100755 --- a/src/app/directives/kibanaPanel.js +++ b/src/app/directives/kibanaPanel.js @@ -49,6 +49,10 @@ function (angular) { 'class="fa fa-info-circle pointer" bs-tooltip data-title="{{task.description}}" container="body" >'+ '' + + '' + + ''+ + '' + // bettermap fitBound action + '' + '' + '' + diff --git a/src/app/panels/bettermap/editor.html b/src/app/panels/bettermap/editor.html index c547a0577..7e9784196 100755 --- a/src/app/panels/bettermap/editor.html +++ b/src/app/panels/bettermap/editor.html @@ -44,4 +44,25 @@
Ending Longitude
+ + +
+
+
+
Auto fitbounds
+ +
+
+
+
+
Default Latitude if not exists
+ +
+
+
+
+
Default Longitude if not exists
+ +
+
\ No newline at end of file diff --git a/src/app/panels/bettermap/module.js b/src/app/panels/bettermap/module.js index 9eb05648f..085f6f01b 100755 --- a/src/app/panels/bettermap/module.js +++ b/src/app/panels/bettermap/module.js @@ -24,6 +24,7 @@ function (angular, app, _, L, localRequire) { 'use strict'; var DEBUG = false; // DEBUG mode + var fitBoundsFlag = true; // flag for done fitbounds or not var module = angular.module('kibana.panels.bettermap', []); app.useModule(module); @@ -65,6 +66,9 @@ function (angular, app, _, L, localRequire) { // tooltip : "_id", field : null, show_queries:true, + fitBoundsAuto : true, + lat_empty: 0, + lon_empty: 0, }; _.defaults($scope.panel, _d); @@ -91,6 +95,11 @@ function (angular, app, _, L, localRequire) { $scope.refresh = false; }; + $scope.fitBounds = function () { + fitBoundsFlag = true; + $scope.$emit('draw'); + }; + $scope.get_data = function(segment,query_id) { $scope.require(['./leaflet/plugins'], function () { $scope.panel.error = false; @@ -186,7 +195,13 @@ function (angular, app, _, L, localRequire) { if($scope.query_id === query_id) { // Keep only what we need for the set $scope.data = $scope.data.slice(0,$scope.panel.size).concat(_.map(results.response.docs, function(hit) { - var latlon = hit[$scope.panel.field].split(','); + var latlon; + if( hit[$scope.panel.field]) { + latlon = hit[$scope.panel.field].split(','); + } else { + latlon = [$scope.panel.lat_empty, $scope.panel.lon_empty]; + } + return { coordinates : new L.LatLng(latlon[0],latlon[1]), tooltip : hit[$scope.panel.tooltip] @@ -270,7 +285,10 @@ function (angular, app, _, L, localRequire) { layerGroup.addTo(map); - map.fitBounds(_.pluck(scope.data,'coordinates')); + if( scope.panel.fitBoundsAuto || fitBoundsFlag ) { + map.fitBounds(_.pluck(scope.data,'coordinates')); + fitBoundsFlag = false; + } }); } }