Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
meshviewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
infrastruktur
meshviewer
Commits
22b49c1a
Commit
22b49c1a
authored
10 years ago
by
Nils Schneider
Browse files
Options
Downloads
Patches
Plain Diff
map: draw only labels present on map using rtrees
parent
9d2318dc
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
app.js
+1
-0
1 addition, 0 deletions
app.js
bower.json
+2
-1
2 additions, 1 deletion
bower.json
lib/map.js
+28
-7
28 additions, 7 deletions
lib/map.js
lib/map/clientlayer.js
+49
-39
49 additions, 39 deletions
lib/map/clientlayer.js
lib/map/labelslayer.js
+23
-23
23 additions, 23 deletions
lib/map/labelslayer.js
with
103 additions
and
70 deletions
app.js
+
1
−
0
View file @
22b49c1a
...
...
@@ -12,6 +12,7 @@ require.config({
"
numeral
"
:
"
../bower_components/numeraljs/min/numeral.min
"
,
"
numeral-intl
"
:
"
../bower_components/numeraljs/min/languages.min
"
,
"
virtual-dom
"
:
"
../bower_components/virtual-dom/dist/virtual-dom
"
,
"
rbush
"
:
"
../bower_components/rbush/rbush
"
,
"
helper
"
:
"
../helper
"
},
shim
:
{
...
...
This diff is collapsed.
Click to expand it.
bower.json
+
2
−
1
View file @
22b49c1a
...
...
@@ -23,7 +23,8 @@
"numeraljs"
:
"~1.5.3"
,
"roboto-fontface"
:
"~0.3.0"
,
"virtual-dom"
:
"~2.0.1"
,
"leaflet-providers"
:
"~1.0.27"
"leaflet-providers"
:
"~1.0.27"
,
"rbush"
:
"https://github.com/mourner/rbush.git#~1.3.5"
},
"authors"
:
[
"Nils Schneider <nils@nilsschneider.net>"
...
...
This diff is collapsed.
Click to expand it.
lib/map.js
+
28
−
7
View file @
22b49c1a
define
([
"
map/clientlayer
"
,
"
map/labelslayer
"
,
"
d3
"
,
"
leaflet
"
,
"
moment
"
,
"
locationmarker
"
,
"
d3
"
,
"
leaflet
"
,
"
moment
"
,
"
locationmarker
"
,
"
rbush
"
,
"
leaflet.label
"
,
"
leaflet.providers
"
],
function
(
ClientLayer
,
LabelsLayer
,
d3
,
L
,
moment
,
LocationMarker
)
{
function
(
ClientLayer
,
LabelsLayer
,
d3
,
L
,
moment
,
LocationMarker
,
rbush
)
{
var
options
=
{
worldCopyJump
:
true
,
zoomControl
:
false
}
...
...
@@ -300,6 +300,15 @@ define(["map/clientlayer", "map/labelslayer",
return
L
.
circle
(
barycenter
,
r
*
config
.
mapSigmaScale
)
}
function
mapRTree
(
d
)
{
var
o
=
[
d
.
nodeinfo
.
location
.
latitude
,
d
.
nodeinfo
.
location
.
longitude
,
d
.
nodeinfo
.
location
.
latitude
,
d
.
nodeinfo
.
location
.
longitude
]
o
.
node
=
d
return
o
}
self
.
setData
=
function
(
data
)
{
nodeDict
=
{}
linkDict
=
{}
...
...
@@ -349,11 +358,23 @@ define(["map/clientlayer", "map/labelslayer",
groupNew
=
L
.
featureGroup
(
markersNew
).
addTo
(
map
)
groupLost
=
L
.
featureGroup
(
markersLost
).
addTo
(
map
)
clientLayer
.
setData
(
data
.
nodes
.
all
.
filter
(
online
).
filter
(
has_location
))
labelsLayer
.
setData
({
online
:
nodesOnline
.
filter
(
has_location
),
offline
:
nodesOffline
.
filter
(
has_location
),
new
:
data
.
nodes
.
new
.
filter
(
has_location
),
lost
:
data
.
nodes
.
lost
.
filter
(
has_location
)
var
rtreeOnlineAll
=
rbush
(
9
)
var
rtreeOnline
=
rbush
(
9
)
var
rtreeOffline
=
rbush
(
9
)
var
rtreeNew
=
rbush
(
9
)
var
rtreeLost
=
rbush
(
9
)
rtreeOnlineAll
.
load
(
data
.
nodes
.
all
.
filter
(
online
).
filter
(
has_location
).
map
(
mapRTree
))
rtreeOnline
.
load
(
nodesOnline
.
filter
(
has_location
).
map
(
mapRTree
))
rtreeOffline
.
load
(
nodesOffline
.
filter
(
has_location
).
map
(
mapRTree
))
rtreeNew
.
load
(
data
.
nodes
.
new
.
filter
(
has_location
).
map
(
mapRTree
))
rtreeLost
.
load
(
data
.
nodes
.
lost
.
filter
(
has_location
).
map
(
mapRTree
))
clientLayer
.
setData
(
rtreeOnlineAll
)
labelsLayer
.
setData
({
online
:
rtreeOnline
,
offline
:
rtreeOffline
,
new
:
rtreeNew
,
lost
:
rtreeLost
})
updateView
(
true
)
...
...
This diff is collapsed.
Click to expand it.
lib/map/clientlayer.js
+
49
−
39
View file @
22b49c1a
...
...
@@ -6,6 +6,13 @@ define(["leaflet"],
this
.
redraw
()
},
drawTile
:
function
(
canvas
,
tilePoint
)
{
function
getTileBBox
(
s
,
map
,
tileSize
,
margin
)
{
var
tl
=
map
.
unproject
([
s
.
x
-
margin
,
s
.
y
-
margin
])
var
br
=
map
.
unproject
([
s
.
x
+
margin
+
tileSize
,
s
.
y
+
margin
+
tileSize
])
return
[
br
.
lat
,
tl
.
lng
,
tl
.
lat
,
br
.
lng
]
}
if
(
!
this
.
data
)
return
...
...
@@ -13,29 +20,32 @@ define(["leaflet"],
var
s
=
tilePoint
.
multiplyBy
(
tileSize
)
var
map
=
this
.
_map
function
project
(
coords
)
{
var
p
=
map
.
project
(
new
L
.
LatLng
(
coords
[
0
],
coords
[
1
]))
return
{
x
:
p
.
x
-
s
.
x
,
y
:
p
.
y
-
s
.
y
}
}
var
nodes
=
this
.
data
var
ctx
=
canvas
.
getContext
(
"
2d
"
)
var
margin
=
50
var
bbox
=
getTileBBox
(
s
,
map
,
tileSize
,
margin
)
ctx
.
beginPath
()
nodes
.
forEach
(
function
(
d
)
{
var
p
=
project
([
d
.
nodeinfo
.
location
.
latitude
,
d
.
nodeinfo
.
location
.
longitude
])
if
(
p
.
x
+
margin
<
0
||
p
.
y
+
margin
<
0
||
p
.
x
-
tileSize
-
margin
>
0
||
p
.
y
-
tileSize
-
margin
>
0
)
return
var
nodes
=
this
.
data
.
search
(
bbox
)
var
clients
=
d
.
statistics
.
clients
if
(
d
.
clients
===
0
)
if
(
nodes
.
length
===
0
)
return
var
ctx
=
canvas
.
getContext
(
"
2d
"
)
var
distance
=
12
var
radius
=
3
var
a
=
1.2
var
startAngle
=
Math
.
PI
ctx
.
beginPath
()
nodes
.
forEach
(
function
(
d
)
{
var
p
=
map
.
project
([
d
.
node
.
nodeinfo
.
location
.
latitude
,
d
.
node
.
nodeinfo
.
location
.
longitude
])
var
clients
=
d
.
node
.
statistics
.
clients
if
(
clients
===
0
)
return
p
.
x
-=
s
.
x
p
.
y
-=
s
.
y
var
angle
=
startAngle
for
(
var
i
=
0
;
i
<
clients
;
i
++
)
{
...
...
This diff is collapsed.
Click to expand it.
lib/map/labelslayer.js
+
23
−
23
View file @
22b49c1a
...
...
@@ -6,6 +6,13 @@ define(["leaflet"],
this
.
redraw
()
},
drawTile
:
function
(
canvas
,
tilePoint
)
{
function
getTileBBox
(
s
,
map
,
tileSize
,
margin
)
{
var
tl
=
map
.
unproject
([
s
.
x
-
margin
,
s
.
y
-
margin
])
var
br
=
map
.
unproject
([
s
.
x
+
margin
+
tileSize
,
s
.
y
+
margin
+
tileSize
])
return
[
br
.
lat
,
tl
.
lng
,
tl
.
lat
,
br
.
lng
]
}
if
(
!
this
.
data
)
return
...
...
@@ -13,38 +20,31 @@ define(["leaflet"],
var
s
=
tilePoint
.
multiplyBy
(
tileSize
)
var
map
=
this
.
_map
function
project
(
coords
)
{
var
p
=
map
.
project
(
new
L
.
LatLng
(
coords
[
0
],
coords
[
1
]))
return
{
x
:
p
.
x
-
s
.
x
,
y
:
p
.
y
-
s
.
y
}
}
function
projectNodes
(
d
)
{
return
{
p
:
project
([
d
.
nodeinfo
.
location
.
latitude
,
d
.
nodeinfo
.
location
.
longitude
]),
o
:
d
}
}
var
p
=
map
.
project
([
d
.
node
.
nodeinfo
.
location
.
latitude
,
d
.
node
.
nodeinfo
.
location
.
longitude
])
var
margin
=
150
function
onTile
(
d
)
{
return
d
.
p
.
x
+
margin
>
0
||
d
.
p
.
y
+
margin
>
0
||
d
.
p
.
x
-
tileSize
-
margin
<
0
||
d
.
p
.
y
-
tileSize
-
margin
<
0
p
.
x
-=
s
.
x
p
.
y
-=
s
.
y
return
{
p
:
p
,
o
:
d
.
node
}
}
var
ctx
=
canvas
.
getContext
(
"
2d
"
)
var
margin
=
256
var
bbox
=
getTileBBox
(
s
,
map
,
tileSize
,
margin
)
var
nodesOnline
=
this
.
data
.
online
.
map
(
projectNodes
).
filter
(
onTile
)
var
nodesOffline
=
this
.
data
.
offline
.
map
(
projectNodes
).
filter
(
onTile
)
var
nodesNew
=
this
.
data
.
new
.
map
(
projectNodes
).
filter
(
onTile
)
var
nodesLost
=
this
.
data
.
lost
.
map
(
projectNodes
).
filter
(
onTile
)
var
nodesOnline
=
this
.
data
.
online
.
search
(
bbox
).
map
(
projectNodes
)
var
nodesOffline
=
this
.
data
.
offline
.
search
(
bbox
).
map
(
projectNodes
)
var
nodesNew
=
this
.
data
.
new
.
search
(
bbox
).
map
(
projectNodes
)
var
nodesLost
=
this
.
data
.
lost
.
search
(
bbox
).
map
(
projectNodes
)
var
ctx
=
canvas
.
getContext
(
"
2d
"
)
var
distance
=
10
ctx
.
font
=
"
12px Roboto
"
ctx
.
textBaseline
=
"
middle
"
ctx
.
textAlign
=
"
left
"
ctx
.
lineWidth
=
2.5
var
distance
=
10
function
drawLabel
(
d
)
{
ctx
.
strokeText
(
d
.
o
.
nodeinfo
.
hostname
,
d
.
p
.
x
+
distance
,
d
.
p
.
y
)
ctx
.
fillText
(
d
.
o
.
nodeinfo
.
hostname
,
d
.
p
.
x
+
distance
,
d
.
p
.
y
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment