-
Notifications
You must be signed in to change notification settings - Fork 41
/
world.js
38 lines (37 loc) · 1.33 KB
/
world.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var dataURLPoly = './data/countries.geo.json';
// countries data taken from https://github.com/johan/world.geo.json
getjson(dataURLPoly,drawGeoJSON);
//var dataURLPoint = './data/capitals.json';
//getjson(dataURLPoint,drawGeoJSON);
function drawGeoJSON(resp) {
var geojson = JSON.parse(resp);
// covert wgs84 data to Web Mercator projection
var geojson3857 = reproject.reproject(
geojson,'EPSG:4326','EPSG:3857',proj4.defs);
var svgMap = document.getElementById('map');
var convertor = new GeoJSON2SVG(
{
viewportSize: {width:800,height:800},
attributes: {
'style': 'stroke:#006600; fill: #F0F8FF;stroke-width:0.5px;',
'vector-effect':'non-scaling-stroke'
},
explode: false
}
);
var svgElements = convertor.convert(geojson3857);
var parser = new DOMParser();
svgElements.forEach(function(svgStr) {
var svg = parseSVG(svgStr);
svgMap.appendChild(svg);
});
}
//parseSVG from http://stackoverflow.com/questions/3642035/jquerys-append-not-working-with-svg-element
function parseSVG(s) {
var div= document.createElementNS('http://www.w3.org/1999/xhtml', 'div');
div.innerHTML= '<svg xmlns="http://www.w3.org/2000/svg">'+s+'</svg>';
var frag= document.createDocumentFragment();
while (div.firstChild.firstChild)
frag.appendChild(div.firstChild.firstChild);
return frag;
}