Maps
note
When rendering HomeflowJS map elements into DOM nodes, remember to set a height
on the container DOM node or the map will not be visible.
Property Results Map
The property results map will be included by default with the PropertyResults
component, on the route #/map
.
If you wish to render the map separately (like if you want to render the map and results side-by-side), pass the noMap
prop to PropertyResults
and render the PropertiesMap
yourself:
Whether you render the map yourself or let PropertyResults
do so, you must define a template with an id of property-map-popup-template
somewhere in your markup for Leaflet to use as a popup when a property marker is clicked.
As much of the code for the property results map depends on older libraries and legacy JS, this template uses lodash.template instead of React.
Here is a simple example:
You can optionally set the type of layer to use on the Leaflet map. The default is the normal leaflet map layer, but you can pass the string google
to use the google maps layer:
If you use google
, make sure the agency has a google_maps_api_key
set up in their admin area.
If you need to render a custom layer, you can instead pass a callback function (it's important you pass this as a function that returns the tile layer instead of trying to pass the L.tileLayer object itself):
PropertyMap
The PropertyMap
component will render a map for a single property on the property show page.
By default it will render a leaflet map. Pass the prop google
to render a Google map instead (ensure the agent has a google_maps_api_key
set in admin if you use this).
Leaflet property map zoom level is defaulted to 100.
You can set it to the agency property zoom level (editable in exampleagency.homeflow.co.uk/configure/website/appearance/preferences -> Zoom on property maps) by adding to your views/properties/_show.ljson
file the following:
Leaflet map markers assume a default anchor position of the top left corner of the icon, which can make most marker icons appear offset whilst zooming. An anchor position of [12, 41]
has been applied for the
default marker icon (anchoring at the center bottom point of the marker).
If using a custom marker icon this value may need to be updated depending on the dimensions and shape of the custom icon. This can be done by adding to your views/properties/show.liquid
the following:
Prop | Type | Description |
---|---|---|
google | Boolean | Use Google Maps instead of Leaflet to render the map. |
custom | String | Pass "simple_bw" to render a simplified grayscale google map. |
CustomPopup | Component | Component to render as a popup when marker is clicked |
How to add a popup to the Property Map depends on whether it is a google map or leaflet map.
Unlike the Property Results Map, which renders a react leaflet map with a google tile layer if the google
prop is included,
the Property Map uses the google maps API to render a map in vanilla Javascript if the google
prop is included,
so each requires a different approach.
If a leaflet map is rendered you can simply pass a React component as the CustomPopup
prop, similar to what is done in the Branches Map.
The CustomPopup
will receieve the property as a prop.
If a google map is rendered you will need to add a template script to the theme with an id
of property-show-map-popup-template
:
This can either be added directly to /views/properties/_show.liquid
or can be added to its own liquid partial, which
can then be included in /views/properties/_show.liquid
.
The innerHTML
of this script will be passed to the google map and attached to the marker. Note that you will need to use liquid
to generate dynamic property data.
PropertyStreetview
Renders a google streetview element for the property.
BranchesMap
Renders a leaflet map of the agency's branch locations for the branches index page. Optionally pass a CustomPopup
component as a prop to use this when a marker is clicked instead of the default. The CustomPopup
will receive the branch as a prop.
You can override the default icon by passing an iconConfig
prop. The shape of the object should match the example in the Leaflet docs: https://leafletjs.com/reference.html#icon
The default iconConfig looks like this:
Prop | Type | Description |
---|---|---|
CustomPopup | Component | Component to render as a popup when markers are clicked |
google | Boolean | Use a Google map layer on top of the Leaflet map (requires Google API key to be set) |
iconConfig | Object | Pass a custom object to be passed to Leaflet Icon |
BranchMap
Render a map for a single Branch on the Branch show page.
By default it will render a Leaflet map. Pass the prop google
to render a Google map instead (ensure the agent has a google_maps_api_key
set in admin if you use this).
You can override the default icon by passing an iconConfig
prop as described for the BranchesMap component above.
Prop | Type | Description |
---|---|---|
google | Boolean | Use Google Maps instead of Leaflet to render the map. |
custom | String | Pass "simple_bw" to render a simplified grayscale google map. |
iconConfig | Object | Pass a custom object to be passed to Leaflet Icon |
CustomPopup | Component | Component to render as a popup when marker is clicked |
Similar to the Property Map, the Branch Map uses the google maps Javascript API to render a google map, so rendering a popup will require different implementations depending on whether a leaflet or google map is displayed.
If a leaflet map is rendered you can simply pass a React component as the CustomPopup
prop, similar to what is done in the Branches Map.
The CustomPopup
will receive the branch as a prop.
If a google map is rendered you will need to add a template script to the theme with an id
of branch-map-popup-template
:
This can either be added directly to /views/branches/_show.liquid
or can be added to its own liquid partial, which
can then be included in /views/branches/_show.liquid
.
The innerHTML
of this script will be passed to the google map and attached to the marker. Note that you will need to use liquid
to generate dynamic branch data.