angular.module('quartermaester') .controller("mapCtrl", function($scope, $filter, $timeout, uiGmapGoogleMapApi, qmCsv) { var qmData = {}; $scope.state = "slider"; $scope.search = ""; $scope.slider = { show: "episodes", currentEpisode: 0, currentChapter: 0 }; $scope.options = { characterPaths: true, houseHeraldry: false, geographicRegions: false, politicalAllegiances: false, characters: {} }; $scope.map = { center: { latitude: 1.3182, longitude: -105.9960 }, zoom: 4, options: { maxZoom: 5, minZoom: 1, disableDefaultUI: true, zoomControl: true }, events: { click: mapClick }, control: {}, locationClick: locationClick, heraldryClick: heraldryClick, characterClick: characterClick, loyaltyRangeClick: loyaltyRangeClick }; $scope.mapModels = { towns: [], heraldry: [], characters: [], paths: [], regions: [], loyaltyRanges: [], editableLoyaltyRanges: [] }; $scope.episodes = []; $scope.chapters = []; $scope.searchResults = []; $scope.clickHistory = []; $scope.toState = toState; $scope.slideTo = slideTo; $scope.panTo = panTo; $scope.resultClick = resultClick; $scope.refreshMap = refreshMap; $scope.locationDetail = null; $scope.lastClick = null; // Set up promises uiGmapGoogleMapApi.then(onMapLoad); qmCsv.loadData().then(addToScope); ////////////////// function addToScope(d) { qmData = d; for (var i=0;i=0; bookId--) { var prologue = parseInt(qmData.books[bookId].precedingChapters, 10); if (prologue > $scope.slider[measure]-1) continue; $scope.slider[measure] = prologue; break; } } break; case -1: if ($scope.slider[measure]>0) $scope.slider[measure]--; break; case 1: if ($scope.slider[measure]= 270) { $scope.slider[measure] = 344; break; } for (var bookId=0; bookId<=4; bookId++) { var epilogue = parseInt(qmData.books[bookId].precedingChapters, 10)-1; if (epilogue < $scope.slider[measure]+1) continue; $scope.slider[measure] = epilogue; break; } } break; default: $scope.state = "slider"; if (input.indexOf("-")<0) { // HBO show $scope.slider.show = "episodes"; $scope.slider.currentEpisode = qmCsv.getEpisodeId(input); // var reMatch = /S(\d)E0?(\d+)/.exec(input); // $scope.slider.currentEpisode = 10*(parseInt(reMatch[1])-1) + parseInt(reMatch[2])-1; } else { $scope.slider.show = "chapters"; // $scope.slider.currentChapter = qmCsv.getChapterId(input); var reMatch = /(\w{4})\-(\d+)/.exec(input); var bookId = books.indexOf(reMatch[1]); $scope.slider.currentChapter = parseInt(qmData.books[bookId].precedingChapters, 10) + parseInt(reMatch[2], 10); } break; } $scope.$broadcast('rzSliderForceRender'); } function panTo(input) { var location = $filter('filter')($scope.map.locations, {key: input})[0]; $scope.map.control.getGMap().panTo({lat: location.coords.latitude, lng: location.coords.longitude}); $scope.locationDetail = location; $scope.state = "location"; } function resultClick(model) { switch (model.icon) { case "glyphicon-map-marker": var town = $filter('filter')($scope.mapModels.towns, {key: model.key})[0]; $scope.map.control.getGMap().panTo({lat: town.coords.latitude, lng: town.coords.longitude}); $scope.locationDetail = town; $scope.state = "location"; break; case "glyphicon-user": $scope.options.characters[model.key] = true; var character = $filter('filter')($scope.characters, {key: model.key})[0]; var allCharacterMarkers = $filter('qmSlider')(qmData.characterMarkers, $scope.slider, $scope.options); var matchedCharacterMarkers = $filter('filter')(allCharacterMarkers, {character: {key: model.key}}); $scope.locationDetail = { name: "", url: "", house: character.name, houseImg: character.house.img, houseUrl: character.url, direct: "#" }; $scope.state = "location"; if (matchedCharacterMarkers.length==0) break; var thisCharacterMarker = matchedCharacterMarkers[0]; $scope.map.control.getGMap().panTo({lat: thisCharacterMarker.coords.latitude, lng: thisCharacterMarker.coords.longitude}); $scope.locationDetail.name = thisCharacterMarker.town.name; $scope.locationDetail.url = thisCharacterMarker.town.url; $scope.locationDetail.direct = ($scope.slider.show=="episodes") ? thisCharacterMarker.episode.url : thisCharacterMarker.chapter.url; break; case "glyphicon-home": var house = $filter('filter')(qmData.heraldry, {seat: model.subtitle})[0]; $scope.map.control.getGMap().panTo({lat: house.coords.latitude, lng: house.coords.longitude}); $scope.locationDetail = { name: house.seat, url: house.seatUrl, house: house.name, houseImg: house.houseImg, houseUrl: house.url, direct: house.direct }; $scope.state = "location"; break; case "glyphicon-facetime-video": case "glyphicon-book": slideTo(model.abbr); break; default: console.log("resultClick", model); } } function locationClick(marker, eventName, model) { $scope.locationDetail = model; $scope.state = "location"; } function heraldryClick(marker, eventName, model) { $scope.locationDetail = { name: model.seat, url: model.seatUrl, house: model.name, houseImg: model.houseImg, houseUrl: model.url, direct: model.direct }; $scope.state = "location"; } function characterClick(marker, eventName, model) { $scope.locationDetail = { name: model.town.name, url: model.town.url, house: model.character.name, houseImg: model.character.houseImg, houseUrl: model.character.url, direct: ($scope.slider.show=="episodes") ? model.episode.url : model.chapter.url }; $scope.state = "location"; } function loyaltyRangeClick(e, eventName, model) { var keyMatch = /(.+)\-\d+\w?$/.exec(model.key); var matchingBelligerant = $filter('filter')(qmData.belligerents, {key: keyMatch[1]})[0]; var filtered = $filter('filter')(qmData.belligerents, {key: keyMatch[1]}); $scope.locationDetail = { house: matchingBelligerant.title + " " + matchingBelligerant.name, houseImg: matchingBelligerant.houseImg, houseUrl: matchingBelligerant.url }; $scope.state = "location"; } function mapClick(a, b, c, d) { $scope.state = "slider"; //console.log(a, b, c, d); //console.log("lng", c[0].latLng.lng()); //$scope.lastClick = JSON; //console.log($scope.mapModels.paths); addClickToEditor(c[0].latLng.lat(), c[0].latLng.lng()); // $scope.map.control.getGMap().setMapTypeId("SATELLITE"); // console.log($scope.map.control.getGMap()); } function addClickToEditor(latitude, longitude) { $scope.clickHistory.push({ latitude: latitude, longitude: longitude }); } function getTileCode(a,b) { //converts tile x,y into keyhole string var c=Math.pow(2,b); var d=a.x; var e=a.y; var f="t"; for(var g=0;g= tileRange) return false; if (coord.y < 0 || coord.y >= tileRange) return false; return "tiles/" + getTileCode(coord, zoom) + ".jpg"; }, tileSize: new maps.Size(256, 256), maxZoom: 9, minZoom: 0, radius: 1738000, name: 'TWOIAF' }); $scope.$watch("map.control", function( mapControl, emptyObj ) { $scope.map.control.getGMap().mapTypes.set('quartermaester', quartermaesterMapType); $scope.map.control.getGMap().setMapTypeId('quartermaester'); }); // Add background to .rz-bar var rzbars = document.getElementsByClassName("rz-bar"); rzbars[0].innerHTML = "123456"; rzbars[2].innerHTML = "AGOTACOKASOSAFFCADWD"; } });