Hi,
I was able to build some very stable applications using the concept of single page application but I still have some questions about the client side and how to make sure that when the THINKGEO map JAVASCRIPT API is used no other actions should take place on the server side ending up with errors like layer not open… If I am not wrong when an AJAXCALL is issued from the client it should be ISSUE ONLY if all other client side based activities have been completed. Now the question what could be used to make sure that the client MAP API is completed before issuing an AJAXCALL.
could you provide more guidance about this?
thanks a lot.
jm
Question about synchronization
Hi JM,
Seems like I was a bit confused with your purpose and your requirement, could you please give a scenario here? Actually, some of the THINKGEO Map JavaScript APIs are rendered based on the server side code, like the LayerOverlay and MarkerOverlay, their data is requested from the server side asynchronously, for example, the MarkerOverlay, if you pan the map, a ajaxCall will be called to server side to get its data, if the server side runs into error, there will be no response back, no markers will be rendered. For LayerOverlay, maybe a different, if it runs into error, such a Layer not open, it will print the exception on the tile image.
Hope it helps,
Regards,
Johnny
Hi Johnny,
Well as you say some of the client API are using server side components. Now the question is linked with the fact that one could interact with the application when the internal THINKGEO API is at work and require let’s say some work on a layer that is actually actively used by the internal API… like I want to add or delete a marker then I issue an Ajaxcall but I do not know if there is an active process currently requesting the marker layer/overlay…
thanks a lot.
jm.
It could be Nice to have access to a "lock" on the server side that could be set by internal thinkgeo api when an internal thinkgeo operation is running then the customer code on the server could wait until the internal operation is completed.
jm
Hi JM,
Thanks for your further information, may I make a confirmation with your? Is your problem like the following:
An client call(let’s name it CallA) is sent to server, then the server starts processing this callA, while server is processing callA, another client call(let’s name it CallB) is sent to server. Because the server is processing callA so the coming of callB might cause some concurrent problem.
If yes, would you please use Map1.ajaxCallAction(parameters) and use the callback function inform the client side that the callA on server side is over.
Hope it helps
Summer
Hi Summer,
Well… the way you describe is what I am use to do. Now the question is that I am getting "The Layer must be opened before you can perform this method." this is the kind of code I am using:
gridLayer.Open();
gridLayer.FeatureSource.Open();
dataLayer.Open();
dataLayer.FeatureSource.Open();
foreach (Feature gridCell in gridLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns)) {
var elements = dataLayer.QueryTools.GetFeaturesWithin(gridCell, ReturningColumnsType.AllColumns).ToList();
elements = elements.Where(e => e.ColumnValues["FeatureType"] == "ENDPOINT_SHAPE").ToList();
var dynHeat = new Feature(gridCell.GetShape().GetCenterPoint());
dynHeat.ColumnValues["DensityCounter"] =
elements.Sum(e => double.Parse(e.ColumnValues["DensityCounter"]))
.ToString(CultureInfo.InvariantCulture);
dynHeats.Add(dynHeat);
}
gridLayer.FeatureSource.Close();
gridLayer.Close();
dataLayer.FeatureSource.Close();
dataLayer.Close();
What about getting the error on this : " var elements = dataLayer.QueryTools.GetFeaturesWithin(gridCell, ReturningColumnsType.AllColumns).ToList();" as you can see the layer has been open before the loop and will be closed when exiting the loop. I cannot explain why I am getting this error. My code on the server side is serialized. However, I am wondering what if the client issue a "Map1.redrawLayer(…)" and right away an AjaxCall??? is the "Map1.redrawLayer(…)" synchronous or not??? if not then the layer could be used at the same time by the AjaxCall and the the "Map1.redrawLayer(…)" operation.
jm.
Hi JM,
I guess you need to lock the layer in the AjaxCall, In Map Suite, each layer is locked during drawing. Maybe that’s the issue. Please have a try and any questions or problems please let me know.
Thanks,
Johnny
Hi Johnny,
Could you indicate to me where this property can be set when using the MVC edition? I have found the lock property but in a desktop edition only…
Thanks in advance
JM.
It looks like that the lock is not available then there is I think an issue when one need to update overlay in ajax mode and if the client is using some client API at the same time…?
This likes a server architect design issue: the layer should be always open (or cached) at the server side, and is ready for any client requests: these requests can be queued dependent on what kinds. Only feature lock is needed when editing a feature.
the thing is that there is many ways to access an overlay/layer and I need to know if there is an issue when the browser is using and ajax call just after let say a Map1.redrawLayer… kind of call. I think that everything is asynchronous and I would like to see something looking like when the Map1.redrawLayer… is completed then a callback function is executed.
It could really be nice to have the possibility for call back function every time that and asynchronous API is used!
jm.
Hi Jm,
I guess what you are looking forward to is what we were thinking. Could you wait one day, then I will.be avaible in office, and digg it into further, I guess here may be an issue here, but not very sure now.
sorry for the inconvience,
thanks,
johnny
Hi JM,
Thanks for your waiting, we tried to simulate the situation that AjaxCallRequestB is send while the server side is dealing with AjaxCallRequestA, and found that actually these AjaxCalls are quened, so we didn’t recreate your problem, would you please check the attached testcode and tell us what we missed?
Waiting for your further information.
Best Regards
Summer
001_TestCode.txt (4.53 KB)
Hi,
The test case is not right. The client issue a JavaScript call to redraw a layer like Map1.redraw… Then an Ajaxcall … The question is about javascript asynchronous vs. Ajaxcall.
Jm.
Hi Jm,
Thanks for your further information, now, we have recreated your problem flowing is the code that we recreate the problem:
<script language="javascript" type="text/javascript">
function RedrawMap(e) {
Map1.redrawLayer('overLay');
Map1.ajaxCallAction('@ViewContext.RouteData.Values["Controller"].ToString()', 'ClickEvent1', null, function (e) {
}
</script>
Following is the code that we fixed this problem :
<script language="javascript" type="text/javascript">
function RedrawMap(e) {
Map1.redrawLayer('overLay');
var overlay = Map1.getLayer('overLay');
overlay.events.register('loadend', this, function call() {
//Redraw finished you can add your ajaxcall here.
Map1.ajaxCallAction('@ViewContext.RouteData.Values["Controller"].ToString()', 'ClickEvent1', null, function (e) { alert("ok!"); })
});
}
</script>
Hope it helps.
Summer
Good! Now what do we do? I think that there is more linked with this problem. Client side processes must be serialized when a call to the server is issue.
This is computer science 101. I have very important projects down the road and this is the kind of thing that could create issues for the kind of features I need to develop
Look forward for a fix.
Thanks.
Hi JM,
Sorry last response didn’t displayed correctly, following is the code we recreated the problem:
function RedrawMap(e) {
Map1.redrawLayer(‘overLay’);
Map1.ajaxCallAction(’@ViewContext.RouteData.Values[“Controller”].ToString()’, ‘ClickEvent1’, null, function (e) { })
}
Following is how we fixed it:
function RedrawMap(e) {
Map1.redrawLayer(‘overLay’);
var overlay = Map1.getLayer(‘overLay’);
overlay.events.register(
‘loadend’,
this,
function call() { Map1.ajaxCallAction(’@ViewContext.RouteData.Values[“Controller”].ToString()’, ‘ClickEvent1’, null, function (e) { alert(“ok!”); }) }
);
Hope it helps, if you have any more question , please feel free to let us know.
Best Regards
Summer
Ok! works ok now. But when there is more than one layer/overlay to refresh it could be not that easy.
jm.
Hi Jm,
Good to hear it is fit for you.
As for more than one layer to refresh, I am thinking we may set a globe counter to count how many layers have been completed the refresh and if the counter is equal to the layers count then we can fire the Ajax call in the call back. May be there are another good solutions, but this is the first one slipped out from my mind.
Thanks,
Johnny