ThinkGeo.com    |     Documentation    |     Premium Support

Map refreshes / reloads on every Click o the map?

Hey! Here I am again with more questions =)


The short version first: I want to be able to Click on the Map and then determine if I clicked any of my custom drawn polygons. I want to do this without reloading the map/page.


I added (manually)  an OnClick-event in the ASPX-file like this:



<



ContentTemplate>

    <cc1:Map ID="Map1" runat="server" Width="100%" Height="100%" OnClick="Map1_Click">

    </cc1:Map>

</ContentTemplate>

Then, in the CS-file I added some code like this:



protected


First problem:

Everytime I click the map the page reloads/refreshes. Isnt there some AJAX-way to execute on server and then update the client without reload?



Second problem:

The GetFeaturesTouching-method returns no Features. I cannot understand what the second parameter is (the string[]-thing) so I just made that en empty array.


Further comment:

What Im actually trying to do is to avoid having manually click an "Edit button". Instead, I want the application to understand that a User clicked a Shape and then automatically start editing that shape which is much better than changing mode manually.



I also tried to set Map1.Mode = ModeType.EditShape in the Page_Load but that didnt work at all. I tried this since I realized that the Map actually works fine in that mode at all times. Then you can always modify polygons, you can pan and zoom which is really all I need. However, I want an AJAX-like response to when an Shape is created or changed so that the new shape can be saved in the database and the map/page DOES NOT reload =)

 




Thanks in advance =)

 


 


 


 


 void Map1_Click(object sender, MapClickedEventArgs e)

{

   InMemoryLayer shapeLayer = (InMemoryLayer)Map1.DynamicLayers["shapeLayer"];

   Collection<Feature> features = shapeLayer.QueryTools.GetFeaturesTouching(e.Position, new string[0] { });

   if (features.Count > 0)

   {

      Feature feature = features[0];

      shapeLayer.Features.Remove(feature.Id);

      Map1.EditLayer.Features.Add(feature.Id, feature);

      Map1.Mode = ModeType.EditShape;

   }

}

 

 




Ted, 
  
 Thanks for the post, we were able to see what you mean on the First problem and we are looking to implement a solution where you would have control over refreshing each set of layers separately.  For example if you clicked on the polygon you may only want to refresh the DynamicLayers collection.  This would leave the static layers be and only redraw the dynamic layer on top and work like you would expect.     
  
 On the second problem, I agree this API is a little confusing.  What the string array is for is to specify the column names associated with the feature you want returned, so an empty string array is fine if you don’t need any of the column information for the feature.  In the next beta refresh we are going to add an overload to this API so instead of passing in a string array you can pass in an enumeration of “AllColumnns” or “NoColumns”  we feel this API will be much easier to use since most users will want either one of these scenarios. 
  
 On the Final issue have you looked at the FinishTrackShape event?  I’m not sure if this will get you exactly what you need or now or you may already be using it, but if not try it out and let us know if you run into any issues.  You can take a look at the FinishTrackShape sample under the shapes section for more information. 
  
 Thanks! 
  
  
 

Thx for the answer =) 
  
 On the second problem: When I click I get no Features returned even though I click on a Feature. That is the problem. I cannot fiigure out why and I thought that had something to do with the fact that Im sending in an empty string array? Cause the code looks almost exactly the same as in one of your examples… 
  
 I’ve been working on another part of the project lately, so I will look at FinishTrackShape-event, but if Im not mistaken there were some issues with taht (or the event didnt exist or the page was reloaded… hmm). I’ll get baxck to you on this. 
 

Thanks Ted, let us know what you find.