Ejemplo n.º 1
0
        private static int InsertEarthquakeToDisplay(Earthquake eq)
        {
            if(m_cameraManager == null)
            {
                return 0;
            }

            bool haveTerraTiles = (Project.terraserverAvailable || Project.terraserverDisconnected)
                                    && (m_cameraManager.terraTopLeft.Lng < m_cameraManager.terraBottomRight.Lng)
                                    && (m_cameraManager.terraTopLeft.Lat > m_cameraManager.terraBottomRight.Lat);

            // for PDA we need to cover all area covered by tiles, which is wider than visible window:
            double lngCLeft = haveTerraTiles ? m_cameraManager.terraTopLeft.Lng : m_cameraManager.CoverageTopLeft.Lng;
            double lngCRight = haveTerraTiles ? m_cameraManager.terraBottomRight.Lng : m_cameraManager.CoverageBottomRight.Lng;
            double latCTop = haveTerraTiles ? m_cameraManager.terraTopLeft.Lat : m_cameraManager.CoverageTopLeft.Lat;
            double latCBottom = haveTerraTiles ? m_cameraManager.terraBottomRight.Lat : m_cameraManager.CoverageBottomRight.Lat;

            double lng = eq.Location.Lng;
            double lat = eq.Location.Lat;

            // here is a catch: eq coordinates are <180 >-180 (normaliized) while coverage coordinates are not.
            bool span180W = lngCLeft < -180.0d;
            bool span180E = lngCRight > 180.0d;
            // de-normalize lng for comparisons, if span180 takes place:
            if(span180W && lng > 0)
            {
                lng -= 360.0d;
            }
            if(span180E && lng < 0)
            {
                lng += 360.0d;
            }

            if (lng > lngCRight || lng < lngCLeft || lat > latCTop || lat < latCBottom)
            {
                return 0;
            }

            int ii;
            for (ii=0; ii < m_earthquakesDisplayed.Count ;ii++)
            {
                Earthquake other = (Earthquake)m_earthquakesDisplayed[ii];
                double lato = other.Location.Lat;

                if(lato == lat)
                {
                    if(eq.sameAs(other))
                    {
                        //LibSys.StatusBar.Trace(" ---- ignored duplicate earthquake (orig from " + other.Source + ") : " + eq);
                        return 0;		// ignore if it ain't new
                    }
                }
                else if(lato < lat)	// sort north to south
                {
                    break;
                }
            }
            if(ii == m_earthquakesDisplayed.Count)
            {
                m_earthquakesDisplayed.Add(eq);
            }
            else
            {
                m_earthquakesDisplayed.Insert(ii, eq);
            }
            return 1;
        }
Ejemplo n.º 2
0
        public static void insertEarthquake(string[] infos)
        {
            /* DEBUG
            for(int jj=0; jj < infos.Length ;jj++)
            {
                LibSys.StatusBar.Trace("infos: " + jj + " '" + infos[jj] + "'");
            }
            */
            Earthquake eq = new Earthquake(infos);

            /* DEBUG
            if (eq.Location.X > -127 || eq.Location.X < -130 || eq.Location.Y > 45 || eq.Location.Y < 43)
            {
                return;
            }
            */

            // Filter out future quakes:
            DateTime dtInsane = DateTime.Now.AddDays(5);
            if(eq.DateTime.Ticks > dtInsane.Ticks)
            {
                return;
            }

            //double lng = eq.Location.Lng;
            double lat = eq.Location.Lat;

            lock(m_earthquakesAll)
            {

                int ii;
                for (ii=0; ii < m_earthquakesAll.Count ;ii++)
                {
                    Earthquake other = (Earthquake)m_earthquakesAll[ii];
                    double lngo = other.Location.Lng;
                    double lato = other.Location.Lat;

                    //if(lngo == lng)
                    if(lato == lat)
                    {
                        if(eq.sameAs(other))
                        {
                            //LibSys.StatusBar.Trace(" ---- ignored duplicate earthquake (orig from " + other.Source + ") : " + eq);
                            return;		// ignore if it ain't new
                        }
                    }
                        //else if(lngo < lng)	// sort east to west
                        //else if(lato > lat)	// sort south to north
                    else if(lato < lat)	// sort north to south
                    {
                        break;
                    }
                }
                eq.Id = Project.eqId++;		// new earthquake, assign an Id
                if(ii == m_earthquakesAll.Count)
                {
                    m_earthquakesAll.Add(eq);
                }
                else
                {
                    m_earthquakesAll.Insert(ii, eq);
                }

                // invalidating every object's drawing area is VERY expensive, we do PictureManager.Refresh() instead
                // at the end of interpreting all files. So the next line is commented out.
                //DynamicObjectCreateCallback(eq);
            }
        }