ThinkGeo.com    |     Documentation    |     Premium Support

OnMapCreated / OnMapCreating Events Not Firing

Hello,



We are using MapSuite version 7.  While working on another issue I discovered that neither the OnMapCreated or the OnMapCreating events are firing. I also note that neither method is listed in the MVC Javascript API Refrence.



We maintain all our javascript in separate files. This seems to be affecting all maps, which are created/setup in  controllers, and then rendered in a MVC Partial view such as this:


@model ACCESSWeb.Models.Maps.BasicMap
@using ThinkGeo.MapSuite.MvcEdition
 
<div id="DemoMap">
    @Html.Partial("~/Views/Shared/Mapping/Partial/_CommonMapElementsPartial.cshtml")
    @Html.ThinkGeo().Map(Model.Map).Render()    
</div>





I have tried with following test method defined in both separate javascript files and with a script tag within the Razor view, neither of which work. I do not know if I am doing something wrong, as this is how I have seen others instructed to Any assitance would be appreciated.


var OnMapCreated = function(map) {
    alert("MapCreated");
}


Hi Michael, 
  
 We put the OnMapCreated function in separated JavaScript file and it still fired. 
  
 Could you please create a simple sample can reproduce that, so we can help you on this. 
  
 Regards, 
  
 Don

I have created a simple demo project that exhibits this behavior on both of the machines I have tested it on. I had to remove the packages folder from the project folder, it should be restored by the Nuget Package Manager, and the dlls. The project references for MapsuiteCore, MapSuiteMVC Edition, GeoAPI, and NetTopologySuite will need to be added on your end. This was the only way I could get the ZIP file to the needed size.



This is using MapSuite MVC version 7.0.



Also, perhaps you ThinkGeo should consider adding 7zip archives and allowing multi-part archives for file upload. It would certainly make things simpler when trying to provide samples like this.

Hi
Michael,



Thanks for your sample. 



As you know, JavaScript is interpretive
programming language. We need to define a function before using. In this case,
we need to define the OnMapCreated function before rendering Map, as we will
try to execute the OnMapCreated function if it is already defined when
executing Map().Render(). Please try the modified code below:



_MapPartial.cshtml.




@using ThinkGeo.MapSuite.MvcEdition
@model MapSuiteMVCCreationEvents.Models.BasicMap
 
<script type="text/javascript">
    var OnMapCreated = function (map) {
        alert("MapCreated");
    }
script>
  
<div id="DemoMap">
    @Html.Partial("~/Views/Shared/Mapping/Partial/_CommonMapElementsPartial.cshtml")
    @Html.ThinkGeo().Map(Model.Map).Render()
div>


Hope this would be helpful and any other question
please feel free to let us know.



Regards,

Kevin





That was exactly the issue, I do no know why I did not think of this. 
  
 Thanks for the assistance.

You’re always welcome, Michael, any other question don’t hesitate to let us know.



Regards,

Kevin