UNPKG

@mapgis/webclient-leaflet-plugin

Version:

384 lines (323 loc) 16.1 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title> document/theme/RandomThemeLayer.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 &quot;@mapgis/webclient-leaflet-plugin&quot; <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">document/theme/RandomThemeLayer.js</span> </header> <section> <article> <pre class="prettyprint source linenums"><code>import { Zondy, Extent } from '@mapgis/webclient-common' import * as L from '@mapgis/leaflet' // eslint-disable-next-line import/no-extraneous-dependencies import { copyAttributesWithClip } from '@mapgis/webclient-graphic-render' import GeoFeatureThemeLayer from './GeoFeatureThemeLayer' import ThemeLayer from './ThemeLayer' /** * @class Zondy.ThemeLayer.RandomThemeLayer * @classdesc 随机专题图。 * @description 随机专题图对数据(&lt;{@link Zondy.Feature.Vector}>)属性字段(attributes)的属性值进行分段,使用不同的颜色或符号(线型、填充)渲染不同范围段的属性值。 * 随机专题图一般用来反映连续分布现象的数量或程度特征,如降水量的分布,土壤侵蚀强度的分布等。 * @extends Zondy.ThemeLayer.GeoFeatureThemeLayer * @param {string} name - 图层名 * @param {Object} options - 图层参数。 * @param {string} [options.id] - 专题图层 ID。默认使用 CommonUtil.createUniqueID("themeLayer_") 创建专题图层 ID。 * @param {number} [options.opacity=1] - 图层透明度。 * @param {number} [options.nodesClipPixel=2] - 节点抽稀像素距离。 * @param {boolean} [options.isHoverAble=false] - 图形是否在 hover 时高亮。 * @param {boolean} [options.isMultiHover=false] - 是否多图形同时高亮,用于高亮同一个数据对应的所有图形(如:多面)。 * @param {boolean} [options.isClickAble=true] - 图形是否可点击。 * @param {boolean} [options.isAllowFeatureStyle=false] - 是否允许 feature 样式(style) 中的有效属性应用到专题图层。禁止对专题要素使用数据(feature)的 style。此属性可强制将数据 feature 的 style 中有效属性应用到专题要素上,且拥有比图层 style 和 styleGroups 更高的优先级,使专题要素的样式脱离专题图层的控制。可以通过此方式实现对特殊数据(feature) 对应专题要素赋予独立 style。 */ const RandomThemeLayer = GeoFeatureThemeLayer.extend({ /** * @function Zondy.ThemeLayer.RandomThemeLayer.prototype.initialize * @description 初始化。 * @param {string} name - 专题图名。 * @param {Object} options - 需要设置的参数对象。 */ initialize(name, options) { GeoFeatureThemeLayer.prototype.initialize.call(this, name, options) // {Array&lt;Zondy.ThemeLayer.ThemeStyle>} 图层中专题要素的样式 this.style = [] // {String} 用于指定专题要素样式的属性字段名称。 // 此属性字段是要用户数据(feature) attributes 中包含的字段,且字段对应的值的类型必须是数值型。使用标签分组显示还需要设置 styleGroups 属性。 this.keepStyle = true }, /** * @function Zondy.ThemeLayer.RandomThemeLayer.prototype.getColor * @description 获取随机颜色 * @return {Array} color */ getColor() { const colorValue = '0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f' const colorArray = colorValue.split(',') let color = '#' // 定义一个存放十六进制颜色值的字符串变量,先将#存放进去 for (let i = 0; i &lt; 6; i++) { color += colorArray[Math.floor(Math.random() * 16)] } return color }, /** * @function Zondy.ThemeLayer.RandomThemeLayer.prototype.getStyleByData * @return {Array&lt;Zondy.ThemeLayer.ThemeStyle>} 专题要素的 Style */ getStyleByData() { const me = this const style = copyAttributesWithClip({}, me.style) style.fillColor = me.getColor() return style }, /** * @function Zondy.ThemeLayer.RandomThemeLayer.prototype.onAdd * @description 添加专题图 * @param map - {L.map} 要添加的地图 */ onAdd(map) { const me = this me.map = me._map = map me._initContainer() if (!me.levelRenderer) { map.removeLayer(me) return } // 初始化渲染器 const size = map.getSize() me.container.style.width = `${size.x}px` me.container.style.height = `${size.y}px` me._updateOpacity() me.renderer = me.levelRenderer.init(me.container) me.renderer.clear() if (me.features &amp;&amp; me.features.length > 0) { me._reset() } // 处理用户预先(在图层添加到 map 前)监听的事件 me.addTFEvents() me.mouseMoveHandler = function (e) { const xy = e.layerPoint me.currentMousePosition = L.point( xy.x + me.movingOffset[0], xy.y + me.movingOffset[1] ) } map.on('mousemove', me.mouseMoveHandler) me.zoomstartHandler = function (e) { me.keepStyle = false // alert('start'); } map.on('zoomstart ', me.zoomstartHandler) me.zoomendHandler = function (e) { me.keepStyle = true // alert('end'); } map.on('zoomend', me.zoomendHandler) me.update() }, /** * @function Zondy.ThemeLayer.RandomThemeLayer.prototype.redrawThematicFeatures * @description 重绘专题要素 * @param bounds - {L.Bounds} 地图范围 */ redrawThematicFeatures(bounds) { const me = this // 获取高亮专题要素对应的用户 id const hoverone = me.renderer.getHoverOne() let hoverFid = null if (hoverone &amp;&amp; hoverone.refDataID) { hoverFid = hoverone.refDataID } const features = me.features if (bounds &amp;&amp; bounds instanceof L.LatLngBounds) { const crs = this._map.options.crs bounds = L.bounds( crs.project(bounds.getSouthWest()), crs.project(bounds.getNorthEast()) ) bounds = new Extent({ xmin: bounds.min.x, ymin: bounds.min.y, xmax: bounds.max.x, ymax: bounds.max.y }) } // 清除当前所有可视元素 me.renderer.clearAll() const cache = me.cache const cacheFields = me.cacheFields const cmZoom = me._map.getZoom() const maxCC = me.maxCacheCount for (let i = 0, len = features.length; i &lt; len; i++) { const feature = features[i] if (!feature || !feature.geometry) { continue } // 要素范围判断 const feaBounds = feature.geometry.extent // 剔除当前视图(地理)范围以外的数据 if (bounds &amp;&amp; !bounds.intersects(feaBounds)) { continue } // 缓存字段 const fields = `${feature.FID}_zoom_${cmZoom.toString()}` if (cache[fields] &amp;&amp; me.keepStyle) { cache[fields].updateAndAddShapes() continue } const thematicFeature = me.createThematicFeature(features[i]) // 检查 thematicFeature 是否有可视化图形 if (thematicFeature.getShapesCount() &lt; 1) { continue } // 加入缓存 cache[fields] = thematicFeature cacheFields.push(fields) // 缓存数量限制 if (cacheFields.length > maxCC) { const fieldsTemp = cacheFields[0] cacheFields.splice(0, 1) delete cache[fieldsTemp] } // console.log("total: %d ,current:%d", features.length,i); } me.renderer.render() // 地图漫游后,重新高亮图形 if (hoverFid &amp;&amp; me.options.isHoverAble &amp;&amp; me.options.isMultiHover) { const hShapes = this.getShapesByFeatureID(hoverFid) this.renderer.updateHoverShapes(hShapes) } }, /** * @function Zondy.ThemeLayer.RandomThemeLayer.prototype.redraw * @description 重绘专题图 */ redraw() { if (!this.keepStyle) { this.clearCache() } return ThemeLayer.prototype.redraw.apply(this, arguments) } }) Zondy.ThemeLayer.RandomThemeLayer = RandomThemeLayer export default RandomThemeLayer </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>