mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-05-01 04:37:20 +00:00
First commit
This is the beginnings of a new core plugin to add geospatial capabilities, building on the JSON operators that we now have in the core. It uses the libraries leaflet.js for mapping and turf.js for geospatial calculations.
This commit is contained in:
41
plugins/tiddlywiki/geospatial/geotools.js
Normal file
41
plugins/tiddlywiki/geospatial/geotools.js
Normal file
@@ -0,0 +1,41 @@
|
||||
/*\
|
||||
title: $:/plugins/tiddlywiki/geospatial/geotools.js
|
||||
type: application/javascript
|
||||
module-type: library
|
||||
|
||||
Geospatial utilities
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"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;
|
||||
}
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user