OpenSpace.Map

This class sets up a map window containing an Open Space data layer, a vector layer and a marker layer.

Inherits

Example

The following example shows how to add a default map and set the map center:

var osMap;

function init()
{
osMap = new OpenSpace.Map('map');
osMap.setCenter(new OpenSpace.MapPoint(438760,114760), 8);
}
Summary
This class sets up a map window containing an Open Space data layer, a vector layer and a marker layer.
Constructor for a new OpenSpace.Map instance.
A convenience method to return a reference to the default marker layer.
A convenience method to return a reference to the default vector layer.
A convenience method to return a reference to the info window.
A convenience method to create a marker, optionally with an associated popup info window.
A convenience method to remove a marker.
A convenience method to remove all markers.
A convenience method to add features to the map.
A convenience method to remove features from the map.
A convenience method to remove all features from the map.
A convenience method to open a popup info window.
A convenience method to close a popup info window.
This function should be called by any external code which dynamically changes the size of the map div (because mozilla wont let us catch the “onresize” for an element)
Gets the coordinates of a point on the map given the position of a point on the map window

Constructor

OpenSpace.Map

Constructor for a new OpenSpace.Map instance.

Parameters

div{String} Id of an element in your page that will contain the map.
options{Object} Optional object with properties to tag onto the map.

Examples

// create a map with default options in an element with the id "map1"
var osMap = new OpenSpace.Map("map1");

// create a map with non-default options in an element with id "map2"
// This example will restrict the mapping resolutions to the overview maps only
var options = {
resolutions: [2500, 1000, 500]
};
var osMap = new OpenSpace.Map("map2", options);

Functions

getMarkerLayer

getMarkerLayer: function()

A convenience method to return a reference to the default marker layer.

Returns

{OpenLayers.Layer.Markers}

getVectorLayer

getVectorLayer: function()

A convenience method to return a reference to the default vector layer.

Returns

{OpenLayers.Layer.Vector}

getInfoWindow

getInfoWindow: function()

A convenience method to return a reference to the info window.

Returns

{OpenSpace.InfoWindow}

createMarker

createMarker: function(pos,
icon,
html,
size)

A convenience method to create a marker, optionally with an associated popup info window.  The marker is added to the default markers layer on the map.

Parameters

pos{OpenSpace.MapPoint} Position of the marker on the map
icon{OpenSpace.Icon} The image to show for the marker
html{String} The HTML contents of the associated popup window
size{OpenSpace.ScreenSize} The size of the popup window

Returns

{OpenLayers.Marker}

Example

// Add a default marker
var pos = new OpenSpace.MapPoint(440000, 110000);
var marker = osMap.createMarker(pos);
// Add a marker with custom icon and a popup info window
var pos = new OpenSpace.MapPoint(444000, 110000);
var size = new OpenLayers.Size(33, 45);
var offset = new OpenLayers.Pixel(-16, -37);
var infoWindowAnchor = new OpenLayers.Pixel(16, 16);
var icon = new OpenSpace.Icon('http://openspace.ordnancesurvey.co.uk/osmapapi/img/OS/images/markers/marker_blue.png', size, offset, null, infoWindowAnchor);
var marker = osMap.createMarker(pos, icon, 'test info window content in HTML <b>bold</b> <a href="index.html">Back to Index</a><p>fsdfsfd sdf sf sd sdf sd f sd fs df sdf fdfsdfdf sdfsdfsd sdfsf.</p><img src=\"logo.gif\"/>', new OpenLayers.Size(200, 300));

removeMarker

removeMarker: function(marker)

A convenience method to remove a marker.  The marker is removed from the default markers layer on the map.

Parameters

marker{OpenLayers.Marker} Marker to be removed

clearMarkers

clearMarkers: function()

A convenience method to remove all markers.  All markers are removed from the default marker layer on the map.

addFeatures

addFeatures: function(features)

A convenience method to add features to the map.  The features are added to the default vector layer on the map.

Parameters

features{Array(OpenLayers.Feature.Vector)}

removeFeatures

removeFeatures: function(features)

A convenience method to remove features from the map.  The features are removed from the default vector layer on the map.

Parameters

features{Array(OpenLayers.Feature.Vector)}

destroyFeatures

destroyFeatures: function()

A convenience method to remove all features from the map.  All features in the default vector layer are removed.

openInfoWindow

openInfoWindow: function(icon,
pos,
html,
size)

A convenience method to open a popup info window.

Parameters

icon{OpenSpace.Icon} The image from which the popup window will appear from.
pos{OpenSpace.MapPoint} The position on the map the popup will appear from.
html{String} The HTML contents of the popup.
size{OpenSpace.ScreenSize} The size of the popup.

