Skip to content

ym.services.GeoJsonService

Overview

The abstract class GeoJsonService is the base class for all GeoJSON WebService calls.

Initialization

Constructor(name, path, options, defaults)

Name Description Data type Default value
name The name of the class written out as a string; for example "MyAwesomeClass". string
path This is the WebService path where all searches should be performed in the context of the inheriting class; for example "api_rst/v2/geojson/geocode" for a class that should address the geocoder. string
options Settings that should overwrite the default settings. These options are also automatically passed to the GeoJSON object. This means that all options from the GeoJSON object can also be used here. object
defaults Default settings that the inheriting class can specify. object

Example implementation

To register a new GeoJSON WebService, the class GeoJsonService is used:

function MyWebService(options) {
    ym.services.GeoJsonService.call(this, "MyWebService", "path/to/your/webservice", options, {
        defaultA: 10,
        defaultB: "hello, world!"
    });
}

// Creates an inheritance of ym.services.GeoJsonService and adds a mixin object to the prototype of the class
ym.util.inherits(MyWebService, ym.services.GeoJsonService, {

    // Overrides the send method.
    send: function (myData) {
        ym.services.GeoJsonService.prototype.send.call(this, {
            // ... GeoJSON declaration for the request ...
        });
    }
});

Run WebService

var map = new ym.modules.Map("{...}");

var myWebService = new MyWebService({ defaultB: "hello, universe!" });
console.log(myWebService.options); // => { defaultA: 10, defaultB: "hello, universe!" }

// Each time a response is received, the GeoJSON is updated on the map.
myWebService.addTo(map);

myWebService.send("{ ... your data ... }");

Integrate directly into the map

var myWebService = new MyWebService({ defaultB: "hello, universe!" });
console.log(myWebService.options); // => { defaultA: 10, defaultB: "hello, universe!" }

myWebService.on('success', function (req, res) {
    console.log(res.body); // For map integration it must be a valid GeoJSON,
});

myWebService.send("{ ... your data ... }");

Methods

getBounds()

Returns the surrounding rectangle of the GeoJSON object. The method is only used after a) a map is registered and b) data has already been loaded.

  • Return: LatLngBounds

addTo(map)

Draws the internal GeoJSON object on the map.

Parameter Description Data type Default value
map Map
  • Return: this

removeFrom(map)

Removes the GeoJSON from the map.

Parameter Description Data type Default value
map Map
  • Return: this

coordFormatMapping()

SmartMaps has an enumeration (enum) with different coordinate formats for better readability. These represent standards, which are translated for the GeoJSON.

Parameter Description Data type Default value
coordFormat SmartMaps' own coordinate format enumeration: GEODECIMAL_POINT := urn:ogc:def:crs:OGC:1.3:CRS84, MERCATOR := urn:ogc:def:crs:EPSG::900913 string GEODECIMAL_POINT
  • Return: As return, one of the translated codes in properties.name is provided:
{
    "type": "name",
    "properties": {
        "name": "{formatted string}"
    }
}