Added code for building data files
This commit is contained in:
@@ -112,6 +112,8 @@ struct CurrentAreaSearch {
|
||||
};
|
||||
|
||||
// Data
|
||||
// For backwards compatibility, default code is EPSG:32633 (UTM zone 33)
|
||||
char const *epsgCode = "EPSG:32633";
|
||||
RoadNodeSet set;
|
||||
SearchResult lastSearchResult;
|
||||
std::set<uint32_t> excludedNodes;
|
||||
@@ -214,10 +216,29 @@ void loadData(std::string filePath) {
|
||||
addLinkToRoadNode(set.roadNodes, fromPoint, toPoint, speedLimit, motorway, tunnel, passableSameDirection, passableOppositeDirection);
|
||||
addLinkToRoadNode(set.roadNodes, toPoint, fromPoint, speedLimit, motorway, tunnel, passableOppositeDirection, passableSameDirection);
|
||||
}
|
||||
|
||||
// Finally, check if the file contains a string describing the EPSG code of its coordinates. For backwards compatibility, this
|
||||
// field may not be there
|
||||
source.read(buffer, 4);
|
||||
if (!source.eof()) {
|
||||
uint32_t lengthOfString = ntohl(*reinterpret_cast<uint32_t*>(buffer));
|
||||
// I think it is technically a memory leak to create this buffer without eventually destroying it, but it should
|
||||
// only happen once, and it's tiny, so I don't care.
|
||||
char* stringBuffer = new char[lengthOfString+1];
|
||||
source.read(stringBuffer, lengthOfString);
|
||||
*(stringBuffer + lengthOfString) = 0;
|
||||
|
||||
epsgCode = stringBuffer;
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
// Get the EPSG code
|
||||
std::string getEpsgCode() {
|
||||
return std::string(epsgCode);
|
||||
}
|
||||
|
||||
// Search functions
|
||||
JSNodeInfo findClosestNode(float positionX, float positionY) {
|
||||
float closestDistance = 1e99;
|
||||
@@ -1002,6 +1023,7 @@ EMSCRIPTEN_BINDINGS(my_module) {
|
||||
emscripten::register_vector<AreaSearchEntry>("AreaSearchEntries");
|
||||
|
||||
emscripten::function("loadData", &loadData);
|
||||
emscripten::function("getEpsgCode", &getEpsgCode);
|
||||
emscripten::function("findClosestNode", &findClosestNode);
|
||||
emscripten::function("findAllPathsFromPoint", &findAllPathsFromPointJS);
|
||||
emscripten::function("getPath", &getPathJS);
|
||||
|
||||
Reference in New Issue
Block a user