playbook_ui_docs 12.28.0.pre.alpha.PLAY814removemomentjs871 → 12.28.0.pre.alpha.PLAY837MapCustomButton868

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83402394f37e6b33829033f8f5edd82dddcec67b886b322c74930c9924a69d3d
4
- data.tar.gz: ea171d5457ccab6d5c7147dd8a6a4bdc3091840fe90a212848ae39d81689be7e
3
+ metadata.gz: 5a190a60e7ac71bbe145381200c14e00f26b9f4aabbcdf9ace62d5bbda2a712f
4
+ data.tar.gz: 102b23a8670cf6c7d3d644977c8782af70a7c3d922d4b15d9d185561b0ee8c00
5
5
  SHA512:
6
- metadata.gz: '093c98503af57e3e6340908a786661007a5c7477e78b345566bf41900e15387b3cb9976a917219be322065056b3fb588b4653806ea0bafb949d4ab1c29d8ecff'
7
- data.tar.gz: 8e8147c6d34606c04da7d6f14ac64133e8821f02189a052a216e95ef947e9b45eb1a348d9eaad922b5c96adbba2fe27cac9124554ca41702d2b8949b20284955
6
+ metadata.gz: ecca175ac0723a43181db1d0ed5d70b81db2c946ad6fa8220a213f88ee5bccbb6c89e99ca9dfc552add9823370af75347c224a09daab9b6b38e0b1ab61ad12b4
7
+ data.tar.gz: d22418dcddbfeda850b603af73c2f36701e032c39984fe9aadf632a7612871036012df20268dc772c0c77e296961927014fe3315c100a9dfcda50ac222b7c03b
@@ -0,0 +1,83 @@
1
+ import React, { useRef, useEffect, useState } from 'react'
2
+ import { Map, mapTheme, MapCustomButton } from '../..'
3
+ import maplibregl from 'maplibre-gl'
4
+
5
+ const MapWithCustomButton = (props) => {
6
+
7
+ //set Map instance to access from outside useEffect
8
+ const [mapInstance, setMapInstance] = useState(null)
9
+ const mapContainerRef = useRef(null)
10
+
11
+ //Set default position
12
+ const defaultPosition = [-75.379143, 39.831200]
13
+
14
+ // linking Maplibre methods to PB custom zoom in, zoom out, and fly to buttons
15
+ const handleZoomIn = (map) => {map.zoomIn({...mapTheme.zoomConfig})}
16
+ const handleZoomOut = (map) => {map.zoomOut({...mapTheme.zoomConfig})}
17
+ const handleFlyTo = (map) => {map.flyTo({
18
+ center: defaultPosition,
19
+ ... mapTheme.flyToConfig
20
+ });}
21
+
22
+ //This function is called by the useEffect when map instance first loads
23
+ const loadMap = ( { target: map }) => {
24
+ //set marker/pin
25
+ new maplibregl.Marker({
26
+ color: mapTheme.marker,
27
+ }).setLngLat(defaultPosition)
28
+ .setPopup(new maplibregl.Popup({closeButton: false}).setHTML(`<h4 class="pb_title_kit_size_4">Hello World!</h4>`)) // add popup
29
+ .addTo(map);
30
+
31
+ // disable map zoom when using scroll
32
+ map.scrollZoom.disable();
33
+
34
+ //add attributioncontrols
35
+ map.addControl(new maplibregl.AttributionControl({
36
+ compact: true
37
+ }));
38
+
39
+ //set map instance
40
+ setMapInstance(map)
41
+ }
42
+
43
+ useEffect(() => {
44
+ new maplibregl.Map({
45
+ container: mapContainerRef.current,
46
+ center: defaultPosition,
47
+ ...mapTheme.mapConfig
48
+ }).on('load', loadMap)
49
+
50
+ }, [])
51
+
52
+ return (
53
+ <Map
54
+ {...props}
55
+ >
56
+ <Map.Controls flyTo
57
+ flyToClick={()=> {handleFlyTo(mapInstance)}}
58
+ zoomBtns
59
+ zoomInClick={() => {handleZoomIn(mapInstance)}}
60
+ zoomOutClick={()=> {handleZoomOut(mapInstance)}}
61
+ >
62
+ <MapCustomButton icon="home"
63
+ onClick={() => alert("button clicked!")}
64
+ />
65
+ <MapCustomButton icon="search"
66
+ onClick={() => alert("button clicked!")}
67
+ />
68
+ </Map.Controls>
69
+ <div
70
+ ref={mapContainerRef}
71
+ style={{
72
+ position: 'absolute',
73
+ left: 0,
74
+ right: 0,
75
+ top: 0,
76
+ bottom: 0,
77
+ }}
78
+ />
79
+ </Map>
80
+ )
81
+ }
82
+
83
+ export default MapWithCustomButton
@@ -0,0 +1 @@
1
+ If you want to add custom buttons to the Map, you can use the `MapCustomButton` component nested inside Map.Controls as shown in the code snippet below. Note that when Map.Controls is used in this way, the props for the rest of the buttons must also be passed to Map.Controls instead of the Map itself.
@@ -4,3 +4,4 @@ examples:
4
4
  react:
5
5
  - map_default: Default
6
6
  - map_with_plugin: Map With Polygon Draw Plugin
7
+ - map_with_custom_button: Map With Custom Button
@@ -1,2 +1,3 @@
1
1
  export { default as MapDefault } from './_map_default.jsx'
2
2
  export { default as MapWithPlugin } from './_map_with_plugin.jsx'
3
+ export {default as MapWithCustomButton} from './_map_with_custom_button.jsx'