Googlelocator
Future

Googlelocator is a plugin that manages google places and maps and markers.

Javascript

Import the javascript file with import 'xtendui/src/googlelocator'.

Initialize manually within javascript with new Xt.Googlelocator(document.querySelector('.my-container'), {/* options */}).

Usage

Search for "New York" to see it in action.

This demos use loader see documentation for more info.

Needs google API key with Maps Javascript API, Places API.

Options

Here are the main javascript options. This component has complex options that are false by default see demo for custom values.

Additionally you have to pass functions to options.formatData to populate inside options.itemsTemplate with query data-xt-populate="<FunctionName>".

SyntaxDefault / ArgumentsDescription
Optiondebug:BooleanfalseDebug on console
OptioninitialLocate:BooleanfalseAutomatic locate on page load (needs https)
OptioninitialSearch:BooleanfalseAutomatic search on page load
OptionseachMapBounds:BooleanfalseMap bounds of current map when searching
OptionsearchRadius:Number25000Radius for locate and minimum radius for search (search uses location viewport given by google)
OptionlocateText:String'Locate'Locate text for input
OptionsubmitDelay:Number250Delay before each submit to show loader before js loop stops the render
Optionelements.loader:Query'[data-xt-googlelocator-loader]'Container query for loader
Optionelements.searchInput:Query'[data-xt-googlelocator-search-input]'Container query for searh input
Optionelements.searchBtn:Query'[data-xt-googlelocator-search-btn]'Container query for search button
Optionelements.map:Query'[data-xt-googlelocator-map]'Container query for google map
Optionelements.itemsTemplate:Query'[data-xt-googlelocator-items-template]'Container query for template cloned for maps items
Optionelements.itemsContainer:Query'[data-xt-googlelocator-items-container]'Container query for items container to append items to
Optionelements.results:Query'[data-xt-googlelocator-results]'Container query for results messages
Optionelements.resultsFounds:Query'[data-xt-googlelocator-results-found]'Container query for results found
Optionelements.locateBtn:Query'[data-xt-googlelocator-locate-btn]'Container query for locate button
Optionelements.repeatBtn:Query'[data-xt-googlelocator-repeat-btn]'Container query for repeat search button
Optionelements.filter:Query'[data-xt-googlelocator-filter]'Container query for filter checkbox and radio
Optionelements.formatData:Object<Object>Object for format data and filter functions

Default google maps options as follow.

// event
events: {
  animateMarkerClick: false,
  animateMarkerResultClick: false,
  infoWindowMarkerClick: true,
  infoWindowMarkerResultClick: false,
},
// autocomplete
autocompleteOptions: false,
autocompleteServiceOptions: false,
// map
map: {
  mapId: null,
  center: false,
  zoom: false,
  zoomMin: false,
  scrollwheel: false,
  zoomControl: true,
  mapTypeControl: false,
  scaleControl: true,
  streetViewControl: false,
  rotateControl: false,
  fullscreenControl: false,
  cluster: false,
},
// infoWindow
infoWindow: {},

Match Media

You can add additional options that gets added on match media query. You can use different queries with different and nested options.

SyntaxDefault / ArgumentsDescription
Optionmatches:ObjectfalseAdd additional options on match media query

Util

You can get self object on Xtend UI components with the constructor or Xt.get.

new Xt.Googlelocator(document.querySelector('.my-container'), {}).then(self => {})

// or

Xt.get({ name: 'xt-googlelocator', el: document.querySelector('.my-container') }).then(self => {})

You can set default options for all components of the same type, with Xt.options.

Xt.options['xt-googlelocator'] = {
  debug: true,
}

By default components are loaded and initialized only when inside viewport or instantly if self.container is not visible (display: none).

You can force global observer options or singular component observer options passing this option.

SyntaxDefault / ArgumentsDescription
Optionobserver:Boolean|nullnullForce enable or disable intersection observer

Listen

Listen to events, for listeners use this guideline.

SyntaxDOM ElementDescription
Eventchange.xt.googlelocatorcontainerChange event
Eventsetup.xt.googlelocatorcontainerSetup event
Eventinit.xt.googlelocatorcontainerInit or reinit event
Eventstatus.xt.googlelocatorcontainerStatus event (enabled or disabled)
Eventdestroy.xt.googlelocatorcontainerDestroy event

Properties

Access properties by getting self object.

SyntaxDescription
Propertyself.componentName:StringComponent name (used in Xt.get)
Propertyself.options:ObjectFinal options
Propertyself.initial:BooleanIf initial or reset activation
Propertyself.disabled:BooleanIf component disabled
Propertyself.container:NodeContainer node
Propertyself.locations:ArrayCurrent found locations
Propertyself.loaderElement:NodeLoader node
Propertyself.itemsTemplate:NodeItems template node
Propertyself.itemsContainer:NodeItems container node
Propertyself.resultElement:NodeResult node
Propertyself.foundElement:NodeFound node
Propertyself.mapElement:NodeMap node
Propertyself.map:ObjectMap object
Propertyself.info:ObjectInfoWindow object
Propertyself.cluster:ObjectMarkerClusterer object
Propertyself.searchInput:NodeSearch input node
Propertyself.search:ObjectSearch object
Propertyself.searchBtn:NodeSearch button node
Propertyself.filters:NodeFilter nodes
Propertyself.position:ObjectCurrent map position
Propertyself.viewport:ObjectCurrent map viewport
Propertyself.radius:NumberCurrent map radius

Methods

Call methods by getting self object.

SyntaxDescription
Methodself.reinit()Reinit component
Methodself.disable()Disable component
Methodself.enable()Enable component
Methodself.destroy()Destroy component

If you want to add markers dynamically override self.submit and call self.submitDeferred() when done:

self.submit = async () => {
  self.options.markers = await queryByLatLng(self.position.lat(), self.position.lng(), self.map.getZoom())
  self.submitDeferred()
}