zoukankan      html  css  js  c++  java
  • 腾讯地图打开地图选取位置 withMap

    https://lbs.qq.com/tool/component-picker.html

    withMap

    import React, { Component } from "react";
    export default function withMap() {
      return function(Target) {
        return class WithMap extends Component {
          state = {
            open: false,
            cb: null,
          };
    
          componentDidMount() {
            const _this = this;
            window.addEventListener("message", this.handleMessage, false);
          }
          componentWillUnmount() {
            window.removeEventListener("message", this.handleMessage);
          }
          handleMessage = event => {
            var loc = event.data;
            if (loc && loc.module == "locationPicker") {
              this.handleToogleOpen(false)(loc);
            }
          };
          handleToogleOpen = (is, cb) => loc => {
            this.setState(prevState => ({
              open: is,
              cb: !!cb ? cb : prevState.cb,
            }));
    
            const { cb: scb } = this.state;
            if (loc && scb) {
              scb(loc);
            }
          };
          render() {
            return (
              <>
                {this.state.open && (
                  <iframe
                    id="mapPage"
                    style={{
                       "100%",
                      height: "100vh",
                      zIndex: "1200",
                      position: "fixed",
                      top: "0",
                      left: "0",
                      right: "0",
                    }}
                    frameBorder="0"
                    src={`https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=VT4BZ-42ZWX-EZL43-76VKV-OJXIQ-MIFLF&referer=myapp`}
                  />
                )}
    
                <Target {...this.props} handleToogleOpen={this.handleToogleOpen} />
              </>
            );
          }
        };
      };
    }
    

    使用

    @withMap() // 注入即可
    @inject(MAINTENANCESTORE)
    @observer
    class ApplyForMaintenance extends Component {
      render() {
        const { maintenanceStore, handleToogleOpen } = this.props;
    
        const getAddress = handleToogleOpen(true, loc => {
          l(loc);
          maintenanceStore.AFM.address = loc.poiaddress;
        });
        return (
              <TextField
                required
                fullWidth
                label="地址"
                onFocus={getAddress}
                value={maintenanceStore.AFM.address}
              />
        );
      }
    }
    
  • 相关阅读:
    iOS-禁止scrollview垂直方向滚动,只允许水平方向滚动;或只允许垂直方向滚动
    MongoDB安装
    Vue运用
    egg-middleware 中间件
    如何判断扫码的客户端是微信还是支付宝
    node 短信接口的调用
    Mui 长按保存图片
    egg-sequelize --- nodejs
    egg-mongoose --- nodejs
    Mongoose 基本用法
  • 原文地址:https://www.cnblogs.com/ajanuw/p/10096778.html
Copyright © 2011-2022 走看看