Skip to content

Commit

Permalink
Add symbol-z-order property to symbol layout style spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhamley committed Sep 1, 2018
1 parent b450d0a commit 75b90cd
Show file tree
Hide file tree
Showing 12 changed files with 349 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,9 @@ class SymbolBucket implements Bucket {
this.iconSizeData = getSizeData(this.zoom, unevaluatedLayoutValues['icon-size']);

const layout = this.layers[0].layout;
this.sortFeaturesByY = layout.get('text-allow-overlap') || layout.get('icon-allow-overlap') ||
layout.get('text-ignore-placement') || layout.get('icon-ignore-placement');
const zOrderByViewportY = layout.get('symbol-z-order') === 'viewport-y';
this.sortFeaturesByY = zOrderByViewportY && (layout.get('text-allow-overlap') || layout.get('icon-allow-overlap') ||
layout.get('text-ignore-placement') || layout.get('icon-ignore-placement'));

this.sourceID = options.sourceID;
}
Expand Down
26 changes: 26 additions & 0 deletions src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,32 @@
},
"property-type": "data-constant"
},
"symbol-z-order": {
"type": "enum",
"values": {
"viewport-y": {
"doc": "Symbols will be sorted by their y-position relative to the viewport."
},
"source": {
"doc": "Symbols will be rendered in the same order as the source data with no sorting applied."
}
},
"default": "viewport-y",
"doc": "Controls the order in which overlapping symbols in the same layer are rendered",
"sdk-support": {
"basic functionality": {
"js": "0.49.0"
},
"data-driven styling": {}
},
"expression": {
"interpolated": false,
"parameters": [
"zoom"
]
},
"property-type": "data-constant"
},
"icon-allow-overlap": {
"type": "boolean",
"default": false,
Expand Down
1 change: 1 addition & 0 deletions src/style-spec/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export type SymbolLayerSpecification = {|
"symbol-placement"?: PropertyValueSpecification<"point" | "line" | "line-center">,
"symbol-spacing"?: PropertyValueSpecification<number>,
"symbol-avoid-edges"?: PropertyValueSpecification<boolean>,
"symbol-z-order"?: PropertyValueSpecification<"viewport-y" | "source">,
"icon-allow-overlap"?: PropertyValueSpecification<boolean>,
"icon-ignore-placement"?: PropertyValueSpecification<boolean>,
"icon-optional"?: PropertyValueSpecification<boolean>,
Expand Down
2 changes: 2 additions & 0 deletions src/style/style_layer/symbol_style_layer_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type LayoutProps = {|
"symbol-placement": DataConstantProperty<"point" | "line" | "line-center">,
"symbol-spacing": DataConstantProperty<number>,
"symbol-avoid-edges": DataConstantProperty<boolean>,
"symbol-z-order": DataConstantProperty<boolean>,
"icon-allow-overlap": DataConstantProperty<boolean>,
"icon-ignore-placement": DataConstantProperty<boolean>,
"icon-optional": DataConstantProperty<boolean>,
Expand Down Expand Up @@ -60,6 +61,7 @@ const layout: Properties<LayoutProps> = new Properties({
"symbol-placement": new DataConstantProperty(styleSpec["layout_symbol"]["symbol-placement"]),
"symbol-spacing": new DataConstantProperty(styleSpec["layout_symbol"]["symbol-spacing"]),
"symbol-avoid-edges": new DataConstantProperty(styleSpec["layout_symbol"]["symbol-avoid-edges"]),
"symbol-z-order": new DataConstantProperty(styleSpec["layout_symbol"]["symbol-z-order"]),
"icon-allow-overlap": new DataConstantProperty(styleSpec["layout_symbol"]["icon-allow-overlap"]),
"icon-ignore-placement": new DataConstantProperty(styleSpec["layout_symbol"]["icon-ignore-placement"]),
"icon-optional": new DataConstantProperty(styleSpec["layout_symbol"]["icon-optional"]),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions test/integration/render-tests/symbol-z-order/default/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"version": 8,
"metadata": {
"test": {
"height": 128,
"width": 128
}
},
"center": [
0,
0
],
"zoom": 0,
"sources": {
"icon-source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
7,
7
]
},
"properties": {
"icon": "building"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
14,
14
]
},
"properties": {
"icon": "restaurant"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
},
"properties": {
"icon": "school"
}
}
]
}
}
},
"sprite": "local://sprites/sprite",
"layers": [
{
"id": "icons",
"type": "symbol",
"source": "icon-source",
"layout": {
"icon-image": "{icon}-12",
"icon-allow-overlap": true
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions test/integration/render-tests/symbol-z-order/disabled/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"version": 8,
"metadata": {
"test": {
"height": 128,
"width": 128
}
},
"center": [
0,
0
],
"zoom": 0,
"sources": {
"icon-source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
7,
7
]
},
"properties": {
"icon": "building"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
14,
14
]
},
"properties": {
"icon": "restaurant"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
},
"properties": {
"icon": "school"
}
}
]
}
}
},
"sprite": "local://sprites/sprite",
"layers": [
{
"id": "icons",
"type": "symbol",
"source": "icon-source",
"layout": {
"icon-image": "{icon}-12",
"icon-allow-overlap": true,
"symbol-z-order": "source"
}
}
]
}
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,89 @@
{
"version": 8,
"metadata": {
"test": {
"height": 128,
"width": 128
}
},
"center": [
0,
0
],
"zoom": 0,
"pitch": 60,
"sources": {
"icon-source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
7,
7
]
},
"properties": {
"icon": "building",
"title": "building"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
14,
14
]
},
"properties": {
"icon": "restaurant",
"title": "restaurant"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
},
"properties": {
"icon": "school",
"title": "school"
}
}
]
}
}
},
"sprite": "local://sprites/sprite",
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "icons",
"type": "symbol",
"source": "icon-source",
"layout": {
"symbol-z-order": "source",
"icon-image": "{icon}-12",
"icon-allow-overlap": true,
"text-allow-overlap": true,
"text-field": "{title}",
"text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
"text-offset": [0, 0.6],
"text-anchor": "top"
},
"paint": {
"text-color": "#ffffff"
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions test/integration/render-tests/symbol-z-order/pitched/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"version": 8,
"metadata": {
"test": {
"height": 128,
"width": 128
}
},
"center": [
0,
0
],
"zoom": 0,
"pitch": 45,
"sources": {
"icon-source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
7,
7
]
},
"properties": {
"icon": "building"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
14,
14
]
},
"properties": {
"icon": "restaurant"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
},
"properties": {
"icon": "school"
}
}
]
}
}
},
"sprite": "local://sprites/sprite",
"layers": [
{
"id": "icons",
"type": "symbol",
"source": "icon-source",
"layout": {
"icon-image": "{icon}-12",
"icon-allow-overlap": true,
"symbol-z-order": "source"
}
}
]
}

0 comments on commit 75b90cd

Please sign in to comment.