From db4a3cfcf39c788eeb68922389555e2b76206601 Mon Sep 17 00:00:00 2001 From: James Mead Date: Wed, 28 Jun 2017 11:38:46 +0100 Subject: [PATCH] Add /app/themes/coop-tech-oowp-theme/public/js/app.js And use relative URL in script tag so it is served locally. --- about.html | 2 +- .../coop-tech-oowp-theme/public/js/app.js | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/themes/coop-tech-oowp-theme/public/js/app.js diff --git a/about.html b/about.html index fa751e4..13c6b2e 100644 --- a/about.html +++ b/about.html @@ -127,7 +127,7 @@ section#contact div.row div p a:hover { - + diff --git a/app/themes/coop-tech-oowp-theme/public/js/app.js b/app/themes/coop-tech-oowp-theme/public/js/app.js new file mode 100644 index 0000000..e376162 --- /dev/null +++ b/app/themes/coop-tech-oowp-theme/public/js/app.js @@ -0,0 +1,53 @@ +$(document).foundation(); + +$('#coops-view-tabs').on('change.zf.tabs', function() { + window.app.createMapMultiMarker('map-coops', 54.7, -4.2, 6, window.app.mapEntries); +}); + +var elem = new Foundation.Sticky($('.top-bar')); +var app = window.app || {}; + +var mapboxAccessToken = window.mapboxAccessToken || ''; + +app.apiUrl = 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=' + mapboxAccessToken; + +app.tileLayerOptions = { + maxZoom: 18, + attribution: 'Map data © OpenStreetMap contributors, ' + 'CC-BY-SA, ' + 'Imagery © Mapbox', + id: 'mapbox.streets', + token: window.mapboxAccessToken +}; + +app.map = null; + +app.createMap = function(mapId, lat, lng, zoom) { + window.app.map = L.map(mapId).setView([lat, lng], zoom); +} + +app.createMapSingleMarker = function(mapId, lat, lng, zoom, markerText) { + if (!window.app.map) { + window.app.createMap(mapId, lat, lng, zoom); + var myMap = window.app.map; + + L.tileLayer(window.app.apiUrl, window.app.tileLayerOptions).addTo(myMap); + + var marker = L.marker([lat - 0.0005, lng]).addTo(myMap); + marker.bindPopup(markerText).openPopup(); + } +} + +app.createMapMultiMarker = function(mapId, lat, lng, zoom, markersArray) { + if (!window.app.map) { + window.app.createMap(mapId, lat, lng, zoom); + var myMap = window.app.map; + + L.tileLayer(window.app.apiUrl, window.app.tileLayerOptions).addTo(myMap); + + markersArray.forEach(function (markerVar) { + var marker = L.marker([markerVar.lat, markerVar.lng]).addTo(myMap); + marker.bindPopup(markerVar.markerText); + }); + } +}; + +//# sourceMappingURL=app.js.map