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="jflzf2b" 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="nnppjao" id='KuLXF'><tfoot id='KuLXF'></tfoot><dl id='KuLXF'><fieldset id='KuLXF'></fieldset></dl></div>

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

                問題描述

                我已經嘗試了這兩種方法,但都無法使其正常工作.我想在多個時區的地圖頂部放置時鐘.我有一個 javascript 來創建時鐘,并將時鐘放在 div 元素中.

                這是我嘗試過的:

                1. 使用 0,0 坐標創建一個點.
                2. 從這里使用 containerPointToLatLng 獲取地圖頂部的緯度值.
                3. 使用上述 lat 和 long 作為時區創建 LatLng.
                4. 將此 LatLng 轉換為 Point,然后使用 x,y 從該點定位 div 元素.

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

                有什么建議嗎?

                解決方案

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

                現場演示: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

                這篇關于如何使用傳單 js 在地圖上精確放置 div 元素?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 屬性)
                Trigger click on leaflet marker(觸發點擊傳單標記)
                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 圖層控件添加到側邊欄)
                <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="ng33rog" 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>
                          主站蜘蛛池模板: 合肥礼品公司-合肥礼品定制-商务礼品定制公司-安徽柏榽商贸有限公司 | 安规电容|薄膜电容|陶瓷电容|智旭JEC安规电容厂家 | 招商帮-一站式网络营销服务|互联网整合营销|网络推广代运营|信息流推广|招商帮企业招商好帮手|搜索营销推广|短视视频营销推广 | 行业分析:提及郑州火车站附近真有 特殊按摩 ?2025实地踩坑指南 新手如何避坑不踩雷 | 带压开孔_带压堵漏_带压封堵-菏泽金升管道工程有限公司 | 全自动包装秤_全自动上袋机_全自动套袋机_高位码垛机_全自动包装码垛系统生产线-三维汉界机器(山东)股份有限公司 | IIS7站长之家-站长工具-爱网站请使用IIS7站长综合查询工具,中国站长【WWW.IIS7.COM】 | 武汉EPS线条_EPS装饰线条_EPS构件_湖北博欧EPS线条厂家 | 电镀标牌_电铸标牌_金属标贴_不锈钢标牌厂家_深圳市宝利丰精密科技有限公司 | 灰板纸、灰底白、硬纸板等纸品生产商-金泊纸业 | 卓能JOINTLEAN端子连接器厂家-专业提供PCB接线端子|轨道式端子|重载连接器|欧式连接器等电气连接产品和服务 | PC阳光板-PC耐力板-阳光板雨棚-耐力板雨棚,厂家定制[优尼科板材] | 冷热冲击试验箱_温度冲击试验箱价格_冷热冲击箱排名_林频厂家 | 济南轻型钢结构/济南铁艺护栏/济南铁艺大门-济南燕翔铁艺制品有限公司 | 阳光模拟试验箱_高低温试验箱_高低温冲击试验箱_快速温变试验箱|东莞市赛思检测设备有限公司 | 14米地磅厂家价价格,150吨地磅厂家价格-百科 | PC阳光板-PC耐力板-阳光板雨棚-耐力板雨棚,厂家定制[优尼科板材] | 紫外线老化试验箱_uv紫外线老化试验箱价格|型号|厂家-正航仪器设备 | 广州企亚 - 数码直喷、白墨印花、源头厂家、透气无手感方案服务商! | 河南橡胶接头厂家,河南波纹补偿器厂家,河南可曲挠橡胶软连接,河南套筒补偿器厂家-河南正大阀门 | 重庆磨床过滤机,重庆纸带过滤机,机床伸缩钣金,重庆机床钣金护罩-重庆达鸿兴精密机械制造有限公司 | 密集柜_档案密集柜_智能密集架_密集柜厂家_密集架价格-智英伟业 密集架-密集柜厂家-智能档案密集架-自动选层柜订做-河北风顺金属制品有限公司 | 不锈钢管件(不锈钢弯头,不锈钢三通,不锈钢大小头),不锈钢法兰「厂家」-浙江志通管阀 | 上海公众号开发-公众号代运营公司-做公众号的公司企业服务商-咏熠软件 | 厂房出售_厂房仓库出租_写字楼招租_土地出售-中苣招商网-中苣招商网 | 滚筒烘干机_转筒烘干机_滚筒干燥机_转筒干燥机_回转烘干机_回转干燥机-设备生产厂家 | 建筑消防设施检测系统检测箱-电梯**检测仪器箱-北京宇成伟业科技有限责任公司 | 超高频感应加热设备_高频感应电源厂家_CCD视觉检测设备_振动盘视觉检测设备_深圳雨滴科技-深圳市雨滴科技有限公司 | 工业冷却塔维修厂家_方形不锈钢工业凉水塔维修改造方案-广东康明节能空调有限公司 | 洁净化验室净化工程_成都实验室装修设计施工_四川华锐净化公司 | 微水泥_硅藻泥_艺术涂料_艺术漆_艺术漆加盟-青岛泥之韵环保壁材 武汉EPS线条_EPS装饰线条_EPS构件_湖北博欧EPS线条厂家 | 断桥铝破碎机_铝合金破碎机_废铁金属破碎机-河南鑫世昌机械制造有限公司 | 浙江栓钉_焊钉_剪力钉厂家批发_杭州八建五金制造有限公司 | 工业冷却塔维修厂家_方形不锈钢工业凉水塔维修改造方案-广东康明节能空调有限公司 | 锂电池砂磨机|石墨烯砂磨机|碳纳米管砂磨机-常州市奥能达机械设备有限公司 | 翰墨AI智能写作助手官网_人工智能问答在线AI写作免费一键生成 | 气体检测仪-氢气检测仪-可燃气体传感器-恶臭电子鼻-深国安电子 | 动物麻醉机-数显脑立体定位仪-北京易则佳科技有限公司 | 宿舍管理系统_智慧园区系统_房屋/房产管理系统_公寓管理系统 | 锥形螺带干燥机(新型耙式干燥机)百科-常州丰能干燥工程 | 杭州用友|用友软件|用友财务软件|用友ERP系统--杭州协友软件官网 |