I am designing a web-page to allow users to edit geographical features on the fly. I use a simple function to calculate road lengths that they have been created. The issue is that I have to reload the page to update the statistics. The function I use to create the statistics is below, how can I make this run to update the stat's without reloading the page:
function postExecute() {
var roadLengthCalc = Math.round(RoadLength['RoadLength']);
document.getElementById("Road_Length").innerHTML = roadLengthCalc;
}
You can use the setInterval function:
For example:
setInterval(function(){ postExecute(); },3000);
The 3000 is the frequency in milliseconds.
Documentation:
You can find the full documentation for this function at the link below:
http://www.w3schools.com/jsref/met_win_setinterval.asp
JSFiddle working example:
http://jsfiddle.net/d5DkA/
Related
having some issues with the HERE maps api outputting the data i'm requesting too many times. I need it to output only once every 10 seconds, however it is doing it far more times than that.
The code I have here is as follows:
function getMapCorners() {
var mapView = map.getViewModel();
var mapCorners = mapView.b.bounds.cb.X;
var corners = [mapCorners[9], mapCorners[10], mapCorners[3], mapCorners[4]];
console.log(corners);
}
map.addEventListener("mapviewchange", function () {
setTimeout(getMapCorners, 10000);
});
I need to grab these specific co-ordinates as this is feeding into another API that is creating markers on the map in specific areas. When zooming in, it does wait 10 seconds to run the function, but then it throws out the co-ordinate changes for every change in the map's view model during that 10 seconds.
The other API has a request limit of 100 every 15 minutes. So I need this to change so that it will run the function every 10 seconds, and it will only output the information for the final viewModel when the function runs.
If you want to run getMapCorners once every 10 seconds, then do this:
function doEveryTenSeconds(){
getMapCorners();
setTimeout(doEveryTenSeconds, 10000);
}
doEveryTenSeconds();
First, please don't use internal name of objects like .b.bounds.cb.X - b, cb, X are defined by compilation of js library and will be changed for new version of JS API. Please use for it a name of methods and objects described in documentation: https://developer.here.com/documentation/maps/3.1.29.0/api_reference/H.map.ViewModel.html#getLookAtData like:
var mapCorners = map.getViewModel().getLookAtData().bounds.getBoundingBox();
Second, the map event 'mapviewchange' runs multiply times during interacting with map therefore you get multiply times run of function getMapCorners. Suggestion to achieve what you want:
function getMapCorners() {
console.log("getMapCorners!!!", map.getViewModel().getLookAtData().bounds.getBoundingBox());
map.addEventListener("mapviewchange", onMapViewChange);
}
function onMapViewChange() {
map.removeEventListener("mapviewchange", onMapViewChange);
setTimeout(getMapCorners, 10000);
}
See please full code there on https://jsfiddle.net/1m8fvLjy/1/
I have a search function that I need to fire about 2 seconds after the user stops typing in a search bar (which then filters entries of a table). If the user types or otherwise edits the contents of the search bar within those 2 seconds, the timer resets back to 2 seconds before the search request fires.
If I need to, I will post example code of what I have if requested, but I have little idea what should be included at the moment.
Edit: Tags and fact that the project is in Laravel is irrelevant.
This is not a laravel problem but off JavaScript
this should get you started in what you're trying to achieve:
var countDown;
const functionForSearching=()=>{
//do your searching here
}
const delayedSearch() {
clearTimeout(countDown);
countDown = setTimeout(()=>{
//call your search Function Here
functionForSeaching()
},2000);
}
How would I use the getLogo function to display the Spil Logo on inside my HTML5 game?
Here's the link to their docs
http://developers.spilgames.com/wiki/Developer_Platform_-_Learning_center_-_HTML5_API_getLogo
I don't understand if it's meant to display their logo automatically, or if I'm meant to do something with the object data it returns, and if so how would use it?
We provide basically only two properties: a URL to the image and a function. What you need to do within your game is attach the Javascript link to the image.
A typical logo implementation looks like this for a DOM implementation. But of course this depends on the nature of your game and if you're using a framework:
GameAPI.loadAPI(function (apiInstance) {
// getLogo example
var logoData = apiInstance.Branding.getLogo();
// Create a DOM element and use the values returned by the call
var logo = document.createElement('img');
logo.src = logoData.image;
logo.addEventListener('click', logoData.action);
document.body.appendChild(logo);
});
You can find a tutorial complete with jsFiddle example here: http://developers.spilgames.com/wiki/Developer_Platform_-_Learning_center_-_HTML5_API_-_(Tutorial)_Get_logo
If you run into technical issues, you can always get in touch with the Tech Support team using the "Support" tab on this page: http://developers.spilgames.com/contact
Hopefully this answers your question!
I need to do a simple pdf with some 3D objects for an oral presentation. I made several views, each one with a camera viewpoint, an object and a display mode.
To avoid the need to manually switch between the different viewpoints with the context menu, I would like the viewpoints to switch automatically with a Timer (each viewpoint staying for a few seconds). And I would like to not have to touch the mouse at all (nor the keyboard), so I would like to have the playback started as soon as the page appears.
I found the javascript command runtime.setView(N,x) to switch to the x'th view among N, but I don't know where to put it (I don't want to define a function which will be called when I press a button, since I want everything to be automated). Also, I don't know how to pause for a few seconds.
Any help ? Thanks !
I believe you're looking for setInterval(fn, time) which will call a function periodically at a time interval that you set. I'm not familiar with the setView() method you mentioned, but here's some pseudo code that you would put in tags at the end of the document body.
function startSwitcher()
var viewNum = 0;
var maxViews = 5; // you set this to how many views there are
setInterval(function() {
++viewNum;
if (viewNum >= maxViews) {
viewNum = 0;
}
runtime.setView(N, viewNum); // you will have to figure out this line
}, 2000);
}
startSwitcher();
The 2000 is 2000 milliseconds and is the time interval between executing the function. You can put any number of milliseconds there.
The runtime.setView(N, viewNum) line is something you will have to figure out as I am not familiar with whatever library you're trying to use there. The operative part of this code is the viewNum variable which configures which view in rotation should be next.
I think the runtime.SetView(..) Methods works with the name of the view as a string instead of the viewnumber. I have this function in a Dokument-level script and it works for me:
// view is the name of the view for example "TopView"
function setView(view){
console.println("Navigating to view: "+view);
var pageIndex = this.pageNum;
var annotIndex = 0;
var c3d = this.getAnnots3D( pageIndex )[ annotIndex ].context3D;
c3d.runtime.setView(view, true);
}
Combine this with the setInterval(..) from jfriend00´s answer und you should get what you need.
Best regards
I have a countdown timer which uses ajax calls to update itself. Something like
<div class="timer5">--:--:--</div>
I want to call a PHP function (only once) using jQuery which will update the database once the timer goes to 00:00:00.
The thing is, the timer can be increased at any time (it's an auction) so I can't just run a script after X time that will update the DB. I have to call the script when the timer really reaches zero.
How can this be done? Is there a some sort of an event in jQuery for that?
In my experience jquery countdown plugin is good for these things.Using this plugin you can easily do this.
var auction_id = array('1','2','3','4','5') // auction ids in array
jQuery(auction_id).each(function(key, val){
jQuery('.countbox-'+val).countdown({
//other options ref in plugin link
onExpiry: function(){
sold(val); // passing argument
//ajax call goes here to update db
}
});
}
To update your clock, I already answered here. The second part of the answer will be help full for you.
if you want to create multiple auction clock in page.you need to collect all auction ids
in array.then you can create clock for each of auction.
If it's done using AJAX you already get a call to your server, updating the timer and knowing how much time is left. Do the database update there.