gridviz 3.0.10 → 3.0.11
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.
- package/dist/gridviz.js +91 -21
- package/dist/gridviz.min.js +1 -1
- package/package.json +1 -1
- package/src/layer/GeoJSONLayer.js +94 -24
package/package.json
CHANGED
|
@@ -29,11 +29,40 @@ export class GeoJSONLayer extends Layer {
|
|
|
29
29
|
* @type {function(object):boolean} */
|
|
30
30
|
this.preprocess = opts.preprocess
|
|
31
31
|
|
|
32
|
+
//for points
|
|
33
|
+
/**
|
|
34
|
+
* @private
|
|
35
|
+
* @type {function(object,number):string} */
|
|
36
|
+
this.shape = opts.shape || ((f, z) => 'circle')
|
|
37
|
+
/**
|
|
38
|
+
* In pixel
|
|
39
|
+
* @private
|
|
40
|
+
* @type {function(object,number):number} */
|
|
41
|
+
this.size = opts.size || ((f, z) => 10)
|
|
42
|
+
/**
|
|
43
|
+
* @private
|
|
44
|
+
* @type {function(object,number):string} */
|
|
45
|
+
this.strokeStyle = opts.strokeStyle || ((f, z) => 'red')
|
|
46
|
+
/**
|
|
47
|
+
* @private
|
|
48
|
+
* @type {function(object,number):string} */
|
|
49
|
+
this.fillStyle = opts.fillStyle || ((f, z) => 'black')
|
|
50
|
+
/**
|
|
51
|
+
* In pixel
|
|
52
|
+
* @private
|
|
53
|
+
* @type {function(object,number):number} */
|
|
54
|
+
this.lineWidth = opts.lineWidth || ((f, z) => 2)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
//for lines
|
|
59
|
+
|
|
32
60
|
/**
|
|
33
61
|
* @private
|
|
34
62
|
* @type {function(object,number):string} */
|
|
35
63
|
this.color = opts.color || ((f, z) => 'gray')
|
|
36
64
|
/**
|
|
65
|
+
* In pixel
|
|
37
66
|
* @private
|
|
38
67
|
* @type {function(object,number):number} */
|
|
39
68
|
this.width = opts.width || ((f, z) => 2)
|
|
@@ -42,6 +71,7 @@ export class GeoJSONLayer extends Layer {
|
|
|
42
71
|
* @type {function(object,number):Array.<number>|undefined} */
|
|
43
72
|
this.lineDash = opts.lineDash || ((f, z) => undefined)
|
|
44
73
|
|
|
74
|
+
|
|
45
75
|
/**
|
|
46
76
|
* @private
|
|
47
77
|
* @type {Array.<object> | undefined} */
|
|
@@ -53,6 +83,7 @@ export class GeoJSONLayer extends Layer {
|
|
|
53
83
|
this.loadingStatus = 'notLoaded'
|
|
54
84
|
}
|
|
55
85
|
|
|
86
|
+
|
|
56
87
|
/**
|
|
57
88
|
* Draw the layer.
|
|
58
89
|
* @param {import("../core/GeoCanvas.js").GeoCanvas} geoCanvas The canvas where to draw the layer.
|
|
@@ -65,34 +96,73 @@ export class GeoJSONLayer extends Layer {
|
|
|
65
96
|
return
|
|
66
97
|
}
|
|
67
98
|
|
|
68
|
-
//TODO sort lines by width ?
|
|
69
|
-
|
|
70
99
|
//
|
|
71
100
|
const z = geoCanvas.view.z
|
|
72
101
|
|
|
73
102
|
for (const f of this.fs) {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
const gt = f.geometry.type
|
|
104
|
+
|
|
105
|
+
if (gt == "Point") {
|
|
106
|
+
const c = f.geometry.coordinates
|
|
107
|
+
|
|
108
|
+
//get style parameters for the point feature
|
|
109
|
+
const shape = this.shape(f,z)
|
|
110
|
+
if(!shape || shape=="none") continue
|
|
111
|
+
const size = this.size(f,z) * z
|
|
112
|
+
if(!size) continue
|
|
113
|
+
const strokeStyle = this.strokeStyle(f,z)
|
|
114
|
+
const fillStyle = this.fillStyle(f,z)
|
|
115
|
+
const lineWidth = this.lineWidth(f,z) * z
|
|
116
|
+
|
|
117
|
+
//set canvas drawing parameters
|
|
118
|
+
if(strokeStyle) geoCanvas.ctx.strokeStyle = strokeStyle
|
|
119
|
+
if(fillStyle) geoCanvas.ctx.fillStyle = fillStyle
|
|
120
|
+
if(lineWidth) geoCanvas.ctx.lineWidth = lineWidth
|
|
121
|
+
|
|
122
|
+
if (shape == "circle") {
|
|
123
|
+
//draw circle - fill and stroke
|
|
124
|
+
geoCanvas.ctx.beginPath()
|
|
125
|
+
geoCanvas.ctx.arc(c[0], c[1], size / 2, 0, 2 * Math.PI, false)
|
|
126
|
+
if(fillStyle) geoCanvas.ctx.fill()
|
|
127
|
+
if(strokeStyle && lineWidth) geoCanvas.ctx.stroke()
|
|
128
|
+
} else if (shape == "square") {
|
|
129
|
+
//draw square - fill and stroke
|
|
130
|
+
geoCanvas.ctx.beginPath()
|
|
131
|
+
geoCanvas.ctx.rect(c[0] - size / 2, c[1] - size / 2, size, size)
|
|
132
|
+
if(fillStyle) geoCanvas.ctx.fill()
|
|
133
|
+
if(strokeStyle && lineWidth) geoCanvas.ctx.stroke()
|
|
134
|
+
} else {
|
|
135
|
+
console.error("Unexpected shape for point geojson: " + shape)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
} else if (gt == "LineString") {
|
|
139
|
+
|
|
140
|
+
const cs = f.geometry.coordinates
|
|
141
|
+
if (cs.length < 2) continue
|
|
142
|
+
|
|
143
|
+
//set color
|
|
144
|
+
const col = this.color(f, z)
|
|
145
|
+
if (!col || col == 'none') continue
|
|
146
|
+
geoCanvas.ctx.strokeStyle = col
|
|
147
|
+
|
|
148
|
+
//set linewidth
|
|
149
|
+
const wP = this.width(f, z)
|
|
150
|
+
if (!wP || wP < 0) continue
|
|
151
|
+
geoCanvas.ctx.lineWidth = wP * z
|
|
152
|
+
|
|
153
|
+
//set line dash
|
|
154
|
+
const ldP = this.lineDash(f, z)
|
|
155
|
+
if (ldP) geoCanvas.ctx.setLineDash(ldP)
|
|
156
|
+
|
|
157
|
+
//draw line
|
|
158
|
+
geoCanvas.ctx.beginPath()
|
|
159
|
+
geoCanvas.ctx.moveTo(cs[0][0], cs[0][1])
|
|
160
|
+
for (let i = 1; i < cs.length; i++) geoCanvas.ctx.lineTo(cs[i][0], cs[i][1])
|
|
161
|
+
geoCanvas.ctx.stroke()
|
|
162
|
+
} else {
|
|
163
|
+
console.log("Unsupported geometry type in GeoJSONLayer: " + gt)
|
|
164
|
+
}
|
|
165
|
+
|
|
96
166
|
}
|
|
97
167
|
|
|
98
168
|
//...
|