1.0.0 • Published 4 years ago
saturn-js-api v1.0.0
saturn
saturn 定义了一套基于 typescript 的统一的 webgis 框架访问接口,采用对象适配器的设计模式来实现不同的 webgis 框架的相同操作。 它所带来的好处是,减小切换框架时所带来的的代价。当有新的框架出现时(如 leaflet),开发人员需在学习的同时基于 saturn 编写相应的适配器。
目前正在适配的 arcgis api for js 的版本是4.16,openlayers 的版本是6.4.0。
对于 saturn 暂时未支持的接口,可以取出其 value 并强制转换为 arcgis/ol api 原本的类型再操作。
目录
Map
示例:
// 以 openlayers 适配器为例
import {
MapAdapter as OlMap,
MapImageLayerAdapter as OlMapImageLayer
} from './lib/saturn/adapter/ol'
import { Map } from './lib/saturn'
const map: Map = new OlMap({
layers: [
new OlMapImageLayer({
url: '' // MapServer 动态服务地址
})
]
})
构造函数
new xxMap(options?) // xx 泛指待适配的框架,如 ol
options 概览
名字 | 类型 | 描述 |
---|---|---|
layers | Layer[] | 可操作图层数组 |
View
示例
import {
MapAdapter as OlMap,
ViewAdapter as OlView,
PointAdapter as OlPoint,
MapImageLayerAdapter as OlMapImageLayer,
} from './lib/saturn/adapter/ol'
import { Map, View } from './lib/saturn'
const map: Map = new OlMap({
layers: [
new OlMapImageLayer({
url: '' // MapServer 服务地址
})
]
})
const view: View = new OlView({
map,
container: 'viewDiv',
center: new OlPoint({
x: 12706131.00825,
y: 2579675.822
}),
zoom: 13
})
构造函数
new xxView(options?)
options 概览
名字 | 类型 | 描述 |
---|---|---|
center | Point | 视图中心 |
container | string | 呈现视图的 DOM 元素 id |
map | Map | 需要显示在视图的地图对象 |
zoom | number | 地图缩放级别 |
Graphic
构造函数
new xxGraphic(options?)
options 概览
名字 | 类型 | 描述 |
---|---|---|
geometry | Geometry | 定义图形位置的几何 |
Geometry
Point
Point -> Geometry
示例
import {
PointAdapter as OlPoint
} from './lib/saturn/adapter/ol'
import { Point } from './lib/saturn'
const pt: Point = new OlPoint({
x: 12706131.00825,
y: 2579675.822
})
构造函数
new xxPoint(options?)
options 概览
名字 | 类型 | 描述 |
---|---|---|
latitude | number | 纬度 |
longitude | number | 经度 |
x | number | x 坐标 |
y | number | y 坐标 |
Layer
MapImageLayer
MapImageLayer -> Layer
概述
MapImageLayer 对应 arcgis api for js 4.x 里的 MapImageLayer,主要用于展示动态地图服务的图层。
示例
import {
MapImageLayerAdapter as OlMapImageLayer,
} from './lib/saturn/adapter/ol'
import { MapImageLayer } from './lib/saturn'
const ly: MapImageLayer = new OlMapImageLayer({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer'
})
构造函数
new xxMapImageLayer(options?)
options 概览
名字 | 类型 | 描述 |
---|---|---|
url | string | 地图服务的 rest 端点 url |
GraphicsLayer
构造函数
new xxGraphicsLayer(options?)
options 概览
名字 | 类型 | 描述 |
---|---|---|
graphics | Graphic[] | 图形数组 |
适配器
esri
概述
esri 适配器在实现 saturn 接口的同时调用了 arcgis api for js,但并非所有 arcgis api 的功能都能并且能适配,目前只适配了上述 saturn 的接口。
- FeatureLayer
起步
// 首先要在项目的启动入口里全局配置 esri-loader
// 以 vue 为例,则在 main.ts 文件里编写如下代码:
import { setDefaultOptions } from 'esri-loader'
setDefaultOptions({
url: encodeURI('/arcgis_js_sdk/arcgis_js_api/library/4.14/init.js'),
css: encodeURI('/arcgis_js_sdk/arcgis_js_api/library/4.14/esri/css/main.css'),
insertCssBefore: 'style'
})
ol
概述
ol 适配器在实现 saturn 接口的同时调用了 openlayers,但并非所有 openlayers 的功能都能并且能适配,目前只适配了上述 saturn 的接口。(ol 适配工作已推迟)
1.0.0
4 years ago