Permalink
Browse files

app: parse SRS from request

  • Loading branch information...
olt committed Jul 27, 2017
1 parent 02d3522 commit d806a7a07bfc8a86ec09e430fbafe63c8480e678
Showing with 39 additions and 3 deletions.
  1. +39 −3 maps/request.go
View
@@ -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
@@ -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 == "" {

0 comments on commit d806a7a

Please sign in to comment.