closeInfoWindow

closeInfoWindow: function()

A convenience method to close a popup info window.

getCenter

getCenter: function ()

Returns

{OpenSpace.MapPoint}

setCenter

setCenter: function (mapPoint,
zoom,
dragging,
forceZoomChange)

Parameters

mapPoint{OpenSpace.MapPoint}
zoom{Integer}
dragging{Boolean} Specifies whether or not to trigger movestart/end events
forceZoomChange{Boolean} Specifies whether or not to trigger zoom change events (needed on baseLayer change)

updateSize

updateSize: function()

This function should be called by any external code which dynamically changes the size of the map div (because mozilla wont let us catch the “onresize” for an element)

getMapPointFromViewPortPx

getMapPointFromViewPortPx: function (viewPortPx)

Gets the coordinates of a point on the map given the position of a point on the map window

Parameters

viewPortPx{OpenLayers.Pixel} Position of a point on the map viewport

Returns

{OpenSpace.MapPoint} An OpenSpace.MapPoint which is the passed-in view port OpenLayers.Pixel, translated into British National Grid by the current base layer.

getViewPortPxFromMapPoint

getViewPortPxFromMapPoint: function (mapPoint)

Parameters

mapPoint{OpenSpace.MapPoint}

Returns

{OpenLayers.Pixel} An OpenLayers.Pixel which is the passed-in OpenSpace.MapPoint, translated into view port pixels by the current base layer.

getMapPointFromPixel

getMapPointFromPixel: function (px)

Parameters

px{OpenLayers.Pixel}

Returns

{OpenSpace.MapPoint} An OpenSpace.MapPoint corresponding to the given OpenLayers.Pixel, translated into British National Grid by the current base layer

getPixelFromMapPoint

getPixelFromMapPoint: function (mapPoint)

Parameters

mapPoint{OpenSpace.MapPoint}

Returns

{OpenLayers.Pixel} An OpenLayers.Pixel corresponding to the OpenSpace.MapPoint translated into view port pixels by the current base layer.

getMapPointFromLayerPx

getMapPointFromLayerPx: function (px)

Parameters

px{OpenLayers.Pixel}

Returns

{OpenSpace.MapPoint}

getLayerPxFromMapPoint

getLayerPxFromMapPoint: function (mapPoint)

Parameters

mapPoint{OpenSpace.MapPoint} map point

Returns

{OpenLayers.Pixel} An OpenLayers.Pixel which is the passed-in OpenSpace.MapPoint, translated into layer pixels by the current base layer

getMarkerLayer: function()
A convenience method to return a reference to the default marker layer.
getVectorLayer: function()
A convenience method to return a reference to the default vector layer.
getInfoWindow: function()
A convenience method to return a reference to the info window.
createMarker: function(pos,
icon,
html,
size)
A convenience method to create a marker, optionally with an associated popup info window.
removeMarker: function(marker)
A convenience method to remove a marker.
clearMarkers: function()
A convenience method to remove all markers.
addFeatures: function(features)
A convenience method to add features to the map.
removeFeatures: function(features)
A convenience method to remove features from the map.
destroyFeatures: function()
A convenience method to remove all features from the map.
openInfoWindow: function(icon,
pos,
html,
size)
A convenience method to open a popup info window.
closeInfoWindow: function()
A convenience method to close a popup info window.
getCenter: function ()
{OpenSpace.MapPoint}
This class represents an eastings and northings pair of coordinates in British National Grid (BNG) format
setCenter: function (mapPoint,
zoom,
dragging,
forceZoomChange)
updateSize: function()
This function should be called by any external code which dynamically changes the size of the map div (because mozilla wont let us catch the “onresize” for an element)
getMapPointFromViewPortPx: function (viewPortPx)
Gets the coordinates of a point on the map given the position of a point on the map window
getViewPortPxFromMapPoint: function (mapPoint)
getMapPointFromPixel: function (px)
getPixelFromMapPoint: function (mapPoint)
getMapPointFromLayerPx: function (px)
getLayerPxFromMapPoint: function (mapPoint)
Instances of OpenLayers.Map are interactive maps embedded in a web page.
Instances of OpenLayers.Layer.Vector are used to render vector data from a variety of sources.
This class sets up a popup info window containing user supplied HTML content.
A class to extend OpenLayers.Icon to hold extra information on the offset of the infoWindow.
Instances of this class represent a width/height pair
Instances of OpenLayers.Marker are a combination of a OpenLayers.LonLat and an OpenLayers.Icon.
Vector features use the OpenLayers.Geometry classes as geometry description.
This class represents a screen coordinate, in x and y coordinates