GeoJSON Import & Export
The GeoJsonSerializer utility class handles bi-directional conversion between standard GeoJSON
specifications and the SDK's internal editable drawing features. All conversions checked for a
10,000+ point dataset round-trip with 100% geometry recovery.
Polygon Export Format
Fill and stroke styling is preserved on export:
{
"type": "Feature",
"properties": {
"fillColor": "#6366f1",
"strokeColor": "#4f46e5",
"strokeWidth": 2
},
"geometry": {
"type": "Polygon",
"coordinates": [[[78.9, 20.5], [79.1, 20.5], [79.0, 20.7], [78.9, 20.5]]]
}
}
Handling Circles in Standard GeoJSON
Since standard RFC 7946 GeoJSON lacks a native Circle geometry, GeoJsonSerializer converts
circles into 64-vertex polygon approximations, preserving circle metadata (isCircle,
center, radius) in properties for future editable re-imports:
{
"type": "Feature",
"id": "circle-xyz123",
"properties": {
"isCircle": true,
"center": [78.9629, 20.5937],
"radius": 1500.5
},
"geometry": {
"type": "Polygon",
"coordinates": [
[[78.9629, 20.607], [79.076, 20.5937], "...", [78.9629, 20.607]]
]
}
}
Text Notation Export Format
{
"type": "Feature",
"properties": {
"isNotation": true,
"notationText": "Label text here",
"notationSize": 16,
"notationColor": "#6366f1"
},
"geometry": {
"type": "Point",
"coordinates": [78.9629, 20.5937]
}
}
Exporting Shapes to GeoJSON
import { GeoJsonSerializer } from '@sovereignsolutions/ss-map-gl';
// 1. Get raw drawn shapes
const internalFeatures = drawingController.getAllFeatures();
// 2. Export to standard GeoJSON FeatureCollection
const standardGeoJson = GeoJsonSerializer.exportToGeoJson(internalFeatures);
console.log('Exported GeoJSON:', JSON.stringify(standardGeoJson, null, 2));
Importing GeoJSON to the Map
The SDK also imports standard Point objects containing a radius property - a widely used
point-radius format outside the SDK. Upon calling GeoJsonSerializer.importFromGeoJson(), this
Point structure is automatically reconstructed into an editable 64-vertex circle shape:
import { GeoJsonSerializer } from '@sovereignsolutions/ss-map-gl';
const externalGeoJson = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [72.8777, 19.0760],
},
properties: {
radius: 2000, // In meters
},
},
],
};
// 1. Convert standard GeoJSON into internal editable features
const internalFeatures = GeoJsonSerializer.importFromGeoJson(externalGeoJson);
// 2. Add to active drawing layer
drawingController.addFeatures(internalFeatures);
See also: Drawing Controller.