Skip to content

Commit ad157c9

Browse files
author
wgj
committed
fix: Point.Content Bug fix.
Signed-off-by: wgj <wgj>
1 parent c3d3bdf commit ad157c9

File tree

21 files changed

+106
-64
lines changed

21 files changed

+106
-64
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@
7474

7575
- TileLayers
7676

77-
- Types
78-
7977
## Data Structure
8078

8179
- ThemeProps: `{ path?: L.PathOptions }` (see [Leaflet.js](#docs) docs)
@@ -491,14 +489,15 @@ import { RCMap, MassPoints, Popup, Tooltip } from 'rc-leaflet'
491489
#### `Usage`
492490

493491
```jsx
494-
import { RCMap, ClusterPoints, Popup, Tooltip } from 'rc-leaflet'
492+
import { RCMap, Point, ClusterPoints, Popup, Tooltip } from 'rc-leaflet'
495493
496494
(
497495
<RCMap>
498496
<ClusterPoints points />
499497
500498
<DivIcon>
501499
<ClusterPoints points>
500+
<Point.Content />
502501
<Popup>this is Popup.</Popup>
503502
<Tooltip>this is Tooltip.</Tooltip>
504503
</ClusterPoints>
@@ -840,7 +839,7 @@ import { RCMap, Icon, Point } from 'rc-leaflet'
840839
#### `Usage`
841840
842841
```jsx
843-
import { RCMap, DivIcon, Point } from 'rc-leaflet'
842+
import { RCMap, Point, DivIcon, Point } from 'rc-leaflet'
844843
845844
(
846845
<RCMap>

UPDATE.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,46 @@
44

55
- feature: new Component `Point.Content`, used to replace `content` prop of `DivIcon`.
66

7+
```jsx
8+
<Point>
9+
<Point.Content />
10+
</Point>
11+
12+
<Point>
13+
<DivIcon>
14+
<Point.Content />
15+
</DivIcon>
16+
</Point>
17+
18+
<DivIcon>
19+
<Point>
20+
<Point.Content />
21+
</Point>
22+
</DivIcon>
23+
24+
<ClusterPoints>
25+
<Point.Content />
26+
</ClusterPoints>
27+
28+
<DivIcon>
29+
<ClusterPoints>
30+
<Point.Content />
31+
</ClusterPoints>
32+
</DivIcon>
33+
```
34+
735
- feature: new Components, export all abstract Components for plugin development.
836

937
- feature: add `TileLayers.OpenStreetMap`, `TileLayers.GoogleMap` config.
1038

1139
- feature: new Components `TileLayer.BMap`, `TileLayer.AMap`, `TileLayer.OpenStreetMap`, `TileLayer.GoogleMap`
1240

41+
```jsx
42+
<RCMap crs>
43+
<TileLayer.GoogleMap />
44+
</RCMap>
45+
```
46+
1347
## v1.1.3
1448

1549
- fix: handle the edge case when layer of `DivOverlay` is changed.
@@ -26,7 +60,7 @@
2660

2761
- feature: new Component `MassPoints`.
2862

29-
```js
63+
```jsx
3064
<MassPoints points />
3165

3266
<MassPoints points iconUrl />
@@ -39,7 +73,7 @@
3973

4074
- feature: new Component `ClusterPoints`.
4175

42-
```js
76+
```jsx
4377
<ClusterPoints points />
4478

4579
<DivIcon>
@@ -70,7 +104,7 @@
70104

71105
- feature: `DivIcon` supports single jsx element.
72106

73-
```js
107+
```jsx
74108
let Content = (
75109
<div>
76110
<div>content row.</div>

src/components/BaseIcon/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { PureComponent, Children, isValidElement, cloneElement } from 'react'
22
import PropTypes from 'prop-types'
33
import L from 'leaflet'
4-
import * as Types from '../Util/PropTypes'
4+
import { Pixel } from '../../util/PropTypes'
55

66
interface PartialProps {
77
layer: L.Marker
@@ -16,14 +16,14 @@ export default abstract class BaseIcon<T extends L.Icon | L.DivIcon, P extends L
1616
attribution: PropTypes.string,
1717
iconUrl: PropTypes.string,
1818
iconRetinaUrl: PropTypes.string,
19-
iconSize: Types.Pixel,
20-
iconAnchor: Types.Pixel,
21-
popupAnchor: Types.Pixel,
22-
tooltipAnchor: Types.Pixel,
19+
iconSize: Pixel,
20+
iconAnchor: Pixel,
21+
popupAnchor: Pixel,
22+
tooltipAnchor: Pixel,
2323
shadowUrl: PropTypes.string,
2424
shadowRetinaUrl: PropTypes.string,
25-
shadowSize: Types.Pixel,
26-
shadowAnchor: Types.Pixel,
25+
shadowSize: Pixel,
26+
shadowAnchor: Pixel,
2727
className: PropTypes.string,
2828
layer: PropTypes.instanceOf(L.Marker),
2929
children: PropTypes.node

src/components/CircleMarker/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PropTypes from 'prop-types'
22
import L from 'leaflet'
3-
import * as Types from '../Util/PropTypes'
3+
import { Point } from '../../util/PropTypes'
44
import Path from '../Path'
55

66
export type CircleMarkerOptions = Omit<L.CircleMarkerOptions, 'radius'>
@@ -16,7 +16,7 @@ export default class CircleMarker<P extends CircleMarkerOptions = CircleMarkerOp
1616
public static propTypes = {
1717
...Path.propTypes,
1818
radius: PropTypes.number.isRequired,
19-
center: Types.Point.isRequired
19+
center: Point.isRequired
2020
}
2121

2222
protected createInstance (props: Props & P): L.CircleMarker {

src/components/ClusterPoints/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react'
44
import PropTypes from 'prop-types'
55
import L from 'leaflet'
66
import 'leaflet.markercluster'
7-
import * as Types from '../Util/PropTypes'
7+
import { Icon, Point } from '../../util/PropTypes'
88
import { ContextType } from '../RCMap/Context'
99
import Layer from '../Layer'
1010
import PointContext from '../Point/Context'
@@ -28,8 +28,8 @@ type Props = Readonly<RequiredProps & Partial<PartialProps> & L.MarkerClusterGro
2828
export default class ClusterPoints extends Layer<L.MarkerClusterGroup, Props> {
2929
public static propTypes = {
3030
...Layer.propTypes,
31-
points: PropTypes.arrayOf(Types.Point).isRequired,
32-
icon: Types.Icon,
31+
points: PropTypes.arrayOf(Point).isRequired,
32+
icon: Icon,
3333
clusterPane: PropTypes.string,
3434
chunkProgress: PropTypes.func,
3535
showCoverageOnHover: PropTypes.bool,

src/components/DivIcon/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PropTypes from 'prop-types'
22
import L from 'leaflet'
3-
import * as Types from '../Util/PropTypes'
3+
import { Pixel } from '../../util/PropTypes'
44
import creator, { defaultIcon } from './creator'
55
import BaseIcon, { Props as BaseIconProps } from '../BaseIcon'
66

@@ -25,10 +25,10 @@ export default class DivIcon extends BaseIcon<L.DivIcon, Props> {
2525
public static propTypes = {
2626
...BaseIcon.propTypes,
2727
html: PropTypes.oneOfType([PropTypes.string, PropTypes.oneOf<false>([false])]),
28-
bgPos: Types.Pixel,
29-
iconSize: Types.Pixel,
30-
iconAnchor: Types.Pixel,
31-
popupAnchor: Types.Pixel,
28+
bgPos: Pixel,
29+
iconSize: Pixel,
30+
iconAnchor: Pixel,
31+
popupAnchor: Pixel,
3232
className: PropTypes.string
3333
}
3434

src/components/DivOverlay/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { PureComponent } from 'react'
22
import { createPortal } from 'react-dom'
33
import PropTypes from 'prop-types'
44
import L from 'leaflet'
5-
import * as Types from '../Util/PropTypes'
5+
import { Pixel, Point } from '../../util/PropTypes'
66
import Context, { ContextType } from '../RCMap/Context'
77

88
interface PartialProps {
@@ -17,12 +17,12 @@ type Props = Readonly<Partial<PartialProps>>
1717

1818
export default abstract class DivOverlay<T extends L.Popup | L.Tooltip, P extends L.PopupOptions | L.TooltipOptions> extends PureComponent<Props & P> {
1919
public static propTypes = {
20-
offset: Types.Pixel,
20+
offset: Pixel,
2121
zoomAnimation: PropTypes.bool,
2222
className: PropTypes.string,
2323
pane: PropTypes.string,
2424
layer: PropTypes.instanceOf(L.Layer),
25-
position: Types.Point,
25+
position: Point,
2626
children: PropTypes.node,
2727
onOpen: PropTypes.func,
2828
onClose: PropTypes.func

src/components/Evented/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PureComponent } from 'react'
22
import PropTypes from 'prop-types'
33
import L from 'leaflet'
4-
import { LeafletMouseEventHandlerFn } from '../Util/Types'
4+
import { LeafletMouseEventHandlerFn } from '../../util/Types'
55

66
interface MouseEvents {
77
onClick: LeafletMouseEventHandlerFn

src/components/MassPoints/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Children, isValidElement, cloneElement } from 'react'
22
import PropTypes from 'prop-types'
33
import L from 'leaflet'
4-
import * as Types from '../Util/PropTypes'
5-
import { getBounds } from '../Util/Map'
4+
import { Pixel, Point } from '../../util/PropTypes'
5+
import { getBounds } from '../../util/Map'
66
import { ContextType } from '../RCMap/Context'
77
import { defaultOptions } from '../Icon/creator'
88
import InteractiveLayer from '../InteractiveLayer'
@@ -38,12 +38,12 @@ type State = Readonly<{
3838
export default class MassPoints extends InteractiveLayer<L.ImageOverlay, Props, State> {
3939
public static propTypes = {
4040
...InteractiveLayer.propTypes,
41-
points: PropTypes.arrayOf(Types.Point).isRequired,
41+
points: PropTypes.arrayOf(Point).isRequired,
4242
iconUrl: PropTypes.string,
43-
iconSize: Types.Pixel,
44-
iconAnchor: Types.Pixel,
45-
popupAnchor: Types.Pixel,
46-
tooltipAnchor: Types.Pixel
43+
iconSize: Pixel,
44+
iconAnchor: Pixel,
45+
popupAnchor: Pixel,
46+
tooltipAnchor: Pixel
4747
}
4848

4949
private canvas: HTMLCanvasElement

src/components/Point/Content.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ interface PartialProps {
1111

1212
type Props = Readonly<Partial<PartialProps>>
1313

14+
const isTargetPoint = (layer: L.Layer): layer is L.Marker => {
15+
if (!layer) {
16+
return false
17+
}
18+
const point = layer as L.Marker
19+
const icon = point.getIcon && point.getIcon()
20+
return icon && icon instanceof L.DivIcon
21+
}
22+
1423
export default class Content extends PureComponent<Props> {
1524
public static propTypes = {
1625
children: PropTypes.node
@@ -25,10 +34,10 @@ export default class Content extends PureComponent<Props> {
2534
const layer = this.context && this.context.instance
2635

2736
if (layer) {
28-
if (layer instanceof L.Marker && layer.getIcon() instanceof L.DivIcon && layer.getElement()) {
37+
if (isTargetPoint(layer)) {
2938
return createPortal(<div className={className} {...props}>{ children }</div>, layer.getElement())
3039
} else if (layer instanceof L.LayerGroup) {
31-
const points = layer.getLayers().filter(el => el instanceof L.Marker && el.getIcon() instanceof L.DivIcon && el.getElement()) as L.Marker[]
40+
const points = layer.getLayers().filter<L.Marker>(isTargetPoint)
3241
return points.map(point => createPortal(<div className={className} {...props}>{ children }</div>, point.getElement()))
3342
}
3443
}

0 commit comments

Comments
 (0)