Compare commits
No commits in common. "v0.1.8.1" and "master" have entirely different histories.
7
.babelrc
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"plugins": ["transform-class-properties"],
|
||||
"presets": [
|
||||
"@babel/preset-env",
|
||||
"@babel/preset-react"
|
||||
]
|
||||
}
|
90
.clang-format
Normal file
@ -0,0 +1,90 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlinesLeft: false
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: true
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterClass: true
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
IndentBraces: true
|
||||
BreakBeforeBinaryOperators: false
|
||||
BreakBeforeBraces: Allman
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
ColumnLimit: 100
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
|
||||
IncludeCategories:
|
||||
- Regex: '^<'
|
||||
Priority: 3
|
||||
- Regex: '^"(osrm|util|engine|extract|contract)/'
|
||||
Priority: 2
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
IndentCaseLabels: false
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp11
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
...
|
||||
|
101
.clang-tidy
Normal file
@ -0,0 +1,101 @@
|
||||
---
|
||||
Checks: >
|
||||
bugprone-*,
|
||||
-bugprone-narrowing-conversions,
|
||||
-bugprone-easily-swappable-parameters,
|
||||
-bugprone-branch-clone,
|
||||
-bugprone-misplaced-widening-cast,
|
||||
-bugprone-exception-escape,
|
||||
-bugprone-implicit-widening-of-multiplication-result,
|
||||
-bugprone-integer-division,
|
||||
-bugprone-reserved-identifier,
|
||||
-bugprone-unhandled-self-assignment,
|
||||
-bugprone-forward-declaration-namespace,
|
||||
-bugprone-sizeof-expression,
|
||||
-bugprone-throw-keyword-missing,
|
||||
-bugprone-chained-comparison,
|
||||
-bugprone-incorrect-enable-if,
|
||||
-bugprone-switch-missing-default-case,
|
||||
-bugprone-empty-catch,
|
||||
-bugprone-unchecked-optional-access,
|
||||
-clang-analyzer-*,
|
||||
-clang-diagnostic-deprecated-declarations,
|
||||
-clang-diagnostic-constant-conversion,
|
||||
cppcoreguidelines-avoid-goto,
|
||||
cppcoreguidelines-no-malloc,
|
||||
cppcoreguidelines-virtual-class-destructor,
|
||||
google-*,
|
||||
-google-build-explicit-make-pair,
|
||||
-google-build-using-namespace,
|
||||
-google-explicit-constructor,
|
||||
-google-default-arguments,
|
||||
-google-readability-braces-around-statements,
|
||||
-google-readability-casting,
|
||||
-google-readability-namespace-comments,
|
||||
-google-readability-function,
|
||||
-google-readability-todo,
|
||||
-google-runtime-int,
|
||||
-google-build-namespaces,
|
||||
-google-runtime-references,
|
||||
-google-readability-function-size,
|
||||
llvm-*,
|
||||
-llvm-namespace-comment,
|
||||
-llvm-qualified-auto,
|
||||
-llvm-include-order,
|
||||
-llvm-else-after-return,
|
||||
-llvm-header-guard,
|
||||
-llvm-twine-local,
|
||||
misc-*,
|
||||
-misc-argument-comment,
|
||||
-misc-const-correctness,
|
||||
-misc-non-private-member-variables-in-classes,
|
||||
-misc-unconventional-assign-operator,
|
||||
-misc-no-recursion,
|
||||
-misc-misplaced-const,
|
||||
-misc-definitions-in-headers,
|
||||
-misc-unused-parameters,
|
||||
-misc-include-cleaner,
|
||||
modernize-concat-nested-namespaces,
|
||||
modernize-use-using,
|
||||
performance-*,
|
||||
-performance-no-int-to-ptr,
|
||||
-performance-enum-size,
|
||||
-performance-avoid-endl,
|
||||
readability-*,
|
||||
-readability-avoid-const-params-in-decls,
|
||||
-readability-braces-around-statements,
|
||||
-readability-container-size-empty,
|
||||
-readability-convert-member-functions-to-static,
|
||||
-readability-const-return-type,
|
||||
-readability-function-cognitive-complexity,
|
||||
-readability-function-size,
|
||||
-readability-identifier-naming,
|
||||
-readability-implicit-bool-conversion,
|
||||
-readability-magic-numbers,
|
||||
-readability-else-after-return,
|
||||
-readability-inconsistent-declaration-parameter-name,
|
||||
-readability-isolate-declaration,
|
||||
-readability-identifier-length,
|
||||
-readability-redundant-declaration,
|
||||
-readability-uppercase-literal-suffix,
|
||||
-readability-named-parameter,
|
||||
-readability-qualified-auto,
|
||||
-readability-suspicious-call-argument,
|
||||
-readability-redundant-access-specifiers,
|
||||
-readability-redundant-member-init,
|
||||
-readability-static-definition-in-anonymous-namespace,
|
||||
-readability-use-anyofallof,
|
||||
-readability-simplify-boolean-expr,
|
||||
-readability-make-member-function-const,
|
||||
-readability-redundant-string-init,
|
||||
-readability-non-const-parameter,
|
||||
-readability-redundant-inline-specifier,
|
||||
-readability-avoid-nested-conditional-operator,
|
||||
-readability-avoid-return-with-void-value,
|
||||
-readability-redundant-casting,
|
||||
-readability-static-accessed-through-instance
|
||||
|
||||
WarningsAsErrors: '*'
|
||||
HeaderFilterRegex: '.*'
|
||||
|
||||
|
14
.cncc.style
Normal file
@ -0,0 +1,14 @@
|
||||
# Kind-specific patterns to check AST nodes against. Both python-clang and
|
||||
# libclang docs explain CursorKind, with differences in detail. See also:
|
||||
# - https://github.com/llvm-mirror/clang/blob/aca4fe314a55cacae29e1548cb7bfd2119c6df4c/bindings/python/clang/cindex.py#L599
|
||||
# - http://clang.llvm.org/doxygen/group__CINDEX.html#gaaccc432245b4cd9f2d470913f9ef0013
|
||||
# - https://docs.python.org/2/library/re.html#regular-expression-syntax
|
||||
|
||||
class_decl: '^([A-Z]+[a-z]+)+$'
|
||||
struct_decl: '^([A-Z]+[a-z]+)+$'
|
||||
field_decl: '^[a-z_]+$'
|
||||
var_decl: '^[a-z]+[a-z0-9_]*$'
|
||||
parm_decl: '^[a-z]*[a-z0-9_]*$'
|
||||
namespace: '^[a-z_]*$'
|
||||
cxx_method: '^([A-Z]+[a-z]+)+$'
|
||||
function_decl: '^[a-z]+([A-Z]+[a-z]+)*$'
|
2
.dockerignore
Normal file
@ -0,0 +1,2 @@
|
||||
test
|
||||
build
|
30
.editorconfig
Normal file
@ -0,0 +1,30 @@
|
||||
# EditorConfig is awesome: http://EditorConfig.org
|
||||
#
|
||||
# NOTE: Keep settings in sync with the master .clang-format file
|
||||
#
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# CMake configuration files
|
||||
[{CMakeLists.txt,CMakeSettings.json,*.cmake}]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# CI configuration files
|
||||
[{.travis.yml,appveyor.yml}]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# Unix shell scripts
|
||||
[*.sh]
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# Windows shell scripts
|
||||
[*.bat]
|
||||
end_of_line = crlf
|
||||
indent_style = space
|
||||
trim_trailing_whitespace = true
|
2
.eslintignore
Normal file
@ -0,0 +1,2 @@
|
||||
features/support/flatbuffers.js
|
||||
features/support/fbresult_generated.js
|
28
.eslintrc
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"rules": {
|
||||
"indent": [
|
||||
2,
|
||||
4
|
||||
],
|
||||
"quotes": [
|
||||
1,
|
||||
"single"
|
||||
],
|
||||
"linebreak-style": [
|
||||
2,
|
||||
"unix"
|
||||
],
|
||||
"semi": [
|
||||
2,
|
||||
"always"
|
||||
],
|
||||
"no-console": [
|
||||
1
|
||||
]
|
||||
},
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": "eslint:recommended"
|
||||
}
|
18
.gitattributes
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
# Set the default behavior, in case people don't have core.autocrlf set.
|
||||
* text=auto
|
||||
|
||||
# Explicitly declare text files you want to always be normalized and converted
|
||||
# to native line endings on checkout.
|
||||
*.cpp text
|
||||
*.hpp text
|
||||
|
||||
# Declare files that will always have CRLF line endings on checkout.
|
||||
*.bat text eol=crlf
|
||||
*.cmd text eol=crlf
|
||||
*.ps1 text eol=crlf
|
||||
|
||||
# Declare files that will always have LF line endings on checkout.
|
||||
*.sh text eol=lf
|
||||
|
||||
# https://eslint.org/docs/latest/rules/linebreak-style#using-this-rule-with-version-control-systems
|
||||
*.js text eol=lf
|
65
.gitea/workflows/publish-container.yaml
Normal file
@ -0,0 +1,65 @@
|
||||
name: Build and Publish Docker Image
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published, prereleased]
|
||||
|
||||
env:
|
||||
IMAGE_NAME: openharbor/osrm-backend
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
strategy:
|
||||
matrix:
|
||||
docker-base-image: ["debian", "alpine"]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v4
|
||||
with:
|
||||
images: ${{ env.IMAGE_NAME }}
|
||||
|
||||
- name: Docker meta - debug
|
||||
id: metadebug
|
||||
uses: docker/metadata-action@v4
|
||||
with:
|
||||
images: ${{ env.IMAGE_NAME }}
|
||||
flavor: |
|
||||
latest=true
|
||||
suffix=-debug,onlatest=true
|
||||
|
||||
- name: Log in to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
|
||||
|
||||
- name: Build and push debug image
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/riscv64
|
||||
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
|
||||
tags: ${{ steps.metadebug.outputs.tags }}
|
||||
build-args: |
|
||||
DOCKER_TAG=${{ join(steps.metadebug.outputs.tags) }}-${{ matrix.docker-base-image }}
|
||||
|
||||
- name: Build and push normal image
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/riscv64
|
||||
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
build-args: |
|
||||
DOCKER_TAG=${{ join(steps.meta.outputs.tags) }}-${{ matrix.docker-base-image }}
|
30
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
---
|
||||
name: Bug Report
|
||||
about: Report issue with osrm-backend
|
||||
labels: Bug Report
|
||||
---
|
||||
|
||||
# Issue
|
||||
|
||||
Please describe the issue you are seeing with OSRM.
|
||||
Images are a good way to illustrate your problem.
|
||||
|
||||
**Note**: If your issue relates to the demo site (https://map.project-osrm.org) or routing provided on openstreetmap.org, be aware that they use separate [profile settings](https://github.com/fossgis-routing-server/cbf-routing-profiles) from those provided by default in `osrm-backend`.
|
||||
If your issue relates to the demo site or openstreetmap.org behaviour, please check these profiles first to see if they explain the behaviour before creating an issue here.
|
||||
|
||||
# Steps to reproduce
|
||||
|
||||
Please provide the steps required to reproduce your problem.
|
||||
- `osrm-backend` version being used
|
||||
- OSM extract that was processed
|
||||
- Processing commands (e.g. CH vs MLD processing)
|
||||
- Server queries
|
||||
|
||||
If you're reporting an issue with https://map.project-osrm.org, please provide a link to the problematic request.
|
||||
|
||||
# Specifications
|
||||
|
||||
Please provide details of your development environment.
|
||||
- Library/dependency versions
|
||||
- Operating system
|
||||
- Hardware
|
10
.github/ISSUE_TEMPLATE/feature.md
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
name: Feature Request
|
||||
about: Request a new feature in osrm-backend
|
||||
labels: Feature Request
|
||||
---
|
||||
|
||||
# Feature
|
||||
|
||||
Please describe the feature you would like to see in OSRM.
|
||||
Images are often a good way to illustrate your requested feature.
|
19
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# Issue
|
||||
|
||||
What issue is this PR targeting? If there is no issue that addresses the problem, please open a corresponding issue and link it here.
|
||||
|
||||
Please read our [documentation](https://github.com/Project-OSRM/osrm-backend/blob/master/docs/releasing.md) on release and version management.
|
||||
If your PR is still work in progress please attach the relevant label.
|
||||
|
||||
## Tasklist
|
||||
|
||||
- [ ] CHANGELOG.md entry ([How to write a changelog entry](http://keepachangelog.com/en/1.0.0/#how))
|
||||
- [ ] update relevant [Wiki pages](https://github.com/Project-OSRM/osrm-backend/wiki)
|
||||
- [ ] add tests (see [testing documentation](https://github.com/Project-OSRM/osrm-backend/blob/master/docs/testing.md))
|
||||
- [ ] review
|
||||
- [ ] adjust for comments
|
||||
- [ ] cherry pick to release branch
|
||||
|
||||
## Requirements / Relations
|
||||
|
||||
Link any requirements here. Other pull requests this PR is based on?
|
84
.github/workflows/osrm-backend-docker.yml
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
name: build and publish container image
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
strategy:
|
||||
matrix:
|
||||
docker-base-image: ["debian", "alpine"]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: ghcr.io/${{ github.repository }}
|
||||
|
||||
- name: Docker meta - debug
|
||||
id: metadebug
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: ghcr.io/${{ github.repository }}
|
||||
flavor: |
|
||||
latest=true
|
||||
suffix=-debug,onlatest=true
|
||||
|
||||
- name: Docker meta - assertions
|
||||
id: metaassertions
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: ghcr.io/${{ github.repository }}
|
||||
flavor: |
|
||||
latest=true
|
||||
suffix=-assertions,onlatest=true
|
||||
|
||||
- name: Log in to GitHub Docker Registry
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build container image - debug
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
|
||||
tags: ${{ steps.metadebug.outputs.tags }}
|
||||
build-args: |
|
||||
DOCKER_TAG=${{ join(steps.metadebug.outputs.tags ) }}-${{ matrix.docker-base-image }}
|
||||
|
||||
|
||||
- name: Build container image - assertions
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
|
||||
tags: ${{ steps.metaassertions.outputs.tags }}
|
||||
build-args: |
|
||||
DOCKER_TAG=${{ join(steps.metaassertions.outputs.tags ) }}-${{ matrix.docker-base-image }}
|
||||
|
||||
# build and publish "normal" image as last to get it listed on top
|
||||
- name: Build container image - normal
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
build-args: |
|
||||
DOCKER_TAG=${{ join(steps.meta.outputs.tags ) }}-${{ matrix.docker-base-image }}
|
786
.github/workflows/osrm-backend.yml
vendored
Normal file
@ -0,0 +1,786 @@
|
||||
name: osrm-backend CI
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
tags:
|
||||
- v[1-9]+.[0-9]+.[0-9]+
|
||||
- v[1-9]+.[0-9]+.[0-9]+-[a-zA-Z]+.[0-9]+
|
||||
- v[1-9]+.[0-9]+-[0-9a-zA-Z]+
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
env:
|
||||
CCACHE_TEMPDIR: /tmp/.ccache-temp
|
||||
CCACHE_COMPRESS: 1
|
||||
CASHER_TIME_OUT: 599 # one second less than 10m to avoid 10m timeout error: https://github.com/Project-OSRM/osrm-backend/issues/2742
|
||||
CMAKE_VERSION: 3.21.2
|
||||
ENABLE_NODE_BINDINGS: "ON"
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
windows-release-node:
|
||||
needs: format-taginfo-docs
|
||||
runs-on: windows-2022
|
||||
continue-on-error: false
|
||||
env:
|
||||
BUILD_TYPE: Release
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: pip install "conan<2.0.0"
|
||||
- run: conan --version
|
||||
- run: cmake --version
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
- run: node --version
|
||||
- run: npm --version
|
||||
- name: Prepare environment
|
||||
shell: bash
|
||||
run: |
|
||||
PACKAGE_JSON_VERSION=$(node -e "console.log(require('./package.json').version)")
|
||||
echo PUBLISH=$([[ "${GITHUB_REF:-}" == "refs/tags/v${PACKAGE_JSON_VERSION}" ]] && echo "On" || echo "Off") >> $GITHUB_ENV
|
||||
- run: npm install --ignore-scripts
|
||||
- run: npm link --ignore-scripts
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_CONAN=ON -DENABLE_NODE_BINDINGS=ON ..
|
||||
cmake --build . --config Release
|
||||
|
||||
# TODO: MSVC goes out of memory when building our tests
|
||||
# - name: Run tests
|
||||
# shell: bash
|
||||
# run: |
|
||||
# cd build
|
||||
# cmake --build . --config Release --target tests
|
||||
# # TODO: run tests
|
||||
# - name: Run node tests
|
||||
# shell: bash
|
||||
# run: |
|
||||
# ./lib/binding/osrm-extract.exe -p profiles/car.lua test/data/monaco.osm.pbf
|
||||
|
||||
# mkdir -p test/data/ch
|
||||
# cp test/data/monaco.osrm* test/data/ch/
|
||||
# ./lib/binding/osrm-contract.exe test/data/ch/monaco.osrm
|
||||
|
||||
# ./lib/binding/osrm-datastore.exe test/data/ch/monaco.osrm
|
||||
# node test/nodejs/index.js
|
||||
- name: Build Node package
|
||||
shell: bash
|
||||
run: ./scripts/ci/node_package.sh
|
||||
- name: Publish Node package
|
||||
if: ${{ env.PUBLISH == 'On' }}
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
allowUpdates: true
|
||||
artifactErrorsFailBuild: true
|
||||
artifacts: build/stage/**/*.tar.gz
|
||||
omitBody: true
|
||||
omitBodyDuringUpdate: true
|
||||
omitName: true
|
||||
omitNameDuringUpdate: true
|
||||
replacesArtifacts: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
format-taginfo-docs:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
- name: Enable Node.js cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-node-
|
||||
- name: Prepare environment
|
||||
run: |
|
||||
npm ci --ignore-scripts
|
||||
clang-format-15 --version
|
||||
- name: Run checks
|
||||
run: |
|
||||
./scripts/check_taginfo.py taginfo.json profiles/car.lua
|
||||
./scripts/format.sh && ./scripts/error_on_dirty.sh
|
||||
node ./scripts/validate_changelog.js
|
||||
npm run docs && ./scripts/error_on_dirty.sh
|
||||
npm audit --production
|
||||
|
||||
docker-image-matrix:
|
||||
strategy:
|
||||
matrix:
|
||||
docker-base-image: ["debian", "alpine"]
|
||||
needs: format-taginfo-docs
|
||||
runs-on: ubuntu-22.04
|
||||
continue-on-error: false
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v4
|
||||
- name: Enable osm.pbf cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: berlin-latest.osm.pbf
|
||||
key: v1-berlin-osm-pbf
|
||||
restore-keys: |
|
||||
v1-berlin-osm-pbf
|
||||
- name: Docker build
|
||||
run: |
|
||||
docker build -t osrm-backend-local -f docker/Dockerfile-${{ matrix.docker-base-image }} .
|
||||
- name: Test Docker image
|
||||
run: |
|
||||
if [ ! -f "${PWD}/berlin-latest.osm.pbf" ]; then
|
||||
wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf
|
||||
fi
|
||||
TAG=osrm-backend-local
|
||||
# when `--memory-swap` value equals `--memory` it means container won't use swap
|
||||
# see https://docs.docker.com/config/containers/resource_constraints/#--memory-swap-details
|
||||
MEMORY_ARGS="--memory=1g --memory-swap=1g"
|
||||
docker run $MEMORY_ARGS -t -v "${PWD}:/data" "${TAG}" osrm-extract --dump-nbg-graph -p /opt/car.lua /data/berlin-latest.osm.pbf
|
||||
docker run $MEMORY_ARGS -t -v "${PWD}:/data" "${TAG}" osrm-components /data/berlin-latest.osrm.nbg /data/berlin-latest.geojson
|
||||
if [ ! -s "${PWD}/berlin-latest.geojson" ]
|
||||
then
|
||||
>&2 echo "No berlin-latest.geojson found"
|
||||
exit 1
|
||||
fi
|
||||
# removing `.osrm.nbg` to check that whole pipeline works without it
|
||||
rm -rf "${PWD}/berlin-latest.osrm.nbg"
|
||||
|
||||
docker run $MEMORY_ARGS -t -v "${PWD}:/data" "${TAG}" osrm-partition /data/berlin-latest.osrm
|
||||
docker run $MEMORY_ARGS -t -v "${PWD}:/data" "${TAG}" osrm-customize /data/berlin-latest.osrm
|
||||
docker run $MEMORY_ARGS --name=osrm-container -t -p 5000:5000 -v "${PWD}:/data" "${TAG}" osrm-routed --algorithm mld /data/berlin-latest.osrm &
|
||||
curl --retry-delay 3 --retry 10 --retry-all-errors "http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true"
|
||||
docker stop osrm-container
|
||||
|
||||
build-test-publish:
|
||||
needs: format-taginfo-docs
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- name: gcc-13-debug-cov
|
||||
continue-on-error: false
|
||||
node: 20
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TOOLS: ON
|
||||
BUILD_TYPE: Debug
|
||||
CCOMPILER: gcc-13
|
||||
CUCUMBER_TIMEOUT: 20000
|
||||
CXXCOMPILER: g++-13
|
||||
ENABLE_COVERAGE: ON
|
||||
|
||||
- name: clang-18-debug-asan-ubsan
|
||||
continue-on-error: false
|
||||
node: 20
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TOOLS: ON
|
||||
BUILD_TYPE: Debug
|
||||
CCOMPILER: clang-18
|
||||
CUCUMBER_TIMEOUT: 20000
|
||||
CXXCOMPILER: clang++-18
|
||||
ENABLE_SANITIZER: ON
|
||||
TARGET_ARCH: x86_64-asan-ubsan
|
||||
OSRM_CONNECTION_RETRIES: 10
|
||||
OSRM_CONNECTION_EXP_BACKOFF_COEF: 1.5
|
||||
|
||||
- name: clang-18-release
|
||||
continue-on-error: false
|
||||
node: 18
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TOOLS: ON
|
||||
BUILD_TYPE: Release
|
||||
CCOMPILER: clang-18
|
||||
CXXCOMPILER: clang++-18
|
||||
CUCUMBER_TIMEOUT: 60000
|
||||
ENABLE_LTO: OFF
|
||||
|
||||
- name: clang-18-debug
|
||||
continue-on-error: false
|
||||
node: 18
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TOOLS: ON
|
||||
BUILD_TYPE: Debug
|
||||
CCOMPILER: clang-18
|
||||
CXXCOMPILER: clang++-18
|
||||
CUCUMBER_TIMEOUT: 60000
|
||||
ENABLE_LTO: OFF
|
||||
|
||||
- name: clang-18-debug-clang-tidy
|
||||
continue-on-error: false
|
||||
node: 18
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TOOLS: ON
|
||||
BUILD_TYPE: Debug
|
||||
CCOMPILER: clang-18
|
||||
CXXCOMPILER: clang++-18
|
||||
CUCUMBER_TIMEOUT: 60000
|
||||
ENABLE_CLANG_TIDY: ON
|
||||
|
||||
|
||||
- name: clang-17-release
|
||||
continue-on-error: false
|
||||
node: 18
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TOOLS: ON
|
||||
BUILD_TYPE: Release
|
||||
CCOMPILER: clang-17
|
||||
CXXCOMPILER: clang++-17
|
||||
CUCUMBER_TIMEOUT: 60000
|
||||
ENABLE_LTO: OFF
|
||||
|
||||
- name: clang-16-release
|
||||
continue-on-error: false
|
||||
node: 18
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TOOLS: ON
|
||||
BUILD_TYPE: Release
|
||||
CCOMPILER: clang-16
|
||||
CXXCOMPILER: clang++-16
|
||||
CUCUMBER_TIMEOUT: 60000
|
||||
ENABLE_LTO: OFF
|
||||
|
||||
- name: conan-linux-debug-asan-ubsan
|
||||
continue-on-error: false
|
||||
node: 18
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TOOLS: ON
|
||||
BUILD_TYPE: Release
|
||||
CCOMPILER: clang-18
|
||||
CXXCOMPILER: clang++-18
|
||||
ENABLE_CONAN: ON
|
||||
ENABLE_SANITIZER: ON
|
||||
ENABLE_LTO: OFF
|
||||
|
||||
- name: conan-linux-release
|
||||
continue-on-error: false
|
||||
node: 18
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TOOLS: ON
|
||||
BUILD_TYPE: Release
|
||||
CCOMPILER: clang-18
|
||||
CXXCOMPILER: clang++-18
|
||||
ENABLE_CONAN: ON
|
||||
ENABLE_LTO: OFF
|
||||
|
||||
- name: gcc-14-release
|
||||
continue-on-error: false
|
||||
node: 20
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TOOLS: ON
|
||||
BUILD_TYPE: Release
|
||||
CCOMPILER: gcc-14
|
||||
CXXCOMPILER: g++-14
|
||||
CXXFLAGS: '-Wno-array-bounds -Wno-uninitialized'
|
||||
|
||||
- name: gcc-13-release
|
||||
continue-on-error: false
|
||||
node: 20
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TOOLS: ON
|
||||
BUILD_TYPE: Release
|
||||
CCOMPILER: gcc-13
|
||||
CXXCOMPILER: g++-13
|
||||
CXXFLAGS: '-Wno-array-bounds -Wno-uninitialized'
|
||||
|
||||
- name: gcc-12-release
|
||||
continue-on-error: false
|
||||
node: 20
|
||||
runs-on: ubuntu-22.04
|
||||
BUILD_TOOLS: ON
|
||||
BUILD_TYPE: Release
|
||||
CCOMPILER: gcc-12
|
||||
CXXCOMPILER: g++-12
|
||||
CXXFLAGS: '-Wno-array-bounds -Wno-uninitialized'
|
||||
|
||||
- name: conan-linux-release-node
|
||||
build_node_package: true
|
||||
continue-on-error: false
|
||||
node: 20
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TYPE: Release
|
||||
CCOMPILER: clang-16
|
||||
CXXCOMPILER: clang++-16
|
||||
ENABLE_CONAN: ON
|
||||
NODE_PACKAGE_TESTS_ONLY: ON
|
||||
|
||||
- name: conan-linux-debug-node
|
||||
build_node_package: true
|
||||
continue-on-error: false
|
||||
node: 20
|
||||
runs-on: ubuntu-24.04
|
||||
BUILD_TYPE: Debug
|
||||
CCOMPILER: clang-16
|
||||
CXXCOMPILER: clang++-16
|
||||
ENABLE_CONAN: ON
|
||||
NODE_PACKAGE_TESTS_ONLY: ON
|
||||
|
||||
- name: conan-macos-x64-release-node
|
||||
build_node_package: true
|
||||
continue-on-error: true
|
||||
node: 20
|
||||
runs-on: macos-13 # x86_64
|
||||
BUILD_TYPE: Release
|
||||
CCOMPILER: clang
|
||||
CXXCOMPILER: clang++
|
||||
CUCUMBER_TIMEOUT: 60000
|
||||
ENABLE_ASSERTIONS: ON
|
||||
ENABLE_CONAN: ON
|
||||
|
||||
- name: conan-macos-arm64-release-node
|
||||
build_node_package: true
|
||||
continue-on-error: true
|
||||
node: 20
|
||||
runs-on: macos-14 # arm64
|
||||
BUILD_TYPE: Release
|
||||
CCOMPILER: clang
|
||||
CXXCOMPILER: clang++
|
||||
CUCUMBER_TIMEOUT: 60000
|
||||
ENABLE_ASSERTIONS: ON
|
||||
ENABLE_CONAN: ON
|
||||
|
||||
name: ${{ matrix.name}}
|
||||
continue-on-error: ${{ matrix.continue-on-error }}
|
||||
runs-on: ${{ matrix.runs-on }}
|
||||
env:
|
||||
BUILD_TOOLS: ${{ matrix.BUILD_TOOLS }}
|
||||
BUILD_TYPE: ${{ matrix.BUILD_TYPE }}
|
||||
BUILD_SHARED_LIBS: ${{ matrix.BUILD_SHARED_LIBS }}
|
||||
CCOMPILER: ${{ matrix.CCOMPILER }}
|
||||
CFLAGS: ${{ matrix.CFLAGS }}
|
||||
CUCUMBER_TIMEOUT: ${{ matrix.CUCUMBER_TIMEOUT }}
|
||||
CXXCOMPILER: ${{ matrix.CXXCOMPILER }}
|
||||
CXXFLAGS: ${{ matrix.CXXFLAGS }}
|
||||
ENABLE_ASSERTIONS: ${{ matrix.ENABLE_ASSERTIONS }}
|
||||
ENABLE_CLANG_TIDY: ${{ matrix.ENABLE_CLANG_TIDY }}
|
||||
ENABLE_COVERAGE: ${{ matrix.ENABLE_COVERAGE }}
|
||||
ENABLE_CONAN: ${{ matrix.ENABLE_CONAN }}
|
||||
ENABLE_SANITIZER: ${{ matrix.ENABLE_SANITIZER }}
|
||||
NODE_PACKAGE_TESTS_ONLY: ${{ matrix.NODE_PACKAGE_TESTS_ONLY }}
|
||||
TARGET_ARCH: ${{ matrix.TARGET_ARCH }}
|
||||
OSRM_CONNECTION_RETRIES: ${{ matrix.OSRM_CONNECTION_RETRIES }}
|
||||
OSRM_CONNECTION_EXP_BACKOFF_COEF: ${{ matrix.OSRM_CONNECTION_EXP_BACKOFF_COEF }}
|
||||
ENABLE_LTO: ${{ matrix.ENABLE_LTO }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build machine architecture
|
||||
run: uname -m
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
- name: Enable Node.js cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-node-
|
||||
- name: Enable compiler cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.ccache
|
||||
key: ccache-${{ matrix.name }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
ccache-${{ matrix.name }}-
|
||||
- name: Enable Conan cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.conan
|
||||
key: v9-conan-${{ matrix.name }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
v9-conan-${{ matrix.name }}-
|
||||
- name: Enable test cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{github.workspace}}/test/cache
|
||||
key: v4-test-${{ matrix.name }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
v4-test-${{ matrix.name }}-
|
||||
- name: Prepare environment
|
||||
run: |
|
||||
echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
|
||||
mkdir -p $HOME/.ccache
|
||||
|
||||
PACKAGE_JSON_VERSION=$(node -e "console.log(require('./package.json').version)")
|
||||
echo PUBLISH=$([[ "${GITHUB_REF:-}" == "refs/tags/v${PACKAGE_JSON_VERSION}" ]] && echo "On" || echo "Off") >> $GITHUB_ENV
|
||||
echo "OSRM_INSTALL_DIR=${GITHUB_WORKSPACE}/install-osrm" >> $GITHUB_ENV
|
||||
echo "OSRM_BUILD_DIR=${GITHUB_WORKSPACE}/build-osrm" >> $GITHUB_ENV
|
||||
if [[ "$ENABLE_SANITIZER" == 'ON' ]]; then
|
||||
# We can only set this after checkout once we know the workspace directory
|
||||
echo "LSAN_OPTIONS=print_suppressions=0:suppressions=${GITHUB_WORKSPACE}/scripts/ci/leaksanitizer.conf" >> $GITHUB_ENV
|
||||
echo "UBSAN_OPTIONS=symbolize=1:halt_on_error=1:print_stacktrace=1:suppressions=${GITHUB_WORKSPACE}/scripts/ci/undefinedsanitizer.conf" >> $GITHUB_ENV
|
||||
echo "ASAN_OPTIONS=print_suppressions=0:suppressions=${GITHUB_WORKSPACE}/scripts/ci/addresssanitizer.conf" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
if [[ "${RUNNER_OS}" == "Linux" ]]; then
|
||||
echo "JOBS=$((`nproc` + 1))" >> $GITHUB_ENV
|
||||
elif [[ "${RUNNER_OS}" == "macOS" ]]; then
|
||||
echo "JOBS=$((`sysctl -n hw.ncpu` + 1))" >> $GITHUB_ENV
|
||||
fi
|
||||
# See: https://github.com/actions/toolkit/issues/946#issuecomment-1590016041
|
||||
# We need it to be able to access system folders while restoring cached Boost below
|
||||
- name: Give tar root ownership
|
||||
if: runner.os == 'Linux' && matrix.ENABLE_CONAN != 'ON'
|
||||
run: sudo chown root /bin/tar && sudo chmod u+s /bin/tar
|
||||
- name: Cache Boost
|
||||
if: runner.os == 'Linux' && matrix.ENABLE_CONAN != 'ON'
|
||||
id: cache-boost
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
/usr/local/include/boost
|
||||
/usr/local/lib/libboost*
|
||||
key: v1-boost-${{ runner.os }}-${{ runner.arch }}-${{ matrix.runs-on }}
|
||||
restore-keys: |
|
||||
v1-boost-${{ runner.os }}-${{ runner.arch }}-${{ matrix.runs-on }}
|
||||
|
||||
- name: Install Boost
|
||||
if: steps.cache-boost.outputs.cache-hit != 'true' && runner.os == 'Linux' && matrix.ENABLE_CONAN != 'ON'
|
||||
run: |
|
||||
BOOST_VERSION="1.85.0"
|
||||
BOOST_VERSION_FLAVOR="${BOOST_VERSION}-b2-nodocs"
|
||||
wget -q https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION_FLAVOR}.tar.gz
|
||||
tar xzf boost-${BOOST_VERSION_FLAVOR}.tar.gz
|
||||
cd boost-${BOOST_VERSION}
|
||||
sudo ./bootstrap.sh
|
||||
sudo ./b2 install
|
||||
cd ..
|
||||
sudo rm -rf boost-${BOOST_VERSION}*
|
||||
|
||||
- name: Install dev dependencies
|
||||
run: |
|
||||
python3 -m pip install "conan<2.0.0" || python3 -m pip install "conan<2.0.0" --break-system-packages
|
||||
|
||||
# workaround for issue that GitHub Actions seems to not adding it to PATH after https://github.com/actions/runner-images/pull/6499
|
||||
# and that's why CI cannot find conan executable installed above
|
||||
if [[ "${RUNNER_OS}" == "macOS" ]]; then
|
||||
echo "/Library/Frameworks/Python.framework/Versions/Current/bin" >> $GITHUB_PATH
|
||||
fi
|
||||
|
||||
# ccache
|
||||
if [[ "${RUNNER_OS}" == "Linux" ]]; then
|
||||
sudo apt-get update -y && sudo apt-get install ccache
|
||||
elif [[ "${RUNNER_OS}" == "macOS" ]]; then
|
||||
brew install ccache
|
||||
fi
|
||||
|
||||
# Linux dev packages
|
||||
if [ "${ENABLE_CONAN}" != "ON" ]; then
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y libbz2-dev libxml2-dev libzip-dev liblua5.2-dev
|
||||
if [[ "${CCOMPILER}" != clang-* ]]; then
|
||||
sudo apt-get install -y ${CXXCOMPILER}
|
||||
fi
|
||||
if [[ "${ENABLE_COVERAGE}" == "ON" ]]; then
|
||||
sudo apt-get install -y lcov
|
||||
fi
|
||||
fi
|
||||
|
||||
# TBB
|
||||
TBB_VERSION=2021.12.0
|
||||
if [[ "${RUNNER_OS}" == "Linux" ]]; then
|
||||
TBB_URL="https://github.com/oneapi-src/oneTBB/releases/download/v${TBB_VERSION}/oneapi-tbb-${TBB_VERSION}-lin.tgz"
|
||||
elif [[ "${RUNNER_OS}" == "macOS" ]]; then
|
||||
TBB_URL="https://github.com/oneapi-src/oneTBB/releases/download/v${TBB_VERSION}/oneapi-tbb-${TBB_VERSION}-mac.tgz"
|
||||
fi
|
||||
wget --tries 5 ${TBB_URL} -O onetbb.tgz
|
||||
tar zxvf onetbb.tgz
|
||||
sudo cp -a oneapi-tbb-${TBB_VERSION}/lib/. /usr/local/lib/
|
||||
sudo cp -a oneapi-tbb-${TBB_VERSION}/include/. /usr/local/include/
|
||||
- name: Add Clang 18 to list of Conan compilers # workaround for the issue that Conan 1.x doesn't know about Clang 18
|
||||
if: ${{ matrix.ENABLE_CONAN == 'ON' && matrix.CCOMPILER == 'clang-18' }}
|
||||
run: |
|
||||
sudo wget https://github.com/mikefarah/yq/releases/download/v4.9.6/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq
|
||||
|
||||
conan config init
|
||||
yq eval '.compiler.clang.version += ["18"]' -i "$HOME/.conan/settings.yml"
|
||||
- name: Add Apple-clang 16 to list of Conan compilers # workaround for the issue that Conan 1.x doesn't know about Apple-clang 16
|
||||
if: ${{ matrix.ENABLE_CONAN == 'ON' && matrix.runs-on == 'macos-14' }}
|
||||
run: |
|
||||
sudo wget https://github.com/mikefarah/yq/releases/download/v4.9.6/yq_darwin_arm64 -O /usr/local/bin/yq && sudo chmod +x /usr/local/bin/yq
|
||||
|
||||
conan config init
|
||||
yq eval '.compiler.apple-clang.version += ["16.0"]' -i "$HOME/.conan/settings.yml"
|
||||
- name: Prepare build
|
||||
run: |
|
||||
mkdir ${OSRM_BUILD_DIR}
|
||||
ccache --max-size=256M
|
||||
npm ci --ignore-scripts
|
||||
if [[ "${ENABLE_COVERAGE}" == "ON" ]]; then
|
||||
lcov --directory . --zerocounters # clean cached files
|
||||
fi
|
||||
echo "CC=${CCOMPILER}" >> $GITHUB_ENV
|
||||
echo "CXX=${CXXCOMPILER}" >> $GITHUB_ENV
|
||||
if [[ "${RUNNER_OS}" == "macOS" ]]; then
|
||||
# missing from GCC path, needed for conan builds of libiconv, for example.
|
||||
sudo xcode-select --switch /Library/Developer/CommandLineTools
|
||||
echo "LIBRARY_PATH=${LIBRARY_PATH}:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib" >> $GITHUB_ENV
|
||||
echo "CPATH=${CPATH}:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Build and install OSRM
|
||||
run: |
|
||||
echo "Using ${JOBS} jobs"
|
||||
pushd ${OSRM_BUILD_DIR}
|
||||
|
||||
ccache --zero-stats
|
||||
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
|
||||
-DENABLE_CONAN=${ENABLE_CONAN:-OFF} \
|
||||
-DENABLE_ASSERTIONS=${ENABLE_ASSERTIONS:-OFF} \
|
||||
-DENABLE_CLANG_TIDY=${ENABLE_CLANG_TIDY:-OFF} \
|
||||
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS:-OFF} \
|
||||
-DENABLE_COVERAGE=${ENABLE_COVERAGE:-OFF} \
|
||||
-DENABLE_NODE_BINDINGS=${ENABLE_NODE_BINDINGS:-OFF} \
|
||||
-DENABLE_SANITIZER=${ENABLE_SANITIZER:-OFF} \
|
||||
-DBUILD_TOOLS=${BUILD_TOOLS:-OFF} \
|
||||
-DENABLE_CCACHE=ON \
|
||||
-DENABLE_LTO=${ENABLE_LTO:-ON} \
|
||||
-DCMAKE_INSTALL_PREFIX=${OSRM_INSTALL_DIR}
|
||||
make --jobs=${JOBS}
|
||||
|
||||
if [[ "${NODE_PACKAGE_TESTS_ONLY}" != "ON" ]]; then
|
||||
make tests --jobs=${JOBS}
|
||||
make benchmarks --jobs=${JOBS}
|
||||
|
||||
sudo make install
|
||||
if [[ "${RUNNER_OS}" == "Linux" ]]; then
|
||||
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${OSRM_INSTALL_DIR}/lib" >> $GITHUB_ENV
|
||||
fi
|
||||
echo "PKG_CONFIG_PATH=${OSRM_INSTALL_DIR}/lib/pkgconfig" >> $GITHUB_ENV
|
||||
fi
|
||||
popd
|
||||
- name: Build example
|
||||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY != 'ON' }}
|
||||
run: |
|
||||
mkdir example/build && pushd example/build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
|
||||
make --jobs=${JOBS}
|
||||
popd
|
||||
- name: Run all tests
|
||||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY != 'ON' }}
|
||||
run: |
|
||||
make -C test/data benchmark
|
||||
|
||||
# macOS SIP strips the linker path. Reset this inside the running shell
|
||||
export LD_LIBRARY_PATH=${{ env.LD_LIBRARY_PATH }}
|
||||
./example/build/osrm-example test/data/mld/monaco.osrm
|
||||
|
||||
# All tests assume to be run from the build directory
|
||||
pushd ${OSRM_BUILD_DIR}
|
||||
for i in ./unit_tests/*-tests ; do echo Running $i ; $i ; done
|
||||
if [ -z "${ENABLE_SANITIZER}" ]; then
|
||||
npm run nodejs-tests
|
||||
fi
|
||||
popd
|
||||
npm test
|
||||
|
||||
- name: Use Node 18
|
||||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
- name: Run Node package tests on Node 18
|
||||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' }}
|
||||
run: |
|
||||
node --version
|
||||
npm run nodejs-tests
|
||||
- name: Use Node 20
|
||||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
- name: Run Node package tests on Node 20
|
||||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' }}
|
||||
run: |
|
||||
node --version
|
||||
npm run nodejs-tests
|
||||
- name: Use Node latest
|
||||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: latest
|
||||
- name: Run Node package tests on Node-latest
|
||||
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' }}
|
||||
run: |
|
||||
node --version
|
||||
npm run nodejs-tests
|
||||
|
||||
- name: Upload test logs
|
||||
uses: actions/upload-artifact@v4
|
||||
if: failure()
|
||||
with:
|
||||
name: logs
|
||||
path: test/logs/
|
||||
|
||||
# - name: Generate code coverage
|
||||
# if: ${{ matrix.ENABLE_COVERAGE == 'ON' }}
|
||||
# run: |
|
||||
# lcov --directory . --capture --output-file coverage.info # capture coverage info
|
||||
# lcov --remove coverage.info '/usr/*' --output-file coverage.info # filter out system
|
||||
# lcov --list coverage.info #debug info
|
||||
|
||||
# # Uploading report to CodeCov
|
||||
# - name: Upload code coverage
|
||||
# if: ${{ matrix.ENABLE_COVERAGE == 'ON' }}
|
||||
# uses: codecov/codecov-action@v4
|
||||
# with:
|
||||
# files: coverage.info
|
||||
# name: codecov-osrm-backend
|
||||
# fail_ci_if_error: true
|
||||
# verbose: true
|
||||
- name: Build Node package
|
||||
if: ${{ matrix.build_node_package }}
|
||||
run: ./scripts/ci/node_package.sh
|
||||
- name: Publish Node package
|
||||
if: ${{ matrix.build_node_package && env.PUBLISH == 'On' }}
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
allowUpdates: true
|
||||
artifactErrorsFailBuild: true
|
||||
artifacts: build/stage/**/*.tar.gz
|
||||
omitBody: true
|
||||
omitBodyDuringUpdate: true
|
||||
omitName: true
|
||||
omitNameDuringUpdate: true
|
||||
replacesArtifacts: true
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Show CCache statistics
|
||||
run: |
|
||||
ccache -p
|
||||
ccache -s
|
||||
|
||||
benchmarks:
|
||||
if: github.event_name == 'pull_request'
|
||||
needs: [format-taginfo-docs]
|
||||
runs-on: self-hosted
|
||||
env:
|
||||
CCOMPILER: clang-16
|
||||
CXXCOMPILER: clang++-16
|
||||
CC: clang-16
|
||||
CXX: clang++-16
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
GITHUB_REPOSITORY: ${{ github.repository }}
|
||||
RUN_BIG_BENCHMARK: ${{ contains(github.event.pull_request.labels.*.name, 'Performance') }}
|
||||
steps:
|
||||
- name: Checkout PR Branch
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
path: pr
|
||||
- name: Activate virtualenv
|
||||
run: |
|
||||
python3 -m venv .venv
|
||||
source .venv/bin/activate
|
||||
echo PATH=$PATH >> $GITHUB_ENV
|
||||
pip install "conan<2.0.0" "requests==2.31.0" "numpy==1.26.4"
|
||||
- name: Prepare data
|
||||
run: |
|
||||
if [ "$RUN_BIG_BENCHMARK" = "true" ]; then
|
||||
rm -rf ~/data.osm.pbf
|
||||
wget http://download.geofabrik.de/europe/poland-latest.osm.pbf -O ~/data.osm.pbf --quiet
|
||||
gunzip -c ./pr/test/data/poland_gps_traces.csv.gz > ~/gps_traces.csv
|
||||
else
|
||||
if [ ! -f "~/data.osm.pbf" ]; then
|
||||
wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf -O ~/data.osm.pbf
|
||||
else
|
||||
echo "Using cached data.osm.pbf"
|
||||
fi
|
||||
gunzip -c ./pr/test/data/berlin_gps_traces.csv.gz > ~/gps_traces.csv
|
||||
fi
|
||||
- name: Prepare environment
|
||||
run: |
|
||||
echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
|
||||
mkdir -p $HOME/.ccache
|
||||
ccache --zero-stats
|
||||
ccache --max-size=256M
|
||||
- name: Checkout Base Branch
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.base.ref }}
|
||||
path: base
|
||||
- name: Build Base Branch
|
||||
run: |
|
||||
cd base
|
||||
npm ci --ignore-scripts
|
||||
cd ..
|
||||
mkdir base/build
|
||||
cd base/build
|
||||
cmake -DENABLE_CONAN=ON -DCMAKE_BUILD_TYPE=Release -DENABLE_NODE_BINDINGS=ON ..
|
||||
make -j$(nproc)
|
||||
make -j$(nproc) benchmarks
|
||||
cd ..
|
||||
make -C test/data
|
||||
- name: Build PR Branch
|
||||
run: |
|
||||
cd pr
|
||||
npm ci --ignore-scripts
|
||||
cd ..
|
||||
mkdir -p pr/build
|
||||
cd pr/build
|
||||
cmake -DENABLE_CONAN=ON -DCMAKE_BUILD_TYPE=Release -DENABLE_NODE_BINDINGS=ON ..
|
||||
make -j$(nproc)
|
||||
make -j$(nproc) benchmarks
|
||||
cd ..
|
||||
make -C test/data
|
||||
# we run benchmarks in tmpfs to avoid impact of disk IO
|
||||
- name: Create folder for tmpfs
|
||||
run: |
|
||||
# if by any chance it was mounted before(e.g. due to previous job failed), unmount it
|
||||
sudo umount ~/benchmarks | true
|
||||
rm -rf ~/benchmarks
|
||||
mkdir -p ~/benchmarks
|
||||
# see https://llvm.org/docs/Benchmarking.html
|
||||
- name: Run PR Benchmarks
|
||||
run: |
|
||||
sudo cset shield -c 2-3 -k on
|
||||
sudo mount -t tmpfs -o size=4g none ~/benchmarks
|
||||
cp -rf pr/build ~/benchmarks/build
|
||||
cp -rf pr/lib ~/benchmarks/lib
|
||||
mkdir -p ~/benchmarks/test
|
||||
cp -rf pr/test/data ~/benchmarks/test/data
|
||||
cp -rf pr/profiles ~/benchmarks/profiles
|
||||
|
||||
sudo cset shield --exec -- ./pr/scripts/ci/run_benchmarks.sh -f ~/benchmarks -r $(pwd)/pr_results -s $(pwd)/pr -b ~/benchmarks/build -o ~/data.osm.pbf -g ~/gps_traces.csv
|
||||
sudo umount ~/benchmarks
|
||||
sudo cset shield --reset
|
||||
- name: Run Base Benchmarks
|
||||
run: |
|
||||
sudo cset shield -c 2-3 -k on
|
||||
sudo mount -t tmpfs -o size=4g none ~/benchmarks
|
||||
cp -rf base/build ~/benchmarks/build
|
||||
cp -rf base/lib ~/benchmarks/lib
|
||||
mkdir -p ~/benchmarks/test
|
||||
cp -rf base/test/data ~/benchmarks/test/data
|
||||
cp -rf base/profiles ~/benchmarks/profiles
|
||||
|
||||
# TODO: remove it when base branch will have this file at needed location
|
||||
if [ ! -f ~/benchmarks/test/data/portugal_to_korea.json ]; then
|
||||
cp base/src/benchmarks/portugal_to_korea.json ~/benchmarks/test/data/portugal_to_korea.json
|
||||
fi
|
||||
# we intentionally use scripts from PR branch to be able to update them and see results in the same PR
|
||||
sudo cset shield --exec -- cset shield --exec -- ./pr/scripts/ci/run_benchmarks.sh -f ~/benchmarks -r $(pwd)/base_results -s $(pwd)/pr -b ~/benchmarks/build -o ~/data.osm.pbf -g ~/gps_traces.csv
|
||||
sudo umount ~/benchmarks
|
||||
sudo cset shield --reset
|
||||
- name: Post Benchmark Results
|
||||
run: |
|
||||
python3 pr/scripts/ci/post_benchmark_results.py base_results pr_results
|
||||
- name: Show CCache statistics
|
||||
run: |
|
||||
ccache -p
|
||||
ccache -s
|
||||
|
||||
ci-complete:
|
||||
runs-on: ubuntu-22.04
|
||||
needs: [build-test-publish, docker-image-matrix, windows-release-node, benchmarks]
|
||||
steps:
|
||||
- run: echo "CI complete"
|
||||
|
29
.github/workflows/stale.yml
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
name: 'Close stale issues'
|
||||
on:
|
||||
# NOTE: uncomment if you want to test changes to this file in PRs CI
|
||||
# pull_request:
|
||||
# branches:
|
||||
# - master
|
||||
schedule:
|
||||
- cron: '30 1 * * *' # every day at 1:30am
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/stale@v9
|
||||
with:
|
||||
operations-per-run: 3000
|
||||
stale-issue-message: 'This issue seems to be stale. It will be closed in 30 days if no further activity occurs.'
|
||||
stale-pr-message: 'This PR seems to be stale. Is it still relevant?'
|
||||
days-before-issue-stale: 180 # 6 months
|
||||
days-before-issue-close: 30 # 1 month
|
||||
days-before-pr-stale: 180 # 6 months
|
||||
days-before-pr-close: -1 # never close PRs
|
||||
exempt-issue-labels: 'Do Not Stale,Feature Request,Performance,Bug Report,CI,Starter Task,Refactor,Guidance'
|
||||
|
||||
|
||||
|
109
.gitignore
vendored
@ -1,2 +1,107 @@
|
||||
/.settings
|
||||
/.project
|
||||
# pre compiled dependencies #
|
||||
#############################
|
||||
osrm-deps
|
||||
|
||||
.ycm_extra_conf.py
|
||||
|
||||
# Compiled source #
|
||||
###################
|
||||
*.com
|
||||
*.class
|
||||
*.dll
|
||||
*.exe
|
||||
*.o
|
||||
*.so
|
||||
|
||||
# Packages #
|
||||
############
|
||||
# it's better to unpack these files and commit the raw source
|
||||
# git has its own built in compression methods
|
||||
*.7z
|
||||
*.dmg
|
||||
*.gz
|
||||
*.iso
|
||||
*.jar
|
||||
*.rar
|
||||
*.tar
|
||||
*.zip
|
||||
|
||||
# Logs and databases #
|
||||
######################
|
||||
*.log
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
# OS generated files #
|
||||
######################
|
||||
.DS_Store
|
||||
ehthumbs.db
|
||||
Icon?
|
||||
Thumbs.db
|
||||
|
||||
# build related files #
|
||||
#######################
|
||||
/_build*
|
||||
/build/
|
||||
/example/build/
|
||||
/test/data/monaco.osrm*
|
||||
/test/data/ch
|
||||
/test/data/mld
|
||||
/cmake/postinst
|
||||
|
||||
# Eclipse related files #
|
||||
#########################
|
||||
.setting*
|
||||
.scb
|
||||
.cproject
|
||||
.project
|
||||
|
||||
# Visual Studio (Code) related files #
|
||||
######################################
|
||||
/.vs*
|
||||
/*.local.bat
|
||||
/CMakeSettings.json
|
||||
/.cache
|
||||
|
||||
# Jetbrains related files #
|
||||
###########################
|
||||
.idea/
|
||||
|
||||
# Compiled Binary Files #
|
||||
####################################
|
||||
/osrm-extract
|
||||
/osrm-io-benchmark
|
||||
/osrm-components
|
||||
/osrm-routed
|
||||
/osrm-datastore
|
||||
/osrm-prepare
|
||||
/osrm-unlock-all
|
||||
/osrm-cli
|
||||
/osrm-check-hsgr
|
||||
/osrm-springclean
|
||||
/nohup.out
|
||||
|
||||
# Sandbox folder #
|
||||
###################
|
||||
/sandbox/
|
||||
|
||||
# Test related files #
|
||||
######################
|
||||
/test/profile.lua
|
||||
/test/cache
|
||||
/test/speeds.csv
|
||||
/test/penalties.csv
|
||||
node_modules
|
||||
|
||||
# Deprecated config file #
|
||||
##########################
|
||||
/server.ini
|
||||
|
||||
*.swp
|
||||
|
||||
# local lua debugging file
|
||||
debug.lua
|
||||
|
||||
# node-osrm artifacts
|
||||
lib/binding
|
||||
|
||||
|
0
.gitmodules
vendored
Normal file
16
.npmignore
Normal file
@ -0,0 +1,16 @@
|
||||
*
|
||||
!README.md
|
||||
!CHANGELOG.md
|
||||
!CONTRIBUTING.MD
|
||||
!LICENCE.TXT
|
||||
!package.json
|
||||
!package-lock.json
|
||||
!yarn.lock
|
||||
!docs
|
||||
!example
|
||||
!taginfo.json
|
||||
!lib/*.js
|
||||
!profiles/*
|
||||
!profiles/lib/*
|
||||
!profiles/examples/*
|
||||
!scripts/node_install.sh
|
24
AUTHORS.md
@ -1,24 +0,0 @@
|
||||
The following people contributed to the Open Source Routing Machine web frontend:
|
||||
|
||||
Dennis Schieferdecker
|
||||
Dennis Luxen
|
||||
Pascal Neis
|
||||
Teemu Koskinen
|
||||
Nicolas Belett Vigneron
|
||||
Moyg
|
||||
Jean-Frederic
|
||||
Zbigniew Czernik
|
||||
Jonas Häggqvist
|
||||
Sabas
|
||||
Paul Spencer
|
||||
Raphael Pinson
|
||||
Juan Luis Rodriguez Ponce
|
||||
Lauris Bukšis-Haberkorns
|
||||
Barboska
|
||||
miszka999
|
||||
Konstantin Delchev
|
||||
Fumito Mizuno
|
||||
Necdet Varoglu (OSM-Comenius Project)
|
||||
Madalina Ionescu (OSM-Comenius Project)
|
||||
Luis Costa (OSM-Comenius Project)
|
||||
Tobias Johansson
|
1102
CHANGELOG.md
Normal file
755
CMakeLists.txt
Normal file
@ -0,0 +1,755 @@
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR AND NOT MSVC_IDE)
|
||||
message(FATAL_ERROR "In-source builds are not allowed.
|
||||
Please create a directory and run cmake from there, passing the path to this source directory as the last argument.
|
||||
This process created the file `CMakeCache.txt' and the directory `CMakeFiles'. Please delete them.")
|
||||
endif()
|
||||
|
||||
# detect if this is included as subproject and if so expose
|
||||
# some variables to its parent scope
|
||||
get_directory_property(BUILD_AS_SUBPROJECT PARENT_DIRECTORY)
|
||||
if(BUILD_AS_SUBPROJECT)
|
||||
message(STATUS "Building libosrm as subproject.")
|
||||
endif()
|
||||
|
||||
# set OSRM_BUILD_DIR location (might be used in various scripts)
|
||||
if (NOT WIN32 AND NOT DEFINED ENV{OSRM_BUILD_DIR})
|
||||
set(ENV{OSRM_BUILD_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
option(ENABLE_CONAN "Use conan for dependencies" OFF)
|
||||
option(ENABLE_CCACHE "Speed up incremental rebuilds via ccache" ON)
|
||||
option(BUILD_TOOLS "Build OSRM tools" OFF)
|
||||
option(BUILD_PACKAGE "Build OSRM package" OFF)
|
||||
option(BUILD_ROUTED "Build osrm-routed HTTP server" ON)
|
||||
option(ENABLE_ASSERTIONS "Use assertions in release mode" OFF)
|
||||
option(ENABLE_DEBUG_LOGGING "Use debug logging in release mode" OFF)
|
||||
option(ENABLE_COVERAGE "Build with coverage instrumentalisation" OFF)
|
||||
option(ENABLE_SANITIZER "Use memory sanitizer for Debug build" OFF)
|
||||
option(ENABLE_LTO "Use Link Time Optimisation" ON)
|
||||
option(ENABLE_FUZZING "Fuzz testing using LLVM's libFuzzer" OFF)
|
||||
option(ENABLE_NODE_BINDINGS "Build NodeJs bindings" OFF)
|
||||
option(ENABLE_CLANG_TIDY "Enables clang-tidy checks" OFF)
|
||||
|
||||
|
||||
if (ENABLE_CLANG_TIDY)
|
||||
find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
|
||||
if(NOT CLANG_TIDY_COMMAND)
|
||||
message(FATAL_ERROR "ENABLE_CLANG_TIDY is ON but clang-tidy is not found!")
|
||||
else()
|
||||
message(STATUS "Found clang-tidy at ${CLANG_TIDY_COMMAND}")
|
||||
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND};--warnings-as-errors=*;--header-filter=.*")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
# be compatible with version handling before cmake 3.x
|
||||
if (POLICY CMP0057)
|
||||
cmake_policy(SET CMP0057 NEW)
|
||||
endif()
|
||||
if (POLICY CMP0074)
|
||||
cmake_policy(SET CMP0074 NEW)
|
||||
endif()
|
||||
if (POLICY CMP0167)
|
||||
cmake_policy(SET CMP0167 NEW)
|
||||
endif()
|
||||
project(OSRM C CXX)
|
||||
|
||||
|
||||
if(ENABLE_LTO AND (CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES MinRelSize OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo))
|
||||
include(CheckIPOSupported)
|
||||
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT error)
|
||||
if(LTO_SUPPORTED)
|
||||
message(STATUS "IPO / LTO enabled")
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
else()
|
||||
message(FATAL_ERROR "IPO / LTO not supported: <${error}>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# add @loader_path/$ORIGIN to rpath to make binaries relocatable
|
||||
if (APPLE)
|
||||
set(CMAKE_BUILD_RPATH "@loader_path")
|
||||
else()
|
||||
set(CMAKE_BUILD_RPATH "\$ORIGIN")
|
||||
# https://stackoverflow.com/questions/6324131/rpath-origin-not-having-desired-effect
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
|
||||
endif()
|
||||
|
||||
include(JSONParser)
|
||||
file(READ "package.json" packagejsonraw)
|
||||
sbeParseJson(packagejson packagejsonraw)
|
||||
|
||||
# This regex is not strict enough, but the correct one is too complicated for cmake matching.
|
||||
# https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
||||
if (packagejson.version MATCHES "^([0-9]+)\.([0-9]+)\.([0-9]+)([-+][0-9a-zA-Z.-]+)?$")
|
||||
set(OSRM_VERSION_MAJOR ${CMAKE_MATCH_1})
|
||||
set(OSRM_VERSION_MINOR ${CMAKE_MATCH_2})
|
||||
set(OSRM_VERSION_PATCH ${CMAKE_MATCH_3})
|
||||
set(OSRM_VERSION_PRERELEASE_BUILD ${CMAKE_MATCH_4})
|
||||
|
||||
set(OSRM_VERSION packagejson.version)
|
||||
else()
|
||||
message(FATAL_ERROR "Version from package.json cannot be parsed, expected semver compatible label, but found ${packagejson.version}")
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
add_definitions("-DOSRM_PROJECT_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"")
|
||||
else()
|
||||
add_definitions(-DOSRM_PROJECT_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
endif()
|
||||
|
||||
# these two functions build up custom variables:
|
||||
# DEPENDENCIES_INCLUDE_DIRS and OSRM_DEFINES
|
||||
# These variables we want to pass to
|
||||
# include_directories and add_definitions for both
|
||||
# this build and for sharing externally via pkg-config
|
||||
|
||||
function(add_dependency_includes)
|
||||
if(${ARGC} GREATER 0)
|
||||
list(APPEND DEPENDENCIES_INCLUDE_DIRS "${ARGV}")
|
||||
set(DEPENDENCIES_INCLUDE_DIRS "${DEPENDENCIES_INCLUDE_DIRS}" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction(add_dependency_includes)
|
||||
|
||||
function(add_dependency_defines defines)
|
||||
list(APPEND OSRM_DEFINES "${defines}")
|
||||
set(OSRM_DEFINES "${OSRM_DEFINES}" PARENT_SCOPE)
|
||||
endfunction(add_dependency_defines)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(FindPackageHandleStandardArgs)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
message(STATUS "Building on a 64 bit system")
|
||||
else()
|
||||
message(FATAL_ERROR "Building on a 32 bit system is not supported")
|
||||
endif()
|
||||
|
||||
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/include/)
|
||||
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include/)
|
||||
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/generated/include/)
|
||||
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/third_party/sol2/include)
|
||||
|
||||
set(BOOST_COMPONENTS date_time iostreams program_options thread unit_test_framework)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/util/version.hpp.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/util/version.hpp
|
||||
)
|
||||
file(GLOB UtilGlob src/util/*.cpp src/util/*/*.cpp)
|
||||
file(GLOB ExtractorGlob src/extractor/*.cpp src/extractor/*/*.cpp)
|
||||
file(GLOB GuidanceGlob src/guidance/*.cpp src/extractor/intersection/*.cpp)
|
||||
file(GLOB PartitionerGlob src/partitioner/*.cpp)
|
||||
file(GLOB CustomizerGlob src/customize/*.cpp)
|
||||
file(GLOB ContractorGlob src/contractor/*.cpp)
|
||||
file(GLOB UpdaterGlob src/updater/*.cpp)
|
||||
file(GLOB StorageGlob src/storage/*.cpp)
|
||||
file(GLOB ServerGlob src/server/*.cpp src/server/**/*.cpp)
|
||||
file(GLOB EngineGlob src/engine/*.cpp src/engine/**/*.cpp)
|
||||
file(GLOB ErrorcodesGlob src/osrm/errorcodes.cpp)
|
||||
|
||||
add_library(UTIL OBJECT ${UtilGlob})
|
||||
add_library(EXTRACTOR OBJECT ${ExtractorGlob})
|
||||
add_library(GUIDANCE OBJECT ${GuidanceGlob})
|
||||
add_library(PARTITIONER OBJECT ${PartitionerGlob})
|
||||
add_library(CUSTOMIZER OBJECT ${CustomizerGlob})
|
||||
add_library(CONTRACTOR OBJECT ${ContractorGlob})
|
||||
add_library(UPDATER OBJECT ${UpdaterGlob})
|
||||
add_library(STORAGE OBJECT ${StorageGlob})
|
||||
add_library(ENGINE OBJECT ${EngineGlob})
|
||||
|
||||
if (BUILD_ROUTED)
|
||||
add_library(SERVER OBJECT ${ServerGlob})
|
||||
add_executable(osrm-routed src/tools/routed.cpp $<TARGET_OBJECTS:SERVER> $<TARGET_OBJECTS:UTIL>)
|
||||
endif()
|
||||
|
||||
set_target_properties(UTIL PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
add_executable(osrm-extract src/tools/extract.cpp)
|
||||
add_executable(osrm-partition src/tools/partition.cpp)
|
||||
add_executable(osrm-customize src/tools/customize.cpp)
|
||||
add_executable(osrm-contract src/tools/contract.cpp)
|
||||
add_executable(osrm-datastore src/tools/store.cpp $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||
add_library(osrm src/osrm/osrm.cpp $<TARGET_OBJECTS:ENGINE> $<TARGET_OBJECTS:STORAGE> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||
add_library(osrm_contract src/osrm/contractor.cpp $<TARGET_OBJECTS:CONTRACTOR> $<TARGET_OBJECTS:UTIL>)
|
||||
add_library(osrm_extract src/osrm/extractor.cpp $<TARGET_OBJECTS:EXTRACTOR> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||
add_library(osrm_guidance $<TARGET_OBJECTS:GUIDANCE> $<TARGET_OBJECTS:UTIL>)
|
||||
add_library(osrm_partition src/osrm/partitioner.cpp $<TARGET_OBJECTS:PARTITIONER> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||
add_library(osrm_customize src/osrm/customizer.cpp $<TARGET_OBJECTS:CUSTOMIZER> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||
add_library(osrm_update $<TARGET_OBJECTS:UPDATER> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||
add_library(osrm_store $<TARGET_OBJECTS:STORAGE> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||
|
||||
# Explicitly set the build type to Release if no other type is specified
|
||||
# on the command line. Without this, cmake defaults to an unoptimized,
|
||||
# non-debug build, which almost nobody wants.
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
message(STATUS "No build type specified, defaulting to Release")
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
message(STATUS "Configuring OSRM in debug mode")
|
||||
elseif(CMAKE_BUILD_TYPE MATCHES Release)
|
||||
message(STATUS "Configuring OSRM in release mode")
|
||||
elseif(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
|
||||
message(STATUS "Configuring OSRM in release mode with debug flags")
|
||||
elseif(CMAKE_BUILD_TYPE MATCHES MinRelSize)
|
||||
message(STATUS "Configuring OSRM in release mode with minimized size")
|
||||
else()
|
||||
message(STATUS "Unrecognized build type - will use cmake defaults")
|
||||
endif()
|
||||
|
||||
# Additional logic for the different build types
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
|
||||
message(STATUS "Configuring debug mode flags")
|
||||
set(ENABLE_ASSERTIONS ON)
|
||||
set(ENABLE_DEBUG_LOGGING ON)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -fno-inline -fno-omit-frame-pointer")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-inline -fno-omit-frame-pointer")
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -ggdb")
|
||||
endif()
|
||||
|
||||
set(MAYBE_COVERAGE_LIBRARIES "")
|
||||
if (ENABLE_COVERAGE)
|
||||
if (NOT CMAKE_BUILD_TYPE MATCHES "Debug")
|
||||
message(ERROR "ENABLE_COVERAGE=ON only makes sense with a Debug build")
|
||||
endif()
|
||||
message(STATUS "Enabling coverage")
|
||||
set(MAYBE_COVERAGE_LIBRARIES "-lgcov")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ftest-coverage -fprofile-arcs")
|
||||
endif()
|
||||
|
||||
|
||||
if (ENABLE_SANITIZER)
|
||||
set(SANITIZER_FLAGS "-g -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined -fno-omit-frame-pointer")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAGS}")
|
||||
set(OSRM_CXXFLAGS "${OSRM_CXXFLAGS} ${SANITIZER_FLAGS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS}")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${SANITIZER_FLAGS}")
|
||||
endif()
|
||||
|
||||
# Configuring compilers
|
||||
include(cmake/warnings.cmake)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fPIC -fcolor-diagnostics -ftemplate-depth=1024")
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
set(COLOR_FLAG "-fdiagnostics-color=auto")
|
||||
check_cxx_compiler_flag("-fdiagnostics-color=auto" HAS_COLOR_FLAG)
|
||||
if(NOT HAS_COLOR_FLAG)
|
||||
set(COLOR_FLAG "")
|
||||
endif()
|
||||
# using GCC
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 ${COLOR_FLAG} -fPIC -ftemplate-depth=1024")
|
||||
|
||||
if(WIN32) # using mingw
|
||||
add_dependency_defines(-DWIN32)
|
||||
set(OPTIONAL_SOCKET_LIBS ws2_32 wsock32)
|
||||
endif()
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||
# using Intel C++
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-intel -wd10237 -Wall -ipo -fPIC")
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
# using Visual Studio C++
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") # avoid compiler error C1128 from scripting_environment_lua.cpp
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DWIN32_LEAN_AND_MEAN") # avoid compiler error C2011 from dual #include of winsock.h and winsock2.h
|
||||
add_dependency_defines(-DBOOST_LIB_DIAGNOSTIC)
|
||||
add_dependency_defines(-D_CRT_SECURE_NO_WARNINGS)
|
||||
add_dependency_defines(-DNOMINMAX) # avoid min and max macros that can break compilation
|
||||
add_dependency_defines(-D_WIN32_WINNT=0x0501)
|
||||
add_dependency_defines(-DXML_STATIC)
|
||||
find_library(ws2_32_LIBRARY_PATH ws2_32)
|
||||
target_link_libraries(osrm-extract wsock32 ws2_32)
|
||||
endif()
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
find_library(RT_LIB rt)
|
||||
if (RT_LIB)
|
||||
set(MAYBE_RT_LIBRARY -lrt)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
# Third-party libraries
|
||||
set(RAPIDJSON_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/rapidjson/include")
|
||||
include_directories(SYSTEM ${RAPIDJSON_INCLUDE_DIR})
|
||||
|
||||
set(MICROTAR_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/microtar/src")
|
||||
include_directories(SYSTEM ${MICROTAR_INCLUDE_DIR})
|
||||
|
||||
add_library(MICROTAR OBJECT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/microtar/src/microtar.c")
|
||||
set_property(TARGET MICROTAR PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
target_no_warning(MICROTAR unused-variable)
|
||||
target_no_warning(MICROTAR format)
|
||||
|
||||
set(PROTOZERO_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/protozero/include")
|
||||
include_directories(SYSTEM ${PROTOZERO_INCLUDE_DIR})
|
||||
|
||||
set(VTZERO_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/vtzero/include")
|
||||
include_directories(SYSTEM ${VTZERO_INCLUDE_DIR})
|
||||
|
||||
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "Disable the build of Flatbuffers tests and samples.")
|
||||
set(FLATBUFFERS_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers")
|
||||
set(FLATBUFFERS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include")
|
||||
include_directories(SYSTEM ${FLATBUFFERS_INCLUDE_DIR})
|
||||
add_subdirectory(${FLATBUFFERS_SRC_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-build
|
||||
EXCLUDE_FROM_ALL)
|
||||
|
||||
set(FMT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/fmt/include")
|
||||
add_compile_definitions(FMT_HEADER_ONLY)
|
||||
include_directories(SYSTEM ${FMT_INCLUDE_DIR})
|
||||
|
||||
|
||||
# see https://stackoverflow.com/questions/70898030/boost-link-error-using-conan-find-package
|
||||
if (MSVC)
|
||||
add_definitions(-DBOOST_ALL_NO_LIB)
|
||||
endif()
|
||||
|
||||
if(ENABLE_CONAN)
|
||||
message(STATUS "Installing dependencies via Conan")
|
||||
|
||||
# Conan will generate Find*.cmake files to build directory, so we use them with the highest priority
|
||||
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_BINARY_DIR})
|
||||
list(INSERT CMAKE_PREFIX_PATH 0 ${CMAKE_BINARY_DIR})
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cmake/conan.cmake)
|
||||
|
||||
conan_check(REQUIRED)
|
||||
|
||||
set(CONAN_BOOST_VERSION "1.85.0@#14265ec82b25d91305bbb3b30d3357f8")
|
||||
set(CONAN_BZIP2_VERSION "1.0.8@#d1b2d5816f25865acf978501dff1f897")
|
||||
set(CONAN_EXPAT_VERSION "2.6.2@#2d385d0d50eb5561006a7ff9e356656b")
|
||||
set(CONAN_LUA_VERSION "5.4.6@#658d6089093cf01992c2737ab2e96763")
|
||||
set(CONAN_TBB_VERSION "2021.12.0@#e56e5b44be8d690530585dd3634c0106")
|
||||
|
||||
set(CONAN_SYSTEM_INCLUDES ON)
|
||||
|
||||
|
||||
set(CONAN_ARGS
|
||||
REQUIRES
|
||||
"boost/${CONAN_BOOST_VERSION}"
|
||||
"bzip2/${CONAN_BZIP2_VERSION}"
|
||||
"expat/${CONAN_EXPAT_VERSION}"
|
||||
"lua/${CONAN_LUA_VERSION}"
|
||||
"onetbb/${CONAN_TBB_VERSION}"
|
||||
BASIC_SETUP
|
||||
GENERATORS cmake_find_package json # json generator generates a conanbuildinfo.json in the build folder so (non-CMake) projects can easily parse OSRM's dependencies
|
||||
KEEP_RPATHS
|
||||
NO_OUTPUT_DIRS
|
||||
OPTIONS boost:without_stacktrace=True # Apple Silicon cross-compilation fails without it
|
||||
BUILD missing
|
||||
)
|
||||
|
||||
# Enable revisions in the conan config
|
||||
execute_process(COMMAND ${CONAN_CMD} config set general.revisions_enabled=1 RESULT_VARIABLE RET_CODE)
|
||||
if(NOT "${RET_CODE}" STREQUAL "0")
|
||||
message(FATAL_ERROR "Error setting revisions for Conan: '${RET_CODE}'")
|
||||
endif()
|
||||
|
||||
# explicitly say Conan to use x86 dependencies if build for x86 platforms (https://github.com/conan-io/cmake-conan/issues/141)
|
||||
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
conan_cmake_run("${CONAN_ARGS};ARCH;x86")
|
||||
# cross-compilation for Apple Silicon
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
|
||||
conan_cmake_run("${CONAN_ARGS};ARCH;armv8")
|
||||
else()
|
||||
conan_cmake_run("${CONAN_ARGS}")
|
||||
endif()
|
||||
|
||||
add_dependency_includes(${CONAN_INCLUDE_DIRS_BOOST})
|
||||
add_dependency_includes(${CONAN_INCLUDE_DIRS_BZIP2})
|
||||
add_dependency_includes(${CONAN_INCLUDE_DIRS_EXPAT})
|
||||
add_dependency_includes(${CONAN_INCLUDE_DIRS_LUA})
|
||||
add_dependency_includes(${CONAN_INCLUDE_DIRS_TBB})
|
||||
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
|
||||
set(Boost_DATE_TIME_LIBRARY "${Boost_date_time_LIB_TARGETS}")
|
||||
set(Boost_PROGRAM_OPTIONS_LIBRARY "${Boost_program_options_LIB_TARGETS}")
|
||||
set(Boost_IOSTREAMS_LIBRARY "${Boost_iostreams_LIB_TARGETS}")
|
||||
set(Boost_THREAD_LIBRARY "${Boost_thread_LIB_TARGETS}")
|
||||
set(Boost_ZLIB_LIBRARY "${Boost_zlib_LIB_TARGETS}")
|
||||
set(Boost_UNIT_TEST_FRAMEWORK_LIBRARY "${Boost_unit_test_framework_LIB_TARGETS}")
|
||||
|
||||
|
||||
find_package(BZip2 REQUIRED)
|
||||
find_package(EXPAT REQUIRED)
|
||||
find_package(lua REQUIRED)
|
||||
set(LUA_LIBRARIES ${lua_LIBRARIES})
|
||||
|
||||
find_package(TBB REQUIRED)
|
||||
|
||||
|
||||
# note: we avoid calling find_package(Osmium ...) here to ensure that the
|
||||
# expat and bzip2 are used from conan rather than the system
|
||||
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libosmium/include)
|
||||
else()
|
||||
find_package(Boost 1.70 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
|
||||
add_dependency_includes(${Boost_INCLUDE_DIRS})
|
||||
|
||||
find_package(TBB REQUIRED)
|
||||
add_dependency_includes(${TBB_INCLUDE_DIR})
|
||||
set(TBB_LIBRARIES TBB::tbb)
|
||||
|
||||
find_package(EXPAT REQUIRED)
|
||||
add_dependency_includes(${EXPAT_INCLUDE_DIRS})
|
||||
|
||||
find_package(BZip2 REQUIRED)
|
||||
add_dependency_includes(${BZIP2_INCLUDE_DIR})
|
||||
|
||||
find_package(Lua 5.2 REQUIRED)
|
||||
if (LUA_FOUND)
|
||||
message(STATUS "Using Lua ${LUA_VERSION_STRING}")
|
||||
endif()
|
||||
|
||||
add_dependency_includes(${LUA_INCLUDE_DIR})
|
||||
|
||||
# add a target to generate API documentation with Doxygen
|
||||
find_package(Doxygen)
|
||||
if(DOXYGEN_FOUND)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
|
||||
add_custom_target(doc
|
||||
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with Doxygen" VERBATIM
|
||||
)
|
||||
endif()
|
||||
|
||||
# note libosmium depends on expat and bzip2
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third_party/libosmium/cmake")
|
||||
if(NOT OSMIUM_INCLUDE_DIR)
|
||||
set(OSMIUM_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/libosmium/include")
|
||||
endif()
|
||||
find_package(Osmium REQUIRED COMPONENTS io)
|
||||
include_directories(SYSTEM ${OSMIUM_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
# prefix compilation with ccache by default if available and on clang or gcc
|
||||
if(ENABLE_CCACHE AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"))
|
||||
find_program(CCACHE_FOUND ccache)
|
||||
if(CCACHE_FOUND)
|
||||
message(STATUS "Using ccache to speed up incremental builds")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# even with conan builds we want to link to system zlib
|
||||
# to ensure that osrm binaries play well with other binaries like nodejs
|
||||
find_package(ZLIB REQUIRED)
|
||||
add_dependency_includes(${ZLIB_INCLUDE_DIRS})
|
||||
|
||||
add_dependency_defines(-DBOOST_SPIRIT_USE_PHOENIX_V3)
|
||||
add_dependency_defines(-DBOOST_RESULT_OF_USE_DECLTYPE)
|
||||
|
||||
# Workaround for https://github.com/boostorg/phoenix/issues/111
|
||||
add_dependency_defines(-DBOOST_PHOENIX_STL_TUPLE_H_)
|
||||
|
||||
add_definitions(${OSRM_DEFINES})
|
||||
include_directories(SYSTEM ${DEPENDENCIES_INCLUDE_DIRS})
|
||||
|
||||
set(BOOST_BASE_LIBRARIES
|
||||
${Boost_DATE_TIME_LIBRARY}
|
||||
${Boost_IOSTREAMS_LIBRARY}
|
||||
${Boost_THREAD_LIBRARY})
|
||||
|
||||
set(BOOST_ENGINE_LIBRARIES
|
||||
${Boost_ZLIB_LIBRARY}
|
||||
${Boost_REGEX_LIBRARY}
|
||||
${BOOST_BASE_LIBRARIES})
|
||||
|
||||
# Binaries
|
||||
target_link_libraries(osrm-datastore osrm_store ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||
target_link_libraries(osrm-extract osrm_extract ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||
target_link_libraries(osrm-partition osrm_partition ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||
target_link_libraries(osrm-customize osrm_customize ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||
target_link_libraries(osrm-contract osrm_contract ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||
if (BUILD_ROUTED)
|
||||
target_link_libraries(osrm-routed osrm ${Boost_PROGRAM_OPTIONS_LIBRARY} ${OPTIONAL_SOCKET_LIBS} ${ZLIB_LIBRARY})
|
||||
endif()
|
||||
|
||||
set(EXTRACTOR_LIBRARIES
|
||||
${BZIP2_LIBRARIES}
|
||||
${BOOST_BASE_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${EXPAT_LIBRARIES}
|
||||
${LUA_LIBRARIES}
|
||||
${OSMIUM_LIBRARIES}
|
||||
${TBB_LIBRARIES}
|
||||
${ZLIB_LIBRARY}
|
||||
${MAYBE_COVERAGE_LIBRARIES})
|
||||
set(GUIDANCE_LIBRARIES
|
||||
${BOOST_BASE_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${LUA_LIBRARIES}
|
||||
${TBB_LIBRARIES}
|
||||
${MAYBE_COVERAGE_LIBRARIES})
|
||||
set(PARTITIONER_LIBRARIES
|
||||
${BOOST_ENGINE_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${TBB_LIBRARIES}
|
||||
${MAYBE_RT_LIBRARY}
|
||||
${MAYBE_COVERAGE_LIBRARIES}
|
||||
${ZLIB_LIBRARY})
|
||||
set(CUSTOMIZER_LIBRARIES
|
||||
${BOOST_ENGINE_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${TBB_LIBRARIES}
|
||||
${MAYBE_RT_LIBRARY}
|
||||
${MAYBE_COVERAGE_LIBRARIES})
|
||||
set(UPDATER_LIBRARIES
|
||||
${BOOST_BASE_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${TBB_LIBRARIES}
|
||||
${MAYBE_RT_LIBRARY}
|
||||
${MAYBE_COVERAGE_LIBRARIES}
|
||||
${ZLIB_LIBRARY})
|
||||
set(CONTRACTOR_LIBRARIES
|
||||
${BOOST_BASE_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${LUA_LIBRARIES}
|
||||
${TBB_LIBRARIES}
|
||||
${MAYBE_RT_LIBRARY}
|
||||
${MAYBE_COVERAGE_LIBRARIES})
|
||||
set(ENGINE_LIBRARIES
|
||||
${BOOST_ENGINE_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${TBB_LIBRARIES}
|
||||
${MAYBE_RT_LIBRARY}
|
||||
${MAYBE_COVERAGE_LIBRARIES}
|
||||
${ZLIB_LIBRARY})
|
||||
set(STORAGE_LIBRARIES
|
||||
${BOOST_BASE_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${TBB_LIBRARIES}
|
||||
${MAYBE_RT_LIBRARY}
|
||||
${MAYBE_COVERAGE_LIBRARIES})
|
||||
set(UTIL_LIBRARIES
|
||||
${BOOST_BASE_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${TBB_LIBRARIES}
|
||||
${MAYBE_COVERAGE_LIBRARIES}
|
||||
${ZLIB_LIBRARY})
|
||||
|
||||
# Libraries
|
||||
target_link_libraries(osrm ${ENGINE_LIBRARIES})
|
||||
target_link_libraries(osrm_update ${UPDATER_LIBRARIES})
|
||||
target_link_libraries(osrm_contract ${CONTRACTOR_LIBRARIES} osrm_update osrm_store)
|
||||
target_link_libraries(osrm_extract osrm_guidance ${EXTRACTOR_LIBRARIES})
|
||||
target_link_libraries(osrm_partition ${PARTITIONER_LIBRARIES})
|
||||
target_link_libraries(osrm_customize ${CUSTOMIZER_LIBRARIES} osrm_update osrm_store)
|
||||
target_link_libraries(osrm_store ${STORAGE_LIBRARIES})
|
||||
|
||||
# BUILD_COMPONENTS
|
||||
add_executable(osrm-components src/tools/components.cpp $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||
target_link_libraries(osrm-components ${TBB_LIBRARIES} ${BOOST_BASE_LIBRARIES} ${UTIL_LIBRARIES})
|
||||
install(TARGETS osrm-components DESTINATION bin)
|
||||
|
||||
if(BUILD_TOOLS)
|
||||
message(STATUS "Activating OSRM internal tools")
|
||||
add_executable(osrm-io-benchmark src/tools/io-benchmark.cpp $<TARGET_OBJECTS:UTIL>)
|
||||
target_link_libraries(osrm-io-benchmark ${BOOST_BASE_LIBRARIES} ${TBB_LIBRARIES})
|
||||
|
||||
install(TARGETS osrm-io-benchmark DESTINATION bin)
|
||||
endif()
|
||||
|
||||
if (ENABLE_ASSERTIONS)
|
||||
message(STATUS "Enabling assertions")
|
||||
add_definitions(-DBOOST_ENABLE_ASSERT_HANDLER)
|
||||
endif()
|
||||
|
||||
if (ENABLE_DEBUG_LOGGING)
|
||||
message(STATUS "Enabling debug logging")
|
||||
add_definitions(-DENABLE_DEBUG_LOGGING)
|
||||
endif()
|
||||
|
||||
# Add RPATH info to executables so that when they are run after being installed
|
||||
# (i.e., from /usr/local/bin/) the linker can find library dependencies. For
|
||||
# more info see http://www.cmake.org/Wiki/CMake_RPATH_handling
|
||||
set_property(TARGET osrm-extract PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
set_property(TARGET osrm-partition PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
set_property(TARGET osrm-contract PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
set_property(TARGET osrm-datastore PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
if (BUILD_ROUTED)
|
||||
set_property(TARGET osrm-routed PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
endif()
|
||||
|
||||
file(GLOB FlatbuffersGlob third_party/flatbuffers/include/flatbuffers/*.h)
|
||||
file(GLOB LibraryGlob include/osrm/*.hpp)
|
||||
file(GLOB ParametersGlob include/engine/api/*_parameters.hpp)
|
||||
set(ApiHeader include/engine/api/base_result.hpp)
|
||||
set(EngineHeader include/engine/status.hpp include/engine/engine_config.hpp include/engine/hint.hpp include/engine/bearing.hpp include/engine/approach.hpp include/engine/phantom_node.hpp)
|
||||
set(UtilHeader include/util/coordinate.hpp include/util/json_container.hpp include/util/typedefs.hpp include/util/alias.hpp include/util/exception.hpp include/util/bearing.hpp)
|
||||
set(ExtractorHeader include/extractor/extractor.hpp include/storage/io_config.hpp include/extractor/extractor_config.hpp include/extractor/travel_mode.hpp)
|
||||
set(PartitionerHeader include/partitioner/partitioner.hpp include/partitioner/partitioner_config.hpp)
|
||||
set(ContractorHeader include/contractor/contractor.hpp include/contractor/contractor_config.hpp)
|
||||
set(StorageHeader include/storage/storage.hpp include/storage/io_config.hpp include/storage/storage_config.hpp)
|
||||
install(FILES ${EngineHeader} DESTINATION include/osrm/engine)
|
||||
install(FILES ${UtilHeader} DESTINATION include/osrm/util)
|
||||
install(FILES ${StorageHeader} DESTINATION include/osrm/storage)
|
||||
install(FILES ${ExtractorHeader} DESTINATION include/osrm/extractor)
|
||||
install(FILES ${PartitionerHeader} DESTINATION include/osrm/partitioner)
|
||||
install(FILES ${ContractorHeader} DESTINATION include/osrm/contractor)
|
||||
install(FILES ${LibraryGlob} DESTINATION include/osrm)
|
||||
install(FILES ${ParametersGlob} DESTINATION include/osrm/engine/api)
|
||||
install(FILES ${ApiHeader} DESTINATION include/osrm/engine/api)
|
||||
install(FILES ${FlatbuffersGlob} DESTINATION include/flatbuffers)
|
||||
install(TARGETS osrm-extract DESTINATION bin)
|
||||
install(TARGETS osrm-partition DESTINATION bin)
|
||||
install(TARGETS osrm-customize DESTINATION bin)
|
||||
install(TARGETS osrm-contract DESTINATION bin)
|
||||
install(TARGETS osrm-datastore DESTINATION bin)
|
||||
if (BUILD_ROUTED)
|
||||
install(TARGETS osrm-routed DESTINATION bin)
|
||||
endif()
|
||||
install(TARGETS osrm DESTINATION lib)
|
||||
install(TARGETS osrm_extract DESTINATION lib)
|
||||
install(TARGETS osrm_partition DESTINATION lib)
|
||||
install(TARGETS osrm_customize DESTINATION lib)
|
||||
install(TARGETS osrm_update DESTINATION lib)
|
||||
install(TARGETS osrm_contract DESTINATION lib)
|
||||
install(TARGETS osrm_store DESTINATION lib)
|
||||
install(TARGETS osrm_guidance DESTINATION lib)
|
||||
|
||||
|
||||
# Install profiles and support library to /usr/local/share/osrm/profiles by default
|
||||
set(DefaultProfilesDir profiles)
|
||||
install(DIRECTORY ${DefaultProfilesDir} DESTINATION share/osrm)
|
||||
|
||||
# Install data geojson files to /usr/local/share/osrm/data by default
|
||||
set(DefaultProfilesDir data)
|
||||
install(DIRECTORY ${DefaultProfilesDir} DESTINATION share/osrm)
|
||||
|
||||
# Setup exporting variables for pkgconfig and subproject
|
||||
#
|
||||
|
||||
if(BUILD_PACKAGE)
|
||||
include(CPackConfig)
|
||||
include(CPack)
|
||||
endif()
|
||||
|
||||
function(JOIN VALUES GLUE OUTPUT)
|
||||
string (REPLACE ";" "${GLUE}" _TMP_STR "${VALUES}")
|
||||
set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
JOIN("${OSRM_DEFINES}" " " TMP_OSRM_DEFINES)
|
||||
set(LibOSRM_CXXFLAGS "${OSRM_CXXFLAGS} ${TMP_OSRM_DEFINES}")
|
||||
set(LibOSRM_LDFLAGS "${OSRM_LDFLAGS}")
|
||||
|
||||
if(BUILD_AS_SUBPROJECT)
|
||||
set(LibOSRM_CXXFLAGS "${LibOSRM_CXXFLAGS}" PARENT_SCOPE)
|
||||
set(LibOSRM_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE)
|
||||
set(LibOSRM_LIBRARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE)
|
||||
set(LibOSRM_LIBRARIES "osrm" PARENT_SCOPE)
|
||||
set(LibOSRM_DEPENDENT_LIBRARIES "${ENGINE_LIBRARIES}" PARENT_SCOPE)
|
||||
set(LibOSRM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/osrm"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/third_party"
|
||||
"${DEPENDENCIES_INCLUDE_DIRS}" PARENT_SCOPE)
|
||||
set(LibOSRM_LIBRARY_DIRS "${LibOSRM_LIBRARY_DIR}" PARENT_SCOPE)
|
||||
endif()
|
||||
|
||||
# pkgconfig defines
|
||||
set(PKGCONFIG_OSRM_CXXFLAGS "${LibOSRM_CXXFLAGS}")
|
||||
set(PKGCONFIG_OSRM_LDFLAGS "${LibOSRM_LDFLAGS}")
|
||||
set(PKGCONFIG_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/lib")
|
||||
set(PKGCONFIG_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include")
|
||||
|
||||
list(APPEND DEPENDENCIES_INCLUDE_DIRS "${PKGCONFIG_INCLUDE_DIR}")
|
||||
list(APPEND DEPENDENCIES_INCLUDE_DIRS "${PKGCONFIG_INCLUDE_DIR}/osrm")
|
||||
JOIN("-I${DEPENDENCIES_INCLUDE_DIRS}" " -I" PKGCONFIG_OSRM_INCLUDE_FLAGS)
|
||||
|
||||
# Boost uses imported targets, we need to use a generator expression to extract
|
||||
# the link libraries to be written to the pkg-config file.
|
||||
# Conan & TBB define dependencies as CMake targets too, that's why we do the same for them.
|
||||
foreach(engine_lib ${ENGINE_LIBRARIES})
|
||||
if("${engine_lib}" MATCHES "^Boost.*" OR "${engine_lib}" MATCHES "^CONAN_LIB.*" OR "${engine_lib}" MATCHES "^TBB.*")
|
||||
list(APPEND PKGCONFIG_DEPENDENT_LIBRARIES "$<TARGET_LINKER_FILE:${engine_lib}>")
|
||||
else()
|
||||
list(APPEND PKGCONFIG_DEPENDENT_LIBRARIES "${engine_lib}")
|
||||
endif()
|
||||
endforeach(engine_lib)
|
||||
JOIN("${PKGCONFIG_DEPENDENT_LIBRARIES}" " " PKGCONFIG_OSRM_DEPENDENT_LIBRARIES)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkgconfig.in pkgconfig.configured @ONLY)
|
||||
file(GENERATE
|
||||
OUTPUT
|
||||
${PROJECT_BINARY_DIR}/libosrm.pc
|
||||
INPUT
|
||||
${PROJECT_BINARY_DIR}/pkgconfig.configured)
|
||||
|
||||
install(FILES ${PROJECT_BINARY_DIR}/libosrm.pc DESTINATION ${PKGCONFIG_LIBRARY_DIR}/pkgconfig)
|
||||
|
||||
# uninstall target
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
|
||||
IMMEDIATE @ONLY)
|
||||
|
||||
add_custom_target(uninstall
|
||||
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake)
|
||||
|
||||
|
||||
# Modular build system: each directory registered here provides its own CMakeLists.txt
|
||||
add_subdirectory(unit_tests)
|
||||
add_subdirectory(src/benchmarks)
|
||||
|
||||
if (ENABLE_NODE_BINDINGS)
|
||||
add_subdirectory(src/nodejs)
|
||||
endif()
|
||||
|
||||
|
||||
if (ENABLE_FUZZING)
|
||||
# Requires libosrm being built with sanitizers; make configurable and default to ubsan
|
||||
set(FUZZ_SANITIZER "undefined" CACHE STRING "Sanitizer to be used for Fuzz testing")
|
||||
set_property(CACHE FUZZ_SANITIZER PROPERTY STRINGS "undefined" "integer" "address" "memory" "thread" "leak")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-coverage=edge,indirect-calls,8bit-counters -fsanitize=address")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
|
||||
set(OSRM_LDFLAGS "${OSRM_LDFLAGS} -fsanitize=address")
|
||||
|
||||
message(STATUS "Using -fsanitize=${FUZZ_SANITIZER} for Fuzz testing")
|
||||
|
||||
add_subdirectory(fuzz)
|
||||
endif ()
|
||||
|
||||
# add headers sanity check target that includes all headers independently
|
||||
set(check_headers_dir "${PROJECT_BINARY_DIR}/check-headers")
|
||||
file(GLOB_RECURSE headers_to_check
|
||||
${PROJECT_BINARY_DIR}/*.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/*.hpp)
|
||||
foreach(header ${headers_to_check})
|
||||
if ("${header}" MATCHES ".*/include/nodejs/.*")
|
||||
# we do not check NodeJS bindings headers
|
||||
continue()
|
||||
endif()
|
||||
get_filename_component(filename ${header} NAME_WE)
|
||||
set(filename "${check_headers_dir}/${filename}.cpp")
|
||||
if (NOT EXISTS ${filename})
|
||||
file(WRITE ${filename} "#include \"${header}\"\n")
|
||||
endif()
|
||||
list(APPEND sources ${filename})
|
||||
endforeach()
|
||||
add_library(check-headers STATIC EXCLUDE_FROM_ALL ${sources})
|
||||
set_target_properties(check-headers PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${check_headers_dir})
|
||||
|
3
CODE-OF-CONDUCT.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Code of conduct
|
||||
|
||||
Everyone is invited to participate in Project OSRM’s open source projects and public discussions: we want to create a welcoming and friendly environment. Harassment of participants or other unethical and unprofessional behavior will not be tolerated in our spaces. The [Contributor Covenant](http://contributor-covenant.org) applies to all projects under the Project-OSRM organization and we ask that you please read [the full text](http://contributor-covenant.org/version/1/2/0/).
|
81
CONTRIBUTING.md
Normal file
@ -0,0 +1,81 @@
|
||||
# Everyone
|
||||
|
||||
Please take some time to review our [code of conduct](CODE-OF-CONDUCT.md) to help guide your interactions with others on this project.
|
||||
|
||||
# User
|
||||
|
||||
Before you open a new issue, please search for older ones that cover the same issue.
|
||||
In general "me too" comments/issues are frowned upon.
|
||||
You can add a :+1: emoji reaction to the issue if you want to express interest in this.
|
||||
|
||||
# Developer
|
||||
|
||||
We use `clang-format` version `15` to consistently format the code base. There is a helper script under `scripts/format.sh`.
|
||||
The format is automatically checked by the `mason-linux-release` job of a Travis CI build.
|
||||
To save development time a local hook `.git/hooks/pre-push`
|
||||
```
|
||||
#!/bin/sh
|
||||
|
||||
remote="$1"
|
||||
if [ x"$remote" = xorigin ] ; then
|
||||
if [ $(git rev-parse --abbrev-ref HEAD) = master ] ; then
|
||||
echo "Rejected push to $remote/master" ; exit 1
|
||||
fi
|
||||
|
||||
./scripts/format.sh && ./scripts/error_on_dirty.sh
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "Unstaged format changes" ; exit 1
|
||||
fi
|
||||
fi
|
||||
```
|
||||
could check code format, modify a local repository and reject push due to unstaged formatting changes.
|
||||
Also `pre-push` hook rejects direct pushes to `origin/master`.
|
||||
|
||||
⚠️ `scripts/format.sh` checks all local files that match `*.cpp` or `*.hpp` patterns.
|
||||
|
||||
|
||||
In general changes that affect the API and/or increase the memory consumption need to be discussed first.
|
||||
Often we don't include changes that would increase the memory consumption a lot if they are not generally usable (e.g. elevation data is a good example).
|
||||
|
||||
## Pull Request
|
||||
|
||||
Every pull-request that changes the API needs to update the docs in `docs/http.md` and add an entry to `CHANGELOG.md`.
|
||||
Breaking changes need to have a BREAKING prefix. See the [releasing documentation](docs/releasing.md) on how this affects the version.
|
||||
|
||||
Early feedback is also important.
|
||||
You will see that a lot of the PR have tags like `[not ready]` or `[wip]`.
|
||||
We like to open PRs as soon as we are starting to work on something to make it visible to the rest of the team.
|
||||
If your work is going in entirely the wrong direction, there is a good chance someone will pick up on this before it is too late.
|
||||
Everyone is encouraged to read PRs of other people and give feedback.
|
||||
|
||||
For every significant code change we require a pull request review before it is merged.
|
||||
If your pull request modifies the API this need to be signed of by a team discussion.
|
||||
This means you will need to find another member of the team with commit access and request a review of your pull request.
|
||||
|
||||
Once your pull request is reviewed you can merge it! If you don't have commit access, ping someone that has commit access.
|
||||
If you do have commit access there are in general two accepted styles to merging:
|
||||
|
||||
1. Make sure the branch is up to date with `master`. Run `git rebase master` to find out.
|
||||
2. Once that is ensured you can either:
|
||||
- Click the nice green merge button (for a non-fast-forward merge)
|
||||
- Merge by hand using a fast-forward merge
|
||||
|
||||
Which merge you prefer is up to personal preference. In general it is recommended to use fast-forward merges because it creates a history that is sequential and easier to understand.
|
||||
|
||||
# Maintainer
|
||||
|
||||
## Doing a release
|
||||
|
||||
There is an in-depth guide around how to push out a release once it is ready [here](docs/releasing.md).
|
||||
|
||||
## The API
|
||||
|
||||
Changes to the API need to be discussed and signed off by the team. Breaking changes even more so than additive changes.
|
||||
|
||||
## Milestones
|
||||
|
||||
If a pull request or an issue is applicable for the current or next milestone, depends on the target version number.
|
||||
Since we use semantic versioning we restrict breaking changes to major releases.
|
||||
After a Release Candidate is released we usually don't change the API anymore if it is not critical.
|
||||
Bigger code changes after a RC was released should also be avoided.
|
||||
|
44
Doxyfile.in
Normal file
@ -0,0 +1,44 @@
|
||||
PROJECT_NAME = "Project OSRM"
|
||||
PROJECT_BRIEF = "Open Source Routing Machine"
|
||||
BUILTIN_STL_SUPPORT = YES
|
||||
|
||||
EXTRACT_ALL = YES
|
||||
EXTRACT_PRIVATE = YES
|
||||
EXTRACT_PACKAGE = YES
|
||||
EXTRACT_STATIC = YES
|
||||
EXTRACT_LOCAL_CLASSES = YES
|
||||
EXTRACT_ANON_NSPACES = YES
|
||||
|
||||
QUIET = YES
|
||||
|
||||
INPUT = @CMAKE_CURRENT_SOURCE_DIR@
|
||||
USE_MDFILE_AS_MAINPAGE = @CMAKE_CURRENT_SOURCE_DIR@/README.md
|
||||
FILE_PATTERNS = *.h *.hpp *.c *.cc *.cpp *.md
|
||||
RECURSIVE = YES
|
||||
|
||||
EXCLUDE = @CMAKE_CURRENT_SOURCE_DIR@/third_party \
|
||||
@CMAKE_CURRENT_SOURCE_DIR@/build \
|
||||
@CMAKE_CURRENT_SOURCE_DIR@/node_modules \
|
||||
@CMAKE_CURRENT_SOURCE_DIR@/unit_tests \
|
||||
@CMAKE_CURRENT_SOURCE_DIR@/benchmarks \
|
||||
@CMAKE_CURRENT_SOURCE_DIR@/features
|
||||
|
||||
SOURCE_BROWSER = YES
|
||||
|
||||
CLANG_ASSISTED_PARSING = NO
|
||||
|
||||
HTML_COLORSTYLE_HUE = 217
|
||||
HTML_COLORSTYLE_SAT = 71
|
||||
HTML_COLORSTYLE_GAMMA = 50
|
||||
|
||||
GENERATE_TREEVIEW = YES
|
||||
|
||||
HAVE_DOT = @DOXYGEN_DOT_FOUND@
|
||||
CALL_GRAPH = YES
|
||||
CALLER_GRAPH = YES
|
||||
|
||||
DOT_IMAGE_FORMAT = svg
|
||||
INTERACTIVE_SVG = YES
|
||||
DOT_GRAPH_MAX_NODES = 500
|
||||
DOT_TRANSPARENT = YES
|
||||
DOT_MULTI_TARGETS = YES
|
22
LICENSE.TXT
Normal file
@ -0,0 +1,22 @@
|
||||
Copyright (c) 2017, Project OSRM contributors
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
250
README.md
@ -1,71 +1,191 @@
|
||||
Overview
|
||||
--------
|
||||
The repository provides a Leaflet [(1)] based web frontend to the Open Source Routing Machine (Project-OSRM [(2)]).
|
||||
The frontend is implemented in Javascript.
|
||||
Data is fetched from routing and geocoding servers using JSONP queries.
|
||||
The website is XHTML 1.0 Strict compliant.
|
||||
A deployed version of the the web frontend can be seen at [(3)].
|
||||
## Open Source Routing Machine
|
||||
|
||||
|
||||
Setup
|
||||
-----
|
||||
The frontend should work directly as provided.
|
||||
Settings - including URLs of the routing server, geocoder server and tile servers - are specified in `OSRM.config.js`.
|
||||
Note that the URL shortener used for generating route links only works with URLs pointing to the official Project-OSRM website.
|
||||
[](https://github.com/Project-OSRM/osrm-backend/actions/workflows/osrm-backend.yml) [](https://codecov.io/gh/Project-OSRM/osrm-backend) [](https://discord.gg/es9CdcCXcb)
|
||||
|
||||
High performance routing engine written in C++ designed to run on OpenStreetMap data.
|
||||
|
||||
The following services are available via HTTP API, C++ library interface and NodeJs wrapper:
|
||||
- Nearest - Snaps coordinates to the street network and returns the nearest matches
|
||||
- Route - Finds the fastest route between coordinates
|
||||
- Table - Computes the duration or distances of the fastest route between all pairs of supplied coordinates
|
||||
- Match - Snaps noisy GPS traces to the road network in the most plausible way
|
||||
- Trip - Solves the Traveling Salesman Problem using a greedy heuristic
|
||||
- Tile - Generates Mapbox Vector Tiles with internal routing metadata
|
||||
|
||||
To quickly try OSRM use our [demo server](http://map.project-osrm.org) which comes with both the backend and a frontend on top.
|
||||
|
||||
For a quick introduction about how the road network is represented in OpenStreetMap and how to map specific road network features have a look at [the OSM wiki on routing](https://wiki.openstreetmap.org/wiki/Routing) or [this guide about mapping for navigation](https://web.archive.org/web/20221206013651/https://labs.mapbox.com/mapping/mapping-for-navigation/).
|
||||
|
||||
Related [Project-OSRM](https://github.com/Project-OSRM) repositories:
|
||||
- [osrm-frontend](https://github.com/Project-OSRM/osrm-frontend) - User-facing frontend with map. The demo server runs this on top of the backend
|
||||
- [osrm-text-instructions](https://github.com/Project-OSRM/osrm-text-instructions) - Text instructions from OSRM route response
|
||||
- [osrm-backend-docker](https://github.com/project-osrm/osrm-backend/pkgs/container/osrm-backend) - Ready to use Docker images
|
||||
|
||||
## Documentation
|
||||
|
||||
### Full documentation
|
||||
|
||||
- [Hosted documentation](http://project-osrm.org)
|
||||
- [osrm-routed HTTP API documentation](docs/http.md)
|
||||
- [libosrm API documentation](docs/libosrm.md)
|
||||
|
||||
## Contact
|
||||
|
||||
- Discord: [join](https://discord.gg/es9CdcCXcb)
|
||||
- IRC: `irc.oftc.net`, channel: `#osrm` ([Webchat](https://webchat.oftc.net))
|
||||
- Mailinglist: `https://lists.openstreetmap.org/listinfo/osrm-talk`
|
||||
|
||||
## Quick Start
|
||||
|
||||
The easiest and quickest way to setup your own routing engine is to use Docker images we provide.
|
||||
|
||||
There are two pre-processing pipelines available:
|
||||
- Contraction Hierarchies (CH)
|
||||
- Multi-Level Dijkstra (MLD)
|
||||
|
||||
we recommend using MLD by default except for special use-cases such as very large distance matrices where CH is still a better fit for the time being.
|
||||
In the following we explain the MLD pipeline.
|
||||
If you want to use the CH pipeline instead replace `osrm-partition` and `osrm-customize` with a single `osrm-contract` and change the algorithm option for `osrm-routed` to `--algorithm ch`.
|
||||
|
||||
### Using Docker
|
||||
|
||||
We base our Docker images ([backend](https://github.com/Project-OSRM/osrm-backend/pkgs/container/osrm-backend), [frontend](https://hub.docker.com/r/osrm/osrm-frontend/)) on Debian and make sure they are as lightweight as possible. Older backend versions can be found on [Docker Hub](https://hub.docker.com/r/osrm/osrm-backend/).
|
||||
|
||||
Download OpenStreetMap extracts for example from [Geofabrik](http://download.geofabrik.de/)
|
||||
|
||||
wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf
|
||||
|
||||
Pre-process the extract with the car profile and start a routing engine HTTP server on port 5000
|
||||
|
||||
docker run -t -v "${PWD}:/data" ghcr.io/project-osrm/osrm-backend osrm-extract -p /opt/car.lua /data/berlin-latest.osm.pbf || echo "osrm-extract failed"
|
||||
|
||||
The flag `-v "${PWD}:/data"` creates the directory `/data` inside the docker container and makes the current working directory `"${PWD}"` available there. The file `/data/berlin-latest.osm.pbf` inside the container is referring to `"${PWD}/berlin-latest.osm.pbf"` on the host.
|
||||
|
||||
docker run -t -v "${PWD}:/data" ghcr.io/project-osrm/osrm-backend osrm-partition /data/berlin-latest.osrm || echo "osrm-partition failed"
|
||||
docker run -t -v "${PWD}:/data" ghcr.io/project-osrm/osrm-backend osrm-customize /data/berlin-latest.osrm || echo "osrm-customize failed"
|
||||
|
||||
Note there is no `berlin-latest.osrm` file, but multiple `berlin-latest.osrm.*` files, i.e. `berlin-latest.osrm` is not file path, but "base" path referring to set of files and there is an option to omit this `.osrm` suffix completely(e.g. `osrm-partition /data/berlin-latest`).
|
||||
|
||||
docker run -t -i -p 5000:5000 -v "${PWD}:/data" ghcr.io/project-osrm/osrm-backend osrm-routed --algorithm mld /data/berlin-latest.osrm
|
||||
|
||||
Make requests against the HTTP server
|
||||
|
||||
curl "http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true"
|
||||
|
||||
Optionally start a user-friendly frontend on port 9966, and open it up in your browser
|
||||
|
||||
docker run -p 9966:9966 osrm/osrm-frontend
|
||||
xdg-open 'http://127.0.0.1:9966'
|
||||
|
||||
In case Docker complains about not being able to connect to the Docker daemon make sure you are in the `docker` group.
|
||||
|
||||
sudo usermod -aG docker $USER
|
||||
|
||||
After adding yourself to the `docker` group make sure to log out and back in again with your terminal.
|
||||
|
||||
We support the following images in the Container Registry:
|
||||
|
||||
Name | Description
|
||||
-----|------
|
||||
`latest` | `master` compiled with release flag
|
||||
`latest-assertions` | `master` compiled with with release flag, assertions enabled and debug symbols
|
||||
`latest-debug` | `master` compiled with debug flag
|
||||
`<tag>` | specific tag compiled with release flag
|
||||
`<tag>-debug` | specific tag compiled with debug flag
|
||||
|
||||
### Building from Source
|
||||
|
||||
The following targets Ubuntu 22.04.
|
||||
For instructions how to build on different distributions, macOS or Windows see our [Wiki](https://github.com/Project-OSRM/osrm-backend/wiki).
|
||||
|
||||
Install dependencies
|
||||
|
||||
```bash
|
||||
sudo apt install build-essential git cmake pkg-config \
|
||||
libbz2-dev libxml2-dev libzip-dev libboost-all-dev \
|
||||
lua5.2 liblua5.2-dev libtbb-dev
|
||||
```
|
||||
|
||||
Compile and install OSRM binaries
|
||||
|
||||
```bash
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ..
|
||||
cmake --build .
|
||||
sudo cmake --build . --target install
|
||||
```
|
||||
|
||||
### Request Against the Demo Server
|
||||
|
||||
Read the [API usage policy](https://github.com/Project-OSRM/osrm-backend/wiki/Demo-server).
|
||||
|
||||
Simple query with instructions and alternatives on Berlin:
|
||||
|
||||
```
|
||||
curl "https://router.project-osrm.org/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true&alternatives=true"
|
||||
```
|
||||
|
||||
### Using the Node.js Bindings
|
||||
|
||||
The Node.js bindings provide read-only access to the routing engine.
|
||||
We provide API documentation and examples [here](docs/nodejs/api.md).
|
||||
|
||||
You will need a modern `libstdc++` toolchain (`>= GLIBCXX_3.4.26`) for binary compatibility if you want to use the pre-built binaries.
|
||||
For older Ubuntu systems you can upgrade your standard library for example with:
|
||||
|
||||
```
|
||||
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y libstdc++-9-dev
|
||||
```
|
||||
|
||||
You can install the Node.js bindings via `npm install @project-osrm/osrm` or from this repository either via
|
||||
|
||||
npm install
|
||||
|
||||
which will check and use pre-built binaries if they're available for this release and your Node version, or via
|
||||
|
||||
npm install --build-from-source
|
||||
|
||||
to always force building the Node.js bindings from source.
|
||||
|
||||
#### Unscoped packages
|
||||
|
||||
Prior to v5.27.0, the `osrm` Node package was unscoped. If you are upgrading from an old package, you will need to do the following:
|
||||
|
||||
```
|
||||
npm uninstall osrm --save
|
||||
npm install @project-osrm/osrm --save
|
||||
```
|
||||
|
||||
#### Package docs
|
||||
|
||||
For usage details have a look [these API docs](docs/nodejs/api.md).
|
||||
|
||||
An exemplary implementation by a 3rd party with Docker and Node.js can be found [here](https://github.com/door2door-io/osrm-express-server-demo).
|
||||
|
||||
|
||||
Branches
|
||||
--------
|
||||
* The `master` branch will always point to the latest released version of the frontend.
|
||||
* The `develop` branch should always point to a working version with new features and bugfixes (think of it as a nightly-build).
|
||||
* Other branches contain various work in progress.
|
||||
## References in publications
|
||||
|
||||
When using the code in a (scientific) publication, please cite
|
||||
|
||||
Bugtracking
|
||||
-----------
|
||||
Please use the OSRM-Project bug tracker [(4)] for submitting any bug reports or feature requests.
|
||||
|
||||
|
||||
Contribute
|
||||
----------
|
||||
If you like to contribute, simply fork the project and start coding.
|
||||
It is best practice to create a new branch (from the current master) with a descriptive name for your contributions.
|
||||
When you are done, send a pull request from that branch.
|
||||
With this workflow, each pull request is isolated and can be easily merged.
|
||||
|
||||
|
||||
Integration into Project-OSRM repository
|
||||
----------------------------------------
|
||||
The Project-OSRM repository already contains the frontend repository as a submodule.
|
||||
It will always point to the latest deployed version.
|
||||
To successfully work a repository that contains submodules, use the following git commands (available in git 1.7.1+):
|
||||
|
||||
* `git clone --recursive`
|
||||
to clone a repository and the contained submodules
|
||||
|
||||
* `git pull && git submodule update`
|
||||
to pull the latest version of the repository and update its submodules if required
|
||||
|
||||
Note that the frontend can also be checked out independently of the Project-OSRM repository.
|
||||
|
||||
|
||||
Compatibility
|
||||
-------------
|
||||
The frontend has been tested with Firefox 3.0+, Internet Explorer 8+ and Chrome 18+.
|
||||
Certain visuals like rounded corners or moving boxes will only show in newer browser versions.
|
||||
But no actual functionality is affected by this.
|
||||
Note that the frontend will not work with Internet Explorer 6 or 7.
|
||||
|
||||
|
||||
References
|
||||
----------
|
||||
[(1)] Cloudmade Leaflet: http://leaflet.cloudmade.com/
|
||||
[(2)] Project OSRM: http://project-osrm.org/
|
||||
[(3)] Project OSRM Frontend: http://map.project-osrm.org/
|
||||
[(4)] Project OSRM Bugtracker: https://github.com/DennisOSRM/Project-OSRM/issues/
|
||||
|
||||
|
||||
[(1)]: http://leaflet.cloudmade.com/ "Cloudmade Leaflet"
|
||||
[(2)]: http://project-osrm.org/ "Project OSRM"
|
||||
[(3)]: http://map.project-osrm.org/ "Project-OSRM Frontend"
|
||||
[(4)]: https://github.com/DennisOSRM/Project-OSRM/issues/ "Project-OSRM Bugtracker"
|
||||
```
|
||||
@inproceedings{luxen-vetter-2011,
|
||||
author = {Luxen, Dennis and Vetter, Christian},
|
||||
title = {Real-time routing with OpenStreetMap data},
|
||||
booktitle = {Proceedings of the 19th ACM SIGSPATIAL International Conference on Advances in Geographic Information Systems},
|
||||
series = {GIS '11},
|
||||
year = {2011},
|
||||
isbn = {978-1-4503-1031-4},
|
||||
location = {Chicago, Illinois},
|
||||
pages = {513--516},
|
||||
numpages = {4},
|
||||
url = {http://doi.acm.org/10.1145/2093973.2094062},
|
||||
doi = {10.1145/2093973.2094062},
|
||||
acmid = {2094062},
|
||||
publisher = {ACM},
|
||||
address = {New York, NY, USA},
|
||||
}
|
||||
```
|
||||
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM base class
|
||||
// [has to be loaded before all other OSRM classes]
|
||||
|
||||
var OSRM = {};
|
||||
OSRM.VERSION = '0.1.8.1';
|
||||
OSRM.DATE = '120918';
|
||||
OSRM.CONSTANTS = {};
|
||||
OSRM.DEFAULTS = {};
|
||||
OSRM.GLOBALS = {};
|
||||
OSRM.Control = {}; // control container
|
||||
OSRM.G = OSRM.GLOBALS; // abbreviations
|
||||
OSRM.C = OSRM.CONSTANTS;
|
@ -1,116 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM config file
|
||||
// [has to be loaded directly after OSRM.base]
|
||||
|
||||
OSRM.DEFAULTS = {
|
||||
ROUTING_ENGINES: [
|
||||
{ url: 'http://router.project-osrm.org/viaroute',
|
||||
timestamp: 'http://router.project-osrm.org/timestamp',
|
||||
metric: 0,
|
||||
label: 'ENGINE_0',
|
||||
}
|
||||
],
|
||||
|
||||
WEBSITE_URL: document.URL.replace(/#*(\?.*|$)/i,""), // truncates URL before first ?, and removes tailing #
|
||||
HOST_GEOCODER_URL: 'http://nominatim.openstreetmap.org/search',
|
||||
HOST_REVERSE_GEOCODER_URL: 'http://nominatim.openstreetmap.org/reverse',
|
||||
HOST_SHORTENER_URL: 'http://map.project-osrm.org/shorten/',
|
||||
|
||||
SHORTENER_PARAMETERS: '%url&jsonp=%jsonp',
|
||||
SHORTENER_REPLY_PARAMETER: 'ShortURL',
|
||||
|
||||
ROUTING_ENGINE: 0,
|
||||
DISTANCE_FORMAT: 0, // 0: km, 1: miles
|
||||
GEOCODER_BOUNDS: '',
|
||||
ZOOM_LEVEL: 14,
|
||||
HIGHLIGHT_ZOOM_LEVEL: 16,
|
||||
JSONP_TIMEOUT: 10000,
|
||||
|
||||
ONLOAD_ZOOM_LEVEL: 5,
|
||||
ONLOAD_LATITUDE: 48.84,
|
||||
ONLOAD_LONGITUDE: 10.10,
|
||||
ONLOAD_SOURCE: "",
|
||||
ONLOAD_TARGET: "",
|
||||
|
||||
LANGUAGE: "en",
|
||||
LANUGAGE_ONDEMAND_RELOADING: true,
|
||||
LANGUAGE_SUPPORTED: [
|
||||
{encoding:"en", name:"English"},
|
||||
{encoding:"bg", name:"Български"},
|
||||
{encoding:"cs", name:"Česky"},
|
||||
{encoding:"de", name:"Deutsch"},
|
||||
{encoding:"dk", name:"Dansk"},
|
||||
{encoding:"es", name:"Español"},
|
||||
{encoding:"fi", name:"Suomi"},
|
||||
{encoding:"fr", name:"Français"},
|
||||
{encoding:"it", name:"Italiano"},
|
||||
{encoding:"ja", name:"日本人"},
|
||||
{encoding:"lv", name:"Latviešu"},
|
||||
{encoding:"pl", name:"Polski"},
|
||||
{encoding:"pt", name:"Portugues"},
|
||||
{encoding:"ro", name:"Română"},
|
||||
{encoding:"ru", name:"Русский"},
|
||||
{encoding:"sv", name:"Svenska"},
|
||||
{encoding:"tr", name:"Türkçe"}
|
||||
],
|
||||
|
||||
TILE_SERVERS: [
|
||||
{ display_name: 'osm.org',
|
||||
url:'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
attribution:'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 Mapnik',
|
||||
options:{maxZoom: 18}
|
||||
},
|
||||
{ display_name: 'osm.de',
|
||||
url:'http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png',
|
||||
attribution:'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 Mapnik',
|
||||
options:{maxZoom: 18}
|
||||
},
|
||||
{ display_name: 'MapQuest',
|
||||
url:'http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png',
|
||||
attribution:'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 MapQuest',
|
||||
options:{maxZoom: 18, subdomains: '1234'}
|
||||
},
|
||||
{ display_name: 'CloudMade',
|
||||
url:'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
|
||||
attribution:'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade',
|
||||
options:{maxZoom: 18}
|
||||
},
|
||||
{
|
||||
display_name: 'Bing Road',
|
||||
apikey:'AjCb2f6Azv_xt9c6pl_xok96bgAYrXQNctnG4o07sTj4iS9N68Za4B3pRJyeCjGr', // please use your own apikey (http://msdn.microsoft.com/en-us/library/ff428642.aspx)
|
||||
options:{type:"Road", minZoom: 1},
|
||||
bing:true,
|
||||
},
|
||||
{
|
||||
display_name: 'Bing Aerial',
|
||||
apikey:'AjCb2f6Azv_xt9c6pl_xok96bgAYrXQNctnG4o07sTj4iS9N68Za4B3pRJyeCjGr', // please use your own apikey (http://msdn.microsoft.com/en-us/library/ff428642.aspx)
|
||||
options:{type:"Aerial", minZoom: 1},
|
||||
bing:true,
|
||||
}
|
||||
],
|
||||
|
||||
NOTIFICATIONS: {
|
||||
LOCALIZATION: 1800000, // 30min
|
||||
CLICKING: 60000, // 1min
|
||||
DRAGGING: 120000, // 2min
|
||||
MAINTENANCE: false
|
||||
},
|
||||
OVERRIDE_MAINTENANCE_NOTIFICATION_HEADER: undefined,
|
||||
OVERRIDE_MAINTENANCE_NOTIFICATION_BODY: undefined
|
||||
};
|
@ -1,297 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM geocoding routines
|
||||
// [geocoder query, management and display of geocoder results]
|
||||
|
||||
// some constants
|
||||
OSRM.CONSTANTS.SOURCE_LABEL = "source";
|
||||
OSRM.CONSTANTS.TARGET_LABEL = "target";
|
||||
OSRM.CONSTANTS.VIA_LABEL = "via";
|
||||
OSRM.CONSTANTS.DO_FALLBACK_TO_LAT_LNG = true;
|
||||
|
||||
|
||||
OSRM.Geocoder = {
|
||||
|
||||
//[normal geocoding]
|
||||
|
||||
// process input request and call geocoder if needed
|
||||
call: function(marker_id, query) {
|
||||
if(query=="")
|
||||
return;
|
||||
|
||||
// geo coordinates given -> directly draw results
|
||||
if(query.match(/^\s*[-+]?[0-9]*\.?[0-9]+\s*[,;]\s*[-+]?[0-9]*\.?[0-9]+\s*$/)){
|
||||
var coord = query.split(/[,;]/);
|
||||
OSRM.Geocoder._onclickResult(marker_id, coord[0], coord[1]);
|
||||
OSRM.Geocoder.updateAddress( marker_id );
|
||||
return;
|
||||
}
|
||||
|
||||
// build basic request for geocoder
|
||||
var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json&json_callback=%jsonp" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&accept-language="+OSRM.Localization.current_language+"&limit=30&q=" + query;
|
||||
// prioritize results in currently shown mapview
|
||||
var bounds = OSRM.G.map.getBounds();
|
||||
call += "&viewbox=" + bounds._southWest.lat + "," + bounds._northEast.lng + "," + bounds._northEast.lat + "," + bounds._southWest.lng;
|
||||
OSRM.JSONP.call( call, OSRM.Geocoder._showResults, OSRM.Geocoder._showResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_"+marker_id, {marker_id:marker_id,query:query} );
|
||||
},
|
||||
|
||||
|
||||
// helper function for clicks on geocoder search results
|
||||
_onclickResult: function(marker_id, lat, lon) {
|
||||
var index;
|
||||
if( marker_id == OSRM.C.SOURCE_LABEL )
|
||||
index = OSRM.G.markers.setSource( new L.LatLng(lat, lon) );
|
||||
else if( marker_id == OSRM.C.TARGET_LABEL )
|
||||
index = OSRM.G.markers.setTarget( new L.LatLng(lat, lon) );
|
||||
else
|
||||
return;
|
||||
|
||||
OSRM.G.markers.route[index].show();
|
||||
OSRM.G.markers.route[index].centerView();
|
||||
if( OSRM.G.markers.route.length > 1 )
|
||||
OSRM.Routing.getRoute();
|
||||
},
|
||||
|
||||
|
||||
// process geocoder response
|
||||
_showResults: function(response, parameters) {
|
||||
if(!response){
|
||||
OSRM.Geocoder._showResults_Empty(parameters);
|
||||
return;
|
||||
}
|
||||
if(response.length == 0) {
|
||||
OSRM.Geocoder._showResults_Empty(parameters);
|
||||
return;
|
||||
}
|
||||
|
||||
// filter/sort inputs
|
||||
var filtered_response_temp = []; // filter results
|
||||
for(var i=0, iEnd=response.length; i < iEnd; i++){
|
||||
var result = response[i];
|
||||
if( OSRM.Geocoder._filterResult( result ) )
|
||||
continue;
|
||||
filtered_response_temp.push( result );
|
||||
}
|
||||
if(filtered_response_temp.length == 0) { // stop if no results remain
|
||||
OSRM.Geocoder._showResults_Empty(parameters);
|
||||
return;
|
||||
}
|
||||
filtered_response_temp.sort( OSRM.Geocoder._compareResults ); // rank results
|
||||
filtered_response_temp.sort( OSRM.Geocoder._compareLocations ); // remove duplicate locations (stable sort -> retain highest ranked)
|
||||
var filtered_response = [];
|
||||
filtered_response.push( filtered_response_temp[0] );
|
||||
for(var i=1, iEnd = filtered_response_temp.length; i<iEnd; i++) {
|
||||
var prev_result = filtered_response_temp[i-1];
|
||||
var result = filtered_response_temp[i];
|
||||
if( result.lat != prev_result.lat || result.lon != prev_result.lon ) {
|
||||
filtered_response.push( result );
|
||||
}
|
||||
}
|
||||
filtered_response.sort( OSRM.Geocoder._compareResults ); // rank results again
|
||||
|
||||
// show first result
|
||||
OSRM.Geocoder._onclickResult(parameters.marker_id, filtered_response[0].lat, filtered_response[0].lon);
|
||||
if( OSRM.G.markers.route.length > 1 ) // if a route is displayed, we don't need to show other possible geocoding results
|
||||
return;
|
||||
|
||||
// show possible results for input
|
||||
var html = "";
|
||||
html += '<table class="results medium-font">';
|
||||
for(var i=0; i < filtered_response.length; i++){
|
||||
var result = filtered_response[i];
|
||||
|
||||
//odd or even ?
|
||||
var rowstyle='results-body-odd';
|
||||
if(i%2==0) { rowstyle='results-body-even'; }
|
||||
|
||||
html += '<tr class="'+rowstyle+'">';
|
||||
if(!result.icon)
|
||||
result.icon = "http://nominatim.openstreetmap.org/images/mapicons/poi_point_of_interest.glow.12.png";
|
||||
html += '<td class="results-body-counter"><img src="'+ result.icon + '" alt=""/></td>';
|
||||
html += '<td class="results-body-items">';
|
||||
|
||||
if(result.display_name){
|
||||
html += '<div class="results-body-item" onclick="OSRM.Geocoder._onclickResult(\''+parameters.marker_id+'\', '+result.lat+', '+result.lon+');">'+result.display_name;
|
||||
// debug output to show osm_type, class, type
|
||||
// html += '<br/><span class="results-body-item-remark small-font">[osm_type: ' + result.osm_type + ', class: ' + result.class + ', type: ' + result.type + ']</span>';
|
||||
html += '</div>';
|
||||
}
|
||||
html += "</td></tr>";
|
||||
}
|
||||
html += '</table>';
|
||||
|
||||
document.getElementById('information-box-header').innerHTML =
|
||||
"<div class='header-title'>"+OSRM.loc("SEARCH_RESULTS")+"</div>" +
|
||||
"<div class='header-content'>("+OSRM.loc("FOUND_X_RESULTS").replace(/%i/,filtered_response.length)+")</div>";
|
||||
"<div class='header-content'>(found "+filtered_response.length+" results)"+"</div>";
|
||||
document.getElementById('information-box').innerHTML = html;
|
||||
},
|
||||
_showResults_Empty: function(parameters) {
|
||||
document.getElementById('information-box-header').innerHTML =
|
||||
"<div class='header-title'>"+OSRM.loc("SEARCH_RESULTS")+"</div>" +
|
||||
"<div class='header-content'>("+OSRM.loc("FOUND_X_RESULTS").replace(/%i/,0)+")</div>";
|
||||
if(parameters.marker_id == OSRM.C.SOURCE_LABEL)
|
||||
document.getElementById('information-box').innerHTML = "<div class='no-results big-font'>"+OSRM.loc("NO_RESULTS_FOUND_SOURCE")+": "+parameters.query +"</div>";
|
||||
else if(parameters.marker_id == OSRM.C.TARGET_LABEL)
|
||||
document.getElementById('information-box').innerHTML = "<div class='no-results big-font'>"+OSRM.loc("NO_RESULTS_FOUND_TARGET")+": "+parameters.query +"</div>";
|
||||
else
|
||||
document.getElementById('information-box').innerHTML = "<div class='no-results big-font'>"+OSRM.loc("NO_RESULTS_FOUND")+": "+parameters.query +"</div>";
|
||||
},
|
||||
_showResults_Timeout: function() {
|
||||
document.getElementById('information-box-header').innerHTML =
|
||||
"<div class='header-title'>"+OSRM.loc("SEARCH_RESULTS")+"</div>" +
|
||||
"<div class='header-content'>("+OSRM.loc("FOUND_X_RESULTS").replace(/%i/,0)+")</div>";
|
||||
document.getElementById('information-box').innerHTML = "<div class='no-results big-font'>"+OSRM.loc("TIMED_OUT")+"</div>";
|
||||
},
|
||||
|
||||
|
||||
// filter search results [true: result will not be displayed]
|
||||
_filterResult: function(result) {
|
||||
// if( result.osm_type == "relation")
|
||||
// return true;
|
||||
if( result.type == "aerial_views")
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
|
||||
|
||||
// comparator for sorting results [higher weight: result will appear first]
|
||||
_compare_class_weights: {
|
||||
boundary: 9000,
|
||||
place: 8000,
|
||||
highway: 7000,
|
||||
},
|
||||
_compare_type_weights: {
|
||||
country: 13,
|
||||
state: 12,
|
||||
county: 11,
|
||||
city: 10,
|
||||
town: 9,
|
||||
village: 8,
|
||||
hamlet: 7,
|
||||
suburb: 6,
|
||||
locality: 5,
|
||||
farm: 4
|
||||
},
|
||||
_compareResults: function(lhs, rhs) {
|
||||
var class_values = OSRM.Geocoder._compare_class_weights;
|
||||
var type_values = OSRM.Geocoder._compare_type_weights;
|
||||
|
||||
var lhs_value = (-class_values[ lhs["class"] ] || 0) + (-type_values[ lhs.type ] || 0);
|
||||
var rhs_value = (-class_values[ rhs["class"] ] || 0) + (-type_values[ rhs.type ] || 0);
|
||||
|
||||
return (lhs_value - rhs_value);
|
||||
},
|
||||
|
||||
|
||||
// comparator for sorting objects according to their locations
|
||||
_compareLocations: function(lhs, rhs) {
|
||||
if( lhs.lat != rhs.lat )
|
||||
return lhs.lat < rhs.lat;
|
||||
else
|
||||
return lhs.lon < rhs.lon;
|
||||
},
|
||||
|
||||
|
||||
// [reverse geocoding]
|
||||
|
||||
//update geo coordinates in input boxes
|
||||
updateLocation: function(marker_id) {
|
||||
if (marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource()) {
|
||||
document.getElementById("gui-input-source").value = OSRM.G.markers.route[0].getLat().toFixed(6) + ", " + OSRM.G.markers.route[0].getLng().toFixed(6);
|
||||
} else if (marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget()) {
|
||||
document.getElementById("gui-input-target").value = OSRM.G.markers.route[OSRM.G.markers.route.length-1].getLat().toFixed(6) + ", " + OSRM.G.markers.route[OSRM.G.markers.route.length-1].getLng().toFixed(6);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// update address in input boxes
|
||||
updateAddress: function(marker_id, do_fallback_to_lat_lng) {
|
||||
// build request for reverse geocoder
|
||||
var lat = null;
|
||||
var lng = null;
|
||||
|
||||
if(marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource()) {
|
||||
lat = OSRM.G.markers.route[0].getLat();
|
||||
lng = OSRM.G.markers.route[0].getLng();
|
||||
} else if(marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() ) {
|
||||
lat = OSRM.G.markers.route[OSRM.G.markers.route.length-1].getLat();
|
||||
lng = OSRM.G.markers.route[OSRM.G.markers.route.length-1].getLng();
|
||||
} else
|
||||
return;
|
||||
|
||||
var call = OSRM.DEFAULTS.HOST_REVERSE_GEOCODER_URL + "?format=json&json_callback=%jsonp" + "&accept-language="+OSRM.Localization.current_language + "&lat=" + lat.toFixed(6) + "&lon=" + lng.toFixed(6);
|
||||
OSRM.JSONP.call( call, OSRM.Geocoder._showReverseResults, OSRM.Geocoder._showReverseResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_"+marker_id, {marker_id:marker_id, do_fallback: do_fallback_to_lat_lng} );
|
||||
},
|
||||
|
||||
|
||||
// processing JSONP response of reverse geocoder
|
||||
_showReverseResults: function(response, parameters) {
|
||||
if(!response) {
|
||||
OSRM.Geocoder._showReverseResults_Timeout(response, parameters);
|
||||
return;
|
||||
}
|
||||
|
||||
if(response.address == undefined) {
|
||||
OSRM.Geocoder._showReverseResults_Timeout(response, parameters);
|
||||
return;
|
||||
}
|
||||
|
||||
// build reverse geocoding address
|
||||
var used_address_data = 0;
|
||||
var address = "";
|
||||
if( response.address.road) {
|
||||
address += response.address.road;
|
||||
used_address_data++;
|
||||
}
|
||||
if( response.address.city ) {
|
||||
if( used_address_data > 0 )
|
||||
address += ", ";
|
||||
address += response.address.city;
|
||||
used_address_data++;
|
||||
} else if( response.address.village ) {
|
||||
if( used_address_data > 0 )
|
||||
address += ", ";
|
||||
address += response.address.village;
|
||||
used_address_data++;
|
||||
}
|
||||
if( used_address_data < 2 && response.address.country ) {
|
||||
if( used_address_data > 0 )
|
||||
address += ", ";
|
||||
address += response.address.country;
|
||||
used_address_data++;
|
||||
}
|
||||
if( used_address_data == 0 ) {
|
||||
OSRM.Geocoder._showReverseResults_Timeout(response, parameters);
|
||||
return;
|
||||
}
|
||||
|
||||
// add result to DOM
|
||||
if(parameters.marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource() )
|
||||
document.getElementById("gui-input-source").value = address;
|
||||
else if(parameters.marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() )
|
||||
document.getElementById("gui-input-target").value = address;
|
||||
},
|
||||
_showReverseResults_Timeout: function(response, parameters) {
|
||||
if(!parameters.do_fallback)
|
||||
return;
|
||||
|
||||
OSRM.Geocoder.updateLocation(parameters.marker_id);
|
||||
}
|
||||
|
||||
};
|
@ -1,193 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM route management (handles drawing of route geometry - current route, old route, unnamed route, highlight unnamed streets)
|
||||
// [this holds the route geometry]
|
||||
|
||||
|
||||
OSRM.HistoryRoute = function() {
|
||||
// style and count of history routes
|
||||
this._history_styles = [{color:'#FFFFFF', opacity:0.5, weight:5, dashArray:""},
|
||||
{color:'#0000DD', opacity:0.45, weight:5, dashArray:""},
|
||||
{color:'#0000BB', opacity:0.40, weight:5, dashArray:""},
|
||||
{color:'#000099', opacity:0.35, weight:5, dashArray:""},
|
||||
{color:'#000077', opacity:0.30, weight:5, dashArray:""},
|
||||
{color:'#000055', opacity:0.25, weight:5, dashArray:""},
|
||||
{color:'#000033', opacity:0.20, weight:5, dashArray:""},
|
||||
{color:'#000011', opacity:0.15, weight:5, dashArray:""},
|
||||
{color:'#000000', opacity:0.10, weight:5, dashArray:""}
|
||||
];
|
||||
this._history_length = this._history_styles.length;
|
||||
|
||||
// actual history data
|
||||
this._history = [];
|
||||
for(var i=0, size=this._history_length; i<size; i++) {
|
||||
var history = {};
|
||||
history.route = new OSRM.SimpleRoute("current" , {dashArray:""} );
|
||||
history.markers = [];
|
||||
history.checksum = null;
|
||||
this._history.push(history);
|
||||
}
|
||||
|
||||
// helper functions bound to this
|
||||
this._initiate_redrawHistory = OSRM.bind(this, this._getRoute_RedrawHistory);
|
||||
this._callback_redrawHistory = OSRM.bind(this, this._showRoute_RedrawHistory);
|
||||
};
|
||||
OSRM.extend( OSRM.HistoryRoute,{
|
||||
// switch history routes on/off
|
||||
activate: function() {
|
||||
this.storeHistoryRoute = this._storeHistoryRoute;
|
||||
this.fetchHistoryRoute = this._fetchHistoryRoute;
|
||||
this.showHistoryRoutes = this._showHistoryRoutes;
|
||||
this.clearHistoryRoutes = this._clearHistoryRoutes;
|
||||
OSRM.G.map.on('zoomend', this._initiate_redrawHistory );
|
||||
|
||||
this.storeHistoryRoute();
|
||||
},
|
||||
deactivate: function() {
|
||||
this.clearHistoryRoutes();
|
||||
|
||||
this.storeHistoryRoute = this.empty;
|
||||
this.fetchHistoryRoute = this.empty;
|
||||
this.showHistoryRoutes = this.empty;
|
||||
this.clearHistoryRoutes = this.empty;
|
||||
OSRM.G.map.off('zoomend', this._initiate_redrawHistory );
|
||||
},
|
||||
|
||||
// empty function
|
||||
empty: function() {},
|
||||
storeHistoryRoute: function() {},
|
||||
fetchHistoryRoute: function() {},
|
||||
showHistoryRoutes: function() {},
|
||||
clearHistoryRoutes: function() {},
|
||||
|
||||
// actual functions
|
||||
_storeHistoryRoute: function() {
|
||||
var route = OSRM.G.route;
|
||||
if( !route.isShown() || !route.isRoute() )
|
||||
return;
|
||||
|
||||
// store current route in staging spot
|
||||
var hint_data = OSRM.G.response.hint_data;
|
||||
this._history[0].route.setPositions( route.getPositions() );
|
||||
this._history[0].checksum = hint_data.checksum;
|
||||
this._history[0].markers = [];
|
||||
|
||||
var markers = this._getCurrentMarkers();
|
||||
for(var i=0,size=markers.length; i<size; i++) {
|
||||
var position = { lat:markers[i].lat, lng:markers[i].lng, hint:hint_data.locations[i] };
|
||||
this._history[0].markers.push(position);
|
||||
}
|
||||
},
|
||||
_fetchHistoryRoute: function() {
|
||||
if( this._history[0].markers.length == 0 )
|
||||
return;
|
||||
if( OSRM.G.route.isShown() && this._equalMarkers(this._history[0].markers, this._getCurrentMarkers()) )
|
||||
return;
|
||||
if( this._equalMarkers(this._history[0].markers, this._history[1].markers) )
|
||||
return;
|
||||
|
||||
// move all routes down one position
|
||||
for(var i=this._history_length-1; i>0; i--) {
|
||||
this._history[i].route.setPositions( this._history[i-1].route.getPositions() ); // copying positions quicker than creating new route!
|
||||
this._history[i].markers = this._history[i-1].markers;
|
||||
this._history[i].checksum = this._history[i-1].checksum;
|
||||
}
|
||||
// reset staging spot
|
||||
this._history[0].route.setPositions( [] );
|
||||
this._history[0].markers = [];
|
||||
this._history[0].checksum = null;
|
||||
},
|
||||
_showHistoryRoutes: function() {
|
||||
for(var i=1,size=this._history_length; i<size; i++) {
|
||||
this._history[i].route.setStyle( this._history_styles[i] );
|
||||
this._history[i].route.show();
|
||||
OSRM.G.route.hideOldRoute();
|
||||
}
|
||||
},
|
||||
_clearHistoryRoutes: function() {
|
||||
for(var i=0,size=this._history_length; i<size; i++) {
|
||||
this._history[i].route.hide();
|
||||
this._history[i].route.setPositions( [] );
|
||||
this._history[i].markers = [];
|
||||
this._history[i].checksum = null;
|
||||
}
|
||||
},
|
||||
|
||||
// get positions of current markers (data of jsonp response used, as not all data structures up-to-date!)
|
||||
_getCurrentMarkers: function() {
|
||||
var route = [];
|
||||
|
||||
var positions = OSRM.G.route.getPositions();
|
||||
if(positions.length == 0)
|
||||
return route;
|
||||
|
||||
for(var i=0; i<OSRM.G.response.via_points.length; i++)
|
||||
route.push( {lat:OSRM.G.response.via_points[i][0], lng:OSRM.G.response.via_points[i][1]} );
|
||||
return route;
|
||||
},
|
||||
|
||||
// check if two routes are equivalent by checking their markers
|
||||
_equalMarkers: function(lhs, rhs) {
|
||||
if(lhs.length != rhs.length)
|
||||
return false;
|
||||
for(var i=0,size=lhs.length; i<size; i++) {
|
||||
if( lhs[i].lat.toFixed(5) != rhs[i].lat.toFixed(5) || lhs[i].lng.toFixed(5) != rhs[i].lng.toFixed(5) )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
// requery history routes
|
||||
_showRoute_RedrawHistory: function(response, history_id) {
|
||||
if(!response)
|
||||
return;
|
||||
|
||||
var positions = OSRM.RoutingGeometry._decode(response.route_geometry, 5);
|
||||
this._history[history_id].route.setPositions(positions);
|
||||
this._updateHints(response, history_id);
|
||||
},
|
||||
_getRoute_RedrawHistory: function() {
|
||||
for(var i=0,size=this._history_length; i<size; i++)
|
||||
if( this._history[i].markers.length > 0 ) {
|
||||
OSRM.JSONP.clear('history'+i);
|
||||
OSRM.JSONP.call(this._buildCall(i)+'&instructions=false', this._callback_redrawHistory, OSRM.JSONP.empty, OSRM.DEFAULTS.JSONP_TIMEOUT, 'history'+i, i);
|
||||
}
|
||||
},
|
||||
_buildCall: function(history_id) {
|
||||
var source = OSRM.G.active_routing_server_url;
|
||||
source += '?z=' + OSRM.G.map.getZoom() + '&output=json&jsonp=%jsonp';
|
||||
|
||||
if(this._history[history_id].checksum)
|
||||
source += '&checksum=' + this._history[history_id].checksum;
|
||||
|
||||
var history_markers = this._history[history_id].markers;
|
||||
for(var i=0,size=history_markers.length; i<size; i++) {
|
||||
source += '&loc=' + history_markers[i].lat.toFixed(6) + ',' + history_markers[i].lng.toFixed(6);
|
||||
if( history_markers[i].hint )
|
||||
source += '&hint=' + history_markers[i].hint;
|
||||
}
|
||||
return source;
|
||||
},
|
||||
_updateHints: function(response, history_id) {
|
||||
this._history[history_id].checksum = response.hint_data.checksum;
|
||||
|
||||
var hints = response.hint_data.locations;
|
||||
for(var i=0; i<hints.length; i++)
|
||||
this._history[history_id].markers[i].hint = hints[i];
|
||||
}
|
||||
});
|
@ -1,127 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM map handling
|
||||
// [initialization, event handling, centering relative to UI]
|
||||
|
||||
// will hold the map object
|
||||
OSRM.GLOBALS.map = null;
|
||||
OSRM.GLOBALS.localizable_maps = [];
|
||||
|
||||
|
||||
// map controller
|
||||
// [map initialization, event handling]
|
||||
OSRM.Map = {
|
||||
|
||||
// map initialization
|
||||
init: function() {
|
||||
// check if GUI is initialized!
|
||||
if(OSRM.G.main_handle == null)
|
||||
OSRM.GUI.init();
|
||||
|
||||
// setup tile servers
|
||||
var tile_servers = OSRM.DEFAULTS.TILE_SERVERS;
|
||||
var base_maps = {};
|
||||
for(var i=0, size=tile_servers.length; i<size; i++) {
|
||||
if( tile_servers[i].bing == true ) {
|
||||
base_maps[ tile_servers[i].display_name ] = new L.BingLayer( tile_servers[i].apikey, tile_servers[i].options );
|
||||
OSRM.G.localizable_maps.push( base_maps[ tile_servers[i].display_name ] );
|
||||
} else {
|
||||
tile_servers[i].options.attribution = tile_servers[i].attribution;
|
||||
base_maps[ tile_servers[i].display_name ] = new L.TileLayer( tile_servers[i].url, tile_servers[i].options );
|
||||
}
|
||||
L.Util.stamp( base_maps[ tile_servers[i].display_name ] ); // stamp tile servers so that their order is correct in layers control
|
||||
}
|
||||
|
||||
// setup map
|
||||
OSRM.G.map = new OSRM.Control.Map('map', {
|
||||
center: new L.LatLng(OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE),
|
||||
zoom: OSRM.DEFAULTS.ONLOAD_ZOOM_LEVEL,
|
||||
layers: [base_maps[tile_servers[0].display_name]],
|
||||
zoomAnimation: false, // animations have to be inactive during initialization (leaflet issue #918)
|
||||
fadeAnimation: false,
|
||||
zoomControl: false // use OSRM zoom buttons
|
||||
});
|
||||
|
||||
// add locations control
|
||||
OSRM.G.map.locationsControl = new OSRM.Control.Locations();
|
||||
OSRM.G.map.locationsControl.addTo(OSRM.G.map);
|
||||
|
||||
// add layer control
|
||||
OSRM.G.map.layerControl = new OSRM.Control.Layers(base_maps, {});
|
||||
OSRM.G.map.layerControl.addTo(OSRM.G.map);
|
||||
|
||||
// add zoom control
|
||||
OSRM.G.map.zoomControl = new OSRM.Control.Zoom();
|
||||
OSRM.G.map.zoomControl.addTo(OSRM.G.map);
|
||||
OSRM.G.map.zoomControl.show();
|
||||
|
||||
// add scale control
|
||||
OSRM.G.map.scaleControl = new L.Control.Scale();
|
||||
OSRM.G.map.scaleControl.options.metric = (OSRM.G.DISTANCE_FORMAT != 1);
|
||||
OSRM.G.map.scaleControl.options.imperial = (OSRM.G.DISTANCE_FORMAT == 1);
|
||||
OSRM.G.map.scaleControl.addTo(OSRM.G.map);
|
||||
|
||||
// map events
|
||||
OSRM.G.map.on('zoomend', OSRM.Map.zoomed );
|
||||
OSRM.G.map.on('click', OSRM.Map.click );
|
||||
OSRM.G.map.on('contextmenu', OSRM.Map.contextmenu );
|
||||
OSRM.G.map.on('mousemove', OSRM.Map.mousemove );
|
||||
},
|
||||
initFinally: function() {
|
||||
L.Util.setOptions( OSRM.G.map, {
|
||||
zoomAnimation: true,
|
||||
fadeAnimation: true
|
||||
} );
|
||||
},
|
||||
|
||||
// init map position and zoom (respect UI visibility / use browser geolocation)
|
||||
initPosition: function() {
|
||||
var position = new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE);
|
||||
OSRM.G.map.setViewUI( position, OSRM.DEFAULTS.ONLOAD_ZOOM_LEVEL, true);
|
||||
if (navigator.geolocation && document.URL.indexOf("file://") == -1) // convenience: FF does not save access rights for local files
|
||||
navigator.geolocation.getCurrentPosition(OSRM.Map.geolocationResponse);
|
||||
},
|
||||
|
||||
// map event handlers
|
||||
zoomed: function(e) {
|
||||
if(OSRM.G.dragging)
|
||||
OSRM.Routing.getRoute_Dragging();
|
||||
else
|
||||
OSRM.Routing.getRoute_Redraw({keepAlternative:true});
|
||||
},
|
||||
contextmenu: function(e) {;},
|
||||
mousemove: function(e) { OSRM.Via.drawDragMarker(e); },
|
||||
click: function(e) {
|
||||
OSRM.GUI.deactivateTooltip( "CLICKING" );
|
||||
if( !OSRM.G.markers.hasSource() ) {
|
||||
var index = OSRM.G.markers.setSource( e.latlng );
|
||||
OSRM.Geocoder.updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
|
||||
OSRM.G.markers.route[index].show();
|
||||
OSRM.Routing.getRoute( {recenter:OSRM.G.markers.route.length == 2} ); // allow recentering when the route is first shown
|
||||
} else if( !OSRM.G.markers.hasTarget() ) {
|
||||
var index = OSRM.G.markers.setTarget( e.latlng );
|
||||
OSRM.Geocoder.updateAddress( OSRM.C.TARGET_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
|
||||
OSRM.G.markers.route[index].show();
|
||||
OSRM.Routing.getRoute( {recenter:OSRM.G.markers.route.length == 2} ); // allow recentering when the route is first shown
|
||||
}
|
||||
},
|
||||
geolocationResponse: function(response) {
|
||||
var latlng = new L.LatLng(response.coords.latitude, response.coords.longitude);
|
||||
OSRM.G.map.setViewUI(latlng, OSRM.DEFAULTS.ZOOM_LEVEL );
|
||||
}
|
||||
};
|
@ -1,142 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM marker management (all route markers should only be set and deleted with these routines!)
|
||||
// [this holds the vital information of the route]
|
||||
|
||||
OSRM.Markers = function() {
|
||||
this.route = new Array();
|
||||
this.highlight = new OSRM.DragMarker("highlight", {zIndexOffset:-1,draggable:true,icon:OSRM.G.icons['marker-highlight'],dragicon:OSRM.G.icons['marker-highlight-drag']});;
|
||||
this.hover = new OSRM.Marker("hover", {zIndexOffset:-1,draggable:false,icon:OSRM.G.icons['marker-highlight']});;
|
||||
this.dragger = new OSRM.DragMarker("drag", {draggable:true,icon:OSRM.G.icons['marker-drag'],dragicon:OSRM.G.icons['marker-drag']});;
|
||||
};
|
||||
OSRM.extend( OSRM.Markers,{
|
||||
reset: function() {
|
||||
// remove route markers
|
||||
for(var i=0; i<this.route.length;i++)
|
||||
this.route[i].hide();
|
||||
this.route.splice(0, this.route.length);
|
||||
document.getElementById('gui-delete-source').style.visibility = "hidden";
|
||||
document.getElementById('gui-delete-target').style.visibility = "hidden";
|
||||
// remove special markers
|
||||
this.highlight.hide();
|
||||
this.dragger.hide();
|
||||
},
|
||||
removeVias: function() {
|
||||
// assert correct route array s - v - t
|
||||
for(var i=1; i<this.route.length-1;i++)
|
||||
this.route[i].hide();
|
||||
this.route.splice(1, this.route.length-2);
|
||||
},
|
||||
setSource: function(position) {
|
||||
// source node is always first node
|
||||
if( this.route[0] && this.route[0].label == OSRM.C.SOURCE_LABEL )
|
||||
this.route[0].setPosition(position);
|
||||
else
|
||||
this.route.splice(0,0, new OSRM.RouteMarker(OSRM.C.SOURCE_LABEL, {draggable:true,icon:OSRM.G.icons['marker-source'],dragicon:OSRM.G.icons['marker-source-drag']}, position));
|
||||
document.getElementById('gui-delete-source').style.visibility = "visible";
|
||||
return 0;
|
||||
},
|
||||
setTarget: function(position) {
|
||||
// target node is always last node
|
||||
if( this.route[this.route.length-1] && this.route[ this.route.length-1 ].label == OSRM.C.TARGET_LABEL )
|
||||
this.route[this.route.length-1].setPosition(position);
|
||||
else
|
||||
this.route.splice( this.route.length,0, new OSRM.RouteMarker(OSRM.C.TARGET_LABEL, {draggable:true,icon:OSRM.G.icons['marker-target'],dragicon:OSRM.G.icons['marker-target-drag']}, position));
|
||||
document.getElementById('gui-delete-target').style.visibility = "visible";
|
||||
return this.route.length-1;
|
||||
},
|
||||
setVia: function(id, position) {
|
||||
// via nodes only between source and target nodes
|
||||
if( this.route.length<2 || id > this.route.length-2 )
|
||||
return -1;
|
||||
|
||||
this.route.splice(id+1,0, new OSRM.RouteMarker(OSRM.C.VIA_LABEL, {draggable:true,icon:OSRM.G.icons['marker-via'],dragicon:OSRM.G.icons['marker-via-drag']}, position));
|
||||
return id+1;
|
||||
},
|
||||
removeMarker: function(id) {
|
||||
if( id >= this.route.length )
|
||||
return;
|
||||
|
||||
// also remove vias if source or target are removed
|
||||
if( id==0 && this.route[0].label == OSRM.C.SOURCE_LABEL ) {
|
||||
this.removeVias();
|
||||
document.getElementById('gui-input-source').value = "";
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-header').innerHTML = "";
|
||||
document.getElementById('gui-delete-source').style.visibility = "hidden";
|
||||
} else if( id == this.route.length-1 && this.route[ this.route.length-1 ].label == OSRM.C.TARGET_LABEL ) {
|
||||
this.removeVias();
|
||||
id = this.route.length-1;
|
||||
document.getElementById('gui-input-target').value = "";
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-header').innerHTML = "";
|
||||
document.getElementById('gui-delete-target').style.visibility = "hidden";
|
||||
}
|
||||
|
||||
this.route[id].hide();
|
||||
this.route.splice(id, 1);
|
||||
},
|
||||
reverseMarkers: function() {
|
||||
var size = this.route.length;
|
||||
|
||||
// invert route, if a route is shown
|
||||
if( size > 1 ) {
|
||||
// switch positions in nodes
|
||||
var temp_position = this.route[0].getPosition();
|
||||
this.route[0].setPosition( this.route[size-1].getPosition() );
|
||||
this.route[size-1].setPosition( temp_position );
|
||||
// switch nodes in array
|
||||
var temp_node = this.route[0];
|
||||
this.route[0] = this.route[size-1];
|
||||
this.route[size-1] = temp_node;
|
||||
// reverse route
|
||||
this.route.reverse();
|
||||
// clear information (both delete markers stay visible)
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-header').innerHTML = "";
|
||||
|
||||
// invert marker, if only one marker is shown (implicit clear of information / delete markers)
|
||||
} else if( size > 0 ) {
|
||||
var position = this.route[0].getPosition();
|
||||
var label = this.route[0].label;
|
||||
this.removeMarker(0);
|
||||
if( label == OSRM.C.TARGET_LABEL )
|
||||
this.setSource( position );
|
||||
else if( label == OSRM.C.SOURCE_LABEL )
|
||||
this.setTarget( position );
|
||||
this.route[0].show();
|
||||
}
|
||||
|
||||
},
|
||||
hasSource: function() {
|
||||
if( this.route[0] && this.route[0].label == OSRM.C.SOURCE_LABEL )
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
hasTarget: function() {
|
||||
if( this.route[this.route.length-1] && this.route[this.route.length-1].label == OSRM.C.TARGET_LABEL )
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
|
||||
//relabel all via markers
|
||||
relabelViaMarkers: function() {
|
||||
for(var i=1, size=this.route.length-1; i<size; i++)
|
||||
this.route[i].marker.setLabel(i);
|
||||
}
|
||||
});
|
@ -1,149 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM route management (handles drawing of route geometry - current route, old route, unnamed route, highlight unnamed streets)
|
||||
// [this holds the route geometry]
|
||||
|
||||
|
||||
OSRM.Route = function() {
|
||||
this._current_route = new OSRM.SimpleRoute("current" , {dashArray:""} );
|
||||
this._alternative_route = new OSRM.SimpleRoute("alternative" , {dashArray:""} );
|
||||
this._old_route = new OSRM.SimpleRoute("old", {color:"#123", dashArray:""} );
|
||||
this._unnamed_route = new OSRM.MultiRoute("unnamed");
|
||||
|
||||
this._current_route_style = {color:'#0033FF', weight:5, dashArray:""};
|
||||
this._current_noroute_style = {color:'#222222', weight:2, dashArray:"8,6"};
|
||||
this._old_route_style = {color:'#112233', weight:5, dashArray:""};
|
||||
this._old_noroute_style = {color:'#000000', weight:2, dashArray:"8,6"};
|
||||
this._unnamed_route_style = {color:'#FF00FF', weight:10, dashArray:""};
|
||||
this._old_unnamed_route_style = {color:'#990099', weight:10, dashArray:""};
|
||||
this._alternative_route_style = {color:'#770033', weight:5, opacity:0.6, dashArray:""};
|
||||
|
||||
this._noroute = OSRM.Route.ROUTE;
|
||||
this._history = new OSRM.HistoryRoute();
|
||||
};
|
||||
OSRM.Route.NOROUTE = true;
|
||||
OSRM.Route.ROUTE = false;
|
||||
OSRM.extend( OSRM.Route,{
|
||||
|
||||
// show/hide route
|
||||
showRoute: function(positions, noroute) {
|
||||
this._noroute = noroute;
|
||||
this._current_route.setPositions( positions );
|
||||
if ( this._noroute == OSRM.Route.NOROUTE )
|
||||
this._current_route.setStyle( this._current_noroute_style );
|
||||
else
|
||||
this._current_route.setStyle( this._current_route_style );
|
||||
this._current_route.show();
|
||||
//this._raiseUnnamedRoute();
|
||||
|
||||
this._history.fetchHistoryRoute();
|
||||
this._history.showHistoryRoutes();
|
||||
this._history.storeHistoryRoute();
|
||||
},
|
||||
hideRoute: function() {
|
||||
this._current_route.hide();
|
||||
this._unnamed_route.hide();
|
||||
|
||||
this._history.fetchHistoryRoute();
|
||||
this._history.showHistoryRoutes();
|
||||
// deactivate GUI features that need a route
|
||||
OSRM.GUI.deactivateRouteFeatures();
|
||||
},
|
||||
|
||||
// show/hide highlighting for unnamed routes
|
||||
showUnnamedRoute: function(positions) {
|
||||
this._unnamed_route.clearRoutes();
|
||||
for(var i=0; i<positions.length; i++) {
|
||||
this._unnamed_route.addRoute(positions[i]);
|
||||
}
|
||||
this._unnamed_route.setStyle( this._unnamed_route_style );
|
||||
this._unnamed_route.show();
|
||||
},
|
||||
hideUnnamedRoute: function() {
|
||||
this._unnamed_route.hide();
|
||||
},
|
||||
// TODO: hack to put unnamed_route above old_route -> easier way in will be available Leaflet 0.4
|
||||
_raiseUnnamedRoute: function() {
|
||||
if(this._unnamed_route.isShown()) {
|
||||
this._unnamed_route.hide();
|
||||
this._unnamed_route.show();
|
||||
}
|
||||
},
|
||||
|
||||
// show/hide previous route as shadow
|
||||
showOldRoute: function() {
|
||||
this._old_route.setPositions( this._current_route.getPositions() );
|
||||
if ( this._noroute == OSRM.Route.NOROUTE)
|
||||
this._old_route.setStyle( this._old_noroute_style );
|
||||
else
|
||||
this._old_route.setStyle( this._old_route_style );
|
||||
this._old_route.show();
|
||||
this._raiseUnnamedRoute();
|
||||
// change color of unnamed route highlighting - no separate object as dragged route does not have unnamed route highlighting
|
||||
this._unnamed_route.setStyle( this._old_unnamed_route_style );
|
||||
},
|
||||
hideOldRoute: function() {
|
||||
this._old_route.hide();
|
||||
},
|
||||
|
||||
// show/hide alternative route
|
||||
showAlternativeRoute: function(positions) {
|
||||
this._alternative_route.setPositions( positions );
|
||||
this._alternative_route.setStyle( this._alternative_route_style );
|
||||
this._alternative_route.show();
|
||||
},
|
||||
hideAlternativeRoute: function() {
|
||||
this._alternative_route.hide();
|
||||
},
|
||||
|
||||
// query routines
|
||||
isShown: function() {
|
||||
return this._current_route.isShown();
|
||||
},
|
||||
isRoute: function() {
|
||||
return !(this._noroute);
|
||||
},
|
||||
getPositions: function() {
|
||||
return this._current_route.getPositions();
|
||||
},
|
||||
getPoints: function() {
|
||||
return this._current_route.getPoints();
|
||||
},
|
||||
|
||||
// helper routines
|
||||
reset: function() {
|
||||
this.hideRoute();
|
||||
this._old_route.hide();
|
||||
this._noroute = OSRM.Route.ROUTE;
|
||||
this._history.clearHistoryRoutes();
|
||||
},
|
||||
fire: function(type,event) {
|
||||
this._current_route.route.fire(type,event);
|
||||
},
|
||||
centerView: function() {
|
||||
this._current_route.centerView();
|
||||
},
|
||||
|
||||
// handle history routes
|
||||
activateHistoryRoutes: function() {
|
||||
this._history.activate();
|
||||
},
|
||||
deactivateHistoryRoutes: function() {
|
||||
this._history.deactivate();
|
||||
}
|
||||
});
|
@ -1,119 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM via marker routines
|
||||
// [find correct position for a via marker]
|
||||
|
||||
|
||||
OSRM.Via = {
|
||||
|
||||
// find route segment of current route geometry that is closest to the new via node (marked by index of its endpoint)
|
||||
_findNearestRouteSegment: function( new_via ) {
|
||||
var min_dist = Number.MAX_VALUE;
|
||||
var min_index = undefined;
|
||||
|
||||
var p = OSRM.G.map.latLngToLayerPoint( new_via );
|
||||
var positions = OSRM.G.route.getPoints();
|
||||
for(var i=1; i<positions.length; i++) {
|
||||
var _sqDist = L.LineUtil._sqClosestPointOnSegment(p, positions[i-1], positions[i], true);
|
||||
if( _sqDist < min_dist) {
|
||||
min_dist = _sqDist;
|
||||
min_index = i;
|
||||
}
|
||||
}
|
||||
|
||||
return min_index;
|
||||
},
|
||||
|
||||
|
||||
// find the correct index among all via nodes to insert the new via node, and insert it
|
||||
findViaIndex: function( new_via_position ) {
|
||||
// find route segment that is closest to click position (marked by last index)
|
||||
var nearest_index = OSRM.Via._findNearestRouteSegment( new_via_position );
|
||||
|
||||
// find correct index to insert new via node
|
||||
var via_points = OSRM.G.response.via_points;
|
||||
var new_via_index = via_points.length-2;
|
||||
var via_index = Array();
|
||||
for(var i=1; i<via_points.length-1; i++) {
|
||||
via_index[i-1] = OSRM.Via._findNearestRouteSegment( new L.LatLng(via_points[i][0], via_points[i][1]) );
|
||||
if(via_index[i-1] > nearest_index) {
|
||||
new_via_index = i-1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// add via node
|
||||
return new_via_index;
|
||||
},
|
||||
|
||||
|
||||
//function that draws a drag marker
|
||||
dragTimer: new Date(),
|
||||
|
||||
drawDragMarker: function(event) {
|
||||
if( OSRM.G.route.isShown() == false)
|
||||
return;
|
||||
if( OSRM.G.dragging == true )
|
||||
return;
|
||||
|
||||
// throttle computation
|
||||
if( (new Date() - OSRM.Via.dragTimer) < 25 )
|
||||
return;
|
||||
OSRM.Via.dragTimer = new Date();
|
||||
|
||||
// get distance to route
|
||||
var minpoint = OSRM.G.route._current_route.route.closestLayerPoint( event.layerPoint );
|
||||
var min_dist = minpoint ? minpoint.distance : 1000;
|
||||
|
||||
// get distance to markers
|
||||
var mouse = event.latlng;
|
||||
for(var i=0, size=OSRM.G.markers.route.length; i<size; i++) {
|
||||
if(OSRM.G.markers.route[i].label=='drag')
|
||||
continue;
|
||||
var position = OSRM.G.markers.route[i].getPosition();
|
||||
var dist = OSRM.G.map.project(mouse).distanceTo(OSRM.G.map.project(position));
|
||||
if( dist < 20 )
|
||||
min_dist = 1000;
|
||||
}
|
||||
|
||||
// check whether mouse is over another marker
|
||||
var pos = OSRM.G.map.layerPointToContainerPoint(event.layerPoint);
|
||||
var obj = document.elementFromPoint(pos.x,pos.y);
|
||||
for(var i=0, size=OSRM.G.markers.route.length; i<size; i++) {
|
||||
if(OSRM.G.markers.route[i].label=='drag')
|
||||
continue;
|
||||
if( obj == OSRM.G.markers.route[i].marker._icon)
|
||||
min_dist = 1000;
|
||||
}
|
||||
|
||||
// special care for highlight marker
|
||||
if( OSRM.G.markers.highlight.isShown() ) {
|
||||
if( OSRM.G.map.project(mouse).distanceTo(OSRM.G.map.project( OSRM.G.markers.highlight.getPosition() ) ) < 20 )
|
||||
min_dist = 1000;
|
||||
else if( obj == OSRM.G.markers.highlight.marker._icon)
|
||||
min_dist = 1000;
|
||||
}
|
||||
|
||||
if( min_dist < 20) {
|
||||
OSRM.G.markers.dragger.setPosition( OSRM.G.map.layerPointToLatLng(minpoint) );
|
||||
OSRM.G.markers.dragger.show();
|
||||
} else
|
||||
OSRM.G.markers.dragger.hide();
|
||||
}
|
||||
|
||||
};
|
@ -1,147 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2011-2012, Pavel Shramov
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are
|
||||
permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
of conditions and the following disclaimer in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// TileLayer using BingMaps
|
||||
// [modified to support multiple cultures]
|
||||
|
||||
L.BingLayer = L.TileLayer.extend({
|
||||
options: {
|
||||
subdomains: [0, 1, 2, 3],
|
||||
type: 'Aerial', // supported: 'Road', 'Aerial', 'AerialWithLabels'
|
||||
attribution: 'Bing',
|
||||
culture: 'en-US'
|
||||
},
|
||||
|
||||
initialize: function(key, options) {
|
||||
L.Util.setOptions(this, options);
|
||||
|
||||
this._key = key;
|
||||
this._url = null;
|
||||
this.meta = {};
|
||||
this.loadMetadata();
|
||||
},
|
||||
|
||||
tile2quad: function(x, y, z) {
|
||||
var quad = '';
|
||||
for (var i = z; i > 0; i--) {
|
||||
var digit = 0;
|
||||
var mask = 1 << (i - 1);
|
||||
if ((x & mask) != 0) digit += 1;
|
||||
if ((y & mask) != 0) digit += 2;
|
||||
quad = quad + digit;
|
||||
}
|
||||
return quad;
|
||||
},
|
||||
|
||||
getTileUrl: function(p, z) {
|
||||
var z = this._getZoomForUrl();
|
||||
var subdomains = this.options.subdomains,
|
||||
s = this.options.subdomains[(p.x + p.y) % subdomains.length];
|
||||
return this._url.replace('{subdomain}', s)
|
||||
.replace('{quadkey}', this.tile2quad(p.x, p.y, z))
|
||||
.replace('{culture}', this.options.culture);
|
||||
},
|
||||
|
||||
loadMetadata: function() {
|
||||
var _this = this;
|
||||
var cbid = '_bing_metadata_' + L.Util.stamp(this);
|
||||
window[cbid] = function (meta) {
|
||||
_this.meta = meta;
|
||||
window[cbid] = undefined;
|
||||
var e = document.getElementById(cbid);
|
||||
e.parentNode.removeChild(e);
|
||||
if (meta.errorDetails) {
|
||||
alert("Got metadata" + meta.errorDetails);
|
||||
return;
|
||||
}
|
||||
_this.initMetadata();
|
||||
};
|
||||
var url = "http://dev.virtualearth.net/REST/v1/Imagery/Metadata/" + this.options.type + "?include=ImageryProviders&jsonp=" + cbid + "&key=" + this._key;
|
||||
var script = document.createElement("script");
|
||||
script.type = "text/javascript";
|
||||
script.src = url;
|
||||
script.id = cbid;
|
||||
document.getElementsByTagName("head")[0].appendChild(script);
|
||||
},
|
||||
|
||||
initMetadata: function() {
|
||||
var r = this.meta.resourceSets[0].resources[0];
|
||||
this.options.subdomains = r.imageUrlSubdomains;
|
||||
this._url = r.imageUrl;
|
||||
this._providers = [];
|
||||
for (var i = 0; i < r.imageryProviders.length; i++) {
|
||||
var p = r.imageryProviders[i];
|
||||
for (var j = 0; j < p.coverageAreas.length; j++) {
|
||||
var c = p.coverageAreas[j];
|
||||
var coverage = {zoomMin: c.zoomMin, zoomMax: c.zoomMax, active: false};
|
||||
var bounds = new L.LatLngBounds(
|
||||
new L.LatLng(c.bbox[0]+0.01, c.bbox[1]+0.01),
|
||||
new L.LatLng(c.bbox[2]-0.01, c.bbox[3]-0.01)
|
||||
);
|
||||
coverage.bounds = bounds;
|
||||
coverage.attrib = p.attribution;
|
||||
this._providers.push(coverage);
|
||||
}
|
||||
}
|
||||
this._update();
|
||||
},
|
||||
|
||||
_update: function() {
|
||||
if (this._url == null || !this._map) return;
|
||||
this._update_attribution();
|
||||
L.TileLayer.prototype._update.apply(this, []);
|
||||
},
|
||||
|
||||
_update_attribution: function() {
|
||||
var bounds = this._map.getBounds();
|
||||
var zoom = this._map.getZoom();
|
||||
if(this._map.attributionControl) // check if attributionControl is active
|
||||
for (var i = 0; i < this._providers.length; i++) {
|
||||
var p = this._providers[i];
|
||||
if ((zoom <= p.zoomMax && zoom >= p.zoomMin) &&
|
||||
bounds.intersects(p.bounds)) {
|
||||
if (!p.active)
|
||||
this._map.attributionControl.addAttribution(p.attrib);
|
||||
p.active = true;
|
||||
} else {
|
||||
if (p.active)
|
||||
this._map.attributionControl.removeAttribution(p.attrib);
|
||||
p.active = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onRemove: function(map) {
|
||||
if(this._map.attributionControl) // check if attributionControl is activ
|
||||
for (var i = 0; i < this._providers.length; i++) {
|
||||
var p = this._providers[i];
|
||||
if (p.active) {
|
||||
this._map.attributionControl.removeAttribution(p.attrib);
|
||||
p.active = false;
|
||||
}
|
||||
}
|
||||
L.TileLayer.prototype.onRemove.apply(this, [map]);
|
||||
}
|
||||
});
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// Leaflet bugfixes
|
||||
// [assorted bugfixes to Leaflet functions we use]
|
||||
|
||||
|
||||
// bugfix for issue #892 of Leaflet
|
||||
L.DomUtil.enableTextSelection = function () {
|
||||
if( !document.onselectstart )
|
||||
return;
|
||||
document.onselectstart = this._onselectstart;
|
||||
this._onselectstart = null;
|
||||
};
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// Leaflet extension: LabelMarker
|
||||
// [marker class that allows for changing icons while dragging]
|
||||
|
||||
|
||||
// extended marker class
|
||||
L.LabelMarker = L.Marker.extend({
|
||||
// change marker icon
|
||||
changeIcon: function( icon ) {
|
||||
this.options.icon = icon;
|
||||
|
||||
if (this._map) {
|
||||
this._changeIcon();
|
||||
}
|
||||
},
|
||||
|
||||
// add/change marker label
|
||||
setLabel: function( label ) {
|
||||
if(this._icon) {
|
||||
this._icon.lastChild.innerHTML=label;
|
||||
this._icon.lastChild.style.display = "block";
|
||||
}
|
||||
},
|
||||
|
||||
// add/change marker tooltip
|
||||
setTitle: function ( title ) {
|
||||
this.options.title = title;
|
||||
this._icon.title = title;
|
||||
},
|
||||
|
||||
// actual icon changing routine
|
||||
_changeIcon: function () {
|
||||
var options = this.options,
|
||||
map = this._map,
|
||||
animation = (map.options.zoomAnimation && map.options.markerZoomAnimation),
|
||||
classToAdd = animation ? 'leaflet-zoom-animated' : 'leaflet-zoom-hide';
|
||||
|
||||
if (this._icon) {
|
||||
this._icon = options.icon.changeIcon( this._icon );
|
||||
L.DomUtil.addClass(this._icon, classToAdd);
|
||||
L.DomUtil.addClass(this._icon, 'leaflet-clickable');
|
||||
}
|
||||
}
|
||||
});
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// Leaflet extension: LabelMarkerIcon
|
||||
// [icon class with extra label and simple icon changing]
|
||||
|
||||
|
||||
// extended icon class
|
||||
L.LabelMarkerIcon = L.Icon.extend({
|
||||
// altered icon creation (with label)
|
||||
_createImg: function (src) {
|
||||
var el;
|
||||
if (!L.Browser.ie6) {
|
||||
el = document.createElement('div');
|
||||
|
||||
var img = document.createElement('img');
|
||||
var num = document.createElement('div');
|
||||
img.src = src;
|
||||
num.className = 'via-counter';
|
||||
num.innerHTML = "";
|
||||
|
||||
el.appendChild(img);
|
||||
el.appendChild(num);
|
||||
} else {
|
||||
el = document.createElement('div');
|
||||
el.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '")';
|
||||
}
|
||||
return el;
|
||||
},
|
||||
|
||||
// non-destructive icon changing
|
||||
changeIcon: function (el) {
|
||||
return this._changeIcon('icon', el);
|
||||
},
|
||||
|
||||
changeShadow: function (el) {
|
||||
return this.options.shadowUrl ? this._changeIcon('shadow', el) : null;
|
||||
},
|
||||
|
||||
_changeIcon: function (name, el) {
|
||||
var src = this._getIconUrl(name);
|
||||
if (!src) {
|
||||
if (name === 'icon') {
|
||||
throw new Error("iconUrl not set in Icon options (see the docs).");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
var img = this._changeImg(src, el);
|
||||
this._setIconStyles(img, name);
|
||||
|
||||
return img;
|
||||
},
|
||||
|
||||
_changeImg: function (src, el) {
|
||||
if (!L.Browser.ie6) {
|
||||
el.firstChild.src = src;
|
||||
} else {
|
||||
el.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '")';
|
||||
}
|
||||
return el;
|
||||
}
|
||||
});
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM Layers control
|
||||
// [extension of Layers.Control with OSRM styling and additional query methods]
|
||||
OSRM.Control.Layers = L.Control.Layers.extend({
|
||||
|
||||
// query functionality
|
||||
getActiveLayerName: function () {
|
||||
var i, input, obj,
|
||||
inputs = this._form.getElementsByTagName('input'),
|
||||
inputsLen = inputs.length;
|
||||
|
||||
for (i = 0; i < inputsLen; i++) {
|
||||
input = inputs[i];
|
||||
obj = this._layers[input.layerId];
|
||||
if (input.checked && !obj.overlay) {
|
||||
return obj.name;
|
||||
}
|
||||
}
|
||||
},
|
||||
getActiveLayer: function () {
|
||||
var i, input, obj,
|
||||
inputs = this._form.getElementsByTagName('input'),
|
||||
inputsLen = inputs.length;
|
||||
|
||||
for (i = 0; i < inputsLen; i++) {
|
||||
input = inputs[i];
|
||||
obj = this._layers[input.layerId];
|
||||
if (input.checked && !obj.overlay) {
|
||||
return obj.layer;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// overwrite Control.Layers methods to get OSRM styling
|
||||
_initLayout: function () {
|
||||
L.Control.Layers.prototype._initLayout.apply(this);
|
||||
this._container.className = "box-wrapper gui-control-wrapper";
|
||||
this._layersLink.className = "box-content gui-control gui-layers";
|
||||
this._form.className = "box-content gui-control gui-layers-list medium-font";
|
||||
|
||||
this._baseLayersList.className = "gui-layers-base";
|
||||
this._separator.className = "gui-layers-separator";
|
||||
this._overlaysList.className = "gui-layers-overlays";
|
||||
},
|
||||
_expand: function () {
|
||||
L.DomUtil.addClass(this._container, 'gui-layers-expanded');
|
||||
},
|
||||
_collapse: function () {
|
||||
this._container.className = this._container.className.replace(' gui-layers-expanded', '');
|
||||
}
|
||||
|
||||
});
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// locations control
|
||||
// [navigation buttons for important locations - zoom on route, zoom on user]
|
||||
OSRM.Control.Locations = L.Control.extend({
|
||||
options: {
|
||||
position: 'topright'
|
||||
},
|
||||
|
||||
onAdd: function (map) {
|
||||
// create wrapper
|
||||
var container = L.DomUtil.create('div', 'box-wrapper gui-control-wrapper');
|
||||
L.DomEvent.disableClickPropagation(container);
|
||||
|
||||
// create buttons
|
||||
this._userButton = this._createButton('gui-locations-user', container, OSRM.GUI.zoomOnUser, map, !!navigator.geolocation );
|
||||
this._routeButton = this._createButton('gui-locations-route', container, OSRM.GUI.zoomOnRoute, map, false);
|
||||
|
||||
this._container = container;
|
||||
return container;
|
||||
},
|
||||
|
||||
_createButton: function (id, container, fn, context, isActive) {
|
||||
var inactive = (isActive == false) ? "-inactive" : "";
|
||||
var classNames = "box-content" + " " + "gui-control"+inactive + " " + id+inactive;
|
||||
var link = L.DomUtil.create('a', classNames, container);
|
||||
link.title = id;
|
||||
|
||||
L.DomEvent
|
||||
.on(link, 'click', L.DomEvent.stopPropagation)
|
||||
.on(link, 'click', L.DomEvent.preventDefault)
|
||||
.on(link, 'click', fn, context)
|
||||
.on(link, 'dblclick', L.DomEvent.stopPropagation);
|
||||
|
||||
return link;
|
||||
},
|
||||
|
||||
activateRoute: function() {
|
||||
this._routeButton.className = "box-content gui-control gui-locations-route";
|
||||
},
|
||||
deactivateRoute: function() {
|
||||
this._routeButton.className = "box-content gui-control-inactive gui-locations-route-inactive";
|
||||
},
|
||||
setTooltips: function( userButton, routeButton) {
|
||||
this._userButton.title = userButton;
|
||||
this._routeButton.title = routeButton;
|
||||
}
|
||||
});
|
@ -1,123 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM Map control
|
||||
// [extension of L.Map with additional view & bounds methods that respect OSRM UI visibility; methods for querying active layers]
|
||||
OSRM.Control.Map = L.Map.extend({
|
||||
_boundsInsideView: function(bounds) {
|
||||
var viewBounds = this.getBounds(),
|
||||
viewSw = this.project(viewBounds.getSouthWest()),
|
||||
viewNe = this.project(viewBounds.getNorthEast()),
|
||||
sw = this.project(bounds.getSouthWest()),
|
||||
ne = this.project(bounds.getNorthEast());
|
||||
|
||||
if (viewNe.y > ne.y) { // north
|
||||
return false;
|
||||
}
|
||||
if (viewNe.x < ne.x) { // east
|
||||
return false;
|
||||
}
|
||||
if (viewSw.y < sw.y) { // south
|
||||
return false;
|
||||
}
|
||||
if (viewSw.x > sw.x) { // west
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
setViewBounds: function(bounds) {
|
||||
var zoom = this.getBoundsZoom(bounds); // maximum zoom level at which the bounds fit onto the map
|
||||
|
||||
if( this._zoom > zoom ) { // if current zoom level is too close change zoom level and recenter
|
||||
this.setView(bounds.getCenter(), zoom);
|
||||
} else if(!this._boundsInsideView(bounds)){ // if current zoom level is okay, but bounds are outside the viewport, pan
|
||||
this.setView(bounds.getCenter(), this._zoom);
|
||||
}
|
||||
},
|
||||
setViewUI: function(position, zoom, no_animation) {
|
||||
if( OSRM.G.main_handle.boxVisible() ) {
|
||||
var point = this.project( position, zoom);
|
||||
point.x-=OSRM.G.main_handle.boxWidth()/2;
|
||||
position = this.unproject(point,zoom);
|
||||
}
|
||||
this.setView( position, zoom, no_animation);
|
||||
},
|
||||
setViewBoundsUI: function(bounds) {
|
||||
var southwest = bounds.getSouthWest();
|
||||
var northeast = bounds.getNorthEast();
|
||||
var zoom = this.getBoundsZoom(bounds);
|
||||
var sw_point = this.project( southwest, zoom);
|
||||
if( OSRM.G.main_handle.boxVisible() )
|
||||
sw_point.x-=OSRM.G.main_handle.boxWidth()+20;
|
||||
else
|
||||
sw_point.x-=20;
|
||||
sw_point.y+=20;
|
||||
var ne_point = this.project( northeast, zoom);
|
||||
ne_point.y-=20;
|
||||
ne_point.x+=20;
|
||||
bounds.extend( this.unproject(sw_point,zoom) );
|
||||
bounds.extend( this.unproject(ne_point,zoom) );
|
||||
this.setViewBounds( bounds );
|
||||
},
|
||||
fitBoundsUI: function(bounds) {
|
||||
var southwest = bounds.getSouthWest();
|
||||
var northeast = bounds.getNorthEast();
|
||||
var zoom = this.getBoundsZoom(bounds);
|
||||
var sw_point = this.project( southwest, zoom);
|
||||
if( OSRM.G.main_handle.boxVisible() )
|
||||
sw_point.x-=OSRM.G.main_handle.boxWidth()+20;
|
||||
else
|
||||
sw_point.x-=20;
|
||||
sw_point.y+=20;
|
||||
var ne_point = this.project( northeast, zoom);
|
||||
ne_point.y-=20;
|
||||
ne_point.x+=20;
|
||||
bounds.extend( this.unproject(sw_point,zoom) );
|
||||
bounds.extend( this.unproject(ne_point,zoom) );
|
||||
this.fitBounds( bounds );
|
||||
},
|
||||
getBoundsUI: function(unbounded) {
|
||||
var bounds = this.getPixelBounds();
|
||||
if( OSRM.G.main_handle.boxVisible() )
|
||||
bounds.min.x+=OSRM.G.main_handle.boxWidth();
|
||||
var sw = this.unproject(new L.Point(bounds.min.x, bounds.max.y), this._zoom, true),
|
||||
ne = this.unproject(new L.Point(bounds.max.x, bounds.min.y), this._zoom, true);
|
||||
return new L.LatLngBounds(sw, ne);
|
||||
},
|
||||
getCenterUI: function(unbounded) {
|
||||
var viewHalf = this.getSize();
|
||||
if( OSRM.G.main_handle.boxVisible() )
|
||||
viewHalf.x += OSRM.G.main_handle.boxWidth();
|
||||
var centerPoint = this._getTopLeftPoint().add(viewHalf.divideBy(2));
|
||||
|
||||
return this.unproject(centerPoint, this._zoom, unbounded);
|
||||
},
|
||||
getActiveLayerId: function() {
|
||||
var tile_server_id = 0;
|
||||
|
||||
var tile_servers = OSRM.DEFAULTS.TILE_SERVERS;
|
||||
var tile_server_name = this.layerControl.getActiveLayerName();
|
||||
for(var i=0, size=tile_servers.length; i<size; i++) {
|
||||
if( tile_servers[i].display_name == tile_server_name ) {
|
||||
tile_server_id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return tile_server_id;
|
||||
}
|
||||
});
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// zoom control
|
||||
// [modified zoom control with ids, prevention of click propagation, show/hide with respect to main OSRM window]
|
||||
OSRM.Control.Zoom = L.Control.extend({
|
||||
options: {
|
||||
position: 'topleft'
|
||||
},
|
||||
|
||||
onAdd: function (map) {
|
||||
// create wrapper
|
||||
var container = L.DomUtil.create('div', 'box-wrapper gui-control-wrapper');
|
||||
L.DomEvent.disableClickPropagation(container);
|
||||
|
||||
// create buttons
|
||||
this._zoomIn = this._createButton('gui-zoom-in', container, map.zoomIn, map, true);
|
||||
this._zoomOut = this._createButton('gui-zoom-out', container, map.zoomOut, map, true);
|
||||
|
||||
this._container = container;
|
||||
return container;
|
||||
},
|
||||
|
||||
_createButton: function (id, container, fn, context, isActive) {
|
||||
var inactive = (isActive == false) ? "-inactive" : "";
|
||||
var classNames = "box-content" + " " + "gui-control"+inactive + " " + id+inactive;
|
||||
var link = L.DomUtil.create('a', classNames, container);
|
||||
link.title = id;
|
||||
|
||||
L.DomEvent
|
||||
.on(link, 'click', L.DomEvent.stopPropagation)
|
||||
.on(link, 'click', L.DomEvent.preventDefault)
|
||||
.on(link, 'click', fn, context)
|
||||
.on(link, 'dblclick', L.DomEvent.stopPropagation);
|
||||
|
||||
return link;
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
if( this._container )
|
||||
this._container.style.visibility="hidden";
|
||||
},
|
||||
|
||||
show: function() {
|
||||
if( this._container ) {
|
||||
this._container.style.top = "5px";
|
||||
this._container.style.left = ( OSRM.G.main_handle.boxVisible() == true ? (OSRM.G.main_handle.boxWidth()+10) : "30") + "px";
|
||||
this._container.style.visibility="visible";
|
||||
}
|
||||
},
|
||||
setTooltips: function( zoomIn, zoomOut) {
|
||||
this._zoomIn.title = zoomIn;
|
||||
this._zoomOut.title = zoomOut;
|
||||
}
|
||||
});
|
@ -1,175 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM markers
|
||||
// [base marker class, derived highlight marker and route marker classes]
|
||||
|
||||
|
||||
// base marker class (wraps Leaflet markers)
|
||||
OSRM.Marker = function( label, style, position ) {
|
||||
this.label = label ? label : "marker";
|
||||
this.position = position ? position : new L.LatLng(0,0);
|
||||
|
||||
this.marker = new L.LabelMarker( this.position, style );
|
||||
this.marker.parent = this;
|
||||
|
||||
this.shown = false;
|
||||
this.hint = null;
|
||||
};
|
||||
OSRM.extend( OSRM.Marker,{
|
||||
show: function() {
|
||||
OSRM.G.map.addLayer(this.marker);
|
||||
this.shown = true;
|
||||
},
|
||||
hide: function() {
|
||||
OSRM.G.map.removeLayer(this.marker);
|
||||
this.shown = false;
|
||||
|
||||
// revert highlighted description
|
||||
if( this.label == "highlight" )
|
||||
if( this.description ) {
|
||||
var desc = document.getElementById("description-"+this.description);
|
||||
desc && (desc.className = "description-body-item");
|
||||
this.description = null;
|
||||
}
|
||||
},
|
||||
setPosition: function( position ) {
|
||||
this.position = position;
|
||||
this.marker.setLatLng( position );
|
||||
this.hint = null;
|
||||
},
|
||||
getPosition: function() {
|
||||
return this.position;
|
||||
},
|
||||
getLat: function() {
|
||||
return this.position.lat;
|
||||
},
|
||||
getLng: function() {
|
||||
return this.position.lng;
|
||||
},
|
||||
isShown: function() {
|
||||
return this.shown;
|
||||
},
|
||||
centerView: function(zoom) {
|
||||
if( zoom == undefined )
|
||||
zoom = OSRM.DEFAULTS.ZOOM_LEVEL;
|
||||
OSRM.G.map.setViewUI( this.position, zoom );
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.Marker: \""+this.label+"\", "+this.position+")";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// route marker class (draggable, invokes route drawing routines)
|
||||
OSRM.RouteMarker = function ( label, style, position ) {
|
||||
style.baseicon = style.icon;
|
||||
OSRM.RouteMarker.prototype.base.constructor.apply( this, arguments );
|
||||
this.label = label ? label : "route_marker";
|
||||
|
||||
this.marker.on( 'click', this.onClick );
|
||||
this.marker.on( 'drag', this.onDrag );
|
||||
this.marker.on( 'dragstart', this.onDragStart );
|
||||
this.marker.on( 'dragend', this.onDragEnd );
|
||||
};
|
||||
OSRM.inheritFrom( OSRM.RouteMarker, OSRM.Marker );
|
||||
OSRM.extend( OSRM.RouteMarker, {
|
||||
onClick: function(e) {
|
||||
for( var i=0; i<OSRM.G.markers.route.length; i++) {
|
||||
if( OSRM.G.markers.route[i].marker === this ) {
|
||||
OSRM.G.markers.removeMarker( i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
OSRM.Routing.getRoute();
|
||||
OSRM.G.markers.highlight.hide();
|
||||
OSRM.G.markers.dragger.hide();
|
||||
},
|
||||
onDrag: function(e) {
|
||||
this.parent.setPosition( e.target.getLatLng() );
|
||||
if(OSRM.G.markers.route.length>1)
|
||||
OSRM.Routing.getRoute_Dragging();
|
||||
OSRM.Geocoder.updateLocation( this.parent.label );
|
||||
},
|
||||
onDragStart: function(e) {
|
||||
OSRM.GUI.deactivateTooltip( "DRAGGING" );
|
||||
OSRM.G.dragging = true;
|
||||
this.changeIcon(this.options.dragicon);
|
||||
|
||||
// store id of dragged marker
|
||||
for( var i=0; i<OSRM.G.markers.route.length; i++)
|
||||
if( OSRM.G.markers.route[i].marker === this ) {
|
||||
OSRM.G.dragid = i;
|
||||
break;
|
||||
}
|
||||
|
||||
if( this.parent != OSRM.G.markers.highlight)
|
||||
OSRM.G.markers.highlight.hide();
|
||||
if( this.parent != OSRM.G.markers.dragger)
|
||||
OSRM.G.markers.dragger.hide();
|
||||
if (OSRM.G.route.isShown())
|
||||
OSRM.G.route.showOldRoute();
|
||||
},
|
||||
onDragEnd: function(e) {
|
||||
OSRM.G.dragging = false;
|
||||
this.changeIcon(this.options.baseicon);
|
||||
|
||||
this.parent.setPosition( e.target.getLatLng() );
|
||||
if (OSRM.G.route.isShown()) {
|
||||
OSRM.Routing.getRoute();
|
||||
OSRM.G.route.hideOldRoute();
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
} else {
|
||||
OSRM.Geocoder.updateAddress(this.parent.label);
|
||||
OSRM.GUI.clearResults();
|
||||
}
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.RouteMarker: \""+this.label+"\", "+this.position+")";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//drag marker class (draggable, invokes route drawing routines)
|
||||
OSRM.DragMarker = function ( label, style, position ) {
|
||||
OSRM.DragMarker.prototype.base.constructor.apply( this, arguments );
|
||||
this.label = label ? label : "drag_marker";
|
||||
};
|
||||
OSRM.inheritFrom( OSRM.DragMarker, OSRM.RouteMarker );
|
||||
OSRM.extend( OSRM.DragMarker, {
|
||||
onClick: function(e) {
|
||||
if( this.parent != OSRM.G.markers.dragger)
|
||||
this.parent.hide();
|
||||
},
|
||||
onDragStart: function(e) {
|
||||
var new_via_index = OSRM.Via.findViaIndex( e.target.getLatLng() );
|
||||
OSRM.G.markers.route.splice(new_via_index+1,0, this.parent );
|
||||
|
||||
OSRM.RouteMarker.prototype.onDragStart.call(this,e);
|
||||
},
|
||||
onDragEnd: function(e) {
|
||||
OSRM.G.markers.route[OSRM.G.dragid] = new OSRM.RouteMarker(OSRM.C.VIA_LABEL, {draggable:true,icon:OSRM.G.icons['marker-via'],dragicon:OSRM.G.icons['marker-via-drag']}, e.target.getLatLng() );
|
||||
OSRM.G.markers.route[OSRM.G.dragid].show();
|
||||
|
||||
OSRM.RouteMarker.prototype.onDragEnd.call(this,e);
|
||||
this.parent.hide();
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.DragMarker: \""+this.label+"\", "+this.position+")";
|
||||
}
|
||||
});
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM routes
|
||||
// [drawing of all types of route geometry]
|
||||
|
||||
|
||||
// simple route class (wraps Leaflet Polyline)
|
||||
OSRM.SimpleRoute = function (label, style) {
|
||||
this.label = (label ? label : "route");
|
||||
this.route = new L.Polyline( [], style );
|
||||
this.shown = false;
|
||||
};
|
||||
OSRM.extend( OSRM.SimpleRoute,{
|
||||
show: function() {
|
||||
OSRM.G.map.addLayer(this.route);
|
||||
this.shown = true;
|
||||
},
|
||||
hide: function() {
|
||||
OSRM.G.map.removeLayer(this.route);
|
||||
this.shown = false;
|
||||
},
|
||||
isShown: function() {
|
||||
return this.shown;
|
||||
},
|
||||
getPoints: function() {
|
||||
return this.route._originalPoints;
|
||||
},
|
||||
getPositions: function() {
|
||||
return this.route.getLatLngs();
|
||||
},
|
||||
setPositions: function(positions) {
|
||||
this.route.setLatLngs( positions );
|
||||
},
|
||||
setStyle: function(style) {
|
||||
this.route.setStyle(style);
|
||||
},
|
||||
centerView: function() {
|
||||
var bounds = new L.LatLngBounds( this.getPositions() );
|
||||
OSRM.g.map.fitBoundsUI( bounds );
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.Route("+ this.label + ", " + this.route.getLatLngs().length + " points)";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// multiroute class (wraps Leaflet LayerGroup to hold several disjoint routes)
|
||||
OSRM.MultiRoute = function (label) {
|
||||
this.label = (label ? label : "multiroute");
|
||||
this.route = new L.LayerGroup();
|
||||
|
||||
this.shown = false;
|
||||
};
|
||||
OSRM.extend( OSRM.MultiRoute,{
|
||||
show: function() {
|
||||
OSRM.G.map.addLayer(this.route);
|
||||
this.shown = true;
|
||||
},
|
||||
hide: function() {
|
||||
OSRM.G.map.removeLayer(this.route);
|
||||
this.shown = false;
|
||||
},
|
||||
isShown: function() {
|
||||
return this.shown;
|
||||
},
|
||||
addRoute: function(positions) {
|
||||
var line = new L.Polyline( positions );
|
||||
line.on('click', function(e) { OSRM.G.route.fire('click',e); });
|
||||
this.route.addLayer( line );
|
||||
},
|
||||
clearRoutes: function() {
|
||||
this.route.clearLayers();
|
||||
},
|
||||
setStyle: function(style) {
|
||||
this.route.invoke('setStyle', style);
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.MultiRoute("+ this.label + ")";
|
||||
}
|
||||
});
|
Before Width: | Height: | Size: 15 KiB |
@ -1,44 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM GUI
|
||||
// [base GUI class, all other GUI modules extend this class]
|
||||
|
||||
|
||||
OSRM.GUI = {
|
||||
|
||||
// initialization functions of all GUI parts
|
||||
init_functions: [],
|
||||
|
||||
// init GUI
|
||||
init: function() {
|
||||
for(var i=0, size=OSRM.GUI.init_functions.length; i<size; i++) {
|
||||
OSRM.GUI.init_functions[i]();
|
||||
}
|
||||
},
|
||||
|
||||
//extend GUI class and add init functions to the array
|
||||
extend: function( properties ) {
|
||||
for( property in properties ) {
|
||||
if( property == 'init' )
|
||||
OSRM.GUI.init_functions.push( properties[property] );
|
||||
else
|
||||
OSRM.GUI[property] = properties[property];
|
||||
}
|
||||
}
|
||||
|
||||
};
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM MainGUI
|
||||
// [handles all GUI events that interact with appearance of main window]
|
||||
|
||||
|
||||
// OSRM GUIBoxGroup
|
||||
// [group UI boxes so that handles can be shown/hidden together]
|
||||
|
||||
OSRM.GUIBoxGroup = function() {
|
||||
this._handles = [];
|
||||
};
|
||||
|
||||
OSRM.extend( OSRM.GUIBoxGroup, {
|
||||
add: function( handle ) {
|
||||
this._handles.push( handle );
|
||||
handle.$addToGroup(this);
|
||||
},
|
||||
select: function( handle ) {
|
||||
for(var i=0; i< this._handles.length; i++) {
|
||||
if( this._handles[i] != handle )
|
||||
this._handles[i].$hideBox();
|
||||
else
|
||||
this._handles[i].$showBox();
|
||||
}
|
||||
},
|
||||
|
||||
$hide: function() {
|
||||
for(var i=0; i< this._handles.length; i++) {
|
||||
this._handles[i].$hide();
|
||||
}
|
||||
},
|
||||
$show: function() {
|
||||
for(var i=0; i< this._handles.length; i++) {
|
||||
this._handles[i].$show();
|
||||
}
|
||||
}
|
||||
});
|
@ -1,134 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM GUIBoxHandle
|
||||
// [performs showing and hiding of UI boxes]
|
||||
|
||||
OSRM.GUIBoxHandle = function( box_name, side, css, transitionStartFct, transitionEndFct ) {
|
||||
// do not create handle if box does not contain a toggle button
|
||||
var toggle = document.getElementById( box_name + '-toggle');
|
||||
if( toggle == null ) {
|
||||
console.log("[error] No toggle button for " + box_name);
|
||||
return;
|
||||
}
|
||||
|
||||
// create handle DOM elements
|
||||
var wrapper = document.createElement('div');
|
||||
wrapper.id = box_name + '-handle-wrapper';
|
||||
wrapper.className = 'box-wrapper box-handle-wrapper-'+side;
|
||||
wrapper.style.cssText += css;
|
||||
var content = document.createElement('div');
|
||||
content.id = box_name + '-handle-content';
|
||||
content.className = 'box-content box-handle-content-'+side;
|
||||
var icon = document.createElement('div');
|
||||
icon.id = box_name + '-handle-icon';
|
||||
icon.className = 'iconic-button';
|
||||
icon.title = box_name;
|
||||
|
||||
content.appendChild(icon);
|
||||
wrapper.appendChild(content);
|
||||
document.body.appendChild(wrapper);
|
||||
|
||||
// create attributes
|
||||
this._box = document.getElementById( box_name + '-wrapper' );
|
||||
this._class = this._box.className;
|
||||
this._width = this._box.clientWidth;
|
||||
this._side = side;
|
||||
this._handle = wrapper;
|
||||
this._box_group = null;
|
||||
this._transitionEndFct = transitionEndFct;
|
||||
|
||||
// hide box and show handle by default
|
||||
this._box.style[this._side]=-this._width+"px";
|
||||
this._box_visible = false;
|
||||
this._box.style.visibility="hidden";
|
||||
this._handle.style.visibility="visible";
|
||||
|
||||
// add functionality
|
||||
var full_fct = transitionStartFct ? OSRM.concat(this._toggle, transitionStartFct) : this._toggle;
|
||||
var fct = OSRM.bind( this, full_fct );
|
||||
toggle.onclick = fct;
|
||||
icon.onclick = fct;
|
||||
|
||||
var full_fct = transitionEndFct ? OSRM.concat(this._onTransitionEnd, transitionEndFct) : this._onTransitionEnd;
|
||||
var fct = OSRM.bind( this, full_fct );
|
||||
if( OSRM.Browser.FF3==-1 && OSRM.Browser.IE6_9==-1 ) {
|
||||
var box_wrapper = document.getElementById(box_name + '-wrapper');
|
||||
box_wrapper.addEventListener("transitionend", fct, false);
|
||||
box_wrapper.addEventListener("webkitTransitionEnd", fct, false);
|
||||
box_wrapper.addEventListener("oTransitionEnd", fct, false);
|
||||
box_wrapper.addEventListener("MSTransitionEnd", fct, false);
|
||||
} else {
|
||||
this._legacyTransitionEndFct = fct; // legacy browser support
|
||||
}
|
||||
};
|
||||
|
||||
OSRM.extend( OSRM.GUIBoxHandle, {
|
||||
boxVisible: function() {
|
||||
return this._box_visible;
|
||||
},
|
||||
boxWidth: function() {
|
||||
return this._width;
|
||||
},
|
||||
|
||||
$addToGroup: function(group) {
|
||||
this._box_group = group;
|
||||
},
|
||||
$show: function() {
|
||||
this._handle.style.visibility="visible";
|
||||
},
|
||||
$hide: function() {
|
||||
this._handle.style.visibility="hidden";
|
||||
},
|
||||
$showBox: function() {
|
||||
this._box_visible = true;
|
||||
this._box.style.visibility="visible";
|
||||
this._handle.style.visibility="hidden";
|
||||
this._box.style[this._side]="5px";
|
||||
},
|
||||
$hideBox: function() {
|
||||
this._box_visible = false;
|
||||
this._box.style.visibility="hidden";
|
||||
this._handle.style.visibility="visible";
|
||||
this._box.style[this._side]=-this._width+"px";
|
||||
},
|
||||
|
||||
_toggle: function() {
|
||||
this._box.className += " box-animated";
|
||||
if( this._box_visible == false ) {
|
||||
this._box_group.$hide();
|
||||
this._box.style[this._side]="5px";
|
||||
this._box.style.visibility="visible"; // already show box, so that animation is seen
|
||||
} else {
|
||||
this._box.style[this._side]=-this._width+"px";
|
||||
}
|
||||
// legacy browser support
|
||||
if( OSRM.Browser.FF3!=-1 || OSRM.Browser.IE6_9!=-1 )
|
||||
setTimeout(this._legacyTransitionEndFct, 0);
|
||||
},
|
||||
_onTransitionEnd: function() {
|
||||
this._box.className = this._class;
|
||||
if( this._box_visible == true ) {
|
||||
this._box_group.$show();
|
||||
this._box_visible = false;
|
||||
this._box.style.visibility="hidden";
|
||||
} else {
|
||||
this._box_visible = true;
|
||||
this._box.style.visibility="visible";
|
||||
}
|
||||
}
|
||||
});
|
@ -1,144 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM MainGUI
|
||||
// [handles all GUI events that interact with appearance of main window]
|
||||
|
||||
|
||||
OSRM.GUI.extend( {
|
||||
|
||||
// init GUI
|
||||
init: function() {
|
||||
// init main box
|
||||
var main_group = new OSRM.GUIBoxGroup();
|
||||
OSRM.G.main_handle = new OSRM.GUIBoxHandle("main", "left", "left:-5px;top:5px;", OSRM.GUI.beforeMainTransition, OSRM.GUI.afterMainTransition);
|
||||
main_group.add( OSRM.G.main_handle );
|
||||
main_group.select( OSRM.G.main_handle );
|
||||
|
||||
// init additional boxes
|
||||
var option_group = new OSRM.GUIBoxGroup();
|
||||
var config_handle = new OSRM.GUIBoxHandle("config", "right", "right:-5px;bottom:70px;");
|
||||
var mapping_handle = new OSRM.GUIBoxHandle("mapping", "right", "right:-5px;bottom:25px;");
|
||||
option_group.add( config_handle );
|
||||
option_group.add( mapping_handle );
|
||||
option_group.select( null );
|
||||
|
||||
// init starting source/target
|
||||
document.getElementById('gui-input-source').value = OSRM.DEFAULTS.ONLOAD_SOURCE;
|
||||
document.getElementById('gui-input-target').value = OSRM.DEFAULTS.ONLOAD_TARGET;
|
||||
|
||||
//init units selector
|
||||
OSRM.GUI.initDistanceFormatsSelector();
|
||||
},
|
||||
|
||||
// set language dependent labels
|
||||
setLabels: function() {
|
||||
document.getElementById("open-josm").innerHTML = OSRM.loc("OPEN_JOSM");
|
||||
document.getElementById("open-osmbugs").innerHTML = OSRM.loc("OPEN_OSMBUGS");
|
||||
document.getElementById("gui-reset").innerHTML = OSRM.loc("GUI_RESET");
|
||||
document.getElementById("gui-reverse").innerHTML = OSRM.loc("GUI_REVERSE");
|
||||
document.getElementById("gui-option-highlight-nonames-label").lastChild.nodeValue = OSRM.loc("GUI_HIGHLIGHT_UNNAMED_ROADS");
|
||||
document.getElementById("gui-option-show-previous-routes-label").lastChild.nodeValue = OSRM.loc("GUI_SHOW_PREVIOUS_ROUTES");
|
||||
document.getElementById("gui-search-source").innerHTML = OSRM.loc("GUI_SEARCH");
|
||||
document.getElementById("gui-search-target").innerHTML = OSRM.loc("GUI_SEARCH");
|
||||
document.getElementById("gui-search-source-label").innerHTML = OSRM.loc("GUI_START")+":";
|
||||
document.getElementById("gui-search-target-label").innerHTML = OSRM.loc("GUI_END")+":";
|
||||
document.getElementById("gui-input-source").title = OSRM.loc("GUI_START_TOOLTIP");
|
||||
document.getElementById("gui-input-target").title = OSRM.loc("GUI_END_TOOLTIP");
|
||||
document.getElementById("legal-notice").innerHTML = OSRM.loc("GUI_LEGAL_NOTICE");
|
||||
document.getElementById("gui-mapping-label").innerHTML = OSRM.loc("GUI_MAPPING_TOOLS");
|
||||
document.getElementById("gui-config-label").innerHTML = OSRM.loc("GUI_CONFIGURATION");
|
||||
document.getElementById("gui-language-2-label").innerHTML = OSRM.loc("GUI_LANGUAGE")+":";
|
||||
document.getElementById("gui-units-label").innerHTML = OSRM.loc("GUI_UNITS")+":";
|
||||
document.getElementById('gui-data-timestamp-label').innerHTML = OSRM.loc("GUI_DATA_TIMESTAMP");
|
||||
document.getElementById('gui-data-timestamp').innerHTML = OSRM.G.data_timestamp;
|
||||
document.getElementById('gui-timestamp-label').innerHTML = OSRM.loc("GUI_VERSION");
|
||||
document.getElementById('gui-timestamp').innerHTML = OSRM.DATE+"; v"+OSRM.VERSION;
|
||||
document.getElementById('config-handle-icon').title = OSRM.loc("GUI_CONFIGURATION");
|
||||
document.getElementById('mapping-handle-icon').title = OSRM.loc("GUI_MAPPING_TOOLS");
|
||||
document.getElementById('main-handle-icon').title = OSRM.loc("GUI_MAIN_WINDOW");
|
||||
OSRM.G.map.zoomControl.setTooltips( OSRM.loc("GUI_ZOOM_IN"), OSRM.loc("GUI_ZOOM_OUT") );
|
||||
OSRM.G.map.locationsControl.setTooltips( OSRM.loc("GUI_ZOOM_ON_USER"), OSRM.loc("GUI_ZOOM_ON_ROUTE") );
|
||||
OSRM.GUI.setDistanceFormatsLanguage();
|
||||
OSRM.GUI.setRoutingEnginesLanguage();
|
||||
},
|
||||
|
||||
// clear output area
|
||||
clearResults: function() {
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-header').innerHTML = "";
|
||||
},
|
||||
|
||||
// reposition and hide zoom controls before main box animation
|
||||
beforeMainTransition: function() {
|
||||
OSRM.G.map.zoomControl.hide();
|
||||
},
|
||||
// show zoom controls after main box animation
|
||||
afterMainTransition: function() {
|
||||
OSRM.G.map.zoomControl.show();
|
||||
},
|
||||
|
||||
// distance format routines
|
||||
initDistanceFormatsSelector: function() {
|
||||
var options = OSRM.GUI.getDistanceFormats();
|
||||
OSRM.GUI.selectorInit( "gui-units-toggle", options, OSRM.DEFAULTS.DISTANCE_FORMAT, OSRM.GUI._onDistanceFormatChanged );
|
||||
},
|
||||
setDistanceFormat: function(type) {
|
||||
if( OSRM.G.active_distance_format == type )
|
||||
return;
|
||||
OSRM.G.active_distance_format = type;
|
||||
|
||||
// change scale control
|
||||
if(OSRM.G.map) {
|
||||
OSRM.G.map.scaleControl.removeFrom(OSRM.G.map);
|
||||
OSRM.G.map.scaleControl.options.metric = (type != 1);
|
||||
OSRM.G.map.scaleControl.options.imperial = (type == 1);
|
||||
OSRM.G.map.scaleControl.addTo(OSRM.G.map);
|
||||
}
|
||||
|
||||
// change converter
|
||||
if( type == 1 )
|
||||
OSRM.Utils.toHumanDistance = OSRM.Utils.toHumanDistanceMiles;
|
||||
else
|
||||
OSRM.Utils.toHumanDistance = OSRM.Utils.toHumanDistanceMeters;
|
||||
},
|
||||
_onDistanceFormatChanged: function(type) {
|
||||
OSRM.GUI.setDistanceFormat(type);
|
||||
OSRM.Routing.getRoute({keepAlternative:true});
|
||||
},
|
||||
setDistanceFormatsLanguage: function() {
|
||||
var options = OSRM.GUI.getDistanceFormats();
|
||||
OSRM.GUI.selectorRenameOptions("gui-units-toggle", options );
|
||||
},
|
||||
getDistanceFormats: function() {
|
||||
return [{display:OSRM.loc("GUI_KILOMETERS"),value:0},{display:OSRM.loc("GUI_MILES"),value:1}];
|
||||
},
|
||||
|
||||
// data timestamp routines
|
||||
queryDataTimestamp: function() {
|
||||
OSRM.G.data_timestamp = "n/a";
|
||||
OSRM.JSONP.call( OSRM.G.active_routing_timestamp_url+"?jsonp=%jsonp", OSRM.GUI.setDataTimestamp, OSRM.JSONP.empty, OSRM.DEFAULTS.JSONP_TIMEOUT, 'data_timestamp');
|
||||
},
|
||||
setDataTimestamp: function(response) {
|
||||
if(!response)
|
||||
return;
|
||||
|
||||
OSRM.G.data_timestamp = response.timestamp.slice(0,25).replace(/<\/?[^>]+(>|$)/g ,""); // discard tags
|
||||
document.getElementById('gui-data-timestamp').innerHTML = OSRM.G.data_timestamp;
|
||||
}
|
||||
|
||||
});
|
@ -1,191 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM Notifications
|
||||
// [handles notifications: timed tooltips and exclusive notifications]
|
||||
|
||||
|
||||
OSRM.GUI.extend( {
|
||||
|
||||
// tooltips
|
||||
activeExclusive: undefined,
|
||||
activeTooltip: undefined,
|
||||
tooltips: {},
|
||||
// LOCALIZATION: deactivation triggered in OSRM.Localization.setLanguageWrapper
|
||||
// CLICKING: deactivation triggered in OSRM.Map.click
|
||||
// DRAGGING: deactivation triggered in OSRM.Routing.getRoute_Dragging
|
||||
// MAINTENANCE: deactivation only by config
|
||||
|
||||
|
||||
// initialize notifications and tooltip timers
|
||||
init: function() {
|
||||
// exclusive notifications
|
||||
var config = OSRM.DEFAULTS.NOTIFICATIONS;
|
||||
if( config["MAINTENANCE"] == true ) {
|
||||
var header = OSRM.DEFAULTS.OVERRIDE_MAINTENANCE_NOTIFICATION_HEADER || OSRM.loc("NOTIFICATION_MAINTENANCE_HEADER");
|
||||
var body = OSRM.DEFAULTS.OVERRIDE_MAINTENANCE_NOTIFICATION_BODY || OSRM.loc("NOTIFICATION_MAINTENANCE_BODY");
|
||||
OSRM.GUI.exclusiveNotify( header, body, false);
|
||||
OSRM.GUI.activeExclusive = "MAINTENANCE";
|
||||
return;
|
||||
}
|
||||
|
||||
// tooltip timers
|
||||
var config = OSRM.DEFAULTS.NOTIFICATIONS;
|
||||
var tooltips = OSRM.GUI.tooltips;
|
||||
for( id in config ) {
|
||||
// skip notification?
|
||||
if( !OSRM.Utils.isNumber( config[id] ) )
|
||||
continue;
|
||||
// create structure to hold timer data
|
||||
tooltips[id] = {};
|
||||
// start timer
|
||||
tooltips[id]._timer = setTimeout(
|
||||
function(_id){ return function(){OSRM.GUI._showTooltip(_id);}; }(id),
|
||||
config[id]
|
||||
);
|
||||
|
||||
// mark tooltip as pending
|
||||
tooltips[id]._pending = true;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// deactivate pending tooltip
|
||||
deactivateTooltip: function(id) {
|
||||
var tooltips = OSRM.GUI.tooltips;
|
||||
if(tooltips[id] == undefined)
|
||||
return;
|
||||
|
||||
// mark tooltip as no longer pending
|
||||
tooltips[id]._pending = false;
|
||||
},
|
||||
// show tooltip after timer expired
|
||||
_showTooltip: function(id) {
|
||||
var tooltips = OSRM.GUI.tooltips;
|
||||
// only show tooltip if it exists
|
||||
if(tooltips[id] == undefined)
|
||||
return;
|
||||
|
||||
// only show tooltip if it is still pending
|
||||
if( tooltips[id]._pending == false ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if a notification is currently shown, restart timer
|
||||
var config = OSRM.DEFAULTS.NOTIFICATIONS;
|
||||
if( OSRM.GUI.isTooltipVisible() ) {
|
||||
tooltips[id]._timer = setTimeout(
|
||||
function(_id){ return function(){OSRM.GUI._showTooltip(_id);}; }(id),
|
||||
config[id]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// show notification
|
||||
OSRM.GUI.tooltipNotify( OSRM.loc("NOTIFICATION_"+id+"_HEADER"), OSRM.loc("NOTIFICATION_"+id+"_BODY") );
|
||||
OSRM.GUI.activeTooltip = id;
|
||||
|
||||
// mark tooltip as no longer pending
|
||||
tooltips[id]._pending = false;
|
||||
},
|
||||
|
||||
|
||||
// exclusive notification
|
||||
exclusiveNotify: function( header, text, closable ){
|
||||
document.getElementById('exclusive-notification-blanket').style.display = "block";
|
||||
document.getElementById('exclusive-notification-label').innerHTML = header;
|
||||
document.getElementById('exclusive-notification-box').innerHTML = text;
|
||||
if( closable )
|
||||
document.getElementById('exclusive-notification-toggle').onclick = OSRM.GUI.exclusiveDenotify;
|
||||
else
|
||||
document.getElementById('exclusive-notification-toggle').style.display = "none";
|
||||
OSRM.GUI.exclusiveResize();
|
||||
},
|
||||
exclusiveDenotify: function() {
|
||||
document.getElementById('exclusive-notification-blanket').style.display = "none";
|
||||
OSRM.GUI.activeExclusive = undefined;
|
||||
},
|
||||
exclusiveUpdate: function() {
|
||||
if( OSRM.GUI.activeExclusive == undefined )
|
||||
return;
|
||||
|
||||
// override mainly intended for maintenance mode
|
||||
var header = OSRM.DEFAULTS["OVERRIDE_"+OSRM.GUI.activeExclusive+"_HEADER"] || OSRM.loc("NOTIFICATION_MAINTENANCE_HEADER");
|
||||
var body = OSRM.DEFAULTS["OVERRIDE_"+OSRM.GUI.activeExclusive+"_BODY"] || OSRM.loc("NOTIFICATION_MAINTENANCE_BODY");
|
||||
|
||||
document.getElementById('exclusive-notification-label').innerHTML = header;
|
||||
document.getElementById('exclusive-notification-box').innerHTML = body;
|
||||
OSRM.GUI.exclusiveResize();
|
||||
},
|
||||
exclusiveResize: function() {
|
||||
var height = document.getElementById('exclusive-notification-box').clientHeight;
|
||||
document.getElementById('exclusive-notification-content').style.height = (height + 28) + "px";
|
||||
document.getElementById('exclusive-notification-wrapper').style.height = (height + 48) + "px";
|
||||
},
|
||||
inMaintenance: function() {
|
||||
return OSRM.GUI.activeExclusive == "MAINTENANCE";
|
||||
},
|
||||
|
||||
// tooltip notification
|
||||
tooltipNotify: function( header, text ){
|
||||
document.getElementById('tooltip-notification-wrapper').style.display = "block";
|
||||
document.getElementById('tooltip-notification-label').innerHTML = header;
|
||||
document.getElementById('tooltip-notification-box').innerHTML = text;
|
||||
document.getElementById('tooltip-notification-box').style.display = "block"; // simple trick to always start with a minimized tooltip
|
||||
OSRM.GUI.tooltipResize();
|
||||
|
||||
document.getElementById('tooltip-notification-toggle').onclick = OSRM.GUI.tooltipDenotify;
|
||||
document.getElementById('tooltip-notification-resize').onclick = OSRM.GUI.tooltipResize;
|
||||
},
|
||||
tooltipDenotify: function() {
|
||||
document.getElementById('tooltip-notification-wrapper').style.display = "none";
|
||||
OSRM.GUI.activeTooltip = undefined;
|
||||
},
|
||||
tooltipUpdate: function() {
|
||||
if( OSRM.GUI.activeTooltip == undefined )
|
||||
return;
|
||||
document.getElementById('tooltip-notification-label').innerHTML = OSRM.loc("NOTIFICATION_"+OSRM.GUI.activeTooltip+"_HEADER");
|
||||
document.getElementById('tooltip-notification-box').innerHTML = OSRM.loc("NOTIFICATION_"+OSRM.GUI.activeTooltip+"_BODY");
|
||||
OSRM.GUI.tooltipResize();
|
||||
OSRM.GUI.tooltipResize(); // simple trick to retain opened/closed state of tooltip
|
||||
},
|
||||
tooltipResize: function() {
|
||||
if( document.getElementById('tooltip-notification-box').style.display == "none" ) {
|
||||
document.getElementById('tooltip-notification-box').style.display = "block";
|
||||
var height = document.getElementById('tooltip-notification-box').clientHeight;
|
||||
document.getElementById('tooltip-notification-content').style.height = (height + 28) + "px";
|
||||
document.getElementById('tooltip-notification-wrapper').style.height = (height + 48) + "px";
|
||||
document.getElementById('tooltip-notification-resize').className = "iconic-button up-marker top-right-button";
|
||||
} else {
|
||||
document.getElementById('tooltip-notification-box').style.display = "none";
|
||||
document.getElementById('tooltip-notification-content').style.height = "18px";
|
||||
document.getElementById('tooltip-notification-wrapper').style.height = "38px";
|
||||
document.getElementById('tooltip-notification-resize').className = "iconic-button down-marker top-right-button";
|
||||
}
|
||||
},
|
||||
isTooltipVisible: function() {
|
||||
return document.getElementById('tooltip-notification-wrapper').style.display == "block";
|
||||
},
|
||||
|
||||
|
||||
// update language of any notification
|
||||
updateNotifications: function() {
|
||||
OSRM.GUI.exclusiveUpdate();
|
||||
OSRM.GUI.tooltipUpdate();
|
||||
}
|
||||
|
||||
});
|
@ -1,80 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM RoutingEngineGUI
|
||||
// [handles all GUI aspects that deals with switching the routing engine]
|
||||
|
||||
|
||||
OSRM.GUI.extend( {
|
||||
|
||||
// init
|
||||
init: function() {
|
||||
// gather routing engines
|
||||
var options = OSRM.GUI.getRoutingEngines();
|
||||
|
||||
// generate selectors
|
||||
OSRM.GUI.selectorInit("gui-engine-toggle", options, OSRM.DEFAULTS.ROUTING_ENGINE, OSRM.GUI._onRoutingEngineChanged);
|
||||
},
|
||||
|
||||
// change active routing engine
|
||||
setRoutingEngine: function(engine) {
|
||||
if( engine == OSRM.G.active_routing_engine )
|
||||
return;
|
||||
|
||||
OSRM.GUI.selectorChange( 'gui-engine-toggle', engine );
|
||||
|
||||
OSRM.G.active_routing_engine = engine;
|
||||
OSRM.G.active_routing_metric = OSRM.DEFAULTS.ROUTING_ENGINES[ OSRM.G.active_routing_engine ].metric;;
|
||||
OSRM.G.active_routing_server_url = OSRM.DEFAULTS.ROUTING_ENGINES[ OSRM.G.active_routing_engine ].url;
|
||||
OSRM.G.active_routing_timestamp_url = OSRM.DEFAULTS.ROUTING_ENGINES[ OSRM.G.active_routing_engine ].timestamp;
|
||||
|
||||
// requery data timestamp
|
||||
OSRM.GUI.queryDataTimestamp();
|
||||
OSRM.JSONP.call( OSRM.DEFAULTS.ROUTING_ENGINES[ OSRM.G.active_routing_engine ].timestamp+"?jsonp=%jsonp", OSRM.GUI.setDataTimestamp, OSRM.GUI.setDataTimestampTimeout, OSRM.DEFAULTS.JSONP_TIMEOUT, 'data_timestamp');
|
||||
},
|
||||
_onRoutingEngineChanged: function(engine) {
|
||||
if( engine == OSRM.G.active_routing_engine )
|
||||
return;
|
||||
|
||||
OSRM.GUI.setRoutingEngine( engine );
|
||||
|
||||
// requery route
|
||||
if( OSRM.G.markers.route.length > 1 )
|
||||
OSRM.Routing.getRoute();
|
||||
},
|
||||
|
||||
// change language of routing engine entries
|
||||
setRoutingEnginesLanguage: function() {
|
||||
// gather routing engines
|
||||
var options = OSRM.GUI.getRoutingEngines();
|
||||
|
||||
// change dropdown menu names
|
||||
OSRM.GUI.selectorRenameOptions( "gui-engine-toggle", options );
|
||||
},
|
||||
|
||||
// gather routing engines
|
||||
getRoutingEngines: function() {
|
||||
var engines = OSRM.DEFAULTS.ROUTING_ENGINES;
|
||||
var options = [];
|
||||
for(var i=0, size=engines.length; i<size; i++) {
|
||||
options.push( {display:OSRM.loc(engines[i].label), value:i} );
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
});
|
@ -1,181 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM RoutingGUI
|
||||
// [handles all GUI events that interact with routing in main window]
|
||||
|
||||
|
||||
OSRM.GUI.extend( {
|
||||
|
||||
// init
|
||||
init: function() {
|
||||
// init variables
|
||||
OSRM.GUI.setDistanceFormat(OSRM.DEFAULTS.DISTANCE_FORMAT);
|
||||
|
||||
// init events
|
||||
document.getElementById("gui-input-source").onchange = function() {OSRM.GUI.inputChanged(OSRM.C.SOURCE_LABEL);};
|
||||
document.getElementById("gui-delete-source").onclick = function() {OSRM.GUI.deleteMarker(OSRM.C.SOURCE_LABEL);};
|
||||
document.getElementById("gui-search-source").onclick = function() {OSRM.GUI.showMarker(OSRM.C.SOURCE_LABEL);};
|
||||
|
||||
document.getElementById("gui-input-target").onchange = function() {OSRM.GUI.inputChanged(OSRM.C.TARGET_LABEL);};
|
||||
document.getElementById("gui-delete-target").onclick = function() {OSRM.GUI.deleteMarker(OSRM.C.TARGET_LABEL);};
|
||||
document.getElementById("gui-search-target").onclick = function() {OSRM.GUI.showMarker(OSRM.C.TARGET_LABEL);};
|
||||
|
||||
document.getElementById("gui-reset").onclick = OSRM.GUI.resetRouting;
|
||||
document.getElementById("gui-reverse").onclick = OSRM.GUI.reverseRouting;
|
||||
document.getElementById("open-josm").onclick = OSRM.GUI.openJOSM;
|
||||
document.getElementById("open-osmbugs").onclick = OSRM.GUI.openOSMBugs;
|
||||
document.getElementById("option-highlight-nonames").onclick = OSRM.GUI.hightlightNonames;
|
||||
document.getElementById("option-show-previous-routes").onclick = OSRM.GUI.showPreviousRoutes;
|
||||
},
|
||||
|
||||
// toggle GUI features that need a route to work
|
||||
activateRouteFeatures: function() {
|
||||
OSRM.Printing.activate();
|
||||
OSRM.G.map.locationsControl.activateRoute();
|
||||
OSRM.G.active_shortlink = null; // delete shortlink when new route is shown (RoutingDescription calls this method!)
|
||||
},
|
||||
deactivateRouteFeatures: function() {
|
||||
OSRM.Printing.deactivate();
|
||||
OSRM.G.map.locationsControl.deactivateRoute();
|
||||
OSRM.G.active_shortlink = null; // delete shortlink when the route is hidden
|
||||
},
|
||||
|
||||
// click: button "reset"
|
||||
resetRouting: function() {
|
||||
document.getElementById('gui-input-source').value = "";
|
||||
document.getElementById('gui-input-target').value = "";
|
||||
|
||||
OSRM.G.route.reset();
|
||||
OSRM.G.markers.reset();
|
||||
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-header').innerHTML = "";
|
||||
|
||||
OSRM.JSONP.reset();
|
||||
},
|
||||
|
||||
// click: button "reverse"
|
||||
reverseRouting: function() {
|
||||
// invert input boxes
|
||||
var tmp = document.getElementById("gui-input-source").value;
|
||||
document.getElementById("gui-input-source").value = document.getElementById("gui-input-target").value;
|
||||
document.getElementById("gui-input-target").value = tmp;
|
||||
|
||||
// recompute route if needed
|
||||
if( OSRM.G.route.isShown() ) {
|
||||
OSRM.G.markers.route.reverse();
|
||||
OSRM.Routing.getRoute_Reversed(); // temporary route reversal for query, actual reversal done after receiving response
|
||||
OSRM.G.markers.route.reverse();
|
||||
OSRM.G.markers.highlight.hide();
|
||||
OSRM.RoutingDescription.showSimple( OSRM.G.response );
|
||||
|
||||
// simply reverse markers
|
||||
} else {
|
||||
OSRM.G.markers.reverseMarkers();
|
||||
}
|
||||
},
|
||||
|
||||
// click: button "show"
|
||||
showMarker: function(marker_id) {
|
||||
if( OSRM.JSONP.fences["geocoder_source"] || OSRM.JSONP.fences["geocoder_target"] ) // needed when focus was on input box and user clicked on button
|
||||
return;
|
||||
|
||||
if( marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource() )
|
||||
OSRM.G.markers.route[0].centerView();
|
||||
else if( marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() )
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].centerView();
|
||||
},
|
||||
|
||||
// changed: any inputbox (is called when enter is pressed [after] or focus is lost [before])
|
||||
inputChanged: function(marker_id) {
|
||||
if( marker_id == OSRM.C.SOURCE_LABEL)
|
||||
OSRM.Geocoder.call(OSRM.C.SOURCE_LABEL, document.getElementById('gui-input-source').value);
|
||||
else if( marker_id == OSRM.C.TARGET_LABEL)
|
||||
OSRM.Geocoder.call(OSRM.C.TARGET_LABEL, document.getElementById('gui-input-target').value);
|
||||
},
|
||||
|
||||
// click: button "open JOSM"
|
||||
openJOSM: function() {
|
||||
var center = OSRM.G.map.getCenterUI();
|
||||
var bounds = OSRM.G.map.getBoundsUI();
|
||||
|
||||
var xdelta = Math.min(0.02, Math.abs(bounds.getSouthWest().lng - center.lng) );
|
||||
var ydelta = Math.min(0.01, Math.abs(bounds.getSouthWest().lat - center.lat) );
|
||||
|
||||
var p = [ 'left=' + (center.lng - xdelta).toFixed(6), 'bottom=' + (center.lat - ydelta).toFixed(6), 'right=' + (center.lng + xdelta).toFixed(6), 'top=' + (center.lat + ydelta).toFixed(6)];
|
||||
var url = 'http://127.0.0.1:8111/load_and_zoom?' + p.join('&');
|
||||
|
||||
var frame = document.getElementById('josm-frame');
|
||||
if(!frame) {
|
||||
frame = L.DomUtil.create('iframe', null, document.body);
|
||||
frame.style.display = "none";
|
||||
frame.id = 'josm-frame';
|
||||
}
|
||||
frame.src = url;
|
||||
},
|
||||
|
||||
//click: button "open OSM Bugs"
|
||||
openOSMBugs: function() {
|
||||
var position = OSRM.G.map.getCenterUI();
|
||||
window.open( "http://osmbugs.org/?lat="+position.lat.toFixed(6)+"&lon="+position.lng.toFixed(6)+"&zoom="+OSRM.G.map.getZoom() );
|
||||
},
|
||||
|
||||
//click: button "delete marker"
|
||||
deleteMarker: function(marker_id) {
|
||||
var id = null;
|
||||
if(marker_id == 'source' && OSRM.G.markers.hasSource() )
|
||||
id = 0;
|
||||
else if(marker_id == 'target' && OSRM.G.markers.hasTarget() )
|
||||
id = OSRM.G.markers.route.length-1;
|
||||
if( id == null)
|
||||
return;
|
||||
|
||||
OSRM.G.markers.removeMarker( id );
|
||||
OSRM.Routing.getRoute();
|
||||
OSRM.G.markers.highlight.hide();
|
||||
},
|
||||
|
||||
//click: checkbox "show previous routes"
|
||||
showPreviousRoutes: function(value) {
|
||||
if( document.getElementById('option-show-previous-routes').checked == false)
|
||||
OSRM.G.route.deactivateHistoryRoutes();
|
||||
else
|
||||
OSRM.G.route.activateHistoryRoutes();
|
||||
},
|
||||
|
||||
//click: button "zoom on route"
|
||||
zoomOnRoute: function() {
|
||||
if( OSRM.G.route.isShown() == false )
|
||||
return;
|
||||
|
||||
var bounds = new L.LatLngBounds( OSRM.G.route._current_route.getPositions() );
|
||||
OSRM.G.map.fitBoundsUI(bounds);
|
||||
},
|
||||
|
||||
//click: button "zoom on user"
|
||||
zoomOnUser: function() {
|
||||
if (navigator.geolocation)
|
||||
navigator.geolocation.getCurrentPosition(OSRM.Map.geolocationResponse);
|
||||
},
|
||||
|
||||
//click: toggle highlighting unnamed streets
|
||||
hightlightNonames: function() {
|
||||
OSRM.Routing.getRoute_Redraw({keepAlternative:true});
|
||||
}
|
||||
|
||||
});
|
@ -1,119 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM selector
|
||||
// [create special selector elements]
|
||||
|
||||
|
||||
OSRM.GUI.extend( {
|
||||
|
||||
// initialize selector with all options and our look&feel
|
||||
selectorInit: function(id, options, selected, onchange_fct) {
|
||||
// create dropdown menu
|
||||
var select = document.getElementById(id);
|
||||
select.className += " styled-select-helper base-font";
|
||||
select.onchange = function() { OSRM.GUI._selectorOnChange(this); onchange_fct(this.value); };
|
||||
|
||||
// fill dropdown menu
|
||||
for(var i=0, size=options.length; i<size; i++) {
|
||||
var option=document.createElement("option");
|
||||
option.innerHTML = options[i].display;
|
||||
option.value = options[i].value;
|
||||
select.appendChild(option);
|
||||
}
|
||||
select.value = options[selected].value;
|
||||
|
||||
// create visible dropdown menu
|
||||
var textnode = document.createTextNode( options[selected].display );
|
||||
var myspan = document.createElement("span");
|
||||
myspan.className = "styled-select base-font";
|
||||
myspan.id = "styled-select-" + select.id;
|
||||
myspan.appendChild(textnode);
|
||||
select.parentNode.insertBefore(myspan, select);
|
||||
myspan.style.width = (select.offsetWidth-2)+"px";
|
||||
myspan.style.height = (select.offsetHeight)+"px"; // clientHeight gives the height of the opened dropbox!
|
||||
},
|
||||
|
||||
// required behaviour of selector on change to switch shown name
|
||||
_selectorOnChange: function(select) {
|
||||
var option = select.getElementsByTagName("option");
|
||||
for(var i = 0; i < option.length; i++)
|
||||
if(option[i].selected == true) {
|
||||
document.getElementById("styled-select-" + select.id).childNodes[0].nodeValue = option[i].childNodes[0].nodeValue;
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
// change selector value
|
||||
selectorChange: function(id, value) {
|
||||
var select = document.getElementById(id);
|
||||
select.value = value;
|
||||
OSRM.GUI._selectorOnChange(select);
|
||||
},
|
||||
|
||||
// replace selector options with new names
|
||||
selectorRenameOptions: function(id, options) {
|
||||
var select = document.getElementById(id);
|
||||
var styledSelect = document.getElementById("styled-select-"+id);
|
||||
|
||||
// create new dropdown menu
|
||||
var new_select = document.createElement("select");
|
||||
new_select.id = id;
|
||||
new_select.className = select.className;
|
||||
new_select.onchange = select.onchange;
|
||||
|
||||
// fill new dropdown menu
|
||||
var selected_display = "";
|
||||
for(var i=0, size=options.length; i<size; i++) {
|
||||
var option=document.createElement("option");
|
||||
option.innerHTML = options[i].display;
|
||||
option.value = options[i].value;
|
||||
new_select.appendChild(option);
|
||||
|
||||
if( options[i].value == select.value )
|
||||
selected_display = options[i].display;
|
||||
}
|
||||
new_select.value = select.value;
|
||||
|
||||
// switch old with new dropdown menu
|
||||
select.parentNode.insertBefore(new_select, select);
|
||||
select.parentNode.removeChild(select);
|
||||
|
||||
// change styled dropdown menu size & language
|
||||
styledSelect.childNodes[0].nodeValue = selected_display;
|
||||
styledSelect.style.width = (new_select.offsetWidth-2)+"px";
|
||||
styledSelect.style.height = (new_select.offsetHeight)+"px";
|
||||
|
||||
// // old variant without creating a new dropdown menu (works in current browsers, but not in older FF or IE)
|
||||
// var select = document.getElementById(id);
|
||||
// var select_options = select.getElementsByTagName("option");
|
||||
// var styledSelect = document.getElementById("styled-select-"+id);
|
||||
//
|
||||
// // fill dropdown menu with new option names
|
||||
// for(var i = 0; i < select_options.length; i++) {
|
||||
// select_options[i].childNodes[0].nodeValue = options[i].display;
|
||||
//
|
||||
// if(select_options[i].selected == true)
|
||||
// styledSelect.childNodes[0].nodeValue = options[i].display;
|
||||
// }
|
||||
//
|
||||
// // resize visible dropdown menu as needed
|
||||
// styledSelect.style.width = (select.offsetWidth-2)+"px";
|
||||
// styledSelect.style.height = (select.offsetHeight)+"px"; // clientHeight gives the height of the opened dropbox!
|
||||
}
|
||||
|
||||
});
|
Before Width: | Height: | Size: 402 B |
Before Width: | Height: | Size: 484 B |
Before Width: | Height: | Size: 483 B |
Before Width: | Height: | Size: 397 B |
Before Width: | Height: | Size: 493 B |
Before Width: | Height: | Size: 482 B |
Before Width: | Height: | Size: 707 B |
Before Width: | Height: | Size: 221 B |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 534 B |
Before Width: | Height: | Size: 690 B |
Before Width: | Height: | Size: 737 B |
Before Width: | Height: | Size: 713 B |
Before Width: | Height: | Size: 700 B |
Before Width: | Height: | Size: 684 B |
Before Width: | Height: | Size: 824 B |
Before Width: | Height: | Size: 817 B |
Before Width: | Height: | Size: 913 B |
Before Width: | Height: | Size: 329 B |
Before Width: | Height: | Size: 378 B |
Before Width: | Height: | Size: 347 B |
Before Width: | Height: | Size: 462 B |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 347 B |
Before Width: | Height: | Size: 349 B |
Before Width: | Height: | Size: 350 B |
Before Width: | Height: | Size: 322 B |
Before Width: | Height: | Size: 477 B |
Before Width: | Height: | Size: 480 B |
Before Width: | Height: | Size: 488 B |