Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapContext的moveToLocation方法不会将地图中心移动到当前定位点 #1101

Closed
kaisa911 opened this issue Nov 13, 2018 · 3 comments
Closed

Comments

@kaisa911
Copy link

问题描述
在组件里调用生成了mapContext,调用moveToLocation(),地图中心并不会移动到当前点。
调用includesPoints方法,地图也不会进行缩放显示出点

复现步骤
引入一个Map组件,添加上showLocation属性,id属性。
写一个Button,点击触发moveToLocation方法。
发现地图中心没有移动到当前定位点。
写一个Button,点击触发includePoints方法。
发现地图没有变化

[或者可以直接贴源代码,能贴文字就不要截图]

// 这里可以贴代码
import Taro, { Component } from '@tarojs/taro';
import { View, Map, Button } from '@tarojs/components';
import { connect } from '@tarojs/redux';

import './index.less';

@connect(({ counter }) => ({
  counter
}))
class Index extends Component {
  config = {
    navigationBarTitleText: '首页'
  };

  componentWillReceiveProps(nextProps) {
    console.log(this.props, nextProps);
  }

  componentWillUnmount() {}

  componentDidShow() {
    this.mapCtx = Taro.createMapContext('map4select', this.$scope);
  }

  componentDidHide() {}
  moveToLocation = () => {
    this.mapCtx.moveToLocation();
  };
  includePoints = () => {
    const points = [
      { longitude: 116.43851, latitude: 39.9219 },
      { longitude: 116.44355, latitude: 39.92511 },
      { longitude: 116.44859000000001, latitude: 39.9219 },
      { longitude: 116.44355, latitude: 39.918690000000005 }
    ];
    this.mapCtx.includePoints({
      padding: [10],
      points: points
    });
  };

  render() {
    return (
      <View className='index'>
        <Map id='map4select' showLocation style={{ width: '750px', height: '200px' }} />
        <Button onClick={this.moveToLocation}>moveToLocation</Button>
        <Button onClick={this.includePoints}>includePoints</Button>
      </View>
    );
  }
}

export default Index;

期望行为
期望点击moveToLocation会将地图中心移动到中心点。
期望点击includePoints会地图缩放,让地图展示出四个点。

报错信息

无报错

系统信息

  • 操作系统: [CentOs]
  • Taro 版本 [v1.1.4]
  • Node.js 版本 [ v8.9.3]
  • 报错平台 [weapp]

补充信息
[可选]
[根据你的调查研究,出现这个问题的原因可能在哪里?]

@kaisa911
Copy link
Author

解决了一个问题,就是在js文件里map的style的宽度和高度用的‘px’,在小程序里就会渲染成px,而不是像在在less文件里写的px会转换成rpx。所以会导致moveToLocation()不能在将地图中心移动到定位点。

@luckyadam
Copy link
Member

@kaisa911
Copy link
Author

https://nervjs.github.io/taro/docs/size.html#api
这个

感谢,第二个问题应该是在模拟器中无效,需要在真机上才能看到。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants