Skip to content

Commit 9e91461

Browse files
author
Emmanuel Nhan
committed
initial commit
0 parents  commit 9e91461

File tree

17 files changed

+1714
-0
lines changed

17 files changed

+1714
-0
lines changed

.gitignore

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Created by https://www.gitignore.io/api/node,intellij+all
2+
3+
### Intellij+all ###
4+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
5+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
6+
7+
# User-specific stuff
8+
.idea/**/workspace.xml
9+
.idea/**/tasks.xml
10+
.idea/**/usage.statistics.xml
11+
.idea/**/dictionaries
12+
.idea/**/shelf
13+
14+
# Sensitive or high-churn files
15+
.idea/**/dataSources/
16+
.idea/**/dataSources.ids
17+
.idea/**/dataSources.local.xml
18+
.idea/**/sqlDataSources.xml
19+
.idea/**/dynamic.xml
20+
.idea/**/uiDesigner.xml
21+
.idea/**/dbnavigator.xml
22+
23+
# Gradle
24+
.idea/**/gradle.xml
25+
.idea/**/libraries
26+
27+
# CMake
28+
cmake-build-*/
29+
30+
# Mongo Explorer plugin
31+
.idea/**/mongoSettings.xml
32+
33+
# File-based project format
34+
*.iws
35+
36+
# IntelliJ
37+
out/
38+
39+
# mpeltonen/sbt-idea plugin
40+
.idea_modules/
41+
42+
# JIRA plugin
43+
atlassian-ide-plugin.xml
44+
45+
# Cursive Clojure plugin
46+
.idea/replstate.xml
47+
48+
# Crashlytics plugin (for Android Studio and IntelliJ)
49+
com_crashlytics_export_strings.xml
50+
crashlytics.properties
51+
crashlytics-build.properties
52+
fabric.properties
53+
54+
# Editor-based Rest Client
55+
.idea/httpRequests
56+
57+
### Intellij+all Patch ###
58+
# Ignores the whole .idea folder and all .iml files
59+
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
60+
61+
.idea/
62+
63+
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
64+
65+
*.iml
66+
modules.xml
67+
.idea/misc.xml
68+
*.ipr
69+
70+
### Node ###
71+
# Logs
72+
logs
73+
*.log
74+
npm-debug.log*
75+
yarn-debug.log*
76+
yarn-error.log*
77+
78+
# Runtime data
79+
pids
80+
*.pid
81+
*.seed
82+
*.pid.lock
83+
84+
# Directory for instrumented libs generated by jscoverage/JSCover
85+
lib-cov
86+
87+
# Coverage directory used by tools like istanbul
88+
coverage
89+
90+
# nyc test coverage
91+
.nyc_output
92+
93+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
94+
.grunt
95+
96+
# Bower dependency directory (https://bower.io/)
97+
bower_components
98+
99+
# node-waf configuration
100+
.lock-wscript
101+
102+
# Compiled binary addons (https://nodejs.org/api/addons.html)
103+
build/Release
104+
105+
# Dependency directories
106+
node_modules/
107+
jspm_packages/
108+
109+
# TypeScript v1 declaration files
110+
typings/
111+
112+
# Optional npm cache directory
113+
.npm
114+
115+
# Optional eslint cache
116+
.eslintcache
117+
118+
# Optional REPL history
119+
.node_repl_history
120+
121+
# Output of 'npm pack'
122+
*.tgz
123+
124+
# Yarn Integrity file
125+
.yarn-integrity
126+
127+
# dotenv environment variables file
128+
.env
129+
130+
# parcel-bundler cache (https://parceljs.org/)
131+
.cache
132+
133+
# next.js build output
134+
.next
135+
136+
# nuxt.js build output
137+
.nuxt
138+
139+
# vuepress build output
140+
.vuepress/dist
141+
142+
# Serverless directories
143+
.serverless
144+
145+
146+
# End of https://www.gitignore.io/api/node,intellij+all
147+
148+
config.js

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright © 2018 Sigfox
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Sigfox-maps
2+
3+
This project is an example of how to use the Sigfox backend API to display your own maps.
4+
5+
## Technologies
6+
7+
This application is a simple [nodeJs](http://nodejs.org) server application which uses [Express](http://expressjs.com)
8+
for routing and [Pug](https://pugjs.org) for templating.
9+
The simple frontend uses [Leaflet](https://leafletjs.com/) to display maps.
10+
11+
## Prerequisites
12+
13+
To run/use this sample project, you will need git and nodejs (at least v8.10.0) installed.
14+
15+
If you really do not want to install git, just hit the download button, to retrieve a tarball of the whole repository.
16+
17+
## Configuration
18+
19+
To configure properly the application, you need to rename the config.js.sample to config.js and edit this file to provide your own setup.
20+
21+
```javascript
22+
const config = {
23+
sigfoxApiUser: "yourSigfoxApiUser",
24+
sigfoxApiPassword: "yourSigfoxApiPassword",
25+
sigfoxApiSite: "api.sigfox.com",
26+
publicMapPath: "/v2/tiles/public-coverage",
27+
https: true,
28+
backgroundMap: "https://api.mapbox.com/v4/mapbox.light/{z}/{x}/{y}.png?access_token=[yourToken]"
29+
}
30+
```
31+
32+
In production situation, you should only set your own credentials to access the Sigfox API and set your background map URL according to your map provider.
33+
The example above showcases a [Mapbox](https://www.mapbox.com/) map with a light style (you'll have to set your own token). To sum up, the `backgroundMap` property expects a TMS URL.
34+
You can use other background map providers:
35+
- **Jawg:** `http://tile.jawg.io/jawg-light/{z}/{x}/{y}.png?access-token=[YOUR_ACCESS_TOKEN]`
36+
- **HERE:** `https://1.base.maps.api.here.com/maptile/2.1/maptile/newest/normal.day/{z}/{x}/{y}/256/png8?app_id=[app_id]&app_code=[app_code]`
37+
- **Google:** Google maps use custom format and should be integrated using a [leaflet plugin](https://gitlab.com/IvanSanchez/Leaflet.GridLayer.GoogleMutant)
38+
- **Bing:** Bing maps use custom format and should be integrated using a [leaflet plugin](https://github.com/digidem/leaflet-bing-layer)
39+
40+
In test situation, you might want to mock the Sigfox Backend. In order to do this, you can edit the other properties :
41+
42+
- `sigfoxApiSite` to specify the base URL of your mock (including the http(s) prefix)
43+
- `publicMapPath` to specify the endpoint. To provide a compatible endpoint, check the documentation of the Sigfox API v2
44+
- `https` to specify if your mock is deployed on https context (set it to true), or http (set it to false)
45+
46+
## How to run
47+
48+
You just have to do a simple : `npm install && npm start`
49+
On Windows the `&&` operator might not work, so, launch in sequence
50+
```
51+
npm install
52+
npm start
53+
```
54+
55+
Open the url <http://localhost:3000/> on your browser.

app.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const createError = require('http-errors');
2+
const express = require('express');
3+
const path = require('path');
4+
const cookieParser = require('cookie-parser');
5+
const logger = require('morgan');
6+
7+
const publicMapRouter = require('./routes/publicmap');
8+
9+
const app = express();
10+
11+
// view engine setup
12+
app.set('views', path.join(__dirname, 'views'));
13+
app.set('view engine', 'pug');
14+
15+
app.use(logger('dev'));
16+
app.use(express.json());
17+
app.use(express.urlencoded({ extended: false }));
18+
app.use(cookieParser());
19+
app.use(express.static(path.join(__dirname, 'public')));
20+
21+
app.use('/publicmap', publicMapRouter);
22+
23+
// redirect root urls to the only usable page
24+
app.get('/', function(req, res) {
25+
res.redirect('/publicmap');
26+
});
27+
app.get('', function(req, res) {
28+
res.redirect('/publicmap');
29+
});
30+
31+
// catch 404 and forward to error handler
32+
app.use(function(req, res, next) {
33+
next(createError(404));
34+
});
35+
36+
// error handler
37+
app.use(function(err, req, res, next) {
38+
// set locals, only providing error in development
39+
res.locals.message = err.message;
40+
res.locals.error = req.app.get('env') === 'development' ? err : {};
41+
42+
// render the error page
43+
res.status(err.status || 500);
44+
res.render('error');
45+
});
46+
47+
module.exports = app;

assets/WorldCountries.geojson

Lines changed: 262 additions & 0 deletions
Large diffs are not rendered by default.

bin/www

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../app');
8+
var debug = require('debug')('sigfox-maps:server');
9+
var http = require('http');
10+
11+
/**
12+
* Get port from environment and store in Express.
13+
*/
14+
15+
var port = normalizePort(process.env.PORT || '3000');
16+
app.set('port', port);
17+
18+
/**
19+
* Create HTTP server.
20+
*/
21+
22+
var server = http.createServer(app);
23+
24+
/**
25+
* Listen on provided port, on all network interfaces.
26+
*/
27+
28+
server.listen(port);
29+
server.on('error', onError);
30+
server.on('listening', onListening);
31+
32+
/**
33+
* Normalize a port into a number, string, or false.
34+
*/
35+
36+
function normalizePort(val) {
37+
var port = parseInt(val, 10);
38+
39+
if (isNaN(port)) {
40+
// named pipe
41+
return val;
42+
}
43+
44+
if (port >= 0) {
45+
// port number
46+
return port;
47+
}
48+
49+
return false;
50+
}
51+
52+
/**
53+
* Event listener for HTTP server "error" event.
54+
*/
55+
56+
function onError(error) {
57+
if (error.syscall !== 'listen') {
58+
throw error;
59+
}
60+
61+
var bind = typeof port === 'string'
62+
? 'Pipe ' + port
63+
: 'Port ' + port;
64+
65+
// handle specific listen errors with friendly messages
66+
switch (error.code) {
67+
case 'EACCES':
68+
console.error(bind + ' requires elevated privileges');
69+
process.exit(1);
70+
break;
71+
case 'EADDRINUSE':
72+
console.error(bind + ' is already in use');
73+
process.exit(1);
74+
break;
75+
default:
76+
throw error;
77+
}
78+
}
79+
80+
/**
81+
* Event listener for HTTP server "listening" event.
82+
*/
83+
84+
function onListening() {
85+
var addr = server.address();
86+
var bind = typeof addr === 'string'
87+
? 'pipe ' + addr
88+
: 'port ' + addr.port;
89+
debug('Listening on ' + bind);
90+
}

config.js.sample

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
const config = {
3+
sigfoxApiUser: "yourSigfoxApiUser",
4+
sigfoxApiPassword: "yourSigfoxApiPassword",
5+
sigfoxApiSite: "api.sigfox.com",
6+
publicMapPath: "/v2/tiles/public-coverage",
7+
https: true,
8+
backgroundMap: "https://api.mapbox.com/v4/mapbox.light/{z}/{x}/{y}.png?access_token={yourToken}"
9+
};
10+
11+
module.exports = config;

0 commit comments

Comments
 (0)