Fork me on GitHub

class Maptimize.AddressChooser.Widget

Class to add "AddressChooser" behavior to a form. HTML markup must be present in DOM (nothing is generated by this object). Supported input fields are: input[type=text], select and textarea

It creates a Map object depending on mapping system on map DOM element. When map is ready onInitialized id called. In this callback map can be customized.

There are also 2 events fired by this object:

suggests:started: When a request is send to mapping system to get placemarks suggests from current address. suggests:found: When a response is received by mapping system.

Default options are (required fields are in bold):

 <th>Name</th>
 <th>Default value</th>
 <th>Description</th>

 <td>**map**</td>
 <td>map</td>
 <td>DOM id of map element</td>

 <td>**lat**</td>
 <td>lat</td>
 <td>DOM id of lat field (required)</td>

 <td>**lng**</td>
 <td>lng</td>
 <td>DOM id of lng field (required)</td>

 <td>street</td>
 <td>street</td>
 <td>DOM id of street field,can be use as unique address field</td>

 <td>city</td>
 <td>city</td>
 <td>DOM id of city field</td>

 <td>zip</td>
 <td>zip</td>
 <td>DOM id of zip field</td>

 <td>state</td>
 <td>state</td>
 <td>DOM id of state field</td>

 <td>country</td>
 <td>country</td>
 <td>DOM id of country field</td>

 <td>spinner</td>
 <td>false</td>
 <td>DOM id of a spinner element shown when a suggest search starts and hidden when a response is received</td>

 <td>icon</td>
 <td>null</td>
 <td>Icon object (depending on map system) to override default icon</td>

 <td>auto</td>
 <td>true</td>
 <td>Update map while typing</td>

 <td>delay</td>
 <td>300</td>
 <td>Delay in milliseconds before after typing address before searching for placemarks</td>

 <td>showAddressOnMap</td>
 <td>true</td>
 <td>Display current selected address in info window</td>

 <td>markerDraggable</td>
 <td>true</td>
 <td>Make marker on map draggable to move its position if mapping system has this feature</td>

 <td>mapProxy</td>
 <td>Maptimize.Proxy.GoogleMap</td>
 <td>Map proxy object. This allows to change mapping system. see Map.Proxy.GoogleMap to get information on how to create your own proxy.</td>

 <td>onInitialized</td>
 <td>empty function</td>
 <td>Callback called when the widget is ready (when map is ready to use).</td>

Constructor

new Maptimize.AddressChooser.Widget([options])
  • - options (Hash) – override default options.

Creates a new Maptimize.AddressChooser widget to add map based behavior to a regular address form.

Instance methods

  • addEventListener

    Maptimize.AddressChooser.Widget#addEventListener() -> Event Listener depending on mapping system.

    Returns a handle that can be used to eventually deregister the handler.

  • getAddress

    Maptimize.AddressChooser.Widget#getAddress(placemark) -> String

    Returns full address of a placemark if exists else returns empty string

  • getCity

    Maptimize.AddressChooser.Widget#getCity(placemark) -> String
    • - placemark (Object) – Placemark object depending on mapping system.

    Returns city name of a placemark if exists else returns empty string

  • getCountry

    Maptimize.AddressChooser.Widget#getCountry(placemark) -> String

    Returns country name of a placemark if exists else returns empty string

  • getCurrentAddress

    Maptimize.AddressChooser.Widget#getCurrentAddress() -> String

    Returns current address from input field values

  • getMap

    Maptimize.AddressChooser.Widget#getMap() -> Map object depending on mapping system

    Returns map object used by mapping system

  • getMap

    Maptimize.AddressChooser.Widget#getMap() -> Map object depending on mapping system

    Returns map object used by mapping system

  • getMapProxy

    Maptimize.AddressChooser.Widget#getMapProxy() -> Maptimize.Proxy

    Returns current map proxy

  • getStreet

    Maptimize.AddressChooser.Widget#getStreet(placemark) -> String

    Returns street name of a placemark if exists else returns empty string

  • getZIP

    Maptimize.AddressChooser.Widget#getZIP(placemark) -> String

    Returns zip code (postal code) of a placemark if exists else returns empty string

  • initMap

    Maptimize.AddressChooser.Widget#initMap([showAddress = false, zoom = 5]) -> undefined
    • - zoom (Integer) – map zoom (default 5)

    Initiliazes map with current form values. Use lat/lng values if defined, else get current address from input fields. If address is empty then center map on user location.

  • removeEventListener

    Maptimize.AddressChooser.Widget#removeEventListener(handle) -> undefined
    • - handle (Object) – handle returns by addEventListener.

    Removes an handler that has been created by addEventListener.

  • setIcon

    Maptimize.AddressChooser.Widget#setIcon(icon) -> undefined
    • - icon (Object) – icon object depending on mapping system

    Sets marker icon to override default icon (depending on mapping system)

  • showPlacemark

    Maptimize.AddressChooser.Widget#showPlacemark(index) -> undefined
    • - index (Integer) – index of suggested placemark, must be valid

    Displays suggested placemark on the map.

  • updateMap

    Maptimize.AddressChooser.Widget#updateMap() -> undefined

    fires addresschooser:suggests:started, addresschooser:suggests:found

    Removes a handler that was installed using addEventListener