Skip to content

Commit

Permalink
app: parse SRS from request
Browse files Browse the repository at this point in the history
  • Loading branch information
olt committed Jul 27, 2017
1 parent 02d3522 commit d806a7a
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions maps/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,25 @@ func ParseMapRequest(r *http.Request) (*Request, error) {
}

req := &Request{
HTTP: r,
Query: query,
EPSGCode: 3857,
HTTP: r,
Query: query,
}

req.Width, req.Height, err = parseSize(req.Query)
if err != nil {
return nil, err
}

req.BBOX, err = parseBBOX(req.Query)
if err != nil {
return nil, err
}

req.EPSGCode, err = parseEPSGCode(req.Query)
if err != nil {
return nil, err
}

req.Format, err = parseFormat(req.Query)
if err != nil {
return nil, err
Expand Down Expand Up @@ -148,6 +153,37 @@ func parseBBOX(q url.Values) (BBOX, error) {
return bbox, nil
}

func parseEPSGCode(q url.Values) (int, error) {
srsStr := q.Get("SRS")
if srsStr == "" {
return 0, &MissingParamError{"SRS"}
}

if srsStr == "CRS:84" {
return 4326, nil
}

srsParts := strings.Split(srsStr, ":")
if len(srsParts) != 2 {
return 0, &InvalidParamError{Param: "SRS", Value: srsStr}
}

if !strings.HasPrefix(strings.ToUpper(srsStr), "EPSG") {
return 0, &InvalidParamError{Param: "SRS", Value: srsStr}
}

epsgCode, err := strconv.ParseUint(srsParts[1], 10, 32)
if err != nil {
return 0, &InvalidParamError{Param: "SRS", Value: srsStr}
}

if epsgCode == 900913 {
epsgCode = 3857
}

return int(epsgCode), nil
}

func parseFormat(q url.Values) (string, error) {
format := q.Get("FORMAT")
if format == "" {
Expand Down

0 comments on commit d806a7a

Please sign in to comment.