[OpenLayers-Users] since I'm a little dense...

Adrian Popa adrian_gh.popa at romtelecom.ro
Mon Aug 3 03:29:48 EDT 2009


Hello Nick,

Here's some code - it's not complete - because it mostly lacks variable 
definitions which should be globals. However, they should be easy to add:

//layer definition
markers = new OpenLayers.Layer.Vector("Alarms", {
                        projection: map.displayProjection, strategies: 
[new OpenLayers.Strategy.BBOX()],
                        protocol: new OpenLayers.Protocol.HTTP({ url: 
"kml_alarms.pl", format: new OpenLayers.Format.KML({ extractStyles: 
true, extractAttributes: true })})});
        map.addLayer(markers);

       //if you want to select the markers later, you will need to add 
the necessary functions.
        select = new OpenLayers.Control.SelectFeature(markers, 
{toggle:true});
        markers.events.on({ "featureselected": onMarkerSelect, 
"featureunselected": onMarkerUnselect, "visibilitychanged": 
onMarkerToggle });
        map.addControl(select);
        select.activate();

//.........
// onSubmit: - layer is the layer variable, options are the options 
packed as a JSON/javascript object. Call refreshLayer like: 
refreshLayer(markers, options);

function refreshLayer(layer, options){

    if(options == null){
        layer.refresh({force: true});
    }
    else{
        if(layer.CLASS_NAME == "OpenLayers.Layer.Vector"){
            layer.protocol.options.params = options; //override the 
parameters sent to kml_alarms.pl
            layer.refresh({force: true});
        }
    }
}

If you're using KML format, make sure your serverside script outputs 
content-type application/vnd.google-earth.kml+xml. Something similar 
should exist for GML.
 From this code you're missing a function to pack the search form into 
the "options" object. The object should look like:
options[name] = value;
options[name2] = value2;


Good luck!
Adrian.

P.S. If you intent your application to run for hours and to 
automatically refresh your POIs, you should consider doing a full page 
reload from time to time so that IE won't eat all available memory...


Nick Kendall wrote:
> Adrian, I'd love some code examples. I was toting with the idea of a 
> gml writing php function that re-writes a gml file on the server, and 
> reloading the pages on submit, thus changing the static resource but 
> your way sounds more elegant
>
> Nicholas Efremov-Kendall 
> (917) 399-6939
> Sent from my mobile device
>
> On Aug 3, 2009, at 9:50 AM, Adrian Popa <adrian_gh.popa at romtelecom.ro 
> <mailto:adrian_gh.popa at romtelecom.ro>> wrote:
>
>> Hello,
>>
>> I had a similar task - of showing dynamic POIs and I chose to 
>> implement it like this:
>> - a Vector layer with KML data.
>> - the path to the KML file is actually a path to a serverside script 
>> wich generates KMLs.
>> - on searchbox submit a javascript creates new parameters for the 
>> serverside script
>> - I force a layer refresh
>>
>> It works great - but it tends to crash Internet Explorer after a 
>> while - because IE keeps deleted markers in memory (silly behaviour). 
>> You can get around this by refreshing the whole page, but it's nasty.
>>
>> Let me know if you need some code examples.
>> Regards,
>> Adrian
>>
>> Nicholas Efremov-Kendall wrote:
>>> Hi all,
>>>
>>> I'm still trying to make a dynamic POI, or marker, or points layer, 
>>> whatever you want to call it, that changes the points in the map in 
>>> response to user's searches. I can't use mapserver or a 
>>> pre-programmed server-side option, so I'm forced to write my own gml 
>>> or wkt. I'm still not quite sure how to get this GML to OL and then 
>>> replace it by the next search.
>>>
>>> I think there are two options. One of which would be to send data to 
>>> a markers layer and have JS write the markers out. The other would 
>>> be to have php re-write the gml file on the server and 
>>> theoretically, this should create a new set of points each time the 
>>> search is submitted. Not sure what the best/easiest option would be 
>>> with respect to coding (either on the browser or server-side) or 
>>> from a performance perspective. Does anyone have any 
>>> recommendations? I'm basically copying a php/mysql kml tutorial and 
>>> adapting it to GML (for largely ideological reasons). I've just 
>>> re-read the GML documentation, and it states that the GML is meant 
>>> to only be loaded once, so should I be focusing on a dynamic marker 
>>> layer or what?
>>>
>>> In effect, all I really want is a simple ajax function to load the 
>>> POI/markers that correspond to search criteria, such that every 
>>> search produces a unique (within a limited span of variation of 
>>> course). The maps centering won't really change, just the make up of 
>>> the sites displayed in the map. I can write the gml server side, and 
>>> I can send the request, but I'm not sure what to do with the 
>>> call-back or how to feed that info to OL.�
>>>
>>> Thank you in advance for any advice/help.
>>> (incidentally, I'd be willing to consider contracting someone to do 
>>> this)
>>>
>>> best,
>>> Nick
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org <mailto:Users at openlayers.org>
>>> http://openlayers.org/mailman/listinfo/users
>>>   
>>
>>


-- 
--- 
Adrian Popa
NOC Division
Network Engineer
Divizia Centrul National de Operare Retea
Departament Transport IP & Metro
Compartiment IP Core & Backbone
Phone: +40 21 400 3099

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090803/648f7243/attachment.html


More information about the Users mailing list