float MapPropertiesDlg::ScaleElevation(int elevation) { float normElevation = float(MAX_ELEVATION-elevation) / MAX_ELEVATION; MapControllerPtr mapController = m_mapLayer->GetMapController(); return normElevation*mapController->GetMaxElevationGridSpace(); }
void LocationPolygons::InitPolygons() { if (m_currentLocationSet.empty()) return; //Clears existing polygons m_polygons.clear(); Colour currentColour; GeoCoord currentCoord; Point3D mapPoint; PolygonModelPtr emptyPoly( new PolygonModel() ); m_polygons.push_back( emptyPoly ); int currentPolygonIndex = 0; //Get elevation to be used MapControllerPtr mapController = App::Inst().GetLayerTreeController()->GetMapLayer(0)->GetMapController(); if ( m_autoAdjustElevation ) { m_elevationUsed = mapController->GetMaxElevationGridSpace() * mapController->GetVerticalExaggeration() + 0.005; // Add a minimal amount to avoid clashing // between colours of polygons and map } else { m_elevationUsed = m_inputElevation; } //Sort location set by colour std::sort (m_currentLocationSet.begin(), m_currentLocationSet.end(), LocationPolygons::SortByColour); const std::wstring lat ( L"Latitude" ); const std::wstring lon ( L"Longitude" ); //Goes through each location in the given set for (uint i = 0; i < m_currentLocationSet.size(); i++) { //If the current location is active if (m_currentLocationSet[i]->GetLocationController()->GetLocationModel()->IsActive()) { PolygonModelPtr emptyPoly( new PolygonModel() ); //Sets the current properties of the location currentColour = m_currentLocationSet[i]->GetLocationController()->GetColour(); currentColour.SetAlpha(m_fillOpacity); currentCoord.easting = wxAtof ( m_currentLocationSet[i]->GetLocationController()->GetLocationModel()->GetData(lon).c_str() ); currentCoord.northing = wxAtof ( m_currentLocationSet[i]->GetLocationController()->GetLocationModel()->GetData(lat).c_str() ); //Converts from lat/long point to a point on the map App::Inst().GetMapController()->GetMapModel()->LatLongToGrid(currentCoord, mapPoint); //If there's a new colour, a new polygon is created if (currentColour != m_polygons[currentPolygonIndex]->polygonColour) { m_polygons.push_back(emptyPoly); currentPolygonIndex++; m_polygons[currentPolygonIndex]->polygonColour = currentColour; } //Sets elevation if (m_increasingElevation) mapPoint.y = m_elevationUsed + m_elevationOffset*currentPolygonIndex; else mapPoint.y = m_elevationUsed; //If the point is the same point (within EPSILON) then it should not be added to the polygon //**If the same points are added, then the convex hull algorithm doesn't work** bool shouldAdd = true; for (uint j = 0; j < m_polygons[currentPolygonIndex]->originalVertices.size(); j++) { double deltaX = abs( m_polygons[currentPolygonIndex]->originalVertices[j].x - mapPoint.x ); double deltaY = abs( m_polygons[currentPolygonIndex]->originalVertices[j].z - mapPoint.z ); if (deltaX <= EPSILON && deltaY <= EPSILON) shouldAdd = false; } if (shouldAdd) { m_polygons[currentPolygonIndex]->originalVertices.push_back(mapPoint); } } } //Sorts the polygons according to the given algorithm then initializes them for (uint i = 0; i < m_polygons.size(); i++) { if (m_sortBy == CONVEX_HULL) { ConvexHull(m_polygons[i]); } m_polygons[i]->InitPolygon(m_polygonInflation, m_smoothPolygons); } }