Created
January 30, 2017 13:25
-
-
Save Scarysize/1cf4bb01b654b1d45838ea41144ee892 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
populate(features, options) { | |
const layout = this.layers[0].layout; | |
const iconImage = layout['sdficon-image']; | |
const hasIcon = iconImage; | |
this.features = []; | |
if (!hasIcon) { | |
return; | |
} | |
const icons = options.iconDependencies; | |
for (let i = 0; i < features.length; i++) { | |
const feature = features[i]; | |
if (!this.layers[0].filter(feature)) { | |
continue; | |
} | |
let icon; | |
if (hasIcon) { | |
icon = resolveTokens(feature.properties, iconImage); | |
} | |
if (!icon) { | |
continue; | |
} | |
this.features.push({ | |
icon, | |
index: i, | |
sourceLayerIndex: feature.sourceLayerIndex, | |
geometry: loadGeometry(feature), | |
properties: feature.properties, | |
type: VectorTileFeature.types[feature.type] | |
}); | |
if (icon) { | |
icons[icon] = true; | |
} | |
options.iconDependencies[icon] = true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
populate(features, options) { | |
const layout = this.layers[0].layout; | |
const textField = layout['text-field']; | |
const textFont = layout['text-font']; | |
const iconImage = layout['icon-image']; | |
const hasText = textField && textFont; | |
const hasIcon = iconImage; | |
this.features = []; | |
if (!hasText && !hasIcon) { | |
return; | |
} | |
const icons = options.iconDependencies; | |
const stacks = options.glyphDependencies; | |
const stack = stacks[textFont] = stacks[textFont] || {}; | |
for (let i = 0; i < features.length; i++) { | |
const feature = features[i]; | |
if (!this.layers[0].filter(feature)) { | |
continue; | |
} | |
let text; | |
if (hasText) { | |
text = resolveText(feature, layout); | |
} | |
let icon; | |
if (hasIcon) { | |
icon = resolveTokens(feature.properties, iconImage); | |
} | |
if (!text && !icon) { | |
continue; | |
} | |
this.features.push({ | |
text, | |
icon, | |
index: i, | |
sourceLayerIndex: feature.sourceLayerIndex, | |
geometry: loadGeometry(feature), | |
properties: feature.properties, | |
type: VectorTileFeature.types[feature.type] | |
}); | |
if (icon) { | |
icons[icon] = true; | |
} | |
if (text) { | |
for (let i = 0; i < text.length; i++) { | |
stack[text.charCodeAt(i)] = true; | |
} | |
} | |
} | |
if (layout['symbol-placement'] === 'line') { | |
// Merge adjacent lines with the same text to improve labelling. | |
// It's better to place labels on one long line than on many short segments. | |
this.features = mergeLines(this.features); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment