Skip to content

Commit

Permalink
support for dynamic point styles in builtin viewer. fixed polygon col…
Browse files Browse the repository at this point in the history
…ors not being shown in builtin layer viewer toggle. closes #146
  • Loading branch information
ARolek committed Sep 13, 2017
1 parent 10db7ef commit fd1dc91
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 21 deletions.
2 changes: 2 additions & 0 deletions mapbox/style/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type LayerPaint struct {
FillColor string `json:"fill-color,omitempty"`
FillOutlineColor string `json:"fill-outline-color,omitempty"`
FillOpacity uint8 `json:"fill-opacity,omitempty"`
CircleRadius uint8 `json:"circle-radius,omitempty"`
CircleColor string `json:"circle-color,omitempty"`
}

const (
Expand Down
3 changes: 1 addition & 2 deletions mapbox/style/transition.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package style

type Transition struct {
}
type Transition struct{}
18 changes: 9 additions & 9 deletions server/bindata_assetfs.go

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions server/handle_map_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ func (req HandleMapStyle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// chose our paint type based on the geometry type
switch l.GeomType.(type) {
case tegola.Point, tegola.Point3, tegola.MultiPoint:
layer.Type = style.LayerTypeLine
layer.Type = style.LayerTypeCircle
layer.Paint = &style.LayerPaint{
LineColor: stringToColorHex(l.Name),
CircleRadius: 3,
CircleColor: stringToColorHex(l.Name),
}
case tegola.LineString, tegola.MultiLine:
layer.Type = style.LayerTypeLine
Expand Down
107 changes: 107 additions & 0 deletions server/handle_map_style_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package server_test

import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"reflect"
"testing"

"github.com/dimfeld/httptreemux"
"github.com/terranodo/tegola/mapbox/style"
"github.com/terranodo/tegola/server"
)

func TestHandleMapStyle(t *testing.T) {
// config params this test relies on
server.HostName = serverHostName

// setup a new provider
testcases := []struct {
handler http.Handler
uri string
uriPattern string
reqMethod string
expected style.Root
}{
{
handler: server.HandleMapStyle{},
uri: fmt.Sprintf("/maps/%v/style.json", testMap.Name),
uriPattern: "/maps/:map_name/style.json",
reqMethod: "GET",
expected: style.Root{
Name: testMap.Name,
Version: style.Version,
Center: [2]float64{testMap.Center[0], testMap.Center[1]},
Zoom: testMap.Center[2],
Sources: map[string]style.Source{
testMap.Name: style.Source{
Type: style.SourceTypeVector,
URL: fmt.Sprintf("http://%v/capabilities/%v.json", serverHostName, testMap.Name),
},
},
Layers: []style.Layer{
{
ID: testLayer1.Name,
Source: testMap.Name,
SourceLayer: testLayer1.Name,
Type: style.LayerTypeCircle,
Layout: &style.LayerLayout{
Visibility: "visible",
},
Paint: &style.LayerPaint{
CircleRadius: 3,
CircleColor: "#7a40ce",
},
},
{
ID: testLayer2.Name,
Source: testMap.Name,
SourceLayer: testLayer2.Name,
Type: style.LayerTypeLine,
Layout: &style.LayerLayout{
Visibility: "visible",
},
Paint: &style.LayerPaint{
LineColor: "#7b40ce",
},
},
},
},
},
}

for i, tc := range testcases {
var err error

// setup a new router. this handles parsing our URL wildcards (i.e. :map_name, :z, :x, :y)
router := httptreemux.New()
// setup a new router group
group := router.NewGroup("/")
group.UsingContext().Handler(tc.reqMethod, tc.uriPattern, tc.handler)

r, err := http.NewRequest(tc.reqMethod, tc.uri, nil)
if err != nil {
t.Errorf("test case (%v) failed: %v", i, err)
continue
}

w := httptest.NewRecorder()
router.ServeHTTP(w, r)

if w.Code != http.StatusOK {
t.Errorf("test case (%v). handler returned wrong status code: got (%v) expected (%v)", i, w.Code, http.StatusOK)
}

var output style.Root
if err = json.NewDecoder(w.Body).Decode(&output); err != nil {
t.Errorf("test case (%v) failed: %v", i, err)
continue
}

if !reflect.DeepEqual(output, tc.expected) {
t.Errorf("test case (%v) failed. output \n\n %+v \n\n does not match expected \n\n %+v", i, output, tc.expected)
}
}
}
9 changes: 7 additions & 2 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"github.com/terranodo/tegola/server"
)

// test server config
const (
httpPort = ":8080"
serverVersion = "0.3.0"
httpPort = ":8080"
serverVersion = "0.4.0"
serverHostName = "tegola.io"
)

type testMVTProvider struct{}
Expand All @@ -39,6 +41,7 @@ var testLayer1 = server.Layer{
MinZoom: 4,
MaxZoom: 9,
Provider: &testMVTProvider{},
GeomType: basic.Point{},
DefaultTags: map[string]interface{}{
"foo": "bar",
},
Expand All @@ -49,6 +52,7 @@ var testLayer2 = server.Layer{
MinZoom: 10,
MaxZoom: 20,
Provider: &testMVTProvider{},
GeomType: basic.Line{},
DefaultTags: map[string]interface{}{
"foo": "bar",
},
Expand Down Expand Up @@ -84,6 +88,7 @@ func (l layer) SRID() int {

func init() {
server.Version = serverVersion
server.HostName = serverHostName

// register a map with layers
if err := server.RegisterMap(testMap); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions server/static/css/tegola.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ body, html {
color: #eee;
}
.btn .dot{
border-radius:5px;
width:9px;
height:9px;
border-radius:2px;
width:8px;
height:8px;
display:inline-block;
background-color:#333;
margin-right: 6px;
Expand Down
10 changes: 7 additions & 3 deletions server/static/js/tegola.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ var app = new Vue({
layers: []
};

var layers = maps[i].layers
var layers = maps[i].layers;
// iterate our map layers
for (var j=0, l=layers.length; j<l; j++){
var color = this.map.getPaintProperty(layers[j].name, 'line-color') ||
this.map.getPaintProperty(layers[j].name, 'fill-outline-color') ||
this.map.getPaintProperty(layers[j].name, 'circle-color');

mapItem.layers.push({
name: layers[j].name,
visibility: this.map.getLayoutProperty(layers[j].name, 'visibility') === 'visible' ? 'visible' : 'hidden',
color: this.map.getPaintProperty(layers[j].name, 'line-color')
})
color: color
});
}
mapsList.push(mapItem);
}
Expand Down

0 comments on commit fd1dc91

Please sign in to comment.