[OpenLayers-Users] Simple Point display in OpenLayers
Subhodip Biswas
subhodipbiswas at gmail.com
Sat May 26 12:40:18 PDT 2012
Hi All,
I was trying to display a point on a OSM map in openlayers. I wrote
few code in Backbone.js. Even though I can get the map displayed
perfectly, I somehow cannot get the point displayed up in my map.
Here is the code:
initMap: function() {
// Initialize Basic Openlayers;
var center = new OpenLayers.LonLat(8110203.9998955,
2170000.4068373);
map = new OpenLayers.Map(this.el, {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
});
//alert(this.el);
var layers = [];
var lonLat = new OpenLayers.LonLat(76.289063, 23.885838);
var coordinates = new Array();
layers[0] = new OpenLayers.Layer.OSM();
// Style Point
var style_red = OpenLayers.Util.extend({},
OpenLayers.Feature.Vector.style['default']);
style_red.strokeColor = "red";
style_red.fillColor = "red";
// Make Point
coordinates.push(new OpenLayers.Geometry.Point(lonLat.transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
)));
var pointsGeometry = new
OpenLayers.Geometry.MultiPoint(coordinates);
var pointFeature = new
OpenLayers.Feature.Vector(pointsGeometry, null, style_red);
// Layer
layers[1] = new OpenLayers.Layer.Vector("Points Layer");
layers[1].addFeatures(pointFeature);
//map.addLayer(pointsLayer);
map.addLayers(layers);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.setCenter(center, 12);
}
});
I guess I am missing something simple here, any help/pointer or links
would be much appreciated.
-------------
Regards
Subhodip Biswas
GPG key : FAEA34AB
Server : pgp.mit.edu
http://subhodipbiswas.wordpress.com
More information about the Users
mailing list