Fancybox title / caption - fancybox

I'm very new to website design and can't write js scripts as yet. My CSS is fairly basic. I'm using FB 1.3.4 and it all works fine but I want to change the format of the image title / caption.
I currently have this format:
"Image 1 of 10 This is the caption for this image. [Photo: a Smith]"
What I want is this:
"This is the caption for this image. [Photo: A Smith]
Image 1 of 10"
Note that the Image 1 of 10 is on a new line. I would also like extra spaces between the end of the image caption and the [Photo: A Smith] although I can't work out how to show it here
My script is:
<script type="text/javascript">
$(document).ready(function() {
$(".fancybox").fancybox({
'transitionIn' : 'none',
'transitionOut' : 'none',
'overlayColor' : '#000000',
'overlayOpacity' : '0.90',
'titlePosition' : 'over',
'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' of ' + currentArray.length + (title.length ? ' ' + title : '') + '</span>';
}
});
});
</script>
My CSS for fancybox-title-over is:
.fancybox-title-over {
position: absolute;
bottom: 0;
left: 0;
color: #FFF;
text-align: left;
}
I know that I need to alter titlePosition to 'inside' but can't get beyond that! Can anyone help me with this? Many thanks.

For your titleFormat, replace this line:
'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' of ' + currentArray.length + (title.length ? ' ' + title : '') + '</span>';
}
with this:
'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
return '<span>'+title+'<br />Image ' + (currentIndex + 1) + ' of ' + currentArray.length + (title.length ? ' ' : '') + '</span>';
}
For the extra spaces you want, you may use the character code (one for each extra space you need) inside your title attribute like
title="This is the caption for this image. [Photo: a Smith]"
Also, change the titlePosition to inside like
'titlePosition' : 'inside'
and last: I wouldn't advice you set the title with position: absolute. You may change the text-align to the left with an inline CSS declaration (after you loaded the fancybox CSS file) though with:
.fancybox-title-inside {
text-align: left;
}

Related

Leaflet JS- Highlight on hover

