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}
              />
        );
      }
    }
    
  • 相关阅读:
    C语言修炼-第2天
    static_cast, dynamic_cast, reinterpret_cast, const_cast的区别
    构造函数不能为虚函数的原因
    matlab2016b ubuntu命令行安装 + matconvnet的安装
    python debug open_files
    构造函数不能被继承的原因
    NNVM代码阅读
    ncnn阅读
    Deep TEN: Texture Encoding Network
    git命令笔记
  • 原文地址:https://www.cnblogs.com/ajanuw/p/10096778.html
Copyright © 2011-2022 走看看