Skip to content

Commit

Permalink
Add data-driven styling support for "icon-offset" (#3791)
Browse files Browse the repository at this point in the history
* Add support for icon-offset property functions

* Moved the icon-offset determination to the symbol bucket

* Updated package.json to point to new style and test suite

* Update package.json

* Fix icon-offset zoom-and-property functions

* Update package.json
  • Loading branch information
lucaswoj authored Dec 13, 2016
1 parent 32fcbfe commit 44d9c42
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion js/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ class SymbolBucket {
let shapedIcon;
if (feature.icon) {
const image = icons[feature.icon];
shapedIcon = shapeIcon(image, layout);
const iconOffset = this.layers[0].getLayoutValue('icon-offset', {zoom: this.zoom}, feature.properties);
shapedIcon = shapeIcon(image, iconOffset);

if (image) {
if (this.sdfIcons === undefined) {
Expand Down
6 changes: 3 additions & 3 deletions js/symbol/shaping.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ function align(positionedGlyphs, justify, horizontalAlign, verticalAlign, maxLin
}
}

function shapeIcon(image, layout) {
function shapeIcon(image, iconOffset) {
if (!image || !image.rect) return null;

const dx = layout['icon-offset'][0];
const dy = layout['icon-offset'][1];
const dx = iconOffset[0];
const dy = iconOffset[1];
const x1 = dx - image.width / 2;
const x2 = x1 + image.width;
const y1 = dy - image.height / 2;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"in-publish": "^2.0.0",
"jsdom": "^9.4.2",
"lodash.template": "^4.4.0",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#8a047e6226b996fa8fc4c61a30aebb55c6234896",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#52acb6e9e4b75b7e765ef087a0e539739e9846c1",
"minifyify": "^7.0.1",
"npm-run-all": "^3.0.0",
"nyc": "^8.3.0",
Expand Down

0 comments on commit 44d9c42

Please sign in to comment.