[OpenLayers-Users] tooltipPopup feature
tvnc
tvnc1979 at gmail.com
Thu Aug 11 06:49:38 EDT 2011
using measure control each time when i click to paritial measure distance,
point feature is added to vector layer. i call tooltipPopup function on
mouseover the feature. but it wan't draw a popup, giving me some kind of
event.feature problem
markers = new OpenLayers.Layer.Vector("Markers");
map.addLayers([markers]);
var bot = new OpenLayers.Control.Button
({
displayClass: 'olIkonaUdalj',
eventListeners: {
'activate': klikLivo,
'deactivate': brisMarkera},
type: 2
});
var kontr = new OpenLayers.Control.Panel
({
div: document.getElementById("bp"),
//defaultControl: bot
});
kontr.addControls([bot]);
map.addControl(kontr);
function klikLivo(event) {
/*
if(markers.features.length==0) return;
var i = markers.features.length - 1;
tocke.push(markers.features
[i].geometry);
var lineString = new OpenLayers.Geometry.LineString(tocke);
var lineFeature = new OpenLayers.Feature.Vector(lineString);
poli.addFeatures([lineFeature]);
*/
pn.deactivate();
var crta = new OpenLayers.Control.Measure(OpenLayers.Handler.Path,
{persist: true});
crta.events.on({
"measure": handleMeasurements,
"measurepartial": handleMeasurements
});
map.addControl(crta);
crta.activate();
function handleMeasurements(event) {
tocke = [];
markers.destroyFeatures();
var geometry = event.geometry;
var units = event.units;
var order = event.order;
var measure = event.measure;
var element = document.getElementById('au');
tocke.push(geometry);
for(i=0; i<(tocke[0].components.length); i++){
var pointsGeometry = new OpenLayers.Geometry.Point(tocke
[0].components[i].x, tocke[0].components[i].y);
feature = new OpenLayers.Feature.Vector(pointsGeometry);
markers.addFeatures([feature]);
}
var selectControl = new OpenLayers.Control.SelectFeature(markers,
{hover: true, onSelect: selektirano, onUnselect: us});
map.addControl(selectControl);
selectControl.activate();
var lastFeature = null;
var tooltipPopup = null;
var out = "";
if(order == 1) {
out += "Udaljenost: " + measure.toFixed(2) + " " + units;
} else {
out += "measure: " + measure.toFixed(3) + " " + units +
"<sup>2</" + "sup>";
}
element.innerHTML = out;
}
}
function selektirano(event){
var feature = event.feature;
tooltipPopup = new OpenLayers.Popup("activetooltip",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(180,50),
"nesto", true);
//this is messy, but I'm not a CSS guru
tooltipPopup.contentDiv.style.backgroundColor='ffffcb';
tooltipPopup.closeDiv.style.backgroundColor='ffffcb';
tooltipPopup.contentDiv.style.overflow='hidden';
tooltipPopup.contentDiv.style.padding='3px';
tooltipPopup.contentDiv.style.margin='0';
tooltipPopup.closeOnMove = true;
tooltipPopup.autoSize = true;
feature.popup = tooltipPopup;
map.addPopup(tooltipPopup);
}
function us(){
for(i=0; i<map.popups.length; i++){
map.popups[i].destroy();}
}
More information about the Users
mailing list