Skip to content

Commit

Permalink
Pass feat.type (geometry dimension) in styleOptions (#130)
Browse files Browse the repository at this point in the history
* Pass feature type into styleOptions

This then allows differentiation of styles with the same VT layer name.
Discussed here: #125

* Document passing geometry type into style function

* Allow array return value of style function to contain functions, not just sets of L.Path options

* Tab indents

* Change terminology (type > geometry dimension"

* Use camelCase for geometryDimension

* Revert return function in array

* Change geometryDimension example code
  • Loading branch information
tomchadwin authored and IvanSanchez committed Mar 10, 2018
1 parent 0ae56b3 commit b8d573a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
33 changes: 31 additions & 2 deletions docs/vectorgrid-api-docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ <h3 id='symbolizer-method'>Methods</h3>
<pre><code class="lang-js">var vectorTileOptions = {
vectorTileLayerStyles: {
// A plain set of L.Path options.
water: {
landuse: {
weight: 0,
fillColor: &#39;#9bc2c4&#39;,
fillOpacity: 1,
Expand All @@ -385,6 +385,35 @@ <h3 id='symbolizer-method'>Methods</h3>
fillOpacity: 0
}
},
// A function for styling features dynamically, depending on their
// properties, the map&#39;s zoom level, and the layer's geometry
// dimension (point, line, polygon)
water: function(properties, zoom, geometryDimension) {
if (geometryDimension === 1) { // point
return ({
radius: 5,
color: &#39;#cf52d3&#39;,
});
}

if (geometryDimension === 2) { // line
return ({
weight: 1,
color: &#39;#cf52d3&#39;,
dashArray: &#39;2, 6&#39;,
fillOpacity: 0
});
}

if (geometryDimension === 3) { // polygon
return ({
weight: 1,
fillColor: &#39;#9bc2c4&#39;,
fillOpacity: 1,
fill: true
});
}
},
// An &#39;icon&#39; option means that a L.Icon will be used
place: {
icon: new L.Icon.Default()
Expand All @@ -399,7 +428,7 @@ <h3 id='symbolizer-method'>Methods</h3>
<li>A set of <code>L.Path</code> options</li>
<li>An array of sets of <code>L.Path</code> options</li>
<li>A function that returns a set of <code>L.Path</code> options</li>
<li>A function that returns an array of sets of <code>L.Path</code> options
<li>A function that returns an array of sets of <code>L.Path</code> options for point, line, and polygon styles respectively
<br>
Layers² with no style specified will use the default <code>L.Path</code> options.
<br>
Expand Down
4 changes: 2 additions & 2 deletions src/Leaflet.VectorGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ L.VectorGrid = L.GridLayer.extend({
}

if (styleOptions instanceof Function) {
styleOptions = styleOptions(feat.properties, coords.z);
styleOptions = styleOptions(feat.properties, coords.z, feat.type);
}

if (!(styleOptions instanceof Array)) {
Expand Down Expand Up @@ -188,7 +188,7 @@ L.VectorGrid = L.GridLayer.extend({

_updateStyles: function(feat, renderer, styleOptions) {
styleOptions = (styleOptions instanceof Function) ?
styleOptions(feat.properties, renderer.getCoord().z) :
styleOptions(feat.properties, renderer.getCoord().z, feat.type) :
styleOptions;

if (!(styleOptions instanceof Array)) {
Expand Down

0 comments on commit b8d573a

Please sign in to comment.