Skip to content

Commit

Permalink
Merge pull request #79 from Netcentric/kaw-8201-lazy-loading-map
Browse files Browse the repository at this point in the history
KAW-8201 Add lazy loading for map
  • Loading branch information
lakshmishriaswathnarayana authored Oct 28, 2024
2 parents 2186424 + 1281118 commit 86b7e47
Showing 1 changed file with 49 additions and 36 deletions.
85 changes: 49 additions & 36 deletions blocks/dealer-locator/dealer-locator.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,44 +118,57 @@ export default async function decorate(block) {
},
};

loadScript('/blocks/dealer-locator/vendor/jquery.min.js', { type: 'text/javascript', charset: 'UTF-8' })
.then(() => {
// these scripts depend on jquery:
loadScript('//webapp.woosmap.com/webapp.js', { type: 'text/javascript' }).then(() => {
function loadWebApp() {
const publicKey = 'woos-50c04d89-af71-3a3b-b0b9-0786ee130532';
// eslint-disable-next-line no-undef
const webapp = new window.WebApp('dealer-locator', publicKey);
const config = {
maps: {
provider: 'woosmap',
channel: '',
localities: {
language,
data: 'advanced',
const loadDealerLocator = () => {
loadScript('/blocks/dealer-locator/vendor/jquery.min.js', { type: 'text/javascript', charset: 'UTF-8' })
.then(() => {
// these scripts depend on jquery:
loadScript('//webapp.woosmap.com/webapp.js', { type: 'text/javascript' }).then(() => {
function loadWebApp() {
const publicKey = 'woos-50c04d89-af71-3a3b-b0b9-0786ee130532';
// eslint-disable-next-line no-undef
const webapp = new window.WebApp('dealer-locator', publicKey);
const config = {
maps: {
provider: 'woosmap',
channel: '',
localities: {
language,
data: 'advanced',
},
},
},
theme: {
primaryColor: '#ed1d24',
},
datasource: {
maxResponses: 5,
maxDistance: 1000000,
useDistanceMatrix: true,
distanceMatrixProvider: 'woosmap',
},
internationalization: {
lang: language,
},
woosmapview: isOneLocationVariant ? selectedLocationConfig : defaultLocationConfig,
};
webapp.setConf(config);
if (isOneLocationVariant) {
webapp.setInitialStateToSelectedStore('990002');
theme: {
primaryColor: '#ed1d24',
},
datasource: {
maxResponses: 5,
maxDistance: 1000000,
useDistanceMatrix: true,
distanceMatrixProvider: 'woosmap',
},
internationalization: {
lang: language,
},
woosmapview: isOneLocationVariant ? selectedLocationConfig : defaultLocationConfig,
};
webapp.setConf(config);
if (isOneLocationVariant) {
webapp.setInitialStateToSelectedStore('990002');
}
webapp.render();
}
webapp.render();
}
loadWebApp();
loadWebApp();
});
});
};

const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.intersectionRatio > 0) {
loadDealerLocator();
observer.disconnect();
}
});
}, { threshold: [0.1], rootMargin: '500px' });

observer.observe(block);
}

0 comments on commit 86b7e47

Please sign in to comment.