Beispiel #1
0
        void mWebMapCommon_OnVisibleEdgesChange(object sender, Map2D.VisibleEdgesArgs e)
        {
            IEnumerable <Edge> edges = e.VisibleEdges;

            if (edges == null)
            {
                return;
            }

            foreach (Edge curEdge in edges)
            {
                AbsoluteLocation origin = null, destination = null;
                bool             first = true;
                foreach (Vertex v in curEdge.Vertices)
                {
                    if (first)
                    {
                        origin = v.AbsoluteLocations.First();
                        first  = false;
                    }
                    else
                    {
                        destination = v.AbsoluteLocations.First();
                        break;
                    }
                }
                if (origin != null && destination != null)
                {
                    AddEdgeLine((double)origin.latitude, (double)origin.longitude, (double)destination.latitude, (double)destination.longitude);
                }
            }
        }
Beispiel #2
0
        void ShowNearbyPoi_OnPoiSelected(object sender, ShowNearbyPoi.PoiEventArgs e)
        {
            Vertex           poi    = e.SelectedPoi;
            AbsoluteLocation absLoc = poi.AbsoluteLocations.First();

            mWebMapCommon.UI_CenterAt((double)absLoc.latitude, (double)absLoc.longitude);
        }
Beispiel #3
0
        private void AddVertexPin(Vertex v)
        {
            //Pushpin pushpin = new Pushpin();
            //pushpin.Style = (Style)(Application.Current.Resources["PushpinStyle"]);

            Image pushpin = MarkerConfig.CreateImage(v);

            pushpin.Tap +=
                (object sender, GestureEventArgs e) =>
            {
                e.Handled = true;

                mWebMapCommon.onTap(v);     //updates the title

                //Navigates to the possibilities
                StringBuilder sb = new StringBuilder();
                sb.Append(Globals.XamlUri_OfflineOnTapAction);
                sb.Append("?title=");
                sb.Append(this.ApplicationTitle.Text);
                this.NavigationService.Navigate(new Uri(sb.ToString(), UriKind.Relative));
            };
            //pushpin.MouseLeftButtonUp += new MouseButtonEventHandler(pushpin_MouseLeftButtonUp);
            AbsoluteLocation pos = v.AbsoluteLocations.First();

            mapLayerVertices.AddChild(pushpin, new GeoCoordinate((double)pos.latitude, (double)pos.longitude), PositionOrigin.BottomCenter);
        }
