Hello Andreas,

Thanks for your help - I will look into it. I thought the Sundials example was too tied to KML files, so this is why I didn't chose to follow it.

I will continue this thread if I run into unsolvable problems.

Regards,
Adrian

Andreas Hocevar wrote:
Hi,

On Fri, Jun 19, 2009 at 3:00 PM, Adrian
Popa<[email protected]> wrote:
Here's what I'm trying to do (let me know if I'm reinventing the wheel):
I want to load a bunch of markers onto an existing map, and I want to
register a function to react to a click event. The function will create
a popup and get some content through an ajax call to display on the map.

Please consider using a vector layer instead of a markers layer for
your markers. Then, you add a SelectFeature control to the map,
configured with your vector layer. Now all you have to do is create
your popup in a listener for the layer's featureselected event.

As a starting point, have a look at the sundials example
(http://www.openlayers.org/dev/examples/sundials.html). Create your
vector layer without the protocol and strategies options. You can add
your markers (called features for a vector layer) to the layer anytime
by saying:

var feature = new OpenLayers.Feature.Vector(
    new OpenLayers.Geometry.Point(lon, lat), {
        myAttribute1: "foo",
        myAttribute2: "bar"
    }, {
        externalGraphic: "yourMarkerImageURL"
    }
);
map.addFeatures([feature]);

For creating the popup content (see onFeatureSelect function in the
sundials example), you can e.g. access the myAttribute1 property by
evt.feature.attributes.myAttribute1.

I went through a lot of examples on the net, but things got complicated
- because they started using jugl.js (don't know what that is), or
displaying KML content.

Jugl is a cool template system, created by Tim Schaub. And using
vector layers, it makes no difference whether you display KML content
or features that you add to your layer programmatically.

Can you point me to an example of a popup that gets its contents through
a definable function?

See above, I think that should get you there.

Regards,
Andreas.


_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users

Reply via email to