Skip to content

Commit

Permalink
Favor previous anchor only when still available
Browse files Browse the repository at this point in the history
  • Loading branch information
Asheem Mamoowala committed Jul 15, 2019
1 parent be7e27f commit 1791ada
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/symbol/placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,12 @@ export class Placement {
const textBoxScale = symbolInstance.textBoxScale;
let anchors = layout.get('text-variable-anchor');

// If we this symbol was in the last placement, shift the previously used
// anchor to the front of the anchor list.
// If this symbol was in the last placement, shift the previously used
// anchor to the front of the anchor list, only if the previous anchor
// is still in the anchor list
if (this.prevPlacement && this.prevPlacement.variableOffsets[symbolInstance.crossTileID]) {
const prevOffsets = this.prevPlacement.variableOffsets[symbolInstance.crossTileID];
if (anchors[0] !== prevOffsets.anchor) {
if (anchors.indexOf(prevOffsets.anchor) > 0) {
anchors = anchors.filter(anchor => anchor !== prevOffsets.anchor);
anchors.unshift(prevOffsets.anchor);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"version": 8,
"metadata": {
"test": {
"width": 64,
"height": 64,
"operations": [
[
"setLayoutProperty",
"symbol",
"text-variable-anchor",
["bottom"]
],
[
"wait"
]
]
}
},
"transition": {
"duration": 0
},
"sources": {
"geojson": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
}
}
]
}
}
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "symbol",
"type": "symbol",
"source": "geojson",
"layout": {
"text-variable-anchor": ["left"],
"text-field": "ABC",
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
],
"symbol-placement": "point"
},
"paint": {
"text-color": "red"
}
},
{
"id" : "dot",
"type": "circle",
"source": "geojson",
"paint": {
"circle-color": "red"
}

}
]
}

0 comments on commit 1791ada

Please sign in to comment.