日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【Leafletjs】4.L.Map 中文API

發(fā)布時間:2025/3/21 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Leafletjs】4.L.Map 中文API 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

L.Map

API各種類中的核心部分,用來在頁面中創(chuàng)建地圖并操縱地圖.

使用 example

// initialize the map on the "map" div with a given center and zoom var map = L.map('map', {center: [51.505, -0.09],zoom: 13 });

構(gòu)造器

構(gòu)造器使用描述
L.Map( <HTMLElement|String> id, <Map options> options? ) new L.Map()
L.map()
通過div元素和帶有地圖選項的描述的文字對象來實例化一個地圖對象,其中文字對象是可選的。

Options

Map State Options

選項類型默認(rèn)值描述
centerLatLngnull初始化地圖的地理中心.
zoomNumbernull初始化地圖的縮放.
layersILayer[]null初始化后加載到地圖上的圖層.
minZoomNumbernull地圖的最小視圖。可以重寫地圖圖層的minZoom.
maxZoomNumbernull地圖的最大視圖。可以重寫地圖圖層的maxZoom.
maxBoundsLatLngBoundsnull當(dāng)這個選項被設(shè)置后,地圖被限制在給定的地理邊界內(nèi),當(dāng)用戶平移將地圖拖動到視圖以外的范圍時會出現(xiàn)彈回的效果, 并且也不允許縮小視圖到給定范圍以外的區(qū)域(這取決于地圖的尺寸)。 使用setMaxBounds方法可以動態(tài)地設(shè)置這種約束.
crsCRSL.CRS.
EPSG3857
使用的坐標(biāo)系,當(dāng)你不確定坐標(biāo)系是什么時請不要更改.

Interaction Options

選項類型默認(rèn)值描述
draggingBooleantrue決定地圖是否可被鼠標(biāo)或觸摸拖動.
touchZoomBooleantrue決定地圖是否可被兩只手指觸摸拖拽縮放.
scrollWheelZoomBooleantrue決定地圖是否被被鼠標(biāo)滾輪滾動縮放.
doubleClickZoomBooleantrue決定地圖是否可被雙擊縮放.
boxZoomBooleantrue決定地圖是否可被縮放到鼠標(biāo)拖拽出的矩形的視圖,鼠標(biāo)拖拽時需要同時按住shift鍵.
tapBooleantrueEnables mobile hacks for supporting instant taps (fixing 200ms click delay on iOS/Android) and touch holds (fired as contextmenu events).
tapToleranceNumber15The max number of pixels a user can shift his finger during touch for it to be considered a valid tap.
trackResizeBooleantrue確定地圖在窗口尺寸改變時是否可以自動處理瀏覽器以更新視圖.
worldCopyJumpBooleanfalse當(dāng)這個選項可用時,當(dāng)你平移地圖到其另一個領(lǐng)域時會被地圖捕獲到,并無縫地跳轉(zhuǎn)到原始的領(lǐng)域以保證所有標(biāo)注、矢量圖層之類的覆蓋物仍然可見.
closePopupOnClickBooleantrue當(dāng)你不想用戶點擊地圖關(guān)閉消息彈出框時,請將其設(shè)置為false .

Keyboard Navigation Options

選項類型默認(rèn)值描述
keyboardBooleantrue聚焦到地圖且允許用戶通過鍵盤的方向鍵和+/-鍵來漫游地圖.
keyboardPanOffsetNumber80確定按鍵盤方向鍵時地圖平移的像素.
keyboardZoomOffsetNumber1確定鍵盤+ or -鍵對于的縮放級數(shù).

Panning Inertia Options

選項類型默認(rèn)值描述
inertiaBooleantrue如果該選項可用,在拖動和在某一時間段內(nèi)持續(xù)朝同一方向移動建有動力的地圖時,會有慣性的效果.
inertiaDecelerationNumber3000確定慣性移動減速的速率,單位是像素每秒的二次方2.
inertiaMaxSpeedNumber1500慣性移動的最大速度,單位是像素每秒.
inertiaThresholdNumberdepends放開鼠標(biāo)或是觸摸來停止慣性移動與移動停止之間的毫秒數(shù).

