The problem with Layer.Text is that it accepts a tab delimited file
while I wanted to pass coords, a title and a description for a marker.<br><br>I was able to do do that with adding a few parameters to location and with some editing of the Text.js file.<br><br>Here are the new variables:<br>
<br> layerToUse:null,<br> newLon:null,<br> newLat:null,<br> newTitle:null,<br> newDesc:null,<br> newIcon:null,<br><br>layerToUse places the marker on an existing layer instead of creating a new one (functionality I was looking for).<br>
<br>And also changed the following code:<br><br> loadText: function() {<br> if (!this.loaded) {<br> if (this.location != null) {<br><br> var onFail = function(e) {<br> this.events.triggerEvent("loadend");<br>
};<br><br> this.events.triggerEvent("loadstart");<br> OpenLayers.Request.GET({<br> url: this.location,<br> success: this.parseData,<br>
failure: onFail,<br> scope: this<br> });<br> this.loaded = true;<br> }<br> else if (this.newTitle != null && this.newDesc != null) {<br>
this.parseData();<br> }<br> } <br> }, <br><br> parseData: function(ajaxRequest) {<br> if (ajaxRequest != null) {<br> var text = ajaxRequest.responseText;<br> } else {<br>
if(this.newIcon == null) this.newIcon = "";<br>
var text = "point\ttitle\tdescription\ticon\n" + this.newLat +
"," + this.newLon + "\t" + this.newTitle + "\t" + this.newDesc + "\t" +
this.newIcon + "\n";<br> }<br> var options = {};<br><br>as well as<br><br> data['overflow'] = feature.attributes.overflow || "auto"; <br> var markerFeature = new OpenLayers.Feature(this.layerToUse, location, data);<br>
this.features.push(markerFeature);<br> var marker = markerFeature.createMarker();<br> if ((feature.attributes.title != null) <br> && (feature.attributes.description != null)) {<br>
marker.events.register('click', markerFeature, this.markerClick);<br> }<br> if (this.layerToUse != null) {<br> this.layerToUse.addMarker(marker);<br> } else {<br>
this.addMarker(marker);<br> }<br><br><br>Also from my HTML file I call:<br><br>
var new4 = new OpenLayers.Layer.Text( "Texts", { layerToUse: markers,
newLat: '4420851.767102', newLon: '698762.34033203', newTitle: "Test
Title 2", newDesc: "This is a description 2"} );<br> new4.parseData();<br>
<br>
Instead of:<br>
<br>
map.addLayer(new4);<br>
<br>
In summary, what this does is, it feeds specific layer, coords, title and description to the function.<br>
<br>
I also discovered a nice little bug. If you hide an overlay while a
marker bubble is open, the marker disappears while the bubble still
stays there. This also happens on the OL examples
(markersTextLayer.html).<br>
<br>
I hope I didn't go the long way around to solving this problem...<br><br><div class="gmail_quote">On Thu, Oct 8, 2009 at 3:29 PM, Christopher Schmidt <span dir="ltr"><<a href="mailto:crschmidt@metacarta.com">crschmidt@metacarta.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Thu, Oct 08, 2009 at 01:27:30PM +0300, Alex G. wrote:<br>
> Hi all,<br>
><br>
> I am interesting in constructing a function that places a marker with a<br>
> bubble text as provided by OpenLayers.Layer.Text but I want to provide<br>
> coordinates, title and description on the fly (without saving them to a file<br>
> and then loading them to the function).<br>
><br>
> I am using the OpenLayers example to catch clicks and then place a simple<br>
> marker using markers.addMarker(new OpenLayers.Marker(new<br>
> OpenLayers.LonLat(lonlat.lon,lonlat.lat),icon)); and everything seems to<br>
> working fine.<br>
><br>
> But I cannot seem to be able to figure out a way to do the same for<br>
> OpenLayers.Layer.Text.<br>
<br>
</div>Er... It shouldn't be any different? Can you share your current code<br>
that isn't working?<br>
<br>
-- CHris<br>
<div class="im"><br>
> I am guessing some heavy modification of Layer/Text.js is required? Is there<br>
> maybe a patch around that could help me on this since my Javascript<br>
> knowledge is pretty bad.<br>
><br>
> Thanks in advance!<br>
<br>
</div>> _______________________________________________<br>
> Users mailing list<br>
> <a href="mailto:Users@openlayers.org">Users@openlayers.org</a><br>
> <a href="http://openlayers.org/mailman/listinfo/users" target="_blank">http://openlayers.org/mailman/listinfo/users</a><br>
<br>
</blockquote></div><br>