ym.services.GeoJsonService

Overview

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

Initialization

constructor(name, path, options, defaults)

Name Description Data type Default value
name The name is the name of the class written out as a string; for example "MyAwesomeClass".
[required]
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.
[required]
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.
[optional]
object  
defaults Default settings that the inheriting class can specify.
[optional]
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: "Hallo Universum!" }
 
// 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 ... }");

Methoden

getBounds() from v3

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) from v3

Draws the internal GeoJSON object on the map.

Parameter

Name Description Data type Default value
map   Map  

Return

this

removeFrom(map) from v3

Removes the GeoJSON from the map.

Parameter

Name Description Data type Default value
map   Map  

Return

this

coordFormatMapping() from v3

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

Parameter

Name Description Data type Default value
coordFormat SmartMaps eigene Koordinatenformat-Aufzählung:
GEODECIMAL_POINT := urn:ogc:def:crs:OGC:1.3:CRS84
MERCATOR := urn:ogc:def:crs:EPSG::900913
[optional]
string GEODECIMAL_POINT

Return

As return one of the translated codes in properties.name is provided:

{
    "type": "name",
    "properties": {
        "name": "{formatierte Zeichenkette}"
    }
}