Skip to content

Instantly share code, notes, and snippets.

@trolleway
Created January 4, 2017 23:33
Show Gist options
  • Save trolleway/518f9ea8ea3fa3a270985b8dc29bddf5 to your computer and use it in GitHub Desktop.
Save trolleway/518f9ea8ea3fa3a270985b8dc29bddf5 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script>
function str2feature(str) {
/*
input: string "lat_deg = 54.66972|lon_deg = 25.28512|position=right|label = Вильнюс}}"
output: GeoJSON Feature { "type": "Feature", "properties": { "label": "dsfdsf", "position": "dsfdsf" }, "geometry": { "type": "Point", "coordinates": [ 30.7096, 59.8684 ] } }
*/
var lat;
reg=/lat_deg.?=(.+?)[|}]/g
var match;
while ((match = reg.exec(str)) !== null) {
lat = match[1].trim();
}
var lon;
reg=/lon_deg.?=(.+?)[|}]/g
var match;
while ((match = reg.exec(str)) !== null) {
lon = match[1].trim();
}
var position;
reg=/position.?=(.+?)[|}]/g
var match;
while ((match = reg.exec(str)) !== null) {
position = match[1].trim();
}
if (undefined === position) {
position='right'
}
var label;
reg=/label.?=(.+?)[|}]/g
var match;
while ((match = reg.exec(str)) !== null) {
label = match[1].trim();
}
if (undefined === label) {
label=''
}
var mark;
reg=/mark.?=(.+?)[|}]/g
var match;
while ((match = reg.exec(str)) !== null) {
mark = match[1].trim();
}
if (undefined === mark) {
mark=''
}
var background;
reg=/background.?=(.+?)[|}]/g
var match;
while ((match = reg.exec(str)) !== null) {
background = match[1].trim();
}
if (undefined === background) {
background=''
}
//sample: { "type": "Feature", "properties": { "label": "dsfdsf", "position": "dsfdsf" }, "geometry": { "type": "Point", "coordinates": [ 30.7096, 59.8684 ] } }
var feature;
feature='{ "type": "Feature", "properties": { "label": "'+label + '", "position": "' + position + '", "background": "' + background + '", "mark": "' + mark +
'" }, "geometry": { "type": "Point", "coordinates": [ ' + lon + ', ' + lat + ' ] } }'
return feature;
}
function LocationMap2GeoJSON(str) {
features_parts=str.match( /lat_deg.+?}}/ig )
var GeoJSON
GeoJSON = '{"type": "FeatureCollection","crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },"features": ['
var features_arr = []
var arrayLength = features_parts.length;
for (var i = 0; i < arrayLength; i++) {
str = features_parts[i];
feature = str2feature(str);
features_arr.push(feature);
}
GeoJSON = GeoJSON + features_arr.join(',') + ']}'
return GeoJSON
}
function parce() {
var str = document.getElementById("source").value
GeoJSONstr=LocationMap2GeoJSON(str);
document.getElementById("output").value = GeoJSONstr
createGeoJSONfile();
}
var textFile = null,
makeTextFile = function (text) {
var data = new Blob([text], {type: 'text/plain'});
// If we are replacing a previously generated file we need to
// manually revoke the object URL to avoid memory leaks.
if (textFile !== null) {
window.URL.revokeObjectURL(textFile);
}
textFile = window.URL.createObjectURL(data);
return textFile;
};
var create = document.getElementById('create');
//var textbox = document.getElementById('output');
function createGeoJSONfile() {
var link = document.getElementById('downloadlink');
link.href = makeTextFile(document.getElementById("output").value);
link.style.display = 'block';
var link_qml = document.getElementById('downloadlink_qml');
link_qml.style.display = 'block';
}
</script>
</head>
<body>
<h1>My First Web Page</h1>
<p>My First Paragraph</p>
<p id="demo"></p>
<TEXTAREA id = "source" NAME="address" WRAP="virtual" COLS="180" ROWS="25">
{{ПозКарта+ | Польша
| width = 666
| caption =
| places =
{{ПозКарта~ | Польша|lat_deg = 57.80413|lon_deg = 28.36232|label = Псков}}
{{ПозКарта~ | Польша|lat_deg = 54.66972|lon_deg = 25.28512|position=right|label = Вильнюс}}
{{ПозКарта~ | Польша|lat_deg = 53.68629|lon_deg = 23.84923|position=right|label = Гродно}}
{{ПозКарта~ | Польша|lat_deg = 53.13417|lon_deg = 23.13601|position=right|label = Белосток}}
{{ПозКарта~ | Польша|lat_deg = 52.25520|lon_deg = 21.03764|position=right|label = Варшава-Виленская}}
{{ПозКарта~ | Польша|lat_deg = 59.90766|lon_deg = 30.30739|position=right|label = Санкт-Петербург - Варшавский}}
{{ПозКарта~ | Польша|lat_deg = 54.64491|lon_deg = 25.04711|position=left|label = Ландварово (Лентварис)}}
{{ПозКарта~ | Польша|lat_deg = 54.63621|lon_deg = 22.73204|position=left|label = Чернышевское (Эйдкунен)}}
{{ПозКарта~ | Польша|lat_deg = 54.20933|lon_deg = 24.57518|position=left|label = Варены (Ораны)}}
{{ПозКарта~ | Польша|lat_deg = 54.10606|lon_deg = 22.94592|position=left|label = Сувалки}}
{{ПозКарта~ | Польша|lat_deg = 55.16361|lon_deg = 25.99423|position=left|label = Свенцяны (Svencioneliai)}}
{{ПозКарта~ | Польша|lat_deg = 55.13285|lon_deg = 27.67140|position=left|label = Березвечъ (Глубокое)}}
{{ПозКарта~ | Польша|lat_deg = 57.1686|lon_deg = 27.1207|position=left|label = Сита}}
{{ПозКарта~ | Польша|lat_deg = 57.06470|lon_deg = 27.91157|position=left|label = Пыталово}}
}}
</TEXTAREA><br>
<INPUT TYPE="submit" VALUE="Convert LocationMap~ to GeoJSON" onclick="parce()">
<a download="LocationMap.geojson" id="downloadlink" style="display: none">Download GeoJSON</a> <a href="" id="downloadlink_qml" style="display: none">Download qml style</a><br/>
<TEXTAREA id = "output" NAME="address" WRAP="virtual" COLS="180" ROWS="10"></TEXTAREA><br>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment