Last active
December 22, 2015 22:49
-
-
Save travellingprog/6542886 to your computer and use it in GitHub Desktop.
vortex drawing code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
self.updateLocations = function () { | |
self.getLocationsByVenue({ | |
venueURL: App.venueURL, | |
perspective: App.perspectives.main // add this line | |
}, function (response) { | |
console.log(response); | |
App.locations = response; | |
}); | |
}; | |
//... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $.unsubscribe('GoliathAPILoadedgetDirectionsToLocation'); | |
// need to comment out line, or it also cancels out the subscription function in floor.js' init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// New/changed Methods: getBgImgSize, drawVortex, showVortexes, init | |
Goliath.widgets.Floors = function (kwargs) { | |
kwargs = kwargs || {}; | |
kwargs.classes = kwargs.classes || ''; | |
kwargs.classes += ' widget-floors'; | |
var self = new Goliath.Widget(kwargs); | |
$.extend(self, { | |
floors: App.maps, | |
template: Goliath.templates.floors, | |
floorTemplate: Goliath.templates['floors-floor'], | |
perspective: kwargs.perspective || 'Minimap' | |
}); | |
var getBgImgSize = function ($elem) { | |
var imageSrc = $elem.css('background-image') | |
.replace(/url\((['"])?(.*?)\1\)/gi, '$2').split(',')[0]; | |
var image = new Image(); | |
image.src = imageSrc; | |
var width = image.width, | |
height = image.height; | |
return [width, height]; | |
}; | |
var drawVortex = function(data) { | |
var startCoord = data.startCoord, | |
startLevel = prevFloorLevel, | |
endCoord = data.endCoord, | |
endLevel = data.endLevel; | |
if (startLevel < endLevel) { | |
// going from higher level to lower level | |
} | |
else { | |
// going from lower level to higher level | |
} | |
}; | |
var showVortexes = function (bestPath) { | |
var curFloorId = null; | |
var curFloorLevel = -1, prevFloorLevel; | |
var point = []; | |
for (var i=0, l=bestPath.path.length; i<l; i++) { | |
var node = bestPath.path[i]; | |
if (node.map === curFloorId) continue; | |
curFloorId = node.map; | |
prevFloorLevel = curFloorLevel; | |
for (var j = 0, m = self.floors.length; j < m; j++) { | |
if (self.floors[j]._id === node.map) { | |
curFloorLevel = j; | |
break; | |
} | |
} | |
if (prevFloorLevel === -1) continue; | |
drawVortex({ | |
startCoord: [bestPath.path[i-1].x, bestPath.path[i-1].y], | |
startLevel: prevFloorLevel, | |
endCoord: [node.x, node.y], | |
endLevel: curFloorLevel | |
}); | |
} | |
}; | |
var parentBuild = self.build; | |
self.build = function () { | |
parentBuild(); | |
self.element.html( | |
self.template() | |
); | |
return self.element; | |
}; | |
var initWidget = self.init; | |
self.init = function () { | |
for (var i in self.floors) { | |
var floor = self.floors[i]; | |
self.addFloor(floor); | |
} | |
$('.js-floors-floor', self.element).mouseover(function () { | |
$('.js-floors-floor', self.element).removeClass('s-selected js-selected s-expanded'); | |
$(this).addClass('s-selected js-selected s-expanded'); | |
var floorNumber = $(this).index(); | |
$.publish('floorSelect', { 'floor': floorNumber }); | |
}); | |
$.subscribe('GoliathAPILoadedgetDirectionsToLocation', function (ev, bestPath) { | |
if (!!bestPath) { | |
showVortexes(bestPath); | |
} | |
}); | |
return self; | |
} | |
self.addFloor = function (floor) { | |
var floorWrapper = $('.floors-wrapper', self.element); | |
var origFilename = floor.perspectives[self.perspective].original.split('/').pop(); | |
var settings = { | |
name: floor.name, | |
image: floor.perspectives[self.perspective].image + '/' + origFilename | |
} | |
$('<div />').html( | |
self.floorTemplate(settings) | |
).contents().appendTo(floorWrapper); | |
$('.js-floors-floor-map', self.element).each(function() { | |
$(this).loadBgImg(); | |
}); | |
} | |
$.subscribe('APImapsLoaded', function () { | |
self.update(); | |
}); | |
return self; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment