@2plgiap/react-leaflet-control 中文文档教程

发布于 4年前 浏览 31 项目主页 更新于 3年前

react-leaflet-control

一个 React-Leaflet 组件,它在传单的控制面板中呈现 React 元素。

installation

npm install react-leaflet-control

Options

position:挂载到哪个面板。 选项有 toplefttoprightbottomleftbottomright

Usage

import React, { Component } from 'react';
import Control from 'react-leaflet-control';
import { Map, TileLayer, ZoomControl } from 'react-leaflet';

export default class Example extends Component {
  constructor(){
    this.state = {
      center: [51.3, 0.7]
    } 
  }
  render(){
    <Map
      center={this.state.center}
      zoom={10}
    >
      <ZoomControl position="topright" />
      <TileLayer
        url='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
        attribution='© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
        maxZoom={18}
      />

      <Control position="topleft" >
        <button 
          onClick={ () => this.setState({bounds: [51.3, 0.7]}) }
        >
          Reset View
        </button>
      </Control>
    </Map>
  }
}

react-leaflet-control

A React-Leaflet component that renders React elements in leaflet's control pane.

installation

npm install react-leaflet-control

Options

position: Which pane to mount to. Options are topleft, topright, bottomleft, bottomright

Usage

import React, { Component } from 'react';
import Control from 'react-leaflet-control';
import { Map, TileLayer, ZoomControl } from 'react-leaflet';

export default class Example extends Component {
  constructor(){
    this.state = {
      center: [51.3, 0.7]
    } 
  }
  render(){
    <Map
      center={this.state.center}
      zoom={10}
    >
      <ZoomControl position="topright" />
      <TileLayer
        url='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
        attribution='© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
        maxZoom={18}
      />

      <Control position="topleft" >
        <button 
          onClick={ () => this.setState({bounds: [51.3, 0.7]}) }
        >
          Reset View
        </button>
      </Control>
    </Map>
  }
}
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文