Skip to content

Commit

Permalink
Implemented map view #30
Browse files Browse the repository at this point in the history
(still in progress)
  • Loading branch information
nicho90 committed Aug 24, 2017
1 parent b049329 commit 3f7c57b
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 14 deletions.
13 changes: 8 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"license": "MIT",
"private": true,
"dependencies": {
"angular": "^1.6.4",
"angular": "^1.6.6",
"jquery": "^3.1.0",
"angular-route": "^1.6.4",
"angular-route": "^1.6.6",
"angular-translate": "^2.11.1",
"font-awesome": "^4.6.3",
"bootstrap": "v4.0.0-alpha.6",
"angular-socket-io": "^0.7.0",
"socket.io-client": "^1.5.0",
"angular-sanitize": "^1.6.4",
"angular-sanitize": "^1.6.6",
"videogular": "^1.4.4",
"videogular-themes-default": "^1.4.4",
"videogular-controls": "^1.4.4",
Expand All @@ -27,10 +27,13 @@
"angular-momentjs": "^0.2.2",
"three.js": "threejs#*",
"components-threejs": "^0.0.79",
"ngclipboard": "^1.1.1"
"ngclipboard": "^1.1.1",
"mapbox-gl-js": "https://github.com/nicho90/mapbox-gl-js-bower.git#0.39.1"
},
"resolutions": {
"angular": "1.6.4",
"angular": "1.6.6",
"angular-route": "1.6.6",
"angular-sanitize": "1.6.6",
"bootstrap": "v4.0.0-alpha.6"
}
}
18 changes: 18 additions & 0 deletions public/backend/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ body {
margin-top: 60px;
}

.navbar {
height: 60px;
}

.view {
padding-top: 25px;
padding-bottom: 25px;
}

footer {
position: absolute;
bottom: 0;
Expand Down Expand Up @@ -39,6 +48,13 @@ footer {
}


#map {
width: 100%;
top: 60px;
position: absolute;
}


.previewMap {
border-radius: 3px;
border: 1px solid rgba(0, 0, 0, .125);
Expand All @@ -47,10 +63,12 @@ footer {
border: 1px solid rgba(0, 0, 0, .125);
}


.uuid {
cursor: pointer;
}


.card-footer > .btn-block-xs-only, .btn-block-xs-only {
margin-top: 1px;
margin-bottom: 1px;
Expand Down
16 changes: 10 additions & 6 deletions public/backend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@
<script src="../bower_components/ngclipboard/dist/ngclipboard.min.js"></script>
<script src="../bower_components/videogular/videogular.js"></script>
<script src="../bower_components/videogular-controls/vg-controls.js"></script>

<!-- Three.js -->
<script src="../bower_components/three.js/dist/three.min.js"></script>
<script src="../lib/Detector.js"></script>
<script src="../lib/CSS3DRenderer.js"></script>
<script src="../lib/TransformControls.js"></script>

<!-- Mapbox GL -->
<link href="../bower_components/mapbox-gl-js/mapbox-gl.css" rel="stylesheet"/>
<script src="../bower_components/mapbox-gl-js/mapbox-gl.js"></script>

</head>
<body>


<!-- Main -->
<main ng-controller="mainController">
<main ng-controller="mainController" class="ng-cloak">

<!-- Header -->
<header>
Expand Down Expand Up @@ -131,8 +137,7 @@
</header>

<!-- Content -->
<div class="content container">
<br>
<div ng-class="{ 'content container': isNotMapRoute() }">

<!-- Loading screen -->
<div class="loading middle" ng-show="loading.status">
Expand All @@ -147,9 +152,7 @@
</div>

<!-- Main view -->
<div ng-view ng-show="!loading.status"></div>

<br>
<div class="view" ng-view ng-show="!loading.status"></div>
</div>

<!-- Footer -->
Expand Down Expand Up @@ -203,6 +206,7 @@
<script src="js/filters/previewVideo.js"></script>
<script src="js/filters/previewMapRequest.js"></script>
<script src="js/filters/findLocationById.js"></script>
<script src="js/filters/toGeoJSON.js"></script>

<!-- CONTROLLERS -->
<script src="js/controllers/mainController.js"></script>
Expand Down
15 changes: 15 additions & 0 deletions public/backend/js/controllers/mainController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ app.controller("mainController", function($scope, $rootScope, $filter, $translat
}
};


/**
* [description]
* @return {[type]} [description]
*/
$scope.isNotMapRoute = function(){
var path = $location.path();
if(path === '/map'){
return false;
} else {
return true;
}
};


/**
* [redirect description]
* @param {[type]} path [description]
Expand Down
211 changes: 210 additions & 1 deletion public/backend/js/controllers/mapController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,215 @@
var app = angular.module("ive");

// Map controller
app.controller("mapController", function($scope, $rootScope, $filter, $translate, $location, config, $authenticationService, $window) {
app.controller("mapController", function($scope, $rootScope, $filter, $translate, $location, config, $window, $locationService, $relationshipService) {
$scope.$parent.loading = { status: false, message: "" };

/**
* Load data
* @return {[type]} [description]
*/
$scope.load = function(data){
switch (data) {
case 'locations': {
$locationService.list()
.then(function onSuccess(response) {
$scope.locations = response.data;
$scope.location_geojson = $filter('toGeoJSON')(response.data);

// Update sources
map.getSource('markers').setData($scope.location_geojson);
})
.catch(function onError(response) {
$window.alert(response.data);
});

break;
}
case 'connected_to': {
break;
}
case 'has_parent_location': {
break;
}
default: {

}
}
};


$scope.mapStyle = 'streets-v9';
mapboxgl.accessToken = config.mapboxAccessToken;
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/' + $scope.mapStyle,
center: [7.634355, 51.956875],
zoom: 14
});


