Stores Overlay Query- Advanced
Filter the displayed stores based on a specific query using Query Helper
Example
Stores Overlay Query- Advanced
let typeSelect: HTMLSelectElement;
let tagSelect: HTMLSelectElement;
let clauseAnd: HTMLInputElement;
let clauseOr: HTMLInputElement;
let storesOverlay: woosmap.map.StoresOverlay;
// Function to build and set the query
function setQuery() {
const type = typeSelect.value;
const tag = tagSelect.value;
const clauseFunction = clauseAnd.checked
? woosmap.map.query.and
: woosmap.map.query.or;
let query: woosmap.map.query.Query;
if (type !== "all" && tag !== "all") {
query = clauseFunction([
woosmap.map.query.F("type", type),
woosmap.map.query.F("tag", tag),
]);
} else if (type !== "all") {
query = clauseFunction([woosmap.map.query.F("type", type)]);
} else if (tag !== "all") {
query = clauseFunction([woosmap.map.query.F("tag", tag)]);
} else {
query = clauseFunction([]);
}
storesOverlay.setQuery(query.toString());
}
async function initMap(): Promise<void> {
await woosmap.map.importLibrary("maps");
const center: woosmap.map.LatLngLiteral = { lat: 51.52, lng: -0.13 };
const icon: woosmap.map.Icon = {
url: "https://images.woosmap.com/marker-blue.svg",
scaledSize: {
height: 40,
width: 34,
},
};
const style: woosmap.map.Style = {
breakPoint: 18,
rules: [
{
type: "bose_store",
color: "#2d2d2d",
icon,
},
{
type: "professional_systems",
color: "#733f00",
icon,
},
{
type: "bose_excellence_centre",
color: "#ef8900",
icon,
},
{
type: "bose_reseller",
color: "#607c92",
icon,
},
{
type: "bose_factory_store",
color: "#607c92",
icon,
},
],
default: {
color: "#2D2D2D",
size: 11,
minSize: 3,
icon,
selectedIcon: {
url: "https://images.woosmap.com/marker-red.svg",
scaledSize: {
height: 50,
width: 43,
},
},
},
};
const map = (document.getElementById("map") as woosmap.map.MapElement).innerMap;
map.moveCamera({
zoom: 8,
center: center,
});
storesOverlay = new woosmap.map.StoresOverlay(style);
storesOverlay.setMap(map);
initUI();
}
function initUI() {
typeSelect = document.getElementById("type") as HTMLSelectElement;
tagSelect = document.getElementById("tag") as HTMLSelectElement;
clauseAnd = document.getElementById("clauseAND") as HTMLInputElement;
clauseOr = document.getElementById("clauseOR") as HTMLInputElement;
// Add event listeners to form elements
typeSelect.addEventListener("change", setQuery);
tagSelect.addEventListener("change", setQuery);
clauseAnd.addEventListener("change", setQuery);
clauseOr.addEventListener("change", setQuery);
}
initMap();
let typeSelect;
let tagSelect;
let clauseAnd;
let clauseOr;
let storesOverlay;
// Function to build and set the query
function setQuery() {
const type = typeSelect.value;
const tag = tagSelect.value;
const clauseFunction = clauseAnd.checked
? woosmap.map.query.and
: woosmap.map.query.or;
let query;
if (type !== "all" && tag !== "all") {
query = clauseFunction([
woosmap.map.query.F("type", type),
woosmap.map.query.F("tag", tag),
]);
} else if (type !== "all") {
query = clauseFunction([woosmap.map.query.F("type", type)]);
} else if (tag !== "all") {
query = clauseFunction([woosmap.map.query.F("tag", tag)]);
} else {
query = clauseFunction([]);
}
storesOverlay.setQuery(query.toString());
}
async function initMap() {
await woosmap.map.importLibrary("maps");
const center = { lat: 51.52, lng: -0.13 };
const icon = {
url: "https://images.woosmap.com/marker-blue.svg",
scaledSize: {
height: 40,
width: 34,
},
};
const style = {
breakPoint: 18,
rules: [
{
type: "bose_store",
color: "#2d2d2d",
icon,
},
{
type: "professional_systems",
color: "#733f00",
icon,
},
{
type: "bose_excellence_centre",
color: "#ef8900",
icon,
},
{
type: "bose_reseller",
color: "#607c92",
icon,
},
{
type: "bose_factory_store",
color: "#607c92",
icon,
},
],
default: {
color: "#2D2D2D",
size: 11,
minSize: 3,
icon,
selectedIcon: {
url: "https://images.woosmap.com/marker-red.svg",
scaledSize: {
height: 50,
width: 43,
},
},
},
};
const map = document.getElementById("map").innerMap;
map.moveCamera({
zoom: 8,
center: center,
});
storesOverlay = new woosmap.map.StoresOverlay(style);
storesOverlay.setMap(map);
initUI();
}
function initUI() {
typeSelect = document.getElementById("type");
tagSelect = document.getElementById("tag");
clauseAnd = document.getElementById("clauseAND");
clauseOr = document.getElementById("clauseOR");
// Add event listeners to form elements
typeSelect.addEventListener("change", setQuery);
tagSelect.addEventListener("change", setQuery);
clauseAnd.addEventListener("change", setQuery);
clauseOr.addEventListener("change", setQuery);
}
initMap();
/*
* Always set the map height explicitly to define the size of the element
* that contains the map. `display: block` is required for <wmp-map>/<gmp-map>,
* which default to inline like any other custom element outside a flex/grid
* container (no-op for a plain <div>).
*/
#map {
display: block;
width: 100%;
height: 100%;
}
/*
* Optional: Makes the sample page fill the window.
*/
html,
body {
height: 100%;
margin: 0;
padding: 0;
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
}
#map-panel {
position: absolute;
top: 0;
left: 0;
background-color: #fff;
border-radius: 3px;
box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
margin: 10px;
padding: 5px;
overflow: hidden;
z-index: 1;
max-width: 280px;
padding: 0;
}
#innerWrapper {
display: flex;
flex-direction: column;
flex-grow: 1;
overflow: hidden;
overflow-y: auto;
padding: 0 10px 10px;
font-size: 0.85em;
}
.sectionHeader {
font-weight: 600;
background: #EEE;
border-bottom: 1px solid #eeeeee;
margin: 0 -10px 10px;
padding: 5px 10px;
color: #222;
}
select {
margin: 0.25em 0 0.7em;
padding: 0.5em 0.6em;
border: 1px solid #ccc;
box-shadow: inset 0 1px 3px #ddd;
border-radius: 4px;
vertical-align: middle;
font-weight: normal;
letter-spacing: 0.01em;
font-size: 1em;
display: inline-block;
box-sizing: border-box;
width: 100%;
}
input[type=select]:focus {
outline: 0;
border-color: #03A9F4;
}
select {
height: 2.25em;
border: 1px solid #ccc;
background-color: #fff;
}
.options__header {
font-weight: 600;
line-height: 24px;
display: flex;
}
.options__input {
height: 24px;
display: flex;
align-items: baseline;
}
<html>
<head>
<title>Stores Overlay Query- Advanced</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
</head>
<body>
<div id="map-panel">
<div id="innerWrapper">
<div class="sectionHeader">
<span>setQuery using <em>Query Helper</em></span>
</div>
<div class="options">
<label class="options__header" for="type">Filter by Type </label>
<select id="type">
<option value="all">All</option>
<option value="bose_store">Bose Store</option>
<option value="bose_reseller">Reseller</option>
<option value="professional_systems">Professional Systems</option>
<option value="aviation">Aviation</option>
<option value="bose_music_partners">Music Partners</option>
<option value="bose_excellence_centre">Excellence Centre</option>
<option value="bose_factory_store">Factory Store</option>
<option value="bose_shop-in-shop">Shop In Shop</option>
</select>
</div>
<div class="options">
<label class="options__header" for="tag"
>Filter by Available Service (Tag)
</label>
<select id="tag">
<option value="all">All</option>
<option value="wheelchair_access">Wheelchair Access</option>
<option value="in-store_wi-fi">Wi-Fi</option>
<option value="parking">Parking</option>
<option value="schedule_a_demo">Schedule a Demo</option>
<option value="reserve_and_collect">Reserve & Collect</option>
<option value="delivery_and_installation_service">
Delivery & Installation
</option>
<option value="customised_solutions">Customised Solutions</option>
<option value="financing">Financing</option>
<option value="repair_service">Repair Service</option>
</select>
</div>
<div class="options">
<span class="options__header">Clause</span>
<div class="options__input">
<input
id="clauseAND"
aria-label="Yes"
name="clauses"
type="radio"
value="AND"
checked=""
/>
<label for="true">AND</label>
</div>
<div class="options__input">
<input
id="clauseOR"
aria-label="No"
name="clauses"
type="radio"
value="OR"
/>
<label for="false">OR</label>
</div>
</div>
</div>
</div>
<wmp-map id="map"></wmp-map>
<script>
(g=>{var p,w=window,d=document,l="importLibrary",q="__ib__",e="The Woosmap Maps JavaScript API",o=w.woosmap||(w.woosmap={}),m=o.map||(o.map={}),r=new Set(String(g.libraries||"").split(",").filter(Boolean)),s=new URLSearchParams,u=()=>p||(p=new Promise((f,n)=>{var a=d.createElement("script");s.set("libraries",[...r]+"");for(var k in g)k!="libraries"&&g[k]&&s.set(k,g[k]);s.set("callback","woosmap.map."+q);a.src="https://sdk.woosmap.com/map/map.js?"+s;m[q]=f;a.onerror=()=>n(Error(e+" could not load."));a.nonce=d.querySelector("script[nonce]")?.nonce||"";d.head.append(a)}));m[l]?console.warn(e+" only loads once. Ignoring:",g):m[l]=(f,...n)=>r.add(f)&&u().then(()=>m[l](f,...n))})({
key: "woos-88403c6e-a493-337d-a620-7716f7aa6008",
});
</script>
</body>
</html>
Running the Sample Locally
Before you can run this sample on your local machine, you need to have Git and Node.js installed. If they’re not already installed, follow these instructions to get them set up.
Once you have Git and Node.js installed, you can run the sample by following these steps:
-
Clone the repository and navigate to the directory of the sample.
-
Install the necessary dependencies.
-
Start running the sample.
Here are the commands you can use in your terminal to do this:
git clone -b sample/stores-overlay-query-advanced https://github.com/woosmap/js-samples.git
cd js-samples
npm i
npm start
You can experiment with other samples by switching to any branch that starts with the pattern sample/SAMPLE_NAME.
git checkout sample/SAMPLE_NAME
npm i
npm start