2017-08-31 00:40:37 +03:00
|
|
|
|
function PhotosController () {
|
|
|
|
|
this.PHOTO_MARKER_VIEW_SIZE = 40;
|
2017-09-02 20:20:43 +03:00
|
|
|
|
this.photosDataLoaded = false;
|
|
|
|
|
this.photosRequestInProgress = false;
|
2017-08-31 00:40:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PhotosController.prototype = {
|
|
|
|
|
|
|
|
|
|
appendToMap : function(map) {
|
|
|
|
|
this.map = map;
|
|
|
|
|
this.photoLayer = L.markerClusterGroup({
|
2017-09-06 21:50:14 +03:00
|
|
|
|
iconCreateFunction : this.getClusterIconCreateFunction(),
|
2017-08-31 00:40:37 +03:00
|
|
|
|
showCoverageOnHover : false,
|
|
|
|
|
maxClusterRadius: this.PHOTO_MARKER_VIEW_SIZE + 10,
|
|
|
|
|
icon: {
|
|
|
|
|
iconSize: [this.PHOTO_MARKER_VIEW_SIZE, this.PHOTO_MARKER_VIEW_SIZE]
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-09-06 21:50:14 +03:00
|
|
|
|
this.photoLayer.on('click', this.getPhotoMarkerOnClickFunction());
|
2017-08-31 00:40:37 +03:00
|
|
|
|
this.photoLayer.addTo(this.map);
|
|
|
|
|
},
|
|
|
|
|
|
2017-09-02 20:20:43 +03:00
|
|
|
|
showLayer: function() {
|
|
|
|
|
if (!this.photosDataLoaded && !this.photosRequestInProgress) {
|
|
|
|
|
this.callForImages();
|
|
|
|
|
}
|
|
|
|
|
if (!this.map.hasLayer(this.photoLayer)) {
|
|
|
|
|
this.map.addLayer(this.photoLayer);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
hideLayer: function() {
|
|
|
|
|
if (this.map.hasLayer(this.photoLayer)) {
|
|
|
|
|
this.map.removeLayer(this.photoLayer);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2017-09-06 21:50:14 +03:00
|
|
|
|
getPhotoMarkerOnClickFunction() {
|
|
|
|
|
var _app = this;
|
|
|
|
|
return function(evt) {
|
|
|
|
|
var marker = evt.layer;
|
|
|
|
|
var content;
|
|
|
|
|
if (marker.data.hasPreview) {
|
|
|
|
|
var previewUrl = _app.generatePreviewUrl(marker.data.path);
|
|
|
|
|
var img = "<img src=" + previewUrl + "/>";
|
|
|
|
|
//Workaround for https://github.com/Leaflet/Leaflet/issues/5484
|
|
|
|
|
$(img).on('load', function() {
|
|
|
|
|
marker.getPopup().update();
|
|
|
|
|
});
|
|
|
|
|
content = img;
|
|
|
|
|
} else {
|
|
|
|
|
content = marker.data.path;
|
|
|
|
|
}
|
|
|
|
|
marker.bindPopup(content, {
|
|
|
|
|
className: 'leaflet-popup-photo',
|
|
|
|
|
maxWidth: "auto"
|
|
|
|
|
}).openPopup();
|
|
|
|
|
}
|
2017-08-31 00:40:37 +03:00
|
|
|
|
},
|
|
|
|
|
|
2017-09-06 21:50:14 +03:00
|
|
|
|
getClusterIconCreateFunction() {
|
|
|
|
|
var _app = this;
|
|
|
|
|
return function(cluster) {
|
|
|
|
|
var marker = cluster.getAllChildMarkers()[0].data;
|
|
|
|
|
var iconUrl;
|
|
|
|
|
if (marker.hasPreview) {
|
|
|
|
|
iconUrl = _app.generatePreviewUrl(marker.path);
|
|
|
|
|
} else {
|
|
|
|
|
iconUrl = _app.getImageIconUrl();
|
|
|
|
|
}
|
|
|
|
|
var label = cluster.getChildCount();
|
|
|
|
|
return new L.DivIcon(L.extend({
|
|
|
|
|
className: 'leaflet-marker-photo cluster-marker',
|
|
|
|
|
html: '<div class="thumbnail" style="background-image: url(' + iconUrl + ');"></div><span class="label">' + label + '</span>'
|
|
|
|
|
}, this.icon));
|
|
|
|
|
}
|
2017-08-31 00:40:37 +03:00
|
|
|
|
},
|
|
|
|
|
|
2017-09-06 21:50:14 +03:00
|
|
|
|
createPhotoView: function(markerData) {
|
|
|
|
|
var iconUrl;
|
|
|
|
|
if (markerData.hasPreview) {
|
|
|
|
|
iconUrl = this.generatePreviewUrl(markerData.path);
|
|
|
|
|
} else {
|
|
|
|
|
iconUrl = this.getImageIconUrl();
|
|
|
|
|
}
|
|
|
|
|
this.generatePreviewUrl(markerData.path);
|
2017-08-31 00:40:37 +03:00
|
|
|
|
return L.divIcon(L.extend({
|
2017-09-06 21:50:14 +03:00
|
|
|
|
html: '<div class="thumbnail" style="background-image: url(' + iconUrl + ');"></div>',
|
2017-08-31 00:40:37 +03:00
|
|
|
|
className: 'leaflet-marker-photo photo-marker'
|
2017-09-06 21:50:14 +03:00
|
|
|
|
}, markerData, {
|
2017-08-31 00:40:37 +03:00
|
|
|
|
iconSize: [this.PHOTO_MARKER_VIEW_SIZE, this.PHOTO_MARKER_VIEW_SIZE],
|
|
|
|
|
iconAnchor: [this.PHOTO_MARKER_VIEW_SIZE / 2, this.PHOTO_MARKER_VIEW_SIZE]
|
|
|
|
|
}));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
addPhotosToMap : function(photos) {
|
|
|
|
|
var markers = this.preparePhotoMarkers(photos);
|
|
|
|
|
this.photoLayer.addLayers(markers);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
preparePhotoMarkers : function(photos) {
|
|
|
|
|
var markers = [];
|
|
|
|
|
for (var i = 0; i < photos.length; i++) {
|
|
|
|
|
var markerData = {
|
|
|
|
|
lat: photos[i].lat,
|
|
|
|
|
lng: photos[i].lng,
|
2017-09-06 21:50:14 +03:00
|
|
|
|
path: photos[i].path,
|
|
|
|
|
albumId: photos[i].folderId,
|
|
|
|
|
hasPreview : photos[i].hasPreview
|
2017-08-31 00:40:37 +03:00
|
|
|
|
};
|
|
|
|
|
var marker = L.marker(markerData, {
|
|
|
|
|
icon: this.createPhotoView(markerData)
|
|
|
|
|
});
|
|
|
|
|
marker.data = markerData;
|
|
|
|
|
markers.push(marker);
|
|
|
|
|
}
|
|
|
|
|
return markers;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
callForImages: function() {
|
2017-09-02 20:20:43 +03:00
|
|
|
|
this.photosRequestInProgress = true;
|
2017-08-31 00:40:37 +03:00
|
|
|
|
$.ajax({
|
2017-09-02 18:10:18 +03:00
|
|
|
|
'url' : OC.generateUrl('apps/maps/photos'),
|
2017-08-31 00:40:37 +03:00
|
|
|
|
'type': 'GET',
|
2017-09-02 20:20:43 +03:00
|
|
|
|
'context' : this,
|
|
|
|
|
'success': function(response) {
|
|
|
|
|
if (response.length == 0) {
|
|
|
|
|
//showNoPhotosMessage();
|
|
|
|
|
} else {
|
|
|
|
|
this.addPhotosToMap(response);
|
2017-08-31 00:40:37 +03:00
|
|
|
|
}
|
2017-09-02 20:20:43 +03:00
|
|
|
|
this.photosDataLoaded = true;
|
|
|
|
|
},
|
|
|
|
|
'complete': function(response) {
|
|
|
|
|
this.photosRequestInProgress = false;
|
|
|
|
|
}
|
2017-08-31 00:40:37 +03:00
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/* Preview size 32x32 is used in files view, so it sould be generated */
|
|
|
|
|
generateThumbnailUrl: function (filename) {
|
2017-09-23 19:07:56 +03:00
|
|
|
|
return OC.generateUrl('core') + '/preview.png?file=' + encodeURI(filename) + '&x=32&y=32';
|
2017-08-31 00:40:37 +03:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/* Preview size 375x211 is used in files details view */
|
2017-09-06 21:50:14 +03:00
|
|
|
|
generatePreviewUrl: function (filename) {
|
2017-09-23 19:07:56 +03:00
|
|
|
|
return OC.generateUrl('core') + '/preview.png?file=' + encodeURI(filename) + '&x=375&y=211&a=1';
|
2017-09-06 21:50:14 +03:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getImageIconUrl: function() {
|
2017-09-23 19:07:56 +03:00
|
|
|
|
return OC.generateUrl('/apps/theming/img/core/filetypes') + '/image.svg?v=2';
|
2017-08-31 00:40:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|