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AM,MACNF,IAAK,MAENY,mBAAmB,EACnBC,gBAAgB,EAChBC,mBAAmB,EACnBC,aAAa,EACbC,OAAQ,CACP,CACCC,YAAa,MACbC,QAAS,CAAC,CAAEC,WAAY,WAKvBpC,KAAKF,oBACR6B,EAAKC,OAAS5B,KAAKF,mBAYpB6B,EAAOjC,OAAO0B,MAAMiB,aACnB,mBACAV,EACA3B,KAAKL,OACLK,KAAKJ,SAGNI,KAAKsC,IAAM,IAAIhC,OAAOiC,KAAKC,IAAIxC,KAAKE,aAAcyB,GAE1C,QAAR,EAAA3B,KAAKsC,WAAG,SAAEG,QAAQd,EAAK5B,MAAQC,KAAKD,MAEhCC,KAAKF,mBACRE,KAAKwB,UAAUxB,KAAKF,mBAUrBJ,OAAO0B,MAAMsB,SACZ,uBACA1C,KAAKsC,IACLtC,KAAKL,OACLK,KAAKJ,UAIP,YAAA4B,UAAA,SAAUmB,G,MAEL3C,KAAK4C,QACR5C,KAAK4C,OAAOC,OAAO,MAGpB,IAAIlB,EAAkC,CACrCgB,SAAQ,EACRL,IAAKtC,KAAKsC,KAYXX,EAAOjC,OAAO0B,MAAMiB,aACnB,sBACAV,EACA3B,KAAKL,OACLK,KAAKJ,SAGNI,KAAK4C,OAAS,IAAItC,OAAOiC,KAAKO,OAAOnB,GAErC,IAAMoB,EAAY/C,KAAK4C,OAAOI,cAE1BD,IACK,QAAR,EAAA/C,KAAKsC,WAAG,SAAEW,MAAMF,IAcjBrD,OAAO0B,MAAMsB,SAAS,kBAAmB,CACxC/C,OAAQK,KAAKL,OACbC,QAASI,KAAKJ,QACdC,eAAgBG,KAAKH,eACrByC,IAAKtC,KAAKsC,IACVM,OAAQ5C,KAAK4C,UAGhB,EA9NA,GAgOAlD,OAAOwD,kCAAoCA,G","sources":["webpack://gp-address-autocomplete/./js/src/map-field.ts"],"sourcesContent":["/* eslint-disable jsdoc/no-undefined-types */\n\nconst { jQuery: $ } = window;\n\ninterface GPAAFieldsFilledPlace {\n\tgeometry: {\n\t\tlocation: {\n\t\t\tlat: () => number;\n\t\t\tlng: () => number;\n\t\t};\n\t};\n}\n\ninterface Coords {\n\tlat: number;\n\tlng: number;\n}\n\ninterface GPAddressAutocompleteMapFieldOpts {\n\tformId: number;\n\tfieldId: number;\n\taddressFieldId: number;\n\tprepopulateCoords?: Coords;\n}\n\nclass GP_Address_Autocomplete_Map_Field {\n\tformId: number;\n\n\tfieldId: number;\n\n\taddressFieldId: number;\n\n\tprepopulateCoords?: Coords;\n\n\tmapContainer: HTMLElement;\n\n\tmap: google.maps.Map | undefined;\n\n\tmarker: google.maps.Marker | undefined;\n\n\tzoom = 15;\n\n\tconstructor({\n\t\tformId,\n\t\tfieldId,\n\t\taddressFieldId,\n\t\tprepopulateCoords,\n\t}: GPAddressAutocompleteMapFieldOpts) {\n\t\tthis.formId = formId;\n\t\tthis.fieldId = fieldId;\n\t\tthis.addressFieldId = addressFieldId;\n\t\tthis.prepopulateCoords =\n\t\t\tthis.getPostedAddressFieldCoords() || prepopulateCoords;\n\n\t\tthis.mapContainer = document.querySelector(\n\t\t\t`#gpaa_map_container_${this.fieldId}`\n\t\t)!;\n\n\t\t// The google maps sdk script will not be loaded unless the conncted address field has autocomplete enabled.\n\t\t// This is usually because the attached addressFieldId does not have the \"Enable Google Address Autocomplete\" option enabled.\n\t\t// We do check before rendering the map div if the autocomplete field is checked so this *shouldn't* happen, but just in case...\n\t\tif (window.google === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.setupListeners();\n\t\tthis.initMap();\n\t}\n\n\t// Get coords from an address field that is on a previous page of a multi-page form\n\t// These coords will be stored in a hidden input field\n\tgetPostedAddressFieldCoords(): Coords | undefined {\n\t\tconst $form = document.querySelector(\n\t\t\t`#gform_${this.formId}`\n\t\t);\n\t\tconst $input = $form?.querySelector(\n\t\t\t`input[name=\"gpaa_coords_${this.addressFieldId}\"]`\n\t\t);\n\n\t\tif (!$input?.value) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet prepopulateCoords: Coords | undefined;\n\n\t\ttry {\n\t\t\tprepopulateCoords = JSON.parse($input.value);\n\t\t} catch (err) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.debug(err);\n\n\t\t\treturn;\n\t\t}\n\n\t\t// Convert lat and lng to numbers if they're strings.\n\t\tif (typeof prepopulateCoords?.lat === 'string') {\n\t\t\tprepopulateCoords.lat = Number(prepopulateCoords.lat);\n\t\t}\n\n\t\tif (typeof prepopulateCoords?.lng === 'string') {\n\t\t\tprepopulateCoords.lng = Number(prepopulateCoords.lng);\n\t\t}\n\n\t\tif (!prepopulateCoords?.lat || !prepopulateCoords?.lng) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn prepopulateCoords;\n\t}\n\n\tsetupListeners() {\n\t\twindow.gform.addAction(\n\t\t\t'gpaa_fields_filled',\n\t\t\t(\n\t\t\t\tplace: GPAAFieldsFilledPlace,\n\t\t\t\tinstance: null,\n\t\t\t\tformId: number,\n\t\t\t\tfieldId: number\n\t\t\t) => {\n\t\t\t\tif (formId !== this.formId || fieldId !== this.addressFieldId) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.setMarker({\n\t\t\t\t\tlat: place.geometry.location.lat(),\n\t\t\t\t\tlng: place.geometry.location.lng(),\n\t\t\t\t});\n\t\t\t}\n\t\t);\n\t}\n\n\tinitMap() {\n\t\tlet opts: google.maps.MapOptions = {\n\t\t\tzoom: this.zoom,\n\t\t\tcenter: {\n\t\t\t\tlng: -73.95,\n\t\t\t\tlat: 40.8,\n\t\t\t},\n\t\t\tfullscreenControl: false,\n\t\t\tmapTypeControl: false,\n\t\t\tstreetViewControl: false,\n\t\t\tzoomControl: false,\n\t\t\tstyles: [\n\t\t\t\t{\n\t\t\t\t\tfeatureType: 'poi',\n\t\t\t\t\tstylers: [{ visibility: 'off' }],\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\n\t\tif (this.prepopulateCoords) {\n\t\t\topts.center = this.prepopulateCoords;\n\t\t}\n\n\t\t/**\n\t\t * Filter the options used to initialize the map.\n\t\t *\n\t\t * @param {google.maps.MapOptions} options Contains the map configuration options. All available options are documented here: https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions\n\t\t * @param {number} formId The current form ID.\n\t\t * @param {number} fieldId The current field ID.\n\t\t *\n\t\t * @since 1.2.1\n\t\t */\n\t\topts = window.gform.applyFilters(\n\t\t\t'gpaa_map_options',\n\t\t\topts,\n\t\t\tthis.formId,\n\t\t\tthis.fieldId\n\t\t);\n\n\t\tthis.map = new google.maps.Map(this.mapContainer, opts);\n\n\t\tthis.map?.setZoom(opts.zoom || this.zoom);\n\n\t\tif (this.prepopulateCoords) {\n\t\t\tthis.setMarker(this.prepopulateCoords);\n\t\t}\n\n\t\t/**\n\t\t * Action that fires once right after the map is initialized.\n\t\t *\n\t\t * @param {google.maps.Map} map The map object.\n\t\t * @param {number} formId The current form ID.\n\t\t * @param {number} fieldId The current field ID.\n\t\t */\n\t\twindow.gform.doAction(\n\t\t\t'gpaa_map_initialized',\n\t\t\tthis.map,\n\t\t\tthis.formId,\n\t\t\tthis.fieldId\n\t\t);\n\t}\n\n\tsetMarker(position: Coords) {\n\t\t// remove marker from the map if it exists\n\t\tif (this.marker) {\n\t\t\tthis.marker.setMap(null);\n\t\t}\n\n\t\tlet opts: google.maps.MarkerOptions = {\n\t\t\tposition,\n\t\t\tmap: this.map,\n\t\t};\n\n\t\t/**\n\t\t * Filter the options used to add a marker to the map.\n\t\t *\n\t\t * @param {google.maps.MarkerOptions} options Contains the marker options. All available options are documented here: https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/javascript/reference/marker#MarkerOptions\n\t\t * @param {number} formId The current form ID.\n\t\t * @param {number} fieldId The current field ID.\n\t\t *\n\t\t * @since 1.2.1\n\t\t */\n\t\topts = window.gform.applyFilters(\n\t\t\t'gpaa_marker_options',\n\t\t\topts,\n\t\t\tthis.formId,\n\t\t\tthis.fieldId\n\t\t);\n\n\t\tthis.marker = new google.maps.Marker(opts);\n\n\t\tconst markerPos = this.marker.getPosition();\n\n\t\tif (markerPos) {\n\t\t\tthis.map?.panTo(markerPos);\n\t\t}\n\n\t\t/**\n\t\t * Action that fires after a marker is added to the map.\n\t\t *\n\t\t * @param params.formId ID of the form the map field is in.\n\t\t * @param params.fieldId ID of the map field the marker was added to.\n\t\t * @param params.addressFieldId ID of the address field the map field is attached to.\n\t\t * @param params.map The map object that the marker was added to.\n\t\t * @param params.marker The marker object that was addded to the map.\n\t\t *\n\t\t * @since 1.2.3\n\t\t */\n\t\twindow.gform.doAction('gpaa_marker_set', {\n\t\t\tformId: this.formId,\n\t\t\tfieldId: this.fieldId,\n\t\t\taddressFieldId: this.addressFieldId,\n\t\t\tmap: this.map,\n\t\t\tmarker: this.marker,\n\t\t});\n\t}\n}\n\nwindow.GP_Address_Autocomplete_Map_Field = GP_Address_Autocomplete_Map_Field;\n\n// Make this a module to avoid TypeScript error with block-scoped variables since we're not importing anything\nexport {};\n"],"names":["window","formId","fieldId","addressFieldId","prepopulateCoords","zoom","this","getPostedAddressFieldCoords","mapContainer","document","querySelector","undefined","google","setupListeners","initMap","$form","$input","value","JSON","parse","err","console","debug","lat","Number","lng","gform","addAction","place","instance","setMarker","geometry","location","opts","center","fullscreenControl","mapTypeControl","streetViewControl","zoomControl","styles","featureType","stylers","visibility","applyFilters","map","maps","Map","setZoom","doAction","position","marker","setMap","Marker","markerPos","getPosition","panTo","GP_Address_Autocomplete_Map_Field"],"sourceRoot":""}