[OpenLayers-Users] OpenLayers, syntax issue.

Andreas Hocevar ahocevar at opengeo.org
Thu Nov 24 15:47:06 EST 2011


On Thu, Nov 24, 2011 at 8:21 PM, jns <jnsoak at gmail.com> wrote:
> Hi,
>
> I apologize if this isn't the correct forum for my sort of question. But I'm
> very new to this and I will however give it a try.
>
> This line of code will render the map just as it is supposed to do:
>
> map = new OpenLayers.Map({div: "map", controls: [geolocate], layers:
> [layer]});
>
> ... but shouldn't the following lines give me the same result?
>
> map = new OpenLayers.Map("map");
> map.addControl(geolocate);
> map.addLayer(layer);

These two are not 100% equivalent. The first one creates a map with
geolocate as its only control. The second one adds geolocate to the
default controls (Navigation, PanZoom, ArgParser, Attribution). If you
have a minified build that does not provide all of these default
controls, your application will fail before the map gets rendered.

The 100% equivalent of your first snippet would be

map = new OpenLayers.Map("map", {controls: []});
map.addControl(geolocate);
map.addLayer(layer);

Andreas.

>
> I thought they were equivalent to the above statement, but apparently not
> since no map is rendered. I use jQuery Mobile if it may make any differences
>
> Thanks,
> Jonas
>
> --
> View this message in context: http://osgeo-org.1803224.n2.nabble.com/OpenLayers-syntax-issue-tp7029250p7029250.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>



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


More information about the Users mailing list