Skip to content

Commit

Permalink
fix autofocus for map
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarning committed Jan 23, 2019
1 parent 3f97382 commit 09c6c7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
11 changes: 3 additions & 8 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="leaflet-1.3.4.css"/>

<!-- Source https://leafletjs.com/ -->
<script src="leaflet-1.3.4.js"></script>

<!-- Source: http://d3js.org -->
<!-- Source: https://d3js.org -->
<script src="d3.v5.min.js"></script>
<script src="rbush-2.0.2.min.js"></script>

Expand Down Expand Up @@ -40,12 +41,6 @@
clientZoom: 15,
nodeZoom: 18,
geo: null,
fixedCenter: [
// Northwest
[-5.0, 5.0],
// Southeast
[5.0, -5.0]
],
map_tqFrom: '#F02311',
map_tqTo: '#04C714',
fullscreen: true,
Expand Down Expand Up @@ -99,8 +94,8 @@
var linkScale = d3.interpolate(config.map_tqFrom, config.map_tqTo);
var parent = $('#content');
my_map = createMap(parent, selection, linkScale, sidebar, buttons);
my_map.resetView();
my_map.setData(my_data);
my_map.resetView();
}

function showGraph() {
Expand Down
13 changes: 6 additions & 7 deletions www/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
function createMap(parent, selection, linkScale, sidebar, buttons) {
var self = this;
var savedView;
var nodesBounds;
var nodeBounds;

var map;
var layerControl;
Expand Down Expand Up @@ -180,7 +180,7 @@ function createMap(parent, selection, linkScale, sidebar, buttons) {
return m;
}

function nodesBounds(nodes) {
function getNodeBounds(nodes) {
var min_x = Number.POSITIVE_INFINITY;
var max_x = Number.NEGATIVE_INFINITY;
var min_y = Number.POSITIVE_INFINITY;
Expand Down Expand Up @@ -227,12 +227,11 @@ function createMap(parent, selection, linkScale, sidebar, buttons) {
goto(m);
} else if (savedView) {
map.setView(savedView.center, savedView.zoom);
} else if (nodeBounds) {
setView(nodeBounds);
} else {

setView(nodesBounds);
setView([[5.0, 5.0], [0.0, 0.0]]);
}
} else {
setView(nodesBounds);
}
}

Expand Down Expand Up @@ -263,7 +262,7 @@ function createMap(parent, selection, linkScale, sidebar, buttons) {
nodeDict = {};
linkDict = {};

nodesBounds = nodesBounds(nodes);
nodeBounds = getNodeBounds(nodes);
clientLayer.setData(data);
labelLayer.setData(data, map, nodeDict, linkDict, linkScale);

Expand Down

0 comments on commit 09c6c7d

Please sign in to comment.