@@ -71,6 +71,8 @@ void MapWindow::changeStyle()
71
71
if (++currentStyleIndex == styles.size ()) {
72
72
currentStyleIndex = 0 ;
73
73
}
74
+
75
+ m_sourceAdded = false ;
74
76
}
75
77
76
78
void MapWindow::keyPressEvent (QKeyEvent *ev)
@@ -82,30 +84,115 @@ void MapWindow::keyPressEvent(QKeyEvent *ev)
82
84
changeStyle ();
83
85
break ;
84
86
case Qt::Key_L: {
85
- m_map. setPaintProperty ( " water " , " fill-color " , QColor ( 255 , 0 , 0 ));
86
- m_map. setPaintProperty ( " building " , " fill-color " , " red " ) ;
87
- m_map. setPaintProperty ( " road-secondary-tertiary " , " line-color " , " red " );
87
+ if (m_sourceAdded) {
88
+ return ;
89
+ }
88
90
89
- m_map.setLayoutProperty (" road-label-small" , " symbol-placement" , " point" );
90
- m_map.setLayoutProperty (" road-label-medium" , " symbol-placement" , " point" );
91
- m_map.setLayoutProperty (" road-label-large" , " symbol-placement" , " point" );
91
+ m_sourceAdded = true ;
92
92
93
93
QFile geojson (" :source.geojson" );
94
94
geojson.open (QIODevice::ReadOnly);
95
95
96
- QVariantMap testSource;
97
- testSource[" type" ] = " geojson" ;
98
- testSource[" data" ] = geojson.readAll ();
99
-
100
- m_map.addSource (" testSource" , testSource);
101
-
102
- QVariantMap testLayer;
103
- testLayer[" id" ] = " testLayer" ;
104
- testLayer[" type" ] = " fill" ;
105
- testLayer[" source" ] = " testSource" ;
106
-
107
- m_map.addLayer (testLayer);
108
- m_map.setPaintProperty (" testLayer" , " fill-color" , QColor (" blue" ));
96
+ // The data source for the route line and markers
97
+ QVariantMap routeSource;
98
+ routeSource[" type" ] = " geojson" ;
99
+ routeSource[" data" ] = geojson.readAll ();
100
+ m_map.addSource (" routeSource" , routeSource);
101
+
102
+ // The route case, painted before the route
103
+ QVariantMap routeCase;
104
+ routeCase[" id" ] = " routeCase" ;
105
+ routeCase[" type" ] = " line" ;
106
+ routeCase[" source" ] = " routeSource" ;
107
+ m_map.addLayer (routeCase);
108
+
109
+ m_map.setPaintProperty (" routeCase" , " line-color" , QColor (" white" ));
110
+ m_map.setPaintProperty (" routeCase" , " line-width" , 20.0 );
111
+ m_map.setLayoutProperty (" routeCase" , " line-join" , " round" );
112
+ m_map.setLayoutProperty (" routeCase" , " line-cap" , " round" );
113
+
114
+ // The route, painted on top of the route case
115
+ QVariantMap route;
116
+ route[" id" ] = " route" ;
117
+ route[" type" ] = " line" ;
118
+ route[" source" ] = " routeSource" ;
119
+ m_map.addLayer (route);
120
+
121
+ m_map.setPaintProperty (" route" , " line-color" , QColor (" blue" ));
122
+ m_map.setPaintProperty (" route" , " line-width" , 8.0 );
123
+ m_map.setLayoutProperty (" route" , " line-join" , " round" );
124
+ m_map.setLayoutProperty (" route" , " line-cap" , " round" );
125
+
126
+ // Markers at the beginning and end of the route
127
+ m_map.addImage (" label-arrow" , QImage (" :label-arrow.svg" ));
128
+ m_map.addImage (" label-background" , QImage (" :label-background.svg" ));
129
+
130
+ QVariantMap makerArrow;
131
+ makerArrow[" id" ] = " makerArrow" ;
132
+ makerArrow[" type" ] = " symbol" ;
133
+ makerArrow[" source" ] = " routeSource" ;
134
+ m_map.addLayer (makerArrow);
135
+
136
+ m_map.setLayoutProperty (" makerArrow" , " icon-image" , " label-arrow" );
137
+ m_map.setLayoutProperty (" makerArrow" , " icon-size" , 0.5 );
138
+ m_map.setLayoutProperty (" makerArrow" , " icon-ignore-placement" , true );
139
+
140
+ QVariantList arrowOffset;
141
+ arrowOffset.append (0.0 );
142
+ arrowOffset.append (-15.0 );
143
+ m_map.setLayoutProperty (" makerArrow" , " icon-offset" , arrowOffset);
144
+
145
+ QVariantMap makerBackground;
146
+ makerBackground[" id" ] = " makerBackground" ;
147
+ makerBackground[" type" ] = " symbol" ;
148
+ makerBackground[" source" ] = " routeSource" ;
149
+ m_map.addLayer (makerBackground);
150
+
151
+ m_map.setLayoutProperty (" makerBackground" , " icon-image" , " label-background" );
152
+ m_map.setLayoutProperty (" makerBackground" , " text-field" , " {name}" );
153
+ m_map.setLayoutProperty (" makerBackground" , " icon-text-fit" , " both" );
154
+ m_map.setLayoutProperty (" makerBackground" , " icon-ignore-placement" , true );
155
+ m_map.setLayoutProperty (" makerBackground" , " text-ignore-placement" , true );
156
+ m_map.setLayoutProperty (" makerBackground" , " text-anchor" , " left" );
157
+ m_map.setLayoutProperty (" makerBackground" , " text-size" , 16.0 );
158
+ m_map.setLayoutProperty (" makerBackground" , " text-padding" , 0.0 );
159
+ m_map.setLayoutProperty (" makerBackground" , " text-line-height" , 1.0 );
160
+ m_map.setLayoutProperty (" makerBackground" , " text-max-width" , 8.0 );
161
+
162
+ QVariantList iconTextFitPadding;
163
+ iconTextFitPadding.append (15.0 );
164
+ iconTextFitPadding.append (10.0 );
165
+ iconTextFitPadding.append (15.0 );
166
+ iconTextFitPadding.append (10.0 );
167
+ m_map.setLayoutProperty (" makerBackground" , " icon-text-fit-padding" , iconTextFitPadding);
168
+
169
+ QVariantList backgroundOffset;
170
+ backgroundOffset.append (-0.5 );
171
+ backgroundOffset.append (-1.5 );
172
+ m_map.setLayoutProperty (" makerBackground" , " text-offset" , backgroundOffset);
173
+
174
+ m_map.setPaintProperty (" makerBackground" , " text-color" , QColor (" white" ));
175
+
176
+ QVariantList filterExpression;
177
+ filterExpression.append (" ==" );
178
+ filterExpression.append (" $type" );
179
+ filterExpression.append (" Point" );
180
+
181
+ QVariantList filter;
182
+ filter.append (filterExpression);
183
+
184
+ m_map.setFilter (" makerArrow" , filter);
185
+ m_map.setFilter (" makerBackground" , filter);
186
+
187
+ // Tilt the labels when tilting the map and make them larger
188
+ m_map.setLayoutProperty (" road-label-large" , " text-size" , 30.0 );
189
+ m_map.setLayoutProperty (" road-label-large" , " text-pitch-alignment" , " viewport" );
190
+
191
+ m_map.setLayoutProperty (" road-label-medium" , " text-size" , 30.0 );
192
+ m_map.setLayoutProperty (" road-label-medium" , " text-pitch-alignment" , " viewport" );
193
+
194
+ m_map.setLayoutProperty (" road-label-small" , " text-pitch-alignment" , " viewport" );
195
+ m_map.setLayoutProperty (" road-label-small" , " text-size" , 30.0 );
109
196
}
110
197
break ;
111
198
case Qt::Key_Tab:
0 commit comments