[Commits] r697 - sandbox/docsrc/primers
commits at geoext.org
commits at geoext.org
Wed May 13 00:14:10 CEST 2009
Author: dwins
Date: 2009-05-13 00:14:10 +0200 (Wed, 13 May 2009)
New Revision: 697
Modified:
sandbox/docsrc/primers/openlayers-primer.rst
Log:
Style tweaks for OpenLayers primer.
Modified: sandbox/docsrc/primers/openlayers-primer.rst
===================================================================
--- sandbox/docsrc/primers/openlayers-primer.rst 2009-05-12 21:56:00 UTC (rev 696)
+++ sandbox/docsrc/primers/openlayers-primer.rst 2009-05-12 22:14:10 UTC (rev 697)
@@ -1,3 +1,5 @@
+.. highlight:: javascript
+
====================
Primer: OpenLayers
====================
@@ -2,36 +4,22 @@
-The OpenLayers mapping library is the key component of GeoExt, performing the core map-related
-functions of every GeoExt-based application. To get up to speed with GeoExt, let's discover
-some OpenLayers basics.
+The OpenLayers mapping library is the key component of GeoExt, performing the core map-related functions of every GeoExt-based application. To get up to speed with GeoExt, let's discover some OpenLayers basics.
Layers
======
-As its name suggests, OpenLayers manages a list of layers that together form a web-based
-mapping client. Each layer represents a different piece of data: For instance, one layer
-might be responsible for displaying the boundary of a country, another layer responsible
-for that country's roads.
+As its name suggests, OpenLayers manages a list of layers that together form a web-based mapping client. Each layer represents a different set of data. For instance, one layer might be responsible for displaying the boundary of a country. Another layer responsible for that country's roads.
-OpenLayers contains many types of layers (you can see them all at the `OpenLayers website <http://trac.openlayers.org/browser/trunk/openlayers/lib/OpenLayers/Layer>`_). For this primer, we'll
-focus on two different layer types: WMS and WFS.
+OpenLayers contains many types of layers (you can see them all at the `OpenLayers website <http://trac.openlayers.org/browser/trunk/openlayers/lib/OpenLayers/Layer>`_). For this primer, we'll focus on two different layer types: ``WMS`` and ``Vector``.
-WMS
-~~~
+The WMS Layer
+~~~~~~~~~~~~~
-This is the canonical layer type found in almost all GeoExt applications, where one or more images are used to
-display map-related information to the user. This type is named 'WMS' because it implements the
-`Web Map Service <http://www.opengeospatial.org/standards/wms>`_ standard set by the
-`Open Geospatial Consortium. <http://www.opengeospatial.org/>`_
+This is the canonical layer type found in almost all GeoExt applications, where one or more images are used to display map-related information to the user. This type is named 'WMS' because it implements the `Web Map Service <http://www.opengeospatial.org/standards/wms>`_ standard set by the `Open Geospatial Consortium. <http://www.opengeospatial.org/>`_
-If you followed the :doc:`quickstart` guide in GeoExt under the heading 'Using GeoExt', you will have already encountered a MapPanel and created
-your very own WMS layer. Let's dissect what you did.
+If you followed the :doc:`/tutorials/quickstart` guide, you will have already encountered a ``MapPanel`` and created your very own WMS layer. Let's dissect what you did:
-new OpenLayers.Layer.WMS()
---------------------------
-
-After creating an OpenLayers Map (but before creating a GeoExt MapPanel), you encountered the following code:
-
.. code-block::
- html
-
+ javascript
+ :linenos:
+
var layer = new OpenLayers.Layer.WMS(
@@ -44,65 +32,51 @@
map.addLayer(layer);
This tells OpenLayers that you'd like to create a new WMS layer referenced by the ``layer`` variable, and that you'd like to add that layer
-to the map. In this case, we're adding the `Blue Marble data set provided by NASA <http://earthobservatory.nasa.gov/Features/BlueMarble/>`_
-
-The first parameter ("Blue Marble") represents the name of the layer. This can be anything, and is only used to reference the layer on screen.
+to the map. In this case, we're adding the `Blue Marble data set <http://earthobservatory.nasa.gov/Features/BlueMarble/>`_ provided by NASA.
-The second parameter represents the location of the WMS server tasked with providing the images. We're using a Geoserver instance located at
-sigma.openplans.org.
+In **line 2** we provide "Blue Marble" as the name of the layer. This can be anything, and is only used to reference the layer on screen.
-The third parameter lets you override the parameters of every request passed to the WMS server. Since many servers host different
-data sets, we need to specify which set we'd like: We do this by creating a new object and setting the ``layers`` key to the identifier
-of our Blue Marble data set.
+In **line 3** we provide the location of the WMS server tasked with providing the images. Here, we use a GeoServer instance located at ``sigma.openplans.org``\ .
-Note that ``layers`` isn't the only WMS parameter we can override. You can find out more in the
-`OpenLayers Class Documentation <http://dev.openlayers.org/apidocs/>`_, by selecting 'Layer' and then 'WMS' in the navigation.
+In **line 4** we provide extra parameters for the WMS server. Since many servers host different data sets, we need to specify which set we'd like. We do this by creating a new object and setting the ``layers`` property to ``"bluemarble"``\ , the identifier for the Blue Marble data set.
-And that's it! Now let's move onto WFS.
-
+Note that ``layers`` isn't the only WMS parameter we can provide. You can find out more in the `OpenLayers API Documentation <http://dev.openlayers.org/apidocs/>`_, by selecting 'Layer' and then 'WMS' in the navigation.
-WFS
-~~~
+And that's it! Now let's move on to the vector layer.
-WFS, like WMS, implements a standard set by the Open Geospatial Consortium, this time the
-`Web Feature Service <http://www.opengeospatial.org/standards/wfs>`_. Unlike WMS, however, the WFS layer is used to show
-points, lines and polygons instead of displaying images. In many cases, this layer is
-used to perform client-side rendering instead of having features rendered by the server.
+The Vector Layer
+~~~~~~~~~~~~~~~~
-new OpenLayers.Layer.WFS()
---------------------------
+The WMS Layer, and many of the layer types provided by OpenLayers, use raster files (images like JPG, GIF, and PNG) to display maps. However, OpenLayers can also render map features directly in the browser, simply by adding an ``OpenLayers.Layer.Vector`` to the map. This is useful when displaying data from an OGC `Web Feature Service <http://www.opengeospatial.org/standards/wfs>`, a KML document, or even sketched in by the user. Here's an example that generates some random data and displays it in a vector layer::
-Creating a WFS layer is very similar to creating a WMS layer.
+ var vectorLayer = new OpenLayers.Layer.Vector();
+ for (var i = 0; i < 10; i++){
+ var x = -180 + Math.random() * 360;
+ var y = -90 + Math.random() * 180;
+ var numSides = 3 + Math.round(Math.random() * 6);
+ vectorLayer.addFeature(
+ new OpenLayers.Feature.Vector(
+ OpenLayers.Geometry.Polygon.createRegularPolygon(
+ new OpenLayers.Geometry.Point(x, y),
+ numSides)));
+ }
- .. code-block::
- html
-
- var layer = new OpenLayers.Layer.WFS(
- "United States",
- "http://sigma.openplans.org/geoserver/wfs",
- { typename: 'topp:states' }
- );
- map.addLayer(layer);
-
-Like the WMS layer, the parameters contain a layer name ("United States"), the url of the data provider and options for the WFS request.
-In this case, we're requesting the ``'topp:states'`` layer so it can be rendered in the browser by OpenLayers.
+ var map = new OpenLayers.Map();
+ map.addLayer(vectorLayer);
-This layers extends the `Vector Layer <http://trac.openlayers.org/browser/trunk/openlayers/lib/OpenLayers/Layer/Vector.js>`_.
+While OpenLayers provides customized vector layers for loading data from existing sources, the GeoExt team recommends that you use the generic vector layer and populate it using :class:`GeoExt.data.FeatureStore`\ . For more information on doing this, see :doc:`/tutorials/remote-features-tutorial`\ .
Other Layers
------------
-WMS and WFS are not the only layers out there: There are plenty more available.
-`Browse the OpenLayers source code <http://trac.openlayers.org/browser/trunk/openlayers/lib/OpenLayers/Layer>`_ for more information.
+WMS and Vector are not the only layer types in OpenLayers. There are plenty more available, including Google Maps, Virtual Earth, and many more. Browse the `OpenLayers API documentation <http://dev.openlayers.org/apidocs>`_ for more information.
-
Controls
========
Although OpenLayers is great at managing layers, it also provides a way to interact with those layers, primarily through the use of controls.
-Controls are primary user interface elements and/or API hooks that control and manage interaction with an OpenLayers map. For instance, panning
-and navigating a map is handled by the ``Navigation`` control. If you want a zoom bar in addition to zoom buttons, you'd add a ``PanZoomBar``
+Controls are primary user interface elements and/or API hooks that control and manage interaction with an OpenLayers map. For instance, panning and navigating a map is handled by the ``OpenLayers.Control.Navigation`` control. If you want a zoom bar in addition to zoom buttons, you'd add a ``PanZoomBar``
control. If you then want to see where you've navigated, you'd use the ``NavigationHistory`` control.
Each control provides different and unique functionality. For this primer, we'll focus only on the ``NavigationHistory`` control.
More information about the Commits
mailing list