Google会映射GeoJSON-切换标记图层吗?

use*_*425 9 maps markers layer toggle geojson

我通过调用PostGIS数据库返回了一些GeoJSON.我希望能够为每个功能添加标记,并能够切换不同类型的标记/功能.目前我正在使用JavaScript为每个功能生成一个标记,根据类型将它们添加到数组中,然后根据需要通过数组设置show/hide来切换'layers'.

这工作正常,但我想知道新的GeoJSON功能是否提供了更好的方法.据我所知,所有功能都被添加到同一个数据层,并且切换它们将涉及设置样式或仅替换新的预过滤的GeoJSON.

所以问题是,是否可以拥有多个数据层,并可以轻松地从地图中添加/删除它们,或者我最好不要查看类似OpenLayers的内容?

编辑:更多研究表明它非常简单.

对于要切换的要素集合中的每种要素类型,请创建新的Data对象.将所有相关功能添加到该数据对象.

var datalayer = new google.maps.Data();
datalayer.addGeoJson(feature);
datalayer.setMap(mainmap);
Run Code Online (Sandbox Code Playgroud)

然后将每个数据对象/要素类型存储为键值对.在切换时,根据需要拉出相关数据对象和setMap:

var datalayer= featuretypesobj["feature type to toggle"];
datalayer.setMap(mymap); //or
datalayer.setMap(null);
Run Code Online (Sandbox Code Playgroud)

dat*_*unk 14

您还可以创建单独的图层

var layer_1 = new google.maps.Data();
var layer_2 = new google.maps.Data();
Run Code Online (Sandbox Code Playgroud)

然后填充它,例如使用json数据

layer_1.loadGeoJson('/path/to/data.json');
layer_2.loadGeoJson('/path/to/data2.json');
Run Code Online (Sandbox Code Playgroud)

然后在地图上添加/删除它们

layer_1.setMap(map);
layer_2.setMap(map);
layer_1.setMap(null);
Run Code Online (Sandbox Code Playgroud)