OpenCPN Partial API docs
Loading...
Searching...
No Matches
mbtiles.h
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: MBTiles Chart Support
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2018 by David S. Register *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 ***************************************************************************
25 *
26 *
27 */
28
29#ifndef _CHARTMBTILES_H_
30#define _CHARTMBTILES_H_
31
32#include "chartbase.h"
33#include "georef.h" // for GeoRef type
34#include "OCPNRegion.h"
35#include "viewport.h"
36
37enum class MBTilesType : std::int8_t { BASE, OVERLAY };
38enum class MBTilesScheme : std::int8_t { XYZ, TMS };
39
40class WXDLLEXPORT ChartMbTiles;
41
42//-----------------------------------------------------------------------------
43// Constants, etc.
44//-----------------------------------------------------------------------------
45
46//-----------------------------------------------------------------------------
47// Fwd Refs
48//-----------------------------------------------------------------------------
49
50class ViewPort;
51class PixelCache;
52class ocpnBitmap;
55
56namespace SQLite {
57class Database;
58}
59
60class GLShaderProgram;
61
62//-----------------------------------------------------------------------------
63// Helper classes
64//-----------------------------------------------------------------------------
65
66// ----------------------------------------------------------------------------
67// ChartMBTiles
68// ----------------------------------------------------------------------------
69
70class ChartMBTiles : public ChartBase {
71public:
72 // Public methods
73
75 virtual ~ChartMBTiles();
76
77 // Accessors
78 virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon);
79 virtual ThumbData *GetThumbData();
80 virtual bool UpdateThumbData(double lat, double lon);
81
82 virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
83
84 int GetNativeScale() { return m_Chart_Scale; }
85 double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom);
86 double GetNormalScaleMax(double canvas_scale_factor, int canvas_width);
87
88 virtual InitReturn Init(const wxString &name, ChartInitFlag init_flags);
89
90 bool RenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
91 const OCPNRegion &Region);
92
93 virtual bool RenderRegionViewOnGL(const wxGLContext &glc,
94 const ViewPort &VPoint,
95 const OCPNRegion &RectRegion,
96 const LLRegion &Region);
97
98 virtual double GetNearestPreferredScalePPM(double target_scale_ppm);
99
100 virtual void GetValidCanvasRegion(const ViewPort &VPoint,
101 OCPNRegion *pValidRegion);
102 virtual LLRegion GetValidRegion();
103
104 virtual bool GetChartExtent(Extent *pext);
105
106 void SetColorScheme(ColorScheme cs, bool bApplyImmediate);
107
108 double GetPPM() { return m_ppm_avg; }
109 double GetZoomFactor() { return m_zoomScaleFactor; }
110
111protected:
112 // Methods
113 bool RenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint);
114 InitReturn PreInit(const wxString &name, ChartInitFlag init_flags,
115 ColorScheme cs);
116 InitReturn PostInit(void);
117
118 void PrepareTiles();
119 void PrepareTilesForZoom(int zoomFactor, bool bset_geom);
120 bool getTileTexture(mbTileDescriptor *tile);
121 void FlushTiles(void);
122 void FlushTextures(void);
123 bool RenderTile(mbTileDescriptor *tile, int zoomLevel,
124 const ViewPort &VPoint);
125
126 // Protected Data
127
128 float m_LonMax, m_LonMin, m_LatMax, m_LatMin;
129
130 double m_ppm_avg; // Calculated true scale factor of the 1X chart,
131 // pixels per meter
132
133 int m_b_cdebug;
134
135 int m_minZoom, m_maxZoom;
136 mbTileZoomDescriptor **m_tileArray;
137 LLRegion m_minZoomRegion;
138 wxBitmapType m_imageType;
139
140 double m_zoomScaleFactor;
141
142 MBTilesType m_Type;
143 MBTilesScheme m_Scheme;
144
145 SQLite::Database *m_pDB;
146 int m_nTiles;
147 std::string m_format;
148
149 GLShaderProgram *m_tile_shader_program;
150
151private:
152 void InitFromTiles(const wxString &name);
153 wxPoint2DDouble GetDoublePixFromLL(ViewPort &vp, double lat, double lon);
154};
155
156#endif