Skip to content

Instantly share code, notes, and snippets.

@walkermatt
Created August 16, 2015 15:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walkermatt/bc3ae3d8101addeaeda2 to your computer and use it in GitHub Desktop.
Save walkermatt/bc3ae3d8101addeaeda2 to your computer and use it in GitHub Desktop.
Create WKT POLYGON from a bounding box in JavaScript
var str = "POLYGON((left top,right top,right bottom,left bottom,left top))";
var bbox = {left: 10, top: 30, right: 20, bottom: 40};
str.replace(/[a-z]+/g, function(s) {return bbox[s];});
@victropolis
Copy link

var str = "POLYGON((left top,right top,right bottom,left bottom,left top))";
var bbox = {left: 10, top: 30, right: 20, bottom: 40}; 
str = str.replace(/left/g, function(s) {return bbox[s];});
str = str.replace(/top/g, function(s) {return bbox[s];});
str = str.replace(/right/g, function(s) {return bbox[s];});
str = str.replace(/bottom/g, function(s) {return bbox[s];});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment