Skip to content

Commit

Permalink
can now parse most esri to geojson features
Browse files Browse the repository at this point in the history
  • Loading branch information
odoe committed Nov 23, 2011
1 parent 5d15eba commit 9ca4ac0
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 24 deletions.
31 changes: 13 additions & 18 deletions esritogeo.js
@@ -1,21 +1,12 @@
var stripJSON = function(str) {
return str.replace(/\\n/g, "\\n")
.replace(/\\t/g, "\\t");
};

var jsonToObject = function(stringIn) { var jsonToObject = function(stringIn) {
console.log("Error: parse with JSON.parse()");

/*
var data = JSON.parse(stringIn, function(key, value) {
var type;
if (value && typeof value === 'object') {
type = value.type;
if (typeof type === 'string' && typeof window[type] === 'function') {
return new (window[type])(value);
}
}
return value;
});
*/
var data; var data;
try { try {
data = JSON.parse(stringIn); data = JSON.parse(stripJSON(stringIn));
console.log("json converted to object"); console.log("json converted to object");
} catch(err) { } catch(err) {
data = null; data = null;
Expand Down Expand Up @@ -48,12 +39,16 @@ var featureToGeo = function(feature, geomType) {


// grab the rings to coordinates // grab the rings to coordinates
var geom = feature.geometry; var geom = feature.geometry;
var coordinates = {};
if (geom.rings !== "undefined") { var coordinates;
if (geomType === "Polygon") {
coordinates = geom.rings; coordinates = geom.rings;
} else if (geom.paths !== "undefined") { } else if (geomType === "LineString") {
coordinates = geom.paths; coordinates = geom.paths;
} else if (geomType === "Point") {
coordinates = [geom.x, geom.y];
} }

geometry.coordinates = coordinates; geometry.coordinates = coordinates;


// convert attributes to properties // convert attributes to properties
Expand Down
3 changes: 2 additions & 1 deletion public/stylesheets/partials/typography.styl
@@ -1,6 +1,7 @@
h1 h1
color #666 color #666
font 4em 'ChunkFiveRegular' font-family 'Ultra', serif
font-size: 2.0em
line-height 0.9em line-height 0.9em
margin-bottom 0.9em margin-bottom 0.9em


Expand Down
269 changes: 269 additions & 0 deletions public/stylesheets/style.css
@@ -0,0 +1,269 @@
/* Reset
Based on http://meyerweb.com/eric/thoughts/2008/01/15/resetting-again/
Removed elements not supported in HTML5
-----------------------------------------------------------------------------*/
html,
body,
div,
span,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
address,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
samp,
small,
strike,
strong,
sub,
sup,
var,
b,
i,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
}
/*
Trigger the new block level elements in to the correct content flow
-----------------------------------------------------------------------------*/
article,
aside,
dialog,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
display: block;
}
/* Set up document
-----------------------------------------------------------------------------*/
body {
font: 62.5%/1.5 Helvetica, Arial, "Lucida Grande", "Lucida Sans", Tahoma, Verdana, sans-serif;
text-align: center;
background: #000;
}
#wrapper {
width: 920px;
text-align: left;
margin-left: auto;
margin-right: auto;
background: #fff;
padding: 20px;
-webkit-border-bottom-left-radius: 15px;
-moz-border-bottom-left-radius: 15px;
-o-border-bottom-left-radius: 15px;
border-bottom-left-radius: 15px;
-webkit-border-bottom-right-radius: 15px;
-moz-border-bottom-right-radius: 15px;
-o-border-bottom-right-radius: 15px;
border-bottom-right-radius: 15px;
}
/* Typography
-----------------------------------------------------------------------------*/
h1 {
color: #666;
font-family: 'Ultra', serif;
font-size: 2em;
line-height: 0.9em;
margin-bottom: 0.9em;
}
h2 {
font-size: 1.8em;
line-height: 1em;
margin-bottom: 1em;
}
h3 {
font-size: 1.6em;
line-height: 1.13em;
margin-bottom: 1.13em;
}
h4 {
font-size: 1.4em;
line-height: 1.29em;
margin-bottom: 1.29em;
}
h5 {
font-size: 1.3em;
line-height: 1.38em;
margin-bottom: 1.38em;
}
h6 {
font-size: 1.2em;
line-height: 1.5em;
margin-bottom: 1.5em;
}
p,
q,
cite,
address,
ul,
ol,
dl {
font-size: 1.2em;
line-height: 1.5em;
margin-bottom: 1.5em;
}
li,
dd,
dt {
font-size: 1em;
}
a {
text-decoration: underline;
color: #33c;
outline: none;
}
a:hover {
text-decoration: none;
}
code,
samp,
dfn,
kbd,
var,
acronym,
ins,
del,
abbr {
speak: spell-out;
}
acronym {
speak: normal;
}
/* CSS Tables
-----------------------------------------------------------------------------*/
.css-table {
width: 100%;
display: table;
}
.css-table .two-column {
display: table-row;
}
.css-table .two-column .cell {
display: table-cell;
vertical-align: top;
width: 50%;
}
.css-table .two-column .cell * {
width: 90%;
}
.css-table .three-column {
display: table-row;
}
.css-table .three-column .cell {
display: table-cell;
width: 33.33333%;
}
.css-table .three-column .cell * {
width: 90%;
}
.css-table .four-column {
display: table-row;
}
.css-table .four-column .cell {
display: table-cell;
width: 25%;
}
/* Header
-----------------------------------------------------------------------------*/
header {
background: #f00060;
}
header nav {
width: 960px;
text-align: right;
margin-left: auto;
margin-right: auto;
}
header nav ul {
list-style: none;
padding: 10px;
margin-bottom: 0;
}
header nav ul li {
display: inline;
margin-left: 1%;
}
header nav ul li a {
background: #fc9200;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
-o-border-radius: 15px;
border-radius: 15px;
display: inline-block;
padding: 5px 15px 6px;
color: #fff;
text-decoration: none;
position: relative;
cursor: pointer;
}
header nav ul li a:hover {
background-color: #db0d5f;
}
/* Footer
-----------------------------------------------------------------------------*/
footer {
color: #666;
border-top: 1px solid #ccc;
padding-top: 1.5em;
}
footer ul {
list-style: none;
}
/* main container (my additions)
-----------------------------------------------------------------------------*/
#wrapper {
height: 75%;
}
/* Textarea (my additions)
-----------------------------------------------------------------------------*/
form {
height: 100%;
}
textarea {
width: 100%;
height: 150px;
}
5 changes: 5 additions & 0 deletions public/stylesheets/style.styl
Expand Up @@ -112,5 +112,10 @@ footer
ul ul
list-style none list-style none


/* main container (my additions)
-----------------------------------------------------------------------------*/
/* Textarea (my additions) /* Textarea (my additions)
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
textarea
width 100%
height 150px
6 changes: 3 additions & 3 deletions views/index.jade
Expand Up @@ -5,7 +5,7 @@ form( method='post', action='/' )
label EsriJSON label EsriJSON
textarea(name='inJson', value=jsonIn)=jsonIn textarea(name='inJson', value=jsonIn)=jsonIn
div div
label GeoJSON input(type='submit', value='convert')
textarea= jsonOut
div div
input(type='submit', value='go') label GeoJSON
textarea= jsonOut
1 change: 1 addition & 0 deletions views/layout.jade
Expand Up @@ -2,6 +2,7 @@
html html
head head
title= title title= title
link(rel='stylesheet', href='http://fonts.googleapis.com/css?family=Ultra')
link(rel='stylesheet', href='/stylesheets/style.css') link(rel='stylesheet', href='/stylesheets/style.css')
body body
header header
Expand Down
22 changes: 20 additions & 2 deletions web.js
Expand Up @@ -8,11 +8,29 @@ app.configure(function(){
app.set('view engine', 'jade'); app.set('view engine', 'jade');
app.use(express.bodyParser()); app.use(express.bodyParser());
app.use(express.methodOverride()); app.use(express.methodOverride());
app.use(require('stylus').middleware({ src: __dirname + 'public' })); /*
app.use(require('stylus').middleware({
debug: true,
src: __dirname + '/views',
dest: __dirname + '/public',
compile: compileMethod
}));
*/
app.use(require('stylus').middleware({
debug: true,
src: __dirname + '/public',
dest: __dirname + '/public',
compile: compileMethod
}));
app.use(app.router); app.use(app.router);
app.use(express.static(__dirname + '/public')); app.use(express.static(__dirname + '/public'));
}); });


var compileMethod = function (str) {
return require('stylus')(str)
.set('compress', true);
};

app.configure('development', function(){ app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
}); });
Expand All @@ -29,7 +47,7 @@ var jsonOutput = "this will be GeoJSON";
app.get('/', function(req, res){ app.get('/', function(req, res){
console.log('start of app'); console.log('start of app');
res.render('index', { res.render('index', {
title: 'EsriJSON to GeoJSON (experimental): Only works on Polygons for now', title: 'EsriJSON to GeoJSON (experimental)',
locals: { jsonIn: jsonInput, jsonOut: jsonOutput } locals: { jsonIn: jsonInput, jsonOut: jsonOutput }
}); });
}); });
Expand Down

0 comments on commit 9ca4ac0

Please sign in to comment.