Skip to content

Commit

Permalink
Merge pull request sakitam-fdd#6 from sakitam-fdd/wind-server
Browse files Browse the repository at this point in the history
fix projection and add service feature
  • Loading branch information
sakitam-fdd authored Feb 2, 2018
2 parents 89757f8 + 0fa423b commit ef9548f
Show file tree
Hide file tree
Showing 20 changed files with 932 additions and 99 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.0.3 (2018.02.02)

* 抓取服务新增 3 个接口,包括查询文件树和支持通过文件名查询数据。
* 暂时新增了 ``EPSG:4326`` 投影的兼容处理。#5
* 解决了与 [ol3Echarts](https://github.com/sakitam-fdd/ol3Echarts) 事件处理冲突问题。

## 0.0.2 (2018.01.20)

* 更新部分依赖。
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ import WindLayer from 'wind-layer'
目前可通过 [unpkg.com](https://unpkg.com/wind-layer/dist/windLayer.js) / [jsdelivr](https://cdn.jsdelivr.net/npm/[email protected]/dist/windLayer.js) 获取最新版本的资源。

```bash
// jsdelivr (jsdelivr由于缓存原因最好锁定版本号,否则可能会出现意料之外的问题)
https://cdn.jsdelivr.net/npm/[email protected]/dist/windLayer.js
https://cdn.jsdelivr.net/npm/[email protected]/dist/windLayer.min.js
// npm
https://unpkg.com/wind-layer/dist/windLayer.js
https://unpkg.com/wind-layer/dist/windLayer.min.js
// jsdelivr (jsdelivr由于缓存原因最好锁定版本号,否则可能会出现意料之外的问题)
https://cdn.jsdelivr.net/npm/[email protected]/dist/windLayer.js
https://cdn.jsdelivr.net/npm/[email protected]/dist/windLayer.min.js
```

#### [![示例](https://sakitam-fdd.github.io/wind-layer/windy.jpg)](https://jsfiddle.net/sakitamfdd/hgvdu76j/?utm_source=website&utm_medium=embed&utm_campaign=hgvdu76j)

#### [文档](//sakitam-fdd.github.io/wind-layer/)

#### [点击查看示例](//sakitam-fdd.github.io/wind-layer/examples/index.html)

## 如何获取数据

天气数据由[全球预报系统](http://en.wikipedia.org/wiki/Global_Forecast_System)(GFS)生成,
Expand All @@ -72,14 +74,17 @@ npm run dev:server // 调试环境启动服务
npm run prd:server // 部署环境启动服务
```

### 目前共暴露4个接口
### 目前共暴露7个接口

| url | params | desc |
| :--- | :--- | :---------- |
| `autofetch` | `null` | 无需参数,开启自动抓取程序,默认30分钟抓取一次数据源 |
| `stopautofetch` | `null` | 停止自动抓取程序 |
| `getdata` | `Object` (目前只支持`time` 参数,时间戳) | 获取json数据,存在转换过的直接返回,若只存在元数据则转换后返回,若元数据也不存在则抓取转换后再响应 |
| `gribdata` | `Object` (目前只支持`time` 参数,时间戳) | 获取grib数据(强制抓取数据) |
| `gribdata` | `Object` (目前只支持`time` 参数,时间戳) | 获取grib2数据(强制抓取数据) |
| `getSourceTree` | `null` | 无需参数,获取抓取的数据源 `grib2` 源数据。返回一个list,包含文件名和服务器地址。 |
| `getParseTree` | `null` | 无需参数,获取转换后的 `json` 数据。返回一个list,包含文件名和服务器地址。 |
| `getDataByFileName` | `{ filename }` | 通过文件名请求 `json` 数据,文件名可为源数据文件和json文件名 |

## Resources

Expand Down
3 changes: 2 additions & 1 deletion build/rollup-base-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const friendlyFormatter = require("eslint-friendly-formatter");
const _package = require('../package.json')
const eslintConfig = require('../.eslintrc')
const year = new Date().getFullYear();
const banner = `/*!\n * ${_package.name} v${_package.version}\n * LICENSE : ${_package.license}\n * (c) 2017-${year} ${_package.homepage}\n */`;
const banner = `/*!\n * author: ${_package.author}\n * ${_package.name} v${_package.version}\n * LICENSE: ${_package.license}\n * (c) 2017-${year} ${_package.homepage}\n */`;


const resolve = _path => path.resolve(__dirname, '../', _path)

Expand Down
10 changes: 8 additions & 2 deletions docs/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@
</style>
</head>
<body>
<div id="map"></div>
<div id="map">
<div class="menu">
<button class="base-button" onclick="getData()">获取数据</button>
<button class="base-button" onclick="setData()">设置数据</button>
<button class="base-button" onclick="clearWind()">移除图层</button>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/openlayers/dist/ol.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].2/dist/windLayer.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].3/dist/windLayer.js"></script>
<script>
var Maps = new ol.Map({
target: 'map',
Expand Down
20 changes: 9 additions & 11 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
### npm安装
#### npm安装

```bash
npm install wind-layer --save
import WindLayer from 'wind-layer'

// 指定版本安装
npm install [email protected].1 --save
npm install [email protected].2 --save
import WindLayer from 'wind-layer'

```
### cdn

目前可通过 [unpkg.com](https://unpkg.com/wind-layer/dist/windLayer.js) 获取最新版本的资源。
目前可通过 [unpkg.com](https://unpkg.com/wind-layer/dist/windLayer.js) / [jsdelivr](https://cdn.jsdelivr.net/npm/[email protected]/dist/windLayer.js) 获取最新版本的资源。

```bash
// jsdelivr (jsdelivr由于缓存原因最好锁定版本号,否则可能会出现意料之外的问题)
https://cdn.jsdelivr.net/npm/[email protected]/dist/windLayer.js
https://cdn.jsdelivr.net/npm/[email protected]/dist/windLayer.min.js
// npm
https://unpkg.com/wind-layer/dist/windLayer.js
https://unpkg.com/wind-layer/dist/windLayer.min.js

// 指定版本安装
https://unpkg.com/[email protected]/dist/windLayer.js
https://unpkg.com/[email protected]/dist/windLayer.min.js
```


Expand All @@ -33,7 +31,7 @@ var wind = new WindLayer(res.data, {
minResolution: undefined,
maxResolution: undefined,
zIndex: 0,
projection: 'EPSG:3857',
projection: 'EPSG:3857', // EPSG:4326
ratio: 1
})
wind.appendTo(Maps)
Expand All @@ -47,7 +45,7 @@ wind.appendTo(Maps)
| minResolution | 最小分辨率 | `Number` | 默认为 `undefined` |
| maxResolution | 最大分辨率 | `Number` | 默认为 `undefined` |
| zIndex | 图层index | `Number` | 默认为 `0` |
| projection | 投影 | `String` | 现在默认支持且仅支持 `EPSG:3857` |
| projection | 投影 | `String` | 现在默认支持 `EPSG:3857`, `EPSG:4326`測試中 |
| ratio | 画布和地图窗口的比值 | `Number` | 现在默认 `1.5` |

#### methods
Expand Down
88 changes: 48 additions & 40 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,51 +51,59 @@
<script src="../node_modules/axios/dist/axios.js"></script>
<script src="../dist/windLayer.js"></script>
<script>
var Maps = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
layerName: 'baseLayer',
preload: 4,
source: new ol.source.OSM()
var Maps = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
layerName: 'baseLayer',
preload: 4,
source: new ol.source.OSM({
url: "http://{a-c}.sm.mapstack.stamen.com/" +
"(toner-lite,$fff[difference],$fff[@23],$fff[hsl-saturation@20])/" +
"{z}/{x}/{y}.png"
})
],
loadTilesWhileAnimating: true,
pixelRatio: 1,
view: new ol.View({
projection: 'EPSG:3857',
center: [113.53450137499999, 34.44104525],
zoom: 5
})
});
var wind, data;
axios.get('./out.json').then(function (res) {
if (res.data) {
data = res.data
wind = new WindLayer('', {
layerName: data,
minResolution: undefined,
maxResolution: undefined,
zIndex: 0,
projection: 'EPSG:3857',
ratio: 1
})
wind.appendTo(Maps)
}
});

function getData () {
var _data = wind.getData();
console.log(_data)
],
loadTilesWhileAnimating: true,
pixelRatio: 1,
view: new ol.View({
projection: 'EPSG:4326',
center: [113.53450137499999, 34.44104525],
zoom: 5
})
});
var wind, data;
axios.get('./out.json', {
params: {
time: Date.parse(new Date())
}

function setData () {
wind.setData(data)
}).then(function (res) {
if (res.data) {
data = res.data
wind = new WindLayer(data, {
layerName: data,
minResolution: undefined,
maxResolution: undefined,
zIndex: 0,
projection: 'EPSG:4326',
ratio: 1
})
wind.appendTo(Maps)
}
});

function clearWind () {
wind.clearWind()
}
function getData () {
var _data = wind.getData();
console.log(_data)
}

function setData () {
wind.setData(data)
}

function clearWind () {
wind.clearWind()
}
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wind-layer",
"version": "0.0.2",
"version": "0.0.3",
"description": "a openlayers extension to windjs",
"author": "FDD <[email protected]>",
"homepage": "https://sakitam-fdd.github.io/wind-layer",
Expand Down Expand Up @@ -72,7 +72,7 @@
"koa-views": "^5.2.1",
"nodemon": "^1.12.5",
"pm2": "^2.9.2",
"rollup": "0.54.1",
"rollup": "^0.55.1",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-buble": "^0.16.0",
"rollup-plugin-commonjs": "^8.2.6",
Expand Down
4 changes: 2 additions & 2 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const bodyparser = require('koa-bodyparser')
const logger = require('koa-logger')
const cors = require('koa-cors') // 跨域
const convert = require('koa-convert')

const config = require('./config/config')
const index = require('./routes/index')

// error handler
Expand All @@ -20,7 +20,7 @@ app.use(bodyparser({
}))
app.use(json())
app.use(logger())
app.use(require('koa-static')(__dirname + '/public'))
app.use(require('koa-static')(__dirname + '/' + config.staticDir))

// logger
app.use(async (ctx, next) => {
Expand Down
3 changes: 2 additions & 1 deletion server/bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Module dependencies.
*/

var config = require('../config/config')
var app = require('../app');
var debug = require('debug')('demo:server');
var http = require('http');
Expand All @@ -12,7 +13,7 @@ var http = require('http');
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
var port = normalizePort(process.env.PORT || config.port || '3000');
// app.set('port', port);

/**
Expand Down
5 changes: 3 additions & 2 deletions server/config/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
port: 3000, // 端口
staticDir: 'public', // 静态文件目录
serviceUrl: 'http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_1p00.pl',
sourceDataDir: 'public/sourceData/', // 二进制数据源
parseDataDir: 'public/parseData/' // 转换后的json数据
sourceDataDir: '/sourceData/', // 二进制数据源
parseDataDir: '/parseData/' // 转换后的json数据
}
Loading

0 comments on commit ef9548f

Please sign in to comment.