@hpcc-js/map 3.5.4 → 3.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +88 -88
  3. package/TopoJSON/BR.json +122 -122
  4. package/TopoJSON/GB_idx.json +1 -1
  5. package/TopoJSON/IE_idx.json +1 -1
  6. package/TopoJSON/ND_idx.json +1 -1
  7. package/TopoJSON/countries.json +257 -257
  8. package/TopoJSON/us-counties.json +16550 -16550
  9. package/TopoJSON/us-states.json +458 -458
  10. package/dist/index.js +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.umd.cjs +1 -1
  13. package/dist/index.umd.cjs.map +1 -1
  14. package/package.json +12 -10
  15. package/src/CanvasPinLayer.ts +99 -99
  16. package/src/CanvasPins.ts +397 -397
  17. package/src/Choropleth.css +26 -26
  18. package/src/Choropleth.ts +203 -203
  19. package/src/ChoroplethContinents.ts +13 -13
  20. package/src/ChoroplethCounties.ts +111 -111
  21. package/src/ChoroplethCountries.ts +100 -100
  22. package/src/ChoroplethStates.ts +103 -103
  23. package/src/ChoroplethStatesHeat.ts +8 -8
  24. package/src/GMap.css +20 -20
  25. package/src/GMap.ts +880 -880
  26. package/src/GMapCounties.ts +93 -93
  27. package/src/GMapGraph.ts +61 -61
  28. package/src/GMapHeat.ts +27 -27
  29. package/src/GMapLayered.ts +94 -94
  30. package/src/GMapPin.ts +115 -115
  31. package/src/GMapPinLine.ts +138 -138
  32. package/src/GeoHash.css +14 -14
  33. package/src/GeoHash.ts +139 -139
  34. package/src/Graph.css +9 -9
  35. package/src/Graph.ts +98 -98
  36. package/src/Graticule.css +12 -12
  37. package/src/Graticule.ts +97 -97
  38. package/src/Heat.ts +87 -87
  39. package/src/IChoropleth.ts +8 -8
  40. package/src/Layer.ts +99 -99
  41. package/src/Layered.css +18 -18
  42. package/src/Layered.ts +206 -206
  43. package/src/Lines.css +8 -8
  44. package/src/Lines.ts +78 -78
  45. package/src/OpenStreet.css +15 -15
  46. package/src/OpenStreet.ts +126 -126
  47. package/src/Pins.css +17 -17
  48. package/src/Pins.ts +350 -350
  49. package/src/Projection.ts +42 -42
  50. package/src/TestHeatMap.ts +8 -8
  51. package/src/TopoJSONChoropleth.ts +125 -125
  52. package/src/Utility.ts +484 -484
  53. package/src/__package__.ts +3 -3
  54. package/src/index.ts +33 -33
  55. package/src/leaflet/AlbersPR.ts +48 -48
  56. package/src/leaflet/Blank.ts +9 -9
  57. package/src/leaflet/Circles.ts +139 -139
  58. package/src/leaflet/ClusterCircles.css +26 -26
  59. package/src/leaflet/ClusterCircles.ts +88 -88
  60. package/src/leaflet/Countries.ts +43 -43
  61. package/src/leaflet/DrawLayer.ts +167 -167
  62. package/src/leaflet/FeatureLayer.ts +138 -138
  63. package/src/leaflet/GMap.ts +44 -44
  64. package/src/leaflet/HeatLayer.ts +77 -77
  65. package/src/leaflet/Icons.ts +60 -60
  66. package/src/leaflet/Leaflet.css +3 -3
  67. package/src/leaflet/Leaflet.ts +239 -239
  68. package/src/leaflet/MapBox.ts +35 -35
  69. package/src/leaflet/Markers.ts +109 -109
  70. package/src/leaflet/OpenStreet.ts +27 -27
  71. package/src/leaflet/Path.ts +138 -138
  72. package/src/leaflet/Pins.ts +73 -73
  73. package/src/leaflet/Polygons.ts +113 -113
  74. package/src/leaflet/Region.ts +138 -138
  75. package/src/leaflet/Text.ts +99 -99
  76. package/src/leaflet/TileLayer.ts +81 -81
  77. package/src/leaflet/TopoJSON.ts +146 -146
  78. package/src/leaflet/US.ts +15 -15
  79. package/src/leaflet/USCounties.ts +43 -43
  80. package/src/leaflet/USStates.ts +41 -41
  81. package/src/leaflet/World.css +3 -3
  82. package/src/leaflet/World.ts +172 -172
  83. package/src/leaflet/index.ts +18 -18
  84. package/src/leaflet/leaflet-shim.ts +18 -18
  85. package/src/leaflet/plugins/BeautifyIcon.css +44 -44
  86. package/src/leaflet/plugins/BeautifyIcon.ts +190 -190
  87. package/src/leaflet/plugins/BeutifyIcon.licence +20 -20
  88. package/src/leaflet/plugins/D3SvgOverlay.css +2 -2
  89. package/src/leaflet/plugins/D3SvgOverlay.licence +20 -20
  90. package/src/leaflet/plugins/D3SvgOverlay.ts +175 -175
  91. package/src/leaflet/plugins/HeatLayer.license +21 -21
  92. package/src/leaflet/plugins/HeatLayer.ts +224 -224
  93. package/src/leaflet/plugins/Leaflet.GoogleMutant.ts +424 -424
  94. package/src/leaflet/plugins/lru_map.ts +352 -352
  95. package/src/test.ts +114 -114
