NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I am building an openstreetmap with some geometry points, using this example, and using the OpenLayers.mobile.js.

map = new OpenLayers.Map({
    div: "mapdiv",
    theme: null,
    projection: new OpenLayers.Projection("EPSG:900913"),
    displayProjection: new OpenLayers.Projection("EPSG:4326"),
    maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
    maxResolution: 156543.0399,
    numZoomLevels: 19,
    units: 'm',
    controls: [
         new OpenLayers.Control.Attribution(),
         new OpenLayers.Control.TouchNavigation({
                dragPanOptions: {
                    enableKinetic: true
                }
         }),
         new OpenLayers.Control.Zoom()
    ]
});

map.addLayer(new OpenLayers.Layer.OSM());
map.zoomToMaxExtent();
var style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
style.graphicWidth = 30;
style.graphicHeight = 32;

style.externalGraphic = "img/point.png";

var mapmarkers = new OpenLayers.Layer.Vector( "Markers");

var features = [];
var points = [];

map.addLayer(mapmarkers);
for (var i = markers.length - 1; i >= 0; i--) {
    points[i] = new OpenLayers.Geometry.Point( markers[i].latlng[0], markers[i].latlng[1] );
    features[i] = new OpenLayers.Feature.Vector( points[i], null, style);
}
mapmarkers.addFeatures(features);
map.setCenter(new OpenLayers.LonLat(points[0].x, points[0].y), 5);

I'm getting the correct number of points on the map, but they are sitting at a lat/lang of 0,0. The only difference between the features variable I'm sending to addFeatures .. features.geometry is that it has a bounds object with top/bottom/right/left equivalent to the x and y that isn't present in the example..

If I use the example's map.addLayer(new OpenLayers.Layer.WMS( "OpenLayers WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} )); both points get placed but they are in Antarctica instead of Quebec (at least in different places then)

asked 30 Jan '13, 16:27

thedamon's gravatar image

thedamon
26112
accept rate: 0%

retagged 26 Aug '13, 10:17

MagicFab's gravatar image

MagicFab
935101622

You will have better chances of getting an answer if you rephrase this as an actual question.

(26 Aug '13, 14:56) MagicFab

The problem is with different map projections. Probably you'll have to project your latLon points (which are in WGS84 / EPSG:4326) to Web Mercartor (EPSG:900913) by using something like the projection example from OpenLayers.

permanent link

answered 27 Aug '13, 10:02

gormo's gravatar image

gormo
2.9k32660
accept rate: 13%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×122
×113
×67
×45

question asked: 30 Jan '13, 16:27

question was seen: 4,360 times

last updated: 27 Aug '13, 10:02

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum