-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Woosmap/dev/store-locator-widget
Migrate Store Locator Widget Samples
- Loading branch information
Showing
19 changed files
with
1,500 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% extends '../../src/_includes/layout.njk' %} | ||
{% block external %} | ||
<script src="https://webapp.woosmap.com/webapp.js"></script> | ||
{% endblock %} | ||
{% block html %} | ||
<!-- [START woosmap_{{ tag }}_div] --> | ||
<div id="map"></div> | ||
<!-- [END woosmap_{{ tag }}_div] --> | ||
{% endblock %} | ||
{% block api %}{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// [START woosmap_store_locator_custom_filters] | ||
const availableServices = [ | ||
{ key: "WF", en: "Wireless Hotspot" }, | ||
{ key: "CD", en: "Mobile Payment" }, | ||
{ key: "DT", en: "Drive-Thru" }, | ||
{ key: "DR", en: "Digital Rewards" }, | ||
{ key: "hrs24", en: "Open 24 hours per day" }, | ||
{ key: "WA", en: "Oven-warmed Food" }, | ||
{ key: "LB", en: "LaBoulange" }, | ||
{ key: "XO", en: "Mobile Order and Pay" }, | ||
{ key: "VS", en: "Verismo" }, | ||
{ key: "NB", en: "Nitro Cold Brew" }, | ||
{ key: "CL", en: "Starbucks Reserve-Clover Brewed" }, | ||
]; | ||
|
||
const storeLocatorConfig = { | ||
maps: { | ||
provider: "woosmap", | ||
localities: { | ||
types: [], | ||
componentRestrictions: { country: "gb" }, | ||
}, | ||
}, | ||
filters: { | ||
filters: [ | ||
{ | ||
propertyType: "tag", | ||
title: { | ||
en: "Amenities", | ||
}, | ||
choices: availableServices, | ||
innerOperator: "or", | ||
}, | ||
{ | ||
propertyType: "custom", | ||
title: { | ||
en: "Country", | ||
}, | ||
choices: [ | ||
{ | ||
key: 'country:="US"', | ||
en: "United States", | ||
}, | ||
{ | ||
key: 'country:="GB"', | ||
en: "United Kingdom", | ||
}, | ||
{ | ||
key: 'country:="DE"', | ||
en: "Germany", | ||
}, | ||
{ | ||
key: 'country:="FR"', | ||
en: "France", | ||
}, | ||
], | ||
innerOperator: "or", | ||
}, | ||
], | ||
outerOperator: "and", | ||
}, | ||
theme: { | ||
primary_color: "#008248", | ||
}, | ||
woosmapview: { | ||
initialCenter: { | ||
lat: 54, | ||
lng: -3, | ||
}, | ||
initialZoom: 7, | ||
breakPoint: 11, | ||
style: { | ||
default: { | ||
icon: { | ||
url: "https://demo.woosmap.com/storelocator/images/markers/starbucks-marker.svg", | ||
scaledSize: { | ||
height: 47, | ||
width: 40, | ||
}, | ||
}, | ||
numberedIcon: { | ||
url: "https://demo.woosmap.com/storelocator/images/markers/starbucks-marker.svg", | ||
scaledSize: { | ||
height: 47, | ||
width: 40, | ||
}, | ||
}, | ||
selectedIcon: { | ||
url: "https://demo.woosmap.com/storelocator/images/markers/starbucks-marker-selected.svg", | ||
scaledSize: { | ||
height: 71, | ||
width: 61, | ||
}, | ||
}, | ||
}, | ||
}, | ||
tileStyle: { | ||
color: "#008248", | ||
size: 15, | ||
minSize: 6, | ||
}, | ||
}, | ||
}; | ||
|
||
function isMobileDevice(): boolean { | ||
return window.innerWidth < 500; | ||
} | ||
|
||
function createDiv(className = "", innerHTML = ""): HTMLDivElement { | ||
const div = document.createElement("div"); | ||
div.className = className; | ||
div.innerHTML = innerHTML; | ||
return div; | ||
} | ||
|
||
function filterPanelRenderer( | ||
title: string, | ||
children: HTMLElement[], | ||
): HTMLDivElement { | ||
const div = createDiv( | ||
"filters-list", | ||
`<div class='filter-group'>${title}</div>`, | ||
); | ||
children.forEach((item: HTMLElement) => { | ||
div.appendChild(item); | ||
}); | ||
return div; | ||
} | ||
|
||
function filterRenderer( | ||
key: string, | ||
label: string, | ||
selected: boolean, | ||
): HTMLDivElement { | ||
const className = key.startsWith("country") | ||
? `${key.split("=").pop()?.replace(/[",]+/g, "")} country` | ||
: key; | ||
return createDiv( | ||
selected ? "active" : "", | ||
`<button><div class='icon-service icon-${className}'></div><div class='flex-grow'>${label}</div><div class='active-icon-wrapper'></div></button>`, | ||
); | ||
} | ||
|
||
function initStoreLocator(): void { | ||
const webapp = new window.WebApp("map", "YOUR_API_KEY"); | ||
|
||
webapp.setConf(storeLocatorConfig); | ||
webapp.setFilterPanelRenderer(filterPanelRenderer); | ||
webapp.setFilterRenderer(filterRenderer); | ||
|
||
webapp.render(isMobileDevice()); | ||
} | ||
|
||
initStoreLocator(); | ||
|
||
declare global { | ||
// currently, the WebApp typings are not exported, so we use `any` here | ||
interface Window { | ||
WebApp: new (elementId: string, projectKey: string) => any; | ||
} | ||
} | ||
// [END woosmap_store_locator_custom_filters] | ||
|
||
export {}; |
12 changes: 12 additions & 0 deletions
12
samples/store-locator-custom-filters/store-locator-custom-filters.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"title": "Store Locator Widget - Custom Filters", | ||
"description": "Change the default filters block by applying your own style and creating filters based on search query.", | ||
"tag": "store_locator_custom_filters", | ||
"name": "store-locator-custom-filters", | ||
"pagination": { | ||
"data": "mode", | ||
"size": 1, | ||
"alias": "mode" | ||
}, | ||
"permalink": "samples/{{ page.fileSlug }}/{{mode}}/{% if mode == 'jsfiddle' %}demo{% else %}index{% endif %}.{{ page.outputFileExtension }}" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% extends '../../src/_includes/layout.njk' %} | ||
{% block external %} | ||
<script src="https://webapp.woosmap.com/webapp.js"></script> | ||
{% endblock %} | ||
{% block html %} | ||
<!-- [START woosmap_{{ tag }}_div] --> | ||
<div id="map"></div> | ||
<!-- [END woosmap_{{ tag }}_div] --> | ||
{% endblock %} | ||
{% block api %}{% endblock %} |
Oops, something went wrong.