简体   繁体   中英

OpenLayers SelectFeature on several layers

I am adding several KML layers (88) to an OpenLayers map using the LayerSwitcher. I have added all the layers to a SelectFeature control. However, once I add more than 77 layers to the map using OpenLayers.Map.addLayers the SelectFeature's onSelect function never gets called.

It doesn't seem to be related to the KML layers as I can remove any 11 from the addLayers call and the rest of the layers will work fine. NOTE: I do not have to remove anything from the SelectFeature constructor.

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();

It would be easier to help you if you published a minimized version of your code. Read how to minimize your code first, then you could use jsfiddle.net to host a small demo.

@alexdube77 Thanks for your help. You got me pointed in the right direction.

While creating the minimized version I found the issue. I had to move where I added my Marker, Polyline, and Label layer from after the layers above to before the layers above. This caused these layers to be drawn below the layers above and made the KML layers clickable. I also had to add the following code and call it after adding all the layers to make the markers clickable:

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';
  }
}

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