react 之 openlayer比例尺显示

博客介绍了地图渲染相关内容,包括必要文件的引入、地图的渲染,还讲述了创建比例尺对象scaleline并与地图关联,同时给出了代码和效果图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、必要文件的引入

import React, { Component } from 'react';
import Map from '../../component/map/map';
import {ScaleLine} from 'ol/control.js';

二、地图的渲染

render() {
    return (
      <div>
       {/*显示鼠标的坐标信息 */}
        <Map ref="map" center={{ lon: 113.8, lat: 34.6 }}  />;
      </div>
    );
  }

三、创建比例尺 对象scaleline,并和地图关联

componentDidMount() {
    let {map} = this.refs.map

    var scaleLineControl = new ScaleLine({
        //设置比例尺单位,degrees、imperial、us、nautical、metric(度量单位)
        units: "metric"
    });
    map.addControl(scaleLineControl)

  }

四、代码如下

import React, { Component } from 'react';
import Map from '../../component/map/map';

import {ScaleLine} from 'ol/control.js';

class MapScaleLineControl extends Component {
    constructor(props){
        super(props)
        this.state = {
            x:0,
            y:0
        }
    }
  componentDidMount() {
    let {map} = this.refs.map

    var scaleLineControl = new ScaleLine({
        //设置比例尺单位,degrees、imperial、us、nautical、metric(度量单位)
        units: "metric"
    });
    map.addControl(scaleLineControl)

  }

  render() {
    return (
      <div>
       {/*显示鼠标的坐标信息 */}
        <Map ref="map" center={{ lon: 113.8, lat: 34.6 }}  />;
      </div>
    );
  }
}

export default MapScaleLineControl;

 五、效果图如下

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值