Requests exceeding maximum URL length in Fusion Tables layer

后端 未结 2 698
故里飘歌
故里飘歌 2021-01-25 03:25

I\'m using Fusion Tables layer on Google Maps. If I add a large where condition (where in 1000+ items), the layer does not load.



        
2条回答
  •  无人共我
    2021-01-25 04:10

    If you use the Fusion Tables layer, your map tile requests will end up with long query strings exceeding the maximum URL length. There are no layer settings to use POST instead of GET requests, so we'll have to avoid the problem by filtering map results client-side.

    Inspired by this answer, we can:

    1. Use the Fusion Tables API, request all map data at once. The results will be huge, but the GET request is small:

      https://www.googleapis.com/fusiontables/v2/query?sql=select GEO_ID2, geometry from 1xdysxZ94uUFIit9eXmnw1fYc6VcQiXhceFd_CVKa&key=
      
    2. Wrangle data. The "geometry" column is in GeoJSON. There are a few issues with the returned format: the outermost wrapping object is inconsistent, and the coordinate lists of the polygons don't have the same start and end points.

    3. Draw the GeoJSON features on the map using the Data layer. Adding styles and interactivity for the features is well-documented.

    For this demo, only a small set of IDs is used, and IDs are looked up using array's indexOf(). With more IDs, consider using a faster lookup table.

    html,
    body,
    #map {
      height: 100%;
      margin: 0;
      padding: 0;
    }

提交回复
热议问题