Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 79fa245

Browse filesBrowse files
authored
Merge pull request plotly#3399 from rockg/mapbox-attributes
Expose mapbox minzoom, maxzoom, and symbol-placement properties
2 parents 2e7f533 + 89d873a commit 79fa245
Copy full SHA for 79fa245

File tree

5 files changed

+152
-20
lines changed
Filter options

5 files changed

+152
-20
lines changed

‎src/plots/mapbox/layers.js

Copy file name to clipboardExpand all lines: src/plots/mapbox/layers.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ proto.updateLayer = function(opts) {
9797
source: this.idSource,
9898
'source-layer': opts.sourcelayer || '',
9999
type: opts.type,
100+
minzoom: opts.minzoom,
101+
maxzoom: opts.maxzoom,
100102
layout: convertedOpts.layout,
101103
paint: convertedOpts.paint
102104
}, opts.below);
@@ -151,7 +153,8 @@ function convertOpts(opts) {
151153
Lib.extendFlat(paint, {
152154
'line-width': opts.line.width,
153155
'line-color': opts.color,
154-
'line-opacity': opts.opacity
156+
'line-opacity': opts.opacity,
157+
'line-dasharray': opts.line.dash
155158
});
156159
break;
157160

@@ -176,7 +179,8 @@ function convertOpts(opts) {
176179
'text-field': symbol.text,
177180
'text-size': symbol.textfont.size,
178181
'text-anchor': textOpts.anchor,
179-
'text-offset': textOpts.offset
182+
'text-offset': textOpts.offset,
183+
'symbol-placement': symbol.placement,
180184

181185
// TODO font family
182186
// 'text-font': symbol.textfont.family.split(', '),

‎src/plots/mapbox/layout_attributes.js

Copy file name to clipboardExpand all lines: src/plots/mapbox/layout_attributes.js
+66-18Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var templatedArray = require('../../plot_api/plot_template').templatedArray;
1919

2020
var fontAttr = fontAttrs({
2121
description: [
22-
'Sets the icon text font.',
22+
'Sets the icon text font (color=mapbox.layer.paint.text-color, size=mapbox.layer.layout.text-size).',
2323
'Has an effect only when `type` is set to *symbol*.'
2424
].join(' ')
2525
});
@@ -71,21 +71,21 @@ var attrs = module.exports = overrideAll({
7171
valType: 'number',
7272
dflt: 1,
7373
role: 'info',
74-
description: 'Sets the zoom level of the map.'
74+
description: 'Sets the zoom level of the map (mapbox.zoom).'
7575
},
7676
bearing: {
7777
valType: 'number',
7878
dflt: 0,
7979
role: 'info',
80-
description: 'Sets the bearing angle of the map (in degrees counter-clockwise from North).'
80+
description: 'Sets the bearing angle of the map in degrees counter-clockwise from North (mapbox.bearing).'
8181
},
8282
pitch: {
8383
valType: 'number',
8484
dflt: 0,
8585
role: 'info',
8686
description: [
8787
'Sets the pitch angle of the map',
88-
'(in degrees, where *0* means perpendicular to the surface of the map).'
88+
'(in degrees, where *0* means perpendicular to the surface of the map) (mapbox.pitch).'
8989
].join(' ')
9090
},
9191

@@ -113,7 +113,7 @@ var attrs = module.exports = overrideAll({
113113
valType: 'any',
114114
role: 'info',
115115
description: [
116-
'Sets the source data for this layer.',
116+
'Sets the source data for this layer (mapbox.layer.source).',
117117
'Source can be either a URL,',
118118
'a geojson object (with `sourcetype` set to *geojson*)',
119119
'or an array of tile URLS (with `sourcetype` set to *vector*).'
@@ -125,7 +125,7 @@ var attrs = module.exports = overrideAll({
125125
dflt: '',
126126
role: 'info',
127127
description: [
128-
'Specifies the layer to use from a vector tile source.',
128+
'Specifies the layer to use from a vector tile source (mapbox.layer.source-layer).',
129129
'Required for *vector* source type that supports multiple layers.'
130130
].join(' ')
131131
},
@@ -136,7 +136,7 @@ var attrs = module.exports = overrideAll({
136136
dflt: 'circle',
137137
role: 'info',
138138
description: [
139-
'Sets the layer type.',
139+
'Sets the layer type (mapbox.layer.type).',
140140
'Support for *raster*, *background* types is coming soon.',
141141
'Note that *line* and *fill* are not compatible with Point',
142142
'GeoJSON geometries.'
@@ -161,10 +161,10 @@ var attrs = module.exports = overrideAll({
161161
role: 'style',
162162
description: [
163163
'Sets the primary layer color.',
164-
'If `type` is *circle*, color corresponds to the circle color',
165-
'If `type` is *line*, color corresponds to the line color',
166-
'If `type` is *fill*, color corresponds to the fill color',
167-
'If `type` is *symbol*, color corresponds to the icon color'
164+
'If `type` is *circle*, color corresponds to the circle color (mapbox.layer.paint.circle-color)',
165+
'If `type` is *line*, color corresponds to the line color (mapbox.layer.paint.line-color)',
166+
'If `type` is *fill*, color corresponds to the fill color (mapbox.layer.paint.fill-color)',
167+
'If `type` is *symbol*, color corresponds to the icon color (mapbox.layer.paint.icon-color)'
168168
].join(' ')
169169
},
170170
opacity: {
@@ -173,7 +173,35 @@ var attrs = module.exports = overrideAll({
173173
max: 1,
174174
dflt: 1,
175175
role: 'info',
176-
description: 'Sets the opacity of the layer.'
176+
description: [
177+
'Sets the opacity of the layer.',
178+
'If `type` is *circle*, opacity corresponds to the circle opacity (mapbox.layer.paint.circle-opacity)',
179+
'If `type` is *line*, opacity corresponds to the line opacity (mapbox.layer.paint.line-opacity)',
180+
'If `type` is *fill*, opacity corresponds to the fill opacity (mapbox.layer.paint.fill-opacity)',
181+
'If `type` is *symbol*, opacity corresponds to the icon/text opacity (mapbox.layer.paint.text-opacity)'
182+
].join(' ')
183+
},
184+
minzoom: {
185+
valType: 'number',
186+
min: 0,
187+
max: 24,
188+
dflt: 0,
189+
role: 'info',
190+
description: [
191+
'Sets the minimum zoom level (mapbox.layer.minzoom).',
192+
'At zoom levels less than the minzoom, the layer will be hidden.',
193+
].join(' ')
194+
},
195+
maxzoom: {
196+
valType: 'number',
197+
min: 0,
198+
max: 24,
199+
dflt: 24,
200+
role: 'info',
201+
description: [
202+
'Sets the maximum zoom level (mapbox.layer.maxzoom).',
203+
'At zoom levels equal to or greater than the maxzoom, the layer will be hidden.'
204+
].join(' ')
177205
},
178206

179207
// type-specific style attributes
@@ -183,7 +211,7 @@ var attrs = module.exports = overrideAll({
183211
dflt: 15,
184212
role: 'style',
185213
description: [
186-
'Sets the circle radius.',
214+
'Sets the circle radius (mapbox.layer.paint.circle-radius).',
187215
'Has an effect only when `type` is set to *circle*.'
188216
].join(' ')
189217
}
@@ -195,7 +223,15 @@ var attrs = module.exports = overrideAll({
195223
dflt: 2,
196224
role: 'style',
197225
description: [
198-
'Sets the line width.',
226+
'Sets the line width (mapbox.layer.paint.line-width).',
227+
'Has an effect only when `type` is set to *line*.'
228+
].join(' ')
229+
},
230+
dash: {
231+
valType: 'data_array',
232+
role: 'style',
233+
description: [
234+
'Sets the length of dashes and gaps (mapbox.layer.paint.line-dasharray).',
199235
'Has an effect only when `type` is set to *line*.'
200236
].join(' ')
201237
}
@@ -207,7 +243,7 @@ var attrs = module.exports = overrideAll({
207243
dflt: defaultLine,
208244
role: 'style',
209245
description: [
210-
'Sets the fill outline color.',
246+
'Sets the fill outline color (mapbox.layer.paint.fill-outline-color).',
211247
'Has an effect only when `type` is set to *fill*.'
212248
].join(' ')
213249
}
@@ -219,7 +255,7 @@ var attrs = module.exports = overrideAll({
219255
dflt: 'marker',
220256
role: 'style',
221257
description: [
222-
'Sets the symbol icon image.',
258+
'Sets the symbol icon image (mapbox.layer.layout.icon-image).',
223259
'Full list: https://www.mapbox.com/maki-icons/'
224260
].join(' ')
225261
},
@@ -228,7 +264,7 @@ var attrs = module.exports = overrideAll({
228264
dflt: 10,
229265
role: 'style',
230266
description: [
231-
'Sets the symbol icon size.',
267+
'Sets the symbol icon size (mapbox.layer.layout.icon-size).',
232268
'Has an effect only when `type` is set to *symbol*.'
233269
].join(' ')
234270
},
@@ -237,7 +273,19 @@ var attrs = module.exports = overrideAll({
237273
dflt: '',
238274
role: 'info',
239275
description: [
240-
'Sets the symbol text.'
276+
'Sets the symbol text (mapbox.layer.layout.text-field).'
277+
].join(' ')
278+
},
279+
placement: {
280+
valType: 'enumerated',
281+
values: ['point', 'line', 'line-center'],
282+
dflt: 'point',
283+
role: 'info',
284+
description: [
285+
'Sets the symbol and/or text placement (mapbox.layer.layout.symbol-placement).',
286+
'If `placement` is *point*, the label is placed where the geometry is located',
287+
'If `placement` is *line*, the label is placed along the line of the geometry',
288+
'If `placement` is *line-center*, the label is placed on the center of the geometry',
241289
].join(' ')
242290
},
243291
textfont: fontAttr,

‎src/plots/mapbox/layout_defaults.js

Copy file name to clipboardExpand all lines: src/plots/mapbox/layout_defaults.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ function handleLayerDefaults(layerIn, layerOut) {
6262
coerce('below');
6363
coerce('color');
6464
coerce('opacity');
65+
coerce('minzoom');
66+
coerce('maxzoom');
6567

6668
if(type === 'circle') {
6769
coerce('circle.radius');
6870
}
6971

7072
if(type === 'line') {
7173
coerce('line.width');
74+
coerce('line.dash');
7275
}
7376

7477
if(type === 'fill') {
@@ -82,6 +85,7 @@ function handleLayerDefaults(layerIn, layerOut) {
8285
coerce('symbol.text');
8386
Lib.coerceFont(coerce, 'symbol.textfont');
8487
coerce('symbol.textposition');
88+
coerce('symbol.placement');
8589
}
8690
}
8791
}
Loading
+76Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"data": [
3+
{
4+
"type": "scattermapbox"
5+
}
6+
],
7+
"layout": {
8+
"mapbox": {
9+
"style": "outdoors",
10+
"layers": [
11+
{
12+
"sourcetype": "geojson",
13+
"type": "line",
14+
"minzoom": 4,
15+
"maxzoom": 12,
16+
"color": "gray",
17+
"line": {
18+
"dash": [2.5, 1]
19+
},
20+
"source": {
21+
"type": "FeatureCollection",
22+
"features": [
23+
{
24+
"type": "Feature",
25+
"geometry": {
26+
"type": "LineString",
27+
"coordinates": [[-0.5, 52], [0.5, 50]]
28+
},
29+
"properties": {
30+
"title": "Line Text Example"
31+
}
32+
}
33+
]
34+
}
35+
},
36+
{
37+
"sourcetype": "geojson",
38+
"type": "symbol",
39+
"symbol": {
40+
"text": "{title}",
41+
"textfont": {
42+
"size": 10,
43+
"color": "red"
44+
},
45+
"iconsize": 0,
46+
"placement": "line"
47+
},
48+
"source": {
49+
"type": "FeatureCollection",
50+
"features": [
51+
{
52+
"type": "Feature",
53+
"geometry": {
54+
"type": "LineString",
55+
"coordinates": [[-0.5, 52], [0.5, 50]]
56+
},
57+
"properties": {
58+
"title": "Line Text Example"
59+
}
60+
}
61+
]
62+
}
63+
}
64+
],
65+
"zoom": 5,
66+
"center": {
67+
"lon": 0,
68+
"lat": 51
69+
}
70+
},
71+
"showlegend": false,
72+
"height": 450,
73+
"width": 1100,
74+
"autosize": true
75+
}
76+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.