ThinkGeo.com    |     Documentation    |     Premium Support

Shapefile click event

Hi Jmarshall,

Please view our HowDoISample-ForMvc samples.

You can found the AddAClickEventController.cs which add the click event in project.

And FindFeatureClickedController.cs shows some interactive between click and shape file.

I think you can found more samples follow your requirement from it.

Regards,

Ethan

Is it possible to select multiple features using cntrl + click or similar method?

Hi Jmarshall,

We don’t have existing API for it, but I can discuss about the thinking with you.

If you want to implement this requirement, you should want to write custom JavaScript code to get all points you clicked, then sent them back to server side via CallBack request and handle the response in client side.

Wish that’s helpful.

Regards,

Ethan

What if we want the selected shapes to persist through callbacks? Can we return them to the client via custom View Model?

Hi Jmarshall,

Please view this sample: https://samples.thinkgeo.com/MvcEdition/HowDoISamples/InteractiveOverlays/DrawEditShapes/1,InteractiveOverlays

If you click point, and after that click save button, multiply points will be sent back to server side. You can view it’s JavaScript code and implement your logic. And follow this way your select result will be saved after page load.

Here is the source code of it: https://github.com/ThinkGeo/HowDoISample-ForMvc

Please refer it.

Regards,

Ethan

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