I created a simple web map and now I am stacked on how to use the highlight function on hover. I tried to use the tutorial on the Leaf js site, but when I am trying to call the highlight function under geoJason variable, it is not working. Basically I want the polygon to be highlighted when hovered. The popup is working just fine.
Here is my script, without the highlight function.
ar map = L.map('map').setView([43.0982, -89.3811], 12);
var googleSat = L.tileLayer('http://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',{
minZoom: 1,
maxZoom: 20,
subdomains:['mt0','mt1','mt2','mt3'],
attribution: '<a href="https://www.google.com/maps" target=_blank> Google Sattellite Map</a>' }).addTo(map);
// Adding the geoJason file and styling it.
var myStyle = {
fillColor: "#2c7fb8",
color: "#f20b0b",
weight: 1,
opacity: 1,
fillOpacity: 0.55
};
// Alder district was a geoJason file and now it saved as js file.
var geojason = L.geoJSON(alderdstricts, {
style:myStyle,
onEachFeature:districtdata,
}).addTo(map);
// Function to bind popup to the geoJason data.
function districtdata(feature, layer){
layer.bindPopup("<span class='headings'>District: </span>" + feature.properties.ALD_DIST + "<br>" +
"<span class='headings'>Representative: </span>" + feature.properties.Representa + "<br>"
+ "<span class='headings'>Contact Representative: </span>" + feature.properties.ContactRep + "<br>"
+ "<span class='headings'>District Population: </span>" + feature.properties.DistrictPo
+ "<span class='headings'></span>" + feature.properties.Image)
};
I added all of my script above except the highlight function and that is where I am stacked.
var map = L.map('map').setView([43.0982, -89.3811], 12);
var googleSat = L.tileLayer('http://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',{ minZoom: 1, maxZoom: 20, subdomains:['mt0','mt1','mt2','mt3'], attribution: ' Google Sattellite Map' }).addTo(map);
// Adding the geoJason file and styling it.
var myStyle = {
fillColor: "#2c7fb8",
color: "#f20b0b",
weight: 1,
opacity: 1,
fillOpacity: 0.55
};
// Alder district was a geoJason file and now it saved as js file.
var geojason = L.geoJSON(alderdstricts, { style:myStyle, onEachFeature:districtdata,
}).addTo(map);
// Function to bind popup to the geoJason data.
function districtdata(feature, layer){
layer.bindPopup("District: " + feature.properties.ALD_DIST + "
" + "Representative: " + feature.properties.Representa + "
" + "Contact Representative: " + feature.properties.ContactRep + "
" + "District Population: " + feature.properties.DistrictPo + "" + feature.properties.Image)
layer.on('mouseover', function(e) {
e.target.setStyle({
fillOpacity: 0.8
});
});
layer.on('mouseout', function(e) {
e.target.setStyle({
fillOpacity: 0.55
});
});
};
I'm not sure what you tried, but this should work. It simply adds a "mouseover" and "mouseout" event handler for each polygon, as well as your pop-up. If this doesn't work, please let me know what errors/behaviour you get.
In general, it's best to provide details on what solutions you have already tried in your question. Also, just FYI, JSON is not a contraction of Jason, it stands for JavaScript Object Notation.

How can I change the behaviour of bindPopup

Good day everybody.
I bought a nice template and leaftlet is used to show maker.
Here is the demo . Actually when you clik on a marker, it open a widnows with a picture and some température value.
I would like to have all of the windows open. Of course, I am going to modify the html, to remove the picture and some information as GPS, and only keep the temperatue value. The goal is to be able to immediately see the temperature boxes below the markers. Optionaly, when I click on the marker it redirect to another page, same you click on the picture.
My first problem, I can not find the jacasvript script which work with the link of marker. The idea would be to cancel the effect of the click, or as I wrote, after we click it open the graph page instead of opening the windows.
My first question: how can I find a do to change the action of the click, on the marker
My second question (may be it be cancel the 1st question :) ), how can I change the behaviour of the bindpopup? Is there way "to tell" to the bindpopup, stay always open?
My thirst question: Or can we add one or two additional nice boxes, which show always the temperature below the marker, and keep the bindPopup, as it is? That would be nice as well
Here is the code of the map line 215
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// OpenStreetMap - Homepage
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function createHomepageOSM(_latitude,_longitude,_nbField){
setMapHeight();
if( document.getElementById('map') != null ){
var map = L.map('map', {
center: [_latitude,_longitude],
zoom: 18,
scrollWheelZoom: false
});
//L.tileLayer('http://openmapsurfer.uni-hd.de/tiles/roadsg/x={x}&y={y}&z={z}', {
L.tileLayer('http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
//subdomains: '0123',
maxZoom: 20,
attribution: 'OpenStreetMap contributors, CC-BY-SA'
}).addTo(map);
var markers = L.markerClusterGroup({
showCoverageOnHover: false
});
function locateUser() {
$('#map').addClass('fade-map');
map.locate({setView : true})
}
$('.geo-location').on("click", function() {
locateUser();
});
$.ajax({
type: "POST",
url: "sql/get_map.mysql.php",
//data:'node=node1',
//data:{node_id:"firstnode", node2:"secondnode", node3:"thirdnode", from:"from", to:"to"}, // Send parameter to get.php
success: result,
error: error,
dataType: "json"
});
function error(data)
{
$('body').addClass('loaded');
alert("Error getting datas from DB");
console.log("Error getting datas from DB");
console.log(data);
}
function result(data){
console.info("data:",data);
var allMarkers=[];
var nhtml = '<img src="assets/img/property-types/vineyard.png">';
for (var i = 0; i < data.properties.length; i++) {
allMarkers.push(L.latLng(data.properties[i]['la'], data.properties[i]['lo']));
//data.properties[i]['b2'] = 0;
if((data.properties[i]['b1']>=data.properties[i]['se'] && data.properties[i]['b1'] < data.properties[i]['se']+1) ||
(data.properties[i]['b2']>=data.properties[i]['se'] && data.properties[i]['b2'] < data.properties[i]['se']+1) ||
(data.properties[i]['b3']>=data.properties[i]['se'] && data.properties[i]['b3'] < data.properties[i]['se']+1) ||
(data.properties[i]['b4']>=data.properties[i]['se'] && data.properties[i]['b4'] < data.properties[i]['se']+1)
)
{
nhtml = '<img src="assets/img/property-types/vineyard-orange.png">';
}
if(((data.properties[i]['b1'] < data.properties[i]['se']) && data.properties[i]['b1'] != null) ||
((data.properties[i]['b2'] < data.properties[i]['se']) && data.properties[i]['b2'] != null) ||
((data.properties[i]['b3'] < data.properties[i]['se']) && data.properties[i]['b3'] != null) ||
((data.properties[i]['b4'] < data.properties[i]['se']) && data.properties[i]['b4'] != null)
)
{
nhtml = '<img src="assets/img/property-types/vineyard-red.png">';
}
else{
nhtml = '<img src="assets/img/property-types/vineyard.png">';
}
var _icon = L.divIcon({
//html: '<img src="' + locations[i][7] +'">',
html: nhtml,
iconSize: [40, 48],
iconAnchor: [20, 48],
popupAnchor: [0, -48]
});
var title = data.properties[i]['station'];
var marker = L.marker(new L.LatLng(data.properties[i]['la'],data.properties[i]['lo']), {
title: title,
icon: _icon
});
var str ='';
if(data.properties[i]['b1'] != null)
{
str = str.concat('<div class="tag price"> ' + data.properties[i]['b1'] + '°C</div>');
}
if(data.properties[i]['b2'] != null)
{
str = str.concat('<div class="tag price"> ' + data.properties[i]['b2'] + '°C</div>');
}
if(data.properties[i]['b3'] != null)
{
str = str.concat('<div class="tag price"> ' + data.properties[i]['b3'] + '°C</div>');
}
if(data.properties[i]['b4'] != null)
{
str = str.concat('<div class="tag price"> ' + data.properties[i]['b4'] + '°C</div>');
}
marker.bindPopup(
'<div class="property">' +
'<a data-field=' + data.properties[i]['id_field'] +'" data-station=' + data.properties[i]['id_station'] +'" href="charts.php?field='+ data.properties[i]['id_field'] +'">' +
'<div class="property-image">' +
'<img src="img/stations/station-' + data.properties[i]['id_station'] + '.jpg">' +
'</div>' +
'<div class="overlay">' +
'<div class="info">' +
'<h3>' + data.properties[i]['station'] + '</h3>' +
'<figure>' + data.properties[i]['da'] + '</figure>' +
'<figure>' + data.properties[i]['la'] + ' ' + data.properties[i]['lo'] +'</figure>' +
str +
'<div class="tag"> ' + data.properties[i]['se'] + '°C</div>' +
'</div>' +
'</div>' +
'</a>' +
'</div>'
);
markers.addLayer(marker);
}
if(_nbField>1){
bounds = L.latLngBounds(allMarkers);
map.fitBounds(bounds,{ padding: [10, 10] });
}
map.addLayer(markers);
map.on('locationfound', onLocationFound);
function onLocationFound(){
$('#map').removeClass('fade-map');
}
$('body').addClass('loaded');
setTimeout(function() {
$('body').removeClass('has-fullscreen-map');
}, 1000);
$('#map').removeClass('fade-map');
}
}
}
My last question, with firefox, id possible "to track" the javascript action?
Feel free to aks complementary question to better understand and help, if I missed to provide information.
Many thanks
You can add a click event to the marker:
marker.on('click',(e)=>{
console.log(e);
});
Show all Popups:
You need to set the options autoClose and closeOnClick to false:
marker.bindPopup(content,{autoClose: false, closeOnClick: false});
You can use Tooltips:
marker.bindTooltip('5.3°C', {direction: 'bottom', permanent: true});
I don't know exactly what do you mean, but it sounds like debugging. Use the developer console with the Debugger.
Thanks for your reply and help
Unfortunately 2. does not work. There is no differences. I added closeButton:true, and that works, but it's not what I need.
marker.bindPopup(
'<div class="property">' +
'<a data-field=' + data.properties[i]['id_field'] +'" data-station=' + data.properties[i]['id_station'] +'" href="charts.php?field='+ data.properties[i]['id_field'] +'#st-'+ data.properties[i]['id_station'] +'">' +
'<div class="property-image">' +
'<img src="img/stations/station-' + data.properties[i]['id_station'] + '.jpg">' +
'</div>' +
'<div class="overlay">' +
'<div class="info">' +
'<h3>' + data.properties[i]['station'] + '</h3>' +
'<figure>' + data.properties[i]['da'] + '</figure>' +
'<figure>' + data.properties[i]['la'] + ' ' + data.properties[i]['lo'] +'</figure>' +
str +
'<div class="tag"> ' + data.properties[i]['se'] + '°C</div>' +
'</div>' +
'</div>' +
'</a>' +
'</div>',{autoClose: true, closeOnClick: false, closeButton: true}
);
I also tried the interesting option with tooltip. Bellow the above code I added
marker.bindTooltip('5.3°C', {direction: 'bottom', permanent: true});
But that print an error message
marker.bindTooltip is not a function
Is there additionally library I have to add for tooltop, or is inlcuded into leafet.
(bindTootip would be great and enough for my need)
Thanks for helping
Cheers

