This topic discusses the client API functions used by JavaScript in Map Suite Web Edition 4.0 and higher. You can use these functions by Map.ClientID. For example, if your map control’s clientID on the web page is “Map1”, use these functions by calling Map1.GetMapParser(); in JavaScript.
This topic discusses the client API functions used by JavaScript in Map Suite Web Edition 3.0 and higher.
Contents:
- Overview
- GetOpenLayersMap()
- GetExtent()
- GetCenter()
- SetCenter(lon,lat)
- ZoomIn()
- ZoomOut()
- ZoomToExtent(extent)
- PanByScreenPixel(x, y)
- PanToWorldCoordinate(x, y)
- ZoomToPreviousExtent()
- ZoomToNextExtent()
- ToggleExtent()
- SetDrawMode()
- ClearFeatures()
- CancelLatestFeature()
- PrintMap()
- GetCurrentBaseLayer()
- SetBaseLayer(layerId)
- SetCurrentBackgroundMapType(backgroundMapType)
- SetEditSetting(editSettings)
- OnMapCreating()
- OnMapCreated()
- How To Use OpenLayers’ API
Overview
Use the following functions by Map.ClientID. For example, if your map control’s clientId on the web page is “Map1”, use these functions by calling “Map1.GetMapParser();” in JavaScript.
GetOpenLayersMap()
Description:
Returns OpenLayers.Map object used by current map control. You can call map’s function directly by using it.
Return type: {OpenLayers.Map}
Sample Code:
var map = Map1.GetOpenLayersMap();
GetExtent()
Description:
Returns an OpenLayers.Bounds object which represents the longitude/latitude bounds of the current viewport. If no baseOverlay is set, returns null.
Return type: {OpenLayers.Bounds}
Sample Code:
var extent = Map1.GetExtent();
ZoomIn()
Description:
Zoom in the map by one zoom level.
Sample Code:
Map1.ZoomIn();
Sample Online:
websamples.thinkgeo.com/Samp…ndOut.aspx
ZoomOut()
Description:
Zoom out the map by one zoom level.
Sample Code:
Map1.ZoomOut();
Sample Online:
websamples.thinkgeo.com/Samp…ndOut.aspx
ZoomToExtent(extent)
Description:
Zoom to the specified extent and re-center.
Parameters:
extent: {OpenLayers.Bounds} A fixed extent to zoom to.
Sample Code:
var extent = new OpenLayers.Bounds(30, -95, 78, -60);
Map1.ZoomToExtent(extent);
GetCenter()
Description:
Get an OpenLayers.LonLat object which represents the longitude/latitude of the center of the current viewPort of the map.
Return type: {OpenLayers.LonLat} current center longitude and latitude.
Sample Code:
var center = Map1.GetCenter();
Sample Online:
websamples.thinkgeo.com/Samp…heMap.aspx
SetCenter(longitude, latitude)
Description:
Allow users to re-center the map to the specified longitude & latitude directly.
Parameters:
longitude: {float} The x-axis coordinate in map units
latitude: {float} The y-axis coordinate in map units
Sample Code:
var lonlat = Map1.GetCenter();
var newLongitude = lonlat.lon + 10;
var newLatitude = lonlat.lat + 10;
Map1.SetCenter(newLongitude, newLatitude);
Sample Online:
websamples.thinkgeo.com/Samp…tMenu.aspx
PanByScreenPixel(x, y)
Description:
Pan the map by a value of screen pixels.
Parameters:
x: {Integer} Screen pixel
y: {Integer} Screen pixel
Sample Code:
Map1.PanByScreenPixel (100, 100)
PanToWorldCoordinate(longitude, latitude)
Description:
Pans to a new longitude & latitude. If the new longitude & latitude is in the current extent, the map will slide smoothly.
This function is similar to SetCenter(longitude, latitude), but the effect is different. The SetCenter(longitude, latitude) function jumps to the target instantly, while the PanToWorldCoordinate(longitude, latitude) function pans smoothly over to the target if the target is in the current extent.
Parameters:
longitude: {float} The x-axis coordinate in map units
latitude: {float} The y-axis coordinate in map units
Sample Code:
var lonlat = Map1.GetCenter();
var newLongitude = lonlat.lon + 10;
var newLatitude = lonlat.lat + 10;
Map1.PanToWorldCoordinate(newLongitude, newLatitude);
Sample Online:
websamples.thinkgeo.com/Samp…heMap.aspx
ZoomToPreviousExtent()
Description:
Restore to previous extent.
Sample Code:
Map1.ZoomToPrevousExtent();
Sample Online:
websamples.thinkgeo.com/Samp…story.aspx
ZoomToNextExtent()
Description:
Restore to the next extent.
Sample Code:
Map1.ZoomToNextExtent();
Sample Online:
websamples.thinkgeo.com/Samp…story.aspx
ToggleExtent()
Description:
Toggle the map between the previous and the next extent.
Sample Code:
Map1.ToggleExtent();
Sample Online:
websamples.thinkgeo.com/Samp…story.aspx
SetDrawMode(drawMode)
Description:
Set the map mode by the drawMode parameter. The map mode can be set as “Point”, “Line”, “Polygon”, “Rectangle”, “Square”, “Circle”, “Ellipse”, “Normal” and “Modify”. In the “Normal” mode, the map is in its normal state. In the “Modify” mode, the shapes on the map can be edited. In other modes, you can draw the specified shapes on the map.
Parameters:
“DrawMode”: {string} can be specified as “Point”, “Line”, “Polygon”, “Rectangle”, “Square”, “Circle”, “Ellipse”, “Normal”, “Modify”.
Sample Code:
Map1.SetDrawMode(“Normal”);
Map1.SetDrawMode(“Modify”);
Map1.SetDrawMode(“Point”);
Map1.SetDrawMode(“Line”);
Map1.SetDrawMode(“Polygon”);
Map1.SetDrawMode(“Rectangle”);
Map1.SetDrawMode(“Square”);
Map1.SetDrawMode(“Circle”);
Map1.SetDrawMode(“Ellipse”);
Sample Online:
websamples.thinkgeo.com/Samp…hapes.aspx
ClearFeatures()
Description:
Clear all features drawn on the map.
Sample Code:
Map1.ClearFeatures();
CancelLatestFeature()
Description:
Delete the latest drawn feature.
Sample Code:
Map1. CancelLatestFeature();
Sample Online:
websamples.thinkgeo.com/Samp…hapes.aspx
PrintMap()
Description:
Print the current map.
Sample Code:
Map1.PrintMap();
GetCurrentBaseLayer()
Description:
Allow users to get the map’s current base layer.
Return Type: {OpenLayers.Layer}
Sample Code:
Map1.GetCurrentBaseLayer();
SetBaseLayer(layerId)
Description:
Allow users to specify one of the currently-loaded layers as the map’s new base layer.
Parameters:
layerId: {String} An Id of a layer which you added on the map.
Server Code: Focus on the Id parameter in the constructor of the following Overlays.
WmsOverlay wms = new WmsOverlay(“WMS”);
wms.ServerUris.Add(new Uri(“labs.metacarta.com/wms/vmap0”));
wms.Parameters.Add(“layers”, “basic”);
wms.Parameters.Add(“SRS”, “EPSG:900913”);
GoogleOverlay google = new GoogleOverlay(“Google”);
google.GoogleMapType = GoogleMapType.Normal;
YahooOverlay yahoo = new YahooOverlay(“Yahoo”);
yahoo.YahooMapType = YahooMapType.Regular;
VirtualEarthOverlay ve = new VirtualEarthOverlay(“VE”);
ve.VirtualEarthMapType = VirtualEarthMapType.Road;
Map1.CustomOverlays.Add(wms);
Map1.CustomOverlays.Add(google);
Map1.CustomOverlays.Add(yahoo);
Map1.CustomOverlays.Add(ve);
Client Code: Use the following code to set the preset layer as current base layer.
Map1.SetBaseLayer(“WMS”);
Map1.SetBaseLayer(“Google”);
Map1.SetBaseLayer(“Yahoo”);
Map1.SetBaseLayer(“VE”);
SetCurrentBackgroundMapType(backgroundMapType)
Description:
Change current OpenLayers third part layer’s type.
Please reference the Google, Virtual Earth, or Yahoo API you registered on the web page, then find what type of map they support.
For example:
Google supports: G_HYBRID_MAP, G_NORMAL_MAP, G_SATELLITE_MAP, G_PHYSICAL_MAP…
Reference guide to Google’s supported Map Types:
Google Map Attributes
Yahoo supports: YAHOO_MAP_SAT, YAHOO_MAP_REG, YAHOO_MAP_HYB…
Reference guide to Yahoo’s Map Type control:
Using YMapTypeControl to position map types
Virtual Earth supports: VEMapStyle.Road, VEMapStyle.Aerial, VEMapStyle.Hybrid…
Please reference the latest API to get more supported Map Types.
Sample Code:
//If current map layer is Google:
Map1.SetCurrentBackgroundMapType(G_HYBRID_MAP);
//If current map layer is Virtual Earth:
Map1.SetCurrentBackgroundMapType(VEMapStyle.Road);
//If current map layer is Yahoo:
Map1.SetCurrentBackgroundMapType(YAHOO_MAP_SAT);
Sample Online:
websamples.thinkgeo.com/Samp…ooWms.aspx
SetEditSetting(editSettings)
Description:
Set current map edit mode to Reshape|Rotate|Resize|Drag mode.
Parameters:
editSettings: {string} Can be specified as: EditSettings.Reshape, EditSettings.Resize, EditSettings.Rotate, EditSettings.Drag
Sample Code (using only one setting):
Map1.SetEditSetting(EditSettings.Reshape);
Map1.SetEditSetting(EditSettings.Resize);
Map1.SetEditSetting(EditSettings.Rotate);
Map1.SetEditSetting(EditSettings.Drag);
Sample Code (using multiple settings):
Map1.SetEditSetting(EditSettings.Reshape|EditSettings.Resize|EditSettings.Rotate|EditSettings.Drag);
OnMapCreating()
Description:
Call before the map is initialized.
Sample Code:
<script type=“text/JavaScript”>
var OnMapCreating = function(map){
// JavaScript code
}
</script>
OnMapCreated()
Description:
Call after the map is created.
Sample Code:
<script type=“text/JavaScript”>
var OnMapCreated = function(map){
// JavaScript code
}
</script>
How To Use OpenLayers’ API
- OpenLayers class document online: dev.openlayers.org/releases/…rs-js.html
- How to use it in Map Suite Web Edition:
In Web Edition, all of OpenLayers’ objects are added to the Map object. Thus, we can use OpenLayers’ class via Map.
Example: Add a new WmsLayer on the map using JavaScript:
var OnMapCreated = function(map){
var wmsLayer = new OpenLayers.Layer.WMS( “OpenLayers WMS”, “labs.metacarta.com/wms/vmap0”, {layers: ‘basic’});
map.addLayer(wmsLayer);
}