Creating info windows

These are your basic, run-of-the-mill white tooltips. While the custom overlay is way more customizable, these tooltips can be quite useful since they "just work"™.

The infoWindow component accepts three new arguments: isOpen, content, and target. For all the other options, read InfoWindowOptions ↗.

The isOpen attribute can be used to control the opening and closing of the tooltip using true or false. It automatically reverts back to false when the user closes the info window.

content lets you provide a string with text or even HTML that will be rendered in the tooltip. However, if you really want to render HTML content, I would recommend using the block form of the component. Anything defined within the block, will be rendered inside the info window.

The target attribute is used to attach the info window to a map component, like a marker. The infoWindow component yielded by the map is already attached to the map. You can override the position by overriding the target or setting the lat and lng coordinates manually.

Map components, like markers and circles, also yield their own infoWindow. These ones are already attached to the parent marker component, so the only thing left to do is set the isOpen attribute.

{{#g-map lat="51.507568" lng="-0.127762"
  zoom=12
  styles=primaryMapStyle as |g|}}

  {{!-- A manually positioned info window with basic text --}}
  {{g.infoWindow lat=london.lat lng=london.lng
    isOpen=mapTooltipOpen
    content="Simple text tooltip"}}

  {{!--
    An info window attached to a marker component.
    Notice how it is yielded by the marker itself.
    This info window displays the template defined in the block --}}
  {{#g.marker lat=london.lat lng=london.lng
    onClick=(action (toggle "markerTooltipOpen" this)) as |m|}}
    {{#m.infoWindow isOpen=markerTooltipOpen as |i|}}
      <div class="text-center">
        <img src="/images/doge-dbce44312027ca7f16631937e62ff5e9.jpg" alt="Such doge!" width=200>
        <div>Custom <i>HTML</i> content in infoWindow!</div>
      </div>
    {{/m.infoWindow}}
  {{/g.marker}}
{{/g-map}}

Test Click on the marker to show / hide a tooltip or use the toggle button below.

Next, let's look at how we can modify the default map UI.

Controls ›