70 lines
3.5 KiB
JavaScript
70 lines
3.5 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
/**
|
|
* @ngdoc directive
|
|
* @name locationModule:locationMap
|
|
* @restrict AE
|
|
* @desription Creates custom Google map with map tiles retrieved from the server and places asset pin on this map.
|
|
* This functionality is being used to provide user with ability to find out where particular asset can be found
|
|
*/
|
|
angular.module('locationModule')
|
|
.directive('locationMap', ['userModel', 'locationModel', '$compile', function (userModel, locationModel, $compile) {
|
|
return {
|
|
restrict: 'AE',
|
|
template: '<div class="location-map__content"><div ></div></div>',
|
|
replace: true,
|
|
link: function (scope, $element) {
|
|
scope.locationModel = locationModel;
|
|
/**
|
|
* This method is called on asset pin click event. If asset has no infobubble information,
|
|
* new instance of infobubble will be created, via compiling poi-info-bubble directive on current scope, with
|
|
* parent asset to be specified in parent attribute of the html to be compiled
|
|
* @param {Object} $event Angular click event object.
|
|
* */
|
|
scope.openInfoBubble = function ($e) {
|
|
$e.preventDefault();
|
|
$e.stopPropagation();
|
|
scope.activePOI = scope.POI.details;
|
|
if (scope.POI.details.infoBubble) {
|
|
scope.activePOI.infoBubble.open(scope.locationMap.floormap);
|
|
scope.activePOI.marker.setVisible(false);
|
|
}
|
|
else {
|
|
$compile("<poi-info-bubble parent='activePOI'></poi-info-bubble>")(scope);
|
|
}
|
|
};
|
|
/**
|
|
* Retrieves asset details and asset floorMap tiles
|
|
* Param is asset id string
|
|
* */
|
|
locationModel.getPOIdetails(scope.POI.id)
|
|
.then(function (poi) {
|
|
scope.POI.details = poi;
|
|
locationModel.getMapTiles(poi)
|
|
.then(function () {
|
|
scope.POI.tiles = locationModel.tilesCache[poi.id];
|
|
init();
|
|
});
|
|
});
|
|
/**
|
|
* Triggered, when all necessary data is ready. It creates custom google map
|
|
* and adds asset marker on it.
|
|
* */
|
|
function init() {
|
|
locationModel.initLocationMap($element[0], scope.POI).then(function (mapData) {
|
|
scope.locationMap = mapData;
|
|
locationModel.addLocationMarker(scope.locationMap, scope.POI.details);
|
|
$compile(scope.POI.details.marker.content)(scope);
|
|
scope.activePOI = scope.POI.details;
|
|
$compile("<poi-info-bubble parent='activePOI'></poi-info-bubble>")(scope);
|
|
scope.state.loadingMap = false;
|
|
}).catch(function () {
|
|
scope.state.loadingMap = false;
|
|
});
|
|
}
|
|
}
|
|
};
|
|
}]);
|
|
}());
|