Skip to content

Instantly share code, notes, and snippets.

@parthvhirapara
parthvhirapara / Convert WKT to Json for ESRI JSAPI
Last active September 18, 2015 09:35 — forked from mitch-cohen/Convert WKT to Json for ESRI JSAPI
This function will convert the Well Known Text to JSON for ESRI Geometry creation. See example at http://jsfiddle.net/mac1175/6hcax/
function fromWKT2Json(WKTstr) {
var mods = {};
var convertToPointArray = function (ptArrayString) {
var points = [],
ptStringArray = ptArrayString.replace(/\)|\(/gi, "").split(",");
ptStringArray.forEach(function (pt) {
var splitpt = pt.trim().split(" "),
x = parseFloat(splitpt[0], 10),
y = parseFloat(splitpt[1], 10);
// extension for jQuery
(function (root) {
if (root.Enumerable == null) {
throw new Error("can't find Enumerable. linq.jquery.js must load after linq.js");
}
if (root.jQuery == null) {
throw new Error("can't find jQuery. linq.jquery.js must load after jQuery");
}
// Getting a file through XMLHttpRequest as an arraybuffer and creating a Blob
var rhinoStorage = localStorage.getItem("rhino"),
rhino = document.getElementById("rhino");
if (rhinoStorage) {
// Reuse existing Data URL from localStorage
rhino.setAttribute("src", rhinoStorage);
}
else {
// Create XHR, Blob and FileReader objects
var xhr = new XMLHttpRequest(),