[OpenLayers-Users] featureadded
Puneet Kishor
punk.kish at gmail.com
Thu Oct 6 19:47:37 EDT 2011
The following code is supposed to create a Google Maps base layer, and a point using an external graphic that is rotated (az) and has height (rate) described by the attributes passed when creating the point. A "featureadded" event is supposed to create a popup anchored at the point showing "az" and "rate". The code doesn't work. The base layer is created but neither the point nor the popup are created. Suggestions?
var proj = {
"google": new OpenLayers.Projection("EPSG:900913"),
"latlng": new OpenLayers.Projection("EPSG:4326")
};
map = new OpenLayers.Map('map', {
"maxExtent": new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508),
"maxResolution": 156543.0339,
"proj": proj,
"units": "meters"
});
map.addLayer(new OpenLayers.Layer.Google("Google Physical", {type: google.maps.MapTypeId.TERRAIN}));
map.setCenter(new OpenLayers.LonLat(-89, 43).transform(proj.latlng, proj.google), 2);
var styleMap = new OpenLayers.StyleMap({
"default": {
externalGraphic: "arrow.png",
rotation: "${az}",
graphicWidth:6,
graphicHeight: "${rate}"
}
});
var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {styleMap: styleMap});
// create a point feature
var points = [];
var p = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(-72, 42).transform(proj.latlng, proj.google),
{attributes: {az: 76, rate: 33}},
{styleMap: styleMap}
);
points.push(p);
vectorLayer.addFeatures(points);
vectorLayer.events.on({
"featureadded": function(evt) {
feature = evt.feature;
var str = "";
for (var i in feature.attributes) {
str += "<b>" + i + ":</b> " + feature.attributes[i] + "<br />";
}
map.addPopup(new OpenLayers.Popup.FramedCloud(
"featurePopup",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(50, 30),
str,
null,
true,
null
));
}
});
map.addLayer(vectorLayer);
More information about the Users
mailing list