The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/services/store/kind/geojson/summary.go

59 lines
1.3 KiB

package geojson
import (
"context"
"encoding/json"
"fmt"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/store"
)
func GetObjectKindInfo() models.ObjectKindInfo {
return models.ObjectKindInfo{
ID: models.StandardKindGeoJSON,
Name: "GeoJSON",
Description: "JSON formatted spatial data",
FileExtension: ".geojson",
MimeType: "application/json",
}
}
// Very basic geojson validator
func GetObjectSummaryBuilder() models.ObjectSummaryBuilder {
return func(ctx context.Context, uid string, body []byte) (*models.ObjectSummary, []byte, error) {
var geojson map[string]interface{}
err := json.Unmarshal(body, &geojson)
if err != nil {
return nil, nil, err
}
ftype, ok := geojson["type"].(string)
if !ok {
return nil, nil, fmt.Errorf("missing type")
}
body, err = json.Marshal(geojson)
if err != nil {
return nil, nil, err
}
summary := &models.ObjectSummary{
Kind: models.StandardKindGeoJSON,
Name: store.GuessNameFromUID(uid),
UID: uid,
Fields: map[string]interface{}{
"type": ftype,
},
}
if ftype == "FeatureCollection" {
features, ok := geojson["features"].([]interface{})
if ok {
summary.Fields["count"] = len(features)
}
}
return summary, body, nil
}
}