Skip to content

Commit

Permalink
unfinished work
Browse files Browse the repository at this point in the history
  • Loading branch information
felixebert committed Feb 14, 2017
1 parent bba163c commit 50e1c9e
Show file tree
Hide file tree
Showing 11 changed files with 14,860 additions and 36 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
.settings
.settings
.hg
*.iml
.idea
.DS_Store
bin
node_modules
3 changes: 3 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>Was steckt in meinem Leitungswasser?</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-material/0.8.3/angular-material.css">
<link rel="stylesheet" href="css/screen.css">
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
</head>
<body>
<div align="center">
Expand Down Expand Up @@ -48,6 +49,8 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-route.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-material/0.8.3/angular-material.js"></script>
<script src="modules/tw.js"></script>
<script src="modules/locateMeButtonDirective.js"></script>
<script src="modules/geocodeAddressDirective.js"></script>
<script src="modules/SelectPlaceCtrl.js"></script>
<script src="modules/PlaceCtrl.js"></script>
<script src="modules/NavController.js"></script>
Expand Down
7 changes: 6 additions & 1 deletion frontend/modules/SelectPlaceCtrl.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
(function (angular) {
'use strict';

angular.module('tw').controller('SelectPlaceCtrl', function($scope) {
angular.module('tw').controller('SelectPlaceCtrl', function($scope, $http) {
$scope.cities = Object.keys(tw.data.locations);
$scope.getDistrictsOfCity = function(city) {
var cityObject = tw.data.locations[city];
$scope.districts = Object.keys(cityObject);
}
$scope.$on('location', function(event, latLon) {
$http.get('http://localhost:8012/geocode?lat=' + latLon.lat + '&lon' + latLon.lon).success(function(data) {
console.log(data);
})
})
});

})(angular);
13 changes: 13 additions & 0 deletions frontend/modules/geocodeAddressDirective.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function (angular) {
angular.module('tw').directive('geocodeAddress', function () {
return {
restrict: 'A',
link: function (scope, elem) {
var autocomplete = new google.maps.places.Autocomplete(elem[0]);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
console.log(autocomplete.getPlace());
});
}
}
});
})(angular);
12 changes: 12 additions & 0 deletions frontend/modules/locateMeButtonDirective.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(function (angular) {
angular.module('tw').directive('locateMeButton', function () {
return {
restrict: 'A',
link: function (scope, elem) {
elem.on('click', function () {
scope.$emit('location', {lat: 1, lon: 2});
});
}
}
});
})(angular);
11 changes: 9 additions & 2 deletions frontend/modules/partials/selectPlace.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
<br></br>
<md-select placeholder="Pick" ng-model="selectedDistrict">
<md-option ng-repeat="district in districts" value="{{district}}">{{district}}</md-option>
</md-select>
</md-select>
<br></br>
<md-button class="md-raised" href="#/place/{{selectedCity}} {{selectedDistrict}}">Open Place</md-button>
<md-button class="md-raised" href="#/place/{{selectedCity}} {{selectedDistrict}}">Open Place</md-button>

<md-input-container>
<label>Address</label>
<input ng-model="address" geocode-address>
</md-input-container>

<md-button class="md-raised" locate-me-button>Locate me</md-button>
35 changes: 3 additions & 32 deletions node-backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,8 @@ var mongoose = require('mongoose');
var express = require('express');
var baucis = require('baucis');
var cors = require('cors');
mongoose.connect('mongodb://localhost/tapwater');

// define models
var Location = mongoose.model('Location', new mongoose.Schema({geoFeature: GeoJSON.Feature}));
var sampleLocation = new Location({
geoFeature: {
"type": "Feature",
"properties": {
"haertegrad": "10",
"name": "Aachener Straße"
},
"geometry": {
"type": "MultiLineString",
"coordinates": [[[9.1054195, 49.1836073], [9.1053332, 49.1833407], [9.1051728, 49.1828456], [9.1051326, 49.1828453], [9.1046133, 49.1828413]], [[9.1051326, 49.1828453], [9.1049988, 49.1830276], [9.1048492, 49.1832862]], [[9.1051728, 49.1828456], [9.1053677, 49.1827792], [9.1066049, 49.1825795]]]
}
}
});
sampleLocation.save();


var Zone = mongoose.model('Zone', {
name: String,
calcium: Number,
kalium: Number
});
var sampleZone = new Zone({
name: 'Erlenbach',
calcium: 0.8,
kalium: 0.9
});
sampleZone.save();
var mongoSetup = require('./mongo-setup');
var mongo = mongoSetup.setupInstance();

// rest
baucis.rest('Zone');
Expand All @@ -44,6 +15,6 @@ app.use(cors());
app.use('/api', baucis());
app.listen(8012);

app.get('/geocode', function(req, res) {
app.get('/geocode', function (req, res) {
res.send("Latitude " + req.query.lat + ", Longitude " + req.query.lon + ' has the following mineral values in its tapwater: calcium 0.8, natrium 2, nitrat 5 - you have a good tapwater!');
});
58 changes: 58 additions & 0 deletions node-backend/converter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var process = require('process');
var mongoSetup = require('./mongo-setup');
var heilbronnPlaces = require('./hn-streets.json');
var zones = require('./zones.json');

var GeoJSON = require('mongoose-geojson-schema');
var mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/tapwater');

var Location = mongoose.model('Location', new mongoose.Schema({
name: String,
zone: String,
geometry: GeoJSON.Geometry
}));
var Zone = mongoose.model('Zone', {
name: String,
calcium: Number,
kalium: Number
});


var convertCoordinatesArray = function (coordinates) {
var convertedCoordinates = [];
coordinates.forEach(function (coordinate) {
if (Array.isArray(coordinate[0])) {
convertedCoordinates.push(convertCoordinatesArray(coordinate));
} else {
convertedCoordinates.push([coordinate[1], coordinate[0]]);
}
});
return convertedCoordinates;
};

heilbronnPlaces.features.forEach(function (feature) {
var location = new Location({
name: feature.properties.name,
zone: "Heilbronn " + feature.properties.haertegrad,
geometry: {
"type": feature.geometry.type,
"coordinates": convertCoordinatesArray(feature.geometry.coordinates)
}
});
location.save(function(e) {
console.log(e);
});
});

Object.keys(zones).forEach(function (zoneName) {
var zone = new Zone({
name: zoneName,
calcium: zones[zoneName].calcium,
kalium: zones[zoneName].kalium
});
zone.save();
});

process.exit();
Loading

0 comments on commit 50e1c9e

Please sign in to comment.