Beispiel #4
0
        void ShowNearbyPoi_OnPoiSelected(object sender, ShowNearbyPoi.PoiEventArgs e)
        {
            Vertex           poi    = e.SelectedPoi; // ShowNearbyPoi.SelectedVertexPOI;
            AbsoluteLocation absLoc = poi.AbsoluteLocations.First();

            graphMap.Center = new GeoCoordinate((double)absLoc.latitude, (double)absLoc.longitude);
        }
        void ShowNearbyPoi_OnPoiSelected(object sender, ShowNearbyPoi.PoiEventArgs e)
        {
            Vertex           poi    = e.SelectedPoi; // ShowNearbyPoi.SelectedVertexPOI;
            AbsoluteLocation absLoc = poi.AbsoluteLocations.First();

            JSInterface.centerAt(webBrowserOffline, (double)absLoc.latitude, (double)absLoc.longitude);
        }
        public Vertex getClosestVertex(AbsoluteLocation userAbsLoc)
        {
            /*
             * this may not be the best way of determining
             * the vertex closest to the geopoint - a better solution
             * could be to arrange the vertices in a different data structure
             * (currently it is a list)
             */

            int    floor = (int)userAbsLoc.getAltitude();
            double dist, bestDist = double.MaxValue;
            Vertex closestVertex = null;

            foreach (Vertex v in this.getVertices(floor))
            {
                AbsoluteLocation loc = v.getLocation().getAbsoluteLocation();
                dist = getDistance(loc.getLatitude() * 1E6,
                                   userAbsLoc.getLatitude() * 1E6,
                                   loc.getLongitude() * 1E6,
                                   userAbsLoc.getLongitude() * 1E6);

                if (dist < bestDist)
                {
                    bestDist      = dist;
                    closestVertex = v;
                }
            }
            return(closestVertex);
        }
        public PositionEstimate TestGetRandomPosition(int buildingId)
        {
            Building curBuilding = LoadedBuildings.First(b => b.ID == buildingId);
            Random   r           = new Random();
            int      randomNum   = r.Next(curBuilding.Vertices.Count);
            int      i           = 1;

            foreach (Vertex v in curBuilding.Vertices)
            {
                if (i >= randomNum)
                {
                    AbsoluteLocation absLoc = v.AbsoluteLocations.First();
                    return(new PositionEstimate()
                    {
                        ID = v.ID,
                        VertexID = v.ID,
                        Building_ID = v.Building_ID,
                        Latitude = (double)absLoc.latitude,
                        Longitude = (double)absLoc.longitude,
                        Altitude = (int)absLoc.altitude,
                        Provider = WIFI_PROVIDER,
                        Time = DateTime.Now,
                        Accuracy = 10 //dummy accuracy
                    });
                }
                i++;
            }
            return(null);
        }
        //OK
        private static String createFoliaJsonEdge(Edge e)
        {
            Vertex           origin      = e.Vertices[0];
            Vertex           destination = e.Vertices[1];
            AbsoluteLocation absLoc      = origin.AbsoluteLocations[0];
            StringBuilder    sb          = new StringBuilder();

            sb.Append("{");

            sb.Append("endpoint1: { ");
            sb.Append("   id: ").Append(origin.ID);
            sb.Append(", lat: ").Append(absLoc.latitude);
            sb.Append(", lon: ").Append(absLoc.longitude);
            sb.Append(" }, ");
            absLoc = destination.AbsoluteLocations[0];
            sb.Append("endpoint2: { ");
            sb.Append("   id: ").Append(destination.ID);
            sb.Append(", lat: ").Append(absLoc.latitude);
            sb.Append(", lon: ").Append(absLoc.longitude);
            sb.Append(" } ");

            sb.Append("}");

            return(sb.ToString());
        }
Beispiel #9
0
 /// <summary>
 /// Draws the Label
 /// </summary>
 public override void Draw(SpriteBatch sb)
 {
     if (Visible)
     {
         Text.Draw(sb, AbsoluteLocation.ToVector2());
     }
     base.Draw(sb);
 }
Beispiel #10
0
        /// <summary>
        /// Called when the 'start measuring' button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="curEdge"></param>
        void menuStart_Click(object sender, EventArgs e)
        {
            //Check if new or existing vertex
            Vertex curVertex = Map2DOffline.SelectedOfflineVertex;
            bool   isUnbound = curVertex.ID == Map2DOffline.UNBOUND_ID;
            string queryString;

            if (isUnbound)
            {
                //Converts to int and keeps 6 decimal precision - on the server we correspondingly
                //divide by a million to reproduce the coordinates
                //Reason for using ints: http://stackoverflow.com/questions/5094276/how-to-pass-a-decimal-number-to-a-rest-web-service
                const int        e6     = 1000000;
                AbsoluteLocation absLoc = curVertex.AbsoluteLocations.First();
                int latE6      = (int)(absLoc.latitude * e6);
                int lonE6      = (int)(absLoc.longitude * e6);
                int alt        = (int)absLoc.altitude;
                int buildingId = curVertex.Building_ID;

                //public bool StartMeasuringAtUnboundLocation(string clientMac, int buildingId, int latE6, int lonE6, int altE6)
                StringBuilder sb = new StringBuilder();
                sb.Append("StartMeasuringAtUnboundLocation?");
                sb.Append(string.Format("clientMac='{0}'&", _macAddress));
                sb.Append(string.Format("buildingId={0}&", buildingId));
                sb.Append(string.Format("latE6={0}&", latE6));
                sb.Append(string.Format("lonE6={0}&", lonE6));
                sb.Append(string.Format("alt={0}", alt));
                queryString = sb.ToString();
            }
            else
            {
                //public bool StartMeasuringAtBoundLocation(string clientMac, int vertexId)
                StringBuilder sb = new StringBuilder();
                sb.Append("StartMeasuringAtBoundLocation?");
                //BEWARE: If device id contains '.' it MAY cause problems for some servers. The question is: CAN device ids contain '.'s??
                sb.Append(string.Format("clientMac='{0}'&", _macAddress));
                sb.Append(string.Format("buildingId={0}&", curVertex.Building_ID));
                sb.Append(string.Format("vertexId={0}", curVertex.ID));
                queryString = sb.ToString();
            }
            try
            {
                context.BeginExecute <bool>(
                    new Uri(queryString, UriKind.Relative),
                    OnStartMeasurementComplete, context);
            }
            catch (DataServiceQueryException ex)
            {
                QueryOperationResponse response = ex.Response;
                MessageBox.Show(_macAddress + "\n" + response.Error.Message);
            }
        }
