Application Programming Interface
 Map 
 News 
New Products 
EN ▼
Introduction | Classes: SearchChMap  SearchChPOI |

[map.search.ch] API Reference

The class reference describes all public classes of the API and their methods. Those classes can be used to embed and control the interactive swiss map.

class SearchChMap

This is the main class represeting the map widget and it has to be instantiated within your HTML page.

Constructor

var Map = new SearchChMap({ container:"mapcontainer" });

The contructor expects an object with the following named properties as the only parameter:

PropertyTypeOptionalDefaultDescription
containerMixedyesmapcontainerDOM reference or ID of the container containing the map. Preferably a block element like <div> or <p>
centerMixedyes-Center of the map. String with a swiss address or an array with geo-coordinates. See geographical references for details.
fromMixedja-Start of a route. Same values as in center but requires to as counterpart.
toMixedja-Destination of a route. Same values as in center but requires from as counterpart.
typeStringyesaerialMap type aerial or street
zoomNumberyesautoZoom level. Accepted values: 512,128,32,8,2,1,0.5
These values represent the number of meters per pixel. Will be automatically rounded to the next defined level.
controlsStringyesdefaultUI elements within the map allowing user interaction (comma-separated string):
default: Default selection of control elements
zoom: Zoom control
type: Switch to toggle between aerial and street view
pan: Arrows for panning the map
ruler: Display of the current scale
or string "all"
enableStringyesdragging,clickzoom,poisDifferent behaviors to interact with the map (comma-separated string):
dragging: Click and drag the map with the mouse
clickzoom: Zoom on mouse click. Left button zooms in, right button zooms out
mousewheel: Scroll the map using the mouse wheel
keyboard: Control the map using the arrow and +/- keys of the keyboard
pois: Info-box appearing when mouse moves across a POI
or string "all"
poigroupsStringyesdefaultGroups of POIs to display (comma-separated string). See POI groups and categories.
drawingStringyes-Overlay the map with a drawing created by the "Draw on map" function on map.search.ch, e.g. "mu4zdnjn2".
circleBooleanyesautoEnables the circle indicating the target address (if address enough precisely defined).
autoloadBooleanyestrueIf true the map starts automatically once the page is loaded (onload). Setting this parameter to false means that you need to start the map manually using the method init().
autoresizeBooleanyestrueLet the map automatically detect changes of the containers's size. If set to false, changes need to be reported to the map instance using resized().

Object methods

MethodReturn valueDescription
set(Object p)voidSet or update properties of the map. Requires an object with the same named parameters (except container) as the constructor.
go(Object p)voidMove the map to the given address (center) or by a number of pixels (dx/dy). An object with named parameters is expected:
center: geographical reference of the new center
zoom: Zoom level to switch to (optional). See constructor for allowed values.
dx: Horizontal displacement (in pixels)
dy: Vertical displacement (in pixels)
circle: Enables the circle indicating the target address (Boolean)
Negative values for dx and dy will displace the map in the opposite direction. Floats from 0 to 1 will be interpreted as a percentage of the current width/height of the map.
get([String what])mixedGetter for properties of the map object. All names supported by set() can be used to read a specific property. If called without the optional parameter the method returns an object containing all the properties.
Example: Map.get('zoom') and Map.get().zoom both return the current zoom level. In case the map displays a route then Map.get('routeinfo').distance will provide informations (like the distance in this example) about it.
zoom(int dir)voidZoom the map view. dir > 0: zoom in, dir < 0: zoom out.
enable(String what)voidActivate behaviors for user interaction. Requires a comma-separated list of interaction modes. See constructor parameter enable.
disable(String what)voidDeactivate behaviors. Same values allowed as for enable().
showPOIGroup(String groups)voidShow one or many groups of POIs. Expects a comma-separated string according to this list.
hidePOIGroup(String groups)voidHide groups of POIs. Same parameter as for showPOIGroup()
addPOI(SearchChPOI obj)voidAdd a custom POI to the map. Requires an instance of SearchChPOI as single parameter.
removePOI(SearchChPOI obj)voidRemove a custom POI from the map. Requires a reference to the according SearchChPOI object.
removeAllPOIs()voidRemove all custom POIs from the map.
getPermUrl(String mode)StringReturns an absolute URL to map.search.ch representing the current viewport. Use the optional parameter mode to get an URL for the print view ("print"), the send map page ("email") or the route directions ("directions").
addEventListener(
  String event, mixed func[, Object obj])
voidRegister a handler function for a certain event of the map.
event: Name of the event. See the list below.
func: Reference to a global function or string naming a method of obj.
obj: The object, the method named in func of which will be called.
removeEventListener(
  String event, mixed func[, Object obj])
voidRemove a handler that was activated previously. Requires the same parameters used to register the handler.
resize(int w, int h)voidScale the map container to the given size.
init()voidManually start the map. Needs to be executed if autoload was set to false.

