ALKMaps.Protocol.Script

A basic Script protocol for vector layers.  Create a new instance with the ALKMaps.Protocol.Script constructor.  A script protocol is used to get around the same origin policy.  It works with services that return JSONP - that is, JSON wrapped in a client-specified callback.  The protocol handles fetching and parsing of feature data and sends parsed features to the callback configured with the protocol.  The protocol expects features serialized as GeoJSON by default, but can be configured to work with other formats by setting the format property.

Inherits from

Summary
ALKMaps.Protocol.ScriptA basic Script protocol for vector layers.
Properties
url{String} Service URL.
params{Object} Query string parameters to be appended to the URL.
callback{Object} Function to be called when the read operation completes.
callbackTemplate{String} Template for creating a unique callback function name for the registry.
callbackKey{String} The name of the query string parameter that the service recognizes as the callback identifier.
callbackPrefix{String} Where a service requires that the callback query string parameter value is prefixed by some string, this value may be set.
scope{Object} Optional ``this`` object for the callback.
format{ALKMaps.Format} Format for parsing features.
pendingRequests{Object} References all pending requests.
srsInBBOX{Boolean} Include the SRS identifier in BBOX query string parameter.
Constructor
ALKMaps.Protocol.ScriptA class for giving layers generic Script protocol.
Functions
readConstruct a request for reading new features.
filterToParamsOptional method to translate an ALKMaps.Filter object into an object that can be serialized as request query string provided.
createRequestIssues a request for features by creating injecting a script in the document head.
destroyRequestRemove a script node associated with a response from the document.
handleReadIndividual callbacks are created for read, create and update, should a subclass need to override each one separately.
handleResponseCalled by CRUD specific handlers.
parseFeaturesRead Script response body and return features.
abortAbort an ongoing request.
destroyClean up the protocol.
ALKMaps.Protocol.Script.registerRegister a callback for a newly created script.
ALKMaps.Protocol.Script.unregisterUnregister a callback previously registered with the register function.

Properties

url

{String} Service URL.  The service is expected to return serialized features wrapped in a named callback (where the callback name is generated by this protocol).  Read-only, set through the options passed to the constructor.

params

{Object} Query string parameters to be appended to the URL.  Read-only, set through the options passed to the constructor.  Example: {maxFeatures: 50}

callback

{Object} Function to be called when the read operation completes.

callbackTemplate

{String} Template for creating a unique callback function name for the registry.  Should include ${id}.  The ${id} variable will be replaced with a string identifier prefixed with a “c” (e.g. c1, c2).  Default is “ALKMaps.Protocol.Script.registry.${id}”.

callbackKey

{String} The name of the query string parameter that the service recognizes as the callback identifier.  Default is “callback”.  This key is used to generate the URL for the script.  For example setting callbackKey to “myCallback” would result in a URL like https://example.com/?myCallback=...

callbackPrefix

{String} Where a service requires that the callback query string parameter value is prefixed by some string, this value may be set.  For example, setting callbackPrefix to “foo:” would result in a URL like https://example.com/?callback=foo:...  Default is “”.

scope

{Object} Optional ``this`` object for the callback.  Read-only, set through the options passed to the constructor.

format

{ALKMaps.Format} Format for parsing features.  Default is an ALKMaps.Format.GeoJSON format.  If an alternative is provided, the format’s read method must take an object and return an array of features.

pendingRequests

{Object} References all pending requests.  Property names are script identifiers and property values are script elements.

srsInBBOX

{Boolean} Include the SRS identifier in BBOX query string parameter.  Setting this property has no effect if a custom filterToParams method is provided.  Default is false.  If true and the layer has a projection object set, any BBOX filter will be serialized with a fifth item identifying the projection.  E.g. bbox=-1000,-1000,1000,1000,EPSG:900913

Constructor

ALKMaps.Protocol.Script

A class for giving layers generic Script protocol.

Parameters

