-
Notifications
You must be signed in to change notification settings - Fork 452
/
Copy pathapp.py
284 lines (272 loc) · 10.4 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
import dash
import numpy as np
from dash import html, Patch
import feffery_maplibre as fm
import feffery_antd_components as fac
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
app.layout = html.Div(
[
fac.AntdSpace(
[
fac.AntdSelect(
id='font-select',
options=[
{
'label': font,
'value': font
}
for font in [
'LXGW WenKai Regular',
'DingTalk JinBuTi Regular',
'LXGW Neo XiHei Regular',
'XiaoLaiSC Regular'
]
],
value='LXGW WenKai Regular',
allowClear=False,
style={
'width': 200
}
)
],
style={
'position': 'absolute',
'top': 20,
'left': 20,
'zIndex': 999
}
),
fm.MapContainer(
[
fm.NavigationControl(
visualizePitch=True
),
# 调用esri开放影像底图
fm.Source(
[
fm.Layer(
id='img-layer',
layerProps={
'type': 'raster',
'source': 'img-source'
}
)
],
id='img-source',
sourceProps={
'type': 'raster',
'tiles': [
'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
],
'tileSize': 256
}
),
# 点要素示例
fm.Source(
[
fm.Layer(
id='point-layer',
layerProps={
'type': 'circle',
'layout': {},
'paint': {
'circle-color': 'white',
'circle-radius': 5
}
}
),
fm.Layer(
id='point-text-layer',
layerProps={
'type': 'symbol',
'layout': {
'text-field': '{字段1}\n{字段2}',
'text-size': 18,
'text-font': [],
'text-allow-overlap': True
},
'paint': {
'text-color': 'white',
'text-halo-color': '#000000',
'text-halo-width': 3
}
}
)
],
id='point-source',
sourceProps={
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [-5, 0]
},
'properties': {
'字段1': '落霞与孤鹜齐飞',
'字段2': '秋水共长天一色'
}
}
]
}
}
),
# 线要素示例
fm.Source(
[
fm.Layer(
id='line-layer',
layerProps={
'type': 'line',
'layout': {},
'paint': {
'line-color': 'white',
'line-width': 3
}
}
),
fm.Layer(
id='line-text-layer',
layerProps={
'type': 'symbol',
'layout': {
'text-field': '{字段1} {字段2}',
'text-size': 18,
'text-font': [],
'symbol-placement': 'line',
'symbol-spacing': 10
},
'paint': {
'text-color': 'white',
'text-halo-color': '#000000',
'text-halo-width': 3
}
}
)
],
id='line-source',
sourceProps={
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'LineString',
'coordinates': [
[
i,
np.sin(i)
]
for i in np.arange(0, 10, 0.1)
]
},
'properties': {
'字段1': '落霞与孤鹜齐飞',
'字段2': '秋水共长天一色'
}
}
]
}
}
),
# 面要素示例
fm.Source(
[
fm.Layer(
id='polygon-layer',
layerProps={
'type': 'fill',
'layout': {},
'paint': {
'fill-color': '#f5f5f5',
'fill-opacity': 0.5
}
}
),
fm.Layer(
id='polygon-text-layer',
layerProps={
'type': 'symbol',
'layout': {
'text-field': '{字段1} {字段2}',
'text-size': 18,
'text-font': [],
'symbol-spacing': 75
},
'paint': {
'text-color': 'white',
'text-halo-color': '#000000',
'text-halo-width': 3
}
}
)
],
id='polygon-source',
sourceProps={
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': [
[
[-4, -2],
[-4, -4],
[-2, -4],
[-2, -2],
[-4, -2]
]
]
},
'properties': {
'字段1': '落霞与孤鹜齐飞',
'字段2': '秋水共长天一色'
}
}
]
}
}
)
],
initialViewState={
'zoom': 6,
'longitude': 2
},
style={
'height': '100%',
'position': 'absolute'
},
mapStyle={
'version': 8,
'sources': {},
'layers': [],
'glyphs': 'http://127.0.0.1:3000/font/{fontstack}/{range}'
}
)
],
style={
'height': '100vh',
'position': 'relative'
}
)
@app.callback(
[Output('point-text-layer', 'layerProps'),
Output('line-text-layer', 'layerProps'),
Output('polygon-text-layer', 'layerProps')],
Input('font-select', 'value')
)
def update_font(value):
p = Patch()
p['layout']['text-font'] = [value]
return [p] * 3
if __name__ == '__main__':
app.run(debug=False)