How to tell when a Microsoft map object has finished loading - bing-maps

We're using the Bing Maps AJAX API (v7) to work with maps on our site. The map part itself works, but there are times when the connection to the service is slow. I have some code that needs to run only when the map has completely finished loading. Is there any event or param available in the maps API (I have looked, but can't find anything easily) that will tell me when a map object has completely finished loading?

What do you mean by "when the map has completely finished loading"?
If you don't have any other elements on the map, then use the tiledownloadcomplete event.
If you need to restore the map back to a certain state(with a zoom, location etc), use the viewchangeend event.
I don't think there is an event you can use which signifies that the map has completely loaded in the traditional sense. You can probably approximate this behavior by always causing the map's view to change upon initializing, but eventually arrive at your desired state, so you can subscribe to viewchangeend and execute your code in there.

Related

When do I make an API call

I am currently using VIP architecture and I was wondering when I should make an API call.
For example, I have two views. A connection view leading to a list view.
The list needs the user to connect to load.
My question is, where should I make my API call to fetch data for the second view ?
Should I make the request as soon as the connection succeeds, and then launch the 2nd view once I get the data of this request.
Or
Should I launch the 2nd view first and then make the request for this view ?
The first solution seems slightly faster, but the second one feels cleaner.
What do you think ?
First of all, VIP/MVC/MVVM architecture has nothing to do with your issue, none of there architectures has rules about when you need to make API calls.
Everything depends on your needs and tech requirements.
As for me there is two most important points:
if your second screen is data sensitive and you need to be sure, that it display latest data - make API call after this screen was displayed and update it UI with latest data.
if you don't care if data that you display is latest/ or you this data would not be updated very often/ or you show static data that would be rarely changed, BUT for you is important that user will see next screen immediately - make API call as soon as it possible(preferably on app launch)
If both previous points is not important for you - make API call after screen will be displayed. It will guaranty that you has latest data.
But you need to remember that there is no rule about it, so make API calls when you really need it.

Flux - How to deal with multiple stores updating the same view?