/**
* [position description]
* @type {String}
*/
map.addControl(new mapboxgl.NavigationControl(), 'top-left');


/**
* [features description]
* @type {[type]}
*/
map.on('load', function() {

// Load data
$scope.load("locations");


// Add geojson data as a new source
map.addSource("markers", {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": []
}
});


// Add source as a layer and apply some styles
map.addLayer({
"id": "locations",
"type": "circle",
"source": "markers",
"paint": {
'circle-color': {
property: 'location_type',
type: 'categorical',
stops: [
['abstract', '#00ff00'],
['outdoor', '#0000ff'],
['indoor', '#ff0000'],
]
},
'circle-radius': {
property: 'location_type',
type: 'categorical',
stops: [
['abstract', 5],
['outdoor', 5],
['indoor', 5]
]
},
},
"layout": {
"visibility": "visible"
}
});

// Load data
var bounds = map.getBounds();
var bbox = {
xmin: bounds.getSouthWest().lng,
ymin: bounds.getSouthWest().lat,
xmax: bounds.getNorthEast().lng,
ymax: bounds.getNorthEast().lat
};

// When a click event occurs near a place, open a popup at the location of
// the feature, with description HTML from its properties.
map.on('click', function (e) {
var features = map.queryRenderedFeatures(e.point, {
layers: [
'locations'
]
});

if (!features.length) {
return;
}

var feature = features[0];
var popup = new mapboxgl.Popup({
closeButton: false
});

console.log(feature.properties);

var content = "";

if(feature.layer.id === 'locations'){
content = '' +
'<b>' +
'<a href="locations/' + feature.properties.location_id + '">' + feature.properties.location_name + '</a>' +
'</b>';
}

popup.setLngLat(feature.geometry.coordinates)
.setHTML(content)
.addTo(map);

});

// Use the same approach as above to indicate that the symbols are clickable
// by changing the cursor style to 'pointer'.
map.on('mousemove', function (e) {
var features = map.queryRenderedFeatures(e.point, {
layers: [
'locations'
]
});
map.getCanvas().style.cursor = (features.length) ? 'pointer' : '';
});


/**
* [description]
* @return {[type]} [description]
*/
map.on('zoom', function() {
var zoom = map.getZoom();
});

/**
* [bounds description]
* @type {[type]}
*/
map.on('dragend', function(){
var bounds = map.getBounds();
var bbox = {
xmin: bounds.getSouthWest().lng,
ymin: bounds.getSouthWest().lat,
xmax: bounds.getNorthEast().lng,
ymax: bounds.getNorthEast().lat
};
});

/**
* [bounds description]
* @type {[type]}
*/
map.on('rotateend', function(){
var bounds = map.getBounds();
var bbox = {
xmin: bounds.getSouthWest().lng,
ymin: bounds.getSouthWest().lat,
xmax: bounds.getNorthEast().lng,
ymax: bounds.getNorthEast().lat
};
});

/**
* [bounds description]
* @type {[type]}
*/
map.on('zoomend', function(){
var bounds = map.getBounds();
var bbox = {
xmin: bounds.getSouthWest().lng,
ymin: bounds.getSouthWest().lat,
xmax: bounds.getNorthEast().lng,
ymax: bounds.getNorthEast().lat
};
});
});

});
Loading

0 comments on commit 3f7c57b

Please sign in to comment.