[OpenLayers-Users] Problem with geometry in OL

Andreas Hocevar ahocevar at opengeo.org
Wed Jul 22 05:00:16 EDT 2009


Rohan Patel wrote:
> Hi Andreas,
> That looks pretty good but how do I add vectorLayer to the map?

map.addLayer(vectorLayer);

You will probably want to make the map globally available also (like in
the examples).

Regards,
Andreas.

> Thanks,
> Rohan
>  
>
>     -----Original Message-----
>     From: Andreas Hocevar <ahocevar at opengeo.org>
>     To: Rohan Patel <rohan at quintemri.com>
>     Cc: users <users at openlayers.org>
>     Date: Tue, 21 Jul 2009 19:52:09 +0200
>     Subject: Re: [OpenLayers-Users] Problem with geometry in OL
>
>     Rohan Patel wrote:
>     > Hi Andreas,
>     > Well I have vectorLayer initialized in my init().
>     > I am not that great with javascript, java is actually my forte. Do I
>     > need to make vectorLayer public or something?
>
>     Something like that, yes.
>
>     You now have
>
>     function init() {
>         var vectorLayer = ...;
>     }
>
>     function test() {
>         alert(typeof vectorLayer); // "undefined"
>     }
>
>     So vectorLayer is only known to the init method. Instead, you will
>     want:
>
>     var vectorLayer;
>
>     function init() {
>         vectorLayer = ...;
>     }
>
>     function test() {
>         alert(typeof vectorLayer); // "Object"
>     }
>
>     Regards,
>     Andreas.
>
>     > Thanks,
>     > Rohan
>     >  
>     >
>     >     -----Original Message-----
>     >     From: Andreas Hocevar <ahocevar at opengeo.org>
>     >     To: maelstrom666 <rohan at quintemri.com>
>     >     Cc: users at openlayers.org
>     >     Date: Tue, 21 Jul 2009 15:13:54 +0200
>     >     Subject: Re: [OpenLayers-Users] Problem with geometry in OL
>     >
>     >     Hi,
>     >
>     >     sounds like a scope issue. Is vectorLayer known to your test()
>     >     function? Use Firebug or your favorite debugger to find out.
>     >
>     >     Regards,
>     >     Andreas.
>     >
>     >     On Fri, Jul 17, 2009 at 2:14 PM,
>     maelstrom666<rohan at quintemri.com>
>     >     wrote:
>     >     >
>     >     > Hi I am having some issues with geometry in OL.
>     >     > When I click a button, it activates a function which
>     should add
>     >     a point to
>     >     > the map.
>     >     > Here is the code for that function:
>     >     > <script language="javascript" type="text/javascript">
>     >     > function test()
>     >     > {
>     >     >        var point2 = new OpenLayers.Geometry.Point(-101.04,
>     45.68);
>     >     >        var pointFeature2 = new
>     >     OpenLayers.Feature.Vector(point2,null,style_blue);
>     >     >        vectorLayer.addFeatures([pointFeature2])
>     >     > }
>     >     > </script>
>     >     >
>     >     > in the function init, i have another point which shows up
>     >     without any issues
>     >     > here is an excerpt of tht code:
>     >     >
>     >     > var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
>     >     > var pointFeature = new
>     >     OpenLayers.Feature.Vector(point,null,style_blue);
>     >     > vectorLayer.addFeatures([pointFeature]);
>     >     > map.addLayer(vectorLayer);
>     >     >
>     >     > If you need more code or anything please tell me.
>     >     > Thanks,
>     >     > Rohan
>     >     >
>     >     > --
>     >     > View this message in context:
>     >    
>     http://n2.nabble.com/Problem-with-geometry-in-OL-tp3275045p3275045.html
>
>     >
>     >     > Sent from the OpenLayers Users mailing list archive at
>     Nabble.com.
>     >     > _______________________________________________
>     >     > Users mailing list
>     >     > Users at openlayers.org
>     >     > http://openlayers.org/mailman/listinfo/users
>     >     >
>     >
>     >
>     >
>     >     --
>     >     Andreas Hocevar
>     >     OpenGeo - http://opengeo.org/
>     >     Expert service straight from the developers.
>     >
>
>
>     -- 
>     Andreas Hocevar
>     OpenGeo - http://opengeo.org/
>     Expert service straight from the developers.
>


-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.




More information about the Users mailing list