Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProgGis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Severin Steffensen Hjelseth
ProgGis
Commits
6ceba590
Commit
6ceba590
authored
1 year ago
by
Jakob Severin Steffensen Hjelseth
Browse files
Options
Downloads
Patches
Plain Diff
Polygon OK, ikke Line
parent
1e3df4d7
No related branches found
No related tags found
2 merge requests
!63
Dev
,
!62
Resolve "Rydd opp i riktig filformat ved opplasting av egne geojson-filer"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
javascript/fileHandler.js
+19
-6
19 additions, 6 deletions
javascript/fileHandler.js
javascript/turfFormatConverter.js
+95
-0
95 additions, 0 deletions
javascript/turfFormatConverter.js
with
114 additions
and
6 deletions
javascript/fileHandler.js
+
19
−
6
View file @
6ceba590
...
...
@@ -4,30 +4,43 @@ function handleFile() {
const
selectedFile
=
fileHandler
.
files
[
0
];
if
(
selectedFile
==
null
)
{
return
alert
(
"
No chosen file!
"
)
return
alert
(
"
No chosen file!
"
)
;
}
//console.log(selectedFile); // Printer bare selve filen til loggen
fileHandler
.
value
=
""
;
document
.
getElementById
(
"
loadButton
"
).
style
.
backgroundColor
=
"
orangered
"
;
var
read
=
new
FileReader
();
read
.
readAsDataURL
(
selectedFile
);
var
newLayer
=
L
.
geoJSON
(
null
,
{
style
:
getStyle
()})
var
newLayer
=
L
.
geoJSON
(
null
,
{
style
:
getStyle
()});
var
info
=
null
;
read
.
onloadend
=
function
()
{
fetch
(
read
.
result
).
then
(
function
(
response
)
{
return
response
.
json
();
}).
then
(
function
(
data
)
{
newLayer
.
addData
(
data
);
info
=
isInputMultiPolygon
(
data
);
if
(
info
[
0
])
{
if
(
info
[
1
]
==
"
P
"
)
{
data
=
inputMultiPolygon
(
data
);
}
else
if
(
info
[
1
]
==
"
L
"
)
{
data
=
inputMultiLine
(
data
);
}
}
console
.
log
(
JSON
.
stringify
(
data
));
//newLayer.addData(data);
})
}
/*
overlayMaps[selectedFile.name] = newLayer;
updateSidebar();
handleLayer(selectedFile.name);
*/
}
This diff is collapsed.
Click to expand it.
javascript/turfFormatConverter.js
+
95
−
0
View file @
6ceba590
...
...
@@ -33,3 +33,98 @@ function multiPolygonToFeatureCollection(layer) {
}
return
turf
.
featureCollection
(
features
);
}
/*
Håndtering av input-filer fra bruker for å få de på rett format egnet for turf-operasjoner
*/
function
isInputMultiPolygon
(
layer
)
{
liste
=
layer
[
"
features
"
];
for
(
var
i
=
0
;
i
<
liste
.
length
;
i
++
)
{
if
(
liste
[
i
][
"
geometry
"
][
"
type
"
]
==
"
MultiPolygon
"
)
{
return
[
true
,
"
P
"
];
}
else
if
(
liste
[
i
][
"
geometry
"
][
"
type
"
]
==
"
MultiLineString
"
)
{
return
[
true
,
"
L
"
];
}
}
return
[
false
,
null
];
}
function
turnList
(
liste
)
{
var
more
=
false
;
try
{
var
test
=
liste
[
0
][
0
][
0
];
if
(
test
!=
null
)
{
more
=
true
;
}
}
catch
{
more
=
false
;
}
if
(
more
)
{
var
newList
=
[];
for
(
var
i
=
0
;
i
<
layer
.
length
;
i
++
)
{
newList
.
push
(
turnList
(
liste
[
i
]));
}
}
else
{
var
newList
=
[];
for
(
var
i
=
liste
.
length
-
1
;
i
>
-
1
;
i
--
)
{
newList
.
push
(
liste
[
i
]);
}
}
return
newList
;
}
function
inputMultiPolygon
(
layer
)
{
liste
=
layer
[
"
features
"
];
k
=
liste
.
length
;
for
(
var
i
=
0
;
i
<
k
;
i
++
)
{
if
(
liste
[
i
][
"
geometry
"
][
"
coordinates
"
].
length
==
1
)
{
liste
[
i
][
"
geometry
"
][
"
type
"
]
=
"
Polygon
"
;
liste
[
i
][
"
geometry
"
][
"
coordinates
"
]
=
[
turnList
(
liste
[
i
][
"
geometry
"
][
"
coordinates
"
][
0
][
0
])];
}
else
if
(
liste
[
i
][
"
geometry
"
][
"
coordinates
"
].
length
>
1
)
{
var
coordinates
=
liste
[
i
][
"
geometry
"
][
"
coordinates
"
];
liste
[
i
][
"
geometry
"
][
"
type
"
]
=
"
Polygon
"
;
liste
[
i
][
"
geometry
"
][
"
coordinates
"
]
=
[
turnList
(
coordinates
[
0
][
0
])];
for
(
var
j
=
1
;
j
<
coordinates
.
length
;
j
++
)
{
newElement
=
{
"
type
"
:
liste
[
i
][
"
type
"
],
"
properties
"
:
liste
[
i
][
"
properties
"
],
"
geometry
"
:
{
"
type
"
:
"
Polygon
"
,
"
coordinates
"
:
[
turnList
(
coordinates
[
j
][
0
])]}};
liste
.
push
(
newElement
);
}
}
}
layer
[
"
features
"
]
=
liste
;
return
layer
;
}
function
inputMultiLine
(
layer
)
{
liste
=
layer
[
"
features
"
];
k
=
liste
.
length
;
for
(
var
i
=
0
;
i
<
k
;
i
++
)
{
if
(
liste
[
i
][
"
geometry
"
][
"
coordinates
"
].
length
==
1
)
{
liste
[
i
][
"
geometry
"
][
"
type
"
]
=
"
LineString
"
;
liste
[
i
][
"
geometry
"
][
"
coordinates
"
]
=
turnList
(
liste
[
i
][
"
geometry
"
][
"
coordinates
"
][
0
][
0
]);
}
else
if
(
liste
[
i
][
"
geometry
"
][
"
coordinates
"
].
length
>
1
)
{
var
coordinates
=
liste
[
i
][
"
geometry
"
][
"
coordinates
"
];
liste
[
i
][
"
geometry
"
][
"
type
"
]
=
"
LineString
"
;
liste
[
i
][
"
geometry
"
][
"
coordinates
"
]
=
turnList
(
coordinates
[
0
][
0
]);
for
(
var
j
=
1
;
j
<
coordinates
.
length
;
j
++
)
{
newElement
=
{
"
type
"
:
liste
[
i
][
"
type
"
],
"
properties
"
:
liste
[
i
][
"
properties
"
],
"
geometry
"
:
{
"
type
"
:
"
Polygon
"
,
"
coordinates
"
:
turnList
(
coordinates
[
j
][
0
])}};
liste
.
push
(
newElement
);
}
}
}
layer
[
"
features
"
]
=
liste
;
return
layer
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment