new GeoJSON(value)
Creates a new GeoJSON instance.
Parameters:
Name | Type | Description |
---|---|---|
value |
Object | string | GeoJSON value; the constructor accepts either a string representation of the JSON object, or a JS object. |
- Source:
Example
const Aerospike = require('aerospike') const GeoJSON = Aerospike.GeoJSON const Key = Aerospike.Key // INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE! var config = { hosts: '192.168.33.10:3000', // Timeouts disabled, latency dependent on server location. Configure as needed. policies: { read : new Aerospike.ReadPolicy({socketTimeout : 0, totalTimeout : 0}), write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}), } } Aerospike.connect(config, (error, client) => { if (error) throw error let key = new Key('test', 'demo', 'bob') let location = new GeoJSON({type: 'Point', coordinates: [103.913, 1.308]}) client.put(key, {loc: location}, (error) => { if (error) throw error client.get(key, (error, record) => { if (error) throw error console.log(record.bins.loc) // => {"type":"Point","coordinates":[103.913,1.308]} client.close() }) }) })
Methods
-
<static> Circle(lng, lat, radius)
Helper function to create a new GeoJSON geometry object representing a circle with the given coordinates and radius.
-
Parameters:
Name Type Description lng
number Longitude of the center point.
lat
number Latitude of the center point.
radius
number Radius in meters.
- Source:
- See:
Returns:
a GeoJSON representation of the circle.
- Type
- GeoJSON
Example
const Aerospike = require('aerospike') const GeoJSON = Aerospike.GeoJSON let point = GeoJSON.Circle(103.913, 1.308, 5000)
-
<static> Point(lng, lat)
Helper function to create a new GeoJSON object representing the point with the given coordinates.
-
Parameters:
Name Type Description lng
number Longitude
lat
number Latitude
- Source:
Returns:
a GeoJSON representation of the point
- Type
- GeoJSON
Example
const Aerospike = require('aerospike') const GeoJSON = Aerospike.GeoJSON let point = GeoJSON.Point(103.913, 1.308)
-
<static> Polygon(coordinates)
Helper function to create a new GeoJSON object representing the polygon with the given coordinates.
-
Parameters:
Name Type Argument Description coordinates
Array.<number> <repeatable>
one or more coordinate pairs (lng, lat) describing the polygon.
- Source:
Returns:
a GeoJSON representation of the polygon.
- Type
- GeoJSON
Example
const Aerospike = require('aerospike') const GeoJSON = Aerospike.GeoJSON let polygon = GeoJSON.Polygon([102.913, 0.308], [102.913, 2.308], [104.913, 2.308], [104.913, 0.308], [102.913, 0.308])
-
toJSON()
-
Returns the GeoJSON value as a JS object.
- Source:
Returns:
- Type
- Object
-
toString()
-
Returns the GeoJSON value as a string
- Source:
Returns:
- Type
- string
-
value()
-
Alias for
GeoJSON#toJSON
. Returns the GeoJSON value as a JS object.- Source:
Returns:
- Type
- Object