Display 4 numbers for one leaflet marker/point

So, I have weather data that I need to show winds, temperature and dewpoint for one lat/long point.
I am able to show the marker in leaflet as a point but I can not figure out how to draw a point with essentially 4 label's at the 12, 3, 6, and 9 o'clock positions.
My initial thought was to use the marker with DivIcon to create a text marker. one for each category of each point. However, this is obviously not the best way as that would mean that I now have 5 points for each point (one for the marker and one for each of the 4 categories).
My next thought, as somewhat already stated, is to create a marker with 4 labels.
Is this the best way? One marker with 4 labels? If so, how do I code that.
Is there something else I'm not thinking of that would be better.
Any help, guidance and/or code would be very helpful.
Other items. I'm using geoJson files as my data which i have included a sample of. I have also included a picture of what the outcome should look like.
{
"name": "CurrentCondtions",
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"coordinates": [ -63.17, 46.35 ],
"type": "Point"
},
"properties": {
"DateTimeCurCond": "3/21/2018 11:00:00 AM",
"Station": "CAHR",
"Id": "HARRINGTON CDA CS",
"Temperature": "33",
"SusWind": "14",
"GustWind": "",
"PeakWind": "20",
"MaxWind": "20",
"Dewpoint": "19",
"Identifier": "Point"
}
}]}
I found a solution.
return new L.Marker(latlng,
{
icon: new L.DivIcon(
{
className: 'baseCurCondClass',
// html here defines what goes in the div created for each marker
html: '<div id="curConditionPoint" class="baseCurCondClass" style="width:100px;">'
+ '<div class="row">'
+ '<div class="col-sm-12">'
+ '<div class="maxWindClass text-center">' + feature.properties.MaxWind + '</div>'
+ '</div>'
+ '</div>'
+ '<div class="row">'
+ '<div class="col-sm-4">'
+ '<div class="temperatureClass text-right">' + feature.properties.Temperature + '</div>'
+ '</div>'
+ '<div class="col-sm-4">'
+ '<div>C</div>'
+ '</div>'
+ '<div class="col-sm-4">'
+ '<div class="dewpointClass text-left">' + feature.properties.Dewpoint + '</div>'
+ '</div>'
+ '</div>'
+ '<div class="row">'
+ '<div class="col-sm-12">'
+ '<div class="susWindClass text-center">' + feature.properties.SusWind + '</div>'
+ '</div>'
+ '</div>'
+ '</div>',
// and the marker width and height
iconSize: null,
iconAnchor: [50, 50]
})
});
}
.susWindClass { /*bottom*/
color: #003ef7;
}
.maxWindClass { /*top*/
color: #FF0000;
}
.temperatureClass { /*left*/
color: #FFFF00;
position: absolute;
right: 0px;
}
.dewpointClass { /*right*/
color: #D58D14;
position: absolute;
left: 0px;
}

