forked from gagan-bansal/geojson2svg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gagan-bansal
committed
Apr 11, 2014
1 parent
632949d
commit 00ef0bf
Showing
9 changed files
with
250 additions
and
5,749 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
module.exports = { | ||
mapExtent: [-180,-90,180,90], | ||
mapExtentProjCode: 'EPSG:4326', | ||
mapExtent: [-180,-90,180,90], | ||
inProjCode: 'EPSG:4326', | ||
outProjCode: 'EPSG:4326', | ||
r: 2, | ||
style:"", | ||
proj4jsDefs: { | ||
'SR-ORG:6864': '+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs', | ||
'EPSG:4326': '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,111 @@ | ||
'use strict'; | ||
var testDataSets = []; | ||
//testDataSets.push(require('./testdata1.js')); | ||
testDataSets.push(require('./testdata2.js')); | ||
var expect = require("chai").expect; | ||
var extend = require('deep-extend'); | ||
testDataSets.push(require('./testdata1.js')); | ||
//testDataSets.push(require('./testdata2.js')); | ||
//var expect = require('expect.js'), | ||
var expect = require('chai').expect | ||
,parsePath = require('parse-svg-path') | ||
,jsdom = require('jsdom').jsdom; | ||
|
||
/*expect.Assertion.prototype.path = function(path) { | ||
console.log('this: '+JSON.stringify(this.obj)); | ||
console.log('path: '+ path.length); | ||
expect(this.obj).to.eql(path); | ||
};*/ | ||
|
||
describe('geojson2svg', function() { | ||
testDataSets.forEach(function(testData) { | ||
var precision = testData.precision; | ||
describe(testData.desc+ ': .convert()', function() { | ||
var geojson2svg = require('../src/main.js'); | ||
var converter = geojson2svg(testData.svgSize,testData.options); | ||
testData.primitives.forEach(function(data) { | ||
it(data.type,function() { | ||
var outSVG = converter.convert(data.json); | ||
//console.log('outSVG: '+ outSVG); | ||
//console.log('expected SVG: '+ data.svg); | ||
expect(outSVG).to.deep.equal(data.svg); | ||
testData.geojsons.forEach(function(data) { | ||
it(data.type+ ' {output: "path",explode: false,r:2}',function() { | ||
var actualPaths = converter.convert(data.geojson,testData.options); | ||
testPath(actualPaths,data.path,data.geojson.type,precision); | ||
}); | ||
it(data.type + ' {output: "svg",explode: false,r:2}',function() { | ||
var options = {output:'svg'}; | ||
extend(options,testData.options); | ||
var actualSVGs = converter.convert(data.geojson,options); | ||
testSVG(actualSVGs,data.svg,data.geojson.type,precision); | ||
}); | ||
}); | ||
it('Feature {output: "path",explode: false}', function() { | ||
var actualPaths = converter.convert(testData.feature.geojson, | ||
{output:'path',explode:false}); | ||
testPath(actualPaths,testData.feature.path, | ||
testData.feature.geojson.type, | ||
precision); | ||
}); | ||
it('Feature {output: "svg",explode: false}', function() { | ||
var actualSVGs = converter.convert(testData.feature.geojson, | ||
{ | ||
output:'svg', | ||
explode:false, | ||
attributes: { id: 'id1',style:'stroke: #000066; fill: 3333ff;' } | ||
}); | ||
testSVG(actualSVGs,testData.feature.svg, | ||
testData.feature.geojson.geometry.type, | ||
precision); | ||
}); | ||
it('FeatureCollection {output: "path",explode: false}', function() { | ||
var actualPaths = converter.convert(testData.featureCollection.geojson, | ||
{output: 'path', explode: false}); | ||
expect(actualPaths).to.be.an('array'); | ||
var expPaths = testData.featureCollection.path; | ||
expect(actualPaths.length).to.be.equal(expPaths.length); | ||
for(var i=0; i < expPaths.length; i++) { | ||
testPath([actualPaths[i]],[expPaths[i]], | ||
testData.featureCollection.geojson.features[i].geometry.type,precision); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
function testSVG(actualSVGs,expSVGs,type,precision) { | ||
expect(actualSVGs).to.be.an('array'); | ||
expect(actualSVGs.length).to.be.equal(expSVGs.length); | ||
var expSVGEle,actSVGEle,expPaths,actPaths; | ||
for(var i=0;i<expSVGs.length; i++) { | ||
expSVGEle = jsdom(expSVGs).firstChild; | ||
actSVGEle = jsdom(actualSVGs).firstChild; | ||
expect(actSVGEle.nodeName).to.be.equal('PATH'); | ||
expect(actSVGEle.hasAttribute('d')).to.be.true; | ||
expPaths = expSVGEle.getAttribute('d'); | ||
actPaths = actSVGEle.getAttribute('d'); | ||
testPath([actPaths],[expPaths],type,precision); | ||
} | ||
} | ||
|
||
function testPath(actualPaths,expPaths,type,precision) { | ||
expect(actualPaths).to.be.an('array'); | ||
expect(actualPaths.length).to.be.equal(expPaths.length); | ||
var actPathObj,expPathObj,checkCoord = true; | ||
for(var i=0;i<actualPaths.length; i++) { | ||
actPathObj = parsePath(actualPaths[i]); | ||
expPathObj = parsePath(expPaths[i]); | ||
expect(actPathObj).to.be.an('array'); | ||
expect(actPathObj.length).to.be.equal(expPathObj.length); | ||
//check each path moves | ||
for(var j=0;j< expPathObj.length; j++) { | ||
expect(actPathObj[j].length).to.equal(expPathObj[j].length); | ||
//compare move command | ||
expect(actPathObj[j][0]).to.equal(expPathObj[j][0]); | ||
//do not check for polygon's last close command | ||
checkCoord = !(j == expPathObj.length -1 && (type == 'Polygon' | ||
|| type == 'MultiPolygon')); | ||
if(checkCoord) { | ||
for(var k=1;k<expPathObj[j].length; k++) { | ||
expect(actPathObj[j][k]).to.be.closeTo(expPathObj[j][k],precision); | ||
} | ||
/*//compare x coordinate | ||
expect(actPathObj[j][1]).to.be.closeTo(expPathObj[j][1],precision); | ||
//compare y coordinate | ||
expect(actPathObj[j][2]).to.be.closeTo(expPathObj[j][2],precision);*/ | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.