The case is the following: I have a layer and there are two points on it. The first is in Australia, the second is in the USA. The continent or the exact position of the points doesn't count. The essential part is the great distance between the points. When the application starts, the first point appears (zoomlevel is 18). The second point isn't displayed because it is far away from here and the zoomlevel is high. Then i call the panTo function with the location of the second point and the zoomTo function with the same (18) zoomlevel. The map jumps to the right location but the second point doesn't appear. The point appears only if i zoom in/out or resize the browser window.

I assume Openlayers doesn't load the points which aren't on the screen actually. And those points are loaded only when i jump to their location (panTo) and then change the zoomlevel (or resize the browser window). Has anybody experienced such behaviour? Or has anybody got a solution to this problem?

Thanks in advance!

  • what sort of layer?
    – Ian Turton
    Oct 21, 2013 at 15:07
  • org.gwtopenmaps.openlayers.client.layer.Vector
    – Imreking
    Oct 21, 2013 at 15:09

2 Answers 2


Zoom to dataExtent of layer. It will show both points on the map.

  • This is right, but i have to display the map with high zoom level and then the user can change between locations. So 'zoom to dataExtent' is a good thing but not in this situation. I need a solution when the user can navigate between locations (panTo) with the same (high) zoomLevel and can see all the points on the layer.
    – Imreking
    Oct 21, 2013 at 15:46

OpenLayers can either load all your points at startup or request new points everytimes the map pan or zoomout. If you only have 2 points (or less than a hundred), simply load them all at startup with OpenLayers.Strategy.Fixed. Then you will be able to use panTo() like you do.

Here's an example that loads all the points from a GML file:

var layer = new OpenLayers.Layer.Vector("GML", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "gml/polygon.xml",
        format: new OpenLayers.Format.GML()

If you have too many points for this, you will need to use the BBox strategy. See the example here: http://openlayers.org/dev/examples/strategy-bbox.html

Note that if you already use that and your second point is not showing up, you probably have a bug if you application that prevent it from being drawn. We would need more details to help you further. Could you share an example on http://jsfiddle.net/ ?

Edit from the comments:

Alternatively, if you are not using protocol and only simple point that you add manually to the map. map.panTo() should do the job. I've setup a small demo app here: http://jsfiddle.net/dLTqS/

Here's the code:

<!DOCTYPE html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <title>OpenLayers: Vector Features</title>
    <link rel="stylesheet" href="http://openlayers.org/dev/theme/default/style.css" type="text/css">
    <link rel="stylesheet" href="http://openlayers.org/dev/examples/style.css" type="text/css">
    <script src="http://openlayers.org/dev/OpenLayers.js" type="text/javascript"></script>
    <script type="text/javascript">
        var map, point, point2, point3;

        function init(){
            map = new OpenLayers.Map('map');
            var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                    "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );

            var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry");

            // create a point feature
            point = new OpenLayers.Geometry.Point(-111.04, 45.68);
            var pointFeature = new OpenLayers.Feature.Vector(point);
            point2 = new OpenLayers.Geometry.Point(120.04, -30.98);
            var pointFeature2 = new OpenLayers.Feature.Vector(point2);
            point3 = new OpenLayers.Geometry.Point(0.04, 49.68);
            var pointFeature3 = new OpenLayers.Feature.Vector(point3);

            map.setCenter(new OpenLayers.LonLat(point.x, point.y), 5);
            vectorLayer.addFeatures([pointFeature, pointFeature3, pointFeature2]);

        function panToPoint(id) {
            if(id == 1) {
                map.panTo(new OpenLayers.LonLat(point.x, point.y));
            if(id == 2) {
                map.panTo(new OpenLayers.LonLat(point2.x, point2.y));
            if(id == 3) {
                map.panTo(new OpenLayers.LonLat(point3.x, point3.y));
  <body onload="init()">
    <h1 id="title">panTo() on points</h1>
    <div id="map" class="smallmap"></div>
    <input type="button" id='testButton1' value="Pan to first point" onclick="panToPoint(1)" />
    <input type="button" id='testButton1' value="Pan to second point" onclick="panToPoint(2)" />
    <input type="button" id='testButton1' value="Pan to third point" onclick="panToPoint(3)" />
  • Julien-Samuel Lacroix, thank you for your answer. I have one problem with strategies: they all need some kind of protocol (http, wfs etc.), but in my case i get coordinates via GWT RPC and then display them simply: Point point = new Point(mpoint.getX(), mpoint.getY()); VectorFeature pointFeature = new VectorFeature(point); vectorLayer.addFeature(pointFeature); So i think the refresh strategies of Openlayers can't help in this situation.
    – Imreking
    Oct 22, 2013 at 10:08
  • If you are not using a protocol, you don't need a strategy. That's right. Let me update my response with an example. Oct 22, 2013 at 13:58
  • 1
    Here. I just added an example that use panto and vector points. It works well. If you are experiencing problems with your application, I suspect it is a problem with styles or projection. You will need to narrow down the problem by removing code from your application. Once you have bare example, you will be able to spot the problem. Let us know how it goes. Oct 22, 2013 at 14:46
  • Thank you for your reply. I modified your code a little bit to reflect the structure of my program. Link: link So now this code is logically the same as my GWT-Openlayers code. The problem is that the pure openlayers code (linked above) works but the GWT-Openlayers code doesn't. I narrowed down the problem by removing code as you suggested. Removed the styles and checked the projection but still have the same problem.
    – Imreking
    Oct 25, 2013 at 10:50
  • Please close this one and open a question describing your problem with GWT-OpenLayers as your original question was not related to this package. Tip: The code I provided use global variable and it's not the way to go in GWT-OL. You will need to check that. Oct 25, 2013 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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