Control options

選項類型默認(rèn)值描述
zoomControlBooleantrue確定zoom control是否默認(rèn)加載在地圖上 .
attributionControlBooleantrue確定attribution control是否默認(rèn)加載在地圖上.

Animation options

選項類型默認(rèn)值描述
fadeAnimationBooleandepends確定瓦片淡出動畫是否可用。通常默認(rèn)在所有瀏覽器中都支持CSS3轉(zhuǎn)場,android例外.
zoomAnimationBooleandepends確定瓦片縮放動畫是否可用。通常默認(rèn)在所有瀏覽器中都支持CSS3轉(zhuǎn)場,android例外.
zoomAnimationThresholdNumber4Won't animate zoom if the zoom difference exceeds this value.
markerZoomAnimationBooleandepends確定注記的縮放是否隨地圖縮放動畫而播放,如果被禁用,注記在動畫中拉長時會消失。通常默認(rèn)在所有瀏覽器中都支持CSS3轉(zhuǎn)場,android例外.

Events

You can subscribe to the following events using these methods.

EventData描述
clickMouseEvent用戶點擊或觸摸地圖時觸發(fā).
dblclickMouseEvent用戶雙擊或連續(xù)兩次觸摸地圖時觸發(fā).
mousedownMouseEvent用戶按下鼠標(biāo)按鍵時觸發(fā).
mouseupMouseEvent用戶按下鼠標(biāo)按鍵時觸發(fā).
mouseoverMouseEvent鼠標(biāo)進入地圖時觸發(fā).
mouseoutMouseEvent鼠標(biāo)離開地圖時觸發(fā).
mousemoveMouseEvent鼠標(biāo)在地圖上移動時觸發(fā).
contextmenuMouseEvent當(dāng)用戶在地圖上按下鼠標(biāo)右鍵時觸發(fā),如果有監(jiān)聽器在監(jiān)聽這個時間,則瀏覽器默認(rèn)的情景菜單被禁用.
focusEvent當(dāng)用戶在地圖上進行標(biāo)引、點擊或移動時進行聚焦.
blurEvent當(dāng)?shù)貓D失去焦點時觸發(fā).
preclickMouseEvent當(dāng)鼠標(biāo)在地圖上點擊之前觸發(fā)。有時會在點擊鼠標(biāo)時,并在已存在的點擊事件開始處理之前想要某件事情發(fā)生時用得到.
loadEvent當(dāng)?shù)貓D初始化時觸發(fā)。(當(dāng)?shù)貓D的中心點和縮放初次設(shè)置時).
unloadEventFired when the map is destroyed with remove method.
viewresetEvent當(dāng)?shù)貓D需要重繪內(nèi)容時觸發(fā)。(通常在地圖縮放和載入時發(fā)生)這對于創(chuàng)建用戶自定義的疊置圖層非常有用.
movestartEvent地圖視圖開始改變時觸發(fā)。(比如用戶開始拖動地圖).
moveEvent所有的地圖視圖移動時觸發(fā).
moveendEvent當(dāng)?shù)貓D視圖結(jié)束改變時觸發(fā)。(比如用戶停止拖動地圖).
dragstartEvent用戶開始拖動地圖時觸發(fā).
dragEvent用戶拖動地圖時不斷重復(fù)地觸發(fā).
dragendEvent用戶停止拖動時觸發(fā).
zoomstartEvent當(dāng)?shù)貓D縮放即將發(fā)生時觸發(fā)。(比如縮放動作開始前).
zoomendEvent當(dāng)?shù)貓D縮放時觸發(fā).
zoomlevelschangeEventFired when the number of zoomlevels on the map is changed due to adding or removing a layer.
resizeResizeEventFired when the map is resized.
autopanstartEvent打開彈出窗口時地圖開始自動平移時觸發(fā).
layeraddLayerEvent當(dāng)一個新的圖層添加到地圖上時觸發(fā).
layerremoveLayerEvent當(dāng)一些圖層從地圖上移除時觸發(fā).
baselayerchangeLayerEvent 當(dāng)通過layer control改變基礎(chǔ)圖層時觸發(fā).
overlayaddLayerEvent Fired when an overlay is selected through the layer control.
overlayremoveLayerEvent Fired when an overlay is deselected through the layer control.
locationfoundLocationEvent 當(dāng)?shù)乩韺ぶ烦晒r觸發(fā)(使用locate方法)
locationerrorErrorEvent 當(dāng)?shù)乩韺ぶ峰e誤時觸發(fā)(使用locate方法)
popupopenPopupEvent當(dāng)彈出框打開時觸發(fā)(使用openPopup方法)
popupclosePopupEvent當(dāng)彈出框關(guān)閉時觸發(fā)(使用closePopup方法)

