当前位置:   article > 正文

地图插件 vue2-leaflet

vue2-leaflet
  1. 安装使用
    1. 安装命令
      1. npm install leaflet vue2-leaflet --save
      2. // 或者
      3. yarn add leaflet vue2-leaflet

    2. 使用
      1. // 重点 重点 重点,千万别忘记引入样式,否则地图显示错位
      2. import 'leaflet/dist/leaflet.css';
      3. // 引入想要使用的组件
      4. import { LMap, LTileLayer, LMarker } from 'vue2-leaflet';
      5. export default {
      6. name: 'MyAwesomeMap',
      7. components: {
      8. LMap,
      9. LTileLayer,
      10. LMarker,
      11. },
      12. };

      注意: vue2-leaflet 是对leaflet的封装,在vue项目中可以直接使用vue2-leaflet,但是需要同时安装两个依赖
      vue2-leaflet的官网地址
      leaflet官网地址

  2. 常用插件
    1. Base
      1. l-map  API各种类中的核心部分,用来在页面中创建地图并操纵地图
        1. Props
          Prop nameDescriptionTypeValuesDefault
          optionsLeaflet options to pass to the component constructor
          (传递参数给组件构造函数)
          object-{}
          centerThe center of the map, supports .sync modifier
          (地图的中心点)
          object|array-() => [0, 0]
          boundsThe bounds of the map, supports .sync modifier
          (地图的边界)
          array|object-null
          maxBoundsThe max bounds of the map
          (地图的最大边界)
          array|object-null
          zoomThe zoom of the map, supports .sync modifier
          (地图的缩放)
          number-0
          minZoomThe minZoom of the map
          (地图的最大缩放)
          number-null
          maxZoomThe maxZoom of the map
          (地图的最小缩放)
          number-null
          paddingBottomRightThe paddingBottomRight of the map
          (地图的右下角)
          array-null
          paddingTopLeftThe paddingTopLeft of the map
          (地图左上角)
          array-null
          paddingThe padding of the map
          (地图内部填充)
          array-null
          worldCopyJumpThe worldCopyJump option for the map
          (地图的世界复制跳转选项)
          boolean-false
          crsThe crs option for the map
          (地图的crs选项)
          objectCRS.EPSG3857() => CRS.EPSG3857
          maxBoundsViscositynumber-null
          inertiaboolean-null
          inertiaDecelerationnumber-null
          inertiaMaxSpeednumber-null
          easeLinearitynumber-null
          zoomAnimationboolean-null
          zoomAnimationThresholdnumber-null
          fadeAnimationboolean-null
          markerZoomAnimationboolean-null
          noBlockingAnimationsboolean-false
        2. Events

          Event nameTypeDescription
          leaflet:loadDEPRECATED event
          readyobjectTriggers when the component is ready
          update:zoomnumber,stringTriggers when zoom is updated
          update:centerobject,arrayTriggers when center is updated
          update:boundsobjectTriggers when bounds are updated
        3. leaflet 中文API

          L.Map

          API各种类中的核心部分,用来在页面中创建地图并操纵地图.

          使用 example

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

          构造器

          构造器使用描述
          L.Map( <HTMLElement|String> id, <Map options> options? )new L.Map(…)
          L.map(…)
          通过div元素和带有地图选项的描述的文字对象来实例化一个地图对象,其中文字对象是可选的。

          Options

          Map State Options

          选项类型默认值描述
          centerLatLngnull初始化地图的地理中心.
          zoomNumbernull初始化地图的缩放.
          layersILayer[]null初始化后加载到地图上的图层.
          minZoomNumbernull地图的最小视图。可以重写地图图层的minZoom.
          maxZoomNumbernull地图的最大视图。可以重写地图图层的maxZoom.
          maxBoundsLatLngBoundsnull当这个选项被设置后,地图被限制在给定的地理边界内,当用户平移将地图拖动到视图以外的范围时会出现弹回的效果, 并且也不允许缩小视图到给定范围以外的区域(这取决于地图的尺寸)。 使用setMaxBounds方法可以动态地设置这种约束.
          crsCRSL.CRS.
          EPSG3857
          使用的坐标系,当你不确定坐标系是什么时请不要更改.

          Interaction Options

          选项类型默认值描述
          draggingBooleantrue决定地图是否可被鼠标或触摸拖动.
          touchZoomBooleantrue决定地图是否可被两只手指触摸拖拽缩放.
          scrollWheelZoomBooleantrue决定地图是否被被鼠标滚轮滚动缩放.
          doubleClickZoomBooleantrue决定地图是否可被双击缩放.
          boxZoomBooleantrue决定地图是否可被缩放到鼠标拖拽出的矩形的视图,鼠标拖拽时需要同时按住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当这个选项可用时,当你平移地图到其另一个领域时会被地图捕获到,并无缝地跳转到原始的领域以保证所有标注、矢量图层之类的覆盖物仍然可见.
          closePopupOnClickBooleantrue当你不想用户点击地图关闭消息弹出框时,请将其设置为false .

          Keyboard Navigation Options

          选项类型默认值描述
          keyboardBooleantrue聚焦到地图且允许用户通过键盘的方向键和+/-键来漫游地图.
          keyboardPanOffsetNumber80确定按键盘方向键时地图平移的像素.
          keyboardZoomOffsetNumber1确定键盘+ or -键对于的缩放级数.

          Panning Inertia Options

          选项类型默认值描述
          inertiaBooleantrue如果该选项可用,在拖动和在某一时间段内持续朝同一方向移动建有动力的地图时,会有惯性的效果.
          inertiaDecelerationNumber3000确定惯性移动减速的速率,单位是像素每秒的二次方2.
          inertiaMaxSpeedNumber1500惯性移动的最大速度,单位是像素每秒.
          inertiaThresholdNumberdepends放开鼠标或是触摸来停止惯性移动与移动停止之间的毫秒数.

          Control options

          选项类型默认值描述
          zoomControlBooleantrue确定zoom control是否默认加载在地图上 .
          attributionControlBooleantrue确定attribution control是否默认加载在地图上.

          Animation options

          选项类型默认值描述
          fadeAnimationBooleandepends确定瓦片淡出动画是否可用。通常默认在所有浏览器中都支持CSS3转场,android例外.
          zoomAnimationBooleandepends确定瓦片缩放动画是否可用。通常默认在所有浏览器中都支持CSS3转场,android例外.
          zoomAnimationThresholdNumber4Won't animate zoom if the zoom difference exceeds this value.
          markerZoomAnimationBooleandepends确定注记的缩放是否随地图缩放动画而播放,如果被禁用,注记在动画中拉长时会消失。通常默认在所有浏览器中都支持CSS3转场,android例外.

          Events

          You can subscribe to the following events using these methods.

          EventData描述
          clickMouseEvent用户点击或触摸地图时触发.
          dblclickMouseEvent用户双击或连续两次触摸地图时触发.
          mousedownMouseEvent用户按下鼠标按键时触发.
          mouseupMouseEvent用户按下鼠标按键时触发.
          mouseoverMouseEvent鼠标进入地图时触发.
          mouseoutMouseEvent鼠标离开地图时触发.
          mousemoveMouseEvent鼠标在地图上移动时触发.
          contextmenuMouseEvent当用户在地图上按下鼠标右键时触发,如果有监听器在监听这个时间,则浏览器默认的情景菜单被禁用.
          focusEvent当用户在地图上进行标引、点击或移动时进行聚焦.
          blurEvent当地图失去焦点时触发.
          preclickMouseEvent当鼠标在地图上点击之前触发。有时会在点击鼠标时,并在已存在的点击事件开始处理之前想要某件事情发生时用得到.
          loadEvent当地图初始化时触发。(当地图的中心点和缩放初次设置时).
          unloadEventFired when the map is destroyed with remove method.
          viewresetEvent当地图需要重绘内容时触发。(通常在地图缩放和载入时发生)这对于创建用户自定义的叠置图层非常有用.
          movestartEvent地图视图开始改变时触发。(比如用户开始拖动地图).
          moveEvent所有的地图视图移动时触发.
          moveendEvent当地图视图结束改变时触发。(比如用户停止拖动地图).
          dragstartEvent用户开始拖动地图时触发.
          dragEvent用户拖动地图时不断重复地触发.
          dragendEvent用户停止拖动时触发.
          zoomstartEvent当地图缩放即将发生时触发。(比如缩放动作开始前).
          zoomendEvent当地图缩放时触发.
          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打开弹出窗口时地图开始自动平移时触发.
          layeraddLayerEvent当一个新的图层添加到地图上时触发.
          layerremoveLayerEvent当一些图层从地图上移除时触发.
          baselayerchangeLayerEvent当通过layer control改变基础图层时触发.
          overlayaddLayerEventFired when an overlay is selected through the layer control.
          overlayremoveLayerEventFired when an overlay is deselected through the layer control.
          locationfoundLocationEvent当地理寻址成功时触发(使用locate方法)
          locationerrorErrorEvent当地理寻址错误时触发(使用locate方法)
          popupopenPopupEvent当弹出框打开时触发(使用openPopup方法)
          popupclosePopupEvent当弹出框关闭时触发(使用closePopup方法)

          地图状态修改

          方法返回值描述
          setView( <LatLng> center, <Number> zoom, <zoom/pan options> options? )this设定地图(设定其地理中心和缩放).
          setZoom( <Number> zoom, <zoom options> options? )this设定地图的缩放.
          zoomIn( <Number> delta?, <zoom options> options? )this通过delta变量放大地图的级别,1是delta的默认值.
          zoomOut( <Number> delta?, <zoom options> options? )this通过delta变量缩小地图的级别,1是delta的默认值.
          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将地图视图尽可能大地设定在给定的地理边界内.
          fitWorld( <fitBounds options> options? )this将地图视图尽可能大地设定在包含全部地域的级别上.
          panTo( <LatLng> latlng, <pan options> options? )this将地图平移到给定的中心。如果新的中心点在屏幕内与现有的中心点不同则产生平移动作.
          panInsideBounds( <LatLngBounds> bounds )this平移地图到坐落于给定边界最接近的视图内.
          panBy( <Point> point, <pan options> options? )this通过给定的像素值对地图进行平移.
          invalidateSize( <Boolean> options?, <zoom/pan options> options? )this检查地图容器的大小是否改变并更新地图,如果是这样的话,在动态改变地图大小后调用,如果animate是true的话,对地图进行更新.
          setMaxBounds( <LatLngBounds> bounds, <zoom/pan options> options? )this将地图限定在给定的边界内 (map maxBounds).
          locate( <Locate options> options? )this用地理定位接口Geolocation API获取用户位置信息,在成功定位或定位出错产生locationerror后解除location-found事件与定位数据,且将地图视图设定到检测的确切的用户的位置(如果定位失败则回到地域视图)。在Locate options中有更多详细内容。
          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.

          获取地图状态

          方法返回值描述
          getCenter()LatLng返回地图视图的地理中心.
          getZoom()Number获取地图视图现在所处的缩放级别.
          getMinZoom()Number返回地图最小的缩放级别.
          getMaxZoom()Number返回地图最大的缩放级别.
          getBounds()LatLngBounds返回地图视图的经纬度边界.
          getBoundsZoom( <LatLngBounds> bounds, <Boolean> inside? )Number返回适应整个地图视图边界的最大缩放级别。如果inside的设置时true,这个方法返回适应整个地图视图边界的最小缩放级别.
          getSize()Point返回现有地图容器的大小.
          getPixelBounds()Bounds返回地图视图在像素投影坐标系下的边界。(很多时候对用户自定义图层和叠加很有用).
          getPixelOrigin()Point返回地图图层像素投影坐标系下的左上角的点。(很多时候对用户自定义图层和叠加很有用).

          图层控制/h3>

          方法返回值描述
          addLayer( <ILayer> layer, <Boolean> insertAtTheBottom? )this将图层添加到地图上。如果insertAtTheBottom的选项为true,图层添加时在所以图层之下。(在切换基底图时比较有用).
          removeLayer( <ILayer> layer )this将图层在地图上移除.
          hasLayer( <ILayer> layer )Boolean如果添加的图层是当前图层则返回true.
          openPopup( <Popup> popup )this当关闭前一个弹出框时弹出指定的对话框。(确定在同一时间只有一个打开并可用).
          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关闭openPopup打开的弹出框.
          addControl( <IControl> control )this在地图上添加控制选项.
          removeControl( <IControl> control )this在地图上移除控制选项.

          转换方法

          方法返回值描述
          latLngToLayerPoint( <LatLng> latlng )Point返回地图图层上与地理坐标相一致的点。(在地图上进行位置叠加时比较有用).
          layerPointToLatLng( <Point> point )LatLng返回给定地图上点的地理坐标系.
          containerPointToLayerPoint( <Point> point )Point将于地图容器相关的点转换为地图图层相关的点.
          layerPointToContainerPoint( <Point> point )Point将地图图层相关的点转换为地图容器相关的点.
          latLngToContainerPoint( <LatLng> latlng )Point返回与给定地理坐标系相符的地图容器的点.
          containerPointToLatLng( <Point> point )LatLng返回给定地理容器点的地理坐标.
          project( <LatLng> latlng, <Number> zoom? )Point将地理坐标投影到指定缩放级别的像素坐标系中.
          unproject( <Point> point, <Number> zoom? )LatLng将像素坐标系投影到指定缩放级别的地理坐标系中。(默认为当前的缩放级别).
          mouseEventToContainerPoint( <MouseEvent> event )Point返回鼠标点击事件对象的像素坐标(与地图左上角相关).
          mouseEventToLayerPoint( <MouseEvent> event )Point返回鼠标点击事件对象的像素坐标(与地图图层相关).
          mouseEventToLatLng( <MouseEvent> event )LatLng返回鼠标点击事件对象的地理坐标.

          其他方法

          方法返回值描述
          getContainer()HTMLElement返回地图容器对象.
          getPanes()MapPanes返回不同地图对象的边框(叠加渲染).
          whenReady( <Function> fn, <Object> context? )this当地图的位置和缩放初始化好或是时间发生之后,运行给定的回调方法,通常传递一个函数内容.

          位置选项

          选项类型默认值描述
          watchBooleanfalse如果该值为真,则开始利用W3C的watchPosition方法监听位置变化情况(而不是指监听一次)。你可以通过map.stoplocate()方法来停止监听.
          setViewBooleanfalse如果该值为真,则通过自动将地图视图定位到用户一定精度范围内的位置,如果地理定位失败则显示全部地图.
          maxZoomNumberInfinity在使用setView选项时视图缩放的最大级别.
          timeoutNumber10000在触发locationerror事件之前等待地理定位的毫秒为单位的时间.
          maximumAgeNumber0位置监听的最大生命周期。如果比最后定位回复后毫秒用时短,则locate返回一个缓存位置.
          enableHighAccuracyBooleanfalse开启高精度,参加 W3C SPEC的描述.

          Zoom/pan options

          选项类型默认值描述
          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

          选项类型默认值描述
          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

          选项类型默认值描述
          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:

          选项类型默认值描述
          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地图属性包括互动操作,允许你在运行环境中互动地控制地图行为,比如通过拖拽和点击缩放级别显示和不显示某要素. 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地图拖拽处理程序,可以通过鼠标和触摸的形式.
          touchZoomIHandler触摸地图缩放处理程序.
          doubleClickZoomIHandler双击缩放处理程序.
          scrollWheelZoomIHandler滚动缩放处理程序.
          boxZoomIHandler矩形框(利用鼠标拖动)缩放处理程序.
          keyboardIHandler键盘导向处理程序.
          tapIHandlerMobile touch hacks (quick tap and touch hold) handler.
          zoomControlControl.Zoom缩放控制.
          attributionControlControl.Attribution属性控制.

          地图窗口

          望文思义,这是一个包括可以用来放置自定义图层的不同的地图窗口的对象。最大的区别是图层的叠置.

          Property类型描述
          mapPaneHTMLElement包含其他地图窗口的窗口.
          tilePaneHTMLElement切片图层的窗口.
          objectsPaneHTMLElement包含除切片窗口以外所有窗口的窗口.
          shadowPaneHTMLElement用来隐藏图层的窗口(如标注的隐藏).
          overlayPaneHTMLElement这线段和多边形一类图层的窗口.
          markerPaneHTMLElement标注图标的窗口.
          popupPaneHTMLElement弹出的窗口.

           
    2. #Shapes

      1. l-circle(通过给定的地理点和以米为单位的半径和选项对象来实例化一个圆对象。)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          panestring-'overlayPane'
          attributionstring-null
          namestring-undefined
          layerTypestring-undefined
          visibleboolean-true
          interactiveboolean-true
          bubblingMouseEventsboolean-true
          lStyleobject-null
          strokeboolean-true
          colorstring-'#3388ff'
          weightnumber-3
          opacitynumber-1.0
          lineCapstring-'round'
          lineJoinstring-'round'
          dashArraystring-null
          dashOffsetstring-null
          fillboolean-true
          fillColorstring-'#3388ff'
          fillOpacitynumber-0.2
          fillRulestring-'evenodd'
          classNamestring-null
          radiusnumber-null
          optionsLeaflet options to pass to the component constructorobject-{}
          latLngobject|array-

          () => [0, 0]

        2. Events

          Event nameTypeDescription
          update:visiblebooleanTriggers when the visible prop needs to be updated
          readyobjectTriggers when the component is ready
      2. l-polygon(过给定地理点组成的数组和选项对象来实例化一个多边形)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          panestring-'overlayPane'
          attributionstring-null
          namestring-undefined
          layerTypestring-undefined
          visibleboolean-true
          interactiveboolean-true
          bubblingMouseEventsboolean-true
          lStyleobject-null
          strokeboolean-true
          colorstring-'#3388ff'
          weightnumber-3
          opacitynumber-1.0
          lineCapstring-'round'
          lineJoinstring-'round'
          dashArraystring-null
          dashOffsetstring-null
          fillboolean-true
          fillColorstring-'#3388ff'
          fillOpacitynumber-0.2
          fillRulestring-'evenodd'
          classNamestring-null
          smoothFactornumber-1.0
          noClipboolean-false
          optionsLeaflet options to pass to the component constructorobject-{}
          latLngsarray-

          []

        2. Events

          Event nameTypeDescription
          update:visiblebooleanTriggers when the visible prop needs to be updated
          readyobjectTriggers when the component is ready

      3. l-polyline(通过给定的地理点组成的数组和任意的选项对象实例化一个线段)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          panestring-'overlayPane'
          attributionstring-null
          namestring-undefined
          layerTypestring-undefined
          visibleboolean-true
          interactiveboolean-true
          bubblingMouseEventsboolean-true
          lStyleobject-null
          strokeboolean-true
          colorstring-'#3388ff'
          weightnumber-3
          opacitynumber-1.0
          lineCapstring-'round'
          lineJoinstring-'round'
          dashArraystring-null
          dashOffsetstring-null
          fillboolean-false
          fillColorstring-'#3388ff'
          fillOpacitynumber-0.2
          fillRulestring-'evenodd'
          classNamestring-null
          smoothFactornumber-1.0
          noClipboolean-false
          optionsLeaflet options to pass to the component constructorobject-{}
          latLngsarray-[]
        2. Events

          Event nameTypeDescription
          update:visiblebooleanTriggers when the visible prop needs to be updated
          readyobjectTriggers when the component is ready
      4. l-rectangle(通过给定的地理边界和选项对象来实例化一个矩形对象

        1. Props

          Prop nameDescriptionTypeValuesDefault
          panestring-'overlayPane'
          attributionstring-null
          namestring-undefined
          layerTypestring-undefined
          visibleboolean-true
          interactiveboolean-true
          bubblingMouseEventsboolean-true
          lStyleobject-null
          strokeboolean-true
          colorstring-'#3388ff'
          weightnumber-3
          opacitynumber-1.0
          lineCapstring-'round'
          lineJoinstring-'round'
          dashArraystring-null
          dashOffsetstring-null
          fillboolean-true
          fillColorstring-'#3388ff'
          fillOpacitynumber-0.2
          fillRulestring-'evenodd'
          classNamestring-null
          smoothFactornumber-1.0
          noClipboolean-false
          optionsLeaflet options to pass to the component constructorobject-{}
          boundsfunc-() => [[0,0],[0,0]]
        2. Events

          Event nameTypeDescription
          update:visiblebooleanTriggers when the visible prop needs to be updated
          readyobjectTriggers when the component is ready
    3. #Tiles

      1. l-grid-layer(创建一个地图层,其中每个图块都是实例化的Vue组件。每个图块组件都会获得相应的coords道具,l-grid-layer以指示图块的缩放级别和位置)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          panestring-'tilePane'
          attributionstring-null
          namestring-undefined
          layerTypestring-undefined
          visibleboolean-true
          opacitynumber-1.0
          zIndexnumber-1
          tileSizenumber-256
          noWrapboolean-false
          optionsLeaflet options to pass to the component constructorobject-{}
          tileComponentobject-
        2. Events

          Event nameTypeDescription
          update:visiblebooleanTriggers when the visible prop needs to be updated
          readyobjectTriggers when the component is ready

      2. l-tile-layer(通过给定URL模板和具有选项的对象来实例化一个切片图层)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          panestring-'tilePane'
          attributionstring-null
          namestring-undefined
          layerTypestring-undefined
          visibleboolean-true
          opacitynumber-1.0
          zIndexnumber-1
          tileSizenumber-256
          noWrapboolean-false
          tmsboolean-false
          subdomainsstring|array-'abc'
          detectRetinaboolean-false
          optionsLeaflet options to pass to the component constructorobject-{}
          urlstring-null
          tileLayerClassfunc-tileLayer
        2. Events

          Event nameTypeDescription
          update:visiblebooleanTriggers when the visible prop needs to be updated
          readyobjectTriggers when the component is ready
      3. l-wms-tile-layer(通过给定一个基本的WMS服务的URL和WMS参数或选项对象来实例化一个WMS切片图层对象。)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          panestring-'tilePane'
          attributionstring-null
          namestring-undefined
          layerTypestring-undefined
          visibleboolean-true
          opacitynumber-1.0
          zIndexnumber-1
          tileSizenumber-256
          noWrapboolean-false
          tmsboolean-false
          subdomainsstring|array-'abc'
          detectRetinaboolean-false
          layersstring-''
          stylesstring-''
          formatstring-'image/jpeg'
          transparentboolean-
          versionstring-'1.1.1'
          crsobject-null
          upperCaseboolean-false
          optionsLeaflet options to pass to the component constructorobject-{}
          baseUrlstring-null
        2. Events

          Event nameTypeDescription
          update:visiblebooleanTriggers when the visible prop needs to be updated
          readyobjectTriggers when the component is ready
    4. #Markers

      1. l-circle-marker(是一个特定半径的圆,半径单位是像素。是Circle的延伸。通过Map#addLayer添加到地图上)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          panestring-'markerPane'
          attributionstring-null
          namestring-undefined
          layerTypestring-undefined
          visibleboolean-true
          interactiveboolean-true
          bubblingMouseEventsboolean-true
          lStyleobject-null
          strokeboolean-true
          colorstring-'#3388ff'
          weightnumber-3
          opacitynumber-1.0
          lineCapstring-'round'
          lineJoinstring-'round'
          dashArraystring-null
          dashOffsetstring-null
          fillboolean-true
          fillColorstring-'#3388ff'
          fillOpacitynumber-0.2
          fillRulestring-'evenodd'
          classNamestring-null
          radiusnumber-null
          optionsLeaflet options to pass to the component constructorobject-{}
          latLngobject|array-() => [0, 0]
        2. Events

          Event nameTypeDescription
          update:visiblebooleanTriggers when the visible prop needs to be updated
          readyobjectTriggers when the component is ready
      2. l-icon(简单易用的配置标记图标的方式)

        1. Props
          1. Prop nameDescriptionTypeValuesDefault
            iconUrlstring-null
            iconRetinaUrlstring-null
            iconSizeobject|array-null
            iconAnchorobject|array-null
            popupAnchorobject|array-() => [0, 0]
            tooltipAnchorobject|array-() => [0, 0]
            shadowUrlstring-null
            shadowRetinaUrlstring-null
            shadowSizeobject|array-null
            shadowAnchorobject|array-null
            bgPosobject|array-() => [0, 0]
            classNamestring-''
            optionsobject-{}
      3. l-marker(通过给定一个地理点和一个具有选项的对象来实例化一个注记)

    5. #Controls

      1. l-control(添加任何自定义组件作为表单控件)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          positionstring-'topright'
          optionsLeaflet options to pass to the component constructorobject-{}
          disableClickPropagationboolean-true
          disableScrollPropagationboolean-false
        2. Events

          Event nameTypeDescription
          readyobjectTriggers when the component is ready
      2. l-control-attribution(将任何自定义组件添加为表单控件属​​性)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          positionstring-'topright'
          optionsLeaflet options to pass to the component constructorobject-{}
          prefixstring|boolean-null
        2. Events

          Event nameTypeDescription
          readyobjectTriggers when the component is ready
      3. l-control-layers(将任何自定义组件添加为表单控制层)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          positionstring-'topright'
          optionsLeaflet options to pass to the component constructorobject-{}
          collapsedboolean-true
          autoZIndexboolean-true
          hideSingleBaseboolean-false
          sortLayersboolean-false
          sortFunctionfunc-undefined
        2. Events

          Event nameTypeDescription
          readyobjectTriggers when the component is ready
      4. l-control-scale(将任何自定义组件添加为表单控件比例)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          positionstring-'topright'
          optionsLeaflet options to pass to the component constructorobject-{}
          maxWidthnumber-100
          metricboolean-true
          imperialboolean-true
          updateWhenIdleboolean-false
        2. Events

          Event nameTypeDescription
          readyobjectTriggers when the component is ready
      5. l-control-zoom(将任何自定义组件添加为表单控件缩放)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          positionstring-'topright'
          optionsLeaflet options to pass to the component constructorobject-{}
          zoomInTextstring-'+'
          zoomInTitlestring-'Zoom in'
          zoomOutTextstring-'-'
          zoomOutTitlestring-'Zoom out'
        2. Events

          Event nameTypeDescription
          readyobjectTriggers when the component is ready
    6. #Info

      1. l-popup(通过给定一些选项构造一个弹出框对象,对象用来描述出现形式和位置还有一个可选对象来根据指向的资源对象标注弹出框)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          contentstring-null
          optionsLeaflet options to pass to the component constructorobject-{}
          latLngobject|array-() => []
        2. Events

          Event nameTypeDescription
          readyobjectTriggers when the component is ready
      2. l-tooltip(在地图上显示工具提示)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          contentstring-null
          optionsLeaflet options to pass to the component constructorobject-{}
        2. Events

          Event nameTypeDescription
          readyobjectTriggers when the component is ready
    7. #Grouping

      1. l-feature-group(创建一个图组,视情况指定一组初始图层)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          panestring-'overlayPane'
          attributionstring-null
          namestring-undefined
          layerTypestring-undefined
          visibleboolean-true
          optionsLeaflet options to pass to the component constructorobject-{}
        2. Events

          Event nameTypeDescription
          update:visiblebooleanTriggers when the visible prop needs to be updated
          readyobjectTriggers when the component is ready
      2. l-layer-group(用来将几个图层组成一个组并作为一个图层来处理。如果你将其添加到地图上,组中任何图层的添加或移除都将使其同样在地图添加或删除。继承自ILayer接口)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          panestring-'overlayPane'
          attributionstring-null
          namestring-undefined
          layerTypestring-undefined
          visibleboolean-true
          optionsLeaflet options to pass to the component constructorobject-{}
        2. Events

          Event nameTypeDescription
          update:visiblebooleanTriggers when the visible prop needs to be updated
          readyobjectTriggers when the component is ready
    8. #Other

      1. l-geo-json(创建一个GeoJSON图层。可以任意地接受GeoJSON格式的对象和选项对象并显示在地图上)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          panestring-'overlayPane'
          attributionstring-null
          namestring-undefined
          layerTypestring-undefined
          visibleboolean-true
          optionsLeaflet options to pass to the component constructorobject-{}
          geojsonobject|array-() => ({})
          optionsStyleobject|func-

          null

        2. Events

          Event nameTypeDescription
          update:visiblebooleanTriggers when the visible prop needs to be updated
          readyobjectTriggers when the component is ready
      2. l-image-overlay(通过给定图像的URL和相关的地理范围来实例化一个图像叠加层对象。)

        1. Props

          Prop nameDescriptionTypeValuesDefault
          panestring-'overlayPane'
          attributionstring-null
          namestring-undefined
          layerTypestring-undefined
          visibleboolean-true
          interactiveboolean-false
          bubblingMouseEventsboolean-true
          urlstring-
          bounds-
          opacitynumber-1.0
          altstring-''
          crossOriginboolean-false
          errorOverlayUrlstring-''
          zIndexnumber-1
          classNamestring-''
          optionsLeaflet options to pass to the component constructorobject-{}
        2. Events

          Event nameTypeDescription
          update:visiblebooleanTriggers when the visible prop needs to be updated
          readyobjectTriggers when the component is ready
  3. 案例
    1. 多边形
      1. <template>
      2. <div>
      3. <button @click="clickBtn">
      4. Change rectangle style
      5. </button>
      6. </div>
      7. <l-map
      8. :zoom="zoom"
      9. :center="center"
      10. style="height: 500px; width: 100%"
      11. >
      12. <l-tile-layer
      13. :url="url"
      14. :attribution="attribution"
      15. />
      16. <l-circle
      17. :lat-lng="circle.center"
      18. :radius="circle.radius"
      19. />
      20. <l-rectangle
      21. :bounds="rectangle.bounds"
      22. :l-style="rectangle.style"
      23. />
      24. <l-polygon
      25. :lat-lngs="polygon.latlngs"
      26. :color="polygon.color"
      27. />
      28. <l-polyline
      29. :lat-lngs="polyline.latlngs"
      30. :color="polyline.color"
      31. />
      32. </l-map>
      33. </div>
      34. </template>
      35. <script>
      36. import { latLng } from "leaflet";
      37. import {
      38. LMap,
      39. LTileLayer,
      40. LCircle,
      41. LRectangle,
      42. LPolygon,
      43. LPolyline
      44. } from "vue2-leaflet";
      45. export default {
      46. name: "GeometryTest",
      47. components: {
      48. LMap,
      49. LTileLayer,
      50. LCircle,
      51. LRectangle,
      52. LPolygon,
      53. LPolyline
      54. },
      55. data() {
      56. return {
      57. zoom: 11,
      58. center: [47.31322, -1.319482],
      59. circle: {
      60. center: latLng(47.41322, -1.0482),
      61. radius: 4500
      62. },
      63. rectangle: {
      64. bounds: [[47.341456, -1.397133], [47.303901, -1.243813]],
      65. style: { color: "red", weight: 5 }
      66. },
      67. polygon: {
      68. latlngs: [
      69. [47.2263299, -1.6222],
      70. [47.21024000000001, -1.6270065],
      71. [47.1969447, -1.6136169],
      72. [47.18527929999999, -1.6143036],
      73. [47.1794457, -1.6098404],
      74. [47.1775788, -1.5985107],
      75. [47.1676598, -1.5753365],
      76. [47.1593731, -1.5521622],
      77. [47.1593731, -1.5319061],
      78. [47.1722111, -1.5143967],
      79. [47.1960115, -1.4841843],
      80. [47.2095404, -1.4848709],
      81. [47.2291277, -1.4683914],
      82. [47.2533687, -1.5116501],
      83. [47.2577961, -1.5531921],
      84. [47.26828069, -1.5621185],
      85. [47.2657179, -1.589241],
      86. [47.2589612, -1.6204834],
      87. [47.237287, -1.6266632],
      88. [47.2263299, -1.6222]
      89. ],
      90. color: "#ff00ff"
      91. },
      92. polyline: {
      93. latlngs: [
      94. [47.334852, -1.509485],
      95. [47.342596, -1.328731],
      96. [47.241487, -1.190568],
      97. [47.234787, -1.358337]
      98. ],
      99. color: "green"
      100. },
      101. url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
      102. attribution:
      103. '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
      104. };
      105. },
      106. methods: {
      107. clickBtn() {
      108. this.rectangle.style.weight++;
      109. this.rectangle.style.color =
      110. this.rectangle.style.weight % 2 === 0 ? "blue" : "green";
      111. }
      112. }
      113. };
      114. </script>

      地址:https://vue2-leaflet.netlify.app/examples/geometry-test.html

    2. geoJSon
       

      1. <template>
      2. <div class="imagePreview">
      3. <info-dialog
      4. :title="$t('messages.image')"
      5. width="80%"
      6. :isShowDialog="isShowDialog"
      7. :dialogOperates="dialogOperates"
      8. @closeDialog="closeDialog"
      9. >
      10. <info-container :layout="layout">
      11. <div slot="main">
      12. <l-map
      13. ref="myMap"
      14. :zoom="zoom"
      15. :center="center"
      16. style="height: 600px; width: 100%"
      17. @ready="doSomethingOnReady()"
      18. >
      19. <l-tile-layer :url="url" />
      20. <l-geo-json :geojson="geojson" />
      21. </l-map>
      22. </div>
      23. </info-container>
      24. </info-dialog>
      25. </div>
      26. </template>
      27. <script>
      28. import { LMap, LTileLayer, LGeoJson } from 'vue2-leaflet'
      29. import 'leaflet/dist/leaflet.css'
      30. export default {
      31. name: 'DatasetImagePreview',
      32. components: {
      33. LMap,
      34. LTileLayer,
      35. LGeoJson
      36. },
      37. data () {
      38. return {
      39. url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
      40. zoom: 8,
      41. center: [47.313220, -1.319482],
      42. geojson: null,
      43. layout: { footer: false, header: false },
      44. loading: { isLoading: false },
      45. isShowDialog: false,
      46. row: {}, // 父组件传入数据
      47. // foot按钮
      48. dialogOperates: [{
      49. label: 'refresh',
      50. type: 'primary',
      51. plain: true,
      52. method: () => {
      53. this.geometryInit()
      54. }
      55. }, {
      56. label: 'cancel',
      57. type: 'primary',
      58. plain: true,
      59. method: () => {
      60. this.closeDialog(this.row)
      61. }
      62. }]
      63. }
      64. },
      65. methods: {
      66. doSomethingOnReady () {
      67. this.map = this.$refs.myMap.mapObject
      68. },
      69. // 取消或者离开页面清除请求
      70. cancelImage () {
      71. // 清除定时任务
      72. clearTimeout(this.timer)
      73. clearInterval(this.timer2)
      74. },
      75. // 调用获取分解结果轮询接口
      76. getImageResult (para) {
      77. this.loading.isLoading = true
      78. this.timer = setTimeout(() => {
      79. this.serverApi({
      80. loading: this.loading,
      81. params: para,
      82. interface: this.$https.geometryResult,
      83. success: (data) => {
      84. if (data.statement === 'available' || data.statement === 'error' || data.statement === 'cancelled') {
      85. this.geojson = data.content
      86. this.center = JSON.parse(data.content[0]).geometry.coordinates[0][0]
      87. } else {
      88. setTimeout(() => {
      89. this.getImageResult(para)
      90. }, 15 * 100)
      91. }
      92. },
      93. error: (err) => {
      94. // 保存之后取消轮询,提示错误
      95. this.cancelImage()
      96. this.$message.error(err.response.data.err)
      97. }
      98. })
      99. }, 1000)
      100. },
      101. // livy init查询
      102. geometryInit () {
      103. // 调用接口创建livy查询
      104. let para = { id: this.row.id }
      105. this.loading.isLoading = true
      106. this.serverApi({
      107. loading: this.loading,
      108. params: para,
      109. interface: this.$https.geometryInit,
      110. success: (data) => {
      111. this.statementId = data.statementId
      112. this.clusterId = data.clusterId
      113. this.getImageResult({ id: this.row.id, statementId: this.statementId, clusterId: this.clusterId })
      114. }
      115. })
      116. },
      117. // 打开弹框
      118. showDialog (row) {
      119. this.row = row
      120. this.geometryInit()
      121. this.isShowDialog = true
      122. },
      123. // 取消
      124. closeDialog () {
      125. this.cancelImage()
      126. this.isShowDialog = false
      127. }
      128. }
      129. }
      130. </script>
      131. <style lang="scss" scoped>
      132. .imagePreview {
      133. }
      134. /deep/ .leaflet-control-attribution a {
      135. display: none !important;
      136. }
      137. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/834893
推荐阅读
相关标签
  

闽ICP备14008679号