Skip to content

Commit

Permalink
Merge pull request #193 from gtt-project/fix/wkt-history
Browse files Browse the repository at this point in the history
Fixes rendering for Linestring and Polygon
  • Loading branch information
dkastl authored Sep 13, 2022
2 parents 6559a0e + 43fe9ed commit a66161c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="dialog-geojson-upload" title="<%= l(:title_geojson_upload) %>">
<div id="dialog-geojson-upload" title="<%= l(:title_geojson_upload) %>" style="display:none;">
<textarea placeholder="<%= l(:placeholder_geojson_upload) %>" class="ui-widget ui-state-default ui-corner-all"></textarea>
<input type="file" id="file-selector" accept=".json,.geojson">
</div>
15 changes: 10 additions & 5 deletions src/components/gtt-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,23 +937,28 @@ export class GttClient {
*/
parseHistory() {
document.querySelectorAll('div#history ul.details i').forEach((item: Element) => {
const regex = new RegExp(/\w+[\s]?(\((-?\d+.\d+\s?-?\d+.\d+,?)+\))+/g)
const regex = new RegExp(/\b(?:POINT|LINESTRING|POLYGON)\b\s?(\({1,}[-]?\d+([,. ]\s?[-]?\d+)*\){1,})/gi)
const match = item.innerHTML.match(regex)
if (match !== null) {
const feature = new WKT().readFeature(
match[0], {
match.join(''), {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
}
)
const wkt = new WKT().writeFeature(
let wkt = new WKT().writeFeature(
feature, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857',
decimals: 6
decimals: 5
}
)
item.innerHTML = `<a href="#" onclick="event.preventDefault();" class="wkt">${wkt}</a>`
// Shorten long WKT's
if (wkt.length > 30) {
const parts = wkt.split(' ')
wkt = parts[0] + '...' + parts[parts.length - 1]
}
item.innerHTML = `<a href="#" onclick="event.preventDefault();" class="wkt" data-feature="${match.join('')}">${wkt}</a>`
}
})
}
Expand Down

0 comments on commit a66161c

Please sign in to comment.