地圖狀態(tài)修改

方法返回值描述
setView( <LatLng> center, <Number> zoom, <zoom/pan options> options? ) this設(shè)定地圖(設(shè)定其地理中心和縮放).
setZoom( <Number> zoom, <zoom options> options? ) this設(shè)定地圖的縮放.
zoomIn( <Number> delta?, <zoom options> options? ) this通過delta變量放大地圖的級別,1是delta的默認(rèn)值.
zoomOut( <Number> delta?, <zoom options> options? ) this通過delta變量縮小地圖的級別,1是delta的默認(rèn)值.
setZoomAround( <LatLng> latlng, <Number> zoom, <zoom options> options? ) thisZooms the map while keeping a specified point on the map stationary (e.g. used internally for scroll zoom and double-click zoom).
fitBounds( <LatLngBounds> bounds, <fitBounds options> options? ) this將地圖視圖盡可能大地設(shè)定在給定的地理邊界內(nèi).
fitWorld( <fitBounds options> options? ) this將地圖視圖盡可能大地設(shè)定在包含全部地域的級別上.
panTo( <LatLng> latlng, <pan options> options? ) this將地圖平移到給定的中心。如果新的中心點在屏幕內(nèi)與現(xiàn)有的中心點不同則產(chǎn)生平移動作.
panInsideBounds( <LatLngBounds> bounds ) this平移地圖到坐落于給定邊界最接近的視圖內(nèi).
panBy( <Point> point, <pan options> options? ) this通過給定的像素值對地圖進行平移.
invalidateSize( <Boolean> options?, <zoom/pan options> options? ) this檢查地圖容器的大小是否改變并更新地圖,如果是這樣的話,在動態(tài)改變地圖大小后調(diào)用,如果animate是true的話,對地圖進行更新.
setMaxBounds( <LatLngBounds> bounds, <zoom/pan options> options? ) this將地圖限定在給定的邊界內(nèi) (map maxBounds).
locate( <Locate options> options? ) this用地理定位接口Geolocation API獲取用戶位置信息,在成功定位或定位出錯產(chǎn)生locationerror后解除location-found事件與定位數(shù)據(jù),且將地圖視圖設(shè)定到檢測的確切的用戶的位置(如果定位失敗則回到地域視圖)。在Locate options中有更多詳細(xì)內(nèi)容。
stopLocate()thisStops watching location previously initiated by map.locate({watch: true}) and aborts resetting the map view if map.locate was called with {setView: true}.
remove()thisDestroys the map and clears all related event listeners.

獲取地圖狀態(tài)

方法返回值描述
getCenter()LatLng返回地圖視圖的地理中心.
getZoom()Number獲取地圖視圖現(xiàn)在所處的縮放級別.
getMinZoom()Number返回地圖最小的縮放級別.
getMaxZoom()Number返回地圖最大的縮放級別.
getBounds()LatLngBounds返回地圖視圖的經(jīng)緯度邊界.
getBoundsZoom( <LatLngBounds> bounds, <Boolean> inside? ) Number返回適應(yīng)整個地圖視圖邊界的最大縮放級別。如果inside的設(shè)置時true,這個方法返回適應(yīng)整個地圖視圖邊界的最小縮放級別.
getSize()Point返回現(xiàn)有地圖容器的大小.
getPixelBounds()Bounds返回地圖視圖在像素投影坐標(biāo)系下的邊界。(很多時候?qū)τ脩糇远x圖層和疊加很有用).
getPixelOrigin()Point返回地圖圖層像素投影坐標(biāo)系下的左上角的點。(很多時候?qū)τ脩糇远x圖層和疊加很有用).

