sync
This commit is contained in:
@@ -22,7 +22,6 @@ export default {
|
||||
* @param {*} input
|
||||
*/
|
||||
async toBase64(input) {
|
||||
console.log(input)
|
||||
return new Promise((resolve) => {
|
||||
if (input.files.length == 0){
|
||||
resolve(null)
|
||||
@@ -52,5 +51,41 @@ export default {
|
||||
reject(error)
|
||||
};
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Read data of file/files selected in input as string
|
||||
* @param {*} input
|
||||
*/
|
||||
async read(input) {
|
||||
return new Promise((resolve) => {
|
||||
if (input.files.length == 0){
|
||||
resolve(null)
|
||||
}
|
||||
else if (input.files.length == 1){
|
||||
this.readFile(input.files[0]).then(resolve)
|
||||
}
|
||||
else
|
||||
Promise.all(Array(...input.files).map(this.readFile)).then(resolve)
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Read data of file/files selected in input as string
|
||||
* @param {*} input
|
||||
*/
|
||||
async readFile(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var reader = new FileReader();
|
||||
reader.readAsText(file);
|
||||
|
||||
reader.onload = function () {
|
||||
resolve(reader.result)
|
||||
};
|
||||
reader.onerror = function (error) {
|
||||
reject(error)
|
||||
};
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
{
|
||||
"wellhead": {
|
||||
"stroke-width": 1,
|
||||
"stroke": "#000",
|
||||
"fill": "#fff"
|
||||
"font-family": "Times New Roman",
|
||||
"font-weight": "bold",
|
||||
"stroke-width": "0.5mm",
|
||||
"font-size":"10pt",
|
||||
"stroke": "#fff",
|
||||
"fill": "#000"
|
||||
},
|
||||
"gpt": {
|
||||
"stroke-width": 0,
|
||||
"stroke": "#ff0",
|
||||
"stroke-width": 1,
|
||||
"stroke": "#000",
|
||||
"fill": "#ff0"
|
||||
},
|
||||
"opt": {
|
||||
"stroke-width": 1,
|
||||
"stroke": "#f00",
|
||||
"fill": "#00f"
|
||||
"stroke": "#000",
|
||||
"fill": "#B86B41"
|
||||
},
|
||||
"wpt": {
|
||||
"stroke-width": 1,
|
||||
"stroke": "#f00",
|
||||
"fill": "#00f"
|
||||
"stroke": "#000",
|
||||
"fill": "#67c2e5"
|
||||
}
|
||||
}
|
||||
74
src/svgmap/SvgMapParser.js
Normal file
74
src/svgmap/SvgMapParser.js
Normal file
@@ -0,0 +1,74 @@
|
||||
// import convert from 'xml-js/index.js'
|
||||
// import { XMLParser, XMLBuilder, XMLValidator} from 'fast-xml-parser'
|
||||
import { parse } from 'svg-parser'
|
||||
|
||||
// var convert = require('xml-js');
|
||||
|
||||
export default class {
|
||||
async parse(xml){
|
||||
let result1 = parse(xml);
|
||||
|
||||
this.svg = result1.children.filter(x => x.tagName =='svg')[0]
|
||||
}
|
||||
|
||||
get_layers(){
|
||||
return this.svg.children.filter(x => x.tagName == 'g')
|
||||
}
|
||||
|
||||
get_map_scale(){
|
||||
// console.log(this.svg)
|
||||
let vb = this.svg.properties.viewBox.split(' ').map(x => parseFloat(x))
|
||||
let w = this.svg.properties.width
|
||||
let h = this.svg.properties.height
|
||||
|
||||
let units = {
|
||||
'in': 25.4,
|
||||
'mm': 1,
|
||||
'cm': 10,
|
||||
'px': 0.0846646,
|
||||
// '%': 1
|
||||
}
|
||||
|
||||
const u = Object.keys(units).filter(x => w.endsWith(x))[0]
|
||||
if (!u) throw "Unsupported units"
|
||||
|
||||
w = Math.round(parseFloat(w.substring(0, w.length - u.length)) * units[u] * 100) / 100
|
||||
h = Math.round(parseFloat(h.substring(0, h.length - u.length)) * units[u] * 100) / 100
|
||||
let k = vb[2] / w
|
||||
|
||||
return {w, h, k, u}
|
||||
}
|
||||
|
||||
extract_anchor(layer){
|
||||
let w1 = this.extract_well(layer.children[layer.children.length - 1])
|
||||
let w2 = this.extract_well(layer.children[layer.children.length - 2])
|
||||
|
||||
return{w1, w2}
|
||||
}
|
||||
|
||||
_flat(node){
|
||||
if (!node.children) return [node];
|
||||
return node.children.reduce((s, c) => s.concat(this._flat(c)), [node])
|
||||
}
|
||||
|
||||
extract_well(pivot_group){
|
||||
let scale = this.get_map_scale()
|
||||
|
||||
let flat = this._flat(pivot_group)
|
||||
///// console.log('pivot_group', pivot_group.children)
|
||||
// console.log('FLAT---', flat)
|
||||
let ellipse = flat.filter(x => x.tagName =='circle' || x.tagName =='ellipse')[0]
|
||||
// console.log('ellipse', ellipse)
|
||||
let tr = ellipse.properties.transform.replace('matrix(', '').replace(')', '').split(' ').map(x => parseFloat(x))
|
||||
// console.log('tr', tr)
|
||||
// let x = ellipse.properties.transform
|
||||
// let y = ellipse.cy.baseVal.value
|
||||
|
||||
let text = flat.filter(x => x.type =='text')[0]
|
||||
// console.log('text', text)
|
||||
let name = text.value
|
||||
return {x: tr[4], y: tr[5], name}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user