Skip to content

Commit

Permalink
Fix default color and stroke width properties for Geojson component (#…
Browse files Browse the repository at this point in the history
…3972)

- Fixes #3971
- According to React docs, `defaultProps` only takes effect for `undefined` props, **not** `null` props
- By returning `null` from `getColor`, it ends up passing a `null` prop down to the native component instead of the `defaultProps` values from `MapPolygon`, `MapPolyline`, etc.
- Switching to a simple `return` will return `undefined` from `getColor` and `getStrokeWidth`, which means the default props can take effect
- Updated the documentation to:
  - Specify the actual GeoJSON property names that are being checked
  - Specify that stroke color and stroke width are only used for polygons and polylines (not just "paths")
  - Specify that `fillColor` is only relevant for polygons
  - Add the undocumented `color` property, which appears to be used for Marker/"point" types
- With these changes, the default stroke width of 1 and color of #000 seems to be working for my GeoJSON LineString/Polyline
  • Loading branch information
aardvarkk authored Oct 12, 2021
1 parent 5e9f68a commit fdd1eea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions docs/geojson.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
| Prop | Type | Default | Note |
| --------- | ---- | ------------------------------------------------------ | ---- |
| `geojson` | `GeoJSON` | | [Geojson](https://geojson.org/) description of object. |
| `strokeColor` | `String` | stroke color in GeoJson if present else `#000` | The stroke color to use for the path. |
| `fillColor` | `String` | fill color in GeoJson | The fill color to use for the path. |
| `strokeWidth` | `Number` | stroke width in Geojson if present else `1` | The stroke width to use for the path. |
| `strokeColor` | `String` | `stroke` property in GeoJson if present else `#000` | The stroke color to use for polygons and polylines. |
| `fillColor` | `String` | `fill` property in GeoJson | The fill color to use for polygons. |
| `strokeWidth` | `Number` | `stroke-width` property in Geojson if present else `1` | The stroke width to use for polygons and polylines. |
| `color` | `String` | `marker-color` property in GeoJson | The color to use for points. |
| `lineDashPhase` | `Number` | | (iOS only) The offset (in points) at which to start drawing the dash pattern. Use this property to start drawing a dashed line partway through a segment or gap. For example, a phase value of 6 for the patter 5-2-3-2 would cause drawing to begin in the middle of the first gap. |
| `lineDashPattern` | `Array<Number>` | | An array of numbers specifying the dash pattern to use for the path. The array contains one or more numbers that indicate the lengths (measured in points) of the line segments and gaps in the pattern. The values in the array alternate, starting with the first line segment length, followed by the first gap length, followed by the second line segment length, and so on. |
| `lineCap` | `'butt' | 'round' | 'square'` | | The line cap style to apply to the open ends of the path. Possible values are `butt`, `round` or `square`. Note: lineCap is not yet supported for GoogleMaps provider on iOS. |
Expand Down
4 changes: 2 additions & 2 deletions lib/components/Geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ const getColor = (props, overlay, colorType, overrideColorProp) => {
}
return color;
}
return null;
return;
};

const getStrokeWidth = (props, overlay) => {
Expand All @@ -330,5 +330,5 @@ const getStrokeWidth = (props, overlay) => {
if (doesOverlayContainProperty(overlay, 'stroke-width')) {
return overlay.feature.properties['stroke-width'];
}
return 0;
return;
};

0 comments on commit fdd1eea

Please sign in to comment.