Skip to content

Commit

Permalink
refactor, remove types package
Browse files Browse the repository at this point in the history
  • Loading branch information
cconcannon committed Oct 2, 2021
1 parent f86a43b commit c92bcb2
Show file tree
Hide file tree
Showing 15 changed files with 1,157 additions and 1,140 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ The [spec for `.czml` files seems to be maintained here.](https://github.com/Ana

## Use

### Import the Module

```
import (
...
"github.com/cconcannon/czml"
)
```

### Initialize a CZML data structure

`c := czml.CreateDocument("name")`
Expand Down Expand Up @@ -44,4 +54,4 @@ The documentation about value formats for many of the `.czml` properties, especi

## Contributing

Yes, please. I don't do development full-time so it might be a few days before I respond to PR's, but I really appreciate them! Feel free to fork and develop on your own, too... I'm releasing this with the MIT license very intentionally.
Yes, please.
27 changes: 27 additions & 0 deletions billboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package czml

// Billboard is a billboard, or viewport-aligned image. The billboard is positioned in the scene
// by the position property. A billboard is sometimes called a marker.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Billboard
type Billboard struct {
Show *bool `json:"show,omitempty"`
Image *Uri `json:"image,omitempty"`
Scale *float64 `json:"scale,omitempty"`
PixelOffset *PixelOffset `json:"pixelOffset,omitempty"`
EyeOffset *EyeOffset `json:"eyeOffset,omitempty"`
HorizontalOrigin *HorizontalOrigin `json:"horizontalOrigin,omitempty"`
VerticalOrigin *VerticalOrigin `json:"verticalOrigin,omitempty"`
HeightReference *HeightReference `json:"heightReference,omitempty"`
Color *Color `json:"color,omitempty"`
Rotation *float64 `json:"rotation,omitempty"`
AlignedAxis *AlignedAxis `json:"alignedAxis,omitempty"`
SizeInMeters *bool `json:"sizeInMeters,omitempty"`
Width *float64 `json:"width,omitempty"`
Height *float64 `json:"height,omitempty"`
ScaleByDistance *NearFarScaler `json:"scaleByDistance,omitempty"`
TranslucencyByDistance *NearFarScaler `json:"translucencyByDistance,omitempty"`
PixelOffsetScaleByDistance *NearFarScaler `json:"pixelOffsetScaleByDistance,omitempty"`
ImageSubRegion *BoundingRectangle `json:"imageSubRegion,omitempty"`
DistanceDisplayCondition *DistanceDisplayCondition `json:"distanceDisplayCondition,omitempty"`
DisableDepthTestDistance *float64 `json:"disableDepthTestDistance,omitempty"`
}
47 changes: 47 additions & 0 deletions cartesian.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package czml

// Cartesian2 is two-dimensional Cartesian value specified as [X, Y]. If the array has two elements,
// the value is constant. If it has three or more elements, they are time-tagged samples arranged as
// [Time, X, Y, Time, X, Y, ...], where Time is an ISO 8601 date and time string or seconds since
// epoch.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Cartesian2Value
type Cartesian2Value []float64

// Cartesian2ListValue is a list of two-dimensional Cartesian values specified as
// [X, Y, X, Y, ...].
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Cartesian2ListValue
type Cartesian2ListValue *[]float64

// Cartesian3Value is the position specified as a three-dimensional
// Cartesian value [X, Y, Z] in meters relative to the referenceFrame
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Cartesian3Value
type Cartesian3Value []float64

// Cartesian3VelocityValue is a three-dimensional Cartesian value and its derivative specified as
// [X, Y, Z, dX, dY, dZ]. If the array has six elements, the value is constant. If it has seven or
// more elements, they are time-tagged samples arranged as [Time, X, Y, Z, dX, dY, dZ, Time, X,...],
// where Time is an ISO 8601 date and time string or seconds since epoch.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Cartesian3VelocityValue
type Cartesian3VelocityValue []float64

// UnitCartesian3Value is a three-dimensional unit magnitude Cartesian value specified as [X, Y, Z].
// If the array has three elements, the value is constant. If it has four or more elements, they are
// time-tagged samples arranged as [Time, X, Y, Z, Time, X, Y, Z, ...], where Time is an ISO 8601
// date and time string or seconds since epoch.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/UnitCartesian3Value
type UnitCartesian3Value []interface{}

// UnitCartesian3ListValue is a list of three-dimensional unit magnitude Cartesian values,
// specified as [X, Y, Z, X, Y, Z, ...].
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/UnitCartesian3ListValue
type UnitCartesian3ListValue []interface{}

// Cartesian3ListValue is a list of three-dimensional Cartesian values specified as
// [X, Y, Z, X, Y, Z, ...].
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Cartesian3ListValue
type Cartesian3ListValue []float64

// Cartesian3ListOfListsValue is a list of lists of three-dimensional Cartesian values specified
// as [X, Y, Z, X, Y, Z, ...].
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Cartesian3ListOfListsValue
type Cartesian3ListOfListsValue []Cartesian3Value
53 changes: 53 additions & 0 deletions cartographic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package czml

// CartographicDegreesValue is a geodetic, WGS84 position specified as [Longitude, Latitude, Height]
// where Longitude and Latitude are in degrees and Height is in meters. If the array has three
// elements, the value is constant. If it has four or more elements, they are time-tagged samples
// arranged as [Time, Longitude, Latitude, Height, Time, Longitude, Latitude, Height, ...], where
// Time is an ISO 8601 date and time string or seconds since epoch
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/CartographicDegreesValue
type CartographicDegreesValue []float64

// CartographicRadiansValue is a geodetic, WGS84 position specified as [Longitude, Latitude, Height]
// where Longitude and Latitude are in radians and Height is in meters. If the array has three
// elements, the value is constant. If it has four or more elements, they are time-tagged samples
// arranged as [Time, Longitude, Latitude, Height, Time, Longitude, Latitude, Height, ...], where
// Time is an ISO 8601 date and time string or seconds since epoch
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/CartographicRadiansValue
type CartographicRadiansValue []float64

// CartographicRadiansListOfListsValue is a list of lists of geodetic, WGS84 positions specified as
// [Longitude, Latitude, Height, Longitude, Latitude, Height, ...], where Longitude and Latitude are
// in radians and Height is in meters.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/CartographicRadiansListOfListsValue
type CartographicRadiansListOfListsValue []CartographicRadiansValue

// CartographicDegreesListOfListsValue is a list of lists of geodetic, WGS84 positions specified as
// [Longitude, Latitude, Height, Longitude, Latitude, Height, ...], where Longitude and Latitude are
// in degrees and Height is in meters.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/CartographicDegreesListOfListsValue
type CartographicDegreesListOfListsValue []CartographicDegreesValue

// CartographicRectangleRadiansValue is a two-dimensional region specified as [WestLongitude,
// SouthLatitude, EastLongitude, NorthLatitude], with values in radians. If the array has four
// elements, the value is constant. If it has five or more elements, they are time-tagged samples
// arranged as [Time, WestLongitude, SouthLatitude, EastLongitude, NorthLatitude, Time,
// WestLongitude, SouthLatitude, EastLongitude, NorthLatitude, ...], where Time is an ISO 8601 date
// and time string or seconds since epoch.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/CartographicRectangleRadiansValue
type CartographicRectangleRadiansValue []interface{}

// CartographicRectangleDegreesValue is a two-dimensional region specified as [WestLongitude,
// SouthLatitude, EastLongitude, NorthLatitude], with values in degrees. If the array has four
// elements, the value is constant. If it has five or more elements, they are time-tagged samples
// arranged as [Time, WestLongitude, SouthLatitude, EastLongitude, NorthLatitude, Time,
// WestLongitude, SouthLatitude, EastLongitude, NorthLatitude, ...], where Time is an ISO 8601 date
// and time string or seconds since epoch.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/CartographicRectangleDegreesValue
type CartographicRectangleDegreesValue []interface{}

// CartographicRadiansListValue is a list of geodetic, WGS84 positions specified as
// [Longitude, Latitude, Height, Longitude, Latitude, Height, ...], where Longitude and Latitude
// are in radians and Height is in meters.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/CartographicRadiansListValue
type CartographicRadiansListValue []float64
25 changes: 25 additions & 0 deletions color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package czml

// Color describes a color. The color can optionally vary over time
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Color
type Color struct {
Rgba RgbaValue `json:"rgba,omitempty"`
Rgbaf RgbafValue `json:"rgbaf,omitempty"`
Reference ReferenceValue `json:"reference,omitempty"`
}

// RgbaValue is a color specified as an array of color components [Red, Green, Blue, Alpha] where
// each component is in the range 0-255. If the array has four elements, the color is constant. If
// it has five or more elements, they are time-tagged samples arranged as [Time, Red, Green, Blue,
// Alpha, Time, Red, Green, Blue, Alpha, ...], where Time is an ISO 8601 date and time string or
// seconds since epoch.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/RgbaValue
type RgbaValue []int

// RgbafValue is a color specified as an array of color components [Red, Green, Blue, Alpha] where
// each component is in the range 0.0-1.0. If the array has four elements, the color is constant.
// If it has five or more elements, they are time-tagged samples arranged as [Time, Red, Green,
// Blue, Alpha, Time, Red, Green, Blue, Alpha, ...], where Time is an ISO 8601 date and time string
// or seconds since epoch.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/RgbafValue
type RgbafValue []float32
34 changes: 12 additions & 22 deletions czml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ package czml

import (
"encoding/json"
"errors"

"github.com/cconcannon/czml/types"
)

// Czml is a .czml file, which is a valid JSON document that contains an array of packets
type Document struct {
Packets []types.Packet
type Czml struct {
Packets []Packet
}

// Unmarshal accepts raw byte data (i.e. a .czml file) and returns
Expand All @@ -20,35 +17,28 @@ func Unmarshal(data []byte, v interface{}) error {

// Marshal accepts a name for the document and a Packet array,
// and returns the Marshaled czml data
func Marshal(d Document) ([]byte, error) {
if d.Packets[0].Id != "document" {
return nil, errors.New("the first packet is not the \"document\" packet")
}
return json.Marshal(d.Packets)
func Marshal(c Czml) ([]byte, error) {
return json.Marshal(c.Packets)
}

// MarshalIndent accepts a name for the document, a Packet array,
// a prefix string, and an indentation string, and returns the
// Marshaled and Indented czml data
func MarshalIndent(d Document, prefix, indent string) ([]byte, error) {
if d.Packets[0].Id != "document" {
return nil, errors.New("the first packet is not the \"document\" packet")
}
return json.MarshalIndent(&d.Packets, prefix, indent)
func MarshalIndent(c Czml, prefix, indent string) ([]byte, error) {
return json.MarshalIndent(&c.Packets, prefix, indent)
}

// CreateDocument initializes .czml file data with the "document" packet as the first packet
func CreateDocument(name string) Document {
var packet types.Packet
// CreateCzml initializes .czml file data with the "document" packet as the first packet
func CreateCzml(name string) Czml {
var packet Packet
packet.Id = "document"
packet.Name = name
packet.Version = "1.0"

return Document{[]types.Packet{packet}}
return Czml{[]Packet{packet}}
}

// AddPacket adds a Packet to the .czml document data
func (d *Document) AddPacket(p types.Packet) error {
d.Packets = append(d.Packets, p)
return nil
func (c *Czml) AddPacket(p Packet) {
c.Packets = append(c.Packets, p)
}
59 changes: 59 additions & 0 deletions label.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package czml

// Label is a string of text
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Label
type Label struct {
Show *bool `json:"show,omitempty"`
Text string `json:"text,omitempty"`
Font *Font `json:"font,omitempty"`
Style *LabelStyle `json:"style,omitempty"`
Scale *float64 `json:"scale,omitempty"`
ShowBackground *bool `json:"showBackground,omitempty"`
BackgroundColor *Color `json:"backgroundColor,omitempty"`
BackgroundPadding *BackgroundPadding `json:"backgroundPadding,omitempty"`
PixelOffset *PixelOffset `json:"pixelOffset,omitempty"`
EyeOffset *EyeOffset `json:"eyeOffset,omitempty"`
HorizontalOrigin *HorizontalOrigin `json:"horizontalOrigin,omitempty"`
VerticalOrigin *VerticalOrigin `json:"verticalOrigin,omitempty"`
HeightReference *HeightReference `json:"heightReference,omitempty"`
FillColor *Color `json:"fillColor,omitempty"`
OutlineColor *Color `json:"outlineColor,omitempty"`
OutlineWidth *float64 `json:"outlineWidth,omitempty"`
TranslucencyByDistance *NearFarScaler `json:"translucencyByDistance,omitempty"`
PixelOffsetScaleByDistance *NearFarScaler `json:"pixelOffsetScaleByDistance,omitempty"`
ScaleByDistance *NearFarScaler `json:"scaleByDistance,omitempty"`
DistanceDisplayCondition *DistanceDisplayCondition `json:"distanceDisplayCondition,omitempty"`
DisableDepthTestDistance *float64 `json:"disableDepthTestDistance,omitempty"`
}

// BackgroundPadding describes the amount of horizontal and vertical padding, in pixels, between a
// label's text and its background.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/BackgroundPadding
type BackgroundPadding struct {
Cartesian2 *Cartesian2Value `json:"cartesian2,omitempty"`
Reference ReferenceValue `json:"reference,omitempty"`
}

// Font describes a font used to draw text. Fonts are specified using the same syntax as the CSS
// "font" property.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Font
type Font struct {
Font FontValue `json:"font,omitempty"`
Reference ReferenceValue `json:"reference,omitempty"`
}

// FontValue is a font, specified using the same syntax as the CSS "font" property.
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/FontValue
type FontValue string

// LabelStyle describes the style of a label
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/LabelStyle
type LabelStyle struct {
LabelStyle LabelStyleValue `json:"labelStyle,omitempty"`
Reference ReferenceValue `json:"reference,omitempty"`
}

// LabelStyleValue is the style of a label
// valid values are `FILL`, `OUTLINE`, and `FILL_AND_OUTLINE`
// https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/LabelStyleValue
type LabelStyleValue string
Loading

0 comments on commit c92bcb2

Please sign in to comment.