Commit d483ce2c authored by Tejesh's avatar Tejesh 🖖
Browse files

refactor tooltip code and add events to doc

parent f6d2696e
Pipeline #48914 passed with stage
in 3 minutes and 5 seconds
......@@ -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
......
......@@ -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('savelayer'))
self.mapDiv.dispatchEvent(new Event('layersload'))
}
}
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)
})
}
}
sublayer.bindTooltip(tooltipContent)
self.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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment