Stores Overlay Query- Advanced
Sample code for Woosmap Map JavaScript API
author(s):
Woosmap
HTML
<!DOCTYPE html>
<html>
<head>
<title>Stores Overlay Query- Advanced</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<!-- jsFiddle will insert css and js -->
</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>
...
CSS
/*
* Always set the map height explicitly to define the size of the div element
* that contains the map.
*/
#map {
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;
}
JavaScript
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());
}
function initMap() {
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 = new woosmap.map.Map(document.getElementById("map"), {
zoom: 8,
center: center,
});
storesOverlay = new woosmap.map.StoresOverlay(style);
storesOverlay.setMap(map);
initUI();
}
function initUI() {
typeSelect =...