Skip to content

Commit c2a798f

Browse files
websaidsaid-adibilarijani-syzygy
andauthoredSep 18, 2022
Custom map marker (#163)
* update libs * Add basic custom marker support * fix event parameter * Add prepare script Co-authored-by: Said Adibilarijani <said.adibilarijani@syzygy.de>
1 parent 8a5003b commit c2a798f

File tree

4 files changed

+31508
-6152
lines changed

4 files changed

+31508
-6152
lines changed
 

‎package-lock.json

+25,149
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"start": "webpack-dev-server --history-api-fallback --hot --host 0.0.0.0 --port 4040",
2020
"build": "rimraf lib && rollup -c && rimraf lib/demo && mv lib/src/* lib/ && rimraf lib/src",
2121
"prepublishOnly": "yarn build",
22+
"prepare": "npm run build",
2223
"prettier": "prettier --write \"src/**/*.tsx\" \"demo/**/*.tsx\" ",
2324
"test": "echo \"Error: no test specified\" && exit 1"
2425
},
@@ -99,4 +100,4 @@
99100
"lint-staged": {
100101
"*.{js,css,scss}": "prettier --write"
101102
}
102-
}
103+
}

‎src/overlays/Marker.tsx

+26-24
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ interface MarkerProps extends PigeonProps {
1313
style?: React.CSSProperties
1414
className?: string
1515

16+
children?: JSX.Element
17+
1618
// callbacks
1719
onClick?: ({ event: HTMLMouseEvent, anchor: Point, payload: any }) => void
1820
onContextMenu?: ({ event: HTMLMouseEvent, anchor: Point, payload: any }) => void
@@ -38,7 +40,7 @@ export function Marker(props: MarkerProps): JSX.Element {
3840
const color = props.color || '#93C0D0'
3941

4042
// what do you expect to get back with the event
41-
const eventParameters = (event: React.MouseEvent<SVGElement>) => ({
43+
const eventParameters = (event: React.MouseEvent) => ({
4244
event,
4345
anchor: props.anchor,
4446
payload: props.payload,
@@ -55,30 +57,30 @@ export function Marker(props: MarkerProps): JSX.Element {
5557
...(props.style || {}),
5658
}}
5759
className={props.className ? `${props.className} pigeon-click-block` : 'pigeon-click-block'}
60+
onClick={props.onClick ? (event) => props.onClick(eventParameters(event)) : null}
61+
onContextMenu={props.onContextMenu ? (event) => props.onContextMenu(eventParameters(event)) : null}
62+
onMouseOver={(event) => {
63+
props.onMouseOver && props.onMouseOver(eventParameters(event))
64+
setInternalHover(true)
65+
}}
66+
onMouseOut={(event) => {
67+
props.onMouseOut && props.onMouseOut(eventParameters(event))
68+
setInternalHover(false)
69+
}}
5870
>
59-
<svg width={width} height={height} viewBox="0 0 61 71" fill="none" xmlns="http://www.w3.org/2000/svg">
60-
<g
61-
style={{ pointerEvents: 'auto' }}
62-
onClick={props.onClick ? (event) => props.onClick(eventParameters(event)) : null}
63-
onContextMenu={props.onContextMenu ? (event) => props.onContextMenu(eventParameters(event)) : null}
64-
onMouseOver={(event) => {
65-
props.onMouseOver && props.onMouseOver(eventParameters(event))
66-
setInternalHover(true)
67-
}}
68-
onMouseOut={(event) => {
69-
props.onMouseOut && props.onMouseOut(eventParameters(event))
70-
setInternalHover(false)
71-
}}
72-
>
73-
<path
74-
d="M52 31.5C52 36.8395 49.18 42.314 45.0107 47.6094C40.8672 52.872 35.619 57.678 31.1763 61.6922C30.7916 62.0398 30.2084 62.0398 29.8237 61.6922C25.381 57.678 20.1328 52.872 15.9893 47.6094C11.82 42.314 9 36.8395 9 31.5C9 18.5709 18.6801 9 30.5 9C42.3199 9 52 18.5709 52 31.5Z"
75-
fill={color}
76-
stroke="white"
77-
strokeWidth="4"
78-
/>
79-
<circle cx="30.5" cy="30.5" r="8.5" fill="white" opacity={hover ? 0.98 : 0.6} />
80-
</g>
81-
</svg>
71+
{props.children || (
72+
<svg width={width} height={height} viewBox="0 0 61 71" fill="none" xmlns="http://www.w3.org/2000/svg">
73+
<g style={{ pointerEvents: 'auto' }}>
74+
<path
75+
d="M52 31.5C52 36.8395 49.18 42.314 45.0107 47.6094C40.8672 52.872 35.619 57.678 31.1763 61.6922C30.7916 62.0398 30.2084 62.0398 29.8237 61.6922C25.381 57.678 20.1328 52.872 15.9893 47.6094C11.82 42.314 9 36.8395 9 31.5C9 18.5709 18.6801 9 30.5 9C42.3199 9 52 18.5709 52 31.5Z"
76+
fill={color}
77+
stroke="white"
78+
strokeWidth="4"
79+
/>
80+
<circle cx="30.5" cy="30.5" r="8.5" fill="white" opacity={hover ? 0.98 : 0.6} />
81+
</g>
82+
</svg>
83+
)}
8284
</div>
8385
)
8486
}

‎yarn.lock

+6,331-6,127
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.