Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cto
g1
Commits
d483ce2c
Commit
d483ce2c
authored
May 25, 2018
by
Tejesh
🖖
Browse files
refactor tooltip code and add events to doc
parent
f6d2696e
Pipeline
#48914
passed with stage
in 3 minutes and 5 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
d483ce2c
...
...
@@ -1178,6 +1178,11 @@ attribute.
`g1.mapviewer.fitToLayer(layerName, options)`
Zooms map view to fit the layer. Supports same options as
[
fitBounds options
](
http://leafletjs.com/reference-1.3.0.html#fitbounds-options
)
### g1.mapviewer events
-
`mapload`
is fired when all the map layers are loaded.
-
`layersload`
is fired when all layers are saved in mapviewer.gLayers
-
tooltip is rendered on each layer only after layers are loaded.
## Contributing
...
...
src/mapviewer.js
View file @
d483ce2c
...
...
@@ -57,14 +57,7 @@ export var MapViewer = class MapViewer {
for
(
let
layerName
in
self
.
options
.
layers
)
{
self
.
buildLayer
(
layerName
,
self
.
options
.
layers
[
layerName
])
}
self
.
on
(
'
savelayer
'
,
function
()
{
for
(
let
layerName
in
self
.
options
.
layers
)
{
if
(
self
.
options
.
layers
[
layerName
].
attrs
&&
self
.
options
.
layers
[
layerName
].
attrs
.
tooltip
)
{
self
.
renderTooltip
(
layerName
,
self
.
options
.
layers
[
layerName
])
}
}
self
.
mapDiv
.
dispatchEvent
(
new
Event
(
'
mapload
'
))
})
self
.
renderTooltip
()
}
}
}
...
...
@@ -120,17 +113,25 @@ MapViewer.prototype._saveLayer = function (layerName, layer) {
}
}
if
(
allLayersLoaded
===
true
)
{
self
.
mapDiv
.
dispatchEvent
(
new
Event
(
'
save
layer
'
))
self
.
mapDiv
.
dispatchEvent
(
new
Event
(
'
layer
sload
'
))
}
}
MapViewer
.
prototype
.
renderTooltip
=
function
(
layerName
,
layerConfig
)
{
this
.
gLayers
[
layerName
].
eachLayer
(
function
(
sublayer
)
{
var
tooltipContent
=
layerConfig
.
attrs
.
tooltip
if
(
typeof
(
layerConfig
.
attrs
.
tooltip
)
===
'
function
'
)
{
tooltipContent
=
layerConfig
.
attrs
.
tooltip
(
sublayer
.
feature
.
properties
)
MapViewer
.
prototype
.
renderTooltip
=
function
()
{
var
self
=
this
self
.
on
(
'
layersload
'
,
function
()
{
for
(
let
layerName
in
self
.
options
.
layers
)
{
if
(
self
.
options
.
layers
[
layerName
].
attrs
&&
self
.
options
.
layers
[
layerName
].
attrs
.
tooltip
)
{
self
.
gLayers
[
layerName
].
eachLayer
(
function
(
sublayer
)
{
var
tooltipContent
=
self
.
options
.
layers
[
layerName
].
attrs
.
tooltip
if
(
typeof
(
self
.
options
.
layers
[
layerName
].
attrs
.
tooltip
)
===
'
function
'
)
{
tooltipContent
=
self
.
options
.
layers
[
layerName
].
attrs
.
tooltip
(
sublayer
.
feature
.
properties
)
}
sublayer
.
bindTooltip
(
tooltipContent
)
})
}
}
s
ublayer
.
bindTooltip
(
tooltipContent
)
s
elf
.
mapDiv
.
dispatchEvent
(
new
Event
(
'
mapload
'
)
)
})
}
...
...
@@ -276,6 +277,9 @@ MapViewer.prototype._choropleth = function (layerName) {
sublayer
.
setStyle
(
style
)
})
}
// * @method _calculateMinMax(layer, <function> metricFormula ): <Array>
// * Analogous to d3.extent but for feature.properties
// * Private/internal method
MapViewer
.
prototype
.
_calculateMinMax
=
function
(
layer
,
metricFormula
)
{
var
minVal
,
maxVal
layer
.
eachLayer
(
function
(
sublayer
)
{
...
...
@@ -318,6 +322,16 @@ String.prototype.hashCode = function () {
return
hash
>>>
0
;
}
String
.
prototype
.
slugify
=
function
()
{
return
this
.
toString
().
toLowerCase
()
.
replace
(
/
\s
+/g
,
'
-
'
)
// Replace spaces with -
.
replace
(
/
[^\w\\
-
]
+/g
,
''
)
// Remove all non-word chars
.
replace
(
/
\\
-
\\
-+/g
,
'
-
'
)
// Replace multiple - with single -
.
replace
(
/^-+/
,
''
)
// Trim - from start of text
.
replace
(
/-+$/
,
''
);
// Trim - from end of text
}
L
.
TopoJSON
=
L
.
GeoJSON
.
extend
({
addData
:
function
(
jsonData
)
{
var
key
,
geojson
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment