SOURCE

console 命令行工具 X clear

                    
>
console
var vectorLayer = new ol.layer.Vector({
    source: new ol.source.Vector()
})

var map = new ol.Map({
    target: 'map',
    layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM()
        }),
        vectorLayer
    ],
    view: new ol.View({
        center: ol.proj.fromLonLat([116.39123296750768, 39.907180309385694]),
        zoom: 14
    })
});

var geojson = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              116.38559818267822,
              39.90611510622161
            ],
            [
              116.39722824096681,
              39.906444307614265
            ],
            [
              116.39632701873778,
              39.92207955158697
            ],
            [
              116.38534069061281,
              39.92161877439387
            ],
            [
              116.38465404510497,
              39.921125081103234
            ],
            [
              116.38559818267822,
              39.90611510622161
            ]
          ]
        ]
      }
    }
  ]
}

var featureCollection = new ol.format.GeoJSON({
    dataProjection: 'EPSG:4326',
    featureProjection: 'EPSG:3857'
}).readFeatures(geojson)

vectorLayer.getSource().addFeatures(featureCollection)

map.on('click', event => {
    vectorLayer.getFeatures(event.pixel).then(features => {
        console.log(features)
    })
})
<div id="map" class="map"></div>
.map {
    height: 600px;
    width: 100%;
}

本项目引用的自定义外部资源