From 165233f72928cbef92f4f5a0f1ff45ab8159b238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8A=E5=B1=B1=20=E6=99=BA=E5=A3=AB?= Date: Mon, 24 Feb 2014 17:10:03 +0900 Subject: [PATCH] load japan-ichiji-mesh csv data --- inner/js/data/MeshCSVLoader.js | 61 ++++++++++++++++++++-- inner/js/map/MeshCanvasOverlay.js | 8 +-- inner/js/selection/selection-controller.js | 3 ++ inner/js/selection/selection-session.js | 6 ++- js/mesh-test.js | 3 ++ 5 files changed, 73 insertions(+), 8 deletions(-) diff --git a/inner/js/data/MeshCSVLoader.js b/inner/js/data/MeshCSVLoader.js index 987304f..277652b 100644 --- a/inner/js/data/MeshCSVLoader.js +++ b/inner/js/data/MeshCSVLoader.js @@ -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, @@ -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(); @@ -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 && @@ -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 { diff --git a/inner/js/map/MeshCanvasOverlay.js b/inner/js/map/MeshCanvasOverlay.js index e97ab10..304c219 100644 --- a/inner/js/map/MeshCanvasOverlay.js +++ b/inner/js/map/MeshCanvasOverlay.js @@ -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; @@ -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; diff --git a/inner/js/selection/selection-controller.js b/inner/js/selection/selection-controller.js index 425f1d1..caf2be8 100644 --- a/inner/js/selection/selection-controller.js +++ b/inner/js/selection/selection-controller.js @@ -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); diff --git a/inner/js/selection/selection-session.js b/inner/js/selection/selection-session.js index 7311c57..673ff2f 100644 --- a/inner/js/selection/selection-session.js +++ b/inner/js/selection/selection-session.js @@ -31,7 +31,11 @@ if (!window.mobmap) { window.mobmap={}; } isRectangleFeedbackRecommended: function() { return true; }, - + + makeIDCollection: function(targetProject) { + + }, + // - - - - - - - - - - setStartPos: function(lat, lng) { diff --git a/js/mesh-test.js b/js/mesh-test.js index 2b11018..aaec138 100644 --- a/js/mesh-test.js +++ b/js/mesh-test.js @@ -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");