Bing map infobox on hover over a li not displaying

I am working with integration of bing maps into the application. When the search button is clicked after entering the zip code information, the div below will display a list of available stores and a map with pushpin on that. Showing an infobox is working when I hover over the pushpin. But my requirement is that, I have to show the particular infobox to the user, when the user hovers over the list in the left of the maps.
For example here, when I hover over the first result on the left, the corresponding infobox should show in the map. I am unable to figure out why it not working. Appreciate your help in advance. Thank you. Please find below what I have tried so far.
for (var i = 0; i < data.length; i++) {
if (storeLoc && (data[i].metadata.LocationTypeSort == "ja")) {
console.log(counter);
console.log(data);
innerTablecontent += "<tr><td><h4 class='h4-mapDetails-storeName'>" + '<div style="display: inline-block; vertical-align: middle"><svg xmlns="http://www.w3.org/2000/svg" width="25" height="25"><circle cx="12.5" cy="12.5" r="12.5"/><text x="50%" y="17" text-anchor="middle" fill="white" font-size="14" font-weight="bold">' + (+counter) + '</text></svg></div>' +
" " + "<b><span style='margin-top:-20px;display:block;margin-left:45px;'>" + data[i].metadata.LocationName + "</span></b>" + "</h4><p class='p-mapDetails'>" + data[i].metadata.AddressLine + "," + data[i].metadata.Locality + "," + data[i].metadata.AdminDistrict + " " + data[i].metadata.PostalCode + "</p>"
+ "<p class='p-mapDetails'>" + data[i].metadata.Phone + "<span><span class='index hidden'>" + i + "</span> | " + '<a style=" font-family:Helvetica Neue LT Pro Roman,sans-serif;color:#00A7CE" href="">View details</a>' + "</span></p>"+ "<span class='miles-mapDetails'>" +(data[i].metadata.__Distance* 0.6214).toFixed(2)+"mi</span></td></tr>"
locations.push(data[i].getLocation());
var pin1 = createCirclePushpin(data[i].getLocation(), 12.5, 'rgb(0, 0, 0)', 'black', 1, counter);
pin1.metadata = {
//title: counter + "." + " " + data[i].metadata.LocationName,
title: " ",
description: '<div style="display: inline-block; vertical-align: middle; margin-right:10px;"><svg xmlns="http://www.w3.org/2000/svg" width="25" height="25"><circle cx="12.5" cy="12.5" r="12.5"/><text font-weight="bold" x="50%" y="17" text-anchor="middle" fill="white" font-size="14">' + (+counter) + '</text></svg></div>' + "<span class='h4-mapDetails-storeName'>" + data[i].metadata.LocationName + "</span><p style='margin-bottom:-3px;font-family:Helvetica Neue LT Pro Roman,Helvetica,sans-serif;font-style:normal !important;color:#000;font-size:14px;'>" + data[i].metadata.AddressLine + ", " + data[i].metadata.Locality + "," + data[i].metadata.AdminDistrict + " " +
data[i].metadata.PostalCode + "<br>" + data[i].metadata.Phone + "</p>" + "<a>" + '<a style="font-size:14px;font-family:Helvetica Neue LT Pro Roman,Helvetica,sans-serif;color:#00A7CE" href="">View details</a>' + "</a>"
};
Microsoft.Maps.Events.addHandler(pin1, 'mouseover', pushpinClicked);
map.entities.push(pin1);
counter++;
}
Function to call when the list is hovered:
$("#mapDetails").on("mouseover", "table td", function() {
sideTabHoverEvent(hoverdata[$(this)[0].getElementsByClassName('index')[0].innerText]);
})
function sideTabHoverEvent(e) {
if (e) {
//Set the infobox options with the metadata of the pushpin.
infobox.setOptions({
location: e.getLocation(),
//title: e.metadata.title,
description: e.metadata.description,
visible: true
});
}
}
In you sideTabHoverEnt function you are assuming e is the pushpin the user interacted with, but that's not what you are passing in. You are passing in a string (index as a string). Try doing the following:
function sideTabHoverEvent(e) {
if (e) {
//Turn the index string value into a number.
var idx = parseInt(e);
var shape = map.entities.get(idx);
//Set the infobox options with the metadata of the pushpin.
infobox.setOptions({
location: shape.getLocation(),
//title: shape.metadata.title,
description: shape.metadata.description,
visible: true
});
}
}

JS Image Gallery

I am building a portfolio website and would like to use fancy box to create a simple gallery.
I would like all images from one section to reside inside a single folder ('gallery1') and I would like the user to be able to click through all the images in the folder.
This is my html:
<div class="content_image" rel="gallery" href="image01_large.jpg" ><img src="gallery1/image01_small.jpg"/></div>
I am trying to use this jQuery script but it's not working:
<script type="text/javascript">
$("div[rel=gallery]").fancybox({
'transitionIn' : 'none',
'transitionOut' : 'none',
'titlePosition' : 'over',
'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' ' + title : '') + '</span>';
}
});
</script>
Any help would be much apreciated!
You can find a list of jQuery gallery plugins here, updated version here.
You want to use a gallery plugin, rather than small bits of script, as they are coded to handle all of the popular browsers as well as work efficiently with finesse. I recommend finding a suitable option there and trying the sample usage for the plugin.
Edit
Also try this:
<script type="text/javascript">
$(function(){$("div[rel=gallery]").fancybox({
'transitionIn' : 'none',
'transitionOut' : 'none',
'titlePosition' : 'over',
'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' ' + title : '') + '</span>';
}
})});
</script>