adds hidden method (callable via the console to create a whatsaround need)
@@ -4,15 +4,19 @@ import angular from 'angular';
import overviewTitleBarModule from '../overview-title-bar';
import postItemLineModule from '../post-item-line';
import { actionCreators } from '../../actions/actions';
-import { attach } from '../../utils';
+import {
+ attach,
+ reverseSearchNominatim,
+ nominatim2draftLocation,
+} from '../../utils.js';
import {
selectAllOwnNeeds,
} from '../../selectors';
-import won from '../../won-es6';
import {
resetParams,
} from '../../configRouting';
+import won from '../../won-es6';
const ZERO_UNSEEN = Object.freeze({
matches: 0,
@@ -52,10 +56,62 @@ class OverviewPostsController {
}
};
+ //this.createWhatsAround();
+
const disconnect = this.$ngRedux.connect(selectFromState, actionCreators)(this);
this.$scope.$on('$destroy', disconnect);
}
+ createWhatsAround(){
+ console.log("Create Whats Around");
+
+ if ("geolocation" in navigator) {
+ navigator.geolocation.getCurrentPosition(
+ currentLocation => {
+ console.log(currentLocation);
+ const lat = currentLocation.coords.latitude;
+ const lng = currentLocation.coords.longitude;
+ const zoom = 13; // TODO use `currentLocation.coords.accuracy` to control coarseness of query / zoom-level
+
+ const degreeConstant = 1.0;
+
+ // center map around current location
+
+ reverseSearchNominatim(lat, lng, zoom)
+ .then(searchResult => {
+ const location = nominatim2draftLocation(searchResult);
+
+ let whatsAround = {
+ title: "What's Around?",
+ type: "http://purl.org/webofneeds/model#DoTogether",
+ description: "Automatically created Need to see what's in your location",
+ tags: undefined,
+ location: location,
+ thumbnail: undefined,
+ whatsAround: true
+ };
+
+ console.log("Creating Whats around with data: ", whatsAround);
+
+ this.needs__create(
+ whatsAround,
+ this.$ngRedux.getState().getIn(['config', 'defaultNodeUri'])
+ );
+ });
+ },
+ err => { //error handler
+ if(err.code === 2 ) {
+ console.log("create whats around not possible due to error")
+ }
+ },
+ { //options
+ enableHighAccuracy: true,
+ timeout: 5000,
+ maximumAge: 0
+ }
+ );
+ }
+ }
}
