Skip to content

Commit 0581d3d

Browse files
committed
feature(Style): support mapbox expression.
1 parent d77c8d6 commit 0581d3d

File tree

4 files changed

+246
-139
lines changed

4 files changed

+246
-139
lines changed

src/Converter/Feature2Texture.js

+22-17
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ function _drawPolygon(ctx, vertices, indices, style, size, extent, invCtxScale,
3636
}
3737

3838
// draw line or edge of polygon
39-
if (style.stroke.color) {
39+
if (style.stroke) {
4040
strokeStyle(style, ctx, invCtxScale);
4141
ctx.stroke();
4242
}
4343

4444
// fill polygon only
45-
if (canBeFilled && (style.fill.color || style.fill.pattern)) {
45+
if (canBeFilled && style.fill) {
4646
fillStyle(style, ctx, invCtxScale);
4747
ctx.fill();
4848
}
@@ -56,7 +56,7 @@ function fillStyle(style, ctx, invCtxScale) {
5656
} else {
5757
console.warn('Raster pattern isn\'t completely supported on Ie and edge');
5858
}
59-
} else if (style.fill.color && ctx.fillStyle !== style.fill.color) {
59+
} else if (ctx.fillStyle !== style.fill.color) {
6060
ctx.fillStyle = style.fill.color;
6161
}
6262
if (style.fill.opacity !== ctx.globalAlpha) {
@@ -106,26 +106,31 @@ const coord = new Coordinates('EPSG:4326', 0, 0, 0);
106106
function drawFeature(ctx, feature, extent, style, invCtxScale) {
107107
const extentDim = extent.dimensions();
108108
const scaleRadius = extentDim.x / ctx.canvas.width;
109+
const globals = { zoom: extent.zoom };
109110

110111
for (const geometry of feature.geometries) {
111112
if (geometry.extent.intersectsExtent(extent)) {
112-
const geoStyle = geometry.properties.style || style;
113-
if (feature.type === FEATURE_TYPES.POINT) {
114-
// cross multiplication to know in the extent system the real size of
115-
// the point
116-
const px = (Math.round(geoStyle.point.radius * invCtxScale) || 3 * invCtxScale) * scaleRadius;
117-
for (const indice of geometry.indices) {
118-
const offset = indice.offset * feature.size;
119-
const count = offset + indice.count * feature.size;
120-
for (let j = offset; j < count; j += feature.size) {
121-
coord.setFromArray(feature.vertices, j);
122-
if (extent.isPointInside(coord, px)) {
123-
drawPoint(ctx, feature.vertices[j], feature.vertices[j + 1], geoStyle, invCtxScale);
113+
const context = { globals, properties: () => geometry.properties };
114+
const contextStyle = (geometry.properties.style || style).drawingStylefromContext(context);
115+
116+
if (contextStyle) {
117+
if (feature.type === FEATURE_TYPES.POINT) {
118+
// cross multiplication to know in the extent system the real size of
119+
// the point
120+
const px = (Math.round(contextStyle.point.radius * invCtxScale) || 3 * invCtxScale) * scaleRadius;
121+
for (const indice of geometry.indices) {
122+
const offset = indice.offset * feature.size;
123+
const count = offset + indice.count * feature.size;
124+
for (let j = offset; j < count; j += feature.size) {
125+
coord.setFromArray(feature.vertices, j);
126+
if (extent.isPointInside(coord, px)) {
127+
drawPoint(ctx, feature.vertices[j], feature.vertices[j + 1], contextStyle, invCtxScale);
128+
}
124129
}
125130
}
131+
} else {
132+
drawPolygon(ctx, feature.vertices, geometry.indices, contextStyle, feature.size, extent, invCtxScale, (feature.type == FEATURE_TYPES.POLYGON));
126133
}
127-
} else {
128-
drawPolygon(ctx, feature.vertices, geometry.indices, geoStyle, feature.size, extent, invCtxScale, (feature.type == FEATURE_TYPES.POLYGON));
129134
}
130135
}
131136
}

src/Core/Label.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ class Label extends THREE.Object3D {
4949
* is applied, it cannot be changed directly. However, if it really needed,
5050
* it can be accessed through `label.content.style`, but it is highly
5151
* discouraged to do so.
52+
* @param {Object} [sprites] the sprites.
5253
*/
53-
constructor(content = '', coordinates, style = {}) {
54+
constructor(content = '', coordinates, style = {}, sprites) {
5455
if (coordinates == undefined) {
5556
throw new Error('coordinates are mandatory to add a Label');
5657
}
@@ -94,7 +95,7 @@ class Label extends THREE.Object3D {
9495
if (style.text.haloWidth > 0) {
9596
this.content.classList.add('itowns-stroke-single');
9697
}
97-
style.applyToHTML(this.content);
98+
style.applyToHTML(this.content, sprites);
9899
} else {
99100
this.anchor = [0, 0];
100101
}

0 commit comments

Comments
 (0)