Skip to content

Commit a66161c

Browse files
authored
Merge pull request #193 from gtt-project/fix/wkt-history
Fixes rendering for Linestring and Polygon
2 parents 6559a0e + 43fe9ed commit a66161c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div id="dialog-geojson-upload" title="<%= l(:title_geojson_upload) %>">
1+
<div id="dialog-geojson-upload" title="<%= l(:title_geojson_upload) %>" style="display:none;">
22
<textarea placeholder="<%= l(:placeholder_geojson_upload) %>" class="ui-widget ui-state-default ui-corner-all"></textarea>
33
<input type="file" id="file-selector" accept=".json,.geojson">
44
</div>

src/components/gtt-client.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -937,23 +937,28 @@ export class GttClient {
937937
*/
938938
parseHistory() {
939939
document.querySelectorAll('div#history ul.details i').forEach((item: Element) => {
940-
const regex = new RegExp(/\w+[\s]?(\((-?\d+.\d+\s?-?\d+.\d+,?)+\))+/g)
940+
const regex = new RegExp(/\b(?:POINT|LINESTRING|POLYGON)\b\s?(\({1,}[-]?\d+([,. ]\s?[-]?\d+)*\){1,})/gi)
941941
const match = item.innerHTML.match(regex)
942942
if (match !== null) {
943943
const feature = new WKT().readFeature(
944-
match[0], {
944+
match.join(''), {
945945
dataProjection: 'EPSG:4326',
946946
featureProjection: 'EPSG:3857'
947947
}
948948
)
949-
const wkt = new WKT().writeFeature(
949+
let wkt = new WKT().writeFeature(
950950
feature, {
951951
dataProjection: 'EPSG:4326',
952952
featureProjection: 'EPSG:3857',
953-
decimals: 6
953+
decimals: 5
954954
}
955955
)
956-
item.innerHTML = `<a href="#" onclick="event.preventDefault();" class="wkt">${wkt}</a>`
956+
// Shorten long WKT's
957+
if (wkt.length > 30) {
958+
const parts = wkt.split(' ')
959+
wkt = parts[0] + '...' + parts[parts.length - 1]
960+
}
961+
item.innerHTML = `<a href="#" onclick="event.preventDefault();" class="wkt" data-feature="${match.join('')}">${wkt}</a>`
957962
}
958963
})
959964
}

0 commit comments

Comments
 (0)