options{Object} Optional object whose properties will be set on the instance.

Valid options include

url{String}
params{Object}
callback{Function}
scope{Object}

Functions

read

read: function(options)

Construct a request for reading new features.

Parameters

options{Object} Optional object for configuring the request.  This object is modified and should not be reused.

Valid options

url{String} Url for the request.
params{Object} Parameters to get serialized as a query string.
filter{ALKMaps.Filter} Filter to get serialized as a query string.

Returns

{ALKMaps.Protocol.Response} A response object, whose “priv” property references the injected script.  This object is also passed to the callback function when the request completes, its “features” property is then populated with the features received from the server.

filterToParams

Optional method to translate an ALKMaps.Filter object into an object that can be serialized as request query string provided.  If a custom method is not provided, any filter will not be serialized.

Parameters

filter{ALKMaps.Filter} filter to convert.
params{Object} The parameters object.

Returns

{Object} The resulting parameters object.

createRequest

createRequest: function(url,
params,
callback)

Issues a request for features by creating injecting a script in the document head.

Parameters

url{String} Service URL.
params{Object} Query string parameters.
callback{Function} Callback to be called with resulting data.

Returns

{HTMLScriptElement} The script pending execution.

destroyRequest

destroyRequest: function(script)

Remove a script node associated with a response from the document.  Also unregisters the callback and removes the script from the pendingRequests object.

Parameters

script{HTMLScriptElement}

handleRead

handleRead: function(response,
options)

Individual callbacks are created for read, create and update, should a subclass need to override each one separately.

Parameters

response{ALKMaps.Protocol.Response} The response object to pass to the user callback.
options{Object} The user options passed to the read call.

handleResponse

handleResponse: function(response,
options)

Called by CRUD specific handlers.

Parameters

response{ALKMaps.Protocol.Response} The response object to pass to any user callback.
options{Object} The user options passed to the create, read, update, or delete call.

parseFeatures

parseFeatures: function(data)

Read Script response body and return features.

Parameters

data{Object} The data sent to the callback function by the server.

Returns

{Array({ALKMaps.Feature.Vector})} or {ALKMaps.Feature.Vector} Array of features or a single feature.

abort

abort: function(response)

Abort an ongoing request.  If no response is provided, all pending requests will be aborted.

Parameters

response{ALKMaps.Protocol.Response} The response object returned from a read request.

destroy

destroy: function()

Clean up the protocol.

ALKMaps.Protocol.Script.register

Register a callback for a newly created script.

Parameters

callback{Function} The callback to be executed when the newly added script loads.  This callback will be called with a single argument that is the JSON returned by the service.

Returns

{Number} An identifier for retrieving the registered callback.

ALKMaps.Protocol.Script.unregister

Unregister a callback previously registered with the register function.

Parameters

id{Number} The identifer returned by the register function.
read: function(options)
Construct a request for reading new features.
Base class for format reading/writing a variety of formats.
This class represents an OGC Filter.
createRequest: function(url,
params,
callback)
Issues a request for features by creating injecting a script in the document head.
destroyRequest: function(script)
Remove a script node associated with a response from the document.
handleRead: function(response,
options)
Individual callbacks are created for read, create and update, should a subclass need to override each one separately.
handleResponse: function(response,
options)
Called by CRUD specific handlers.
parseFeatures: function(data)
Read Script response body and return features.
abort: function(response)
Abort an ongoing request.
destroy: function()
Clean up the protocol.
A class for giving layers generic Script protocol.
{Object} Function to be called when the read operation completes.
{ALKMaps.Format} Format for parsing features.
Abstract vector layer protocol class.
{String} The name of the query string parameter that the service recognizes as the callback identifier.
{String} Where a service requires that the callback query string parameter value is prefixed by some string, this value may be set.
Read and write GeoJSON.
Protocols return Response objects to their users.
{Object} References all pending requests.
Vector features use the ALKMaps.Geometry classes as geometry description.
Close