Skip to content

Commit e55d6ae

Browse files
committed
Renders WKT as link and with less decimals
1 parent c1b19f8 commit e55d6ae

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

assets/javascripts/app.map.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ App.map = (function ($, publ) {
144144
this.setGeolocation();
145145
this.setGeocoding();
146146
this.zoomToExtent();
147+
this.parseHistory();
147148

148149
// Control button
149150
var maximizeCtrl = new ol.control.Button({
@@ -300,10 +301,36 @@ App.map = (function ($, publ) {
300301
}
301302
};
302303

304+
/**
305+
* Parse page for WKT strings in history
306+
*/
307+
publ.parseHistory = function () {
308+
$('div#history ul.details i').each( function (idx,item) {
309+
var regex = new RegExp(/\w+\s(\((-?\d+.\d+\s?-?\d+.\d+,?)+\))+/g);
310+
var match = $(item).text().match(regex);
311+
if (match !== null) {
312+
var feature = new ol.format.WKT().readFeature(
313+
match[0], {
314+
dataProjection: 'EPSG:4326',
315+
featureProjection: 'EPSG:3857'
316+
}
317+
);
318+
var wkt = new ol.format.WKT().writeFeature(
319+
feature, {
320+
dataProjection: 'EPSG:4326',
321+
featureProjection: 'EPSG:3857',
322+
decimals: 6
323+
}
324+
);
325+
$(item).html('<a href="#" onclick="event.preventDefault();" class="wkt">' + wkt + '</a>');
326+
}
327+
});
328+
};
329+
303330
/**
304331
* Add Geolocation functionality
305332
*/
306-
publ.setGeolocation = function (){
333+
publ.setGeolocation = function () {
307334

308335
geolocation = new ol.Geolocation({
309336
tracking: false,

0 commit comments

Comments
 (0)