hotspot.ObjectSource

The standard implementation of the IHotspotObjectSource interface.
Note. Deprecated: This module is supported in version 2.1 for backward compatibility. Use the hotspot.layer.ObjectSource module.

See hotspot.layer.ObjectSource

Constructor | Methods

Constructor

hotspot.ObjectSource()

Methods

Name Returns Description
getKey(tileNumber, zoom)

String

Returns the name of the callback function (padding) in the jsonp request if it is static, or null if a dynamic jsonp callback can be used. Templates support the same substitutions as in the template for the tile URL. All characters other than letters, numbers, and the "_" symbol will be replaced with "_".

getKeyTemplate()

String

Returns template for the tile ID.

getTileUrl(tileNumber, zoom)

String

Returns the URL of data for a specific tile.

getTileUrlTemplate()

String

Returns template for the URL for tile data.

parseResponse(layer, res, callback, tileNumber, zoom)

Parses the server response. Sends the callback an array of hotspot objects generated using the json description.

restrict(layer, tileNumber, zoom)

Boolean

Method that is called before sending a request for tile data. If the method returns true, the request will not be sent to the server, and an empty array of objects will be returned as the response. The standard implementation of the method checks whether the "zoom" parameter is within the limits of [options.minZoom, options.maxZoom]. It also checks whether the center of the requested tile falls within the specified options.bounds. If options.bounds=null, this parameter is not checked.

setKeyTemplate(template)

Sets a new tile ID template.

setTileUrlTemplate(template)

Sets a new template for the tile data URL.

Methods details

getKey

{String} getKey(tileNumber, zoom)

Returns the name of the callback function (padding) in the jsonp request if it is static, or null if a dynamic jsonp callback can be used. Templates support the same substitutions as in the template for the tile URL. All characters other than letters, numbers, and the "_" symbol will be replaced with "_".

Returns tile ID. Used when creating padding in the jsonp request for data.

Parameters:

Parameter Default value Description
tileNumber *

Type: Number[]

Tile number (tile coordinates).

zoom *

Type: Integer

Zoom level.

* Mandatory parameter/option.

getKeyTemplate

{String} getKeyTemplate()

Returns template for the tile ID.

getTileUrl

{String} getTileUrl(tileNumber, zoom)

Returns the URL of data for a specific tile.

Parameters:

Parameter Default value Description
tileNumber *

Type: Number[]

Tile number (tile coordinates).

zoom *

Type: Integer

Zoom level.

* Mandatory parameter/option.

Example:

var hotspotObjectSource = new ymaps.hotspot.ObjectSource('dataSource/?%c');
hotspotObjectSource.getTileUrl = function (tileNumber, zoom) {
    if (zoom > 10) {
        // For large scales, use the provided data path.
        return ymaps.hotspot.ObjectSource.prototype.call(this, tileNumber, zoom);
     } else {
        // For small scales, use a different path.
        return 'otherSource/getHotspots.xml?z=' + zoom + '<codeph>&</codeph>x=' + tileNumber[0] + '<codeph>&</codeph>y=' + tileNumber[1]';
     }
};

getTileUrlTemplate

{String} getTileUrlTemplate()

Returns template for the URL for tile data.

parseResponse

{} parseResponse(layer, res, callback, tileNumber, zoom)

Parses the server response. Sends the callback an array of hotspot objects generated using the json description.

Parameters:

Parameter Default value Description
layer *

Type: hotspot.Layer

The layer that the objects belong to.

res *

Type: Object

Server response.

callback *

Type: Function

Handler function.

tileNumber *

Type: Number[]

Number of the tile that the response is for.

zoom *

Type: Number

The zoom level that the response is for; array of objects.

* Mandatory parameter/option.

restrict

{Boolean} restrict(layer, tileNumber, zoom)

Method that is called before sending a request for tile data. If the method returns true, the request will not be sent to the server, and an empty array of objects will be returned as the response. The standard implementation of the method checks whether the "zoom" parameter is within the limits of [options.minZoom, options.maxZoom]. It also checks whether the center of the requested tile falls within the specified options.bounds. If options.bounds=null, this parameter is not checked.

Returns true if the tile extends beyond the boundaries of the data area (there is no data for this tile), or false if it does not (there is data).

Parameters:

Parameter Default value Description
layer *

Type: hotspot.Layer

Hotspot layer.

tileNumber *

Type: Number[]

Tile number.

zoom *

Type: Integer

Zoom level.

* Mandatory parameter/option.

Example:

// Example of redefining the "restrict" method
// Let's assume there is only data for Murmansk and Novosibirsk.
var myMap = new ymaps.Map('map', {center: [32.5, 68.9] , zoom: 9}),
    geoBounds = [
         [[31.729958, 69.369182], [34.203324, 68.666473]], // Murmansk
         [[82.179084, 55.341085], [83.725642, 54.670738]]  // Novosibirsk
    ],
    projection = myMap.options.get('projection');

var myHotspotSource = new ymaps.hotspot.ObjectSource('http://www.myDomain.ru/tiles/?%c', '%c');

myHotspotSource.restrict = function(layer, tileNumber, zoom) {

   // Calculating the pixel boundaries of the cities for this zoom level.
   var boundsFromPoints = ymaps.util.bounds.fromPoints,
       toGlobalPixels = projection.toGlobalPixels,
       pixelBounds = [
           boundsFromPoints(
               toGlobalPixels(geoBounds[0][0]], zoom),
               toGlobalPixels(geoBounds[0][1]], zoom)
           ),
           boundsFromPoints(
               toGlobalPixels(geoBounds[1][0]], zoom),
               toGlobalPixels(geoBounds[1][1]], zoom)
           )
      ],

       // Calculating the pixel boundaries of the tile
       leftTop = [tileNumber[0] * 256, tileNumber[1] * 256],
       tileBounds = [leftTop, [leftTop[0] + 256, leftTop[1] + 256]],
       intersects = ymaps.util.bounds.intersects;
   // If the tile's pixel boundaries intersect with the pixel boundaries of the specified areas,
   // we have to send a request for data
   if (intersects(pixelBounds[0], tileBounds) || (intersects(pixelBounds[1], tileBounds)) {
         return false;
  }

   // For all the other tiles, this source doesn't have any data.
   return true;
}

setKeyTemplate

{} setKeyTemplate(template)

Sets a new tile ID template.

Parameters:

Parameter Default value Description
template *

Type: String

Template for the ID.

* Mandatory parameter/option.

setTileUrlTemplate

{} setTileUrlTemplate(template)

Sets a new template for the tile data URL.

Parameters:

Parameter Default value Description
template *

Type: String

URL template

* Mandatory parameter/option.