pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<tfoot id='tL3ji'></tfoot>

    <small id='tL3ji'></small><noframes id='tL3ji'>

    1. <i id='tL3ji'><tr id='tL3ji'><dt id='tL3ji'><q id='tL3ji'><span id='tL3ji'><b id='tL3ji'><form id='tL3ji'><ins id='tL3ji'></ins><ul id='tL3ji'></ul><sub id='tL3ji'></sub></form><legend id='tL3ji'></legend><bdo id='tL3ji'><pre id='tL3ji'><center id='tL3ji'></center></pre></bdo></b><th id='tL3ji'></th></span></q></dt></tr></i><div class="xrd775t" id='tL3ji'><tfoot id='tL3ji'></tfoot><dl id='tL3ji'><fieldset id='tL3ji'></fieldset></dl></div>
      <legend id='tL3ji'><style id='tL3ji'><dir id='tL3ji'><q id='tL3ji'></q></dir></style></legend>
        <bdo id='tL3ji'></bdo><ul id='tL3ji'></ul>
    2. 觸發點擊傳單標記

      Trigger click on leaflet marker(觸發點擊傳單標記)
        <bdo id='cNY8d'></bdo><ul id='cNY8d'></ul>
        <legend id='cNY8d'><style id='cNY8d'><dir id='cNY8d'><q id='cNY8d'></q></dir></style></legend>

      • <tfoot id='cNY8d'></tfoot>

        1. <small id='cNY8d'></small><noframes id='cNY8d'>

            <tbody id='cNY8d'></tbody>

              <i id='cNY8d'><tr id='cNY8d'><dt id='cNY8d'><q id='cNY8d'><span id='cNY8d'><b id='cNY8d'><form id='cNY8d'><ins id='cNY8d'></ins><ul id='cNY8d'></ul><sub id='cNY8d'></sub></form><legend id='cNY8d'></legend><bdo id='cNY8d'><pre id='cNY8d'><center id='cNY8d'></center></pre></bdo></b><th id='cNY8d'></th></span></q></dt></tr></i><div class="b7tjnn5" id='cNY8d'><tfoot id='cNY8d'></tfoot><dl id='cNY8d'><fieldset id='cNY8d'></fieldset></dl></div>
                本文介紹了觸發點擊傳單標記的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我在地圖上有一堆傳單標記.每個標記都保存在數組 markers 中.標記是動態創建的(在 ajax 調用期間).

                I have a bunch of leaflet markers on the map. Each marker is held in array markers. The markers are created dynamically (during an ajax call).

                var markers = [];
                .
                .
                var marker = L.marker([mar.lat, mar.lng], {
                  // ...build the marker...
                }
                marker._leaflet_id = mar.id; // give the marker an id corresponding to the id of its corresponding div
                var myHoverIcon = L.icon({
                  iconUrl: mar.imgUrl,
                  iconSize: [40, 40],
                  popupAnchor: [0, 0]
                });
                marker.on('click', function(e) {
                  alert('Marker clicked!');
                  marker.setIcon(myHoverIcon);
                });
                .
                .
                markers.push(marker);
                

                每個標記都有一個對應于特定 div 的 id(存儲在 div 上的 data-mess_id 中).計劃是在點擊提要中相應的 div 時更改標記的圖標.

                Each marker has an id corresponding to a particular div (stored in data-mess_id on the div). The plan is to change the marker's icon when its corresponding div in the feed is clicked on.

                $('#feed').on('mouseover', '.message', function() {
                  var cssid = $(this).attr('data-mess_id').toString();
                  var baz = $.grep(markers, function(m) {
                    return (m._leaflet_id == cssid);
                  });
                  baz[0].trigger('click');   // doesn't work 
                  alert(baz[0].getLatLng()); // does work
                
                  // this also does not work:
                  var myHoverIcon = L.icon({
                    iconUrl: baz[0].imgUrl,
                    iconSize: [40, 40],
                    popupAnchor: [0, 0]
                  });
                  baz[0].setIcon(myHoverIcon);
                
                });
                

                除了最后一點,一切都很好.我只是無法在標記上觸發點擊事件.我肯定有正確的標記,因為 baz[0].getLatLng() 正在工作.但是 baz[0].trigger('click') 不起作用.

                It's all working fine except for the final bit. I just can't trigger a click event on the marker. I definitely have the correct marker because baz[0].getLatLng() is working. But baz[0].trigger('click') doesn't work.

                我嘗試動態創建一個新圖標 (myHoverIcon) 但它不起作用.

                I tried creating a new icon dynamically (myHoverIcon) but it doesn't work.

                如何在標記上觸發點擊事件?

                How do I trigger a click event on the marker?

                還有其他方法可以更改標記圖標嗎?

                Is there another way to change the marker icon?

                推薦答案

                要模擬鼠標點擊,您可以使用 fire 方法(繼承自 Evented.fire) 在標記上:

                To emulate a mouse click, you can use the fire method (inherited from Evented.fire) on the marker :

                marker.fire('click');
                

                還有一個演示

                var map = L.map('map').setView([0, 0], 12);
                
                var icon = L.icon({
                  iconUrl: 'http://leafletjs.com/examples/custom-icons/leaf-green.png'
                });
                var marker = L.marker([0, 0], {icon: icon})
                  .addTo(map);
                  
                  
                var myHoverIcon = L.icon({
                  iconUrl: 'http://leafletjs.com/examples/custom-icons/leaf-red.png'
                });
                  
                  
                marker.on('click', function(e) {
                  marker.setIcon(myHoverIcon);
                });
                
                document.querySelector('button').addEventListener('click', function() {
                  marker.fire('click');
                });

                html, body {
                  height: 100%;
                  margin: 0;
                }
                #map {
                  width: 100%;
                  height: 100%;
                }
                
                button {position: absolute; left:10 px; top: 70px;}

                <link rel="stylesheet"  integrity="sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ==" crossorigin=""/>
                
                <script src="https://unpkg.com/leaflet@1.2.0/dist/leaflet.js" integrity="sha512-lInM/apFSqyy1o6s89K4iQUKg6ppXEgsVxT35HbzUupEVRh2Eu9Wdl4tHj7dZO0s1uvplcYGmt3498TtHq+log==" crossorigin=""></script>
                   
                <div id='map'></div>
                <button>Click me</button>

                這篇關于觸發點擊傳單標記的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Check if a polygon point is inside another in leaflet(檢查一個多邊形點是否在傳單中的另一個內部)
                Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標記群集圖標顏色,繼承其余默認 CSS 屬性)
                How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認加載磁貼顏色?)
                Add external geojson to leaflet layer(將外部geojson添加到傳單層)
                Adding Leaflet layer control to sidebar(將 Leaflet 圖層控件添加到側邊欄)
                Leaflet - get latitude and longitude of a marker inside a pop-up(Leaflet - 在彈出窗口中獲取標記的緯度和經度)

                    <tbody id='9iszP'></tbody>

                  <small id='9iszP'></small><noframes id='9iszP'>

                      <tfoot id='9iszP'></tfoot>
                      <i id='9iszP'><tr id='9iszP'><dt id='9iszP'><q id='9iszP'><span id='9iszP'><b id='9iszP'><form id='9iszP'><ins id='9iszP'></ins><ul id='9iszP'></ul><sub id='9iszP'></sub></form><legend id='9iszP'></legend><bdo id='9iszP'><pre id='9iszP'><center id='9iszP'></center></pre></bdo></b><th id='9iszP'></th></span></q></dt></tr></i><div class="xz7dhhv" id='9iszP'><tfoot id='9iszP'></tfoot><dl id='9iszP'><fieldset id='9iszP'></fieldset></dl></div>
                    1. <legend id='9iszP'><style id='9iszP'><dir id='9iszP'><q id='9iszP'></q></dir></style></legend>
                      • <bdo id='9iszP'></bdo><ul id='9iszP'></ul>
                        • 主站蜘蛛池模板: 灌木树苗-绿化苗木-常绿乔木-价格/批发/基地 - 四川成都途美园林 | 真空干燥烘箱_鼓风干燥箱 _高低温恒温恒湿试验箱_光照二氧化碳恒温培养箱-上海航佩仪器 | 东莞注册公司-代办营业执照-东莞公司注册代理记账-极刻财税 | 天津市能谱科技有限公司-专业的红外光谱仪_红外测油仪_紫外测油仪_红外制样附件_傅里叶红外光谱技术生产服务厂商 | 润滑脂-高温润滑脂-轴承润滑脂-食品级润滑油-索科润滑油脂厂家 | 膜结构停车棚-自行车棚-膜结构汽车棚加工安装厂家幸福膜结构 | 齿轮减速马达一体式_蜗轮蜗杆减速机配电机-德国BOSERL齿轮减速电动机生产厂家 | 臭氧实验装置_实验室臭氧发生器-北京同林臭氧装置网 | 企业管理培训,企业培训公开课,企业内训课程,企业培训师 - 名课堂企业管理培训网 | 骁龙云呼电销防封号系统-axb电销平台-外呼稳定『免费试用』 | 河南中专学校|职高|技校招生-河南中职中专网 | 米顿罗计量泵(科普)——韬铭机械 | 顶呱呱交易平台-行业领先的公司资产交易服务平台| 磁力抛光机_磁力研磨机_磁力去毛刺机_精密五金零件抛光设备厂家-冠古科技 | 知名电动蝶阀,电动球阀,气动蝶阀,气动球阀生产厂家|价格透明-【固菲阀门官网】 | 浇钢砖,流钢砖_厂家价低-淄博恒森耐火材料有限公司 | 皮带机_移动皮带机_大倾角皮带机_皮带机厂家 - 新乡市国盛机械设备有限公司 | 行星齿轮减速机,减速机厂家,山东减速机-淄博兴江机械制造 | 地磅-电子地磅维修-电子吊秤-汽车衡-无人值守系统-公路治超-鹰牌衡器 | 重庆磨床过滤机,重庆纸带过滤机,机床伸缩钣金,重庆机床钣金护罩-重庆达鸿兴精密机械制造有限公司 | LED灯杆屏_LED广告机_户外LED广告机_智慧灯杆_智慧路灯-太龙智显科技(深圳)有限公司 | 飞飞影视_热门电影在线观看_影视大全 | 扒渣机,铁水扒渣机,钢水扒渣机,铁水捞渣机,钢水捞渣机-烟台盛利达工程技术有限公司 | 明渠式紫外线杀菌器-紫外线消毒器厂家-定州市优威环保 | 玉米深加工设备-玉米深加工机械-新型玉米工机械生产厂家-河南粮院机械制造有限公司 | 专业生物有机肥造粒机,粉状有机肥生产线,槽式翻堆机厂家-郑州华之强重工科技有限公司 | 卷筒电缆-拖链电缆-特种柔性扁平电缆定制厂家「上海缆胜」 | 河南新乡德诚生产厂家主营震动筛,振动筛设备,筛机,塑料震动筛选机 | 铣床|万能铣床|立式铣床|数控铣床|山东滕州万友机床有限公司 | 彩信群发_群发彩信软件_视频短信营销平台-达信通 | 针焰试验仪,灼热丝试验仪,漏电起痕试验仪,水平垂直燃烧试验仪 - 苏州亚诺天下仪器有限公司 | 篮球架_乒乓球台_足球门_校园_竞技体育器材_厂家_价格-沧州浩然体育器材有限公司 | 酶联免疫分析仪-多管旋涡混合仪|混合器-莱普特科学仪器(北京)有限公司 | 纯化水设备-纯水设备-超纯水设备-[大鹏水处理]纯水设备一站式服务商-东莞市大鹏水处理科技有限公司 | 中药超微粉碎机(中药细胞级微粉碎)-百科 | 家庭教育吧-在线家庭教育平台,专注青少年家庭教育 | 广东西屋电气有限公司-广东西屋电气有限公司 | 上海佳武自动化科技有限公司 | 哈尔滨治「失眠/抑郁/焦虑症/精神心理」专科医院排行榜-京科脑康免费咨询 一对一诊疗 | 热处理温控箱,热处理控制箱厂家-吴江市兴达电热设备厂 | 电动葫芦-河北悍象起重机械有限公司|