geojs 1.6.5 → 1.7.2
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/CHANGELOG.md +18 -0
- package/geo.js +963 -288
- package/geo.lean.js +963 -288
- package/geo.lean.min.js +3 -3
- package/geo.min.js +5 -5
- package/package.json +17 -15
- package/src/canvas/pixelmapFeature.js +208 -0
- package/src/index.js +1 -0
- package/src/pixelmapFeature.js +97 -249
- package/src/pixelmapLayer.js +145 -0
- package/src/quadFeature.js +1 -1
- package/src/tileLayer.js +8 -2
- package/src/webgl/index.js +2 -0
- package/src/webgl/lookupTable2D.js +122 -0
- package/src/webgl/pixelmapFeature.frag +47 -0
- package/src/webgl/pixelmapFeature.js +203 -0
- package/src/webgl/quadFeature.js +41 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geojs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"description": "JavaScript Geo Visualization and Analysis Library",
|
|
5
5
|
"homepage": "https://github.com/OpenGeoscience/geojs",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"vtk.js": "*"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@babel/core": "^7.
|
|
33
|
+
"@babel/core": "^7.17.0",
|
|
34
34
|
"@babel/plugin-proposal-class-properties": "^7.16.5",
|
|
35
35
|
"@babel/preset-env": "^7.16.5",
|
|
36
36
|
"@jsdevtools/coverage-istanbul-loader": "^3.0.5",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"bootswatch": "^3.4.1",
|
|
41
41
|
"codemirror": "^5.65.0",
|
|
42
42
|
"colorbrewer": "^1.5.1",
|
|
43
|
-
"css-loader": "^6.
|
|
43
|
+
"css-loader": "^6.6.0",
|
|
44
44
|
"docco": "^0.9.1",
|
|
45
45
|
"eslint": "^7.12.1",
|
|
46
46
|
"eslint-config-semistandard": "^16.0.0",
|
|
@@ -57,13 +57,13 @@
|
|
|
57
57
|
"jaguarjs-jsdoc": "^1.0.2",
|
|
58
58
|
"jasmine-core": "^4.0.0",
|
|
59
59
|
"js-yaml": "^4.1.0",
|
|
60
|
-
"jsdoc": "^3.6.
|
|
60
|
+
"jsdoc": "^3.6.10",
|
|
61
61
|
"jsdoc-autoprivate": "0.0.1",
|
|
62
62
|
"jsonlint-mod": "^1.7.6",
|
|
63
63
|
"jstransformer-markdown-it": "^2.0.0",
|
|
64
|
-
"karma": "^6.3.
|
|
64
|
+
"karma": "^6.3.15",
|
|
65
65
|
"karma-chrome-launcher": "^3.1.0",
|
|
66
|
-
"karma-coverage": "^2.1.
|
|
66
|
+
"karma-coverage": "^2.1.1",
|
|
67
67
|
"karma-firefox-launcher": "^2.1.2",
|
|
68
68
|
"karma-jasmine": "^4.0.1",
|
|
69
69
|
"karma-jasmine-html-reporter": "^1.7.0",
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"karma-spec-reporter": "^0.0.33",
|
|
73
73
|
"karma-webpack": "^5.0.0",
|
|
74
74
|
"nib": "^1.1.2",
|
|
75
|
+
"npm-run-all": "^4.1.5",
|
|
75
76
|
"pako": "^2.0.4",
|
|
76
77
|
"pug": "^3.0.2",
|
|
77
78
|
"pug-lint": "^2.6.0",
|
|
@@ -124,7 +125,9 @@
|
|
|
124
125
|
]
|
|
125
126
|
},
|
|
126
127
|
"scripts": {
|
|
127
|
-
"build": "
|
|
128
|
+
"build": "npm-run-all -p build-full build-lean",
|
|
129
|
+
"build-full": "webpack --config webpack.config.js",
|
|
130
|
+
"build-lean": "webpack --config webpack-lean.config.js",
|
|
128
131
|
"build-examples": "node examples/build.js && webpack --config webpack-examples.config.js",
|
|
129
132
|
"build-website-examples": "node examples/build-website.js && webpack --config webpack-website-examples.config.js",
|
|
130
133
|
"build-tutorials": "node tutorials/build.js && webpack --config webpack-tutorials.config.js",
|
|
@@ -143,19 +146,18 @@
|
|
|
143
146
|
"test-tutorialsci-all": "GEOJS_TEST_CASE=tests/tutorials.js karma start karma-cov.conf.js --single-run --browsers ChromeHeadlessTouch,FirefoxHeadlessTouch",
|
|
144
147
|
"get-data-files": "node scripts/datastore.js dist/data",
|
|
145
148
|
"ci-clean": "git clean -fxd dist -e dist/data jsdoc/tmpl jsdoc/static images lcov",
|
|
146
|
-
"ci": "npm
|
|
147
|
-
"ci-build": "
|
|
148
|
-
"ci-
|
|
149
|
-
"ci-
|
|
150
|
-
"ci-xvfb": "npm run ci-clean && npm run ci-build && TEST_SAVE_IMAGE='all' xvfb-run -s '-ac -screen 0 1280x1024x24' npm run ci-test",
|
|
149
|
+
"ci": "npm-run-all ci-build ci-test",
|
|
150
|
+
"ci-build": "npm-run-all -c -p build-full build-lean docs get-data-files lint puglint glsllint build-examples build-tutorials",
|
|
151
|
+
"ci-test": "npm-run-all test-headless test-webglheadless test-headed test-tutorials",
|
|
152
|
+
"ci-xvfb": "npm-run-all ci-clean ci-build && TEST_SAVE_IMAGE='all' xvfb-run -s '-ac -screen 0 1280x1024x24' npm run ci-test",
|
|
151
153
|
"start": "karma start karma.conf.js",
|
|
152
|
-
"examples": "
|
|
154
|
+
"examples": "npm-run-all -p build-examples build-tutorials && node ./tests/runners/server.js --host \"${HOST-}\" --port ${PORT-8082} --dist",
|
|
153
155
|
"docs": "jsdoc --pedantic -d dist/apidocs -r src package.json -c jsdoc.conf.json",
|
|
154
156
|
"website": "cd website && npx hexo server",
|
|
155
157
|
"setup-website": "cd website && npm install",
|
|
156
|
-
"build-website": "npm
|
|
158
|
+
"build-website": "npm-run-all ci-build ci-build-website",
|
|
157
159
|
"ci-build-website": "cp -a dist/built/. website/source/built && bash -c '(npm run build-website-examples & npm run build-website-tutorials & wait -n && wait -n)' && cd dist && cp -ar data ../website/source/. && rm -rf ../website/source/data/tiles && rm -rf ../website/source/data/tiles.tgz && rm -rf ../website/source/data/base-images && rm -rf ../website/source/data/base-images.tgz && cp -ar apidocs/. ../website/source/apidocs && cd ../website && npm install && rm -f db.json && npx hexo generate",
|
|
158
|
-
"prepublishOnly": "
|
|
160
|
+
"prepublishOnly": "npm run build && cp dist/built/*.js .",
|
|
159
161
|
"semantic-release": "semantic-release"
|
|
160
162
|
},
|
|
161
163
|
"keywords": [
|
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
var inherit = require('../inherit');
|
|
2
2
|
var registerFeature = require('../registry').registerFeature;
|
|
3
3
|
var pixelmapFeature = require('../pixelmapFeature');
|
|
4
|
+
var geo_event = require('../event');
|
|
5
|
+
var util = require('../util');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Pixelmap feature information record.
|
|
9
|
+
*
|
|
10
|
+
* @typedef {object} geo.pixelmapFeature.info
|
|
11
|
+
* @property {number} width The width of the source image.
|
|
12
|
+
* @property {number} height The width of the source image.
|
|
13
|
+
* @property {CanvasRenderingContext2D} context The HTMLCanvasElement context
|
|
14
|
+
* used for handling the pixelmap.
|
|
15
|
+
* @property {ImageData} imageData The context's image data.
|
|
16
|
+
* @property {number[]} indices An array, one per pixel, of the index value in
|
|
17
|
+
* the image. This decodes the pixel value to the corresponding integer.
|
|
18
|
+
* @property number} area The number of pixels in the image. This is
|
|
19
|
+
* `width * height`.
|
|
20
|
+
* @property {object[]} mappedColors This has one entry for each distinct index
|
|
21
|
+
* value. Each entry has `first` and `last` with the first and last pixel
|
|
22
|
+
* locations where that index occurs. Note that last is the inclusive value
|
|
23
|
+
* of the location (so its maximum possible value is `size - 1`).
|
|
24
|
+
*/
|
|
4
25
|
|
|
5
26
|
/**
|
|
6
27
|
* Create a new instance of class pixelmapFeature.
|
|
@@ -22,6 +43,193 @@ var canvas_pixelmapFeature = function (arg) {
|
|
|
22
43
|
var object = require('./object');
|
|
23
44
|
object.call(this);
|
|
24
45
|
|
|
46
|
+
var m_quadFeature,
|
|
47
|
+
s_exit = this._exit,
|
|
48
|
+
m_this = this;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* If the specified coordinates are in the rendered quad, use the basis
|
|
52
|
+
* information from the quad to determine the pixelmap index value so that it
|
|
53
|
+
* can be included in the `found` results.
|
|
54
|
+
*
|
|
55
|
+
* @param {geo.geoPosition} geo Coordinate.
|
|
56
|
+
* @param {string|geo.transform|null} [gcs] Input gcs. `undefined` to use
|
|
57
|
+
* the interface gcs, `null` to use the map gcs, or any other transform.
|
|
58
|
+
* @returns {geo.feature.searchResult} An object with a list of features and
|
|
59
|
+
* feature indices that are located at the specified point.
|
|
60
|
+
*/
|
|
61
|
+
this.pointSearch = function (geo, gcs) {
|
|
62
|
+
if (m_quadFeature && m_this.m_info) {
|
|
63
|
+
var result = m_quadFeature.pointSearch(geo, gcs);
|
|
64
|
+
if (result.index.length === 1 && result.extra && result.extra[result.index[0]].basis) {
|
|
65
|
+
var basis = result.extra[result.index[0]].basis, x, y, idx;
|
|
66
|
+
x = Math.floor(basis.x * m_this.m_info.width);
|
|
67
|
+
y = Math.floor(basis.y * m_this.m_info.height);
|
|
68
|
+
if (x >= 0 && x < m_this.m_info.width &&
|
|
69
|
+
y >= 0 && y < m_this.m_info.height) {
|
|
70
|
+
idx = m_this.m_info.indices[y * m_this.m_info.width + x];
|
|
71
|
+
result = {
|
|
72
|
+
index: [idx],
|
|
73
|
+
found: [m_this.data()[idx]]
|
|
74
|
+
};
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return {index: [], found: []};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Compute information for this pixelmap image. It is wasteful to call this
|
|
84
|
+
* if the pixelmap has already been prepared (it is invalidated by a change
|
|
85
|
+
* in the image).
|
|
86
|
+
*
|
|
87
|
+
* @returns {geo.pixelmapFeature.info}
|
|
88
|
+
*/
|
|
89
|
+
this._preparePixelmap = function () {
|
|
90
|
+
var i, idx, pixelData;
|
|
91
|
+
|
|
92
|
+
if (!util.isReadyImage(m_this.m_srcImage)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
m_this.m_info = {
|
|
96
|
+
width: m_this.m_srcImage.naturalWidth,
|
|
97
|
+
height: m_this.m_srcImage.naturalHeight,
|
|
98
|
+
canvas: document.createElement('canvas')
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
m_this.m_info.canvas.width = m_this.m_info.width;
|
|
102
|
+
m_this.m_info.canvas.height = m_this.m_info.height;
|
|
103
|
+
m_this.m_info.context = m_this.m_info.canvas.getContext('2d');
|
|
104
|
+
|
|
105
|
+
m_this.m_info.context.drawImage(m_this.m_srcImage, 0, 0);
|
|
106
|
+
m_this.m_info.imageData = m_this.m_info.context.getImageData(
|
|
107
|
+
0, 0, m_this.m_info.canvas.width, m_this.m_info.canvas.height);
|
|
108
|
+
pixelData = m_this.m_info.imageData.data;
|
|
109
|
+
m_this.m_info.indices = new Array(pixelData.length / 4);
|
|
110
|
+
m_this.m_info.area = pixelData.length / 4;
|
|
111
|
+
|
|
112
|
+
m_this.m_info.mappedColors = {};
|
|
113
|
+
for (i = 0; i < pixelData.length; i += 4) {
|
|
114
|
+
idx = pixelData[i] + (pixelData[i + 1] << 8) + (pixelData[i + 2] << 16);
|
|
115
|
+
m_this.m_info.indices[i / 4] = idx;
|
|
116
|
+
if (!m_this.m_info.mappedColors[idx]) {
|
|
117
|
+
m_this.m_info.mappedColors[idx] = {first: i / 4};
|
|
118
|
+
}
|
|
119
|
+
m_this.m_info.mappedColors[idx].last = i / 4;
|
|
120
|
+
}
|
|
121
|
+
return m_this.m_info;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Given the loaded pixelmap image, create a canvas the size of the image.
|
|
126
|
+
* Compute a color for each distinct index and recolor the canvas based on
|
|
127
|
+
* these colors, then draw the resultant image as a quad.
|
|
128
|
+
*
|
|
129
|
+
* @fires geo.event.pixelmap.prepared
|
|
130
|
+
*/
|
|
131
|
+
this._computePixelmap = function () {
|
|
132
|
+
var data = m_this.data() || [],
|
|
133
|
+
colorFunc = m_this.style.get('color'),
|
|
134
|
+
i, idx, lastidx, color, pixelData, indices, mappedColors,
|
|
135
|
+
updateFirst, updateLast = -1, update, prepared;
|
|
136
|
+
|
|
137
|
+
if (!m_this.m_info) {
|
|
138
|
+
m_this.indexModified(undefined, 'clear');
|
|
139
|
+
if (!m_this._preparePixelmap()) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
prepared = true;
|
|
143
|
+
}
|
|
144
|
+
m_this.indexModified(undefined, 'clear');
|
|
145
|
+
mappedColors = m_this.m_info.mappedColors;
|
|
146
|
+
updateFirst = m_this.m_info.area;
|
|
147
|
+
for (idx in mappedColors) {
|
|
148
|
+
if (mappedColors.hasOwnProperty(idx)) {
|
|
149
|
+
color = colorFunc(data[idx], +idx) || {};
|
|
150
|
+
color = [
|
|
151
|
+
(color.r || 0) * 255,
|
|
152
|
+
(color.g || 0) * 255,
|
|
153
|
+
(color.b || 0) * 255,
|
|
154
|
+
color.a === undefined ? 255 : (color.a * 255)
|
|
155
|
+
];
|
|
156
|
+
mappedColors[idx].update = (
|
|
157
|
+
!mappedColors[idx].color ||
|
|
158
|
+
mappedColors[idx].color[0] !== color[0] ||
|
|
159
|
+
mappedColors[idx].color[1] !== color[1] ||
|
|
160
|
+
mappedColors[idx].color[2] !== color[2] ||
|
|
161
|
+
mappedColors[idx].color[3] !== color[3]);
|
|
162
|
+
if (mappedColors[idx].update) {
|
|
163
|
+
mappedColors[idx].color = color;
|
|
164
|
+
updateFirst = Math.min(mappedColors[idx].first, updateFirst);
|
|
165
|
+
updateLast = Math.max(mappedColors[idx].last, updateLast);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/* If nothing was updated, we are done */
|
|
170
|
+
if (updateFirst >= updateLast) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
/* Update only the extent that has changed */
|
|
174
|
+
pixelData = m_this.m_info.imageData.data;
|
|
175
|
+
indices = m_this.m_info.indices;
|
|
176
|
+
for (i = updateFirst; i <= updateLast; i += 1) {
|
|
177
|
+
idx = indices[i];
|
|
178
|
+
if (idx !== lastidx) {
|
|
179
|
+
lastidx = idx;
|
|
180
|
+
color = mappedColors[idx].color;
|
|
181
|
+
update = mappedColors[idx].update;
|
|
182
|
+
}
|
|
183
|
+
if (update) {
|
|
184
|
+
pixelData[i * 4] = color[0];
|
|
185
|
+
pixelData[i * 4 + 1] = color[1];
|
|
186
|
+
pixelData[i * 4 + 2] = color[2];
|
|
187
|
+
pixelData[i * 4 + 3] = color[3];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/* Place the updated area into the canvas */
|
|
191
|
+
m_this.m_info.context.putImageData(
|
|
192
|
+
m_this.m_info.imageData, 0, 0, 0, Math.floor(updateFirst / m_this.m_info.width),
|
|
193
|
+
m_this.m_info.width, Math.ceil((updateLast + 1) / m_this.m_info.width));
|
|
194
|
+
|
|
195
|
+
/* If we haven't made a quad feature, make one now. The quad feature needs
|
|
196
|
+
* to have the canvas capability. */
|
|
197
|
+
if (!m_quadFeature) {
|
|
198
|
+
m_quadFeature = m_this.layer().createFeature('quad', {
|
|
199
|
+
selectionAPI: false,
|
|
200
|
+
gcs: m_this.gcs(),
|
|
201
|
+
visible: m_this.visible(undefined, true)
|
|
202
|
+
});
|
|
203
|
+
m_this.dependentFeatures([m_quadFeature]);
|
|
204
|
+
m_quadFeature.style({
|
|
205
|
+
image: m_this.m_info.canvas,
|
|
206
|
+
position: m_this.style.get('position')})
|
|
207
|
+
.data([{}])
|
|
208
|
+
.draw();
|
|
209
|
+
}
|
|
210
|
+
/* If we prepared the pixelmap and rendered it, send a prepared event */
|
|
211
|
+
if (prepared) {
|
|
212
|
+
m_this.geoTrigger(geo_event.pixelmap.prepared, {
|
|
213
|
+
pixelmap: m_this
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Destroy. Deletes the associated quadFeature.
|
|
220
|
+
*
|
|
221
|
+
* @returns {this}
|
|
222
|
+
*/
|
|
223
|
+
this._exit = function () {
|
|
224
|
+
if (m_quadFeature && m_this.layer()) {
|
|
225
|
+
m_this.layer().deleteFeature(m_quadFeature);
|
|
226
|
+
m_quadFeature = null;
|
|
227
|
+
m_this.dependentFeatures([]);
|
|
228
|
+
}
|
|
229
|
+
s_exit();
|
|
230
|
+
return m_this;
|
|
231
|
+
};
|
|
232
|
+
|
|
25
233
|
this._init(arg);
|
|
26
234
|
return this;
|
|
27
235
|
};
|
package/src/index.js
CHANGED
|
@@ -77,6 +77,7 @@ module.exports = $.extend({
|
|
|
77
77
|
polygonFeature: require('./polygonFeature'),
|
|
78
78
|
quadFeature: require('./quadFeature'),
|
|
79
79
|
pixelmapFeature: require('./pixelmapFeature'),
|
|
80
|
+
pixelmapLayer: require('./pixelmapLayer'),
|
|
80
81
|
renderer: require('./renderer'),
|
|
81
82
|
sceneObject: require('./sceneObject'),
|
|
82
83
|
textFeature: require('./textFeature'),
|