mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2026-03-08 16:00:33 -07:00
* fix: apply automatic eslint fixes * lint: allow hashbang comment for tiddlywiki.js * lint: first back of manual lint fixes for unused vars * lint: added more fixes for unused vars * lint: missed files * lint: updated eslint config with selected rules from #9669
36 lines
745 B
JavaScript
36 lines
745 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;
|
|
};
|