|
| 1 | +/** |
| 2 | + * Gravity Perks // GP Address Autocomplete // Add Google Street View |
| 3 | + * https://gravitywiz.com/documentation/gravity-forms-address-autocomplete/ |
| 4 | + * |
| 5 | + * Experimental Snippet 🧪 |
| 6 | + * |
| 7 | + * Adds a Google Street View container to the bottom of the map and automatically |
| 8 | + * updates the Street View when the user selects an address. |
| 9 | + * |
| 10 | + * Instructions: |
| 11 | + * 1. Install our free Custom JavaScript for Gravity Forms plugin. |
| 12 | + * Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/ |
| 13 | + * 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin. |
| 14 | + */ |
| 15 | + |
| 16 | +window.gform.addAction('gpaa_marker_set', function (opts) { |
| 17 | + var panorama = new google.maps.StreetViewPanorama( |
| 18 | + document.getElementById('gpaa_street_view_container_' + opts.fieldId), |
| 19 | + { |
| 20 | + position: opts.map.getCenter(), |
| 21 | + pov: { |
| 22 | + heading: 34, |
| 23 | + pitch: 10, |
| 24 | + }, |
| 25 | + } |
| 26 | + ); |
| 27 | + |
| 28 | + opts.map.setStreetView(panorama); |
| 29 | +}); |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +window.gform.addAction('gpaa_map_initialized', function(map, formId, fieldId) { |
| 34 | + var mapSel = '#gpaa_map_container_' + fieldId; |
| 35 | + var streetViewSel = '#gpaa_street_view_container_' + fieldId; |
| 36 | + |
| 37 | + if (!$(streetViewSel).length) { |
| 38 | + $(mapSel).after('<div id="gpaa_street_view_container_' + fieldId + '" >Select an address to see a street view.</div>'); |
| 39 | + var divHeight = '500px'; |
| 40 | + $(streetViewSel).css({ |
| 41 | + // customize styling properties for the street view container here... |
| 42 | + height: divHeight, |
| 43 | + lineHeight: divHeight, |
| 44 | + backgroundColor: 'lightgray', |
| 45 | + marginTop: '1rem', |
| 46 | + textAlign: 'center', |
| 47 | + verticalAlign: 'middle', |
| 48 | + }); |
| 49 | + } |
| 50 | +}); |
0 commit comments