Beispiel #11
0
        private static String createFoliaJsonLocation(Vertex v)
        {
            if (v == null)
            {
                return("null");
            }

            AbsoluteLocation absLoc = v.AbsoluteLocations[0];
            SymbolicLocation symLoc = null;

            foreach (SymbolicLocation s in v.SymbolicLocations)
            {
                symLoc = s;
                break;
            }

            //[
            // {id: , latitude: , longitude: , altitude: , title: , description: , url: , location_type: }
            // ]

            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            sb.Append("id: ").Append(v.ID);
            sb.Append(", latitude: ").Append(absLoc.latitude);
            sb.Append(", longitude: ").Append(absLoc.longitude);
            sb.Append(", altitude: ").Append(absLoc.altitude);
            String title = symLoc != null ? symLoc.title : "null";

            sb.Append(", title: ").Append("'").Append(title).Append("'");
            String description = symLoc != null ? symLoc.description : "null";

            sb.Append(", description: ").Append("'").Append(description).Append("'");
            String url = symLoc != null ? symLoc.url : "null";

            sb.Append(", url: ").Append("'").Append(url).Append("'");
            sb.Append(", location_type: ").Append(symLoc != null ? symLoc.info_type : -1);
            //ToString capitalizes boolean, so necessary to call toLower
            string isStair = v.isStairEndpoint().ToString().ToLower();

            sb.Append(", isStairEndpoint: ").Append(isStair);
            string isElevator = v.isElevatorEndpoint().ToString().ToLower();

            sb.Append(", isElevatorEndpoint: ").Append(isElevator);
            string isEntrance = (symLoc != null && (symLoc.is_entrance ?? false)).ToString().ToLower();

            sb.Append(", isEntrance: ").Append(isEntrance);
            sb.Append("}");

            return(sb.ToString());
        }
        //Write vertex's absLoc like so: (lat; lon; floor)
        private String getCoordinatesTitle(Vertex v)
        {
            AbsoluteLocation absLoc = v.AbsoluteLocations[0];
            StringBuilder    sb     = new StringBuilder();

            sb.Append("(");
            sb.Append(Math.Round((double)absLoc.latitude, 5));
            sb.Append("; ");
            sb.Append(Math.Round((double)absLoc.longitude, 5));
            sb.Append("; ");
            sb.Append((int)(absLoc.altitude));
            sb.Append(")");
            return(sb.ToString());
        }
 /// <summary>Serves as the default hash function. </summary>
 /// <returns>A hash code for the current object.</returns>
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = IsValid.GetHashCode();
         hashCode = (hashCode * 397) ^ (RelativeLocation?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (AbsoluteLocation?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (InstanceLocation?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (AnnotationValue?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Keyword?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (AdditionalInfo?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (NestedResults?.GetCollectionHashCode() ?? 0);
         return(hashCode);
     }
 }
        public override void ScriptNotify(object sender, NotifyEventArgs e)
        {
            base.ScriptNotify(sender, e);

            string[] methodParts = e.Value.Split('|');
            //MessageBox.Show(curEdge.Value);
            //window.external.Notify("setSelectedLocation|" + online + "|" + floor + "|" + location.lat + "|" + location.lng);
            if (methodParts[0].StartsWith("setSelectedLocation"))
            {
                int    floor = int.Parse(methodParts[2]);
                double lat   = double.Parse(methodParts[3]);
                double lon   = double.Parse(methodParts[4]);

                StringBuilder title = new StringBuilder();
                title.Append("Unbound: ").Append(floor).Append(";").Append(Math.Round(lat, 5)).Append("; ").Append(Math.Round(lon, 5));

                setSelectedLocation(false, floor, lat, lon);
                //updateSelectedVertex(null, title.ToString(), false);
                UI_ShowSelectedLocation(lat, lon);
            }
            else if (methodParts[0].StartsWith("onTap"))
            {
                //"onTap|" + online + "|" + floor + "|" + vertexItem.id
                int id = int.Parse(methodParts[3]);
                //HACK: Use dictionary graph to get vertex by id
                Building b = LocationService.CurrentBuilding;
                if (b == null)
                {
                    return;
                }

                Vertex           v      = b.Vertices.FirstOrDefault(v1 => v1.ID == id);
                AbsoluteLocation absLoc = v.AbsoluteLocations.First();
                StringBuilder    sb     = new StringBuilder();
                sb.Append("ID: ").Append(v.ID);
                sb.Append(" (").Append(Math.Round((double)absLoc.latitude, 5)).Append(", ");
                sb.Append(Math.Round((double)absLoc.longitude, 5)).Append(", ");
                sb.Append((int)absLoc.altitude).Append(")");
                String title = sb.ToString();

                this.updateSelectedVertex(v, title, true);
                //notify UI that onTap has occured
                if (OnTapChange != null)
                {
                    OnTapChange(null, null);
                }
            }
        }
Beispiel #15
0
 public override void Draw(SpriteBatch sb)
 {
     if (Visible)
     {
         if (AbsoluteLocation.X + Size.Width > GraphicsManager.Instance.Viewport.Width)
         {
             AbsoluteLocation = new Point(AbsoluteLocation.X - Size.Width, AbsoluteLocation.Y);
         }
         Sprite.DrawNineCut(sb, AbsoluteBounds, null, Color);
         for (int i = 0; i < wrappedText.Length; i++)
         {
             wrappedText[i].Draw(sb, AbsoluteLocation.ToVector2() + new Vector2(padding, padding + (lineSpacing + lineHeight) * i));
         }
     }
     base.Draw(sb);
 }
Beispiel #16
0
        private static String createFoliaJsonLocationJava(Vertex v)
        {
            if (v == null)
            {
                return("null");
            }

            AbsoluteLocation absLoc = v.AbsoluteLocations[0];
            SymbolicLocation symLoc = null;

            foreach (SymbolicLocation s in v.SymbolicLocations)
            {
                symLoc = s;
                break;
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            sb.Append("id: ").Append(v.ID);
            sb.Append(", latitude: ").Append(absLoc.latitude);
            sb.Append(", longitude: ").Append(absLoc.longitude);
            sb.Append(", altitude: ").Append(absLoc.altitude);
            String title = symLoc != null ? symLoc.title : "null";

            sb.Append(", title: ").Append("\"").Append(title).Append("\"");
            String description = symLoc != null ? symLoc.description : "null";

            sb.Append(", description: ").Append("\"").Append(description).Append("\"");
            String url = symLoc != null ? symLoc.url : "null";

            sb.Append(", url: ").Append("\"").Append(url).Append("\"");
            //sb.append(", location_type: ").append(symLoc != null ? symLoc.getType().toString() : "N/A");
            sb.Append(", location_type: ").Append(symLoc != null ? symLoc.info_type ?? -1 : -1);
            string isStairEndpoint = v.isStairEndpoint().ToString().ToLower();

            sb.Append(", isStairEndpoint: ").Append(isStairEndpoint);
            string isElevatorEndpoint = v.isElevatorEndpoint().ToString().ToLower();

            sb.Append(", isElevatorEndpoint: ").Append(isElevatorEndpoint);
            string isEntrance = (symLoc != null ? symLoc.is_entrance : false).ToString().ToLower();

            sb.Append(", isEntrance: ").Append(isEntrance);
            sb.Append("}");

            return(sb.ToString());
        }
        private void AddVertexPin(Vertex v)
        {
            Image img = MarkerConfig.CreateImage(v);

            img.Tap += (object sender, GestureEventArgs e) =>
            {
                e.Handled = true;

                Tapped_UpdatePins(v, img);
                Tapped_UpdateMenu();
                Tapped_UpdateTitle();
            };

            //pushpin.MouseLeftButtonUp += new MouseButtonEventHandler(pushpin_MouseLeftButtonUp);
            AbsoluteLocation pos = v.AbsoluteLocations.First();

            mapLayerVertices.AddChild(img, new GeoCoordinate((double)pos.latitude, (double)pos.longitude), PositionOrigin.BottomCenter);
        }
        /**
         * This method is called (from javascript) whenever the user taps on the map - not a marker.
         * This captures the lat, lon coordinates of the selected location
         * This also means that an unbound location has been selected, i.curEdge., selectedVertex will have id = -1.
         * @param isOnline Indicates whether we are in the online phase (false)
         * @param floor the current floor
         * @param lat the latitude of the tapped location
         * @param lon the longitude of the tapped location
         */
        public void setSelectedLocation(bool isOnline, int floor, double lat, double lon)
        {
            Vertex curVertex = new Vertex();

            curVertex.ID          = -1;
            curVertex.Building_ID = LocationService.CurrentBuilding.ID;
            AbsoluteLocation absLoc = new AbsoluteLocation();

            absLoc.latitude  = Convert.ToDecimal(lat);
            absLoc.longitude = Convert.ToDecimal(lon);
            absLoc.altitude  = floor;
            curVertex.AbsoluteLocations.Add(absLoc);

            StringBuilder title = new StringBuilder();

            title.Append("Unbound: ").Append(floor).Append(";").Append(Math.Round(lat, 5)).Append("; ").Append(Math.Round(lon, 5)).Append("; floor ").Append(floor);

            updateSelectedVertex(curVertex, title.ToString(), false);
            UI_ShowSelectedLocation(lat, lon);
        }
        public bool StartMeasuringAtUnboundLocation(string clientMac, int buildingId, int latE6, int lonE6, int alt)
        {
            /// A temporary vertex is created at the specified coordinates in the specified building
            /// but the vertex is not materialized until SaveMeasurement(...) is called.
            /// (until that time the vertex is given a fake id)

            //Create new vertex in the specified building at the specified coordinates with a fake id
            Vertex v = new Vertex();

            v.ID          = GetNextFakeVertexId();
            v.Building_ID = buildingId;
            const decimal    e6     = 1000000;
            AbsoluteLocation absLoc = new AbsoluteLocation();

            absLoc.latitude  = latE6 / e6;
            absLoc.longitude = lonE6 / e6;
            absLoc.altitude  = alt;
            v.AbsoluteLocations.Add(absLoc);

            return(StartMeasuring(clientMac, v));
        }
        public void onTap(Vertex v)
        {
            if (v == null)
            {
                return;
            }

            //NOTE: ID and (lat, lon) is for debugging (tracking down faulty rounded coordinates
            AbsoluteLocation absLoc = v.AbsoluteLocations[0];
            StringBuilder    sb     = new StringBuilder();

            sb.Append("ID: ").Append(v.ID);
            sb.Append(" (").Append(Math.Round((double)absLoc.latitude, 5)).Append(", ");
            sb.Append(Math.Round((double)absLoc.longitude, 5)).Append(", ");
            sb.Append((int)absLoc.altitude).Append(")");
            String title = sb.ToString();

            this.updateSelectedVertex(v, title, true);

            //navigate
        }
Beispiel #21
0
        private void AddVertexPin(Vertex v)
        {
            //Pushpin pushpin = new Pushpin();
            //pushpin.Style = (Style)(Application.Current.Resources["PushpinStyle"]);
            Image pushpin = MarkerConfig.CreateImage(v);

            //pushpin.Tap += new EventHandler<GestureEventArgs>(pushpin_Tap);
            pushpin.Tap += (object sender, GestureEventArgs args) =>
            {
                SymbolicLocation symLoc = v.SymbolicLocations.FirstOrDefault();
                if (symLoc != null)
                {
                    string title       = symLoc.title ?? "";
                    string description = symLoc.description ?? "";
                    string url         = symLoc.url ?? "";
                    MessageBox.Show(string.Format("{0}\n{1}\n{2}", title, description, url));
                }
            };

            AbsoluteLocation pos = v.AbsoluteLocations.First();

            mapLayerVertices.AddChild(pushpin, new GeoCoordinate((double)pos.latitude, (double)pos.longitude), PositionOrigin.BottomCenter);
        }
        // Methods dealing with directed edges //

        //Methods dealing with positioning
        //We don't bother to create a subclass for this behavior as our graph is only used for one purpose in this application
        public void InsertRadiusVertices(Vertex v, int radius)
        {
            AbsoluteLocation sourceLocation = v.getLocation().getAbsoluteLocation();
            AbsoluteLocation targetLocation;
            double           dist;

            foreach (Vertex w in vertices.Values)
            {
                if (v.Equals(w))
                {
                    continue;
                }

                targetLocation = w.getLocation().getAbsoluteLocation();
                dist           = com.smartcampus.baselogic.DistanceMeasurements.CalculateMoveddistanceInMeters(
                    sourceLocation.getLatitude(), sourceLocation.getLongitude(),
                    targetLocation.getLatitude(), targetLocation.getLongitude());

                if (dist <= radius)
                {
                    v.addRadiusVertex((Vertex)w);
                }
            }
        }
Beispiel #23
0
 public Vertex(int id, AbsoluteLocation absoluteLocation)
 {
     this.id       = id;
     this.location = new AggregateLocation(absoluteLocation);
 }
	    public void setAbsoluteLocation(AbsoluteLocation location)
	    {
		    this.absoluteLocation = location;
	    }
	    public AggregateLocation(AbsoluteLocation absoluteLocation, SymbolicLocation symbolicLocation)
	    {
		    this.absoluteLocation = absoluteLocation;
		    this.symbolicLocation = symbolicLocation;
	    }
	    public AggregateLocation(AbsoluteLocation absoluteLocation)
	    {
		    this.absoluteLocation = absoluteLocation;
	    }
        public int SaveMeasurement(string clientMac)
        {
            const int error  = -1;
            int       result = error; //change if success

            if (clientMac == null)
            {
                return(error);
            }

            if (!(savedMeasuringClients.ContainsKey(clientMac) && savedOfflineMeasurements.ContainsKey(clientMac)))
            {
                return(error);
            }

            //Remove the measurement from from the 'current' list.
            SnifferWifiMeasurement curWifi = savedOfflineMeasurements[clientMac];
            Vertex curVertex = savedMeasuringClients[clientMac];

            savedOfflineMeasurements.Remove(clientMac);
            savedMeasuringClients.Remove(clientMac);

            Building curBuilding = LoadedBuildings.First(b => b.ID == curVertex.Building_ID);

            //save changes persistently
            try
            {
                //Notify context about changes
                radiomapEntities localContext = new radiomapEntities(radiomapUri);
                if (curVertex.ID <= UNBOUND_ID_STARTVALUE) //unbound location
                {
                    AbsoluteLocation absLoc = curVertex.AbsoluteLocations.First();
                    localContext.AttachTo("Buildings", curBuilding);
                    localContext.AddRelatedObject(curBuilding, "Vertices", curVertex);
                    localContext.AddRelatedObject(curVertex, "AbsoluteLocations", absLoc);
                }
                else
                {
                    localContext.AttachTo("Vertices", curVertex);
                    result = curVertex.ID;
                }
                localContext.AddRelatedObject(curVertex, "SnifferWifiMeasurements", curWifi);
                foreach (SnifferHistogram curHist in curWifi.SnifferHistograms)
                {
                    localContext.AddRelatedObject(curWifi, "SnifferHistograms", curHist);
                }

                //save to database
                DataServiceResponse response = localContext.SaveChanges(SaveChangesOptions.Batch);

                // Enumerate the returned responses. If a new vertex, add it to the current building and return its id.
                foreach (ChangeOperationResponse change in response)
                {
                    // Get the descriptor for the entity.
                    EntityDescriptor descriptor = change.Descriptor as EntityDescriptor;

                    if (descriptor != null)
                    {
                        if (descriptor.Entity is SnifferWifiMeasurement)
                        {
                            //Yes, the measurement got saved
                            Console.WriteLine("Measurement saved."); //dummy statement
                        }
                        else if (descriptor.Entity is Vertex)
                        {
                            Vertex newVertex = descriptor.Entity as Vertex;
                            curBuilding.Vertices.Add(newVertex);
                            result = newVertex.ID;
                        }
                    }
                }

                return(result);
            }
            catch (DataServiceRequestException)
            {
                return(error);
            }
        }
Beispiel #28
0
 public static AbsoluteLocation CreateAbsoluteLocation(int ID, int vertex_ID)
 {
     AbsoluteLocation absoluteLocation = new AbsoluteLocation();
     absoluteLocation.ID = ID;
     absoluteLocation.Vertex_ID = vertex_ID;
     return absoluteLocation;
 }
Beispiel #29
0
 public void AddToAbsoluteLocations(AbsoluteLocation absoluteLocation)
 {
     base.AddObject("AbsoluteLocations", absoluteLocation);
 }
	public Vertex getClosestVertex(AbsoluteLocation userAbsLoc) {
		/*
		 * this may not be the best way of determining
		 * the vertex closest to the geopoint - a better solution
		 * could be to arrange the vertices in a different data structure
		 * (currently it is a list)
		 */
		
		int floor = (int)userAbsLoc.getAltitude();
		double dist, bestDist = double.MaxValue;
		Vertex closestVertex = null;
		foreach (Vertex v in this.getVertices(floor)) {
			AbsoluteLocation loc = v.getLocation().getAbsoluteLocation();
			dist = getDistance(loc.getLatitude() * 1E6, 
							   userAbsLoc.getLatitude() * 1E6, 
							   loc.getLongitude() * 1E6, 
							   userAbsLoc.getLongitude() * 1E6);
			
			if(dist < bestDist) {
				bestDist = dist;
				closestVertex = v;
			}
		}
		return closestVertex;
	}
        public PositionEstimate GetPosition(string clientMac)
        {
            /**
             * [WebGet] = SnifferReceiver operation (cf: http://msdn.microsoft.com/en-us/library/cc668788.aspx )
             * usage example: http://localhost:38244/SnifferService.svc/GetPosition?mac='Big Mac'
             */

            if (clientMac == null)
            {
                return(null);
            }

            SnifferWifiMeasurement curMeas;

            if (!(currentOnlineMeasurements.TryGetValue(clientMac, out curMeas)))
            {
                return(null); //we do not have a measurement yet to base an estimate on
            }

            //Check whether the client is associated with a building
            //If not, positioning has (JUST) been requested, but the correct building not established yet.
            WifiPosEngine posEngine;

            if (!(currentWifiPosEngines.TryGetValue(clientMac, out posEngine)))
            {
                return(null); //we do not have a wifi pos engine. Reason: User has probably not called StartWifiPositioning.
            }

            if (posEngine.getCurrentBuilding() == null) //It is the very first estimate
            {
                posEngine.setCurrentBuilding(getCorrectBuilding(curMeas));
            }

            EstimateResult currentEstimate = posEngine.getEstimate(curMeas);

            //We have a result
            if (currentEstimate != null && currentEstimate.getVertex() != null)
            {
                //convert estimated location to PositionEstimate
                PositionEstimate result = new PositionEstimate();
                Vertex           v      = currentEstimate.getVertex();
                AbsoluteLocation a      = v.AbsoluteLocations.First();

                result.VertexID    = v.ID;
                result.Building_ID = v.Building_ID;
                result.Latitude    = (double)a.latitude;
                result.Longitude   = (double)a.longitude;
                result.Altitude    = (double)a.longitude;
                result.Accuracy    = currentEstimate.getErrorEstimate();
                result.HasAccuracy = true;
                result.HasBearing  = false;
                result.HasSpeed    = false;
                result.Provider    = WIFI_PROVIDER;
                result.Time        = DateTime.Now;

                return(result);
            }
            else //We do not have a result
            {
                return(null);
            }
        }
Beispiel #32
0
		public Vertex(int id, AbsoluteLocation absoluteLocation)
		{
			this.id = id;
			this.location = new AggregateLocation(absoluteLocation);
		}