UNPKG

@mapgis/webclient-common

Version:

mapgis ES6 format for igserver

866 lines (352 loc) 16.7 kB
<header id="page-title" class="page-title"> <span class="page-title-main">类名</span> <span class="page-title-sub">Evented</span> </header> <section> <article> <div class="container-overview"> <div class='vertical-section'> <div class="members"> <div class="member"> <h4 class="name" id="Evented"> <a class="href-link" href="#Evented">#</a> <span class="code-name" id="Evented" style="font-size:30px"> new Evented<span class="signature">()</span> </span> </h4> <div class="description"> <p>事件基类,所有可接收或者发送的对象继承于此</p> </div> <dl class="details"> </dl> <h5>示例</h5> <pre class="prettyprint"><code>* ```js map.on('click', function(e) { alert(e.latlng); } ); ``` Leaflet deals with event listeners by reference, so if you want to add a listener and then remove it, define it as a function: ```js function onClick(e) { ... } map.on('click', onClick); map.off('click', onClick); ```</code></pre> </div> </div> </div> </div> <div class='vertical-section'> <h3 id='function'>方法</h3> <h4 style="margin-top: 20px;margin-bottom: 20px;">方法概述</h4> <div class="members"> <div class="table-container"> <table class="params table"> <thead> <tr> <th>名称</th> <th>返回值类型</th> <th>描述</th> </tr> </thead> <tbody> <tr class="deep-level-0"> <td class="name"><code><a href="#off">off</a></code></td> <td class="name"> <code> <span class="param-type">Object</span> </code> </td> <td class="name"><code><p>移除事件<br/> 示例如下:<br/> <a href='#off1'>[1、移除一个事件的指定回调函数]</a><br/> <a href='#off2'>[2、移除一个事件的所有回调函数]</a><br/> <a href='#off3'>[3、移除多个事件的同一个指定的回调函数]</a><br/> <a href='#off4'>[4、移除多个指定事件的回调函数]</a><br/> <a href='#off5'>[5、删除时指定上下文 - types类型为字符串]</a><br/> <a href='#off6'>[6、删除时指定上下文 - types类型为对象]</a><br/></p></code></td> </tr> <tr class="deep-level-0"> <td class="name"><code><a href="#on">on</a></code></td> <td class="name"> <code> <span class="param-type">Object</span> </code> </td> <td class="name"><code><p>注册一个新的监听事件;<br/> 示例如下:<br/> <a href='#event1'>[1、注册一个事件]</a><br/> <a href='#event2'>[2、一次注册多个事件 - 同一个回调函数]</a><br/> <a href='#event3'>[3、一次注册多个事件 - 分别指回调应函数]</a><br/> <a href='#event4'>[4、当types为字符串时 - 指定上下文]</a><br/> <a href='#event5'>[5、当types为对象时 - 指定上下文]</a><br/></p></code></td> </tr> </tbody> </table> </div> <h4 style="margin-top: 20px;margin-bottom: 20px;">方法详情</h4> <div class="member"> <h4 class="name" id="off"> <a class="href-link" href="#off">#</a> <span class="code-name" id="off" style="font-size:30px"> off<span class="signature">(types<span class="signature-attributes">opt</span>, fn<span class="signature-attributes">opt</span>, context<span class="signature-attributes">opt</span>)</span> </span> </h4> <div class="description"> <p>移除事件<br/> 示例如下:<br/> <a href='#off1'>[1、移除一个事件的指定回调函数]</a><br/> <a href='#off2'>[2、移除一个事件的所有回调函数]</a><br/> <a href='#off3'>[3、移除多个事件的同一个指定的回调函数]</a><br/> <a href='#off4'>[4、移除多个指定事件的回调函数]</a><br/> <a href='#off5'>[5、删除时指定上下文 - types类型为字符串]</a><br/> <a href='#off6'>[6、删除时指定上下文 - types类型为对象]</a><br/></p> </div> <h4>参数</h4> <div class="table-container"> <table class="params table"> <thead> <tr> <th>名称</th> <th>类型</th> <th class="last">描述</th> </tr> </thead> <tbody> <tr class="deep-level-0"> <td class="name" id="types"><code>types</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>移除指定事件类型上绑定的回调函数<br/> 当类型为字符串时,可以移除单个或多个事件类型绑定的回调函数,单个事件:&quot;click&quot;,多个事件:以空格分割:&quot;click double-click&quot;<br/> 当types为对象时,使用如下方式移除事件:{'click': onClickFun, 'mouse-move': onMouseMoveFun}</p></td> </tr> <tr class="deep-level-0"> <td class="name" id="fn"><code>fn</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"><p>事件回调函数,当types为字符串,且不指定要删除的回调函数时,删除该事件上的所有回调函数</p></td> </tr> <tr class="deep-level-0"> <td class="name" id="context"><code>context</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"><p>事件回调函数的this关键字将指向的对象</p></td> </tr> </tbody> </table> </div> <dl class="details"> </dl> <div class='columns method-parameter'> <div class="column is-2"><label>返回值</label></div> <div class="column is-10"> <div class="columns"> <div class='param-desc column is-7'><p>当前实例</p></div> <div class='column is-5 has-text-left'> <label>类型: </label> <span class="param-type">Object</span> </div> </div> </div> </div> <h5>示例</h5> <p class="code-caption"><h5 id='off1'>移除一个事件的指定回调函数</h5></p> <pre class="prettyprint"><code>// 一个事件的回调函数 const clickFunction = function (event) { console.log("点击事件:", event) } // 调用MapView或SceneView的off方法移除一个事件的回调函数 view.off('click', clickFunction)</code></pre> <p class="code-caption"><h5 id='off2'>移除一个事件的所有回调函数</h5></p> <pre class="prettyprint"><code>// 一个事件的回调函数1 const clickFunction1 = function (event) { console.log("点击事件1:", event) } // 一个事件的回调函数2 const clickFunction2 = function (event) { console.log("点击事件2:", event) } // 调用MapView或SceneView的off方法移除一个事件的所有回调函数 // 不指定回调函数,则移除该事件上的所有绑定的回调函数 view.off('click')</code></pre> <p class="code-caption"><h5 id='off3'>移除多个事件的同一个指定的回调函数</h5></p> <pre class="prettyprint"><code>// 多个事件的同一个回调函数 const eventFunction = function (event) { console.log("事件:", event) } // 调用MapView或SceneView的off方法移除多个事件的同一个指定的回调函数 view.off('click double-click', eventFunction)</code></pre> <p class="code-caption"><h5 id='off4'>移除多个指定事件的回调函数</h5></p> <pre class="prettyprint"><code>// 一个事件的回调函数 const clickFunction = function (event) { console.log("click事件:", event) } // 调用MapView或SceneView的off方法移除多个指定事件的回调函数 view.off({ // 移除click事件上一个指定的函数 "click": clickFunction, // 移除double-click上所有指定的函数 "double-click": undefined })</code></pre> <p class="code-caption"><h5 id='off5'>删除时指定上下文 - types类型为字符串</h5></p> <pre class="prettyprint"><code>// 一个事件的回调函数 const clickFunction = function (event) { console.log("点击事件:", event) } // 调用MapView或SceneView的off方法移除一个事件的回调函数 view.off('click', clickFunction, view) // 调用MapView或SceneView的off方法移除一个事件的所有回调函数 view.off('click', undefined, view)</code></pre> <p class="code-caption"><h5 id='off6'>删除时指定上下文 - types类型为对象</h5></p> <pre class="prettyprint"><code>// 一个事件的回调函数 const clickFunction = function (event) { console.log("click事件:", event) } // 调用MapView或SceneView的off方法移除多个指定事件的回调函数 view.off({ // 移除click事件上一个指定的函数 "click": clickFunction, // 移除double-click上所有指定的函数 "double-click": undefined }, view)</code></pre> </div> <div class="member"> <h4 class="name" id="on"> <a class="href-link" href="#on">#</a> <span class="code-name" id="on" style="font-size:30px"> on<span class="signature">(types<span class="signature-attributes">opt</span>, fn<span class="signature-attributes">opt</span>, context<span class="signature-attributes">opt</span>)</span> </span> </h4> <div class="description"> <p>注册一个新的监听事件;<br/> 示例如下:<br/> <a href='#event1'>[1、注册一个事件]</a><br/> <a href='#event2'>[2、一次注册多个事件 - 同一个回调函数]</a><br/> <a href='#event3'>[3、一次注册多个事件 - 分别指回调应函数]</a><br/> <a href='#event4'>[4、当types为字符串时 - 指定上下文]</a><br/> <a href='#event5'>[5、当types为对象时 - 指定上下文]</a><br/></p> </div> <h4>参数</h4> <div class="table-container"> <table class="params table"> <thead> <tr> <th>名称</th> <th>类型</th> <th style="min-width: 100px;">默认值</th> <th class="last">描述</th> </tr> </thead> <tbody> <tr class="deep-level-0"> <td class="name" id="types"><code>types</code></td> <td class="type"> <span class="param-type">String</span> | <span class="param-type">Object</span> </td> <td class="default"> null </td> <td class="description last"><p>事件类型<br/> 当types为字符串时,可以定义单个或多个事件,单个事件:&quot;click&quot;,多个事件:以空格分割:&quot;click double-click&quot;<br/> 当types为对象时,使用如下方式指定事件:{'click': onClickFun, 'mouse-move': onMouseMoveFun}</p></td> </tr> <tr class="deep-level-0"> <td class="name" id="fn"><code>fn</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="default"> null </td> <td class="description last"><p>事件回调函数</p></td> </tr> <tr class="deep-level-0"> <td class="name" id="context"><code>context</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="default"> null </td> <td class="description last"><p>事件回调函数的this关键字将指向的对象</p></td> </tr> </tbody> </table> </div> <dl class="details"> </dl> <div class='columns method-parameter'> <div class="column is-2"><label>返回值</label></div> <div class="column is-10"> <div class="columns"> <div class='param-desc column is-7'><p>当前实例</p></div> <div class='column is-5 has-text-left'> <label>类型: </label> <span class="param-type">Object</span> </div> </div> </div> </div> <h5>示例</h5> <p class="code-caption"><h5 id='event1'>注册一个事件</h5></p> <pre class="prettyprint"><code>// 初始化一个点击事件回调函数 const clickFunction = function (event) { console.log("点击事件:", event) } // 调用MapView或SceneView的on方法注册一个点击事件 view.on('click', clickFunction)</code></pre> <p class="code-caption"><h5 id='event2'>一次注册多个事件 - 同一个回调函数</h5></p> <pre class="prettyprint"><code>// 初始化一个事件回调函数 const eventFunction = function (event) { console.log("事件:", event) } // 调用MapView或SceneView的on方法注册多个事件 // 多个事件类型使用同一个回调函数 view.on('click right-click-down', eventFunction)</code></pre> <p class="code-caption"><h5 id='event3'>一次注册多个事件 - 分别指回调应函数</h5></p> <pre class="prettyprint"><code>// 初始化一个左键点击事件回调函数 const clickFunction = function (event) { console.log("click事件:", event) } // 初始化一个右键按下事件回调函数 const rightClickFunction = function (event) { console.log("right-click-down事件:", event) } // 调用MapView或SceneView的on方法注册多个事件 // 每一个事件类型,使用单独的回调函数 // 注意使用此种方式,一种类型的事件仅能指定一个回调函数 view.on({ "click": clickFunction, "right-click-down": rightClickFunction })</code></pre> <p class="code-caption"><h5 id='event4'>指定上下文 - types类型为字符串</h5></p> <pre class="prettyprint"><code>// 初始化一个点击事件回调函数 const clickFunction = function (event) { console.log("点击事件:", event) console.log("上下文对象:", this) } // 调用MapView或SceneView的on方法注册一个点击事件 // 指定view为回调函数的上下文对象 view.on('click', clickFunction, view)</code></pre> <p class="code-caption"><h5 id='event5'>指定上下文 - types类型为对象</h5></p> <pre class="prettyprint"><code>// 初始化一个点击事件回调函数 const clickFunction = function (event) { console.log("点击事件:", event) console.log("上下文对象:", this) } // 调用MapView或SceneView的on方法注册一个点击事件 // 指定view为回调函数的上下文对象 view.on({ "click": clickFunction, "right-click-down": clickFunction }, view)</code></pre> </div> </div> </div> </article> </section>