Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion js/geometry/pointbucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ PointBucket.prototype.addFeature = function(feature) {
anchor: point
}];

var placement = this.placement.collision.place(glyphs, point, 1, 16, padding);
var placement = this.placement.collision.place(
glyphs, point, 1, 16, padding, false,
info['icon-allow-overlap'], info['icon-ignore-placement']);

if (placement) {
this.addPoints([point], placement, imagePos);
}
Expand Down
10 changes: 6 additions & 4 deletions js/text/collision.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ function Collision() {
}], new Point(m, m), 1, [Math.PI * 2, 0], false, 2);
}

Collision.prototype.place = function(boxes, anchor, minPlacementScale, maxPlacementScale, padding, horizontal, alwaysVisible) {
Collision.prototype.place = function(boxes, anchor, minPlacementScale, maxPlacementScale,
padding, horizontal, allowOverlap, ignorePlacement) {

var minScale = Infinity;
for (var m = 0; m < boxes.length; m++) {
Expand Down Expand Up @@ -58,15 +59,16 @@ Collision.prototype.place = function(boxes, anchor, minPlacementScale, maxPlacem
}

// Calculate the minimum scale the entire label can be shown without collisions
var scale = alwaysVisible ? minPlacementScale :
var scale = allowOverlap ? minPlacementScale :
this.getPlacementScale(boxes, minPlacementScale, maxPlacementScale, padding);

// Return if the label can never be placed without collision
if (scale === null) return null;

// Calculate the range it is safe to rotate all glyphs
var rotationRange = alwaysVisible ? [2 * Math.PI, 0] : this.getPlacementRange(boxes, scale, horizontal);
this.insert(boxes, anchor, scale, rotationRange, horizontal, padding);
var rotationRange = allowOverlap ? [2 * Math.PI, 0] : this.getPlacementRange(boxes, scale, horizontal);

if (!ignorePlacement) this.insert(boxes, anchor, scale, rotationRange, horizontal, padding);

var zoom = Math.log(scale) / Math.LN2;

Expand Down
3 changes: 2 additions & 1 deletion js/text/placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ Placement.prototype.addFeature = function(line, info, faces, shaping, bucket) {
var anchor = anchors[j];
var glyphs = getGlyphs(anchor, origin, shaping, faces, fontScale, horizontal, line, maxAngleDelta, rotate, slant);
var place = this.collision.place(
glyphs.boxes, anchor, anchor.scale, this.maxPlacementScale, padding, horizontal, info['text-always-visible']);
glyphs.boxes, anchor, anchor.scale, this.maxPlacementScale, padding,
horizontal, info['text-allow-overlap'], info['text-ignore-placement']);

if (place) {
bucket.addGlyphs(glyphs.glyphs, place.zoom, place.rotationRange, this.zoom - this.zOffset);
Expand Down