Leaflet - UTFGrid - add popup - popup

I know it's a beginner question and probably very easy but I can't get it to work. I have a map with 2 utfgrids which show an information about bicycle and hiking routes. It is based on this example:
http://bl.ocks.org/milkbread/6449317
It works fine but I would like to change it this way. When hoovering the existing infobox should show up but when clicking on the route the popup should show up in the place where I clicked (with the same information that shows up in the infobox).
I tried different ways to apply it but I always get an error. Here's a link to my working webiste and a part of the code responsible for the infobox window.
http://wojtas82.zrujnowane.pl/utf2.html#15/54.5027/18.4886/osm-rowerowe-piesze
And the code:
utfGrid2.on('mouseover', function(e){ info.update(e);}).on('mouseout', function(e){ info.update();})
utfGrid1.on('mouseover', function(e){ info.update(e);}).on('mouseout', function(e){ info.update();})
var info = L.control();
info.options.position = 'bottomleft';
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = (props ?
'<img src="img/' + props.data.route +'_'+ props.data.osmc_color +'_'+ props.data.osmc_background +'_'+ props.data.osmc_foreground + '.png" ><br /> ' + "<b>" + props.data.name + "</b><br />" + 'Długość: ' + (props.data.distance ? props.data.distance : '') + ' km' + "<br />" + 'Opis szlaku: ' + (props.data.description ? props.data.description : '') : '');
};
I will be very greatful for help.
Thank you very much.

Have you tried using
L.popup for your popup? Something like
utfGrid1.on('click', function(e) {
if (e.data) {
L.popup()
.setLatLng(e.latlng)
.setContent(e ? '<img src="img/' + e.data.route + '_' + e.data.osmc_color + '_' + e.data.osmc_background + '_' + e.data.osmc_foreground + '.png" ><br /> ' + "<b>" + e.data.name + "</b><br />" + 'Długość: ' + (e.data.distance ? e.data.distance : '') + ' km' + "<br />" + 'Opis szlaku: ' + (e.data.description ? e.data.description : '')).openOn(map);
}
});

Related

Switched from mail app to Gmail app and the function hangs after completion

I built out a script to automatically send out an email based on the results from the form. It was working great and would complete the function in about 10 seconds.
I switched to using GmailApp to send emails so that I can use aliases, however, now my function just hangs after completing the last step, which is assigning the "Email Sent" value and running SpreadsheetApp.flush().
Under the executions page, it shows the function is running upwards of 900+ seconds and has to be manually terminated.
Any thoughts? Appreciate the help!
function sendSurvey() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Test Sheet");
var startRow = 2;
var numRows = 100000;
var dataRange = sheet.getRange(startRow, 1, numRows, 100);
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var npsstatus = row[8];
var csm = row[9];
var emailSent = row[11];
var subject = 'Customer Renewal Survey';
var message = "<HTML><BODY>" +
'<h3>Looks like a customer may require your help!</h3>' + "<br>" +
'<b>Customer Contact: </b>' + " " + row[1] + "<br>" + "<br>" +
'<b>Dedicated CSM: </b>' + " " + row[9] + "<br>" + "<br>" +
'<b>Likelyhood to Recommend: </b>' + " " + row[3] + ' (' + row[8] + ')' + "<br>" + "<br>" +
'<b>What they need help with: </b>' + " " + row[4] + "<br>" + "<br>" +
'<b>Additional Comments: </b>' + " " + row[5] + "<br>" + "<br>" +
'<b>CSM Best Time to Connect: </b>' + " " + row[13] + "<br>" + "<br>" +
"<br>" + "<br>" +
'<img src="cid:image"> <br/>'+
"</BODY></HTML>";
var image = DriveApp.getFileById("");
var imageblob = image.getBlob();
var body = message.replace(/\<br\/\>/gi, '\n').replace(/(<([^>]+)>)/ig, "");
var aliases = GmailApp.getAliases();
Logger.log(aliases);
if (npsstatus == 'Detractor' && emailSent != 'Email Sent') {
GmailApp.sendEmail(primaryEmail, 'Test Survey', body, {htmlBody: message, 'from': aliases[0], name: 'Survey', inlineImages: {image: imageblob}});
sheet.getRange(startRow + i, 12).setValue('Email Sent');
}
SpreadsheetApp.flush();
}
}

