简体   繁体   English

Mapbox GL JS Api 调用控件

[英]Mapbox GL JS Api calls control

Is there any way to control the API calls of Mapbox GL JS.有什么方法可以控制 Mapbox GL JS 的 API 调用。 By this I mean I want API calls to be fired on mouse release.我的意思是我希望在鼠标释放时触发 API 调用。 ie If I drag the map from India to USA and drop the cursor at USA, I don't want the tiles in between these two places to load.即,如果我将 map 从印度拖到美国,然后将 cursor 放在美国,我不想加载这两个地方之间的瓷砖。 I want tiles of USA to load.我想要加载美国的瓷砖。 Is there any way to achieve this有什么办法可以做到这一点

By default as I drag the mouse the API calls gets fired.默认情况下,当我拖动鼠标时,API 调用会被触发。

There's one specific way you can do this, and that's using the transformRequest option when you create the map:有一种特定的方法可以做到这一点,那就是在创建 map 时使用transformRequest选项:

const map = new mapboxgl.Map({
  container: 'map',
  center: [-122.420679, 37.772537],
  zoom: 13,
  style: style_object,
  hash: true,
  transformRequest: (url, resourceType)=> {
    if (!something) {
      return;
    } else {
      return { url } 
    }
  }
});

It may be tricky to work out what the "something" is.弄清楚“某物”是什么可能很棘手。

The dragstart , drag , and dragend map events might also be useful here. dragstartdragdragend map 事件在这里也可能有用。 I'm not entirely sure what your use case here is for preventing tile loads "between" two places, and what that would look like.我不完全确定您在这里的用例是什么用于防止“在”两个地方之间加载瓷砖,以及它会是什么样子。 Is the goal to enhance performance, and would the map just be "blank" in between?目标是提高性能吗,map 是否只是介于两者之间的“空白”?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM