我正在使用LayerSwitcher向OpenLayers映射中添加几个KML层(88)。我已经将所有图层添加到SelectFeature控件中。但是,一旦使用OpenLayers.Map.addLayers在地图上添加了77个以上的图层,就永远不会调用SelectFeature的onSelect函数。

它似乎与KML层无关,因为我可以从addLayers调用中删除任何11个层,其余层都可以正常工作。注意:我不必从SelectFeature构造函数中删除任何内容。

proprietaryMap.addLayers(
[
  BaseLayer,
  SectionLayer, DistrictLayer, BoroughLayer,
  Business, Hotel, Market, Restaurant,
  Library, Museum, Theater,
  PostSecondary, PrivateEarly, PrivateElementry, PrivateHigh, PrivateJunior, PrivateK8, PrivateK12,
  PublicElementry, PublicHigh, PublicJunior, PublicK8, PublicK12, PublicBuilding, PublicSecondary,
  Consulate, Court, Embassy, GOffice, Military, PostOffice,
  Hospital, Inpatient, Outpatient,
  Corrections, Battalion, Division, Engine, Special,
  CCB, Checkpoint, Precinct, NOther,
  Amusement, Beach, Botanical, Garden, Golf, Park, Playground, RecCenter, Sports, Zoo,
  Church, Convent, Mosque, Synagogue, Temple,
  Constituent, Gated, PrivateDev, PublicHousing,
  Adult, Homeless, Nursing,
  Airport, Bridge, Bus, Ferry, Heliport, Marina, Mile, Intersection,
  Subway, Pier, Rail, Toll, Transit, Tunnel, WaterNav,
  Island, Lake, River,
  Center, Cemetery, Landmark, POI, Other
]);

var selectControl = new OpenLayers.Control.SelectFeature(
[
  Business,
  Hotel, Market, Restaurant,
  Library, Museum, Theater,
  PostSecondary, PrivateEarly, PrivateElementry, PrivateHigh, PrivateJunior, PrivateK8, PrivateK12,
  PublicElementry, PublicHigh, PublicJunior, PublicK8, PublicK12, PublicBuilding, PublicSecondary,
  Consulate, Court, Embassy, GOffice, Military, PostOffice,
  Hospital, Inpatient, Outpatient,
  Corrections, Battalion, Division, Engine, Special,
  CCB, Checkpoint, Precinct, NOther,
  Amusement, Beach, Botanical, Garden, Golf, Park, Playground, RecCenter, Sports, Zoo,
  Church, Convent, Mosque, Synagogue, Temple,
  Constituent, Gated, PrivateDev, PublicHousing,
  Adult, Homeless, Nursing,
  Airport, Bridge, Bus, Ferry, Heliport, Marina, Mile, Intersection,
  NYPDSubway, Pier, Rail, Toll, Transit, Tunnel, WaterNav,
  Island, Lake, River,
  Center, Cemetery, Landmark, POI, Other
],
{ onSelect: onFeatureSelect, onUnselect: onFeatureUnselect });

proprietaryMap.addControl(selectControl);
selectControl.activate();

最佳答案

如果您发布了最小化的代码版本,将对您有所帮助。首先阅读如何minimize your code的方法,然后可以使用jsfiddle.net主持一个小型演示。

关于javascript - 多层OpenLayers SelectFeature,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22184482/

10-09 14:53