圖層控制/h3>

方法返回值描述
addLayer( <ILayer> layer, <Boolean> insertAtTheBottom? ) this將圖層添加到地圖上。如果insertAtTheBottom的選項為true,圖層添加時在所以圖層之下。(在切換基底圖時比較有用).
removeLayer( <ILayer> layer ) this將圖層在地圖上移除.
hasLayer( <ILayer> layer ) Boolean如果添加的圖層是當(dāng)前圖層則返回true.
openPopup( <Popup> popup ) this當(dāng)關(guān)閉前一個彈出框時彈出指定的對話框。(確定在同一時間只有一個打開并可用).
openPopup( <String> html | <HTMLElement> el, <LatLng> latlng, <Popup options> options? ) thisCreates a popup with the specified options and opens it in the given point on a map.
closePopup( <Popup> popup? ) this關(guān)閉openPopup打開的彈出框.
addControl( <IControl> control ) this在地圖上添加控制選項.
removeControl( <IControl> control ) this在地圖上移除控制選項.

轉(zhuǎn)換方法

方法返回值描述
latLngToLayerPoint( <LatLng> latlng ) Point返回地圖圖層上與地理坐標(biāo)相一致的點。(在地圖上進行位置疊加時比較有用).
layerPointToLatLng( <Point> point ) LatLng返回給定地圖上點的地理坐標(biāo)系.
containerPointToLayerPoint( <Point> point ) Point將于地圖容器相關(guān)的點轉(zhuǎn)換為地圖圖層相關(guān)的點.
layerPointToContainerPoint( <Point> point ) Point將地圖圖層相關(guān)的點轉(zhuǎn)換為地圖容器相關(guān)的點.
latLngToContainerPoint( <LatLng> latlng ) Point返回與給定地理坐標(biāo)系相符的地圖容器的點.
containerPointToLatLng( <Point> point ) LatLng返回給定地理容器點的地理坐標(biāo).
project( <LatLng> latlng, <Number> zoom? ) Point將地理坐標(biāo)投影到指定縮放級別的像素坐標(biāo)系中.
unproject( <Point> point, <Number> zoom? ) LatLng將像素坐標(biāo)系投影到指定縮放級別的地理坐標(biāo)系中。(默認(rèn)為當(dāng)前的縮放級別).
mouseEventToContainerPoint( <MouseEvent> event ) Point返回鼠標(biāo)點擊事件對象的像素坐標(biāo)(與地圖左上角相關(guān)).
mouseEventToLayerPoint( <MouseEvent> event ) Point返回鼠標(biāo)點擊事件對象的像素坐標(biāo)(與地圖圖層相關(guān)).
mouseEventToLatLng( <MouseEvent> event ) LatLng返回鼠標(biāo)點擊事件對象的地理坐標(biāo).

其他方法

方法返回值描述
getContainer()HTMLElement返回地圖容器對象.
getPanes()MapPanes返回不同地圖對象的邊框(疊加渲染).
whenReady( <Function> fn, <Object> context? )this當(dāng)?shù)貓D的位置和縮放初始化好或是時間發(fā)生之后,運行給定的回調(diào)方法,通常傳遞一個函數(shù)內(nèi)容.

位置選項

