weixin_39801613
weixin_39801613
2021-01-12 05:04

onChangeHandler: flag for user generated event

I would like to know in the onChangeHandler if the event is triggered because of user interactions? Is that possible, or are you considering making that?

该提问来源于开源项目:google-map-react/google-map-react

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

11条回答

  • weixin_39593061 weixin_39593061 4月前

    How did you resolve this issue?

    点赞 评论 复制链接分享
  • weixin_39883065 weixin_39883065 4月前

    Are you still facing this issue?

    点赞 评论 复制链接分享
  • weixin_39676972 weixin_39676972 4月前

    I have the same issue. I need the bounds to set based on the results. I cant do it on google api loaded because that happens when the website is loaded before the search. I defined bounds based on the results but I am having trouble actually setting them after the search results are set into state and the pins are rendered. Any feedback?

    点赞 评论 复制链接分享
  • weixin_39883065 weixin_39883065 4月前

    Here is an example https://github.com/google-map-react/google-map-react-examples/blob/master/src/examples/Main.js#L40

    点赞 评论 复制链接分享
  • weixin_39710396 weixin_39710396 4月前

    I need something like this as well. I'd like to lock the map from external updates if the user drags/zooms. Then when they want, they can press "reset map" which will switch back to automatic bounds.

    But currently onChange is firing for all updates so it's locking automatically which is not what I want.

    点赞 评论 复制链接分享
  • weixin_39519769 weixin_39519769 4月前

    Why you need this? What the real reason?

    点赞 评论 复制链接分享
  • weixin_39519769 weixin_39519769 4月前

    And please describe what mean user-interaction - as even you change center or zoom props it's reaction on some of user interaction.

    点赞 评论 复制链接分享
  • weixin_39519769 weixin_39519769 4月前

    BTW I understand the overall problem, I even wrote a part about in Doc.md Calling onChange at initialization is needed blabla It was my api design mistake to provide bounds as and argument for onChange event, so now every center or zoom props change cause onChange event call, and this behaviour is not like in most controllable react components. In Doc.md I also wrote

    
    NOTE: Now I think it was wrong decision to call onChange 
    at initialization. In the future releases I'll remove 
    such behavior and will provide helper to calculate size and bounds 
    outside map control. 
    I think about helper similar to AutoSizer 
    it also will allow to remove resetBoundsOnResize, style properties
    

    And having that the problem above and this problem have same root I will fix this in the future map version

    点赞 评论 复制链接分享
  • weixin_39801613 weixin_39801613 4月前

    So, this is the case. I am building a search map. So if the user search for something and get results, i will fit bounds to the search result (update zoom and center prop). In this case I will not handle onChange. But if the user is dragging the map, I want to update the bounds and do a new search based on bounds instead of what he searched for. Take a look here: https://www.livvin.com/map

    点赞 评论 复制链接分享
  • weixin_39519769 weixin_39519769 4月前

    For now just check that if center and zoom is the same (with some eps) as you provided then do nothing

    点赞 评论 复制链接分享
  • weixin_39593061 weixin_39593061 4月前

    I also have this problem with current API. I need events like dragstart and dragend, but I can't rich them.

    and also I don't have access to google events directly from onGoogleApiLoaded method for example

    javascript
    onGoogleApiLoaded: () => ({ map, maps }) => {
          map.addListener('dragstart', (event) => {
            console.log(event) // logged undefined
          })
        }
    
    点赞 评论 复制链接分享

相关推荐