Skip to content
Snippets Groups Projects
Commit 2cf00bcb authored by Jakob Severin Steffensen Hjelseth's avatar Jakob Severin Steffensen Hjelseth
Browse files

Merge branch '4-gjore-drop-av-filer-mulig' into 'dev'

Resolve "Gjøre drop av filer mulig"

See merge request !10
parents 79207bd4 3867893e
No related branches found
No related tags found
2 merge requests!11From dev into main,!10Resolve "Gjøre drop av filer mulig"
...@@ -8,10 +8,6 @@ ...@@ -8,10 +8,6 @@
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" /> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script> <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<script src="https://unpkg.com/shpjs@latest/dist/shp.js"></script>
<script src="javascript/catiline.js"></script>
<script src="javascript/leaflet.shpfile.js"></script>
</head> </head>
<body class="standard"> <body class="standard">
...@@ -149,5 +145,7 @@ ...@@ -149,5 +145,7 @@
<script src="javascript/sidebar&boxes.js"></script> <script src="javascript/sidebar&boxes.js"></script>
<script src="javascript/openFileFromExplorer.js"></script> <script src="javascript/openFileFromExplorer.js"></script>
<script src="https://unpkg.com/shpjs@latest/dist/shp.js"></script>
</body> </body>
</html> </html>
This diff is collapsed.
'use strict';
/* global cw, shp */
L.Shapefile = L.GeoJSON.extend({
options: {
importUrl: 'javascript/shp.js'
},
initialize: function(file, options) {
L.Util.setOptions(this, options);
if (typeof cw !== 'undefined') {
/*eslint-disable no-new-func*/
if (!options.isArrayBuffer) {
this.worker = cw(new Function('data', 'cb', 'importScripts("' + this.options.importUrl + '");shp(data).then(cb);'));
} else {
this.worker = cw(new Function('data', 'importScripts("' + this.options.importUrl + '"); return shp.parseZip(data);'));
}
/*eslint-enable no-new-func*/
}
L.GeoJSON.prototype.initialize.call(this, {
features: []
}, options);
this.addFileData(file);
},
addFileData: function(file) {
var self = this;
this.fire('data:loading');
if (typeof file !== 'string' && !('byteLength' in file)) {
var data = this.addData(file);
this.fire('data:loaded');
return data;
}
if (!this.worker) {
shp(file).then(function(data) {
self.addData(data);
self.fire('data:loaded');
}).catch(function(err) {
self.fire('data:error', err);
})
return this;
}
var promise;
if (this.options.isArrayBufer) {
promise = this.worker.data(file, [file]);
} else {
promise = this.worker.data(cw.makeUrl(file));
}
promise.then(function(data) {
self.addData(data);
self.fire('data:loaded');
self.worker.close();
}).then(function() {}, function(err) {
self.fire('data:error', err);
})
return this;
}
});
L.shapefile = function(a, b, c) {
return new L.Shapefile(a, b, c);
};
...@@ -8,25 +8,9 @@ function clickMe() { ...@@ -8,25 +8,9 @@ function clickMe() {
dialog.addEventListener("input", () => { dialog.addEventListener("input", () => {
if (dialog.files.length) { if (dialog.files.length) {
for (i = 0; i < dialog.files.length; i++) { for (i = 0; i < dialog.files.length; i++) {
document.getElementById("layers").innerHTML = dialog.files[i].name; var file = shp(dialog.files[i].name);
L.geoJSON().addData(file).addTo(map);
document.getElementById("layers").innerHTML += "Hei!";
} }
} }
}); });
var geo = L.geoJson({features:[]}, {
onEachFeature: function popUp(f, l) {
var out = [];
if (f.properties){
for(var key in f.properties){
out.push(key + ": " + f.properties[key]);
}
l.bindPopup(out.join("<br />"));
}
}
}).addTo(map);
var base = 'vann.zip';
shp(base).then(function(data){
geo.addData(data);
});
This diff is collapsed.
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment