Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
yopaseopor authored Dec 11, 2020
1 parent 5a0e1d1 commit fe62bf7
Showing 1 changed file with 70 additions and 61 deletions.
131 changes: 70 additions & 61 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,68 +29,77 @@ $(function () {
var layerGroup = overlay['group'],
vectorProperties = overlay,
vector;


if (overlay['geojson'] !== undefined) {
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: overlay['geojson']
})
} else {
var vectorSource = new ol.source.Vector({
format: new ol.format.OSMXML2(),
loader: function (extent, resolution, projection) {
loading.show();
var me = this;
var epsg4326Extent = ol.proj.transformExtent(extent, projection, 'EPSG:4326');
var query = '[maxsize:536870912];' + overlay['query']; // Memory limit 512 MiB
//var query = layerQuery;
query = query.replace(/{{bbox}}/g, epsg4326Extent[1] + ',' + epsg4326Extent[0] + ',' + epsg4326Extent[3] + ',' + epsg4326Extent[2]);

var client = new XMLHttpRequest();
client.open('POST', config.overpassApi());
client.onloadend = function () {
loading.hide();
};
client.onerror = function () {
console.error('[' + client.status + '] Error loading data.');
me.removeLoadedExtent(extent);
vector.setVisible(false);
};
client.onload = function () {
if (client.status === 200) {
var xmlDoc = $.parseXML(client.responseText),
xml = $(xmlDoc),
remark = xml.find('remark'),
nodosLength = xml.find('node').length;

if (remark.length !== 0) {
console.error('Error:', remark.text());
$('<div>').html(remark.text()).dialog({
modal: true,
title: 'Error',
close: function () {
$(this).dialog('destroy');
}
});
client.onerror.call(this);
} else {
console.log('Nodes Found:', nodosLength);
if (nodosLength === 0) {
$('<div>').html(config.i18n.noNodesFound).dialog({
modal: true,
//title: 'Error',
close: function () {
$(this).dialog('destroy');
}
});
}
var features = new ol.format.OSMXML2().readFeatures(xmlDoc, {
featureProjection: map.getView().getProjection()
});
me.addFeatures(features);
}
} else {
client.onerror.call(this);
}
};
client.send(query);
},
strategy: ol.loadingstrategy.bbox
});
}

var vectorSource = new ol.source.Vector({
format: new ol.format.OSMXML2(),
loader: function (extent, resolution, projection) {
loading.show();
var me = this;
var epsg4326Extent = ol.proj.transformExtent(extent, projection, 'EPSG:4326');
var query = '[maxsize:536870912];' + overlay['query']; // Memory limit 512 MiB
//var query = layerQuery;
query = query.replace(/{{bbox}}/g, epsg4326Extent[1] + ',' + epsg4326Extent[0] + ',' + epsg4326Extent[3] + ',' + epsg4326Extent[2]);

var client = new XMLHttpRequest();
client.open('POST', config.overpassApi());
client.onloadend = function () {
loading.hide();
};
client.onerror = function () {
console.error('[' + client.status + '] Error loading data.');
me.removeLoadedExtent(extent);
vector.setVisible(false);
};
client.onload = function () {
if (client.status === 200) {
var xmlDoc = $.parseXML(client.responseText),
xml = $(xmlDoc),
remark = xml.find('remark'),
nodosLength = xml.find('node').length;

if (remark.length !== 0) {
console.error('Error:', remark.text());
$('<div>').html(remark.text()).dialog({
modal: true,
title: 'Error',
close: function () {
$(this).dialog('destroy');
}
});
client.onerror.call(this);
} else {
console.log('Nodes Found:', nodosLength);
if (nodosLength === 0) {
$('<div>').html(config.i18n.noNodesFound).dialog({
modal: true,
//title: 'Error',
close: function () {
$(this).dialog('destroy');
}
});
}
var features = new ol.format.OSMXML2().readFeatures(xmlDoc, {
featureProjection: map.getView().getProjection()
});
me.addFeatures(features);
}
} else {
client.onerror.call(this);
}
};
client.send(query);
},
strategy: ol.loadingstrategy.bbox
});

vectorProperties['source'] = vectorSource;
vectorProperties['visible'] = false;
Expand Down

0 comments on commit fe62bf7

Please sign in to comment.