When trying to create an app that one of its functions is to search for certain places near a given point, I have encountered this error:
SequelizeDatabaseError: st_distance_sphere (geometry, geometry)
function does not exist.
I see in the Doc that it works but I can't see the failure.
const distance= Sequelize.fn('ST_Distance_Sphere', Sequelize.col('ubication'), ubication);
This is the conflict code
and this is the other variable
const ubication = Sequelize.literal(`ST_GeomFromText('POINT( ${meeti.ubication.coordinates[0]} ${meeti.ubication.coordinates[1]} )' )`);
Thank you very much in advance
The function name you are using is obsolete. The proper name is ST_DistanceSphere
Related
I get a syntax error when I insert this particular line
pp = pp.map(x => precise(x));
into my code. No other line gets the same error, and the code runs fine without this line. Please note that I am using google scripts editor.
pp is an array.
The function precise is coded like this.
function precise(x) {
return Number.parseFloat(x).toPrecision(3);
}
I have isolated the code and tried it out in another online JavaScript editor, which works without a problem.
Is it a problem with Google Apps Script?
Are you sure that Google Apps Scripts is compatible with ES6 syntax such as arrow functions?
You could try changing your code to the following and see if it solves the issue:
pp = pp.map(function(x) { return precise(x) });
As the method precise returns the string, You can directly pass the function reference to .map() method
pp = pp.map(precise);
or, You could do
pp = pp.map(function(x) { return precise(x) });
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers
How do I get a list of all the properties of GlobalEventHandlers?
Specifically, I want to test if a passed string is a property of GlobalEventHandlers, something like:
console.log(GlobalEventHandlers.includes('onClick')); // true
console.log(GlobalEventHandlers.includes('fizzBuzz')); // false
The only real way to get all of them is to build the list yourself, but you can loop over the keys in the window object and look for keys that start with on
Object.keys(window).filter(k => !k.indexOf('on'))
BUT that is not going to return just the built in ones. If someone set a custom event listener like
window.onfoobar = function () {}
than that will also show up in the result.
I wrote an npm package that does that for you.
Full usage and installation: global-event-handlers-map.
it extracts every global event handler under every object that exists under window (including window).
for example, by calling:
const getGlobalEventsHandlersMap = require('global-event-handlers-map');
const gehsMap = getGlobalEventsHandlersMap('WebSocket');
you will get the following result (gehsMap would be):
{
"WebSocket": [
"onopen",
"onerror",
"onclose",
"onmessage"
]
}
by calling getGlobalEventsHandlersMap() with no arguments, you will receive ALL global event handlers.
the README file should be very indicative and should help you understand how to get everything you need from that package.
you can either:
execute the code once in the browser, get the results, and use that map statically in your code.
integrate the library in your code and by that dynamically create the map every time your code runs in the browser.
the best way depends on your needs, and should be your call. i can help you understand which way is best for you depends on your needs.
hope that helps!
I am developing a Single Page Application in Clojurescript, and I want to use TinyMCE as a WYSIWYG editor for certain fields. For space efficiency, I want to eventually minify the project using the google clojure compiler in advanced mode. Since the tinymce dev javascript files seems to be unsuitable for use as an extern file, I'm forced to write my own.
There is one particular function call that I can't get to work. In clojurescript, I call:
(.setContent (.get js/tinymce id) cont)
which I'd imagine would compile to something like:
tinymce.get(id).setContent(cont);
I have tried many different function definitions in my externs, yet I keep getting an error:
TypeError: tinymce.get(...).Tl is not a function
Which tells me setContent gets obscured away by the compiler. My current extern file looks like this:
//all seems to be well here...
var tinymce;
tinymce.get = function(name){};
tinymce.remove = function(node){};
tinymce.init = function(editor){};
tinymce.on = function(name, callback, prepend, extra){};
//tinymce setContent attempts
var tinymce.Editor;
tinymce.Editor.prototype.setContent = function(content){};
tinymce.Editor.setContent = function(content){};
tinymce.get(name).setContent = function(content){};
tinymce.get(name).prototype.setContent = function(content){};
var Editor;
Editor.prototype.setContent = function(content){};
Editor.setContent = function(content){};
Which currently is kind of a throw-everything-against-the-wall-and-see-what-sticks attempt. The object get(name) returns should be in the namespace tinymce.Editor.
Is there a proper way of writing an externs to catch these chained function calls? Or is there a way to rewrite the first code snippet so my externs properly preserve the function names? Thanks in advanced.
This line:
var tinymce.Editor;
is not syntactically correct in JS:
SyntaxError: missing ; before statement
Remove it and leave this line:
tinymce.Editor.prototype.setContent = function(content){};
This should work fine.
Also you may always fall back to accessing properties via string literals which will never be renamed:
(require '[goog.object :as gobj])
(gobj/get your-object "i-wont-be-renamed")
I need to know if there is a way to extract the script name when calling a variable or a function in javascript. The scenario is running chrome through webdriver or node and when calling for example window.jQuery.Animation I would like to get the filename (i.e., jquery.js) where this function is defined. I know in chrome you can click on 'show function code' and jump to the file, however I am looking to do the same in a programmatic way.
Thanks
Maybe an Error object can help here:
var e = new Error;
console.log(e.stack);
The first two lines of the stack:
Error
at Object.<anonymous> (/home/joost/src/test/testfile.js:3:9)
You have no such way of doing that in pure JavaScript.
The different javascript engines (spiderMonkey, V8, ...) will often compile the javascript code in some way, so you will lose such information in the process.
To know where a function comes from, you will require this function's source map. If you don't know them, source maps will map a script to it's originating filename / line number.
The mozilla sourceMap library will help you with that.
Though, you will have to generate a source map for your file that uses jQuery as well.
if your script.js is like
var a = jQuery.method // this is line 10
^ col 9
You will have to execute
var sourceMap = require('source-map');
consumer = new SourceMapConsumer('script.map');
consumer.originalPositionFor({ line: 10, column: 9 })
// { source: 'jQuery.js',
// line: 12971,
// column: 222,
// name: 'whatever' }
You'll be then able to query the original position and filename where that object is declared.
So, I am using the ArcGIS API (javascript) in order to get some information from objects in a featurelayer. The first step here should be detecting which object the user clicked. I am using queries for this. For some reason though, I cannot seem to execute my queries. Every time the execute method is called, the console replies that "Object doesn't support property or method 'execute'". The relevant part of the code is as follows:
thema_4_Verblijf = new FeatureLayer("https://services.arcgisonline.nl/arcgis/rest/services/Basisregistraties/BAG/MapServer/4");
map_Thema_4.addLayer(thema_4_Verblijf);
thema_4_Verblijf.on("click", thema_4_Verblijf_Click);
function thema_4_Verblijf_Click(evt){
var query = new Query();
query.returnGeometry = true;
query.outFields = ["*"];
query.geometry = evt.mapPoint;
var queryTask = new QueryTask("https://services.arcgisonline.nl/arcgis/rest/services/Basisregistraties/BAG/MapServer/4");
queryTask.execute(query,showResults);
};
function showResults(featureSet){
//will show results
}
At first, I thought this had to do with me not defining the requirements correctly at the start of the script. This cannot be possible though as execute is a method of QueryTask, and 'new QueryTask' itself completes without any errors. Nonetheless, my requirements as defined are:
require([...
"esri/geometry",
"esri/tasks/query",
"esri/tasks/QueryTask",
"esri/tasks/FeatureSet"
],
function startMap(
...
Query,
QueryTask,
...
Any thoughts on what could be wrong here...?
Alright, so this has been answered..
I tried defining querytask with the legacy module and for some reason that worked.
var queryTask = new esri.tasks.QueryTask(...);
I have experienced this before during my current project, somewhere legacy and AMD modules must be mixed up, even though all my requires have been defined using the AMD way.
So yes, this particular question has been fixed (as in: I can continue) but if someone could explain how the two modules can get mixed up, that would be appreciated.