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

better map auto fit option / icon #242

Merged
merged 1 commit into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/app/directives/kibanaPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function (angular) {
'class="fa fa-info-circle pointer" bs-tooltip data-title="{{task.description}}" container="body" ></i></span>'+
'</span>' +

'<span class="row-button extra" ng-show="panel.fitBoundsAuto != undefined && !panel.fitBoundsAuto">' +
'<a ng-click="fitBounds()"><i tooltip="\'fit bound\'" class="pointer icon-fire"></i>'+
'</a></span>' + // bettermap fitBound action

'<span class="dropdown row-button extra" container="body" bs-tooltip data-title="Export" data-placement="bottom" ng-show="panelMeta.exportfile">' +
'<span class="pointer" class="dropdown-toggle" data-toggle="dropdown">' +
'<i class="fa fa-save" class="pointer"></i>' +
Expand Down
21 changes: 21 additions & 0 deletions src/app/panels/bettermap/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,25 @@ <h6>Ending Longitude</h6>
<input type="number" pattern="[0-9]+([\.|,][0-9]+)?" step="0.01" class="form-control" ng-model="panel.lon_end" ng-change="set_refresh(true)">
</form>
</div>
</div>

<div class="row-fluid">
<div class="span3">
<form>
<h6> Auto fitbounds </h6>
<input type="checkbox" class="input-small" ng-model="panel.fitBoundsAuto" ng-checked="panel.fitBoundsAuto">
</form>
</div>
<div class="span4">
<form>
<h6>Default Latitude if not exists</h6>
<input type="number" pattern="[0-9]+([\.|,][0-9]+)?" step="0.01" class="input-medium" ng-model="panel.lat_empty" ng-change="set_refresh(true)">
</form>
</div>
<div class="span4">
<form>
<h6>Default Longitude if not exists</h6>
<input type="number" pattern="[0-9]+([\.|,][0-9]+)?" step="0.01" class="input-medium" ng-model="panel.lon_empty" ng-change="set_refresh(true)">
</form>
</div>
</div>
22 changes: 20 additions & 2 deletions src/app/panels/bettermap/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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;
}
});
}
}
Expand Down