我正在使用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();
答案 0 :(得分:0)
如果您发布了代码的最小化版本,那么帮助您会更容易。首先阅读如何minimize your code,然后你可以使用jsfiddle.net来举办一个小型演示。
答案 1 :(得分:0)
@ alexdube77感谢您的帮助。你让我指出了正确的方向。
在创建最小化版本时,我发现了问题。我必须移动我从上面的图层之后到上面的图层之前添加我的标记,折线和标签图层的位置。这导致这些图层被绘制在上面的图层下方,并使KML图层可以点击。我还必须添加以下代码并在添加所有图层后调用它以使标记可单击:
function checkMarkerZIndex() {
var olDivs = document.querySelectorAll('.olLayerDiv');
for (var i = 0; i < olDivs.length; i++) {
if (olDivs[i].id.indexOf('OpenLayers_Layer_Markers') > -1)
olDivs[i].style.zIndex = '2000';
}
}