-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
804 lines (747 loc) · 18.6 KB
/
provider.go
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"regexp"
"strconv"
"strings"
"github.com/BurntSushi/toml"
"github.com/gin-gonic/gin"
"github.com/go-spatial/geom"
"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/tegola/atlas"
"github.com/go-spatial/tegola/config"
"github.com/go-spatial/tegola/dict"
"github.com/go-spatial/tegola/mapbox/tilejson"
aprd "github.com/go-spatial/tegola/provider"
"github.com/go-spatial/tegola/server"
"github.com/jinzhu/gorm"
log "github.com/sirupsen/logrus"
)
//Provider 数据库驱动
type Provider struct {
ID string `json:"id" toml:"id" gorm:"primaryKey"`
Name string `json:"name" toml:"name" binding:"required"`
Type string `json:"type" toml:"type"`
Owner string `json:"owner" toml:"owner,omitempty" gorm:"index"`
Host string `json:"host" toml:"host" binding:"required"`
Port int `json:"port" toml:"port" binding:"required"`
User string `json:"user" toml:"user" binding:"required"`
Password string `json:"password" toml:"password" binding:"required"`
Database string `json:"database" toml:"database" binding:"required"`
SRID int `json:"srid" toml:"srid" binding:"required" gorm:"column:srid"`
MaxConnections int `json:"maxConnections" toml:"max_connections,omitempty"`
}
func toDicter(v interface{}) (dict.Dicter, error) {
//借用config的providers解析
type envDict struct {
Providers []interface{} `toml:"providers"`
}
prds := envDict{[]interface{}{v}}
var buf bytes.Buffer
err := toml.NewEncoder(&buf).Encode(prds)
if err != nil {
return nil, fmt.Errorf("参数编码失败")
}
cc, err := config.Parse(&buf, "")
if err != nil {
return nil, fmt.Errorf("config parse error")
}
return cc.Providers[0], nil
}
// RegisterProvider register data provider backends
func RegisterProvider(prd *Provider) (aprd.TilerUnion, error) {
// holder for registered providers
// check if a provider with this name is already registered
p, ok := providers[prd.ID]
if ok {
return p, fmt.Errorf("驱动已存在")
}
if prd.Type == "" {
return p, fmt.Errorf("类型必须指定")
}
cfg, err := toDicter(prd)
if err != nil {
return p, fmt.Errorf("参数有误")
}
// register the provider
prov, err := aprd.For(prd.Type, cfg)
if err != nil {
return p, err
}
// add the provider to our map of registered providers
providers[prd.ID] = prov
log.Infof("registering provider(type): %v (%v)", prd.Name, prd.Type)
//最后保存
err = prd.UpInsert()
return prov, err
}
//UpInsert 创建更新样式存储
//create or update upload data file info into database
func (prd *Provider) UpInsert() error {
tmp := &Provider{}
err := db.Where("id = ?", prd.ID).First(tmp).Error
if err != nil {
if gorm.IsRecordNotFoundError(err) {
err = db.Create(prd).Error
if err != nil {
return err
}
}
return err
}
err = db.Model(&Provider{}).Update(prd).Error
if err != nil {
return err
}
return nil
}
//ProviderLayer 驱动图层
type ProviderLayer struct {
ID string `json:"id" toml:"id" gorm:"primaryKey"`
ProviderID string `json:"providerId" toml:"providerId" binding:"required"`
Name string `json:"name" toml:"name" binding:"required"`
TabLeName string `json:"tablename" toml:"tablename"`
SQL string `json:"sql" toml:"sql,omitempty"`
SRID int `json:"srid" toml:"srid,omitempty" gorm:"column:srid"`
GeomField string `json:"geomField" toml:"geometry_fieldname,omitempty"`
IDField string `json:"idField" toml:"id_fieldname,omitempty"`
Fields string `json:"fields" toml:"fields,omitempty"`
GeomType string `json:"geomType" toml:"geometry_type,omitempty"`
Type string `json:"-" toml:"type,omitempty" gorm:"-"`
Provider aprd.TilerUnion `json:"-" toml:"-" gorm:"-"`
}
//UpInsert 创建更新vtlayer
func (prdLyr *ProviderLayer) UpInsert() error {
tmp := &ProviderLayer{}
err := db.Where("id = ?", prdLyr.ID).First(tmp).Error
if err != nil {
if gorm.IsRecordNotFoundError(err) {
err = db.Create(prdLyr).Error
if err != nil {
return err
}
}
return err
}
err = db.Model(&ProviderLayer{}).Update(prdLyr).Error
if err != nil {
return err
}
return nil
}
// RegisterProviderLayer xxx
func RegisterProviderLayer(player *ProviderLayer) error {
prd, ok := providers[player.ProviderID]
if !ok {
//查找库表
newPrd := &Provider{}
if err := db.Where("id = ?", player.ProviderID).First(newPrd).Error; err != nil {
if !gorm.IsRecordNotFoundError(err) {
return err
}
return fmt.Errorf("%s", MsgList[40410])
}
var err error
prd, err = RegisterProvider(newPrd)
if err != nil {
return err
}
}
if prd.Std != nil {
player.Type = "postgis"
} else if prd.Mvt != nil {
player.Type = "mvt_postgis"
}
err := validPLConsqlfig(player)
if err != nil {
return err
}
//provider内部使用name作为id
cfg, err := toDicter(player)
if err != nil {
return err
}
err = prd.AddLayer(cfg)
if err != nil {
return err
}
return nil
}
func validPLConsqlfig(player *ProviderLayer) error {
if player == nil {
return fmt.Errorf("player is nil")
}
if player.SQL != "" {
rgx := regexp.MustCompile(`(?i)ST_AsMVTGeom`)
if rgx.MatchString(player.SQL) && player.Type != "mvt_postgis" {
return fmt.Errorf(`检测到指定了mvtsql语句,但layer的类型不是'mvt_postgis'`)
}
}
return nil
}
//AutoMap4ProviderLayer 为ProviderLayer自动创建atlasmap
func AutoMap4ProviderLayer(plyrID string) error {
player := &ProviderLayer{ID: plyrID}
dbres := db.Find(player)
if dbres.Error != nil {
log.Warnf(`get prdLayer error, prdlayer(%s) not found ^^`, plyrID)
return dbres.Error
}
prd, ok := providers[player.ProviderID]
if !ok {
newPrd := &Provider{}
if err := db.Where("id = ?", player.ProviderID).First(newPrd).Error; err != nil {
if !gorm.IsRecordNotFoundError(err) {
return err
}
return fmt.Errorf("%s", MsgList[40410])
}
var err error
prd, err = RegisterProvider(newPrd)
if err != nil {
return err
}
}
//若内部图层不存在,则需注册图层
plyr, ok := prd.Layer(plyrID)
if !ok {
err := RegisterProviderLayer(player)
if err != nil {
return err
}
log.Infof("重新注册内部驱动图层%s", plyr.ID())
}
//map name 就是mapid
bbox, _ := prd.LayerExtent(plyrID)
// minzoom := 0
// maxzoom := 14
minzoom := prd.LayerMinZoom(plyrID)
maxzoom := prd.LayerMaxZoom(plyrID)
bounds := fmt.Sprintf("[%f,%f,%f,%f]", bbox.MinX(), bbox.MinY(), bbox.MaxX(), bbox.MaxY())
min := bbox.Min()
max := bbox.Max()
cx := (min[0] + max[0]) / 2
cy := (min[1] + max[1]) / 2
center := fmt.Sprintf("[%f,%f,%.1f]", cx, cy, float64(maxzoom))
mapconf := fmt.Sprintf(`
[[maps]]
name = "%s"
bounds = %s
center = %s
attribution = "auto generate from provider layer"
[[maps.layers]]
id = "%s"
name = "%s"
provider_layer = "%s.%s"
min_zoom = %d
max_zoom = %d`,
plyrID, bounds, center, player.ID, player.Name, player.ProviderID, player.ID, minzoom, maxzoom)
autocfg, err := config.Parse(strings.NewReader(mapconf), "")
if err != nil {
return err
}
err = registerMaps(nil, autocfg.Maps, providers)
if err != nil {
return err
}
log.Info(` auto register map(%s) of vtlyr(%s) ^^`, plyrID, player.ID)
return nil
}
func drivers(c *gin.Context) {
resp := NewRes()
err := db.DB().Ping()
if err != nil {
resp.FailErr(c, err)
return
}
type Driver struct {
Name string
Type string
Version string
}
var drivers = []Driver{
{
"mvt_postgis",
"mvt_postgis",
"v2.4+",
},
{
"postgis",
"postgis",
"^v2.4",
}}
resp.DoneData(c, drivers)
}
//listProviders 获取数据库驱动列表
func listProviders(c *gin.Context) {
resp := NewResp()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
if uid == "" {
uid = ATLAS
}
var providers []Provider
err := db.Find(&providers).Error
if err != nil {
resp.Fail(c, 5001)
return
}
resp.DoneData(c, providers)
}
//registerProvider 注册数据库驱动,驱动不允许更新的?
func registerProvider(c *gin.Context) {
resp := NewResp()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
if uid == "" {
uid = ATLAS
}
provider := &Provider{}
err := c.Bind(provider)
if err != nil {
log.Error(err)
resp.Fail(c, 4001)
return
}
if "" != provider.ID {
if err := db.Where("id = ?", provider.ID).First(&Provider{}).Error; err != nil {
if !gorm.IsRecordNotFoundError(err) {
log.Error(err)
resp.Fail(c, 5001)
return //数据库错误
}
//没找到,继续正常逻辑
} else {
//找到了,id重复,则直接返回id重复
resp.FailMsg(c, "驱动id重复,请使用更新接口更新驱动信息,不传id后台会自动生成驱动id并返回")
return
}
} else {
//id为空,注册新的驱动并返回id
provider.ID = ShortID()
}
if provider.Type == "" {
provider.Type = "mvt_postgis"
}
if provider.MaxConnections == 0 {
provider.MaxConnections = 100
}
_, err = RegisterProvider(provider)
if err != nil {
log.Error(err)
resp.FailMsg(c, err.Error())
return
}
resp.DoneData(c, gin.H{
"id": provider.ID,
})
return
}
//getProviderInfo 获取数据库驱动列表
func getProviderInfo(c *gin.Context) {
resp := NewResp()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
if uid == "" {
uid = ATLAS
}
sid := c.Param("id")
prov := &Provider{}
if err := db.Where("id = ?", sid).First(prov).Error; err != nil {
if !gorm.IsRecordNotFoundError(err) {
log.Error(err)
resp.Fail(c, 5001)
}
resp.Fail(c, 40410)
return
}
resp.DoneData(c, prov)
}
//updateProviderInfo 更新指定数据库驱动
func updateProviderInfo(c *gin.Context) {
resp := NewResp()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
if uid == "" {
uid = ATLAS
}
id := c.Param("id")
type bind struct {
Name string `json:"name"`
User string `json:"user"`
Password string `json:"password"`
MaxConnections int `json:"maxConnections"`
}
prd := &bind{}
err := c.Bind(prd)
if err != nil {
log.Error(err)
resp.Fail(c, 4001)
return
}
if prd.MaxConnections < 0 || prd.MaxConnections > 1024 {
resp.FailMsg(c, "最大连接数可以按照实际情况设置为(0,1024]之间的任意整数")
return
}
// 更新insertUser
dbres := db.Model(Provider{}).Where("id = ?", id).Update(prd)
if dbres.Error != nil {
log.Error(err)
resp.Fail(c, 5001)
return
}
resp.DoneData(c, gin.H{
"affected": dbres.RowsAffected,
})
return
}
//deleteProvider 删除指定数据库
func deleteProvider(c *gin.Context) {
resp := NewResp()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
if uid == "" {
uid = ATLAS
}
ids := c.Param("ids")
sids := strings.Split(ids, ",")
dbres := db.Where("id in (?)", sids).Delete(Provider{})
if dbres.Error != nil {
log.Error(dbres.Error)
resp.Fail(c, 5001)
return
}
resp.DoneData(c, gin.H{
"affected": dbres.RowsAffected,
})
}
//listProviderLayers 获取图层列表
func listProviderLayers(c *gin.Context) {
resp := NewResp()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
if uid == "" {
uid = ATLAS
}
pid := c.Query("pid")
var players []ProviderLayer
if pid != "" {
err := db.Where("provider_id = ?", pid).Find(&players).Error
if err != nil {
resp.Fail(c, 5001)
return
}
} else {
err := db.Find(&players).Error
if err != nil {
resp.Fail(c, 5001)
return
}
}
resp.DoneData(c, players)
}
//createProvider 注册数据库驱动
func createProviderLayer(c *gin.Context) {
resp := NewResp()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
if uid == "" {
uid = ATLAS
}
player := ProviderLayer{}
err := c.Bind(&player)
if err != nil {
log.Error(err)
resp.Fail(c, 4001)
return
}
player.ID = ShortID()
err = RegisterProviderLayer(&player)
if err != nil {
log.Error(err)
resp.FailMsg(c, err.Error())
return
}
err = player.UpInsert()
if err != nil {
log.Error(err)
resp.FailMsg(c, err.Error())
return
}
resp.DoneData(c, gin.H{
"id": player.ID,
})
return
}
//getProviderLayerInfo 获取数据库驱动列表
func getProviderLayerInfo(c *gin.Context) {
resp := NewResp()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
if uid == "" {
uid = ATLAS
}
lid := c.Param("id")
plry := &ProviderLayer{}
if err := db.Where("id = ?", lid).First(plry).Error; err != nil {
if !gorm.IsRecordNotFoundError(err) {
log.Error(err)
resp.Fail(c, 5001)
}
resp.Fail(c, 40411)
return
}
resp.DoneData(c, plry)
}
//updateProviderLayerInfo 更新指定数据库驱动层
func updateProviderLayerInfo(c *gin.Context) {
resp := NewResp()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
if uid == "" {
uid = ATLAS
}
id := c.Param("id")
plyr := &struct {
Name string `json:"name" `
SQL string `json:"sql"`
Fields string `json:"fields"`
}{}
err := c.Bind(plyr)
if err != nil {
log.Error(err)
resp.Fail(c, 4001)
return
}
// 更新insertUser
dbres := db.Model(ProviderLayer{}).Where("id = ?", id).Update(plyr)
if dbres.Error != nil {
log.Error(err)
resp.Fail(c, 5001)
return
}
resp.DoneData(c, gin.H{
"affected": dbres.RowsAffected,
})
return
}
//deleteProvider 删除指定数据库驱动层
func deleteProviderLayer(c *gin.Context) {
resp := NewResp()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
if uid == "" {
uid = ATLAS
}
ids := c.Param("ids")
sids := strings.Split(ids, ",")
dbres := db.Where("id in (?)", sids).Delete(ProviderLayer{})
if dbres.Error != nil {
log.Error(dbres.Error)
resp.Fail(c, 5001)
return
}
resp.DoneData(c, gin.H{
"affected": dbres.RowsAffected,
})
}
func getPrdLayerTileJSON(c *gin.Context) {
resp := NewRes()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
plyrid := c.Param("id")
if plyrid == "" {
resp.Fail(c, 4001)
return
}
amap, err := atlas.GetMap(plyrid)
if err != nil {
err = AutoMap4ProviderLayer(plyrid)
if err != nil {
resp.Fail(c, 4049)
return
}
amap, _ = atlas.GetMap(plyrid)
}
//get atlas map if not exist then create
//get atlas map tilejson
tileJSON := tilejson.TileJSON{
Attribution: &amap.Attribution,
Bounds: amap.Bounds.Extent(),
Center: amap.Center,
Format: "pbf",
Name: &amap.Name,
Scheme: tilejson.SchemeXYZ,
TileJSON: tilejson.Version,
Version: "2",
Grids: make([]string, 0),
Data: make([]string, 0),
}
// parse our query string
q := ""
if c.Query("debug") == "true" {
amap = amap.AddDebugLayers()
q = "?debug=true"
}
tileurl := fmt.Sprintf(`%s/vtlayers/x/%s/{z}/{x}/{y}%s`, rootURL(c.Request), plyrid, q)
// build our vector layer details
layer := tilejson.VectorLayer{
Version: 2,
Extent: 4096,
ID: amap.Layers[0].MVTName(),
Name: amap.Layers[0].MVTName(),
MinZoom: amap.Layers[0].MinZoom,
MaxZoom: amap.Layers[0].MaxZoom,
Tiles: []string{
tileurl,
},
}
tileJSON.MinZoom = amap.Layers[0].MinZoom
tileJSON.MaxZoom = amap.Layers[0].MaxZoom
switch amap.Layers[0].GeomType.(type) {
case geom.Point, geom.MultiPoint:
layer.GeometryType = tilejson.GeomTypePoint
case geom.Line, geom.LineString, geom.MultiLineString:
layer.GeometryType = tilejson.GeomTypeLine
case geom.Polygon, geom.MultiPolygon:
layer.GeometryType = tilejson.GeomTypePolygon
default:
layer.GeometryType = tilejson.GeomTypeUnknown
// TODO: debug log
}
// add our layer to our tile layer response
tileJSON.VectorLayers = append(tileJSON.VectorLayers, layer)
// build our URL scheme for the tile grid
tileJSON.Tiles = append(tileJSON.Tiles, tileurl)
// content type
c.Header("Content-Type", "application/json")
// cache control headers (no-cache)
c.Header("Cache-Control", "no-cache, no-store, must-revalidate")
c.Header("Pragma", "no-cache")
c.Header("Expires", "0")
if err := json.NewEncoder(c.Writer).Encode(tileJSON); err != nil {
log.Printf("error encoding tileJSON for layer (%v)", plyrid)
}
}
func getPrdLayerTiles(c *gin.Context) {
resp := NewRes()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
plryid := c.Param("id")
if plryid == "" {
resp.Fail(c, 4001)
return
}
//直接找map,找不到就塞一个进去,不存储tilelayer和tilemap
amap, err := atlas.GetMap(plryid)
if err != nil {
err = AutoMap4ProviderLayer(plryid)
if err != nil {
resp.Fail(c, 4049)
return
}
amap, _ = atlas.GetMap(plryid)
}
// lookup our Map
placeholder, _ := strconv.ParseUint(c.Param("z"), 10, 32)
z := uint(placeholder)
placeholder, _ = strconv.ParseUint(c.Param("x"), 10, 32)
x := uint(placeholder)
yext := c.Param("y")
ys := strings.Split(yext, ".")
if len(ys) != 2 {
// resp.Fail(c, 404)
// return
}
placeholder, _ = strconv.ParseUint(ys[0], 10, 32)
y := uint(placeholder)
//拷贝过滤新图层
// amap = amap.FilterLayersByZoom(z)
tile := slippy.NewTile(z, x, y)
pbyte, err := amap.Encode(c.Request.Context(), tile)
if err != nil {
switch err {
case context.Canceled:
// TODO: add debug logs
return
default:
errMsg := fmt.Sprintf("marshalling tile: %v", err)
log.Error(errMsg)
http.Error(c.Writer, errMsg, http.StatusInternalServerError)
return
}
}
// c.Header("Content-Type", mvt.MimeType)
c.Header("Content-Encoding", "gzip")
c.Header("Content-Type", "application/x-protobuf")
c.Header("Content-Length", fmt.Sprintf("%d", len(pbyte)))
c.Writer.WriteHeader(http.StatusOK)
c.Writer.Write(pbyte)
// check for tile size warnings
if len(pbyte) > server.MaxTileSize {
log.Infof("tile z:%v, x:%v, y:%v is rather large - %vKb", z, x, y, len(pbyte)/1024)
}
}
//prdLayerViewer 浏览服务集
func prdLayerViewer(c *gin.Context) {
resp := NewRes()
uid := c.GetString(userKey)
if uid == "" {
uid = c.GetString(identityKey)
}
plyrID := c.Param("id")
amap, err := atlas.GetMap(plyrID)
if err != nil {
err = AutoMap4ProviderLayer(plyrID)
if err != nil {
resp.Fail(c, 4049)
return
}
amap, _ = atlas.GetMap(plyrID)
}
prdlayer := &ProviderLayer{ID: plyrID}
dbres := db.Find(prdlayer)
if dbres.Error != nil {
log.Warnf(`get prdLayer error, prdlayer(%s) not found ^^`, plyrID)
resp.Fail(c, 4046)
return
}
tilejson := fmt.Sprintf(`%s/vtlayers/x/%s/`, rootURL(c.Request), plyrID) //need use user own service set//
c.HTML(http.StatusOK, "dataset.html", gin.H{
"Title": "服务集预览(T)",
"Name": prdlayer.Name + "@" + plyrID,
"Format": PBF,
"URL": tilejson,
"Zoom": amap.Layers[0].MaxZoom,
"Center": amap.Center,
})
return
}