<commit_before>define([
    'streamhub-map/views/map-view',
    'streamhub-sdk/content/views/content-list-view',
    'streamhub-map/content/content-point',
    'hgn!streamhub-map/views/templates/marker',
    'inherits',
    'streamhub-map/leaflet',
    'streamhub-map/leaflet-markercluster'],
function (
    MapView,
    ContentListView,
    ContentPoint,
    MarkerTemplate,
    inherits,
    L) {

    var ContentMapView = function (opts) {
        this._contentToMarkerMap = {};
        this._markers = new L.MarkerClusterGroup({
            showCoverageOnHover: false,
            zoomToBoundsOnClick: true,
            maxClusterRadius: 100,
            spiderfyDistanceMultiplier: 2,
            iconCreateFunction: function(cluster) {
                var childMarkers = cluster.getAllChildMarkers();
                var clusterIconHtml;
                for (var i=0; i < childMarkers.length; i++) {
                    var childMarker = childMarkers[i];
                    clusterIconHtml = childMarker._icon ? childMarker._icon.innerHTML : childMarker.options.icon.options.html;
                    if (clusterIconHtml) {
                        break;
                    }
                }

                var $clusterIcon = $(clusterIconHtml);
                $clusterIcon.append('<div class="hub-map-marker-badge">'+childMarkers.length+'</div>');
                return new L.ContentDivIcon({
                    className: 'hub-map-collection-marker',
                    html: '<div class="hub-map-marker-bg">'+$clusterIcon.html()+'</div>',
                    iconSize: [54,55],
                    iconAnchor: [27,27.5]
                });
            }
        });

        MapView.call(this, opts);
    };
    inherits(ContentMapView, MapView);

    ContentMapView.prototype.add = function (content) {
        if (! content._annotations.geocode || ! content._annotations.geocode.latitude || ! content._annotations.geocode.longitude ) {
            return;
        }

        // Adapt Content to ContentPoint
        var contentPoint = new ContentPoint(content);

        MapView.prototype.add.call(this, contentPoint);
    };

    ContentMapView.prototype.setElement = function (el) {
        MapView.prototype.setElement.apply(this, arguments);

        var self = this;

        this.$el.on('focusDataPoint.hub', function (e, focusContext) {
            self._displayDataPointDetails(focusContext.contentItems);
        });

        this._markers.on('click', function (e) {
            var content = e.layer.options.icon.options.content;
            self.$el.trigger('focusDataPoint.hub', { contentItems: [content] });
        });

        this._markers.on('clusterclick', function (e) {
            if (self._map.getMaxZoom() !== self._map.getZoom()) {
                return;
            }

            var content = [];
            for (var i=0; i < e.layer._markers.length; i++) {
                content.push(e.layer._markers[i].options.icon.options.content);
            }
            self.$el.trigger('focusDataPoint.hub', { contentItems: content });
        });
    };

    ContentMapView.prototype._drawMarker = function (dataPoint) {
        var marker = new L.Marker(
            new L.LatLng(dataPoint.lat, dataPoint.lon), {
                icon: new L.ContentDivIcon({
                    className: 'hub-map-content-marker',
                    html: MarkerTemplate({
                        thumbnail_url: dataPoint.getContent().attachments[0].thumbnail_url
                    }),
                    iconSize: [44,48],
                    iconAnchor: [22,48],
                    content: dataPoint.getContent()
                })
            }
        );
        this._markers.addLayer(marker);
        this._map.addLayer(this._markers);

        this._contentToMarkerMap[dataPoint.getContent().id] = marker;
    };

    ContentMapView.prototype._displayDataPointDetails = function (contentItems) {
        if (! this.modal || ! contentItems || ! contentItems.length) {
            return;
        }

        var modalContentView = new ContentListView();
        for (var i=0; i < contentItems.length; i++) {
            modalContentView.more.write(contentItems[i]);
        }

        this.modal.show(modalContentView);
    };

    ContentMapView.prototype._removeDataPoint = function (dataPoint) {
        // Remove marker
        this._markers.removeLayer(this._contentToMarkerMap[dataPoint.getContent().id]);
        MapView.prototype._removeDataPoint.call(this, dataPoint);
    };

    return ContentMapView;
});
<commit_msg>Fix bug with setting marker thumbnail_url when content has no image. Fix bug with curated tweets with flipped lat/lon<commit_after>define([
    'streamhub-map/views/map-view',
    'streamhub-sdk/content/views/content-list-view',
    'streamhub-map/content/content-point',
    'hgn!streamhub-map/views/templates/marker',
    'inherits',
    'streamhub-map/leaflet',
    'streamhub-map/leaflet-markercluster'],
function (
    MapView,
    ContentListView,
    ContentPoint,
    MarkerTemplate,
    inherits,
    L) {

    var ContentMapView = function (opts) {
        this._contentToMarkerMap = {};
        this._markers = new L.MarkerClusterGroup({
            showCoverageOnHover: false,
            zoomToBoundsOnClick: true,
            maxClusterRadius: 100,
            spiderfyDistanceMultiplier: 2,
            iconCreateFunction: function(cluster) {
                var childMarkers = cluster.getAllChildMarkers();
                var clusterIconHtml;
                for (var i=0; i < childMarkers.length; i++) {
                    var childMarker = childMarkers[i];
                    clusterIconHtml = childMarker._icon ? childMarker._icon.innerHTML : childMarker.options.icon.options.html;
                    if (clusterIconHtml) {
                        break;
                    }
                }

                var $clusterIcon = $(clusterIconHtml);
                $clusterIcon.append('<div class="hub-map-marker-badge">'+childMarkers.length+'</div>');
                return new L.ContentDivIcon({
                    className: 'hub-map-collection-marker',
                    html: '<div class="hub-map-marker-bg">'+$clusterIcon.html()+'</div>',
                    iconSize: [54,55],
                    iconAnchor: [27,27.5]
                });
            }
        });

        MapView.call(this, opts);
    };
    inherits(ContentMapView, MapView);

    ContentMapView.prototype.add = function (content) {
        if (! content._annotations.geocode || ! content._annotations.geocode.latitude || ! content._annotations.geocode.longitude ) {
            return;
        }

        // Adapt Content to ContentPoint
        var contentPoint = new ContentPoint(content);

        MapView.prototype.add.call(this, contentPoint);
    };

    ContentMapView.prototype.setElement = function (el) {
        MapView.prototype.setElement.apply(this, arguments);

        var self = this;

        this.$el.on('focusDataPoint.hub', function (e, focusContext) {
            self._displayDataPointDetails(focusContext.contentItems);
        });

        this._markers.on('click', function (e) {
            var content = e.layer.options.icon.options.content;
            self.$el.trigger('focusDataPoint.hub', { contentItems: [content] });
        });

        this._markers.on('clusterclick', function (e) {
            if (self._map.getMaxZoom() !== self._map.getZoom()) {
                return;
            }

            var content = [];
            for (var i=0; i < e.layer._markers.length; i++) {
                content.push(e.layer._markers[i].options.icon.options.content);
            }
            self.$el.trigger('focusDataPoint.hub', { contentItems: content });
        });
    };

    ContentMapView.prototype._drawMarker = function (dataPoint) {
        var thumbnail_url;
        var contentItem = dataPoint.getContent();
        if (contentItem.attachments.length && contentItem.attachments[0].thumbnail_url) {
            thumbnail_url = contentItem.attachments[0].thumbnail_url;
        } else if (contentItem.author && contentItem.author.avatar) {
            thumbnail_url = contentItem.author.avatar;
        }


        var latlng;
        if (contentItem.source === 'twitter') {
            latlng = new L.LatLng(dataPoint.lon, dataPoint.lat);
        } else {
            latlng = new L.LatLng(dataPoint.lat, dataPoint.lon);
        }
        var marker = new L.Marker(
            latlng, {
                icon: new L.ContentDivIcon({
                    className: 'hub-map-content-marker',
                    html: MarkerTemplate({
                        thumbnail_url: thumbnail_url || ''
                    }),
                    iconSize: [44,48],
                    iconAnchor: [22,48],
                    content: dataPoint.getContent()
                })
            }
        );
        this._markers.addLayer(marker);
        this._map.addLayer(this._markers);

        this._contentToMarkerMap[dataPoint.getContent().id] = marker;
    };

    ContentMapView.prototype._displayDataPointDetails = function (contentItems) {
        if (! this.modal || ! contentItems || ! contentItems.length) {
            return;
        }

        var modalContentView = new ContentListView();
        for (var i=0; i < contentItems.length; i++) {
            modalContentView.more.write(contentItems[i]);
        }

        this.modal.show(modalContentView);
    };

    ContentMapView.prototype._removeDataPoint = function (dataPoint) {
        // Remove marker
        this._markers.removeLayer(this._contentToMarkerMap[dataPoint.getContent().id]);
        MapView.prototype._removeDataPoint.call(this, dataPoint);
    };

    return ContentMapView;
});

{'fraction_non_alphanumeric': 0.12038457604582183, 'fraction_numerical': 0.005216324025774778, 'mean_word_length': 1.9345738295318127, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7604843', 'n_tokens_mistral': 2746, 'n_tokens_neox': 2631, 'n_words': 432}