1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
/**
* Method: _creat4KML
* Create function for KML based features.
* the calling context is the feature.
*
* Returns:
* {<Geoportal.Popup.Anchored>} - the popup.
*/
Geoportal.Popup.Anchored._creat4KML= function() {
var popup;
var opts= OpenLayers.Util.extend({},this.layer.formatOptions);
OpenLayers.Util.applyDefaults(
opts,{
size:null,
closeBox:true,
onPopupClose:Geoportal.Popup.onPopupClose,
backgroundColor:'#ffffff',
opacity:0.75
});
var tempText;
if(this.style) {
tempText= null;
// add style pop-up define in kml's file
// user can use in kml's file variable like '$[name]'
// which correspond to balise inside placemark like <name>,<description>,<adresses>
tempText= this.style.balloonStyle;
if(tempText != null) {
var rx= /\$\{([a-zA-Z0-9_\-\.]*)\}/;
while(tempText.match(rx)) {
var test= RegExp.$1;
test= (this.attributes[test]?
(this.attributes[test].value?
this.attributes[test].value
: this.attributes[test])
: "");
tempText= tempText.replace(rx,test);
}
} else {
tempText= (this.attributes.name? this.attributes.name+"<br/>":"")+
(this.attributes.description? this.attributes.description:"");
tempText= Geoportal.Util.cleanContent(tempText);
}
popup= new Geoportal.Popup.Anchored(
"chicken",
this.geometry.getBounds().getCenterLonLat(),
opts.size,
this.style.textColor?
"<div class='gpPopupBody' style='"+this.style.textColor+";'>"+tempText+"</div>"
:
"<div class='gpPopupBody'>"+tempText+"</div>",
null,
opts.closeBox,
this.style.bgColor,
this.style.bgColorOpacity,
opts.onPopupClose,
this
);
} else {
//if there are no style defines in kml's file
tempText= (this.attributes.description? this.attributes.description:"");
tempText= Geoportal.Util.cleanContent(tempText);
popup= new Geoportal.Popup.Anchored(
"chicken",
this.geometry.getBounds().getCenterLonLat(),
opts.size,
"<div class='gpPopupHead'>" +
(this.attributes.name? this.attributes.name:"") +
"</div>" +
"<div class='gpPopupBody'>" +
tempText +
"</div>",
null,
opts.closeBox,
opts.backgroundColor,
opts.opacity,
opts.onPopupClose,
this
);
}
popup= Geoportal.Popup.completePopup(popup,this.layer.formatOptions);
this.popup= popup;
return this.popup;
};
/**
* APIMethod: createPopUpForKMLFeature
* Create function for KML based feature and give a style to the popup.
* Used for OpenLayers.Format.KML on "featureadded" event through
* <OpenLayers.Layer.Vector.onFeatureInsert>() callback.
*
* Parameters:
* feature - {<OpenLayers.Feature.Vector>}
*/
Geoportal.Popup.Anchored.createPopUpForKMLFeature= function(feature) {
feature.createPopup= OpenLayers.Function.bind(Geoportal.Popup.Anchored._creat4KML,feature);
};
/**
* APIFunction: completePopup
* Finalize popup options.
*
* Parameters:
* popup - {<Geoportal.Popup>} the popup to complete.
* options - {Object} the options (autoSize, maxSize, minSize, overflow).
*
* Returns:
* {<Geoportal.Popup>} completed.
*/
Geoportal.Popup.completePopup= function(popup, options) {
if (!options) { return popup;}
popup.autoSize= options.autoSize!=undefined ? options.autoSize:true;
if (options.maxSize) {
popup.maxSize= options.maxSize;
}
if (options.minSize) {
popup.minSize= options.minSize;
}
if (options.overflow) {
popup.contentDiv.style.overflow= options.overflow;
}
return popup;
}; |
Partager