Hexagon Geospatial
MENU

Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Occasional Contributor
Posts: 18
Registered: ‎10-19-2015
Accepted Solution

Zoom to POI using JavaScript

[ Edited ]

Hello

 

I have a workflow that contains a public map. I open a form with detailed information about an object and I want to show to the user the mapviewer zoomed to that specific object. The layer is defined as POI in public maps. I made a new js file with the following content and added it as customscript to my workflow:

 

 

IG.vent.on('mapViewer:ready', function (mapViewer, form) {
    var id = form.getItemById('ID1').getValue();
    if(!_.isEmpty(id)){
   mapViewer.map.loadPoi('1e299b1a-399d-49eb-b166-88e00fe49b0d',id);
    }
});


In debug mode I see that the id (ID1) of my object is correctly taken from the form, the POI id is from my admin database. When it comes to executing loadPOI which is defined in ig.publicmaps.workflows.js I never end up in the .done part of that function. I always end up in an error. I attached the error message to this SR. It is also not very lucky, that .error is not catched (hard to know that there is an error).
What is the problem with my function together with loadPOI()? Did I understand correctly that loadPOI() contains zooming to the specified object?

 

 

By the way, I started this issue with a sample script that I got:

 

IG.vent.on('mapViewer:ready', function (mapViewer) {
        var mapViewer = IG.getItemById('MapViewer');
        var id = IG.getItemById('ID').getValue();
        IG.getItemById('ID').value.subscribe(goToCurrent(mapViewer, id));
});

function goToCurrent (mapViewer, id) {
    if(!_.isEmpty(id)){
   mapViewer.map.loadPoi('1ce6e3ef-7e61-464b-b282-a729b2ba6086',id)
   .done(function(response){
        var activeMapView = IG.getItemById('MapViewer').map.getActiveMapView();
        activeMapView.center.lon(response.properties.pointLocationX);
        activeMapView.center.lat( response.properties.pointLocationY);
        activeMapView.zoomTo(11);
        });
    }
}

The problem as it seems in this script is, that the commands in after .done in this script will never work, because .done cannot work with loadPOI as defined in ig.publicmaps.workflows.js.

 

Thanks & regards

Carmen

 

 

 

Staff
Posts: 1,036
Registered: ‎10-18-2015

Re: Zoom to POI using JavaScript

Hi Carmen,

 

running your code in the browser console you should get something like this:

 

Capture.PNG

 

isn't it?

At the end you need to specify the done part to get the map fitted to the current element. So the whole code would look like this:

IG.vent.on('mapViewer:ready', function(mapViewer, form) {
    var id = form.getItemById('ID').getValue();
    if (!_.isEmpty(id)) {
        mapViewer.map.loadPoi('8564af87-1853-4176-b879-c92f9783beca', id)
            .done(function(response) {
                var activeMapView = form.getItemById('MapViewer').map.getActiveMapView();
                activeMapView.center.lon(response.properties.pointLocationX);
                activeMapView.center.lat(response.properties.pointLocationY);
                activeMapView.zoomTo(9);
            });
    }
});

 

Have you installed EP01? What is the database behind?

 

Thanks,

Stefano

 

 

Stefano Turcato
Presale Engineer
Hexagon Geospatial
Occasional Contributor
Posts: 18
Registered: ‎10-19-2015

Re: Zoom to POI using JavaScript

[ Edited ]

Ciao Stefano

 

In public\log folder I can find this entry:

26.10.2015 11:48:42 ERROR - http://localhost/GMSC/Public/Map/Poi?site=GMSC&poiLayerId=1e299b1a-399d-49eb-b166-88e00fe49b0d&poiId=2&mapViewId=aca7c2f2-bf08-433d-a489-d758c892b8df
System.ArgumentNullException: Der Wert darf nicht NULL sein.
Parametername: value
   [Data]
   MS_LoggedBy: System.Collections.Generic.List`1[System.Object]
   bei System.Runtime.Caching.MemoryCacheEntry..ctor(String key, Object value, DateTimeOffset absExp, TimeSpan slidingExp, CacheItemPriority priority, Collection`1 dependencies, CacheEntryRemovedCallback removedCallback, MemoryCache cache)
   bei System.Runtime.Caching.MemoryCache.AddOrGetExistingInternal(String key, Object value, CacheItemPolicy policy)
   bei System.Runtime.Caching.ObjectCache.Add(String key, Object value, CacheItemPolicy policy, String regionName)
   bei Intergraph.Emea.SmartClient.PublicMaps.ApplicationCache.Add(String key, Object value)
   bei Intergraph.Emea.SmartClient.PublicMaps.ApplicationCache.GetOrAdd[TValue](String key, Func`2 valueFactory)
   bei Intergraph.Emea.SmartClient.PublicMaps.MapController.GetPoi(Guid poiLayerId, String poiId, Guid mapViewId, String site)
   bei Intergraph.Emea.SmartClient.PublicMaps.MapController.Poi(Guid poiLayerId, String poiId, Guid mapViewId, String site)
   bei lambda_method(Closure , Object , Object[] )
   bei System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
   bei System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
   bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bei System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
   bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bei System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
   bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bei System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()

 

I rechecked my configuration and saw that I was having the wrong POI id associated to the mapview I'm using. But the script still does not zoom to the respective location.

 

I've installed EP01 and SQLServer 2012.

 

Thanks

Carmen

Occasional Contributor
Posts: 18
Registered: ‎10-19-2015

Re: Zoom to POI using JavaScript

I restarted IIS and now it works also in my browser and in my project. It seems that it was chached somewhere and I did not realize that. Now also the .done part is executed and it looks correct.

 

Thank you for your help

Highlighted
Staff
Posts: 1,036
Registered: ‎10-18-2015

Re: Zoom to POI using JavaScript

Thanks for the feedback Carmen. Indeed most of the configurations are stored in the Public Maps app pool, so every time you change something you have to recycle that pool. You can also set 

 

<add key="EnableCache" value="false"/>

in the PublicMaps.config file to avoid this behavior while developing the project.

 

Best regards,

Stefano

Stefano Turcato
Presale Engineer
Hexagon Geospatial
Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.