2016-10-26 2 views
0

openlayers 3에서 히트 맵을 클릭하면 모든 기능을 사용하고 싶습니다 ... 가능하거나 불가능합니까? 히트 맵에서 기능을 계산하고 히트 맵 총 카운트 기능 라벨을주는 방법은 무엇입니까? 감사합니다히트 맵 openlayers3의 기능 얻기

답변

0

Openlayers3 쉽게 할 수있는, 당신은 모든 기능을 얻기 위해 getFeatures()를 사용할 수 있습니다.

var features = heatlayer.getSource().getFeatures() 
alert('count: '+features.length); 

이 메서드는 길이를 계산할 수 있도록 모든 기능을 포함하는 배열을 반환합니다.

<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
    <title>heatlayer count example</title> 
 
    <link rel="stylesheet" href="https://openlayers.org/en/v3.20.1/css/ol.css" type="text/css"> 
 
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x --> 
 
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script> 
 
    <script src="https://openlayers.org/en/v3.20.1/build/ol.js"></script> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.min.js"></script> 
 
    <style> 
 
     .map { 
 
     max-width: 566px; 
 
     } 
 
    </style> 
 
    </head> 
 
    <body> 
 
    <div id="map" class="map"></div> 
 
    <script> 
 
     var raster = new ol.layer.Tile({ 
 
     source: new ol.source.OSM() 
 
     }); 
 
     
 
     var heatlayer = new ol.layer.Heatmap({ 
 
     source: new ol.source.Vector(), 
 
     blur: parseInt(14), 
 
     radius: parseInt(8) 
 
     }); 
 
     
 
      var adddata = [[104.807799,30.232233],[106.803599,31.233225]]; 
 
     //addfeature 
 
     for(var i = 0;i < adddata.length ; i++){ 
 
     var feature = new ol.Feature({ 
 
      geometry:new ol.geom.Point([adddata[i][0],adddata[i][1]]) 
 
     }); 
 
     heatlayer.getSource().addFeature(feature); 
 
    } 
 
     
 

 
     var map = new ol.Map({ 
 
     layers: [raster,heatlayer], 
 
     target: 'map', 
 
     controls: ol.control.defaults({ 
 
      attributionOptions: /** @type {olx.control.AttributionOptions} */ ({ 
 
      collapsible: false 
 
      }) 
 
     }), 
 
     view: new ol.View({ 
 
\t \t projection: 'EPSG:4326', 
 
      center:[104.07, 30.7], 
 
      zoom: 2 
 
     }) 
 
     }); 
 

 
     map.on('click', function(event){ 
 
     var features = heatlayer.getSource().getFeatures() 
 
     alert('count: '+features.length); 
 
     }); 
 
     
 
    </script> 
 
    </body> 
 
</html>