-
Notifications
You must be signed in to change notification settings - Fork 113
/
files.html
65 lines (60 loc) · 2.67 KB
/
files.html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!doctype html>
<html>
<head>
<title>js-shapefile-to-geojson Demo Page</title>
<style>
html, body {
height: 100%;
width: 100%;
}
#map {
height: 400px;
background-color: #eee;
}
</style>
</head>
<body>
<a href="http://github.com/wavded/js-shapefile-to-geojson"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
<h2>js-shapefile-to-geojson Demo Page</h2>
<p>Pure client-side JavaScript (no server side code) parsing of shapefiles and dbase files to GeoJSON format displayed using OpenLayers.</p>
<div id="map"></div>
<p>View project at <a href="http://github.com/wavded/js-shapefile-to-geojson">http://github.com/wavded/js-shapefile-to-geojson</a>.
<script src="http://rs1.adc4gis.com/js/openlayers/2.9.1/OpenLayers-Proj4.js"></script>
<script src="stream.js"></script>
<script src="shapefile.js"></script>
<script src="dbf.js"></script>
<script type="text/javascript">
OpenLayers._getScriptLocation = function(){
return "http://rs1.adc4gis.com/js/openlayers/2.9.1/";
};
var map = new OpenLayers.Map("map",{allOverlays: true}),
parser = new OpenLayers.Format.GeoJSON(),
vector = new OpenLayers.Layer.Vector("Converted")
map.addLayer(vector);
var onchange = function(e) {
var shpFile = document.getElementById('shp').files[0];
var dbfFile = document.getElementById('dbf').files[0];
if (shpFile) {
var opts = { shp: shpFile };
if (dbfFile) {
opts['dbf'] = dbfFile;
}
shapefile = new Shapefile(opts, function(data){
var features = parser.read(data.geojson);
vector.addFeatures(features);
map.zoomToExtent(vector.getDataExtent());
console.log(data);
});
}
}
document.body.onload = function(){
document.getElementById('shp').addEventListener('change', onchange, false);
document.getElementById('dbf').addEventListener('change', onchange, false);
}
</script>
<br>
<br>
.shp <input id="shp" type="file" name=".shp" />
.dbf <input id="dbf" type="file" name=".dbf" />
</body>
</html>