Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing an app using OpenTripPlanner.

It creates an OpenLayer map in map.js. I want to access this map in index.html so I can set it's center.

Kindly help me out.

share|improve this question
up vote 1 down vote accepted

i dont think opentripplanner uses openlayers so i have checked it and it uses leaflet so you have to use following method for centering your map.(you can put it anywhere after your map.js is loaded)

_container div#map2.leaflet-container

map.panTo(new L.LatLng(lon, lat));

i hope it helps you...

share|improve this answer

In index.html :

    <script src="map.js"></script>
    <script src="myscript.js"></script>

In myscript.js

mapVariable.setCenter(new OpenLayers.LonLat( yourLon, yourLat) , theZoomLevel );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.