[OpenLayers-Users] Simple Point display in OpenLayers
Arnd Wippermann
arnd.wippermann at web.de
Sun May 27 02:48:41 PDT 2012
You have to use a points array as argument for MultiPoints
And your coordinates not in the view.
var lonLat = new
OpenLayers.LonLat(lon=72.855202114476,lat=19.127904557572).transform(
new OpenLayers.Projection("EPSG:4326"),
new OpenLayers.Projection("EPSG:900913")
//map.getProjectionObject()
);
var points = [];
// Make Point
points.push(new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat));
var pointsGeometry = new OpenLayers.Geometry.MultiPoint(points);
...
Regards
Arnd
-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Subhodip
Biswas
Gesendet: Samstag, 26. Mai 2012 21:40
An: openlayers-users at lists.osgeo.org
Betreff: [OpenLayers-Users] Simple Point display in OpenLayers
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
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users
More information about the Users
mailing list