Widget:OpenStreetMap: Difference between revisions

From Nottinghack Wiki
Jump to navigation Jump to search
Marcus (talk | contribs)
First attempt, not tested
 
Marcus (talk | contribs)
Added central marker and points of interest. Still not tested.
Line 1: Line 1:
<noinclude>__NOTOC__
<noinclude>This widget allows you to embed '''[http://openstreetmap.org OpenStreetMap]''' in a wiki page.
This widget allows you to embed an '''[http://openstreetmap.org OpenStreetMap]''' in a wiki page.


== Using this widget ==
== Using this widget ==
Line 8: Line 7:


=== Parameters ===
=== Parameters ===
;width
: Width of the embedded map (default 400px).
;height
: Height of the embedded map (default 400px).
;lat
;lat
: The x coordinate.
: The x-coordinate for the centre of the view.
;lon
;lon
: The y coordinate.
: The y-coordinate for the centre of the view.
;units
: The type of [http://dev.openlayers.org/docs/files/OpenLayers/Map-js.html#OpenLayers.Map.units map units] used for the coordinates (defaults to 'degrees').
;zoom
;zoom
: The zoom level.
: The [http://wiki.openstreetmap.org/wiki/Zoom_levels zoom level] (default 15).
;showmarker
: Adds a visual marker to the center of the map (default false).
;poifile
: Specifies a file containing points of interest (POI) that should be overlaid on the map.  See the file format description in [http://dev.openlayers.org/releases/OpenLayers-2.6/doc/apidocs/files/OpenLayers/Layer/Text-js.html].
;poititle
: The title of the POI layer (default 'Points of interest').


== Example ==
== Example ==
{{#widget:OpenStreetMap|lat=13.41|lon=52.52|zoom=15}}
{{#widget:OpenStreetMap|lat=13.41|lon=52.52|zoom=15}}


</noinclude><includeonly>
</noinclude><includeonly><!--{counter name="openStreetMapDivID" assign="openStreetMapDivID"}--><div id="openStreetMap<!--{$openStreetMapDivID|escape:'html'}-->" style="width:<!--{$width|escape:'html'|default:'400px'}-->; height:<!--{$height|escape:'html'|default:'400px'};"></div><!--{if $openStreetMapDivID == 1}--><script type="text/javascript" src="http://www.openlayers.org/api/OpenLayers.js"></script><!--{/if}--><script type="text/javascript">
<div id="basic_map_<!--{counter name="osm_widget_counter"}-->" style="width: 400; height: 400;"></div><script src="http://www.openlayers.org/api/OpenLayers.js"></script><script>
(function (){
(function (){
   map = new OpenLayers.Map("basic_map_<!--{counter name="osm_widget_counter"}-->");
   var lon = <!--{$lon|validate:float}-->;
  var lat = <!--{$lat|validate:float}-->;
  var zoom = <!--{$zoom|validate:int|default:15}-->;
  var divID = 'openStreetMap<!--{$openStreetMapDivID|escape:'quotes'}-->';
  var mapUnits = '<!--{$units|escape:'quotes'|default:'degrees'}-->';
 
  map = new OpenLayers.Map(divID, {units:mapUnits});
   var mapnik = new OpenLayers.Layer.OSM();
   var mapnik = new OpenLayers.Layer.OSM();
   map.addLayer(mapnik);
   map.addLayer(mapnik);
   map.setCenter(new OpenLayers.LonLat(<!--{$lon|validate:float}-->, <!--{$lat|validate:float}-->) // Center of the map
 
       .transform(
  // transform from WGS 1984 to Spherical Mercator projection
        new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
  var centerPt = new OpenLayers.LonLat(lon, lat).transform(
        new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
      new OpenLayers.Projection('EPSG:4326'),
      ), <!--{$zoom|validate:int}--> // Zoom level
      map.getProjectionObject();
   );
 
  <!--{if $showmarker}-->
  var markers = new OpenLayers.Layer.Markers("Markers");
   map.addLayer(markers);
  markers.addMarker(new OpenLayers.Marker(centerPt));
  <!--{/if}-->
 
  <!--{if $poifile}-->
  var pois = new OpenLayers.Layer.Text(
      '<!--{$poititle|escape:'quotes'|default:'Points of interest'}-->',
      {
        location:'<!--{$poifile|escape:'quotes'}-->',
        projection:map.displayProjection
       });
  map.addLayer(pois);
  <!--{/if}-->
 
   map.setCenter(centerPt, zoom);
})();
})();
</script><noscript>Please enable JavaScript to view the OpenStreetMap.</noscript></includeonly>
</script><noscript>Please enable JavaScript to view the <a href="http://www.openstreetmap.org/">OpenStreetMap</a>.</noscript></includeonly>

Revision as of 17:09, 11 March 2011

This widget allows you to embed OpenStreetMap in a wiki page.

Using this widget

You can insert a map with the following wiki code:

{{#widget:OpenStreetMap|lat=13.41|lon=52.52|zoom=15}}

Parameters

width
Width of the embedded map (default 400px).
height
Height of the embedded map (default 400px).
lat
The x-coordinate for the centre of the view.
lon
The y-coordinate for the centre of the view.
units
The type of map units used for the coordinates (defaults to 'degrees').
zoom
The zoom level (default 15).
showmarker
Adds a visual marker to the center of the map (default false).
poifile
Specifies a file containing points of interest (POI) that should be overlaid on the map. See the file format description in [1].
poititle
The title of the POI layer (default 'Points of interest').

Example

© OpenStreetMap