Magento 2 - how to load JS template from filesystem in jquery widget

For example, native Magento theme-frontend-blank\web\js\navigation-menu.js has such code:
$.widget('mage.navigationMenu', {
options: {
...
collapsableDropdownTemplate:
'<script type="text/x-magento-template">' +
'<li class="level0 level-top more parent">' +
'<div class="submenu">' +
'<ul><%= elems %></ul>' +
'</div>' +
'</li>' +
'</script>'
And then they do
this.collapsableDropdown = $(
mageTemplate(
this.options.collapsableDropdownTemplate,
{elems: this.elemsToCollapseClone}
)
);
Is it possible to do something like this
collapsableDropdownTemplate: getTemplate(some_relative_path_to_template) ?
instead of
collapsableDropdownTemplate:
'<script type="text/x-magento-template">' +
'<li class="level0 level-top more parent">' +
'<div class="submenu">' +
'<ul><%= elems %></ul>' +
'</div>' +
'</li>' +
'</script>'
My template is a little bit bigger and I want to allow frontend developers to modify it.

Play framework template cannot escape URL

I have this Play template, dynamicLink.scala.html...
#( urlWithQuotes: Html, id: Html, toClick: Html )
#uniqueId_With_Quotes() = {
Html("\"" + (#id) + "_" + scala.util.Random.nextInt.toString + "\"")
}
#defining(uniqueId_With_Quotes()) { uniqueID =>
<a id=#uniqueID class="dynamicLink" href=#urlWithQuotes> #toClick </a>
<script><!--Do stuff with dynamic link using jQuery--></script>
}
It generates a special link with some Javascript. I render this link like so...
#dynamicLink(
Html("#{routes.Controller.action()}"),
Html("MyID"),
Html("Click Me")
)
When I render it, I get...
<a id=
Html("\"" + (MyID) + "_" + scala.util.Random.nextInt.toString + "\"")
class="dynamicLink" href=#{routes.Controler.action()}> Click Me </a>
This is not what I want to render. I want to render this...
<a id="MyID_31734697" class="dynamicLink" href="/path/to/controller/action"> Click Me </a>
How do I make this HTML escape correctly?
* Take #2 - replacing Html params with String *
#(urlWithQuotes: String, id: String, toClickOn: String)
#uniqueId_With_Quotes() = {
Html("\"" + (#id) + "_" + scala.util.Random.nextInt.toString + "\"")
}
#defining(uniqueId_With_Quotes) { uniqueID =>
<a id=#uniqueID class="dynamicLink" href=#urlWithQuotes> #toClickOn </a>
...
}
With...
#dynamicLink2(
"#{routes.Controller.action()}",
"MyID",
"Click Me"
)
Renders...
<a id=
Html("\"" + (MyID) + "_" + scala.util.Random.nextInt.toString + "\"")
class="dynamicLink" href=#{routes.Controller.action()}> Click Me </a>
<script>
...
</script>
* Changing Html to String didn't work *
* Note that " #uniqueId_With_Quotes() " expands into " Html("\"" + (MyID) + "_" + scala.util.Random.nextInt.toString + "\"") ". I want it to actually execute string concatenation. *
Also, this should be obvious, but I want each link and the accompanying jquery to be rendered with an ID that is unique to that link and I don't want the controller to have to worry about assigning these unique id's. My way of doing that is by appending a random number to each id (although it might just be better for the view to have a count). I need to have this stateful behavior in the view because I need "dynamicLink" to be totally transparent to the controller.
Did you tried to use the variables as String types?
#( urlWithQuotes: String, id: String, toClick: String )
I find the solution. You have to pass a Call object.
#dynamicLink(
({routes.Controller.action()}),
"MyID",
"Click Me"
)
Pass those parameters into...
#(urlNoQuotes: Call, id: String = "", toClickOn: String = "")
#uniqueId_With_Quotes() = #{
Html("\"" + (id) + "_" + scala.util.Random.nextInt.toString + "\"")
}
#url() = #{
Html("\"" + urlNoQuotes + "\"")
}
#defining( url() ) { processedURL =>
#defining(uniqueId_With_Quotes()) { uniqueID =>
...
}
}
^ Now it works.