選項類型默認(rèn)值描述
watchBooleanfalse如果該值為真,則開始利用W3C的watchPosition方法監(jiān)聽位置變化情況(而不是指監(jiān)聽一次)。你可以通過map.stoplocate()方法來停止監(jiān)聽.
setViewBooleanfalse如果該值為真,則通過自動將地圖視圖定位到用戶一定精度范圍內(nèi)的位置,如果地理定位失敗則顯示全部地圖.
maxZoomNumberInfinity在使用setView選項時視圖縮放的最大級別.
timeoutNumber10000在觸發(fā)locationerror事件之前等待地理定位的毫秒為單位的時間.
maximumAgeNumber0位置監(jiān)聽的最大生命周期。如果比最后定位回復(fù)后毫秒用時短,則locate返回一個緩存位置.
enableHighAccuracyBooleanfalse開啟高精度,參加 W3C SPEC的描述.

Zoom/pan options

選項類型默認(rèn)值描述
resetBooleanfalseIf true, the map view will be completely reset (without any animations).
panpan options-Sets the options for the panning (without the zoom change) if it occurs.
zoomzoom options-Sets the options for the zoom change if it occurs.
animateBoolean-An equivalent of passing animate to both zoom and pan options (see below).

Pan options

選項類型默認(rèn)值描述
animateBoolean-If true, panning will always be animated if possible. If false, it will not animate panning, either resetting the map view if panning more than a screen away, or just setting a new offset for the map pane (except for `panBy` which always does the latter).
durationNumber0.25Duration of animated panning.
easeLinearityNumber0.25The curvature factor of panning animation easing (third parameter of the Cubic Bezier curve). 1.0 means linear animation, the less the more bowed the curve.
noMoveStartBooleanfalseIf true, panning won't fire movestart event on start (used internally for panning inertia).

Zoom options

選項類型默認(rèn)值描述
animateBoolean-If not specified, zoom animation will happen if the zoom origin is inside the current view. If true, the map will attempt animating zoom disregarding where zoom origin is. Setting false will make it always reset the view completely without animation.

fitBounds options

The same as zoom/pan options and additionally:

選項類型默認(rèn)值描述
paddingTopLeftPoint[0, 0]Sets the amount of padding in the top left corner of a map container that shouldn't be accounted for when setting the view to fit bounds. Useful if you have some control overlays on the map like a sidebar and you don't want them to obscure objects you're zooming to.
paddingBottomRightPoint[0, 0]The same for bottom right corner of the map.
paddingPoint[0, 0]Equivalent of setting both top left and bottom right padding to the same value.

Properties

M地圖屬性包括互動操作,允許你在運行環(huán)境中互動地控制地圖行為,比如通過拖拽和點擊縮放級別顯示和不顯示某要素. Example:

map.doubleClickZoom.disable();

You can also access default map controls like attribution control through map properties:

map.attributionControl.addAttribution("Earthquake data &copy; GeoNames"); Property類型描述
draggingIHandler地圖拖拽處理程序,可以通過鼠標(biāo)和觸摸的形式.
touchZoomIHandler觸摸地圖縮放處理程序.
doubleClickZoomIHandler雙擊縮放處理程序.
scrollWheelZoomIHandler滾動縮放處理程序.
boxZoomIHandler矩形框(利用鼠標(biāo)拖動)縮放處理程序.
keyboardIHandler鍵盤導(dǎo)向處理程序.
tapIHandlerMobile touch hacks (quick tap and touch hold) handler.
zoomControlControl.Zoom縮放控制.
attributionControlControl.Attribution屬性控制.

地圖窗口

望文思義,這是一個包括可以用來放置自定義圖層的不同的地圖窗口的對象。最大的區(qū)別是圖層的疊置.

Property類型描述
mapPaneHTMLElement包含其他地圖窗口的窗口.
tilePaneHTMLElement切片圖層的窗口.
objectsPaneHTMLElement包含除切片窗口以外所有窗口的窗口.
shadowPaneHTMLElement用來隱藏圖層的窗口(如標(biāo)注的隱藏).
overlayPaneHTMLElement這線段和多邊形一類圖層的窗口.
markerPaneHTMLElement標(biāo)注圖標(biāo)的窗口.
popupPaneHTMLElement彈出的窗口.

轉(zhuǎn)載于:https://www.cnblogs.com/shitao/p/3566598.html

總結(jié)

以上是生活随笔為你收集整理的【Leafletjs】4.L.Map 中文API的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。