Property map
Properties as price pins on a Google Map. Choose price pins or location icon pins. Pins drop in, click one to open a card, and pins that are close together group into a cluster.
Price pins
Default. Each pin shows the price. Pins drop in when the map scrolls into view, and the card pops in when you click a pin. Reload to see the drop again.
<div class="map-view" data-map-marker="price" ...> YOUR_API_KEY is not a real key, so the demo map is shown. With a real key the same markup shows Google Maps.
Location icon pins
A classic map pin with a home icon. Sale pins are green, rent pins are brass. Same data, same animations.
<div class="map-view" data-map-marker="icon" ...>
Setup
- Create a key in the Google Cloud Console and turn on Maps JavaScript API. Restrict the key to your website address.
- Put the key in
data-map-key. If it is empty, or stillYOUR_API_KEY, the demo map is shown. - Add your properties as JSON and point
data-property-mapat it.
<div class="map-view" data-property-map="#map-data" data-map-key="API_KEY"></div>
<script type="application/json" id="map-data">
[
{ "id": 1, "lat": 40.730, "lng": -73.987, "price": "$550,000",
"title": "Maple Court House", "address": "2726 Shinn Street, New York",
"image": "assets/img/properties/family-house-garden.webp", "url": "property-details.html",
"status": "sale", "beds": 4, "baths": 3, "area": "2,450 sq ft" }
]
</script>
<script src="assets/js/icons.min.js"></script>
<script src="assets/js/map-view.min.js"></script> If Google rejects the key, the map falls back to the demo map by itself.
Full width
Use .map-view--full for a map that fills the screen below the header, for example on a map listing page.
Attributes and classes
| Name | Purpose |
|---|---|
data-property-map | Selector of the JSON script that holds the properties. |
data-map-key | Google Maps API key. |
data-map-zoom | Start zoom. By default the map fits all pins. |
data-map-marker | price (default) or icon. |
data-map-animate | false turns off the pin drop and the card pop-in. Both are also off for visitors who prefer reduced motion. |
data-map-center | lat,lng to start at a fixed place. |
.map-view | The map box (560px high; 480px on phones). |
.map-view--full | Full screen height below the header. |
.map-pin, .map-pin--icon, .is-rent, .is-active | Pin (price or icon). Rent pins are brass. Added by map-view.js. |
.map-cluster | Group of close pins. Click to zoom in. |
.map-popup | Property card that opens above a pin. |
Keyboard: pins are buttons. Escape closes the card, then leaves full screen. Map colors are set in MAP_STYLE at the top of map-view.js.