I'm a beginner to the flux model but I think I understand it at a high level:
event creator -> events -> dispatch -> store -> view and around we go!
Given that the flux model supports multiple stores, if you have say an event loop that dispatches to 2+ stores, that in turn updates the same view.
How do you manage any inadvertent flicker that would come from that process?
I haven't quite enabled/used react yet (I assume a catch all answer will be that react handles this heavy lifting part of reducing this) but conceptually how could this work outside a specific implementation.
Since store changes are applied serially across stores, do you just wait until all the stores are down processing the dispatcher, and then allow them individually to fire all their changes? Even then you still would loop through and dispatch events at the end, and you'd still potentially have overlapping updates to the UI.
Thanks!
You have different options here:
The vanilla solution is to utilize a waitFor() function in your store-structure, and ensure that in the end each component has only one store it listens to. More or less like this:
Caveat is that your action types and store structures need to be in sync: Each action needs to communicate to all stores that are included in a waitFor cycle. The example in the picture will fail to trigger a render. The top-most store is not listening to the action from dispatcher, and the right store will keep waiting for update. Also, the red line may cause a similar dead end, if it is only 1 of the components. My way of dealing with this is: make all stores in the first line listen to ALL actions, and if the action is irrelevant: emit change.
The other option is to consolidate your data into a single store.
This does not make the issue go away: you need to handle the dependency issues inside the single store. But it does take away the hassle of many actions, many waitFors, and many change emissions..
Remember that the action is processed synchronously - all stores will have emitted, the controller views with have called setState, etc. before the stack unwinds and browser gets a chance to re-render the DOM, so flicker is not possible (the browser won't render in the middle of a function running, since otherwise all DOM manipulation code would cause random flickering).
However, as you say, there will potentially be multiple stores emitting changes, and multiple components listen to them, and hence you may end up calling 'setState' multiple times (even on the same component). This sounds inefficient, but under most circumstances it isn't. As long as the current action originated from an event that came from React (e.g. an event handler added to a component in the JSX), React automatically batches all calls to setState and only does the re-render to the DOM (i.e. any required DOM updates) once, immediately (and synchronously) after you have finished processing the event.
There is a case to be aware of - if you dispatch an action from something outside of a React event handler (e.g. a promise.then, an AJAX callback, setTimeout callback, etc.) then React will have to re-render for every single call to setState in that function, since it doesn't know when else to do it. You can avoid this by using the undocumented batched rendering feature (0.14, note that 0.13 had a different API for this):
ReactDOM.unstable_batchedUpdates(myFunctionThatDispatchesActions);
An alternative might be to use an off-the-shelf Flux implementation which does this for you already. See e.g. https://github.com/acdlite/redux-batched-updates

LeafletJS check for not loading map

How can I detect whether a map is loading properly or not?
What happened was that in my ionic app the map url stopped to work, and the map did not throw an error. It only displayed gray.
Is there a way to check for this event properly and fall back to an alternative map?
A usual but simplistic workaround is to specify a single fallback tile, using the errorTileUrl option of your tileLayer. Typically it shows a light red cross to let the user know the map server does not have any image to provide for that area and that zoom.
Now if you want to be smarter and fallback to a different map (i.e. redirect to a different URL), I am not aware of any out-of-the box solution, but it is very well do-able. The idea is to override the _tileOnError method of the L.TileLayer class, which normally replaces the tile by the one from errorTileUrl when it receives a 404 error (i.e. no tile available on the server). In the given link, it automatically replaces the URL by a new one for a different location (could be a different server), as it expects only a few tiles to be missing.
Now if you assume the whole server would stop responding and you want to switch over to a different tileLayer (so that it stops pinging the faulty server), you could implement for example a simple counter that is incremented by the _tileOnError method, and once a given threshold is reached, switch the layers.
I may be late in answering to this but, here are the layer events which you can make use of. This event is triggered on the layer and not on the map. In this case, if the bingLayer fails to load, tileerror will get triggered.
this.bingLayer.on("tileerror", function (error, tile) {
//do something when the tile fails to load
});
this.bingLayer.on("tileload", function(e){
//do something when the tile loads successfully
})
Experienced same of recent. Found the reason here Tile Usage Policy.
OpenStreetMap data is free for everyone to use. Our tile servers are not.
Below are the minimum requirements that users of tile.openstreetmap.org must >adhere to. These may change in future, depending on available resources. >Should any users or patterns of usage nevertheless cause problems to the >service, access may still be blocked without prior notice. We will try to >contact relevant parties if possible, but cannot guarantee this.
But because OpenStreetMap data is free, many other organisations provide map >tiles made from OSM data. If your project doesn’t meet these requirements, >you can get OSM-derived map tiles elsewhere.
Requirements
Heavy use (e.g. distributing an app that uses tiles from >openstreetmap.org) is forbidden without prior permission from the System >Administrators. See below for alternatives.
Clearly display license attribution.
Do not actively or passively encourage copyright infringement.
Calls to /cgi-bin/export may only be triggered by direct end-user action. >(For example: “click here to export”.) The export call is an expensive >(CPU+RAM) function to run and will frequently reject when server is under >high load.
Highly Recommended: Do not hardcode any URL at tile.openstreetmap.org >into an app.
Recommended: add a link to https://www.openstreetmap.org/fixthemap to >allow your users to report and fix problems in our data.
Use other tile layers that uses osm to render map. Had to use this for map images to show on mobile
{tileLayer: "http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png",
zoomControl: false,
tileLayerOptions: {
opacity: 0.9,
detectRetina: true,
reuseTiles: true
},
scrollWheelZoom: false,
attributionControl: false
}
In a nutshell osm blocked the map tiles.

Using Workflow 4 as a Controller in MVC

I'm building an app that deals with customer queries, where I want to route the query through a decision tree showing appropriate views before taking some automated action against their query. Kind of like the game "20 questions"! Based on the answers at each stage, the path through the app will change.
I was thinking of using MVC, because there are only a few "types" of route and outcome - so I could build fewer pages that way, one to handle each type rather than one for each step. I was also thinking of using Workflow 4 to manage the page flow, because the flowchart model maps pretty nicely to what I'm trying to do.
Does anyone know any good reference apps that use Workflow for this kind of thing?
Thanks
Richard
There where a number of examples using WF3 doing this sort of thing but I haven't seen any for WF4. I suppose it is possible to do but it means running the workflow synchronously and checking the bookmarks as soon as it becomes idle to see which operations are enabled at the moment. That should be possible using a custom SynchronizationContext that does things synchronous and using the Idle callback on the WorklfowApplication to check the current bookmarks.
I actually went with a different option in the end - I wrote a "GetNextAction" function that returned an ActionResult object based on my flowchart logic and state of objects. The controller processes whatever form inputs it's received, updates the object, then calls GetNextAction and returns the result of that function. Seems to be working out ok!

Asynchronous data loading in Entity-Framework?

Did anyone hear about asynchronous executing of an EF query?
I want my items control to be filled right when the form loads and the user should be able to view the list while the rest of the items are still being loaded.
Maybe by auto-splitting the execution in bulks of items (i.e. few queries for each execution) all in same connection.
I posted a feature suggestion to Microsoft, please share them with your ideas as well.
Not wanting to sound like a commercial, but I noticed that the latest DevExpress grid gives features like this in their WPF grid. Essentially you want to load visible-count items first, then load the rest in a background thread so your UI isn't freezing up. The background thread should probably load another page at a time and make them available to the UI thread.
It's something you would want to think about carefully and make sure you get it right, or simply buy a control that does the hard work for you.
I take from your link that this is a web app. Is that correct?
A Query must complete and return data before rendering can begin. An EF feature will not help you here. Rather. look at breaking up your process into several processes that can be done at once.
Keep in mind that ASP.NET cannot return a response to a browser if it is not done rendering the HTML.
Let me assume you are executing a single query, getting the results back and displaying them to a page.
Best option: Page your results. if you Have 4000 records, show the first 50. If you show 200+ records to a user, They cannot digest that much information.
If that does not fit your needs, look at firing one query for 50 results. Make an Ajax call to the the remaining records and build the UI from there, in (reasonably sized) chunks.