mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-03 12:23:51 +00:00

* remove blks first try * dprint.json seems to be OK, some forgotten functions * add some more space-after-keyword settings * server remove blks * add **/files to dprint exclude * dprint.js fixes a typo * add boot.js and bootprefix.js to dprint exclude * dprint change dprint.json * add dprint fmt as script * remove jslint comments * fix whitespace * fix whitespace * remove function-wrapper from geospatial plugin * fix whitespace * add function wrapper to dyannotate-startup * remove dpring.json
37 lines
743 B
JavaScript
37 lines
743 B
JavaScript
/*\
|
|
title: $:/plugins/tiddlywiki/geospatial/geotools.js
|
|
type: application/javascript
|
|
module-type: library
|
|
|
|
Geospatial utilities
|
|
|
|
\*/
|
|
|
|
"use strict";
|
|
|
|
var turf = require("$:/plugins/tiddlywiki/geospatial/turf.js");
|
|
|
|
/*
|
|
Parse a string as a GeoJSON Point
|
|
*/
|
|
exports.parsePoint = function(str) {
|
|
var defaultResult = function() {
|
|
return turf.point([0,0,0]);
|
|
}
|
|
// If the string is missing then return 0,0,0
|
|
if(!str) {
|
|
return defaultResult();
|
|
}
|
|
// Convert to an object
|
|
var json = $tw.utils.parseJSONSafe(str,null);
|
|
if(json === null) {
|
|
return defaultResult();
|
|
}
|
|
// Check it is a valid point
|
|
if(turf.getType(json) !== "Point") {
|
|
return defaultResult();
|
|
}
|
|
// Return the string now we know it is a valid GeoJSON Point
|
|
return json;
|
|
}
|