Permalink
Browse files

Project stub

  • Loading branch information...
1 parent ffe2546 commit dd78171aabc2ad071f1543d3937df8044536f1da @bjornd committed Oct 25, 2012
Showing with 260 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 .gitmodules
  3. +84 −0 app.js
  4. +107 −0 index.html
  5. +2 −0 jquery-1.8.2.min.js
  6. +1 −0 jvectormap
  7. +62 −0 map-sample.svg
View
@@ -0,0 +1 @@
+.DS_Store
View
@@ -0,0 +1,3 @@
+[submodule "jvectormap"]
+ path = jvectormap
+ url = git@github.com:bjornd/jvectormap.git
View
@@ -0,0 +1,84 @@
+var app = function(){
+ var convertSvgToMap = function(svg) {
+ var map = {};
+
+ map.width = parseInt($(svg).find('svg').attr('width'), 10);
+ map.height = parseInt($(svg).find('svg').attr('height'), 10);
+ map.paths = {};
+ $(svg).find('path').each(function(i){
+ map.paths['id'+i] = {
+ path: $(this).attr('d'),
+ name: 'name'+i
+ };
+ });
+ return map;
+ };
+
+ var createMap = function(){
+ $.fn.vectorMap('addMap', 'map', mapData);
+ return new jvm.WorldMap({
+ container: $('#settings-map'),
+ map: 'map',
+ backgroundColor: 'white',
+ regionStyle: {
+ initial: {
+ fill: '#E9AB38'
+ }
+ }
+ });
+ };
+
+ var renderTable = function(){
+ var table = '<table><tr><th>id</th><th>name</th></tr>',
+ id;
+
+ for (id in mapData.paths) {
+ table += '<tr>'+
+ '<td>'+id+'</td>'+
+ '<td>'+mapData.paths[id].name+'</td>'+
+ '</tr>';
+ }
+ table += '</table>'
+ $('#settings-table').html(table);
+ };
+
+ var CardLayout = function(cards){
+ var self = this;
+
+ this.cards = {};
+
+ cards.each(function(index){
+ var card = $(this);
+
+ if (index) {
+ card.hide();
+ } else {
+ self.currentCard = card;
+ }
+ self.cards[card.attr('id').split('-').slice(1).join('-')] = card;
+ });
+ };
+
+ CardLayout.prototype.show = function(cardName){
+ this.currentCard.hide();
+ this.cards[cardName].show();
+ this.currentCard = this.cards[cardName];
+ };
+
+ var layout = new CardLayout($('.card')),
+ mapData;
+
+ $('#input-convert').click(function(){
+ mapData = convertSvgToMap( $.parseXML($('#input-source').val()) );
+
+ layout.show('settings');
+
+ renderTable();
+ createMap();
+ });
+
+ $('#setting-save').click(function(){
+ layout.show('save');
+ $('#save-source').val( "jQuery.fn.vectorMap('addMap'," + JSON.stringify(mapData) + ");" );
+ });
+};
View
@@ -3,7 +3,114 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SVG to jVectorMap converter</title>
+ <link href="jvectormap/jquery-jvectormap.css" rel="stylesheet" media="all"/>
+ <style>
+ html, body {
+ width: 100%;
+ height: 100%;
+ padding: 0;
+ margin: 0;
+ font-family: Helvetica, sans-serif;
+ }
+
+ .card {
+ position: absolute;
+ left: 0;
+ top: 0;
+ bottom: 0;
+ right: 0;
+ margin-top: 40px;
+ margin-bottom: 40px;
+ }
+
+ .card-header {
+ position: absolute;
+ top: -40px;
+ left: 0;
+ height: 20px;
+ padding: 10px;
+ }
+
+ .card-content {
+ height: 100%;
+ }
+
+ .card-footer {
+ position: absolute;
+ bottom: -40px;
+ left: 0;
+ height: 20px;
+ padding: 10px;
+ }
+
+ #input-source {
+ position: absolute;
+ left: 0;
+ top: 0;
+ bottom: 0;
+ right: 0;
+ margin: 5px;
+ }
+
+ #save-source {
+ position: absolute;
+ left: 0;
+ top: 0;
+ bottom: 0;
+ right: 0;
+ margin: 5px;
+ }
+
+ #settings-table {
+ width: 30%;
+ height: 100%;
+ float: left;
+ }
+
+ #settings-map {
+ width: 70%;
+ height: 100%;
+ float: left;
+ }
+ </style>
+ <script src="jquery-1.8.2.min.js"></script>
+ <script src="jvectormap/jquery.jvectormap.min.js"></script>
+ <script src="app.js"></script>
+ <script>
+ $(function(){
+ $.get('map-sample.svg', function(response){
+ $('#input-source').val(response);
+ }, 'text');
+ app();
+ });
+ </script>
</head>
<body>
+ <div id="card-input" class="card">
+ <div class="card-header">Paste SVG code</div>
+ <div class="card-content">
+ <textarea id="input-source"></textarea>
+ </div>
+ <div class="card-footer">
+ <button id="input-convert">Convert to map</button>
+ </div>
+ </div>
+ <div id="card-settings" class="card">
+ <div class="card-header">Settings</div>
+ <div class="card-content">
+ <div id="settings-table"></div>
+ <div id="settings-map"></div>
+ </div>
+ <div class="card-footer">
+ <button id="setting-save">Save</button>
+ </div>
+ </div>
+ <div id="card-save" class="card">
+ <div class="card-header">Copy map source</div>
+ <div class="card-content">
+ <textarea id="save-source"></textarea>
+ </div>
+ <div class="card-footer"></div>
+ </div>
</body>
</html>
View
Oops, something went wrong.
Submodule jvectormap added at 341a05
View
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14948) -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+ width="565.5px" height="466.812px" viewBox="0 0 565.5 466.812" enable-background="new 0 0 565.5 466.812" xml:space="preserve">
+<g>
+ <path id="id1" label="label1" fill="#E9AB38" d="M489.698,447.276c18.385-10.172,34.058-23.434,47.169-39.634c13.337-16.728,22.906-35.49,28.633-56.286
+ l-73.994-20.118c-2.562,9.042-6.555,17.331-11.905,24.865c-0.829,1.206-1.808,2.336-2.712,3.542
+ c-1.055,1.356-2.185,2.637-3.315,3.843l-5.651,5.199l-1.13,0.453l-0.377-0.603c-1.13,0.979-2.336,1.959-3.466,2.938
+ c-3.466,2.637-7.083,5.049-10.926,7.234c-3.843,2.034-7.761,3.843-11.679,5.199c-1.356,0.527-2.562,0.904-3.843,1.281
+ c-0.527,0.151-0.979,0.301-1.432,0.452l-24.112-43.778l1.583,3.089l22.454,41.141c-0.452,0.075-0.904,0.226-1.356,0.301
+ c-14.769,3.089-29.085,3.24-42.949,0.302l-22.529,73.315c20.646,6.254,41.593,8.213,62.841,5.802
+ C451.722,463.552,471.313,457.298,489.698,447.276z"/>
+ <path id="id2" label="label2" fill="#C5C168" d="M400.71,94.338l-3.994-4.521c0-0.076,0-0.076-0.075-0.151l-3.843-4.445c-0.075,0-0.151,0-0.226,0
+ c-0.151,0-0.377-0.075-0.527-0.227l-5.275-5.425l-0.075,0.075c-0.151,0.226-0.227,0.302-0.452,0.302
+ c0,0.15-0.076,0.301-0.151,0.377l-10.625,11.604l-11.453,15.371c-0.151,0.151-0.226,0.377-0.376,0.528
+ c-0.151,0.226-0.227,0.376-0.377,0.527l-9.946,17.858c-0.075,0.075-0.075,0.075-0.075,0.075c-0.075,0-0.075,0.076-0.151,0.226
+ c0,0.151-0.15,0.301-0.15,0.452l-0.076,0.076c-0.075,0.15-0.15,0.301-0.226,0.452c-0.075,0.301-0.226,0.527-0.301,0.828
+ c-0.075,0.076-0.075,0.076-0.151,0.076c0,0.151-0.075,0.301-0.15,0.376l-0.075,0.076c-0.754,1.658-1.507,3.391-2.185,5.124
+ c-0.452,0.979-0.829,1.959-1.206,2.939v0.075c-0.904,2.11-1.658,4.069-2.26,6.103v-0.226l0,0c0,0.075,0,0.226,0,0.301l-0.904,2.486
+ c-0.076,0.226-0.15,0.528-0.226,0.829l0,0c-0.904,2.637-1.658,5.274-2.26,7.912c-0.753,2.637-1.356,5.274-1.884,7.912
+ c-0.753,3.542-1.356,7.158-1.733,10.775c-0.075,0.15-0.15,0.226-0.15,0.301c-0.076,0.15-0.151,0.226-0.227,0.301l-2.938,1.583
+ c-0.075,0.075-0.226,0.075-0.376,0.075c-0.076,0-0.226,0-0.377-0.075c-4.897-2.637-10.474-4.973-16.652-7.158
+ c-5.274-1.809-10.624-3.315-16.125-4.521c-3.165-0.678-6.405-1.281-9.645-1.884l-3.165-0.376v-0.076
+ c-9.645-1.356-20.345-1.583-32.099-0.904c-6.631,0.302-12.659,0.98-18.159,1.809c-0.452,0.15-0.979,0.15-1.432,0.301h0.075
+ c-13.789,2.411-27.352,6.48-40.764,12.282l-0.15-0.377c-8.515,3.542-16.803,7.836-25.092,12.81l0,0
+ c-0.377,0.15-0.603,0.301-0.829,0.527h-0.075l-0.603,0.377l-0.302,0.15c-0.075,0-0.075,0-0.075,0.075l-2.788,1.055l-38.429,124.629
+ l20.043,6.33l0.753-2.412l-0.829,2.788l0.15,0.076l36.093-116.868c0.075-0.226,0.15-0.377,0.376-0.527
+ c15.748-8.063,33.229-13.94,52.292-17.708c17.708-3.541,34.51-4.521,50.484-2.938c0.076,0.076,0.226,0.076,0.302,0.076h0.075
+ c2.336,0.226,4.747,0.527,7.007,0.829l5.802,1.055c0.376,0.075,0.904,0.15,1.356,0.226c0.301,0.075,0.678,0.151,1.055,0.227
+ l1.733,0.376c0.753,0.15,1.507,0.376,2.336,0.527l1.733,0.452c0.301,0.076,0.678,0.151,1.055,0.301
+ c5.953,1.507,11.83,3.542,17.557,5.877c0.075,0.075,0.075,0.075,0.151,0.15c0.075,0,0.151,0.151,0.226,0.227l83.864,151.905
+ l-1.583-3.089l0,0l0,0c0,0,0,0,0.076,0h-0.076l24.112,43.778c0.452-0.151,0.904-0.301,1.432-0.452
+ c1.281-0.376,2.487-0.753,3.843-1.281c3.918-1.356,7.836-3.165,11.679-5.199c3.843-2.185,7.46-4.597,10.926-7.234
+ c1.13-0.979,2.336-1.959,3.466-2.938c0.075-0.075,0.151-0.151,0.226-0.151c0-0.075,0.075-0.075,0.075-0.15l-24.037-43.477v0.076
+ h-0.075l-0.15,0.075c0-0.075,0-0.151,0.075-0.226l-83.563-151.529c-0.15-0.15-0.15-0.376-0.076-0.527
+ c2.713-10.474,6.179-20.496,10.248-30.064l0,0c0.904-2.035,1.733-4.069,2.637-6.104c6.028-13.186,12.659-24.112,19.892-32.777
+ l0.527,0.603c0.151-0.15,0.377-0.226,0.528-0.226c0.226,0,0.377,0.076,0.527,0.301l5.5,6.104l7.007-7.535l-5.35-6.179
+ c-0.226-0.226-0.301-0.377-0.226-0.603c0-0.151,0.15-0.377,0.301-0.528l-0.527-0.603C400.183,94.865,400.484,94.64,400.71,94.338z
+ M205.328,193.95l0.151,0.377c-7.008,2.562-13.714,5.5-20.194,8.816l0,0h-0.076l-0.15,0.226c0,0,0,0.075-0.075,0.15v-0.075
+ c0.075-0.226,0.226-0.301,0.376-0.452c6.48-3.24,13.111-6.179,20.043-8.741L205.328,193.95z"/>
+ <path id="id3" label="label3" fill="#0097D6" d="M126.889,143.692c0.226,0.075,0.376,0.15,0.527,0.376l22.831,39.483l-8.59,29.386h-0.076l-0.829-0.301
+ l-25.92,84.015l4.144,1.281l-3.918,12.885l-7.61-2.486l-16.125-4.22l-29.161,94.79c22.831,9.871,46.491,17.18,70.753,21.852
+ l29.311-94.865l-7.535-2.336c-0.15,0-0.753-0.226-1.582-0.678c-0.98-0.452-1.809-0.829-2.712-1.13h-0.076
+ c-0.075-0.076-0.151-0.076-0.151-0.076s0.076,0,0.151,0c0.076,0,0.151,0,0.151,0.076l0.377-0.076c0,0,0,0,0.075,0
+ c0.151,0,0-0.075-0.527-0.15c-0.302-0.075-0.678-0.226-1.13-0.302l-0.528-0.075l0.151-0.452l0.829-2.788l-0.753,2.412l-20.043-6.33
+ l38.429-124.629l2.788-1.055c0-0.075,0-0.075,0.075-0.075l0.302-0.15l11.152-28.633l-6.631-2.035
+ c-0.15-0.075-0.376-0.226-0.376-0.376c-0.15-0.226-0.15-0.376-0.075-0.603l2.034-6.782l-7.61-2.411l-3.466,10.549
+ c0,0.227-0.151,0.377-0.302,0.528c-0.226,0-0.376,0-0.603,0l-14.241-4.295c-0.151,0-0.227-0.075-0.377-0.226l-14.919-17.858
+ c-0.075-0.15-0.15-0.226-0.15-0.376c0-0.076,0-0.226,0-0.301l2.788-9.645l-56.738-16.652l-2.486,7.912
+ c-0.076,0.226-0.151,0.376-0.377,0.452c-0.075,0.075-0.151,0.075-0.302,0.15c-0.075,0-0.15,0-0.301-0.076L0.829,93.735L0,96.448
+ l34.661,10.7l-2.336,7.384l57.341,17.707l0.076,0.076h0.075l0.527,0.15h0.076L126.889,143.692z M165.694,161.173
+ c0.227,0.076,0.302,0.227,0.453,0.377c0.075,0.227,0.075,0.377,0.075,0.603l-4.069,13.713c0,0.151-0.151,0.377-0.302,0.452
+ c-0.226,0.075-0.376,0.075-0.603,0.075c-0.151-0.075-0.301-0.15-0.452-0.376l-9.795-17.707c-0.076-0.151-0.076-0.377-0.076-0.528
+ c0.076-0.226,0.227-0.377,0.377-0.527c0.226-0.075,0.376-0.075,0.603-0.075L165.694,161.173z"/>
+ <path id="id4" label="label4" fill="#747980" d="M353.089,0c-3.918,5.124-7.912,9.871-12.056,14.316l0.678,0.527c-3.692,3.692-7.761,7.384-12.282,10.926
+ l-11.905-12.96l-9.871,6.556l11.077,14.166c-4.672,3.089-9.72,6.179-14.995,9.193c-24.112,11.83-51.012,13.939-80.775,6.63
+ l-0.226-0.075l3.617-13.337L211.808,32.4l-3.617,12.96l-4.671-1.281l0.376-0.678c-10.097-3.692-20.495-8.439-31.195-14.241
+ L151.98,57.341l0.603-0.753l-17.029,24.94l1.206,0.754l-13.337,19.44l13.563,8.364l11.302-15.371l1.432-0.527
+ c99.989,52.82,186.039,33.305,258.148-58.396L353.089,0z"/>
+</g>
+</svg>

0 comments on commit dd78171

Please sign in to comment.