Skip to content

Commit 2465f56

Browse files
author
thisisaaronland
committed
draw all source features, improved styling
1 parent 0edb34a commit 2465f56

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

cmd/point-in-polygon/main.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"log/slog"
88
"syscall/js"
99
"time"
10-
10+
1111
"github.com/paulmach/orb/geojson"
1212
"github.com/whosonfirst/go-whosonfirst-spatial/database"
13-
"github.com/whosonfirst/go-whosonfirst-spatial/query"
13+
"github.com/whosonfirst/go-whosonfirst-spatial/query"
1414
)
1515

1616
func PointInPolygonFunc() js.Func {
@@ -19,20 +19,20 @@ func PointInPolygonFunc() js.Func {
1919

2020
fc_str := args[0].String()
2121
q_str := args[1].String()
22-
22+
2323
handler := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
2424

2525
resolve := args[0]
2626
reject := args[1]
2727

2828
t1 := time.Now()
2929

30-
defer func(){
30+
defer func() {
3131
slog.Info("Time to perform point-in-polygon query", "time", time.Since(t1))
3232
}()
33-
33+
3434
ctx := context.Background()
35-
35+
3636
var spatial_q *query.SpatialQuery
3737

3838
err := json.Unmarshal([]byte(q_str), &spatial_q)
@@ -42,7 +42,7 @@ func PointInPolygonFunc() js.Func {
4242
reject.Invoke(fmt.Sprintf("Failed to unmarshal spatial query, %w", err))
4343
return nil
4444
}
45-
45+
4646
if spatial_q.Geometry == nil {
4747
slog.Error("Missing geometry in spatial query")
4848
reject.Invoke(fmt.Sprintf("Missing geometry"))
@@ -64,7 +64,7 @@ func PointInPolygonFunc() js.Func {
6464
}
6565

6666
db, err := database.NewSpatialDatabase(ctx, "rtree://")
67-
67+
6868
if err != nil {
6969
slog.Error("Failed to create spatial database", "error", err)
7070
reject.Invoke(fmt.Sprintf("Failed to create new database, w", err))
@@ -73,9 +73,9 @@ func PointInPolygonFunc() js.Func {
7373

7474
slog.Info("Index features", "count", len(fc.Features))
7575
t2 := time.Now()
76-
76+
7777
for offset, f := range fc.Features {
78-
78+
7979
enc_f, _ := f.MarshalJSON()
8080
err := db.IndexFeature(ctx, enc_f)
8181

@@ -108,7 +108,7 @@ func PointInPolygonFunc() js.Func {
108108
}
109109

110110
slog.Info("Time to PIP", "time", time.Since(t3))
111-
111+
112112
enc, err := json.Marshal(rsp)
113113

114114
if err != nil {
-48 KB
Loading

www/javascript/sfomuseum.spatial.wasm.init.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,28 @@ sfomuseum.golang.wasm.fetch("wasm/point_in_polygon.wasm").then((rsp) => {
135135

136136
var osm_layer = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png');
137137
osm_layer.addTo(map);
138+
139+
var source_layer = L.geoJSON(source_data, {
140+
style: {
141+
"color": "#000",
142+
"weight": 1,
143+
"opacity": 1,
144+
"fillColor": "#00308F",
145+
"fillOpacity": 0.2
146+
}
147+
});
148+
source_layer.addTo(map);
149+
150+
var feature_layer = L.geoJSON(map_fc, {
151+
style: {
152+
"color": "#fff",
153+
"weight": 2,
154+
"opacity": 1,
155+
"fillColor": "#ff69b4",
156+
"fillOpacity": 0.3
157+
}
158+
});
138159

139-
var feature_layer = L.geoJSON(map_fc);
140160
feature_layer.addTo(map);
141161

142162
var lat = parseFloat(lat_el.value);

0 commit comments

Comments
 (0)