Events

EventDescription
loadIs fired once the map is loaded completely, i.e. all tiles are loaded and visible.
changeIs fired if the viewport of the map is changed e.g. after dragging or zooming.
maptypechangedIs fired when the map type (aerial/street view) is changed.
dragstartIs fired when the user starts dragging the map with the mouse.
dragendIs fired when the user releases the mouse and dragging stopped.
mouseclickIs fired when the user clicks on the map.
panstartIs fired when the map starts to pan. This can be triggered either by the keyboard or by the pan UI control but not when dragging.
panendIs fired when the panning stops.
zoomstartIs fired when the map starts to zoom.
zoomendIs fired when the zoom animation is over.
mapmoveIs fired continuously when the map is scrolled.

Event handlers can be registered and removed as follows. A handler can either be a global function or an object method and gets an object containing event-specific properties as single parameter.

// Register an event-handler function Map.addEventListener("load", function(e){ alert(e.event); }); // Add and remove an object method as event-listener Map.addEventListener("change", "mapchanged", MyObj); Map.removeEventListener("change", "mapchanged", MyObj);

POI groups and categories


default: Default selection depending on the current zoom level
verkehr: Traffic
bergbahn Mountain trsp
parkhaus Car park
haltestelle Tram/Bus
zug Railway
viasuisse Traffic info
gastro: Gastronomy
bar Bar
cafe Cafe
hotel Hotel
restaurant Restaurant
kultur: Entertainment
kino Cinema
museum Museum
theater Theater
tour Excursions
feuerstelle Fireplace
spielplatz Playground
bad Swimming pool
gebaeude: Public Buildings
kirche Church
polizei Police
schule School
spital Hospital
verwaltung Administration
service: Shopping/Service
apotheke Pharmacy
geldautomat Cash dispenser
post Post Office
shop Shop
tankstelle Gas station
geo: Geo/Weather
berg Mountains
pass Passes
wasserfall Waterfalls
webcam Webcam
meteoradar Weather radar
wikipedia Wikipedia

And this is how those groups are switched on and off:

Map.showPOIGroup("verkehr,bar,cafe,theater"); Map.hidePOIGroup("mobility");

 

class SearchChPOI

This class represents a custom POI (Point of Interest) for the interactive map. Instances of SearchChPOI can be positioned on the map using the method addPOI().

Constructor

var Poi = new SearchChPOI({ center:[600000,200000], html:"Sternwarte Bern" }); Map.addPOI(Poi);

The contructor expects an object with the following named properties as the only parameter:

PropertyTypeOptionalDescription
centerMixednoPosition of the icon. Can either be a string with a swiss address or an array with geo-coordinates. See geographical references for details.
htmlStringnoInfo-box content. HTML code is allowed here.
titleStringyesTitle of the info-box
iconStringyesImage URL of the icon displayed on the map
widthIntegeryesIcon width in pixels
heightIntegeryesIcon height in pixels
enabledBooleanyesTrue (default) if the info-box should pop up when mouse runs over the icon
minzooomNumberyesPOI is only displayed on zoom levels equal or above this value (see parameter zoom of SearchChMap)
maxzooomNumberyesPOI is only displayed on zoom levels less or equal this value

Object methods

MethodReturn valueDescription
set(Object p)voidSet or update properties of the POI object. Requires an object with the same named parameters as for the constructor.
open()voidOpen up the info-box. If the icon is outside the current viewport the map will be moved until the the POI appears.
close()voidHide the info-box if shown
hide()voidHide the icon on the map
show()voidMake the icon visible again
destroy()voidRemove the POI icon from the map and clear all internal references to the object
isVisible()booleanDetermines whether the POI is currently visible in the map
addEventListener(
  String event, mixed func[, Object obj])
voidRegister an event handler.
event: Name of the event. See the following list.
func: Reference to a global function or string with method name of obj.
obj: The object, the method named in func of which will be called.
removeEventListener(
  String event, mixed func[, Object obj])
voidRemove a handler that was activated previously. Requires the same parameters used to register the handler.

Events

EventDescription
mouseoverIs fired when the mouse enters the POI icon on the map.
mouseoutIs fired when the mouse leaves the icon again.
mouseclickIs fired when the POI icon is clicked.
popupopenIs fired when the info-box pops up.
popupcloseIs fired when the info-box hides again.

Event handlers can be registered and removed as follows. A handler can either be a global function or an object method and it receives an object containing event-specific properties as single parameter.

Poi.addEventListener("popupopen", "poiPopup", MyObj); Poi.removeEventListener("popupopen", "poiPopup", MyObj);

Any questions?

If something doesn't work as expected or if you miss important functionality, please don't hesitate to tell us. We wait for your feedback.