geojson2svg
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,50 +0,12 @@ | ||
## Change Log | ||
### Change Log | ||
### v1.0.0 (2015/04/28) | ||
- [aea04b0](https://github.com/gagan-bansal/geojson2svg/commit/aea04b051b3802ea448c0a96516bdc6a8ea15c58) Update README.md (@FearMediocrity) | ||
- [bd1b8c7](https://github.com/gagan-bansal/geojson2svg/commit/bd1b8c751d9156048eca4f2a4cab4800f3793bfc) Default viewport size option added close #9 #changelog (@gagan-bansal) | ||
#### 1.0.0, 2015-04-28 | ||
### v0.1.4 (2015/03/02) | ||
- [d379d21](https://github.com/gagan-bansal/geojson2svg/commit/d379d212e891cb9dc9481743df1d8c51edcc16cc) starting the project | ||
- [4be51ee](https://github.com/gagan-bansal/geojson2svg/commit/4be51eef9054218d64fd09f01c162b5b06beb94d) initial prototype ready | ||
- [4fc5f33](https://github.com/gagan-bansal/geojson2svg/commit/4fc5f33894535a7bc82c2d84c8810af9c8643bb6) return as path string | ||
- [632949d](https://github.com/gagan-bansal/geojson2svg/commit/632949deb9bcc3e78de8a7e042102c06273d450d) return as path string 2 | ||
- [00ef0bf](https://github.com/gagan-bansal/geojson2svg/commit/00ef0bf2ae135692ddf28227b40fe144d5ce1509) all test passed , remaining explode | ||
- [11c7927](https://github.com/gagan-bansal/geojson2svg/commit/11c79277816bf4dc4cae066bd5332f695ee083ff) before pushing to github | ||
- [d838bc1](https://github.com/gagan-bansal/geojson2svg/commit/d838bc13bc24e5ff4f5cd5825f0d1052157acd7f) MIT license added | ||
- [0cf0ad0](https://github.com/gagan-bansal/geojson2svg/commit/0cf0ad059f124bc1fe3a858c345b649e0551bb9b) readme modified | ||
- [d1d9165](https://github.com/gagan-bansal/geojson2svg/commit/d1d916590a0e5bb6e5070fcd0a478051f50da891) created global variable for browser through browserify | ||
- [393dc33](https://github.com/gagan-bansal/geojson2svg/commit/393dc3337c0106ec154e81b649b92b3ea7143be1) small bugfix and README.md written | ||
- [9e50c90](https://github.com/gagan-bansal/geojson2svg/commit/9e50c90db575f7147c046f50192b6c79821c88aa) explode geojson test included | ||
- [0f6d345](https://github.com/gagan-bansal/geojson2svg/commit/0f6d345f44c408065b9286b1eacb78ed8dbe492b) node-clone dependency removed | ||
- [a4d6b58](https://github.com/gagan-bansal/geojson2svg/commit/a4d6b582684c2c29db855840f1f2bf66cb2e6cd3) minified version added | ||
- [b078a6c](https://github.com/gagan-bansal/geojson2svg/commit/b078a6cc5049dfd78e5fba2fcb2a8f2044664a2d) minified version added | ||
- [1ede8f6](https://github.com/gagan-bansal/geojson2svg/commit/1ede8f695a7f51f267553edf74f6d9f1cebebae2) package ver change | ||
- [967a119](https://github.com/gagan-bansal/geojson2svg/commit/967a119781e63c4d3daf68581ad5ed308e1d6787) world example cleaned | ||
- [607ff99](https://github.com/gagan-bansal/geojson2svg/commit/607ff999549f8c846714c32c067e06c3e06b4833) switch dependant from deep-extend to xtend, all dependants version upgraded (@gagan-bansal) | ||
- [9898b51](https://github.com/gagan-bansal/geojson2svg/commit/9898b51ca509720ea550de084aafa137d9b1718b) version number changed (@gagan-bansal) | ||
- [710e964](https://github.com/gagan-bansal/geojson2svg/commit/710e96422a4175711e31467dc9ee7621f25c00f9) default svg output and web mercator extent close #4, close #5 (@gagan-bansal) | ||
- [f1f5452](https://github.com/gagan-bansal/geojson2svg/commit/f1f54526381294a962355ba4566b57fa45f0c5bd) default svg output and web mercator extent close #3, close #4 (correcting the issue number) (@gagan-bansal) | ||
- [62732f0](https://github.com/gagan-bansal/geojson2svg/commit/62732f0195280a64f96fed12d8ece2fece0c848d) color coded map example added (@gagan-bansal) | ||
- [22e471f](https://github.com/gagan-bansal/geojson2svg/commit/22e471f8861e533b332a6bc841d12c4ffce2cf99) color coded map example added (@gagan-bansal) | ||
- [6393794](https://github.com/gagan-bansal/geojson2svg/commit/63937940ed10e317a37486e1e5220cf742a7fb2b) added map examples (@gagan-bansal) | ||
- [5e9c02a](https://github.com/gagan-bansal/geojson2svg/commit/5e9c02a3a4bb418ab17a14f397bc3b174161bca4) demo map display in chrome resolved #7 (@gagan-bansal) | ||
- [1952c6a](https://github.com/gagan-bansal/geojson2svg/commit/1952c6a14aeb3e9d563188cb564dc453ea66a9f7) data display at 180 deg resolved #6 (@gagan-bansal) | ||
- [ac0324c](https://github.com/gagan-bansal/geojson2svg/commit/ac0324c371234ef1ec0168230e94bb1dbd343cde) cdnjs link added (@gagan-bansal) | ||
- [442775e](https://github.com/gagan-bansal/geojson2svg/commit/442775e5cbe279f78f522f5aef28849e23098df6) examples linked to cdnjs geojson2svg (@gagan-bansal) | ||
- [0f46d2f](https://github.com/gagan-bansal/geojson2svg/commit/0f46d2fd25940cb85ca587e9e0ed171a0b89eaf2) fit to width/height option added (@gagan-bansal) | ||
- [c27b75a](https://github.com/gagan-bansal/geojson2svg/commit/c27b75abdec1f65d3191eb6aabe566817b26cdb8) fitTo option added in README (@gagan-bansal) | ||
* Default viewport size option added [#9](https://github.com/gagan-bansal/geojson2svg/issues/9) | ||
### v0.1.0 (2015/04/28) | ||
- [185967a](https://github.com/gagan-bansal/geojson2svg/commit/185967aa13c615e705df326240fe3503972b8c85) default svg output and web mercator extent close #3, close #4 #changelog (@gagan-bansal) | ||
- [7b60f35](https://github.com/gagan-bansal/geojson2svg/commit/7b60f359b6b300d3d0b14e3895fb2d0ac661c12e) Default viewport size option added close #9 #changelog (@gagan-bansal) | ||
- [b5e1c38](https://github.com/gagan-bansal/geojson2svg/commit/b5e1c3858f6e53a31fb91539c9e30a6f7f99b8f9) Update README.md (@FearMediocrity) | ||
- [6f6bc0c](https://github.com/gagan-bansal/geojson2svg/commit/6f6bc0c1a89cbd3aeb2ddfdc0f650689ff942038) fitTo option added in README (@gagan-bansal) | ||
- [362f474](https://github.com/gagan-bansal/geojson2svg/commit/362f4748feb127132af76f41db4bdf975b54feea) fit to width/height option added (@gagan-bansal) | ||
- [78e3c75](https://github.com/gagan-bansal/geojson2svg/commit/78e3c751a4d669d75d76da328eaecc4ac866e3d6) added map examples (@gagan-bansal) | ||
- [3c5854b](https://github.com/gagan-bansal/geojson2svg/commit/3c5854bc08e156b055ccab8c2db2f55b8e296208) demo map display in chrome resolved #7 (@gagan-bansal) | ||
- [ffde512](https://github.com/gagan-bansal/geojson2svg/commit/ffde51253eb4bb73d8124a21ee4e521125ddffe3) data display at 180 deg resolved #6 (@gagan-bansal) | ||
- [ce552fb](https://github.com/gagan-bansal/geojson2svg/commit/ce552fb41206916aaa7002245ae92af2bc7974cf) cdnjs link added (@gagan-bansal) | ||
- [4fa0b51](https://github.com/gagan-bansal/geojson2svg/commit/4fa0b51fc2caf9208e51337d00c440c7666b6586) examples linked to cdnjs geojson2svg (@gagan-bansal) | ||
- [9e07f97](https://github.com/gagan-bansal/geojson2svg/commit/9e07f97c292367db8dd998a485de88cc0797d684) color coded map example added (@gagan-bansal) | ||
- [55b4727](https://github.com/gagan-bansal/geojson2svg/commit/55b47270e5744b1e64480f8a8c87f5a0581ffce3) color coded map example added (@gagan-bansal) | ||
#### 0.1.0, 2014-09-22 | ||
* Default output as svg string [#4](https://github.com/gagan-bansal/geojson2svg/issues/4) | ||
* Default maps extent as of Web Mercator [#3](https://github.com/gagan-bansal/geojson2svg/issues) | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.geojson2svg=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
define(factory); | ||
} else if (typeof exports === 'object') { | ||
module.exports = factory(); | ||
} else { | ||
root.deepmerge = factory(); | ||
} | ||
}(this, function () { | ||
return function deepmerge(target, src) { | ||
var array = Array.isArray(src); | ||
var dst = array && [] || {}; | ||
if (array) { | ||
target = target || []; | ||
dst = dst.concat(target); | ||
src.forEach(function(e, i) { | ||
if (typeof dst[i] === 'undefined') { | ||
dst[i] = e; | ||
} else if (typeof e === 'object') { | ||
dst[i] = deepmerge(target[i], e); | ||
} else { | ||
if (target.indexOf(e) === -1) { | ||
dst.push(e); | ||
} | ||
} | ||
}); | ||
} else { | ||
if (target && typeof target === 'object') { | ||
Object.keys(target).forEach(function (key) { | ||
dst[key] = target[key]; | ||
}) | ||
} | ||
Object.keys(src).forEach(function (key) { | ||
if (typeof src[key] !== 'object' || !src[key]) { | ||
dst[key] = src[key]; | ||
} | ||
else { | ||
if (!target[key]) { | ||
dst[key] = src[key]; | ||
} else { | ||
dst[key] = deepmerge(target[key], src[key]); | ||
} | ||
} | ||
}); | ||
} | ||
return dst; | ||
} | ||
})); | ||
},{}],2:[function(require,module,exports){ | ||
//index.js | ||
@@ -52,21 +106,2 @@ (function() { | ||
},{}],2:[function(require,module,exports){ | ||
module.exports = extend | ||
function extend() { | ||
var target = {} | ||
for (var i = 0; i < arguments.length; i++) { | ||
var source = arguments[i] | ||
for (var key in source) { | ||
if (source.hasOwnProperty(key)) { | ||
target[key] = source[key] | ||
} | ||
} | ||
} | ||
return target | ||
} | ||
},{}],3:[function(require,module,exports){ | ||
@@ -153,4 +188,4 @@ //converter.js | ||
},{"multigeojson":1}],4:[function(require,module,exports){ | ||
var extend = require('xtend'), | ||
},{"multigeojson":2}],4:[function(require,module,exports){ | ||
var merge = require('deepmerge'), | ||
converter = require('./converter.js'); | ||
@@ -189,3 +224,3 @@ | ||
g2svg.prototype.convert = function(geojson,options) { | ||
var opt = extend(extend({},this.options), options || {}); | ||
var opt = merge(merge({},this.options), options || {}); | ||
var multiGeometries = ['MultiPoint','MultiLineString','MultiPolygon']; | ||
@@ -216,3 +251,3 @@ var geometries = ['Point', 'LineString', 'Polygon']; | ||
if(!feature && !feature.geometry) return; | ||
var opt = extend(extend({},this.options), options || {}); | ||
var opt = merge(merge({},this.options), options || {}); | ||
opt.attributes = opt.attributes || {}; | ||
@@ -224,3 +259,3 @@ opt.attributes.id = opt.attributes.id || feature.id || null; | ||
if(converter[geom.type]) { | ||
var opt = extend(extend({},this.options), options || {}); | ||
var opt = merge(merge({},this.options), options || {}); | ||
var output = opt.output || 'svg'; | ||
@@ -283,3 +318,3 @@ var paths = converter[geom.type].call(this,geom, | ||
},{"./converter.js":3,"xtend":2}],5:[function(require,module,exports){ | ||
},{"./converter.js":3,"deepmerge":1}],5:[function(require,module,exports){ | ||
var g2svg = require('./instance.js'); | ||
@@ -286,0 +321,0 @@ var geojson2svg = function(options) { |
@@ -1,1 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.geojson2svg=e()}}(function(){return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module){!function(){function explode(g){return multies.indexOf(g.type)>-1?g.coordinates.map(function(part){var single={};return single.type=g.type.replace("Multi",""),single.coordinates=part,g.crs&&(single.crs=g.crs),single}):!1}function implode(gs){var sameType=gs.every(function(g){return singles.indexOf(g.type)>-1}),crs=gs[0].crs||0,sameCrs=gs.every(function(g){var gcrs=g.crs||0;return gcrs==crs});if(sameType&&sameCrs){var multi={};return multi.type="Multi"+gs[0].type,multi.coordinates=[],0!=crs&&(multi.crs=crs),gs.forEach(function(g){multi.coordinates.push(g.coordinates)}),multi}return!1}var singles=["Point","LineString","Polygon"],multies=["MultiPoint","MultiLineString","MultiPolygon"],multigeojson={explode:explode,implode:implode};"undefined"!=typeof module&&module.exports?module.exports=multigeojson:window&&(window.multigeojson=multigeojson)}()},{}],2:[function(require,module){function extend(){for(var target={},i=0;i<arguments.length;i++){var source=arguments[i];for(var key in source)source.hasOwnProperty(key)&&(target[key]=source[key])}return target}module.exports=extend},{}],3:[function(require,module){function getCoordString(coords,res,origin){var coordStr=coords.map(function(coord){return(coord[0]-origin.x)/res+","+(origin.y-coord[1])/res});return coordStr.join(" ")}function point(geom,res,origin,opt){var r=opt&&opt.r?opt.r:1,path="M"+getCoordString([geom.coordinates],res,origin)+" m"+-r+",0 a"+r+","+r+" 0 1,1 "+2*r+",0 a"+r+","+r+" 0 1,1 "+-2*r+",0";return[path]}function multiPoint(geom,res,origin,opt){var explode=opt&&opt.hasOwnProperty("explode")?opt.explode:!1,paths=multi.explode(geom).map(function(single){return point(single,res,origin,opt)[0]});return explode?paths:[paths.join(" ")]}function lineString(geom,res,origin){var coords=getCoordString(geom.coordinates,res,origin),path="M"+coords;return[path]}function multiLineString(geom,res,origin,opt){var explode=opt&&opt.hasOwnProperty("explode")?opt.explode:!1,paths=multi.explode(geom).map(function(single){return lineString(single,res,origin,opt)[0]});return explode?paths:[paths.join(" ")]}function polygon(geom,res,origin){var mainStr,holes;mainStr=getCoordString(geom.coordinates[0],res,origin),geom.coordinates.length>1&&(holes=geom.coordinates.slice(1,geom.coordinates.length));var path="M"+mainStr;if(holes)for(var i=0;i<holes.length;i++)path+=" M"+getCoordString(holes[i],res,origin);return path+="Z",[path]}function multiPolygon(geom,res,origin,opt){var explode=opt.hasOwnProperty("explode")?opt.explode:!1,paths=multi.explode(geom).map(function(single){return polygon(single,res,origin,opt)[0]});return explode?paths:[paths.join(" ").replace(/Z/g,"")+"Z"]}var multi=require("multigeojson");module.exports={Point:point,MultiPoint:multiPoint,LineString:lineString,MultiLineString:multiLineString,Polygon:polygon,MultiPolygon:multiPolygon}},{multigeojson:1}],4:[function(require,module){var extend=require("xtend"),converter=require("./converter.js"),g2svg=function(options){this.options=options||{},this.viewportSize=this.options.viewportSize||{width:256,height:256},this.mapExtent=this.options.mapExtent||{left:-20037508.342789244,right:20037508.342789244,bottom:-20037508.342789244,top:20037508.342789244},this.res=this.calResolution(this.mapExtent,this.viewportSize,this.options.fitTo)};g2svg.prototype.calResolution=function(extent,size,fitTo){var xres=(extent.right-extent.left)/size.width,yres=(extent.top-extent.bottom)/size.height;if(fitTo){if("width"===fitTo.toLowerCase())return xres;if("height"===fitTo.toLowerCase())return yres;throw new Error('"fitTo" option should be "width" or "height" ')}return Math.max(xres,yres)},g2svg.prototype.convert=function(geojson,options){var opt=extend(extend({},this.options),options||{}),svgElements=[];if("FeatureCollection"==geojson.type)for(var i=0;i<geojson.features.length;i++)svgElements=svgElements.concat(this.convertFeature(geojson.features[i],opt));else if("Feature"==geojson.type)svgElements=this.convertFeature(geojson,opt);else if("GeomtryCollection"==geojson.type)for(var i=0;i<geojson.geometries.length;i++)svgElements=svgElements.concat(this.convertGeometry(geojson.geometries[i],opt));else{if(!converter[geojson.type])return;svgElements=this.convertGeometry(geojson,opt)}return opt.callback&&opt.callback.call(this,svgElements),svgElements},g2svg.prototype.convertFeature=function(feature,options){if(feature||feature.geometry){var opt=extend(extend({},this.options),options||{});return opt.attributes=opt.attributes||{},opt.attributes.id=opt.attributes.id||feature.id||null,this.convertGeometry(feature.geometry,opt)}},g2svg.prototype.convertGeometry=function(geom,options){if(converter[geom.type]){var svgJsons,svgEles,opt=extend(extend({},this.options),options||{}),output=opt.output||"svg",paths=converter[geom.type].call(this,geom,this.res,{x:this.mapExtent.left,y:this.mapExtent.top},opt);return"svg"==output.toLowerCase()?(svgJsons=paths.map(function(path){return pathToSvgJson(path,geom.type,opt.attributes,opt)}),svgEles=svgJsons.map(function(json){return jsonToSvgElement(json,geom.type)})):paths}};var pathToSvgJson=function(path,type,attributes,opt){var svg={},forcePath=opt&&opt.hasOwnProperty("forcePath")?opt.forcePath:!0;"Point"!=type&&"MultiPoint"!=type||forcePath?(svg={d:path},("Polygon"==type||"MultiPolygon"==type)&&"evenodd"==svg["fill-rule"]):(svg.cx=path.split(",")[0],svg.cy=path.split(",")[1],svg.r=opt&&opt.r?opt.r:"1");for(var key in attributes)svg[key]=attributes[key];return svg},jsonToSvgElement=function(json,type,opt){var forcePath=opt&&opt.hasOwnProperty("forcePath")?opt.forcePath:!0,ele="<path";"Point"!=type&&"MultiPoint"!=type||forcePath||(ele="<circle");for(var key in json)ele+=" "+key+'="'+json[key]+'"';return ele+="/>"};module.exports=g2svg},{"./converter.js":3,xtend:2}],5:[function(require,module){var g2svg=require("./instance.js"),geojson2svg=function(options){return new g2svg(options)};module.exports=geojson2svg},{"./instance.js":4}]},{},[5])(5)}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.geojson2svg=e()}}(function(){var define;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){!function(root,factory){"function"==typeof define&&define.amd?define(factory):"object"==typeof exports?module.exports=factory():root.deepmerge=factory()}(this,function(){return function deepmerge(target,src){var array=Array.isArray(src),dst=array&&[]||{};return array?(target=target||[],dst=dst.concat(target),src.forEach(function(e,i){"undefined"==typeof dst[i]?dst[i]=e:"object"==typeof e?dst[i]=deepmerge(target[i],e):-1===target.indexOf(e)&&dst.push(e)})):(target&&"object"==typeof target&&Object.keys(target).forEach(function(key){dst[key]=target[key]}),Object.keys(src).forEach(function(key){"object"==typeof src[key]&&src[key]&&target[key]?dst[key]=deepmerge(target[key],src[key]):dst[key]=src[key]})),dst}})},{}],2:[function(require,module,exports){!function(){function explode(g){return multies.indexOf(g.type)>-1?g.coordinates.map(function(part){var single={};return single.type=g.type.replace("Multi",""),single.coordinates=part,g.crs&&(single.crs=g.crs),single}):!1}function implode(gs){var sameType=gs.every(function(g){return singles.indexOf(g.type)>-1}),crs=gs[0].crs||0,sameCrs=gs.every(function(g){var gcrs=g.crs||0;return gcrs==crs});if(sameType&&sameCrs){var multi={};return multi.type="Multi"+gs[0].type,multi.coordinates=[],0!=crs&&(multi.crs=crs),gs.forEach(function(g){multi.coordinates.push(g.coordinates)}),multi}return!1}var singles=["Point","LineString","Polygon"],multies=["MultiPoint","MultiLineString","MultiPolygon"],multigeojson={explode:explode,implode:implode};"undefined"!=typeof module&&module.exports?module.exports=multigeojson:window&&(window.multigeojson=multigeojson)}()},{}],3:[function(require,module,exports){function getCoordString(coords,res,origin){var coordStr=coords.map(function(coord){return(coord[0]-origin.x)/res+","+(origin.y-coord[1])/res});return coordStr.join(" ")}function point(geom,res,origin,opt){var r=opt&&opt.r?opt.r:1,path="M"+getCoordString([geom.coordinates],res,origin)+" m"+-r+",0 a"+r+","+r+" 0 1,1 "+2*r+",0 a"+r+","+r+" 0 1,1 "+-2*r+",0";return[path]}function multiPoint(geom,res,origin,opt){var explode=opt&&opt.hasOwnProperty("explode")?opt.explode:!1,paths=multi.explode(geom).map(function(single){return point(single,res,origin,opt)[0]});return explode?paths:[paths.join(" ")]}function lineString(geom,res,origin,otp){var coords=getCoordString(geom.coordinates,res,origin),path="M"+coords;return[path]}function multiLineString(geom,res,origin,opt){var explode=opt&&opt.hasOwnProperty("explode")?opt.explode:!1,paths=multi.explode(geom).map(function(single){return lineString(single,res,origin,opt)[0]});return explode?paths:[paths.join(" ")]}function polygon(geom,res,origin,opt){var mainStr,holes;mainStr=getCoordString(geom.coordinates[0],res,origin),geom.coordinates.length>1&&(holes=geom.coordinates.slice(1,geom.coordinates.length));var path="M"+mainStr;if(holes)for(var i=0;i<holes.length;i++)path+=" M"+getCoordString(holes[i],res,origin);return path+="Z",[path]}function multiPolygon(geom,res,origin,opt){var explode=opt.hasOwnProperty("explode")?opt.explode:!1,paths=multi.explode(geom).map(function(single){return polygon(single,res,origin,opt)[0]});return explode?paths:[paths.join(" ").replace(/Z/g,"")+"Z"]}var multi=require("multigeojson");module.exports={Point:point,MultiPoint:multiPoint,LineString:lineString,MultiLineString:multiLineString,Polygon:polygon,MultiPolygon:multiPolygon}},{multigeojson:2}],4:[function(require,module,exports){var merge=require("deepmerge"),converter=require("./converter.js"),g2svg=function(options){this.options=options||{},this.viewportSize=this.options.viewportSize||{width:256,height:256},this.mapExtent=this.options.mapExtent||{left:-20037508.342789244,right:20037508.342789244,bottom:-20037508.342789244,top:20037508.342789244},this.res=this.calResolution(this.mapExtent,this.viewportSize,this.options.fitTo)};g2svg.prototype.calResolution=function(extent,size,fitTo){var xres=(extent.right-extent.left)/size.width,yres=(extent.top-extent.bottom)/size.height;if(fitTo){if("width"===fitTo.toLowerCase())return xres;if("height"===fitTo.toLowerCase())return yres;throw new Error('"fitTo" option should be "width" or "height" ')}return Math.max(xres,yres)},g2svg.prototype.convert=function(geojson,options){var opt=merge(merge({},this.options),options||{}),svgElements=[];if("FeatureCollection"==geojson.type)for(var i=0;i<geojson.features.length;i++)svgElements=svgElements.concat(this.convertFeature(geojson.features[i],opt));else if("Feature"==geojson.type)svgElements=this.convertFeature(geojson,opt);else if("GeomtryCollection"==geojson.type)for(var i=0;i<geojson.geometries.length;i++)svgElements=svgElements.concat(this.convertGeometry(geojson.geometries[i],opt));else{if(!converter[geojson.type])return;svgElements=this.convertGeometry(geojson,opt)}return opt.callback&&opt.callback.call(this,svgElements),svgElements},g2svg.prototype.convertFeature=function(feature,options){if(feature||feature.geometry){var opt=merge(merge({},this.options),options||{});return opt.attributes=opt.attributes||{},opt.attributes.id=opt.attributes.id||feature.id||null,this.convertGeometry(feature.geometry,opt)}},g2svg.prototype.convertGeometry=function(geom,options){if(converter[geom.type]){var svgJsons,svgEles,opt=merge(merge({},this.options),options||{}),output=opt.output||"svg",paths=converter[geom.type].call(this,geom,this.res,{x:this.mapExtent.left,y:this.mapExtent.top},opt);return"svg"==output.toLowerCase()?(svgJsons=paths.map(function(path){return pathToSvgJson(path,geom.type,opt.attributes,opt)}),svgEles=svgJsons.map(function(json){return jsonToSvgElement(json,geom.type)})):paths}};var pathToSvgJson=function(path,type,attributes,opt){var svg={},forcePath=opt&&opt.hasOwnProperty("forcePath")?opt.forcePath:!0;"Point"!=type&&"MultiPoint"!=type||forcePath?(svg={d:path},("Polygon"==type||"MultiPolygon"==type)&&"evenodd"==svg["fill-rule"]):(svg.cx=path.split(",")[0],svg.cy=path.split(",")[1],svg.r=opt&&opt.r?opt.r:"1");for(var key in attributes)svg[key]=attributes[key];return svg},jsonToSvgElement=function(json,type,opt){var forcePath=opt&&opt.hasOwnProperty("forcePath")?opt.forcePath:!0,ele="<path";"Point"!=type&&"MultiPoint"!=type||forcePath||(ele="<circle");for(var key in json)ele+=" "+key+'="'+json[key]+'"';return ele+="/>"};module.exports=g2svg},{"./converter.js":3,deepmerge:1}],5:[function(require,module,exports){var g2svg=require("./instance.js"),geojson2svg=function(options){return new g2svg(options)};module.exports=geojson2svg},{"./instance.js":4}]},{},[5])(5)}); |
{ | ||
"name": "geojson2svg", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Converts geojson to svg/path string given svg viewport size and maps extent.", | ||
@@ -25,4 +25,4 @@ "main": "src/main.js", | ||
"dependencies": { | ||
"multigeojson": "~0.0.1", | ||
"xtend": "~4.0.0" | ||
"deepmerge": "^0.2.10", | ||
"multigeojson": "~0.0.1" | ||
}, | ||
@@ -29,0 +29,0 @@ "devDependencies": { |
@@ -1,2 +0,2 @@ | ||
var extend = require('xtend'), | ||
var merge = require('deepmerge'), | ||
converter = require('./converter.js'); | ||
@@ -35,3 +35,3 @@ | ||
g2svg.prototype.convert = function(geojson,options) { | ||
var opt = extend(extend({},this.options), options || {}); | ||
var opt = merge(merge({},this.options), options || {}); | ||
var multiGeometries = ['MultiPoint','MultiLineString','MultiPolygon']; | ||
@@ -62,3 +62,3 @@ var geometries = ['Point', 'LineString', 'Polygon']; | ||
if(!feature && !feature.geometry) return; | ||
var opt = extend(extend({},this.options), options || {}); | ||
var opt = merge(merge({},this.options), options || {}); | ||
opt.attributes = opt.attributes || {}; | ||
@@ -70,3 +70,3 @@ opt.attributes.id = opt.attributes.id || feature.id || null; | ||
if(converter[geom.type]) { | ||
var opt = extend(extend({},this.options), options || {}); | ||
var opt = merge(merge({},this.options), options || {}); | ||
var output = opt.output || 'svg'; | ||
@@ -73,0 +73,0 @@ var paths = converter[geom.type].call(this,geom, |
'use strict'; | ||
var testDataSets = []; | ||
var extend = require('xtend'); | ||
var merge = require('deepmerge'); | ||
var basics = ['Point', 'LineString', 'Polygon', 'MultiPoint', 'MultiLineString', | ||
@@ -19,3 +19,3 @@ 'MultiPolygon']; | ||
var options = {output:'path'}; | ||
options = extend(options,testData.options); | ||
options = merge(options,testData.options); | ||
var actualPaths = converter.convert(data.geojson,options); | ||
@@ -22,0 +22,0 @@ testPath(actualPaths,data.path,data.geojson.type,precision); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3625
429939
+ Addeddeepmerge@^0.2.10
+ Addeddeepmerge@0.2.10(transitive)
- Removedxtend@~4.0.0
- Removedxtend@4.0.2(transitive)