From 2b540a2131626e98a4b7863be869fb3f296eaf6b Mon Sep 17 00:00:00 2001 From: Brett Camper Date: Wed, 8 Nov 2017 12:52:56 -0500 Subject: [PATCH] skip line outlines that specify non-existent draw styles, and log warning --- src/styles/lines/lines.js | 55 +++++++++++++++++++++---------------- src/styles/points/points.js | 2 +- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/styles/lines/lines.js b/src/styles/lines/lines.js index 7a2f4901b..71a1a7a8f 100644 --- a/src/styles/lines/lines.js +++ b/src/styles/lines/lines.js @@ -1,5 +1,6 @@ // Line rendering style +import log from '../../utils/log'; import {Style} from '../style'; import StyleParser from '../style_parser'; import gl from '../../gl/constants'; // web workers don't have access to GL context, so import all GL constants @@ -12,7 +13,7 @@ import WorkerBroker from '../../utils/worker_broker'; import hashString from '../../utils/hash'; import {shaderSrc_polygonsVertex, shaderSrc_polygonsFragment} from '../polygons/polygons'; -export var Lines = Object.create(Style); +export const Lines = Object.create(Style); Lines.vertex_layouts = [[], []]; // first dimension is texcoords on/off, second is offsets on/off Lines.variants = {}; // mesh variants by variant key @@ -303,31 +304,39 @@ Object.assign(Lines, { // outline inhertits dash pattern, but NOT explicit texture let outline_style = this.styles[draw.outline.style]; - draw.outline.dash = (draw.outline.dash !== undefined ? draw.outline.dash : outline_style.dash); - draw.outline.texture = (draw.outline.texture !== undefined ? draw.outline.texture : outline_style.texture); + if (outline_style) { + draw.outline.dash = (draw.outline.dash !== undefined ? draw.outline.dash : outline_style.dash); + draw.outline.texture = (draw.outline.texture !== undefined ? draw.outline.texture : outline_style.texture); - if (draw.outline.dash != null) { // dash was defined by outline draw or style - draw.outline.dash_key = draw.outline.dash && this.dashTextureKey(draw.outline.dash); - draw.outline.texture_merged = draw.outline.dash_key; - } - else if (draw.outline.dash === null) { // dash explicitly disabled by outline draw or style - draw.outline.dash_key = null; - draw.outline.texture_merged = draw.outline.texture; - } - else if (draw.outline.texture != null) { // texture was defined by outline draw or style - draw.outline.dash_key = null; // outline explicitly turning off dash - draw.outline.texture_merged = draw.outline.texture; + if (draw.outline.dash != null) { // dash was defined by outline draw or style + draw.outline.dash_key = draw.outline.dash && this.dashTextureKey(draw.outline.dash); + draw.outline.texture_merged = draw.outline.dash_key; + } + else if (draw.outline.dash === null) { // dash explicitly disabled by outline draw or style + draw.outline.dash_key = null; + draw.outline.texture_merged = draw.outline.texture; + } + else if (draw.outline.texture != null) { // texture was defined by outline draw or style + draw.outline.dash_key = null; // outline explicitly turning off dash + draw.outline.texture_merged = draw.outline.texture; + } + else { // no dash or texture defined for outline, inherit parent dash + draw.outline.dash = draw.dash; + draw.outline.dash_key = draw.outline.dash && this.dashTextureKey(draw.outline.dash); + draw.outline.texture_merged = draw.outline.dash_key; + } + draw.outline.dash_background_color = (draw.outline.dash_background_color !== undefined ? draw.outline.dash_background_color : outline_style.dash_background_color); + draw.outline.dash_background_color = (draw.outline.dash_background_color !== undefined ? draw.outline.dash_background_color : draw.dash_background_color); + draw.outline.dash_background_color = draw.outline.dash_background_color && StyleParser.parseColor(draw.outline.dash_background_color); + draw.outline.texcoords = ((outline_style.texcoords || draw.outline.texture_merged) ? 1 : 0); + this.computeVariant(draw.outline); } - else { // no dash or texture defined for outline, inherit parent dash - draw.outline.dash = draw.dash; - draw.outline.dash_key = draw.outline.dash && this.dashTextureKey(draw.outline.dash); - draw.outline.texture_merged = draw.outline.dash_key; + else { + log({ level: 'warn', once: true }, `Layer '${draw.layers[draw.layers.length-1]}': ` + + `line 'outline' specifies non-existent draw style '${draw.outline.style}' (or maybe the style is ` + + `defined but is missing a 'base' or has another error), skipping outlines in layer`); + draw.outline = null; } - draw.outline.dash_background_color = (draw.outline.dash_background_color !== undefined ? draw.outline.dash_background_color : outline_style.dash_background_color); - draw.outline.dash_background_color = (draw.outline.dash_background_color !== undefined ? draw.outline.dash_background_color : draw.dash_background_color); - draw.outline.dash_background_color = draw.outline.dash_background_color && StyleParser.parseColor(draw.outline.dash_background_color); - draw.outline.texcoords = ((outline_style.texcoords || draw.outline.texture_merged) ? 1 : 0); - this.computeVariant(draw.outline); } return draw; }, diff --git a/src/styles/points/points.js b/src/styles/points/points.js index dcaf049af..33cf6e5ac 100755 --- a/src/styles/points/points.js +++ b/src/styles/points/points.js @@ -27,7 +27,7 @@ const angles_normalize = 16384 / Math.PI; const offsets_normalize = 64; const texcoord_normalize = 65535; -export var Points = Object.create(Style); +export const Points = Object.create(Style); Points.variants = {}; // mesh variants by variant key