简体   繁体   中英

Is there any way to center a map (Google Map) based where's located a layer from carto

我正在使用carto.js v4从carto获取图层并将其显示在地图(Google地图)上,我想将地图居中放置图层所在的位置

You need to get that info using SQL API and PostGIS functions, in general the easy approach is to center the map in the bounding box of your data so that would be sending this query

select st_asgeojson(
           st_boundingdiagonal(
               st_collect(
                   the_geom)))
  from populated_places

That query will give you the coordinates of the corners of the bounding box as a GeoJSON object, very easy to parse and translate into a Google Maps API map change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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