Dear Openlayers community!

I've created a map with a point in its center.
When I drag the map the point should always stay in the map center (and it
does so already).

Now the problem:
When I drag the map outside the initial viewport (the viewport of the map on
page load),
the point is hidden. When I drag back to the initial vielport the point is
visible again.

Does anyone know a solution for this issue?
I really need help with this, because I think I've already tried everything.
;)

Kind regards
iKey

My DIV container for the map has: width: 400px, height: 300px and the id
"map"

My js code looks like this:

var map_controls = [
        new OpenLayers.Control.Navigation(), 
        new OpenLayers.Control.PanZoomBar()
];

        // set map center
        var center = new OpenLayers.LonLat(8.03522229194641,
52.2718865289123).transform(
            new OpenLayers.Projection("EPSG:4326"), // transform from wgs84
            new OpenLayers.Projection("EPSG:900913") // to Spherical
Mercator Projection
        );
        // set map zoom
        var zoom = 15;

        var map = new OpenLayers.Map("map", {
                        controls: map_controls,
                        units: "m",
                        displayProjection: "EPSG:4326",
            eventListeners: {
                                "move": moveMarker
            }
                });
                
        //var bounds = new
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34);
                
        var layer_map = new OpenLayers.Layer.OSM({
                        //minExtent: bounds,
                        //maxExtent: bounds
                });
    map.addLayer(layer_map);
        map.setCenter(center, zoom);
        
        // create layer for the marker
        var layer_marker = new OpenLayers.Layer.Vector("Marker",  {
                alwaysInRange: true,
                displayOutsideMaxExtent: true,
                //minExtent: bounds,
                        //maxExtent: bounds
                //maxExtent: map.getExtent()
        });

        // set marker style
        var style = {
                        externalGraphic:
"http://www.openstreetmap.org/openlayers/img/marker.png";,
                        //externalGraphic: template_path + 
'/img/marker_set_poi.png',
                        graphicWidth: 30,
                        graphicHeight: 30,
                        graphicZIndex: 1000
                        };
        // create point and feature
        var point = new OpenLayers.Geometry.Point(center.lon, center.lat);
        var pointFeature = new OpenLayers.Feature.Vector(point, null, style);
        // add it to the map
        layer_marker.addFeatures(pointFeature);
        
        /*
        var boxes = new OpenLayers.Layer.Boxes("boxes");
    var box = new OpenLayers.Marker.Box(bounds);
    boxes.addMarker(box);
    map.addLayer(boxes);
        */
        
        map.addLayer(layer_marker);
        
        function moveMarker() {
                if (point != null && map != null && pointFeature != null) {
                        console.log(pointFeature.geometry);
                        //var point2 = new 
OpenLayers.Geometry.Point(map.getCenter().lon,
map.getCenter().lat);
                        //var pointFeature2 = new 
OpenLayers.Feature.Vector(point2, null, style);
                        //layer_marker.addFeatures(pointFeature2);

                        
                        pointFeature.geometry.x = map.getCenter().lon;
                        pointFeature.geometry.y = map.getCenter().lat;
                        pointFeature.layer.drawFeature(pointFeature);
                        //layer_marker.redraw();
                }
        }
-- 
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/Openlayers-marker-layer-dragging-problem-tp5907738p5907738.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
us...@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to