Skip to content

Commit 911a91b

Browse files
committed
feat: Add a patterns to polygons
1 parent f2f1ad9 commit 911a91b

File tree

7 files changed

+286
-35
lines changed

7 files changed

+286
-35
lines changed

src/markerFeature.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var pointFeature = require('./pointFeature');
1818
*
1919
* @typedef {geo.feature.styleSpec} geo.markerFeature.styleSpec
2020
* @extends geo.feature.styleSpec
21-
* @property {number|Function} [radius=5] Radius of each marker in pixels.
21+
* @property {number|Function} [radius=6.25] Radius of each marker in pixels.
2222
* This includes the stroke width if `strokeOffset` is -1, excludes it if
2323
* `strokeOffset` is 1, and includes half the stroke width if `strokeOffset`
2424
* is 0. Note that is `radiusIncludesStroke` is `false`, this never

src/polygonFeature.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,46 @@ var transform = require('./transform');
1515
* style options.
1616
*/
1717

18+
/**
19+
* Style specification for a polygon pattern.
20+
*
21+
* @typedef {geo.polygonPattern} geo.polygonPattern
22+
* @property {geo.geoColor} [fillColor] RGBA fill color. Default is polygon
23+
* fillColor and fillOpacity.
24+
* @property {geo.geoColor} [strokeColor] RGBA stroke color. Default is
25+
* polygon strokeColor and strokeOpacity.
26+
* @property {number} [strokeWidth=1.25] The weight of the pattern marker's
27+
* stroke in pixels. Set this or A on strokeFill to zero to not have a
28+
* stroke.
29+
* @property {number} [strokeOffset=-1] The position of the stroke compared to
30+
* the pattern radius. This can only be -1, 0, or 1 (the sign of the value
31+
* is used).
32+
* @property {boolean} [radiusIncludesStroke=true] If truthy or undefined, the
33+
* `radius` includes the `strokeWidth` based on the `strokeOffset`. If
34+
* defined and falsy, the radius does not include the `strokeWidth`.
35+
* @property {number} [symbol=0] One of the predefined symbol numbers. This is
36+
* one of `geo.markerFeature.symbols`.
37+
* @property {number|number[]} [symbolValue=0] A value the affects the
38+
* appearance of the symbol. Some symbols can take an array of numbers.
39+
* @property {number} [rotation=0] The rotation of the symbol in clockwise
40+
* radians.
41+
* @property {geo.markerFeature.scaleMode} [scaleWithZoom='none'] This
42+
* determines if the fill, stroke, or both scale with zoom. If set, the
43+
* values for radius and strokeWidth are the values at zoom-level zero.
44+
* @property {boolean} [rotateWithMap=false] If truthy, rotate symbols with the
45+
* map. If falsy, symbol orientation is absolute.
46+
* @property {number} [radius=6.25] Radius of each marker in pixels. This
47+
* includes the stroke width if `strokeOffset` is -1, excludes it if
48+
* `strokeOffset` is 1, and includes half the stroke width if `strokeOffset`
49+
* is 0. Note that is `radiusIncludesStroke` is `false`, this never
50+
* includes the stroke width.
51+
* @property {number} [spacing=20] Spacing in pixels between pattern symbols;
52+
* scaled if either radius or strokeWidth is scaled. If positive, patterns
53+
* are on a square grid. If negative, patterns are on a triangular grid.
54+
* @property {number[]} [origin=[0, 0]] Origin of the pattern.
55+
* TODO: define what a zero origin even means.
56+
*/
57+
1858
/**
1959
* Style specification for a polygon feature.
2060
*
@@ -35,6 +75,9 @@ var transform = require('./transform');
3575
* function, this is passed an array of items, each of which has a vertices
3676
* property that is a single continuous array in map gcs coordinates. It
3777
* defaults to the first polygon's first vertex's position.
78+
* @property {geo.polygonPattern|Function} [pattern] Pattern to apply to each
79+
* polygon. Each polygon can be distinct, but the pattern is uniform across
80+
* any one polygon.
3881
*/
3982

4083
/**

src/util/common.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,27 @@ var util = {
15061506
return d;
15071507
},
15081508

1509+
/**
1510+
* Pack an array of three numbers and one boolean into a single float. Each
1511+
* numerical value is either undefined or on the scale of [0, 1] and is
1512+
* mapped to an integer range of [0, 250].
1513+
*
1514+
* @param {number|number[]} value A single value or an array of up to four
1515+
* values where the first three values are numbers and the last is a
1516+
* boolean.
1517+
* @returns {number} A packed number.
1518+
*/
1519+
packFloats: function (value) {
1520+
if (!value.length) {
1521+
return value === undefined ? 0 : Math.floor(Math.abs(value) * 250) + 1;
1522+
}
1523+
return (
1524+
(value[0] === undefined ? 0 : Math.floor(Math.abs(value[0]) * 250) + 1) +
1525+
(value[1] === undefined ? 0 : Math.floor(Math.abs(value[1]) * 250) + 1) * 252 +
1526+
(value[2] === undefined ? 0 : Math.floor(Math.abs(value[2]) * 250) + 1) * 252 * 252
1527+
) * (value[3] ? -1 : 1);
1528+
},
1529+
15091530
///////////////////////////////////////////////////////////////////////////
15101531
/*
15111532
* Utility member properties.

src/webgl/markerFeature.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,6 @@ var webgl_markerFeature = function (arg) {
7474
return shader;
7575
}
7676

77-
/**
78-
* Pack an array of three numbers and one boolean into a single float. Each
79-
* numerical value is either undefined or on the scale of [0, 1] and is
80-
* mapped to an integer range of [0, 250].
81-
*
82-
* @param {number|number[]} value A single value or an array of up to four
83-
* values where the first three values are numbers and the last is a
84-
* boolean.
85-
* @returns {number} A packed number.
86-
*/
87-
function packFloats(value) {
88-
if (!value.length) {
89-
return value === undefined ? 0 : Math.floor(Math.abs(value) * 250) + 1;
90-
}
91-
return (
92-
(value[0] === undefined ? 0 : Math.floor(Math.abs(value[0]) * 250) + 1) +
93-
(value[1] === undefined ? 0 : Math.floor(Math.abs(value[1]) * 250) + 1) * 252 +
94-
(value[2] === undefined ? 0 : Math.floor(Math.abs(value[2]) * 250) + 1) * 252 * 252
95-
) * (value[3] ? -1 : 1);
96-
}
97-
9877
/**
9978
* Create and style the data needed to render the markers.
10079
*
@@ -195,7 +174,7 @@ var webgl_markerFeature = function (arg) {
195174
((Math.sign(styleVal.radiusIncludesStroke !== undefined && styleVal.radiusIncludesStroke ? styleVal.strokeOffset : 1) + 1) * 16) +
196175
styleVal.symbol * 64);
197176
if (styleVal.symbolValue && styleVal.symbol >= markerFeature.symbols.arrow && styleVal.symbol < markerFeature.symbols.arrow + markerFeature.symbols.arrowMax) {
198-
styleVal.symbolValue = packFloats(styleVal.symbolValue);
177+
styleVal.symbolValue = util.packFloats(styleVal.symbolValue);
199178
}
200179
for (j = 0; j < vpf; j += 1, ivpf += 1, ivpf3 += 3) {
201180
if (!onlyStyle) {

0 commit comments

Comments
 (0)