Invoke "markdownify" in a Jekyll Plugin

I am trying to manually call the markdownify filter in a Jekyll plugin. Here is what I have:
module Jekyll
class ColumnBlock < Liquid::Block
include Jekyll::Filters
def initialize(tag_name, markup, tokens)
super
#col = markup
end
def render(context)
text = super
'<div class="col-md-' + #col + '">' + markdownify(text) + '</div>'
end
end
end
Liquid::Template.register_tag('column', Jekyll::ColumnBlock)
I get the following error: Liquid Exception: undefined method 'registers' for nil:NilClass
I am very new to Jekyll and Ruby. What do I have to include when I want to use the markdownify filter?
Why do not call directly the converter??
See the source code
def render(context)
text = super
site = context.registers[:site]
converter = site.getConverterImpl(Jekyll::Converters::Markdown)
'<div class="col-md-' + #col + '">' + converter.convert(text) + '</div>'
end
Update - getConverterImpl is deprecated in Jekyll 3, you should use find_converter_instance instead :
def render(context)
text = super
site = context.registers[:site]
converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
'<div class="col-md-' + #col + '">' + converter.convert(text) + '</div>'

need help Displaying more than 1 response from FQL query is_app_user Or Similar solutions

I am currently trying to get a list of friends who have added the same app via the FQL query.
I am actually doing this for a school project, and apparently, the server where this is going to be saved is not supported via PHP.That is why i am using the JavaScript SDK to code this.
This is actually the first time that I am doing a project in Facebook and everything is extremely new to me and having the graph api is not helping with me with any old documentations at all since many things have been changed and documentation is very scarce >.<.
Currently, I am having problems displaying multiple results (i am only able to do so if i hard code the response)
I've tried using a for loop to print the result but to no avail.
FB.api('/me', function(response) {
showLoader(false);
var query = FB.Data.query('SELECT uid, name, pic_square FROM user WHERE uid
IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user');
query.wait(function(rows) {
for(var i = 0; i< rows.length;i++)
{
document.getElementById('debug').innerHTML =
''+ rows[i].name +"<br />" + "<img src=\""+ rows[i].pic_square +"\" /><br />";
}
});
});
am i doing this wrong in any way? >.<. Any help would be reallllly great!!
Thanks!
Maybe it is the fact that you are stepping over what you are placing in the debug div. Try
document.getElementById('debug').innerHTML +=
Also, you do not have to have a for loop. You can have facebook do it for you by using their forEach function.
To get multiple results returned, I do this:
var linkquery = FB.Data.query('select owner, owner_comment, url from link where owner={0}', response.id);
FB.Data.waitOn([linkquery], function() {
FB.Array.forEach(linkquery.value, function(row) {
document.getElementById('debug').innerHTML += 'FQL Information: '+ "<br />" +
'Your name: ' + row.owner + "<br />" +
'Your comment: ' + row.owner_comment + "<br />" +
'Your link: ' + "<a href='" + row.url + "'>" + row.url + "</a><br /><br />";
});
});
The FB.Array.forEach gets each row.owner and they are being added to the debug div -
document.getElementById('debug').innerHTML +=
with each row that is returned.
Hope that helps