@mapgis/webclient-leaflet-plugin
Version:
455 lines (368 loc) • 15.6 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> view/utils/echarts/EchartsLayerPlugin.js</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/app.min.css">
<link type="text/css" rel="stylesheet" href="styles/iframe.css">
<link type="text/css" rel="stylesheet" href="">
</head>
<body class="layout small-header">
<div id="stickyNavbarOverlay"></div>
<div class="top-nav">
<div class="inner">
<a id="hamburger" role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
<div class="logo">
<h1> MapGIS Client for JavaScript API</h1>
</div>
<div class="menu">
<div class="navigation">
<a
class="link user-link "
href="/docs/cesium/index.html"
>
Cesium
</a>
<a
class="link user-link "
href="/docs/mapboxgl/index.html"
>
MapboxGL
</a>
<a
class="link user-link "
href="/docs/leaflet/index.html"
>
Leaflet
</a>
<a
class="link user-link "
href="/docs/openlayers/index.html"
>
OpenLayers
</a>
</div>
</div>
</div>
</div>
<div id="main">
<div
class="sidebar "
id="sidebarNav"
>
<div>
<span class="mapgis-api-document-span"><a href="index.html">API文档</a></span>
</div>
<div class="search-wrapper">
<input id="search" type="text" placeholder="搜索文档..." class="input">
</div>
<nav>
<div class="category"><div style="font-weight: bold;vertical-align: middle;padding: 0.4rem 0;" class="mapgis-menu-span"><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/m.png" alt="">视图模块</div><ul class="mapgis-sidebar-menus"><li><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/c.png" alt=""><a href="DrawControl.html">DrawControl</a><span style="display: none;"><p>绘制工具</p></span></li><li><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/c.png" alt=""><a href="MapView.html">MapView</a><span style="display: none;"><p>二维场景视图(leaflet引擎),对地图引擎进行管理,如果要对地图图层进行管理请参考[Map]{@link Map},<br/>
参考示例:
<a href='#MapView'>[初始化二维场景视图]</a>
<br>[ES5引入方式]:<br/>
Zondy.MapView() <br/>
[ES6引入方式]:<br/>
import { MapView } from '@mapgis/webclient-leaflet-plugin' <br/></p></span></li><li><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/c.png" alt=""><a href="Popup.html">Popup</a><span style="display: none;"><p>二维场景信息弹窗(leaflet引擎)
参考示例:
<a href='#MapView'>[初始化二维场景视图]</a>
[ES6引入方式]:<br/>
import { Popup } from '@mapgis/webclient-leaflet-plugin' <br/>
自定义样式说明:<br/>
zondy-popup__content 弹窗容器样式<br/>
zondy-popup__tip 弹窗对话框箭头样式<br/>
zondy-popup__header 弹窗头部样式<br/>
zondy-popup__content 弹窗主体样式<br/>
zondy-popup__footer 弹窗底部样式<br/></p></span></li><li><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/c.png" alt=""><a href="Screenshot.html">Screenshot</a><span style="display: none;"><p>屏幕打印工具</p></span></li></ul><div style="font-weight: bold;vertical-align: middle;padding: 0.4rem 0;" class="mapgis-menu-span"><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/m.png" alt="">草图编辑模块</div><ul class="mapgis-sidebar-menus"><li><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/c.png" alt=""><a href="SketchEditorLeaflet.html">SketchEditorLeaflet</a><span style="display: none;"><p>二维场景草图编辑类<br/>
<br>[ES5引入方式]:<br/>
const { SketchEditorLeaflet } = Zondy <br/>
[ES6引入方式]:<br/>
import { SketchEditorLeaflet } from "@mapgis/webclient-leaflet-plugin" <br/></p></span></li></ul><div style="font-weight: bold;vertical-align: middle;padding: 0.4rem 0;" class="mapgis-menu-span"><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/m.png" alt="">渲染器模块</div><ul class="mapgis-sidebar-menus"><li><img style="width: 20px;margin-right: 6px;vertical-align: middle;" src="./styles/c.png" alt=""><a href="Zondy.ThemeLayer.GraphThemeLayer.html">GraphThemeLayer</a><span style="display: none;"><p>统计专题图通过为每个要素绘制统计图表来反映其对应的专题值的大小。它可同时表示多个字段属性信息,在区域本身与各区域之间形成横向和纵向的对比。<br>统计专题图多用于具有相关数量特征的地图上,比如表示不同地区多年的粮食产量、GDP、人口等,不同时段客运量、地铁流量等。目前提供的统计图类型有:柱状图(Bar),折线图(Line),饼图(Pie),三维柱状图(Bar3D),点状图(Point),环状图(Ring)。</p></span></li></ul></div>
</nav>
</div>
<div class="core" id="main-content-wrapper">
<div class="content">
<header id="page-title" class="page-title">
<span class="page-title-main">类名</span>
<span class="page-title-sub">view/utils/echarts/EchartsLayerPlugin.js</span>
</header>
<section>
<article>
<pre class="prettyprint source linenums"><code>import * as L from '@mapgis/leaflet'
import MapCoordSys from './MapCoordSys'
import { getMapRotateBounds } from '../support/utils'
const echarts = window.echarts
const EchartsLayerConstuct = L.Layer.extend({
map: null, // 传入的leaflet地图
chart: null,
options: null,
echartsInitOpts: null,
canvas: null,
initialize(map, options) {
this.map = map
this.options = options
this.echartsInitOpts = options.echartsInitOpts
this.layerId = options.layerId || 'echartlayerdefaultid'
this.layerClass = options.classId || 'echartlayerdefaultclass'
this.visible = true
this.initDevicePixelRatio()
this.initOptions(this.options)
this.initEcharts()
this._resizeCanvas()
},
initDevicePixelRatio() {
this.devicePixelRatio = window.devicePixelRatio || 1
},
initOptions(options) {
if (options) {
if (options.leaflet) {
return
}
this.options.leaflet = {
roam: true
}
}
},
initEcharts() {
echarts.registerCoordinateSystem('leaflet', MapCoordSys)
echarts.extendComponentModel({
type: 'leaflet',
getBMap() {
return this.__leaflet
},
defaultOption: {
roam: false
}
})
echarts.registerAction(
{
type: 'LeafletRoma',
event: 'LeafletRoma',
update: 'updateLayout'
},
function () {}
)
},
_visible() {
this.visible = true
this.canvas.style.visibility = 'visible'
},
_unvisible() {
this.visible = false
this.canvas.style.visibility = 'hidden'
},
onAdd(map) {
const vm = this
this.map = map
this.canvas = this._createCanvas()
this.map.getPanes().overlayPane.appendChild(this.canvas)
this.chart = echarts.init(this.canvas, null, this.echartsInitOpts)
echarts.leafletMap = map
const self = this
map.on('resize', function (e) {
self.resize()
})
map.on('zoomstart', function () {
self._unvisible()
})
map.on('rotate', () => {
self.resize()
})
echarts.extendComponentView({
type: 'leaflet',
render(mapModel, ecModel, api) {
let rendering = true
if (!self._echartRenderApi) {
self._echartRenderApi = api
}
if (!self._mapModel) {
self._mapModel = mapModel
}
const leafletMap = echarts.leafletMap
const viewportRoot = api.getZr().painter.getViewportRoot()
const coordSys = mapModel.coordinateSystem
const moveHandler = function () {
if (rendering || !vm.visible) {
return
}
const topleft = leafletMap.getBounds().getNorthWest()
const offset = leafletMap.latLngToLayerPoint(topleft)
const mapOffset = [
parseInt(offset.x, 10) || 0,
parseInt(offset.y, 10) || 0
]
viewportRoot.style.left = `${mapOffset[0]}px`
viewportRoot.style.top = `${mapOffset[1]}px`
coordSys.setMapOffset(mapOffset)
mapModel.__mapOffset = mapOffset
api.dispatchAction({
type: 'LeafletRoma'
})
}
const zoomEndHandler = function () {
self._visible()
if (rendering || !vm.visible) {
return
}
api.dispatchAction({
type: 'LeafletRoma'
})
}
if (this._oldMoveHandler) {
leafletMap.off('move', this._oldMoveHandler)
}
if (this._oldZoomEndHandler) {
leafletMap.off('zoomend', this._oldZoomEndHandler)
}
leafletMap.on('move', moveHandler)
leafletMap.on('zoomend', zoomEndHandler)
this._oldMoveHandler = moveHandler
this._oldZoomEndHandler = zoomEndHandler
rendering = false
}
})
this.chart.setOption(this.options)
},
onRemove() {
this.chart.dispose()
},
_createCanvas() {
const canvas = document.createElement('div')
canvas.id = this.layerId
canvas.style.top = '0px'
canvas.style.left = '0px'
canvas.height = `${this.map.getSize().y}px`
canvas.width = `${this.map.getSize().x}px`
canvas.style.height = `${this.map.getSize().y}px`
canvas.style.width = `${this.map.getSize().x}px`
canvas.style.zIndex = 1000
canvas.setAttribute('id', this.layerId)
canvas.setAttribute('class', this.layerClass)
this.canvas = canvas
return canvas
},
_resizeCanvas() {
window.onresize = this.resize.bind(this)
},
_calcRotateBounds() {
return getMapRotateBounds(this._map)
},
/**
* 显示图层
* @function L.zondy.EchartsLayer.prototype.show
*/
show() {
this._visible()
},
/**
* 隐藏图层
* @function L.zondy.EchartsLayer.prototype.hide
*/
hide() {
this._unvisible()
},
/**
* 重置图层大小
* @function L.zondy.EchartsLayer.prototype.resize
*/
resize() {
const self = this
const size = self._calcRotateBounds().getSize()
self.canvas.style.width = `${size.x}px`
self.canvas.style.height = `${size.y}px`
self.canvas.width = size.x
self.canvas.height = size.y
self.chart.resize()
// 缓存echart api
if (self._echartRenderApi && self._mapModel && self._map._rotate) {
// 以下渲染逻辑和moveHandler一致
const api = self._echartRenderApi
const mapModel = self._mapModel
const viewportRoot = api.getZr().painter.getViewportRoot()
const coordSys = mapModel.coordinateSystem
const topleft = this.map.getBounds().getNorthWest()
const offset = this.map.latLngToLayerPoint(topleft)
const mapOffset = [
parseInt(offset.x, 10) || 0,
parseInt(offset.y, 10) || 0
]
viewportRoot.style.left = `${mapOffset[0]}px`
viewportRoot.style.top = `${mapOffset[1]}px`
coordSys.setMapOffset(mapOffset)
mapModel.__mapOffset = mapOffset
// 触发echarts图层更新
api.dispatchAction({
type: 'LeafletRoma'
})
}
},
/**
* @function L.zondy.EchartsLayer.prototype.update
* @param {*} option echarts.option
* @see https://www.echartsjs.com/zh/tutorial.html#异步数据加载和更新
* @description ECharts 由数据驱动,数据的改变驱动图表展现的改变,因此动态数据的实现也变得异常简单。所有数据的更新都通过 setOption实现,你只需要定时获取数据,setOption 填入数据,而不用考虑数据到底产生了那些变化,ECharts 会找到两组数据之间的差异然后通过合适的动画去表现数据的变化。
*/
update(option) {
this.chart.setOption(option)
},
/**
* 删除图层
* @function module:客户端可视化.EchartsLayer.prototype.remove
*/
remove() {
this.chart.clear()
if (this.canvas.parentElement) {
this.canvas.parentElement.removeChild(this.canvas)
}
this.map = undefined
return this
},
setOpacity(opacity) {
this.canvas.style.opacity = opacity
}
})
const echartsLayer = function (echartsParams, options) {
return new EchartsLayerConstuct(echartsParams, options)
}
export default echartsLayer
</code></pre>
</article>
</section>
</div>
<footer class="footer">
<div class="content has-text-centered">
<p>文档生成<a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a></p>
<p class="sidebar-created-by">
<a href="http://www.smaryun.com" target="_blank">司马云</a> <span>© 2023 云生态圈</span>
<a href="http://192.168.82.89:8086/#/index" target="_blank">MapGIS Client for JavaScript</a>
</p>
</div>
</footer>
</div>
<div id="side-nav" class="side-nav">
<div style="margin-bottom: 10px;">
<img style="vertical-align: middle;margin-right: 10px;width: 30px;" src="./styles/anchor.png"/><a href="#page-title">构造函数</a>
</div>
<div style="margin-bottom: 10px;">
<img style="vertical-align: middle;margin-right: 10px;width: 30px;" src="./styles/anchor.png"/><a href="#member">成员变量</a>
</div>
<div style="margin-bottom: 10px;">
<img style="vertical-align: middle;margin-right: 10px;width: 30px;" src="./styles/anchor.png"/><a href="#function">方法</a>
</div>
<div>
<img style="vertical-align: middle;margin-right: 10px;width: 30px;" src="./styles/anchor.png"/><a href="#event">事件</a>
</div>
</div>
</div>
<script src="scripts/linenumber.js"> </script>
<script src="scripts/search.js"> </script>
</body>
</html>