Features auto id

by Vladimir Vershinin

HTML

<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v5.3.0/build/ol.js"></script>
<script src="https://unpkg.com/[email protected]/dist/fakerator.min.js"></script>
<script src="https://unpkg.com/[email protected]/lib/index.umd.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/lib/style.css">
<div id="app">
  <p v-if="loading">
    Loading features, please wait...
  </p>
  <p v-if="features.length > 0">
    Loaded features: {{ features.map(feature => feature.id) }}
  </p>
  <vl-map ref="map" data-projection="EPSG:4326">
    <vl-view :zoom.sync="zoom" :center.sync="center"></vl-view>

    <vl-layer-tile>
      <vl-source-osm></vl-source-osm>
    </vl-layer-tile>

    <vl-layer-vector>
      <vl-source-vector :features.sync="features"></vl-source-vector>

      <vl-style-func :factory="styleFactory" />
    </vl-layer-vector>
  </vl-map>
</div>

CSS

html, body, #app {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

.layers {
  position: absolute;
  top: 10px;
  left: 50px;
  z-index: 1;
}

JavaScript

const fakerator = Fakerator();

new Vue({
  el: '#app',
  data() {
    return {
      zoom: 2,
      center: [0, 0],
      features: [],
      loading: false,
    }
  },
  mounted() {
    this.loading = true
    this.loadFeatures().then(features => {
      this.features = features.map(Object.freeze)
      this.loading = false
    })
  },
  methods: {
    // emulates external source
    loadFeatures() {
      return new Promise(resolve => {
        setTimeout(() => {
          // generate GeoJSON random features
          resolve([{
              type: "Feature",
              geometry: {
                type: 'Point',
                coordinates: [5.44921875, 26.745610382199022],
              },
              properties: {
                name: fakerator.names.name(),
                country: fakerator.address.country(),
                city: fakerator.address.city(),
                street: fakerator.address.street(),
                active: false,
              },
            },
            {
              type: "Feature",
              geometry: {
                type: 'Polygon',
                coordinates: [
                  [
                    [
                      -23.37890625,
                      45.336701909968134,
                    ],
                    [
                      -49.39453125,
                      33.137551192346145,
                    ],
                    [
                      -47.4609375,
                      3.6888551431470478,
                    ],
                    [
                      -20.390625,
                      -8.059229627200192,
                    ],
                    [
                      -13.0078125,
                      20.138470312451155,
                    ],
                    [
                      -23.37890625,
                      45.336701909968134,
                    ],
                  ],
                ],
              },
              properties: {
                name:...