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

    <i id='Pfmud'><tr id='Pfmud'><dt id='Pfmud'><q id='Pfmud'><span id='Pfmud'><b id='Pfmud'><form id='Pfmud'><ins id='Pfmud'></ins><ul id='Pfmud'></ul><sub id='Pfmud'></sub></form><legend id='Pfmud'></legend><bdo id='Pfmud'><pre id='Pfmud'><center id='Pfmud'></center></pre></bdo></b><th id='Pfmud'></th></span></q></dt></tr></i><div class="rb57vth" id='Pfmud'><tfoot id='Pfmud'></tfoot><dl id='Pfmud'><fieldset id='Pfmud'></fieldset></dl></div>
  1. <legend id='Pfmud'><style id='Pfmud'><dir id='Pfmud'><q id='Pfmud'></q></dir></style></legend>

        <bdo id='Pfmud'></bdo><ul id='Pfmud'></ul>
    1. <tfoot id='Pfmud'></tfoot>

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

      如何使用傳單 js 在地圖上精確放置 div 元素?

      How to precisely place a div element on a map using leaflet js?(如何使用傳單 js 在地圖上精確放置 div 元素?)
        <tbody id='KuLXF'></tbody>

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

          <legend id='KuLXF'><style id='KuLXF'><dir id='KuLXF'><q id='KuLXF'></q></dir></style></legend><tfoot id='KuLXF'></tfoot>

              <bdo id='KuLXF'></bdo><ul id='KuLXF'></ul>
              <i id='KuLXF'><tr id='KuLXF'><dt id='KuLXF'><q id='KuLXF'><span id='KuLXF'><b id='KuLXF'><form id='KuLXF'><ins id='KuLXF'></ins><ul id='KuLXF'></ul><sub id='KuLXF'></sub></form><legend id='KuLXF'></legend><bdo id='KuLXF'><pre id='KuLXF'><center id='KuLXF'></center></pre></bdo></b><th id='KuLXF'></th></span></q></dt></tr></i><div class="tl77d7z" id='KuLXF'><tfoot id='KuLXF'></tfoot><dl id='KuLXF'><fieldset id='KuLXF'></fieldset></dl></div>

              1. 本文介紹了如何使用傳單 js 在地圖上精確放置 div 元素?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我已經(jīng)嘗試了這兩種方法,但都無法使其正常工作.我想在多個(gè)時(shí)區(qū)的地圖頂部放置時(shí)鐘.我有一個(gè) javascript 來創(chuàng)建時(shí)鐘,并將時(shí)鐘放在 div 元素中.

                這是我嘗試過的:

                1. 使用 0,0 坐標(biāo)創(chuàng)建一個(gè)點(diǎn).
                2. 從這里使用 containerPointToLatLng 獲取地圖頂部的緯度值.
                3. 使用上述 lat 和 long 作為時(shí)區(qū)創(chuàng)建 LatLng.
                4. 將此 LatLng 轉(zhuǎn)換為 Point,然后使用 x,y 從該點(diǎn)定位 div 元素.

                我在頁面第一次渲染和正文調(diào)整大小時(shí)執(zhí)行邏輯.但是,如果我更改瀏覽器窗口的大小,時(shí)鐘的位置會不正確.

                有什么建議嗎?

                解決方案

                要回答OP的精確問題,即在調(diào)整瀏覽器窗口大小時(shí)如何重新定位時(shí)鐘(因此地圖容器尺寸可能已經(jīng)改變),可能應(yīng)該只需重新計(jì)算地圖

                現(xiàn)場演示:http://plnkr.co/edit/V2pvcva5S9OZ2N7LlI8r?p=preview

                I have tried this couple of ways but have not been able to get it working. I want to place clocks at the top of the map within multiple timezones. I have a the javascript to create the clock and I place the clock in a div element.

                Here is what I tried:

                1. Create a Point with 0,0 coordinates.
                2. From this point get the latitude value for the top of the map using containerPointToLatLng.
                3. Create LatLng using the above lat and long for the timezone.
                4. Converted this LatLng to Point and then positioning the div element with the x,y from this point.

                I execute the logic both when the page is first rendered and then on body resize. However, if I change the size of the browser window, the clock does not position correctly.

                Any suggestions?

                解決方案

                To answer OP's precise issue, i.e. how to re-position the clock when the browser window is resized (hence map container dimensions may have changed), one should probably just re-compute the clock position on map's "resize" event.

                However, it is not clear whether OP placed the clock as a child of the map container, or somewhere else on the page DOM tree.

                It is probably much easier to place it as a child of the map, so that its position is always relative to the map container.

                What OP originally asked?

                If I understand correctly the original desired result, the OP would like to overlay a clock (or whatever information) on top of a particular geographical position (Toronto city in that case [UTC -5], according to comments).

                However, the information container should not lay at a basemap fixed position, i.e. not at a precise geographic coordinated point (like a marker or a popup would), but at the top of the map container, similarly to a Control (hence iH8's original answer).

                Except that it should not be totally fixed within the map container, but horizontally move with the city (or whatever specified geographical coordinates). Hence OP's comment to iH8's answer.

                Therefore it sounds like something similar to that site, except with an interactive (navigate-able) map and the "UTC-5" header replaced by a clock (or whatever information, hence an HTML container should do it) and horizontally following Toronto.

                Put differently, the clock should sit at a particular vertical line, i.e. longitude / meridian.

                Unfortunately, even 2 years and a half after the question is posted, there is still no Leaflet plugin that provides such functionality (at least within Leaflet plugins page).

                Extending the use case to highly zoomed-in map…

                That being said, and given the fact that the user may be able to zoom highly into the city (OP did not specify the maximum zoom level), it might not be a very good user experience having that clock horizontally follow a precise longitude: for example, it could track Toronto centroid / city hall / whatever particular place, and when user is zoomed-in at another city district, the clock is no longer visible, whereas he/she is still viewing a part of Toronto city…

                To extend that use case, the clock should very probably be visible in whatever area it applies, i.e. as soon as the map view port intersects the associated time zone.

                Extending the use case to highly zoomed-out map…

                Another point not detailed by OP, is what to do when places of different time zones are visible in the map view port? In the above mentioned site, we have one header per visible time zone, which seems the most complete information we can get.

                But since Leaflet allows to zoom out down to level 0, where the entire world (i.e. essentially 24 time zones / actually 39 according to Wikipedia, not including potential effect of Daylight Saving Time - DST) is represented with a 256 pixels width, there is little room to fit all these clocks, if each one must be vertically aligned with its associated time zone.

                For now let's assume we do not care if clocks overlap.

                Even more custom case…

                But OP may have wished to display the clock only for particular places, not for the entire world. OP did not even say that clocks would be different (we could have clocks for cities in the same time zone, even though it could be more interesting to have these clocks sit next to their city - even on par with their latitude, so that it is easier to spot which city the clock is associated to, like in the case of 2 cities on the same meridian; but in that case, a marker with L.divIcon would be enough).

                Hence a custom case would be not to consider official time zones, but developer's specified areas.

                So we forget about the latitude and try to align a clock vertically above the area, as long as it intersects the map view port.

                Describing a generic solution

                Therefore it sounds like a generic solution would be to enable the application developer to specify an array of HTML Elements, each one associated with a range of longitudes (could also be an area / polygon).

                The time zones use case would then be a particular case where the specified areas are simply those from the time zones.

                Then, each Element should be visible if and only if its associated area intersects the view port (therefore we introduce a possibility to hide it when the latitude range is out of view).

                As for positioning, let's choose:

                • By the top of the map container (similar to a Control), as mentioned by OP.
                • Horizontally centered within the intersection of the view port and of the associated area.

                HTML:

                <div id="map"></div>
                
                <div id="clockToronto" class="clock leaflet-control">Clock here for Toronto</div>
                <div id="clockBurlington" class="clock leaflet-control">Clock here for Burlington</div>
                

                CSS:

                .clock {
                  width: 150px;
                  text-align: center;
                  position: absolute;
                  border: 1px solid black;
                }
                
                #clockToronto {
                  background-color: yellow;
                }
                
                #clockBurlington {
                  background-color: orange;
                }
                

                JavaScript:

                var map = L.map("map").setView([43.7, -79.4], 10);
                
                // Application specific.
                var clockTorontoElement = L.DomUtil.get("clockToronto"),
                    clockBurlingtonElement = L.DomUtil.get("clockBurlington"),
                    zones = [
                      {
                        element: clockTorontoElement, // Using the HTML Element for now.
                        width: parseInt(window.getComputedStyle(clockTorontoElement, null).getPropertyValue("width"), 10),
                        area: L.latLngBounds([43.58, -79.64], [43.86, -79.10]) // Using L.latLngBounds for now.
                      },
                      {
                        element: clockBurlingtonElement, // Using the HTML Element for now.
                        width: parseInt(window.getComputedStyle(clockBurlingtonElement, null).getPropertyValue("width"), 10),
                        area: L.latLngBounds([43.28, -79.96], [43.48, -79.71]) // Using L.latLngBounds for now.
                      }
                    ];
                
                // Initialization
                var controlsContainer = map._container.getElementsByClassName("leaflet-control-container")[0],
                    firstCorner = controlsContainer.firstChild,
                    mapContainerWidth;
                
                map.on("resize", setMapContainerWidth);
                setMapContainerWidth();
                
                // Applying the zones.
                for (var i = 0; i < zones.length; i += 1) {
                  setZone(zones[i]);
                }
                
                function setZone(zoneData) {
                  // Visualize the area.
                  L.rectangle(zoneData.area).addTo(map);
                  console.log("width: " + zoneData.width);
                
                  controlsContainer.insertBefore(zoneData.element, firstCorner);
                  map.on("move resize", function () {
                    updateZone(zoneData);
                  });
                  updateZone(zoneData);
                }
                
                function updateZone(zoneData) {
                  var mapBounds = map.getBounds(),
                      zoneArea = zoneData.area,
                      style = zoneData.element.style;
                
                  if (mapBounds.intersects(zoneArea)) {
                    style.display = "block";
                
                    var hcenterLng = getIntersectionHorizontalCenter(mapBounds, zoneArea),
                        hcenter = isNaN(hcenterLng) ? 0 : map.latLngToContainerPoint([0, hcenterLng]).x;
                
                    // Update Element position.
                    // Could be refined to keep the entire Element visible, rather than cropping it.
                    style.left = (hcenter - (zoneData.width / 2)) + "px";
                  } else {
                    style.display = "none";
                  }
                }
                
                function getIntersectionHorizontalCenter(bounds1, bounds2) {
                  var west1 = bounds1.getWest(),
                      west2 = bounds2.getWest(),
                      westIn = west1 < west2 ? west2 : west1,
                      east1 = bounds1.getEast(),
                      east2 = bounds2.getEast(),
                      eastIn = east1 < east2 ? east1 : east2;
                
                  return (westIn + eastIn) / 2;
                }
                
                function setMapContainerWidth() {
                  mapContainerWidth = map.getSize().x;
                }
                

                Live demo: http://plnkr.co/edit/V2pvcva5S9OZ2N7LlI8r?p=preview

                這篇關(guān)于如何使用傳單 js 在地圖上精確放置 div 元素?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

                Check if a polygon point is inside another in leaflet(檢查一個(gè)多邊形點(diǎn)是否在傳單中的另一個(gè)內(nèi)部)
                Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標(biāo)記群集圖標(biāo)顏色,繼承其余默認(rèn) CSS 屬性)
                Trigger click on leaflet marker(觸發(fā)點(diǎn)擊傳單標(biāo)記)
                How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認(rèn)加載磁貼顏色?)
                Add external geojson to leaflet layer(將外部geojson添加到傳單層)
                Adding Leaflet layer control to sidebar(將 Leaflet 圖層控件添加到側(cè)邊欄)
                <legend id='HLNsZ'><style id='HLNsZ'><dir id='HLNsZ'><q id='HLNsZ'></q></dir></style></legend>
                  1. <i id='HLNsZ'><tr id='HLNsZ'><dt id='HLNsZ'><q id='HLNsZ'><span id='HLNsZ'><b id='HLNsZ'><form id='HLNsZ'><ins id='HLNsZ'></ins><ul id='HLNsZ'></ul><sub id='HLNsZ'></sub></form><legend id='HLNsZ'></legend><bdo id='HLNsZ'><pre id='HLNsZ'><center id='HLNsZ'></center></pre></bdo></b><th id='HLNsZ'></th></span></q></dt></tr></i><div class="bbtff7f" id='HLNsZ'><tfoot id='HLNsZ'></tfoot><dl id='HLNsZ'><fieldset id='HLNsZ'></fieldset></dl></div>

                        <bdo id='HLNsZ'></bdo><ul id='HLNsZ'></ul>

                      • <tfoot id='HLNsZ'></tfoot>
                        • <small id='HLNsZ'></small><noframes id='HLNsZ'>

                            <tbody id='HLNsZ'></tbody>
                          主站蜘蛛池模板: 合金耐磨锤头_破碎机锤头_郑州市德勤建材有限公司 | 皮带式输送机械|链板式输送机|不锈钢输送机|网带输送机械设备——青岛鸿儒机械有限公司 | 棉服定制/厂家/公司_棉袄订做/价格/费用-北京圣达信棉服 | 减速机三参数组合探头|TSM803|壁挂式氧化锆分析仪探头-安徽鹏宸电气有限公司 | 杭州公司变更法人-代理记账收费价格-公司注销代办_杭州福道财务管理咨询有限公司 | 威客电竞(vk·game)·电子竞技赛事官网 | 有机肥设备生产制造厂家,BB掺混肥搅拌机、复合肥设备生产线,有机肥料全部加工设备多少钱,对辊挤压造粒机,有机肥造粒设备 -- 郑州程翔重工机械有限公司 | 筒瓦厂家-仿古瓦-寺庙-古建琉璃瓦-宜兴市古典园林建筑陶瓷厂有限公司 | 月嫂_保姆_育婴_催乳_母婴护理_产后康复_养老护理-吉祥到家家政 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 讲师宝经纪-专业培训机构师资供应商_培训机构找讲师、培训师、讲师经纪就上讲师宝经纪 | 焊锡丝|焊锡条|无铅锡条|无铅锡丝|无铅焊锡线|低温锡膏-深圳市川崎锡业科技有限公司 | 粘度计NDJ-5S,粘度计NDJ-8S,越平水分测定仪-上海右一仪器有限公司 | 干法制粒机_智能干法制粒机_张家港市开创机械制造有限公司 | 软膜天花_软膜灯箱_首选乐创品牌_一站式天花软膜材料供应商! | 动环监控_机房环境监控_DCIM_机房漏水检测-斯特纽 | 铝机箱_铝外壳加工_铝外壳厂家_CNC散热器加工-惠州市铂源五金制品有限公司 | 上海诺狮景观规划设计有限公司| 医养体检包_公卫随访箱_慢病随访包_家签随访包_随访一体机-济南易享医疗科技有限公司 | 酒糟烘干机-豆渣烘干机-薯渣烘干机-糟渣烘干设备厂家-焦作市真节能环保设备科技有限公司 | 智慧消防-消防物联网系统云平台| 湖州织里童装_女童男童中大童装_款式多尺码全_织里儿童网【官网】-嘉兴嘉乐网络科技有限公司 | 预制围墙_工程预制围墙_天津市瑞通建筑材料有限公司 | 净化车间_洁净厂房_净化公司_净化厂房_无尘室工程_洁净工程装修|改造|施工-深圳净化公司 | 温湿度记录纸_圆盘_横河记录纸|霍尼韦尔记录仪-广州汤米斯机电设备有限公司 | 硅PU球场、篮球场地面施工「水性、环保、弹性」硅PU材料生产厂家-广东中星体育公司 | 安徽集装箱厂-合肥国彩钢结构板房工程有限公司 | 除尘器布袋骨架,除尘器滤袋,除尘器骨架,电磁脉冲阀膜片,卸灰阀,螺旋输送机-泊头市天润环保机械设备有限公司 | 升降机-高空作业车租赁-蜘蛛车-曲臂式伸缩臂剪叉式液压升降平台-脚手架-【普雷斯特公司厂家】 | 防腐储罐_塑料储罐_PE储罐厂家_淄博富邦滚塑防腐设备科技有限公司 | 盘装氧量分析仪-防爆壁挂氧化锆分析仪-安徽吉帆仪表有限公司 | 线材成型机,线材折弯机,线材成型机厂家,贝朗自动化设备有限公司1 | 新疆散热器,新疆暖气片,新疆电锅炉,光耀暖通公司 | 暴风影音 | 上海赞永| 工业冷却塔维修厂家_方形不锈钢工业凉水塔维修改造方案-广东康明节能空调有限公司 | 手术室净化厂家-成都做医院净化工程的公司-四川华锐-15年特殊科室建设经验 | 济南品牌包装设计公司_济南VI标志设计公司_山东锐尚文化传播 | 洗地机_全自动洗地机_手推式洗地机【上海滢皓环保】 | 活性炭-果壳木质煤质柱状粉状蜂窝活性炭厂家价格多少钱 | CTAB,表面活性剂1631溴型(十六烷基三甲基溴化铵)-上海升纬化工原料有限公司 | 厂厂乐-汇聚海量采购信息的B2B微营销平台-厂厂乐官网 |