@@ -1,111 +1,111 @@
1
- import { InputField } from "@hpcc-js/common";
2
- import { json as d3Json } from "d3-request";
3
- import { select as d3Select } from "d3-selection";
4
- import * as topojson from "topojson-client";
5
- import { Choropleth, topoJsonFolder } from "./Choropleth.ts";
6
-
7
- let usCounties = null;
8
- let features = null;
9
- let rFeatures = null;
10
-
11
- export class ChoroplethCounties extends Choropleth {
12
- static __inputs: InputField[] = [{
13
- id: "fips",
14
- type: "string"
15
- }, {
16
- id: "value",
17
- type: "number"
18
- }];
19
-
20
- choroPaths;
21
-
22
- constructor() {
23
- super();
24
-
25
- this.projection("AlbersUsaPr");
26
- }
27
-
28
- layerEnter(base, svgElement, domElement) {
29
- Choropleth.prototype.layerEnter.apply(this, arguments);
30
- this._choroTopology = usCounties.topology;
31
- this._choroTopologyObjects = usCounties.topology.objects.counties;
32
-
33
- this._selection.widgetElement(this._choroplethData);
34
- this.choroPaths = d3Select(null);
35
- const context = this;
36
- this
37
- .tooltipHTML(function (d) {
38
- const code = d[0];
39
- return context.tooltipFormat({ label: usCounties.countyNames[code], value: context._dataMap[code] ? context._dataMap[code][1] : "N/A" });
40
- })
41
- ;
42
- }
43
-
44
- layerUpdate(base) {
45
- Choropleth.prototype.layerUpdate.apply(this, arguments);
46
-
47
- this._choroplethData
48
- .style("stroke", this.meshVisible() ? null : "black")
49
- ;
50
-
51
- this.choroPaths = this._choroplethData.selectAll(".shape").data(this.visible() ? this.data() : [], function (d) { return d[0]; });
52
- const context = this;
53
- this.choroPaths.enter().append("path")
54
- .attr("class", "shape")
55
- .attr("vector-effect", "non-scaling-stroke")
56
- .call(this._selection.enter.bind(this._selection))
57
- .on("click", function (d) {
58
- context.click(context.rowToObj(d), "weight", context._selection.selected(this));
59
- })
60
- .on("dblclick", function (d) {
61
- context.dblclick(context.rowToObj(d), "weight", context._selection.selected(this));
62
- })
63
- .on("mouseout.tooltip", this.tooltip.hide)
64
- .on("mousemove.tooltip", this.tooltip.show)
65
- .merge(this.choroPaths)
66
- .attr("d", function (d) {
67
- const retVal = base._d3GeoPath(rFeatures[d.county]);
68
- if (!retVal) {
69
- console.warn("Unknown US County: " + d.county, d);
70
- }
71
- return retVal;
72
- })
73
- .style("fill", function (d) {
74
- const retVal = context._palette(d[1], context._dataMinWeight, context._dataMaxWeight);
75
- return retVal;
76
- })
77
- ;
78
- this.choroPaths.exit().remove();
79
- }
80
-
81
- layerPreRender() {
82
- if (!this._topoJsonPromise) {
83
- this._topoJsonPromise = new Promise<void>((resolve, reject) => {
84
- if (usCounties) {
85
- resolve();
86
- }
87
- d3Json(`${topoJsonFolder()}/us-counties.json`, function (_usCounties) {
88
- usCounties = _usCounties;
89
- features = topojson.feature(usCounties.topology, usCounties.topology.objects.counties).features;
90
- rFeatures = {};
91
- for (const key in features) {
92
- if (features[key].id) {
93
- rFeatures[features[key].id] = features[key];
94
- }
95
- }
96
- resolve();
97
- });
98
- });
99
- }
100
- return this._topoJsonPromise;
101
- }
102
- }
103
- ChoroplethCounties.prototype._class += " map_ChoroplethCounties";
104
-
105
- export interface ChoroplethCounties {
106
- onClickFormatFIPS(): boolean;
107
- onClickFormatFIPS(_: boolean): this;
108
- onClickFormatFIPS_exists(): boolean;
109
- }
110
-
111
- ChoroplethCounties.prototype.publish("onClickFormatFIPS", false, "boolean", "format FIPS code as a String on Click");
1
+ import { InputField } from "@hpcc-js/common";
2
+ import { json as d3Json } from "d3-request";
3
+ import { select as d3Select } from "d3-selection";
4
+ import * as topojson from "topojson-client";
5
+ import { Choropleth, topoJsonFolder } from "./Choropleth.ts";
6
+
7
+ let usCounties = null;
8
+ let features = null;
9
+ let rFeatures = null;
10
+
11
+ export class ChoroplethCounties extends Choropleth {
12
+ static __inputs: InputField[] = [{
13
+ id: "fips",
14
+ type: "string"
15
+ }, {
16
+ id: "value",
17
+ type: "number"
18
+ }];
19
+
20
+ choroPaths;
21
+
22
+ constructor() {
23
+ super();
24
+
25
+ this.projection("AlbersUsaPr");
26
+ }
27
+
28
+ layerEnter(base, svgElement, domElement) {
29
+ Choropleth.prototype.layerEnter.apply(this, arguments);
30
+ this._choroTopology = usCounties.topology;
31
+ this._choroTopologyObjects = usCounties.topology.objects.counties;
32
+
33
+ this._selection.widgetElement(this._choroplethData);
34
+ this.choroPaths = d3Select(null);
35
+ const context = this;
36
+ this
37
+ .tooltipHTML(function (d) {
38
+ const code = d[0];
39
+ return context.tooltipFormat({ label: usCounties.countyNames[code], value: context._dataMap[code] ? context._dataMap[code][1] : "N/A" });
40
+ })
41
+ ;
42
+ }
43
+
44
+ layerUpdate(base) {
45
+ Choropleth.prototype.layerUpdate.apply(this, arguments);
46
+
47
+ this._choroplethData
48
+ .style("stroke", this.meshVisible() ? null : "black")
49
+ ;
50
+
51
+ this.choroPaths = this._choroplethData.selectAll(".shape").data(this.visible() ? this.data() : [], function (d) { return d[0]; });
52
+ const context = this;
53
+ this.choroPaths.enter().append("path")
54
+ .attr("class", "shape")
55
+ .attr("vector-effect", "non-scaling-stroke")
56
+ .call(this._selection.enter.bind(this._selection))
57
+ .on("click", function (d) {
58
+ context.click(context.rowToObj(d), "weight", context._selection.selected(this));
59
+ })
60
+ .on("dblclick", function (d) {
61
+ context.dblclick(context.rowToObj(d), "weight", context._selection.selected(this));
62
+ })
63
+ .on("mouseout.tooltip", this.tooltip.hide)
64
+ .on("mousemove.tooltip", this.tooltip.show)
65
+ .merge(this.choroPaths)
66
+ .attr("d", function (d) {
67
+ const retVal = base._d3GeoPath(rFeatures[d.county]);
68
+ if (!retVal) {
69
+ console.warn("Unknown US County: " + d.county, d);
70
+ }
71
+ return retVal;
72
+ })
73
+ .style("fill", function (d) {
74
+ const retVal = context._palette(d[1], context._dataMinWeight, context._dataMaxWeight);
75
+ return retVal;
76
+ })
77
+ ;
78
+ this.choroPaths.exit().remove();
79
+ }
80
+
81
+ layerPreRender() {
82
+ if (!this._topoJsonPromise) {
83
+ this._topoJsonPromise = new Promise<void>((resolve, reject) => {
84
+ if (usCounties) {
85
+ resolve();
86
+ }
87
+ d3Json(`${topoJsonFolder()}/us-counties.json`, function (_usCounties) {
88
+ usCounties = _usCounties;
89
+ features = topojson.feature(usCounties.topology, usCounties.topology.objects.counties).features;
90
+ rFeatures = {};
91
+ for (const key in features) {
92
+ if (features[key].id) {
93
+ rFeatures[features[key].id] = features[key];
94
+ }
95
+ }
96
+ resolve();
97
+ });
98
+ });
99
+ }
100
+ return this._topoJsonPromise;
101
+ }
102
+ }
103
+ ChoroplethCounties.prototype._class += " map_ChoroplethCounties";
104
+
105
+ export interface ChoroplethCounties {
106
+ onClickFormatFIPS(): boolean;
107
+ onClickFormatFIPS(_: boolean): this;
108
+ onClickFormatFIPS_exists(): boolean;
109
+ }
110
+
111
+ ChoroplethCounties.prototype.publish("onClickFormatFIPS", false, "boolean", "format FIPS code as a String on Click");
@@ -1,100 +1,100 @@
1
- import { json as d3Json } from "d3-request";
2
- import { select as d3Select } from "d3-selection";
3
- import * as topojson from "topojson-client";
4
- import { Choropleth, topoJsonFolder } from "./Choropleth.ts";
5
-
6
- let countries = null;
7
- let features = null;
8
- let rFeatures = null;
9
-
10
- export class ChoroplethCountries extends Choropleth {
11
- _choroTopologyObjectsCountries;
12
- _choroTopologyObjectsLand;
13
- choroPaths;
14
-
15
- constructor() {
16
- super();
17
- }
18
-
19
- layerEnter(base, svgElement, domElement) {
20
- Choropleth.prototype.layerEnter.apply(this, arguments);
21
- this._choroTopology = countries.topology;
22
- this._choroTopologyObjectsCountries = countries.topology.objects.countries;
23
- this._choroTopologyObjectsLand = countries.topology.objects.land;
24
- this._choroTopologyObjects = this._choroTopologyObjectsCountries;
25
-
26
- this._selection.widgetElement(this._choroplethData);
27
- this.choroPaths = d3Select(null);
28
- const context = this;
29
- this
30
- .tooltipHTML(function (d) {
31
- return context.tooltipFormat({ label: d[0], value: d[1] });
32
- })
33
- ;
34
- }
35
-
36
- layerUpdate(base) {
37
- Choropleth.prototype.layerUpdate.apply(this, arguments);
38
-
39
- this._choroplethData
40
- .style("stroke", this.meshVisible() ? null : "black")
41
- ;
42
-
43
- this.choroPaths = this._choroplethData.selectAll(".shape").data(this.visible() ? this.data() : [], function (d) { return d[0]; });
44
- const context = this;
45
- this.choroPaths.enter().append("path")
46
- .attr("class", "shape")
47
- .attr("vector-effect", "non-scaling-stroke")
48
- .call(this._selection.enter.bind(this._selection))
49
- .on("click", function (d) {
50
- if (context._dataMap[d[0]]) {
51
- context.click(context.rowToObj(context._dataMap[d[0]]), "weight", context._selection.selected(this));
52
- }
53
- })
54
- .on("dblclick", function (d) {
55
- if (context._dataMap[d[0]]) {
56
- context.dblclick(context.rowToObj(context._dataMap[d[0]]), "weight", context._selection.selected(this));
57
- }
58
- })
59
- .on("mouseout.tooltip", this.tooltip.hide)
60
- .on("mousemove.tooltip", this.tooltip.show)
61
- .merge(this.choroPaths)
62
- .attr("d", function (d) {
63
- const retVal = base._d3GeoPath(rFeatures[d[0]]);
64
- if (!retVal) {
65
- console.warn("Unknown Country: " + d);
66
- }
67
- return retVal;
68
- })
69
- .style("fill", function (d) {
70
- const retVal = context._palette(d[1], context._dataMinWeight, context._dataMaxWeight);
71
- return retVal;
72
- })
73
- ;
74
- this.choroPaths.exit().remove();
75
- }
76
-
77
- layerPreRender() {
78
- if (!this._topoJsonPromise) {
79
- this._topoJsonPromise = new Promise<void>((resolve, reject) => {
80
- if (countries) {
81
- resolve();
82
- }
83
- d3Json(`${topoJsonFolder()}/countries.json`, function (_countries) {
84
- countries = _countries;
85
- features = topojson.feature(countries.topology, countries.topology.objects.countries).features;
86
- rFeatures = {};
87
- for (const key in features) {
88
- if (features[key].id && countries.countryNames[features[key].id]) {
89
- rFeatures[countries.countryNames[features[key].id].name] = features[key];
90
- }
91
- }
92
- resolve();
93
- });
94
- });
95
- }
96
- return this._topoJsonPromise;
97
- }
98
- }
99
- ChoroplethCountries.prototype._class += " map_ChoroplethCountries";
100
-
1
+ import { json as d3Json } from "d3-request";
2
+ import { select as d3Select } from "d3-selection";
3
+ import * as topojson from "topojson-client";
4
+ import { Choropleth, topoJsonFolder } from "./Choropleth.ts";
5
+
6
+ let countries = null;
7
+ let features = null;
8
+ let rFeatures = null;
9
+
10
+ export class ChoroplethCountries extends Choropleth {
11
+ _choroTopologyObjectsCountries;
12
+ _choroTopologyObjectsLand;
13
+ choroPaths;
14
+
15
+ constructor() {
16
+ super();
17
+ }
18
+
19
+ layerEnter(base, svgElement, domElement) {
20
+ Choropleth.prototype.layerEnter.apply(this, arguments);
21
+ this._choroTopology = countries.topology;
22
+ this._choroTopologyObjectsCountries = countries.topology.objects.countries;
23
+ this._choroTopologyObjectsLand = countries.topology.objects.land;
24
+ this._choroTopologyObjects = this._choroTopologyObjectsCountries;
25
+
26
+ this._selection.widgetElement(this._choroplethData);
27
+ this.choroPaths = d3Select(null);
28
+ const context = this;
29
+ this
30
+ .tooltipHTML(function (d) {
31
+ return context.tooltipFormat({ label: d[0], value: d[1] });
32
+ })
33
+ ;
34
+ }
35
+
36
+ layerUpdate(base) {
37
+ Choropleth.prototype.layerUpdate.apply(this, arguments);
38
+
39
+ this._choroplethData
40
+ .style("stroke", this.meshVisible() ? null : "black")
41
+ ;
42
+
43
+ this.choroPaths = this._choroplethData.selectAll(".shape").data(this.visible() ? this.data() : [], function (d) { return d[0]; });
44
+ const context = this;
45
+ this.choroPaths.enter().append("path")
46
+ .attr("class", "shape")
47
+ .attr("vector-effect", "non-scaling-stroke")
48
+ .call(this._selection.enter.bind(this._selection))
49
+ .on("click", function (d) {
50
+ if (context._dataMap[d[0]]) {
51
+ context.click(context.rowToObj(context._dataMap[d[0]]), "weight", context._selection.selected(this));
52
+ }
53
+ })
54
+ .on("dblclick", function (d) {
55
+ if (context._dataMap[d[0]]) {
56
+ context.dblclick(context.rowToObj(context._dataMap[d[0]]), "weight", context._selection.selected(this));
57
+ }
58
+ })
59
+ .on("mouseout.tooltip", this.tooltip.hide)
60
+ .on("mousemove.tooltip", this.tooltip.show)
61
+ .merge(this.choroPaths)
62
+ .attr("d", function (d) {
63
+ const retVal = base._d3GeoPath(rFeatures[d[0]]);
64
+ if (!retVal) {
65
+ console.warn("Unknown Country: " + d);
66
+ }
67
+ return retVal;
68
+ })
69
+ .style("fill", function (d) {
70
+ const retVal = context._palette(d[1], context._dataMinWeight, context._dataMaxWeight);
71
+ return retVal;
72
+ })
73
+ ;
74
+ this.choroPaths.exit().remove();
75
+ }
76
+
77
+ layerPreRender() {
78
+ if (!this._topoJsonPromise) {
79
+ this._topoJsonPromise = new Promise<void>((resolve, reject) => {
80
+ if (countries) {
81
+ resolve();
82
+ }
83
+ d3Json(`${topoJsonFolder()}/countries.json`, function (_countries) {
84
+ countries = _countries;
85
+ features = topojson.feature(countries.topology, countries.topology.objects.countries).features;
86
+ rFeatures = {};
87
+ for (const key in features) {
88
+ if (features[key].id && countries.countryNames[features[key].id]) {
89
+ rFeatures[countries.countryNames[features[key].id].name] = features[key];
90
+ }
91
+ }
92
+ resolve();
93
+ });
94
+ });
95
+ }
96
+ return this._topoJsonPromise;
97
+ }
98
+ }
99
+ ChoroplethCountries.prototype._class += " map_ChoroplethCountries";
100
+
@@ -1,103 +1,103 @@
1
- import { InputField } from "@hpcc-js/common";
2
- import { json as d3Json } from "d3-request";
3
- import { select as d3Select } from "d3-selection";
4
- import * as topojson from "topojson-client";
5
- import { Choropleth, topoJsonFolder } from "./Choropleth.ts";
6
-
7
- let usStates = null;
8
- let features = null;
9
- let rFeatures = null;
10
-
11
- export class ChoroplethStates extends Choropleth {
12
- static __inputs: InputField[] = [{
13
- id: "state",
14
- type: "string"
15
- }, {
16
- id: "value",
17
- type: "number"
18
- }];
19
-
20
- choroPaths;
21
-
22
- constructor() {
23
- super();
24
-
25
- this.projection("AlbersUsaPr");
26
- }
27
-
28
- layerEnter(base, svgElement, domElement) {
29
- Choropleth.prototype.layerEnter.apply(this, arguments);
30
- this._choroTopology = usStates.topology;
31
- this._choroTopologyObjects = usStates.topology.objects.states;
32
-
33
- this._selection.widgetElement(this._choroplethData);
34
- this.choroPaths = d3Select(null);
35
- const context = this;
36
- this
37
- .tooltipHTML(function (d) {
38
- const code = rFeatures[d[0]].id;
39
- return context.tooltipFormat({ label: usStates.stateNames[code].name, value: d[1] });
40
- })
41
- ;
42
- }
43
-
44
- layerUpdate(base) {
45
- Choropleth.prototype.layerUpdate.apply(this, arguments);
46
-
47
- this._choroplethData
48
- .style("stroke", this.meshVisible() ? null : "black")
49
- ;
50
-
51
- this.choroPaths = this._choroplethData.selectAll(".shape").data(this.visible() ? this.data() : [], function (d) { return d[0]; });
52
- const context = this;
53
- this.choroPaths.enter().append("path")
54
- .attr("class", "shape")
55
- .attr("vector-effect", "non-scaling-stroke")
56
- .call(this._selection.enter.bind(this._selection))
57
- .on("click", function (d) {
58
- context.click(context.rowToObj(d), "weight", context._selection.selected(this));
59
- })
60
- .on("dblclick", function (d) {
61
- context.dblclick(context.rowToObj(d), "weight", context._selection.selected(this));
62
- })
63
- .on("mouseout.tooltip", this.tooltip.hide)
64
- .on("mousemove.tooltip", this.tooltip.show)
65
- .merge(this.choroPaths)
66
- .attr("d", function (d) {
67
- const retVal = base._d3GeoPath(rFeatures[d[0]]);
68
- if (!retVal) {
69
- console.warn("Unknown US State: " + d[0]);
70
- }
71
- return retVal;
72
- })
73
- .style("fill", function (d) {
74
- const retVal = context._palette(d[1], context._dataMinWeight, context._dataMaxWeight);
75
- return retVal;
76
- })
77
- ;
78
- this.choroPaths.exit().remove();
79
- }
80
-
81
- layerPreRender() {
82
- if (!this._topoJsonPromise) {
83
- this._topoJsonPromise = new Promise<void>((resolve, reject) => {
84
- if (usStates) {
85
- resolve();
86
- }
87
- d3Json(`${topoJsonFolder()}/us-states.json`, function (_usStates) {
88
- usStates = _usStates;
89
- features = topojson.feature(usStates.topology, usStates.topology.objects.states).features;
90
- rFeatures = {};
91
- for (const key in features) {
92
- if (features[key].id) {
93
- rFeatures[usStates.stateNames[features[key].id].code] = features[key];
94
- }
95
- }
96
- resolve();
97
- });
98
- });
99
- }
100
- return this._topoJsonPromise;
101
- }
102
- }
103
- ChoroplethStates.prototype._class += " map_ChoroplethStates";
1
+ import { InputField } from "@hpcc-js/common";
2
+ import { json as d3Json } from "d3-request";
3
+ import { select as d3Select } from "d3-selection";
4
+ import * as topojson from "topojson-client";
5
+ import { Choropleth, topoJsonFolder } from "./Choropleth.ts";
6
+
7
+ let usStates = null;
8
+ let features = null;
9
+ let rFeatures = null;
10
+
11
+ export class ChoroplethStates extends Choropleth {
12
+ static __inputs: InputField[] = [{
13
+ id: "state",
14
+ type: "string"
15
+ }, {
16
+ id: "value",
17
+ type: "number"
18
+ }];
19
+
20
+ choroPaths;
21
+
22
+ constructor() {
23
+ super();
24
+
25
+ this.projection("AlbersUsaPr");
26
+ }
27
+
28
+ layerEnter(base, svgElement, domElement) {
29
+ Choropleth.prototype.layerEnter.apply(this, arguments);
30
+ this._choroTopology = usStates.topology;
31
+ this._choroTopologyObjects = usStates.topology.objects.states;
32
+
33
+ this._selection.widgetElement(this._choroplethData);
34
+ this.choroPaths = d3Select(null);
35
+ const context = this;
36
+ this
37
+ .tooltipHTML(function (d) {
38
+ const code = rFeatures[d[0]].id;
39
+ return context.tooltipFormat({ label: usStates.stateNames[code].name, value: d[1] });
40
+ })
41
+ ;
42
+ }
43
+
44
+ layerUpdate(base) {
45
+ Choropleth.prototype.layerUpdate.apply(this, arguments);
46
+
47
+ this._choroplethData
48
+ .style("stroke", this.meshVisible() ? null : "black")
49
+ ;
50
+
51
+ this.choroPaths = this._choroplethData.selectAll(".shape").data(this.visible() ? this.data() : [], function (d) { return d[0]; });
52
+ const context = this;
53
+ this.choroPaths.enter().append("path")
54
+ .attr("class", "shape")
55
+ .attr("vector-effect", "non-scaling-stroke")
56
+ .call(this._selection.enter.bind(this._selection))
57
+ .on("click", function (d) {
58
+ context.click(context.rowToObj(d), "weight", context._selection.selected(this));
59
+ })
60
+ .on("dblclick", function (d) {
61
+ context.dblclick(context.rowToObj(d), "weight", context._selection.selected(this));
62
+ })
63
+ .on("mouseout.tooltip", this.tooltip.hide)
64
+ .on("mousemove.tooltip", this.tooltip.show)
65
+ .merge(this.choroPaths)
66
+ .attr("d", function (d) {
67
+ const retVal = base._d3GeoPath(rFeatures[d[0]]);
68
+ if (!retVal) {
69
+ console.warn("Unknown US State: " + d[0]);
70
+ }
71
+ return retVal;
72
+ })
73
+ .style("fill", function (d) {
74
+ const retVal = context._palette(d[1], context._dataMinWeight, context._dataMaxWeight);
75
+ return retVal;
76
+ })
77
+ ;
78
+ this.choroPaths.exit().remove();
79
+ }
80
+
81
+ layerPreRender() {
82
+ if (!this._topoJsonPromise) {
83
+ this._topoJsonPromise = new Promise<void>((resolve, reject) => {
84
+ if (usStates) {
85
+ resolve();
86
+ }
87
+ d3Json(`${topoJsonFolder()}/us-states.json`, function (_usStates) {
88
+ usStates = _usStates;
89
+ features = topojson.feature(usStates.topology, usStates.topology.objects.states).features;
90
+ rFeatures = {};
91
+ for (const key in features) {
92
+ if (features[key].id) {
93
+ rFeatures[usStates.stateNames[features[key].id].code] = features[key];
94
+ }
95
+ }
96
+ resolve();
97
+ });
98
+ });
99
+ }
100
+ return this._topoJsonPromise;
101
+ }
102
+ }
103
+ ChoroplethStates.prototype._class += " map_ChoroplethStates";
@@ -1,8 +1,8 @@
1
- import { Layered } from "./Layered.ts";
2
-
3
- export class ChoroplethStatesHeat extends Layered {
4
- constructor() {
5
- super();
6
- }
7
- }
8
- ChoroplethStatesHeat.prototype._class += " map_ChoroplethStatesHeat";
1
+ import { Layered } from "./Layered.ts";
2
+
3
+ export class ChoroplethStatesHeat extends Layered {
4
+ constructor() {
5
+ super();
6
+ }
7
+ }
8
+ ChoroplethStatesHeat.prototype._class += " map_ChoroplethStatesHeat";