The MapAPI 1.0 is deprecated. Please use the new MapAPI 1.1.
The API and implementation is plain Javascript, so map applications created by the MapAPI run in all modern browsers without plugins, addons etc. All you need to start is basic Javascript knowledge.
Browser | Version |
---|---|
Mozilla Firefox | 3.0+ |
Apple Safari | 3.1.2+ |
Google Chrome | Current version |
Opera | 10.0+ |
Microsoft Internet Explorer | 6.0+ |
However if you want to use your own server infrastructure, please contact us at mapapi@infoware.de.
<script type="text/javascript" src="<server-url>/MapAPI-1.0/js/mapping.js?vnr=[yourVNR]&pnr=[yourPNR]"></script>into your page and start using the API after an onload event (or $(document).ready(yourInitHandler) when using jQuery).
map.getOptions().setMouseWheelAction(IWMapOptions.CONTROL_NONE); var adapter = new IWMouseWheelAdapter(map, map.getContainer()); IWEventManager.addListener(adapter, 'onmousewheel', function(event) { if(event.delta < 0) { map.zoomIn(); } else { map.zoomOut(); } });
map.getCurrentMapType().setMinLevel(5); map.getCurrentMapType().setMaxLevel(10); map.getCurrentMapType().setPreferredLevel(8); map.setCenter(map.getCenter(), map.getZoom());
var nw = new IWCoordinate(6.85465, 51.08357, IWCoordinate.WGS84).toMercator(); // north-west of Cologne var se = new IWCoordinate(7.20694, 50.64929, IWCoordinate.WGS84).toMercator(); // south-east of Bonn var extCoor = new IWCoordinate(7.14512, 50.70001, IWCoordinate.WGS84).toMercator(); var myBounds = new IWBounds(nw,se); myBounds.extendBy(extCoor); map.setCenter(myBounds.getCenter(), map.getBoundsZoomlevel(myBounds));In the above Example extCoor is one of the chosen point and lies within the IWBounds and is used here to illustrate the use of the method extendBy (). The IWBounds may be extended with extendBy() as often as needed. If a new coordinate lies outside the IWBounds, then the rectangle is enlarged and possibly a different zoom level is chosen.
map.setCenter(route.getBounds().getCenter(), map.getBoundsZoomlevel(route.getBounds()));
projection | conversion | projection |
---|---|---|
Mercator | ↔ | WGS 84 |
LCC Europe | ↔ | WGS 84 |
LCC Europe | → | LCC Germany Bessel AKA LCC TAO |
LCC Germany Bessel | → | LCC Europe |
LCC Germany Bessel | → | Mercator |
WGS84 | → | UTM 32 |
var type = map.getOptions().getMapTypeByName('hybrid'); map.setCenter(map.getCenter(), map.getZoom(), type);
For more details, please have a look at the documentation of IWMapType.
This number is usually greater than 20 on desktop machines. Standard browsers of today allow 6 parallel connections to one server; or to be more precise, to one subdomain of a domain. The other requests are queued. So the loading speed can be optimized by loading the tiles from different servers, and thus creating more parallel connections. For details please see Parallelize downloads across hostnames.
The MapAPI allows downloads from multiple servers. The load is spread equally among these servers. One tile is loaded always from the same server, so caching within the browser is fully used. To use multiple servers, or multiple subdomains on one server / server pool, you can configure aliases in the XML based MapAPI config file. For a MapAPI hosted on our servers, this already is configured.
In this cases you should think of using layers. The markers in these layers are stored on the server and rendererd to a single image every time the map is moved. This is much faster for large amounts of markers. Examples for layers are POIs and routing layers.
For more detailed descriptions see the chapters on overlays and shapes in the tutorial.
Overlays | Layers | |
---|---|---|
numer of markers | limited (depends on target plattform) | huge amounts (managed on the server) |
flexibility | high (own implementations with HTML, JS, CSS) | low (static images only) |
user interaction | fast (Javascript events) | slow (round-trip-time to server) |
Hoewever, we suggest an object-oriented approach for complex applications as it leads to the same advantages as in other programming languages, like an improved reusability, readability, testability and other benefits.
The usual way to create an object in Javascript is var x = new Object();
(or the shorter
notation var x = {};
). The first step to introduce a "class" is to write a constructor
function like this:
function Programmer(name) { this.name = name; this.caffeine = 0; }When a constructor function is called with new, the newly created object becomes accessible in the function by the name
this
.
Now you can create instances of your class by writing var x = new F();
. The result is an object
(typeof x
will return 'Object') with the properties x and y.
As functions can be assigned to any variable, you can add functions as properties to your class to add methods. Again, use this to access the object and its properties from these functions:
function Programmer(name) { this.name = name; this.caffeine = 0; this.work = function() { if (this.caffeine > 0) { console.log(name + ' produces some code'); } else { throw name + ' is out of coffee!'; } } this.drinkCoffee = function() { console.log(name + ' drinks coffee'); this.caffeine += 5; } } var codeMonkey = new Programmer('Code monkey'); // now create an instance and use it try { codeMonkey.work(); } catch (e) { codeMonkey.drinkCoffee(); codeMonkey.work(); }
Assigning the methods in the constructor has two main disadvantages: The constructor becomes more complex (thus making it slower) and the methods have to be assigned to each object which is instantiated from the class (imagine you need a lot of code monkeys...). A more elegant solution is to use the prototype of the constructor function instead:
function Programmer(name) { this.name = name; this.caffeine = 0; } Programmer.prototype.work = function() { if (this.caffeine > 0) { console.log(name + ' produces some code'); } else { throw name + ' is out of coffee!'; } } Programmer.prototype.drinkCoffee = function() { console.log(name + ' drinks coffee'); this.caffeine += 5; }
To extend a class you have to do two steps: Make your constructor call the constructor of the base class, and create the prototype of your constructor as an instance of the base class. Let's have a look at this example:
function CustomCoordinate(x, y, projection) { // TODO calculate lat, lon from x, y IWCoordinate.call(this, lon, lat, IWCoordinate.WGS84); // (1) } CustomCoordinate.prototype = new IWCoordinate(); // (2) CustomCoordinate.prototype.toCustomProjection = function() { var wgs84 = this.toWGS84(); var lat = wgs84.getY(); var lon = wgs84.getX(); // TODO calculate x, y from lat, lon return new IWCoordinate(x, y, 'CustomProjection'); };
This class extends IWCoordinate to support a custom projection. To do this the lines marked with (1) and (2) are important. The first one calls the constructor IWCoordinate on the object "this", i.e. the object which is created by the CustomCoordinate constructor. For details see the documentation of Function.call().
The line marked with (2) makes the prototype of CustomCoordinate an instance of IWCoordinate, thus inheriting all methods and constants defined for IWCoordinate. Now you can use your custom coordinate class as replacement for IWCoordinate, i.e. map.setCenter(new CustomCoordinate(1234, 5678)); will center the map on the WGS84 position corresponding to the coordinate (1234, 5678) in your custom projection.
Copyright 2007-2009 infoware GmbH, mapsuite Javascript Tutorial