// TODO: this method is too big public void createNew() { Debug.WriteLine("----- createCurrentView -----", ToString()); // container to keep map parts which create current map view Hashtable viewParts = new Hashtable(); // get current gps coordinates double latitude = this.currentGpsLocation.getLatitude(); double longitude = this.currentGpsLocation.getLongitude(); //Debug.WriteLine("latitude: " + latitude + ", longitude: " + longitude, this.ToString()); // get point which indicates part image for the location Point partPoint = this.currentMapPkg.getPartPoint(latitude, longitude); Debug.WriteLine("partPoint: " + PointUtil.pointStr(partPoint), ToString()); // get location (pixel coordinates) inside part image Point insidePartPosition = this.currentMapPkg.getInsidePartPosition(latitude, longitude); //Debug.WriteLine("insidePartPosition: (" + insidePartPosition.X + "; " + insidePartPosition.Y + ")", this.ToString()); // add center MapView point Point centerViewPoint = new Point(1, 1); viewParts[centerViewPoint] = this.currentMapPkg.getPart(partPoint); // map view has only sense when there is center map part if (viewParts[centerViewPoint] == null) { Debug.WriteLine("Can't get center part! viewParts[centerViewPoint] is null - skipping.", this.ToString()); // return when center part is null this.currentMapVeiw = null; return; } // add neighbours of center point foreach (DictionaryEntry entry in this.pointSurroundings) { Point directionPoint = (Point)entry.Value; Debug.WriteLine("directionPoint: " + PointUtil.pointStr(directionPoint), ToString()); Point viewNeighbour = PointMath.addPoints(centerViewPoint, directionPoint); Point mapNeighbour = PointMath.addPoints(partPoint, directionPoint); try { viewParts[viewNeighbour] = this.currentMapPkg.getPart(mapNeighbour); if (viewParts[viewNeighbour] == null) { Debug.WriteLine("looking for view neighbour:", this.ToString()); MapPackage neighbourPkg = null; int neighbourDirectionX = 0; if (mapNeighbour.X > this.currentMapPkg.getMaxX()) { neighbourDirectionX = 1; } if (mapNeighbour.X < 0) { neighbourDirectionX = -1; } int neighbourDirectionY = 0; if (mapNeighbour.Y > this.currentMapPkg.getMaxY()) { neighbourDirectionY = 1; } if (mapNeighbour.Y < 0) { neighbourDirectionY = -1; } Point neighbourDirection = new Point(neighbourDirectionX, neighbourDirectionY); try { Debug.WriteLine(" trying to get neighbour pkg for neighbour point: " + PointUtil.pointStr(neighbourDirection), ToString()); // get neighbour map package neighbourPkg = this.mapPkgRepository.getNeighbourMapPkg(this.currentMapPkg, neighbourDirection, this.currentZoom); } catch (MapNotFoundException e) { Debug.WriteLine(" Can't get neighbour pkg for: " + this.currentMapPkg + ", dircetion: (" + directionPoint.X + "; " + directionPoint.Y + "), ERROR: " + e.Message, this.ToString()); } if (neighbourPkg != null) { if (mapNeighbour.X > this.currentMapPkg.getMaxX()) { mapNeighbour.X = 0; } if (mapNeighbour.X < 0) { mapNeighbour.X = neighbourPkg.getMaxX(); } if (mapNeighbour.Y > this.currentMapPkg.getMaxY()) { mapNeighbour.Y = 0; } if (mapNeighbour.Y < 0) { mapNeighbour.Y = neighbourPkg.getMaxY(); } Debug.WriteLine(" getting map part from neighbour pkg for point: " + PointUtil.pointStr(mapNeighbour), this.ToString()); viewParts[viewNeighbour] = neighbourPkg.getPart(mapNeighbour); } } else { Debug.WriteLine("view neighbour ok", this.ToString()); } } catch (Exception e) { Debug.WriteLine("Can't get neighbour(" + entry.Key + ")! ERROR: " + e.Message, this.ToString()); } } // create map view MapView mapView = new MapView(this.currentGpsLocation, insidePartPosition, viewParts, this.orderingPoints); mapView.setLatitudePerPixel(this.currentMapPkg.getLatitudePerPixel()); mapView.setLongitudePerPixel(this.currentMapPkg.getLongitudePerPixel()); Area mapViewArea = createMapViewArea(mapView); Area centerImgArea = createMapViewAreaForCenterImg(mapView); mapView.setArea(mapViewArea); mapView.setCenterImgArea(centerImgArea); Debug.WriteLine("-----------------------------\n", ToString()); this.currentMapVeiw = mapView; }