Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
fix(server): remove topojson api from govpolygon
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Mar 7, 2024
1 parent c3ae4d4 commit 8b63eb0
Showing 1 changed file with 0 additions and 24 deletions.
24 changes: 0 additions & 24 deletions server/govpolygon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/labstack/echo/v4/middleware"
"github.com/reearth/reearthx/log"
"github.com/reearth/reearthx/util"
"github.com/rubenv/topojson"
)

const dirpath = "govpolygondata"
Expand All @@ -30,7 +29,6 @@ type Handler struct {
httpClient *http.Client
lock sync.RWMutex
geojson []byte
topojson []byte
updateIfNotExists bool
updatedAt time.Time
}
Expand All @@ -47,7 +45,6 @@ func New(gqlEndpoint string, updateIfNotExists bool) *Handler {
func (h *Handler) Route(g *echo.Group) *Handler {
g.Use(middleware.CORS(), middleware.Gzip())
g.GET("/plateaugovs.geojson", h.GetGeoJSON)
g.GET("/plateaugovs.topojson", h.GetTeopoJSON)
// g.GET("/update", h.Update, errorLogger)
return h
}
Expand All @@ -67,21 +64,6 @@ func (h *Handler) GetGeoJSON(c echo.Context) error {
return c.JSONBlob(http.StatusOK, h.geojson)
}

func (h *Handler) GetTeopoJSON(c echo.Context) error {
if h.updateIfNotExists && h.topojson == nil {
if err := h.Update(c); err != nil {
log.Errorfc(c.Request().Context(), "govpolygon: fail to init: %v", err)
}
}

h.lock.RLock()
defer h.lock.RUnlock()
if h.topojson == nil {
return c.JSON(http.StatusNotFound, "not found")
}
return c.JSONBlob(http.StatusOK, h.topojson)
}

func (h *Handler) Update(c echo.Context) error {
if !h.updatedAt.IsZero() && util.Now().Sub(h.updatedAt) < cahceDuration {
return nil
Expand Down Expand Up @@ -112,23 +94,17 @@ func (h *Handler) Update(c echo.Context) error {
log.Debugfc(context.Background(), "govpolygon: not found polygon: %v", notfound)
}

t := topojson.NewTopology(g, &topojson.TopologyOptions{})
geojsonj, err := json.Marshal(g)
if err != nil {
return fmt.Errorf("failed to marshal geojson: %w", err)
}
topojsonj, err := json.Marshal(t)
if err != nil {
return fmt.Errorf("failed to marshal topojson: %w", err)
}

if !initial {
h.lock.Lock()
defer h.lock.Unlock()
}

h.geojson = geojsonj
h.topojson = topojsonj
h.updatedAt = util.Now()

return nil
Expand Down

0 comments on commit 8b63eb0

Please sign in to comment.