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
3d1c44ff
Commit
3d1c44ff
authored
May 29, 2018
by
Tejesh
🖖
Browse files
support topojson/geojson or mix of these, fix eclint issues
parent
24c83443
Pipeline
#49442
passed with stage
in 2 minutes and 50 seconds
Changes
13
Pipelines
2
Show whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
3d1c44ff
...
...
@@ -5,7 +5,7 @@ cache:
validate
:
script
:
-
eclint check
'
**/*.html
' '
**/*.js
' '
**/*.css
' '
**/*.yaml
' '
**/*.md
'
-
eclint check
"
**/*.html
" "
**/*.js
" "
**/*.css
" "
**/*.yaml
" "
**/*.md
"
-
yarn install
-
npm run lint
-
npm run test
...
...
src/formhandler.template.html
View file @
3d1c44ff
src/mapviewer.js
View file @
3d1c44ff
...
...
@@ -31,7 +31,7 @@ var defaults = {
* // initialize the map on the "map" div with a given center and zoom
* var mapviewer = g1.mapviewer(config)
* ```
*/
*/
export
var
MapViewer
=
class
MapViewer
{
constructor
(
config
)
{
var
self
=
this
...
...
@@ -61,18 +61,20 @@ export var MapViewer = class MapViewer {
}
}
}
// * @method cacheData(<String> datasetName, 'String' URL || <Object> data): <Object> data
// * GETs data if not already there in this.gData
// *
// * TODO: If dataset itself is given, that is understood as data update.
// * layers rendered based on this data must be reRendered.
// * ?? Do a data diff and then load dependant layers ??
// *
// * @example
// *
// *```js
// mapviewer.cacheData('india_states', 'india-states.geojson')
// *```
/*
* @method cacheData(<String> datasetName, 'String' URL || <Object> data): <Object> data
* GETs data if not already there in this.gData
*
* TODO: If dataset itself is given, that is understood as data update.
* layers rendered based on this data must be reRendered.
* ?? Do a data diff and then load dependant layers ??
*
* @example
*
*```js
mapviewer.cacheData('india_states', 'india-states.geojson')
*```
*/
MapViewer
.
prototype
.
cacheData
=
function
(
layerName
,
url
)
{
var
self
=
this
switch
(
typeof
(
url
))
{
...
...
@@ -94,10 +96,12 @@ MapViewer.prototype.cacheData = function (layerName, url) {
}()
}
}
// * @method _saveLayer(<Layer> layer, <String> layerName ): this
// * Adds a layer to gLayers object, and
// *
// * Private method
/*
* @method _saveLayer(<Layer> layer, <String> layerName ): this
* Adds a layer to gLayers object, and
*
* Private method
*/
MapViewer
.
prototype
.
_saveLayer
=
function
(
layerName
,
layer
)
{
var
self
=
this
,
allLayersLoaded
=
true
self
.
gLayers
[
layerName
]
=
layer
...
...
@@ -172,7 +176,7 @@ MapViewer.prototype.buildLayer = function (layerName, layerConfig) {
gLayer
=
L
.
tileLayer
(
layerConfig
.
url
,
layerConfig
.
options
)
this
.
_saveLayer
(
layerName
,
gLayer
)
break
// TODO: remove duplicate code topojson and
geojson
case
'
geojson
'
:
case
'
topojson
'
:
self
.
cacheData
(
layerName
,
layerConfig
[
dataOrURL
(
layerConfig
)]).
then
(
function
(
mapJSON
)
{
gLayer
=
new
L
.
TopoJSON
(
mapJSON
,
layerConfig
.
options
)
...
...
@@ -189,22 +193,6 @@ MapViewer.prototype.buildLayer = function (layerName, layerConfig) {
}
})
break
case
'
geojson
'
:
self
.
cacheData
(
layerName
,
layerConfig
[
dataOrURL
(
layerConfig
)]).
then
(
function
(
mapJSON
)
{
gLayer
=
L
.
geoJSON
(
mapJSON
,
layerConfig
.
options
)
self
.
_saveLayer
(
layerName
,
gLayer
)
if
(
'
link
'
in
layerConfig
)
{
self
.
cacheData
(
layerName
,
layerConfig
.
link
[
dataOrURL
(
layerConfig
.
link
)]).
then
(
function
(
tableData
)
{
self
.
mergeData
(
mapJSON
,
tableData
,
layerConfig
.
link
.
mapKey
,
layerConfig
.
link
.
dataKey
)
self
.
fitToLayer
(
layerName
)
if
(
'
attrs
'
in
layerConfig
)
self
.
_choropleth
(
layerName
)
})
}
else
{
if
(
'
attrs
'
in
layerConfig
)
self
.
_choropleth
(
layerName
)
self
.
fitToLayer
(
layerName
)
}
})
break
// TODO: remove duplicate code from marker and circkeMarker
case
'
marker
'
:
var
pointLayers
=
[]
...
...
@@ -254,7 +242,7 @@ MapViewer.prototype._choropleth = function (layerName) {
layer
.
eachLayer
(
function
(
sublayer
)
{
var
style
=
{},
prop
,
metricFormula
,
metric
,
domain
for
(
prop
in
self
.
options
.
layers
[
layerName
].
attrs
)
{
if
(
prop
.
toLowerCase
()
==
'
tooltip
'
)
continue
if
(
prop
.
toLowerCase
()
==
'
tooltip
'
)
continue
metric
=
self
.
options
.
layers
[
layerName
].
attrs
[
prop
].
metric
if
(
typeof
(
metric
)
===
'
string
'
)
metricFormula
=
(
row
)
=>
row
[
metric
]
...
...
@@ -295,14 +283,16 @@ MapViewer.prototype._calculateMinMax = function (layer, metricFormula) {
})
return
[
minVal
,
maxVal
]
}
// * @method fitToLayer(<String> layerName ): this
// * Zooms map view to fit the layer
// *
// * @example
// *
// *```js
// mapviewer.fitToLayer('indiaGeojson')
// *```
/*
* @method fitToLayer(<String> layerName ): this
* Zooms map view to fit the layer
*
* @example
*
*```js
mapviewer.fitToLayer('indiaGeojson')
*```
*/
MapViewer
.
prototype
.
fitToLayer
=
function
(
layerName
,
options
=
{})
{
this
.
map
.
fitBounds
(
this
.
gLayers
[
layerName
].
getBounds
(),
options
)
}
...
...
@@ -341,7 +331,8 @@ L.TopoJSON = L.GeoJSON.extend({
L
.
GeoJSON
.
prototype
.
addData
.
call
(
this
,
geojson
)
}
else
throw
new
Error
(
'
json data is not of TopoJSON type
'
)
L
.
GeoJSON
.
prototype
.
addData
.
call
(
this
,
jsonData
)
return
this
}
})
...
...
src/url.js
View file @
3d1c44ff
test/S21_PC.json
View file @
3d1c44ff
test/data_table.json
View file @
3d1c44ff
test/empty.html
View file @
3d1c44ff
test/formhandler-continent.json
View file @
3d1c44ff
test/formhandler.json
View file @
3d1c44ff
test/sales-edit.json
View file @
3d1c44ff
test/sales.json
View file @
3d1c44ff
test/state_score.json
View file @
3d1c44ff
test/test-sanddance.html
View file @
3d1c44ff
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