2017-10-11 118 views
2

在地圖上,我繪製了一個多邊形,並且當我單擊多邊形的僅限邊界時,我想彈出一些信息。 你有任何解決方案來強制選擇邊界嗎?openlayers 3 - 單擊多邊形邊界

  var featureContext = new ol.Feature({ 
       geometry: new ol.geom.Polygon([polyCoords]) 
      }) 

      featureContext.setStyle(
       new ol.style.Style({ 
        stroke: new ol.style.Stroke({ 
         color: context[cc].displayColor, 
         width: 3 
        }) 
       }) 
      ); 

      var layerContext = new ol.layer.Vector({ 
       source: new ol.source.Vector({ 
        features: [featureContext] 
       }) 
      }); 
      map.addLayer(layerContext); 

我已經把現在做:

map.on('singleclick', function(evt) { 
     if (evt.dragging) { 
      return; 
     } 
     var feature = map.forEachFeatureAtPixel(map.getEventPixel(evt.originalEvent), function(feature) { 
      return feature; 
     }); 
     if (feature) { 
      popUp(feature); 
     } 
    }); 

但是這將選擇多邊形(面積等)和彈出信息在多邊形的一切。

感謝您的幫助。

回答

0

不是最優的,但如果您將邊界繪製爲一條線(除多邊形之外),並且只有在要素是一條線時才接受?還要在指向多邊形的線的屬性中添加一個ID。 必須有一些更好的方法......但如果你只有幾個小的多邊形,這沒關係。