Маркеры не отображаются на карте - PullRequest
0 голосов
/ 10 октября 2019

Я пытаюсь сделать свою первую карту с OpenLayers, но у меня проблема, у меня нет маркеров на карте ...

Но я думаю, что функция addMarkers не работает должным образом, потому чтоУ меня есть только карта и нет маркеров ...

addMarkers: function () 
{
    console.log('addMarkers');

    for (var i = 0; i < this.listPlaces.length; i++) {
        var icon = this.getIconFunction('', this.listPlaces[i]);

        if (icon) {
            this.icons.push(icon);
        }
    }

    this.vectorSource = new ol.source.Vector({
        features: this.icons,
        extractStyles: false
    });

    this.vectorLayer = new ol.layer.Vector({
        name: 'Markers',
        source: new ol.source.Cluster({
            distance: 40,
            source: this.vectorSource
        }),
        style: function(feature) 
        {
            console.log('styleFunction');

            var img = RESSOURCES_PATH + '/images/icons/cluster.svg';
            var imgW = 70;
            var imgH = 70;
            var currentClusterHeight = Math.round(imgH);
            var currentClusterWidth = Math.round(imgW);
            var size = feature.get('features').length;

            if (feature.getProperties().features.length === 1) {
              var currentPoint = feature.getProperties().features[0];
              if (currentPoint.getProperties().marker) {
                img = currentPoint.getProperties().marker;
              }
            }

            var style = new ol.style.Style({
              image: new ol.style.Icon(({
                anchor: [currentClusterWidth / 2, currentClusterHeight / 2],
                anchorXUnits: 'pixels',
                anchorYUnits: 'pixels',
                src: img
              })),
              text: new ol.style.Text({
                text: size.toString(),
                fill: new ol.style.Fill({
                  color: '#fff'
                }),
              })
            });

            return style;
        }
    });

    // Add markers to map
    this.map.addLayer(this.vectorLayer);
},

В консоли я не увидел свой 'console.log (' styleFunction ');', это проблема?

Все JS здесь: https://0bin.net/paste/gR2zNZDsgh2sWwPm#RICq87ZHMDrNLaw9DapBgd4d9AVtfB2WlERTN2CuPu7

Заранее спасибо, если вы можете сделать что-то для меня.

...