Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
actually reading values from the dbf now, bad thematic mapping is go
- Loading branch information
Showing
3 changed files
with
203 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<html> | ||
<head> | ||
<title>Binary AJAX</title> | ||
<script type="text/javascript" src="binary.js"></script> | ||
<script type="text/javascript" src="shapefile.js"></script> | ||
<!--[if IE]><script src="excanvas.js"></script><![endif]--> | ||
<script type="text/javascript"> | ||
|
||
var file = "thematicmapping/TM_WORLD_BORDERS_SIMPL-0.3.shp"; | ||
|
||
window.onload = function() { | ||
var b = new BinaryAjax(file, onBinaryAjaxComplete, onBinaryAjaxFail); | ||
} | ||
|
||
function onBinaryAjaxFail() { | ||
alert('failed to load ' + file); | ||
} | ||
|
||
function onBinaryAjaxComplete(oHTTP) { | ||
var binFile = oHTTP.binaryResponse; | ||
|
||
if (window.console && window.console.log) console.log('got data, parsing shapefile'); | ||
|
||
var shpFile = new ShpFile(binFile); | ||
|
||
if (shpFile.header.shapeType != ShpType.SHAPE_POLYGON && shpFile.header.shapeType != ShpType.SHAPE_POLYLINE) { | ||
alert("Shapefile does not contain Polygon records (found type: "+shp.shapeType+")"); | ||
} | ||
|
||
//if (window.console && window.console.log) console.log(records); | ||
render(shpFile.records); | ||
} | ||
|
||
function render(records) { | ||
|
||
if (window.console && window.console.log) console.log('creating canvas and rendering'); | ||
|
||
var canvas = document.getElementById('map'); | ||
|
||
if (window.G_vmlCanvasManager) { | ||
G_vmlCanvasManager.initElement(canvas); | ||
} | ||
|
||
var t1 = new Date().getTime(); | ||
if (window.console && window.console.log) console.log('calculating bbox...'); | ||
|
||
var box; | ||
for (var i = 0; i < records.length; i++) { | ||
var record = records[i]; | ||
if (record.shapeType == ShpType.SHAPE_POLYGON || record.shapeType == ShpType.SHAPE_POLYLINE) { | ||
var shp = record.shape | ||
for (var j = 0; j < shp.rings.length; j++) { | ||
var ring = shp.rings[j]; | ||
for (var k = 0; k < ring.length; k++) { | ||
if (!box) { | ||
box = new Rectangle(ring[k].x, ring[k].y, 0, 0); | ||
} | ||
else { | ||
var l = Math.min(box.x, ring[k].x); | ||
var t = Math.min(box.y, ring[k].y); | ||
var r = Math.max(box.x+box.w, ring[k].x); | ||
var b = Math.max(box.y+box.h, ring[k].y); | ||
box.x = l; | ||
box.y = t; | ||
box.w = r-l; | ||
box.h = b-t; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
var t2 = new Date().getTime(); | ||
if (window.console && window.console.log) console.log('found bbox in ' + (t2 - t1) + ' ms'); | ||
|
||
t1 = new Date().getTime(); | ||
if (window.console && window.console.log) console.log('starting rendering...'); | ||
|
||
var ctx = canvas.getContext('2d'); | ||
|
||
var sc = Math.min(800 / box.w, 400 / box.h); | ||
|
||
ctx.fillStyle = '#ccccff'; | ||
ctx.fillRect(0,0,800,400); | ||
|
||
ctx.lineWidth = 0.5; | ||
ctx.strokeStyle = '#888888'; | ||
ctx.fillStyle = '#fff8f0'; | ||
ctx.beginPath(); | ||
for (var i = 0; i < records.length; i++) { | ||
var record = records[i]; | ||
if (record.shapeType == ShpType.SHAPE_POLYGON || record.shapeType == ShpType.SHAPE_POLYLINE) { | ||
var shp = record.shape; | ||
for (var j = 0; j < shp.rings.length; j++) { | ||
var ring = shp.rings[j]; | ||
if (ring.length < 1) continue; | ||
ctx.moveTo((ring[0].x - box.x) * sc, 400 - (ring[0].y - box.y) * sc); | ||
for (var k = 1; k < ring.length; k++) { | ||
ctx.lineTo((ring[k].x - box.x) * sc, 400 - (ring[k].y - box.y) * sc); | ||
} | ||
} | ||
} | ||
} | ||
ctx.fill(); | ||
ctx.stroke(); | ||
t2 = new Date().getTime(); | ||
if (window.console && window.console.log) console.log('done rendering in ' + (t2 - t1) + ' ms'); | ||
} | ||
|
||
</script> | ||
<style type="text/css"> | ||
body { | ||
background-color: #eee; | ||
color: #000; | ||
font: 12px sans-serif; | ||
margin: 20px; | ||
} | ||
canvas { | ||
background-color: #fff; | ||
padding: 10px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Binary Ajax Shapefile Loader</h1> | ||
<p>Loading shapefile... uninformative errors may appear in the dark crevices of your browser.</p> | ||
<canvas id="map" width="800" height="400"></canvas> | ||
<p>See <a href="http://github.com/RandomEtc/shapefile-js">http://github.com/RandomEtc/shapefile-js</a> for more details.</p> | ||
</body> | ||
</html> |