var ol_map = TETHYS_MAP_VIEW.map;

29 views
Skip to first unread message

climbin...@gmail.com

unread,
Nov 17, 2015, 11:58:59 PM11/17/15
to Tethys Platform
I cant seem to get the openlayers map object using TETHYS_MAP_VIEW.map; or TETHYS_MAP_VIEW.getMap(); as described in the documentation. Looking in tethys_map_view.js it looks like TETHYS_MAP_VIEW.getMap; is correct but I keep getting an undefined object or the function. I'm trying to create the object in a .js file that I load from the template that contains the map. What am I doing wrong?

Thanks

swainn

unread,
Nov 18, 2015, 10:17:56 AM11/18/15
to Tethys Platform, climbin...@gmail.com
Can you please post the script that you are trying to do this in?

climbin...@gmail.com

unread,
Nov 18, 2015, 10:43:40 AM11/18/15
to Tethys Platform, climbin...@gmail.com

Here is the script. It's contained in a js file that's loaded by the map template I created (very similar to the tutorial).

var tst1 = document.getElementById("map_view")

var tst2 = TETHYS_MAP_VIEW.getMap

var tst3 = TETHYS_MAP_VIEW.getMap()

console.log(tst2)
console.log(tst3)

console output is as follows:
->function get_map()
->undefined

swainn

unread,
Nov 18, 2015, 11:08:07 AM11/18/15
to Tethys Platform, climbin...@gmail.com
TETHYS_MAP_VIEW.getMap() is the  correct form, however you must call it after the page finishes loading. This can be done easily using JQuery (which is automatically included with Tethys apps):

$(document).ready(function() {
    var map = TETHYS_MAP_VIEW.getMap();
    console.log(map);
});

or equivalently:

$(function() {
    var map = TETHYS_MAP_VIEW.getMap();
    console.log(map);
});

Sometimes it may be necessary to use the window load event:

$(window).load(function() {
    var map = TETHYS_MAP_VIEW.getMap();
    console.log(map);
});
Reply all
Reply to author
Forward
0 new messages