I am trying to draw a polygon on my map but it's not showing, I do not have a js error on the console...

Here is the code :

     var style = {
       strokeColor: "#00FF00",
       strokeOpacity: 1,
       strokeWidth: 3,
       fillColor: "#00FF00",
       fillOpacity: 0.8
    var points = [];

    var p1 = new OpenLayers.Geometry.Point(49.4, -1.15);
    var p2 = new OpenLayers.Geometry.Point(49.4, -0.92);
    var p4 = new OpenLayers.Geometry.Point(49.23, -1.15);
    var p3 = new OpenLayers.Geometry.Point(49.23, -0.92);
    var ring = new OpenLayers.Geometry.LinearRing(points);
    var polygon = new OpenLayers.Geometry.Polygon([ring]);

    var feature = new OpenLayers.Feature.Vector(polygon, null, style);
    var line_layer = new OpenLayers.Layer.Vector("Test");

Tell me if you see anything wrong !

  • 1
    Welcome to GIS SE. Could you update your answer to include the js error you are getting. – Knightshound Oct 7 '16 at 10:25
  • Sorry I meant I have no error on my js console. – Orfeo Oct 7 '16 at 11:00
  • What does the console.log(polygon); call display? – til_b Oct 7 '16 at 12:29

I have found my error, I got to transform lat lon into point and I have reversed lat and long ... :

        var p4 = new OpenLayers.Geometry.Point(-1.15, 49.41).transform('EPSG:4326', 'EPSG:900913');
    var p3 = new OpenLayers.Geometry.Point(-0.92, 49.41).transform('EPSG:4326', 'EPSG:900913');
    var p2 = new OpenLayers.Geometry.Point(-0.92, 49.23).transform('EPSG:4326', 'EPSG:900913');
    var p1 = new OpenLayers.Geometry.Point(-1.15, 49.23).transform('EPSG:4326', 'EPSG:900913');

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.