geojs 1.6.4 → 1.7.1
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 +19 -1
- package/geo.js +978 -303
- package/geo.lean.js +978 -303
- package/geo.lean.min.js +3 -3
- package/geo.min.js +5 -5
- package/package.json +1 -1
- package/src/annotation.js +2 -2
- package/src/annotationLayer.js +4 -4
- package/src/canvas/pixelmapFeature.js +208 -0
- package/src/index.js +1 -0
- package/src/lineFeature.js +3 -3
- package/src/pixelmapFeature.js +97 -249
- package/src/pixelmapLayer.js +145 -0
- package/src/polygonFeature.js +3 -3
- package/src/quadFeature.js +1 -1
- package/src/tileLayer.js +3 -2
- package/src/util/common.js +3 -3
- 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
package/src/annotation.js
CHANGED
|
@@ -1128,7 +1128,7 @@ function continuousVerticesProcessAction(m_this, evt, name) {
|
|
|
1128
1128
|
return;
|
|
1129
1129
|
}
|
|
1130
1130
|
var cpp = layer.options('continuousPointProximity');
|
|
1131
|
-
var cpc = layer.options('
|
|
1131
|
+
var cpc = layer.options('continuousPointCollinearity');
|
|
1132
1132
|
var ccp = layer.options('continuousCloseProximity');
|
|
1133
1133
|
if (cpp || cpp === 0) {
|
|
1134
1134
|
var vertices = m_this.options('vertices');
|
|
@@ -1140,7 +1140,7 @@ function continuousVerticesProcessAction(m_this, evt, name) {
|
|
|
1140
1140
|
}
|
|
1141
1141
|
var dist = layer.displayDistance(vertices[vertices.length - 2], null, evt.mouse.map, 'display');
|
|
1142
1142
|
if (dist && dist > cpp) {
|
|
1143
|
-
// combine nearly
|
|
1143
|
+
// combine nearly collinear points
|
|
1144
1144
|
if (vertices.length >= (m_this._lastClickVertexCount || 1) + 3) {
|
|
1145
1145
|
var d01 = layer.displayDistance(vertices[vertices.length - 3], null, vertices[vertices.length - 2], null),
|
|
1146
1146
|
d12 = dist,
|
package/src/annotationLayer.js
CHANGED
|
@@ -21,9 +21,9 @@ var textFeature = require('./textFeature');
|
|
|
21
21
|
* @property {number} [continuousPointProximity=5] The minimum distance in
|
|
22
22
|
* display coordinates (pixels) between two adjacent points when dragging
|
|
23
23
|
* to create an annotation. `false` disables continuous drawing mode.
|
|
24
|
-
* @property {number} [
|
|
24
|
+
* @property {number} [continuousPointCollinearity=1.0deg] The minimum angle
|
|
25
25
|
* between a series of three points when dragging to not interpret them as
|
|
26
|
-
*
|
|
26
|
+
* collinear. Only applies if `continuousPointProximity` is not `false`.
|
|
27
27
|
* @property {number} [continuousCloseProximity=10] The minimum distance in
|
|
28
28
|
* display coordinates (pixels) to close a polygon or end drawing a line when
|
|
29
29
|
* dragging to create an annotation. `false` never closes at the end of a
|
|
@@ -135,8 +135,8 @@ var annotationLayer = function (arg) {
|
|
|
135
135
|
// continuous drawing modes.
|
|
136
136
|
continuousPointProximity: 5,
|
|
137
137
|
// in radians, minimum angle between continuous points to interpret them as
|
|
138
|
-
// being
|
|
139
|
-
|
|
138
|
+
// being collinear
|
|
139
|
+
continuousPointCollinearity: 1.0 * Math.PI / 180,
|
|
140
140
|
continuousCloseProximity: 10, // in pixels, 0 is exact
|
|
141
141
|
finalPointProximity: 10, // in pixels, 0 is exact
|
|
142
142
|
showLabels: true,
|
|
@@ -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'),
|
package/src/lineFeature.js
CHANGED
|
@@ -396,9 +396,9 @@ var lineFeature = function (arg) {
|
|
|
396
396
|
*
|
|
397
397
|
* @param {array} data A new data array.
|
|
398
398
|
* @param {number} [tolerance] The maximum variation allowed in map.gcs
|
|
399
|
-
* units. A value of zero will only remove perfectly
|
|
400
|
-
* not specified, this is set to a half display pixel at the map's
|
|
401
|
-
* zoom level.
|
|
399
|
+
* units. A value of zero will only remove perfectly collinear points.
|
|
400
|
+
* If not specified, this is set to a half display pixel at the map's
|
|
401
|
+
* current zoom level.
|
|
402
402
|
* @param {function} [posFunc=this.style.get('position')] The function to
|
|
403
403
|
* get the position of each vertex.
|
|
404
404
|
* @param {function} [lineFunc=this.style.get('line')] The function to get
|