ThinkGeo.com    |     Blog    |     Wiki    |     Support

Shapefile click event

How can we send our custom View Model to the controller via Map1.ajaxCallAction ? It seems the action will only accept a thinkgeo Map object but we need to send our entire view model to the controller because there are properties on the page not included on the map, like grids and other fields.

Hi Jmarshall,

We tried to build a sample to you, but it looks use CustomViewModel is not a good solution.

We succeed to pass CustomViewModel to client side, but all the value get parsed when page init, and in JavaScript code it cannot get any value from the CustomViewModel. So we cannot pass anything back via ajaxCallAction.

So I think you should want to use JsonString instead of the CustomViewModel, you can pass that back via ajaxCallAction, and then return the changed result to client side, after that call our client side API to modify the result in client side.

And you can modify in server side also, just in the server side event modify the “map”. And then redraw map in client side, please notice the client cache should get clear orelse you won’t see the change.

Regards,

Ethan

Do you have a code example of passing this JsonString from server to client and then from client back to server?

Hi Jmarshall,

I think you should want to call server side from client side first, then handle the client side when get call back.

And when you first loaded the page, you can put the logic into the loaded function.

The sample only shows how to communication with server side.

Wish that’s helpful.

9202.zip (474.5 KB)

Regards,

Ethan

So we need to send json to server, deserialize at server, then then work with data, serialize it and send back to client as json? What if we need to manipulate the map object in the server also? How would we send the map object to the client if we are already sending our custom json data to the client?

Just to clarify, there is no other way to use strongly typed view model objects between client and server?

Hi Jmarshall,

If you modify anything about map in server side(It’s also the map parameter in the sample event), you can call client API force redraw the map in client side.

If you need to serialize and deserialize the object to JSON, you can use 3rd part library or system JSON library.

We tried to use ViewModel, but it’s not a good solution to communication between client side and server side. The ViewModel in fact is work for render, it only contains the server side to client side, but cannot handle the client side to server side well. If you have related sample code please let us know, we can discuss about how to make it works with the map.

Regards,

Ethan

“If you modify anything about map in server side(It’s also the map parameter in the sample event), you can call client API force redraw the map in client side.”

Just to clarify this statement, are you saying that if we need to modify the map server side it can be done via the Map parameter server side and it will automatically be sent back to the client if we force redraw? Meaning we don’t need to explicitly pass the map back to view via controller or action? It seems if this is true there is some sync binding going on behind the scenes between client/server when we force redraw?

Hi Jmarshall,

You can just try it, in the sample you can modify the “map” parameter in the ClickEvent function.

You can modify my sample like this:

a.
layerOverlay.ClientCache = new ClientCache(new System.TimeSpan(-1));

b.

[MapActionFilter]
public string ClickEvent(Map map, GeoCollection<object> args)
{
    (map.CustomOverlays[0] as LayerOverlay).Layers.Clear();
    return "";
}

c.
function clickCallBack(result) {
Map1.redrawLayer(‘LayerOverlay’);
}

When you click on map, the shapes will be removed from page.

Wish that’s helpful.

Regards,

Ethan

I’m trying to understand what’s going on behind the scenes with the thinkgeo library so I’ll ask this in a different way. If we are not explicitly returning a map object back to the client then how is the client/view aware of any map changes that were made server side?

Hi,

If you haven’t a callback function to let client side know it changed, the client side won’t knows that.

It will get the changed result when you pan or zoom in client side, or a timer to redraw map.

Regards

Ethan

So calling Map1.redrawLayer or similar force redraw makes the client get the “new” data that was updated on the server?

Hi,

Yes redraw get updated data.

Regards,

Ethan

If we serialize an object client side and send to the server using ajaxCallAction, we then get the objects in the server side MapAction via GeoCollection args. Instead of getting each object by index like args[0].ToString(), is it possible to get the objects via strongly typed like args.MyObjectProperty? Would we need to do something like this? GeoCollection args

Hi,

I don’t understand this reply, so what’s the question here?

Regards,

Ethan

Sorry my full question didn’t send because it had <> symbols in it…
If we serialize an object client side and send to the server using ajaxCallAction, we then get the objects in the server side MapAction via GeoCollection(obj) args. Instead of getting each object by index like args[0].ToString(), is it possible to get the objects via strongly typed like args.MyObjectProperty? Would we need to do something like this? GeoCollection(MapViewModel) args

Hi Jmarshall,

You can refer this topic: Pass two parameter throw ajaxcallaction

It looks you can also get the value by its key.

And if your target is more complex like: GeoCollection(MapViewModel), you can try to test it, but I think it should won’t works because the GeoCollection should be JSON format.

Regards,

Ethan

How do we get the property names to send server action? If we have { LocationName: “this is a test”, LocationNumber: 6 } passed to action, in the action method we only have index and value like 0 : this is a test. How do we send the property name to controller action?

Hi Jmarshall,

It looks in this API you cannot get the key for example “LocationName”, you can just know index of it.

And please make sure the key in client side is different.

In fact I think you can put the key in value like this(you can choose other delimiter):
{0: LocationName_xxx, 1: LocationNumber_6}

And in server side, loop and split them to know what it is.

Regards,

Ethan

This seems extremely limited. What if we have a hundred properties that we want to display in our view with thousands or rows/records, how can we possibly send those to the server and manage that data server side with indexing? It seems this MVC product is very lacking if it can’t even handle strongly typed view models, one of the cornerstones of good MVC development. We need more options to pass data to server.

Hi Jmarshall,

It’s not designed to pass big data back to server side, map need to pass necessary data itself. If you want to do extra data operation, you should want to implement that by custom code but not via map.

And in fact you can try to implement it by a simple custom function just like my suggestion. Loop the parameters, split by special delimiter and get the information you want.

We still thanks your suggestion about our product, maybe we will provide some helper function for pass the data in future.

Regards,

Ethan