World = {
const container = yield html`<div style="height:800px;">`;
const map = (container.value = new maplibregl.Map({
boxZoom: true,
pitch: 0,
bearing: 0,
maplibreLogo: true,
container,
center: [-70.2568, 43.64],
zoom: 12,
style: `https://basemaps.cartocdn.com/gl/${basemap}-gl-style/style.json`,
scrollZoom: true
}));
map.on('load', function() {
map.loadImage('https://i.imgur.com/Aw241O4.png',
function(error,image){
if (error) throw error;
map.addImage('schoolIcon', image)});
map.loadImage('https://i.imgur.com/UTEdNow.png',
function(error,image){
if (error) throw error;
map.addImage('libraryIcon', image)});
map.loadImage('https://i.imgur.com/qBwoy8m.png',
function(error,image){
if (error) throw error;
map.addImage('govtIcon', image)});
map.loadImage('https://i.imgur.com/qpgAMfc.png',
function(error,image){
if (error) throw error;
map.addImage('parkIcon', image)});
map.loadImage('https://i.imgur.com/mlbq8xf.png',
function(error,image){
if (error) throw error;
map.addImage('childcareIcon', image)});
//School data and layer
map.addSource('schools', {
type: 'geojson',
data: maineSchoolsGeoJson
});
map.addLayer({
id: 'schoolPoints',
type: 'symbol',
source: 'schools',
layout: {
'icon-image': 'schoolIcon',
'icon-allow-overlap': true,
'visibility': 'none'
}
});
//Library data and layer
map.addSource('libraries', {
type: 'geojson',
data: maineLibraryGeoJson
});
map.addLayer({
id: 'libraryPoints',
type: 'symbol',
source: 'libraries',
layout: {
'icon-image': 'libraryIcon',
'icon-allow-overlap': true,
'visibility': 'none'
}
});
//Govt data and layer
map.addSource('govt', {
type: 'geojson',
data: maineGovernmentGeoJson
});
map.addLayer({
id: 'govtPoints',
type: 'symbol',
source: 'govt',
layout: {
'icon-image': 'govtIcon',
'icon-allow-overlap': true,
'visibility': 'none'
}
});
//Park data and Layer
map.addSource('park', {
type: 'geojson',
data: parkGeojson
});
map.addLayer({
id: 'parkPoints',
type: 'symbol',
source: 'park',
layout: {
'icon-image': 'parkIcon',
'icon-allow-overlap': true,
'visibility': 'none'
}
});
//Childcare Data and Layer
map.addSource('childCare', {
type: 'geojson',
data: childCareGeoJson
});
map.addLayer({
id: 'childCarePoints',
type: 'symbol',
source: 'childCare',
layout: {
'icon-image': 'childcareIcon',
'icon-allow-overlap': true,
'visibility': 'none'
}
});
});
//School Popup
map.on('mouseenter', 'schoolPoints', function (e) {
popup.setLngLat(e.lngLat).setHTML('<h3>' + e.features[0].properties['School Name'] + '</h3>').addTo(map);
});
map.on('mouseleave', 'schoolPoints', function (e) {
popup.remove();
});
//Library Popup
map.on('mouseenter', 'libraryPoints', function (e) {
popup.setLngLat(e.lngLat).setHTML('<h3>' + e.features[0].properties.Name + '</h3>').addTo(map);
});
map.on('mouseleave', 'libraryPoints', function (e) {
popup.remove();
});
//Government Popup
map.on('mouseenter', 'govtPoints', function (e) {
popup.setLngLat(e.lngLat).setHTML('<h3>' + e.features[0].properties.name + '</h3>').addTo(map);
});
map.on('mouseleave', 'govtPoints', function (e) {
popup.remove();
});
//Park Popup
map.on('mouseenter', 'parkPoints', function (e) {
popup.setLngLat(e.lngLat).setHTML('<h3>' + e.features[0].properties.name + '</h3>').addTo(map);
});
map.on('mouseleave', 'parkPoints', function (e) {
popup.remove();
});
//Child Care Popup
map.on('mouseenter', 'childCarePoints', function (e) {
popup.setLngLat(e.lngLat).setHTML('<h3>' + e.features[0].properties.name + '</h3>').addTo(map);
});
map.on('mouseleave', 'childCarePoints', function (e) {
popup.remove();
});
}