1

how to draw the line between markers, coordinates of markers undertake from a DB. whether it is possible to draw in general lines between markers, I saw examples only with points.

    markers = new OpenLayers.Layer.Markers("Marcadores");
    map.addLayer(markers);

    if (b == 2) 
    {           

            //=================  =========
            var size = new OpenLayers.Size(30, 30);
            var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);

            var location = new OpenLayers.LonLat(kor_1,kor_2).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
            var icon = new OpenLayers.Icon('http://icons.iconarchive.com/icons/icons-land/vista-map-markers/256/Map-Marker-Ball-Pink-icon.png', size, offset);
            markers.addMarker(new OpenLayers.Marker(location, icon.clone()));
            var line = new OpenLayers.Geometry.LineString([kor_1, kor_2]);
        //================= ==============

    }
  • You will need a vector layer, and then draw a feature containing your line. – Devdatta Tengshe May 17 '13 at 5:09
2

You need to add a vector layer, and then add a feature to it. See the following code:

var startPt=new OpenLayers.Geometry.Point( 2, 45);
var endPt=new OpenLayers.Geometry.Point(7,55);

//make the line:
var line=new OpenLayers.Geometry.LineString([startPt, endPt]);

//style
var style={strokeColor:"#0500bd", strokeWidth:3};
//make vector 
var fea=new OpenLayers.Feature.Vector(line, {}, style);

//make vectorLayer
var vec= new OpenLayers.Layer.Vector();

//add the feature
vec.addFeatures([fea]);

//add to map
map.addLayer(vec);

You can see a working sample here: http://jsfiddle.net/devdatta/pwuVz/2/

| improve this answer | |
  • @user2390000 Please consider marking this question as accepted. – Devdatta Tengshe May 17 '13 at 7:54
  • 54:11 ReferenceError: OpenLayers is not defined – CONvid19 Jun 8 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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