Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I would like to take one marker and move it and draw a line to a particular long, lat. This is what I've got so far:

    <script type="text/javascript">
        var map, layer;

            var locations = [
  ['Ameerpet',17.424497,78.451038,1],
 ['Madhapur',17.441148,78.391069,2],
  ['Begumpet',17.444707,78.466381,3]

 ];
        function page_init()
        {
            map = new OpenLayers.Map("basicMap");
            var mapnik         = new OpenLayers.Layer.OSM();
            var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984
            var toProjection   = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
            var position       = new OpenLayers.LonLat(78.466381,17.444707).transform( fromProjection, toProjection);
            var zoom           = 12; 
            map.addLayer(mapnik);
            map.setCenter(position, zoom );
            putMarker(locations)

        }
        function putMarker(locations)
        {
              var  i;
             for (i = 0; i < locations.length; i++)
             { 
                var lonLat = new OpenLayers.LonLat(locations[i][2], locations[i][1]).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());
                var zoom=12;
                var markers = new OpenLayers.Layer.Markers( "Markers" );
                map.addLayer(markers);markers.addMarker(new OpenLayers.Marker(lonLat));map.setCenter (lonLat, zoom);
            }

                path1(locations);
       }
       function path1(locations)
       {
            var lineLayer = new OpenLayers.Layer.Vector("Line Layer"); 
            map.addLayer(lineLayer);                   
            map.addControl(new OpenLayers.Control.DrawFeature(lineLayer, OpenLayers.Handler.Path));                                     
            var points = new Array(
                             new OpenLayers.Geometry.Point(locations[0][2],locations[0][1]).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()),
                             new OpenLayers.Geometry.Point(locations[1][2],locations[1][1]).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()),
                             new OpenLayers.Geometry.Point(locations[2][2],locations[2][1]).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject())
                     );
            var line = new OpenLayers.Geometry.LineString(points);
            var style = { 
              strokeColor: 'blue', 
              strokeOpacity: 0.5,
              strokeWidth: 5
                };
            var lineFeature = new OpenLayers.Feature.Vector(line, null, style); 
            lineLayer.addFeatures([lineFeature]);
        }
       </script>
        <body onLoad="page_init();">
         <div id="basicMap" style="width: 750px; height: 450px;"></div>
share|improve this question
in above example i want one marker and move that marker and draw a line to particulat lang,lat – user15212 Feb 15 at 11:07

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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