Permalink
Browse files

WKX (WKT/WKB) support (#557)

* adding WKT string and WKB Hex/Base64 encoded string support

* adding documentation of additional libraries

* adding missing menu item

* fixing placement of zoomextent

* making requested changes for PR #557

* removing references to Buffer, as it is included in browserify
  • Loading branch information...
lokkju authored and tmcw committed Mar 14, 2017
1 parent 43af91f commit bcebd54c8fd3ea841573268ea765d40e20eca84d
Showing with 59 additions and 1 deletion.
  1. +2 −0 README.md
  2. +1 −0 package.json
  3. +37 −0 src/lib/meta.js
  4. +19 −1 src/ui/file_bar.js
View
@@ -60,6 +60,8 @@ This is made up of small reusable chunks:
* <a href='http://github.com/mapbox/togeojson'>mapbox/togeojson</a>
* <a href='https://github.com/tyrasd/osmtogeojson'>tyrasd/osmtogeojson</a>
* <a href='https://github.com/w8r/Leaflet.draw.drag'>w8r/Leaflet.draw.drag</a>
* <a href='https://github.com/cschwarz/wkx'>cschwarz/wkx</a>
## See Also
View
@@ -42,6 +42,7 @@
"topojson": "1.6.8",
"uglify-js": "2.4.1",
"wellknown": "0.3.1",
"wkx": "^0.4.1",
"xtend": "3.0.0"
},
"devDependencies": {
View
@@ -3,6 +3,7 @@ var escape = require('escape-html'),
geojsonExtent = require('geojson-extent'),
geojsonFlatten = require('geojson-flatten'),
polyline = require('polyline'),
wkx = require('wkx'),
zoomextent = require('../lib/zoomextent');
module.exports.adduserlayer = function(context, _url, _name) {
@@ -52,3 +53,39 @@ module.exports.polyline = function(context) {
alert('Sorry, we were unable to decode that polyline');
}
};
module.exports.wkxBase64 = function(context) {
var input = prompt('Enter your Base64 encoded WKB/EWKB');
try {
var decoded = wkx.Geometry.parse(Buffer.from(input,'base64'));
context.data.set({ map: decoded.toGeoJSON() });
zoomextent(context);
} catch(e) {
console.error(e)
alert('Sorry, we were unable to decode that Base64 encoded WKX data');
}
};
module.exports.wkxHex = function(context) {
var input = prompt('Enter your Hex encoded WKB/EWKB');
try {
var decoded = wkx.Geometry.parse(Buffer.from(input,'hex'));
context.data.set({ map: decoded.toGeoJSON() });
zoomextent(context);
} catch(e) {
console.error(e)
alert('Sorry, we were unable to decode that Hex encoded WKX data');
}
};
module.exports.wkxString = function(context) {
var input = prompt('Enter your WKT/EWKT String');
try {
var decoded = wkx.Geometry.parse(input);
context.data.set({ map: decoded.toGeoJSON() });
zoomextent(context);
} catch(e) {
console.error(e)
alert('Sorry, we were unable to decode that WKT data');
}
};
View
@@ -124,6 +124,24 @@ module.exports = function fileBar(context) {
action: function() {
meta.polyline(context);
}
}, {
title: 'Load WKB Base64 Encoded String',
alt: 'Decode and show WKX data',
action: function() {
meta.wkxBase64(context);
}
}, {
title: 'Load WKB Hex Encoded String',
alt: 'Decode and show WKX data',
action: function() {
meta.wkxHex(context);
}
}, {
title: 'Load WKT String',
alt: 'Decode and show WKX data',
action: function() {
meta.wkxString(context);
}
}
]
}];
@@ -352,7 +370,7 @@ module.exports = function fileBar(context) {
m.close();
saver(context);
}
// Update a file
// Update a file
else if (last.type === 'blob') {
// Build the path
pathparts = d.slice(3);

0 comments on commit bcebd54

Please sign in to comment.