Skip to content

Commit

Permalink
load japan-ichiji-mesh csv data
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuque committed Feb 24, 2014
1 parent 7dee674 commit 165233f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 8 deletions.
61 changes: 58 additions & 3 deletions inner/js/data/MeshCSVLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if (!window.mobmap) { window.mobmap={}; }
this.baseLoader = new mobmap.HugeCSVLoader(inFile);
this.readMode = MeshCSVLoader.RMODE_META;
this.dataType = MeshCSVLoader.DTYPE_STATIC;
this.usingMeshCode = null;
this.meshDefinition = {
originLat: 30,
originLng: 130,
Expand Down Expand Up @@ -53,12 +54,45 @@ if (!window.mobmap) { window.mobmap={}; }

var firstCol = fields[0];
if (firstCol.indexOf('@') === 0) {
this.readDataType(firstCol);
if (this.isMetaUseMeshCode(firstCol)) {
var level = fields[1] ? parseInt(fields[1], 10) : 1;
this.setupMeshCodeMode( level );
} else {
this.readDataType(firstCol);
}
} else {
this.readMeshDefinitionFields(fields);
}
},

isMetaUseMeshCode: function(metaStr) {
var lw = metaStr.toLowerCase();
if (lw.indexOf('use-mesh-code') >= 0) {
return true;
}

return false;
},

setupMeshCodeMode: function(meshLevel) {
// Japanese mesh code mode
this.usingMeshCode = {
level: meshLevel
};

var md = this.meshDefinition;
md.originLat = 0;
md.originLng = 100;

switch(meshLevel) {
default:
// 1-ji
md.stepLat = 1.0 / 1.5;
md.stepLng = 1.0;
break;
}
},

readDataType: function(typeStr) {
// console.log("typeStr=", typeStr);
var lw = typeStr.toLowerCase();
Expand Down Expand Up @@ -99,8 +133,17 @@ if (!window.mobmap) { window.mobmap={}; }
++valueCol;
}

var latI = parseInt( fields[latIndexCol] , 10);
var lngI = parseInt( fields[lngIndexCol] , 10);
var latI, lngI;
if (!this.usingMeshCode) {
latI = parseInt( fields[latIndexCol] , 10);
lngI = parseInt( fields[lngIndexCol] , 10);
} else {
// Mesh-code mode
var meshCode = parseInt( fields[latIndexCol] , 10);
latI = this.calcLatIndexFromMeshCode(meshCode);
lngI = this.calcLngIndexFromMeshCode(meshCode);
--valueCol;
}
var val = parseFloat( fields[valueCol] );

if (this.meshDataListener &&
Expand All @@ -112,8 +155,20 @@ if (!window.mobmap) { window.mobmap={}; }
}
},

calcLatIndexFromMeshCode: function(meshCode) {
return Math.floor(meshCode / 100);
},

calcLngIndexFromMeshCode: function(meshCode) {
return meshCode % 100 ;
},

// callbacks - - - - - - - - - - - - -
csvloaderReadLine: function(fields, lineno) {
if (fields.length < 1) {
return;
}

if (this.readMode === MeshCSVLoader.RMODE_META) {
this.readMetaFields(fields);
} else {
Expand Down
8 changes: 4 additions & 4 deletions inner/js/map/MeshCanvasOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ if (!window.mobmap) { window.mobmap={}; }
var dlng = md.meshDefinition.stepLng;
var dlat = md.meshDefinition.stepLat;
var pt = _tempProjPt;

g.clearRect(0,0, this.canvasSize.w, this.canvasSize.h);
var oldSY = null;
for (var y = sy;y < nY;++y) {
for (var y = sy;y < (sy+nY);++y) {

var oldSX= null;
for (var x = sx;x < nX;++x) {
for (var x = sx;x < (sx+nX);++x) {
var sx1, sy1;
if (oldSX === null || oldSY === null) {
pt.lat = o_lat + y * dlat;
Expand All @@ -121,7 +121,7 @@ if (!window.mobmap) { window.mobmap={}; }
if (x === (nX-1)) {
oldSY = sy2;
}

var cellVal = md.pick(y, x, this.pickTime);
var cellColor = this.mapValueToCellColor(cellVal.val);
g.fillStyle = cellColor;
Expand Down
3 changes: 3 additions & 0 deletions inner/js/selection/selection-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ if (!window.mobmap) { window.mobmap={}; }

commitDraggingSelection: function() {
if (this.currentSelectionSession) {
var prj = this.ownerApp.getCurrentProject();

this.fireBeforeCommitSession(this.currentSelectionSession);
this.currentSelectionSession.makeIDCollection(prj);
}

this.disposeCurrentSession(true);
Expand Down
6 changes: 5 additions & 1 deletion inner/js/selection/selection-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ if (!window.mobmap) { window.mobmap={}; }
isRectangleFeedbackRecommended: function() {
return true;
},


makeIDCollection: function(targetProject) {

},

// - - - - - - - - - -

setStartPos: function(lat, lng) {
Expand Down
3 changes: 3 additions & 0 deletions js/mesh-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

function doTest() {
console.log("Starting test", gSourceFile);
if ( (/japanmesh/i).test(gSourceFile.name) ) {
console.log("japanmesh");
}

gMeshLoader = new mobmap.MeshCSVLoader(gSourceFile);
console.log("+ Generated loader");
Expand Down

0 comments on commit 165233f

Please sign in to comment.