mapquery

package
v0.0.0-...-a5a65f0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2017 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package mapquery provides a Query object suitable to send search queries from the map aspect of the web UI. It is not concurrent safe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteZoomPredicate

func DeleteZoomPredicate(expr string) string

DeleteZoomPredicate looks for a "map:" predicate in expr, and if found, removes it.

func HasZoomParameter

func HasZoomParameter(queryString string) bool

HasZoomParameter returns whether queryString is the "q" parameter of a search query, and whether that parameter contains a map zoom (map predicate).

func New

func New(authToken string, expr string,
	callback func(searchResults string),
	cleanup func()) *js.Object

New returns a new query as a javascript object, or nil if expr violates the rules about the zoom (map:) predicate. See SetZoom for the rules.

func ShiftZoomPredicate

func ShiftZoomPredicate(expr string) string

ShiftZoomPredicate looks for a "map:" predicate in expr, and if found, moves it at the end of the expression if necessary.

Types

type Query

type Query struct {
	// AuthToken is the token for authenticating with Camlistore.
	AuthToken string
	// Expr is the search query expression.
	Expr string
	// Limit is the maximum number of search results that should be returned.
	Limit int

	// Callback is the function to run on the JSON-ified search results, if the search
	// was successful.
	Callback func(searchResults string)
	// Cleanup is run once, right before Callback, or on any error that occurs
	// before Callback.
	Cleanup func()
	// contains filtered or unexported fields
}

Query holds the parameters for the current query.

func (*Query) GetExpr

func (q *Query) GetExpr() string

GetExpr returns the search expression of the query.

func (*Query) GetZoom

func (q *Query) GetZoom() *camtypes.LocationBounds

GetZoom returns the location area that was requested for the last successful query.

func (*Query) Send

func (q *Query) Send()

Send sends the search query, and runs the Query's callback on success. It returns immediately if there's already a query in flight.

func (*Query) SetLimit

func (q *Query) SetLimit(limit int)

func (*Query) SetZoom

func (q *Query) SetZoom(north, west, south, east float64)

SetZoom modifies the query's search expression: it uses the given coordinates in a map predicate to constrain the search expression to the defined area, effectively acting like a map zoom.

The map predicate is defined like locrect, and it has a similar meaning. However, it is not defined server-side, and it is specifically meant to represent the area of the world that is visible in the screen when using the map aspect, and in particular when zooming or panning. As such, it follows stricter rules than the other predicates, which are:

1. only one map predicate is allowed in the whole expression. 2. since the map predicate is interpreted as if it were a logical 'and' with the rest of the whole expression (regardless of its position within the expression), logical 'or's around it are forbidden.

The map predicate is also moved to the end of the expression, for clarity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL