Пример #1
0
        public void TestMethod2()
        {
            int mapZoom = 14;

            System.Diagnostics.Debug.WriteLine("tolerance: " + tolerance(mapZoom));
            var a = this.lineList[0].Coordinates;
            DouglasPeuckerReduction dpr = new DouglasPeuckerReduction(a);
            List<LatLng> reducedLine = dpr.reduceLine(mapZoom);

            //System.Diagnostics.Debug.WriteLine(reducedLined[0].Coordinates);

            foreach (LatLng latlng in this.lineList[0].Coordinates) {
                if (!reducedLine.Contains(latlng))
                    System.Diagnostics.Debug.WriteLine("Removed: " + latlng.ToString());
            }
            foreach (LatLng latlng in reducedLine)
                System.Diagnostics.Debug.WriteLine("Kept: " + latlng.ToString());
        }
Пример #2
0
        public IList<Line> getPoints(string vendor, decimal bottomLeftLat, decimal bottomLeftLng, decimal topRightLat, decimal topRightLng, int zoom)
        {
            //double tolerance = Math.Pow(zoom, -(zoom / 5));

            IList<Line> coordinates;
            IList<Line> returnLine;
            coordinates = returnLine = new List<Line>();

            if (vendor.Equals("level3"))
                coordinates = this.svc.getPoints(vendor, bottomLeftLat, bottomLeftLng, topRightLat, topRightLng);
            else {
                if (vendorPoints != null && vendorPoints.Data != null)
                    vendorPoints.Data.TryGetValue(vendor, out coordinates);
                if (vendorPoints == null)
                    vendorPoints = new ApplicationStore<Dictionary<string, IList<Line>>>(MainFactory.getCacheExpiration(), new Dictionary<string, IList<Line>>());
                if (coordinates == null || coordinates.Count() < 1) {
                    coordinates = this.svc.getPoints(vendor, (decimal)26.4, (decimal)-132.1, (decimal)49.4, (decimal)-59.1);
                    if (!vendorPoints.Data.ContainsKey(vendor)) {
                        vendorPoints.Data.Add(vendor, coordinates);
                        HttpContext.Current.Application["gisFiber"] = vendorPoints;
                    }
                }
            }

            if (zoom <= 12) {
                foreach (Line line in coordinates) {
                    DouglasPeuckerReduction dpr = new DouglasPeuckerReduction(line.Coordinates);
                    if (!vendor.Equals("level3")) {             // if it is a GIS vendor, filter out unnecessary coordinates
                        if (!isOutsideBounds(line, bottomLeftLat, bottomLeftLng, topRightLat, topRightLng)) {
                            var l = new Line(line.Name, dpr.reduceLine(zoom));
                            l.Color = vendorNames.Data[line.Name].ColorHex;
                            returnLine.Add(l);
                        }
                    } else {
                        var l = new Line(line.Name, dpr.reduceLine(zoom));
                        l.Color = "#f00";
                        returnLine.Add(l);
                    }
                }
            } else {
                if (!vendor.Equals("level3")) {             // if it is a GIS vendor, filter out unnecessary coordinates
                    foreach (Line line in coordinates
                                                .Where(x =>
                                                    x.Coordinates.Any(y =>
                                                        y.Lat >= bottomLeftLat &&
                                                        y.Lat <= topRightLat &&
                                                        y.Lng >= bottomLeftLng &&
                                                        y.Lng <= topRightLng))) {
                        var l = new Line(line.Name, line.Coordinates);
                        l.Color = vendorNames.Data[line.Name].ColorHex;
                        returnLine.Add(l);
                    }
                } else {
                    foreach (Line line in coordinates) {
                        var l = new Line(line.Name, line.Coordinates);
                        l.Color = "#f00";
                        returnLine.Add(l);
                    }
                }
            }

            return returnLine;
        }
Пример #3
0
        private IList<ICoordShape> getPolygons(IPolygonSvc svc, 
            decimal? bottomLeftLat, decimal? bottomLeftLng,
            decimal? topRightLat, decimal? topRightLng,
            int zoom)
        {
            IList<ICoordShape> shapeList = null;
            //double tolerance = Math.Pow(zoom, -(zoom / 5));
            if (bottomLeftLat != null && bottomLeftLng != null && topRightLat != null && topRightLng != null)
                shapeList = svc.getPolygons(new LatLng((decimal)bottomLeftLat, (decimal)bottomLeftLng),
                                        new LatLng((decimal)topRightLat, (decimal)topRightLng));
            else
                shapeList = svc.getPolygons();

            if (zoom <= 9) {
                foreach (ICoordShape shape in shapeList) {
                    DouglasPeuckerReduction dpr = new DouglasPeuckerReduction(shape.Coordinates);
                    shape.Coordinates = dpr.reduceLine(zoom, true);
                }
            }

            return shapeList;
        }