Displaying a Configurable Interactive Map

In Displaying a Basic Interactive Map we show how to get an interactive map by means of existing toolkits. It is important to understand that the PTV xMap Server only provides tiles; any user interaction must be implemented client-side. Though there are toolkits providing user interactivity (like Leaflet or OpenLayers) which hide the complexity of composing a complete map image, among other things.

Tiles are supplied to the client via requests to the tile providers. As a drawback, this procedure is handled internally and a direct modification of the tile requests, as described in Requesting a Single Map Image with Web Service API, is not possible. For more flexibility some additional coding is necessary, which depends on the toolkit and its version you use.

Benefits

Displaying an interactive map using the PTV xMap Web serviceClosed A web service represents a communication technology applied in computer networks. It provides an interface described in a machine-processable format, for example WSDL. API has several advantages over the simple map using the RESTClosed REST (Representational State Transfer) represents a World Wide Web paradigm, consisting of constraints to the design of components which results in a better performance and maintainability. API:

  • You have better control about the map appearance and the objects rendered. For example, additional (textual) information for Feature Layer attributes could be shown in tool tips.
  • You are not restricted to integer-based zoom levels.
  • For handling user interaction you can still rely on existing, free toolkits.
  • Depending on your toolkit, there might be a ready-to-use sample below that integrates the web service API.

Prerequisites

Check if the following prerequisites are fulfilled before you start with the integration:

  • Installed and licensed PTV xMap Server
  • Installed PTV Map

Programming Guide

Commonly, the toolkits for map integration provide some native implementation for layers, rendering geographical content by means of tile providers. Via URL templates the various tiles can be requested. What is missing here, is an explicit configuration of the xMap requests. Especially the request profileClosed The request profile is a partial profile provided in object form for a specific request. Any parameter which is not set in the request profile will be taken from the stored profile., which determines graphical options of the drawn objects, is subject of interest. By the way: The following code snippets resemble the xServer 1 approaches.

Due to the fundamental character of the generic requests, the toolkit layers implementation cannot be used. Below, some code samples are provided for a layer with a tile access and a window basedClosed Window based is a way of dealing with refreshing map windows. Each time the map needs to be refreshed, the JavaScript framework requests one large image, which has the same size as your map window. This way, only one request is necessary, but images cannot be reused for the next refresh. map based access. Because their approach to providing map content is totally different from the toolkit implementation, an own layer class is provided, as shown in the following Leaflet samples.

Tile based layer extension

The following code provides a TiledPtvLayer, which generates tiles similar to REST API. Because of its tile basedClosed Tile based is a special way of drawing maps. To draw the map window, the framework requests several small images (tiles) and paints them next to each other. This way, several requests are necessary for one refresh, but tiles can be reused. Only the tiles that have not been visible so far need to be fetched from the server. This approach gives a better user experience, especially if the bandwidth is low. approach, it extends the already existing L.TileLayer class. In function createTile, the request is assembled and the response evaluated via anonymous functions. This the place where these objects can be customized for additional elements:

Drawing individual layer content

The TiledPtvLayer also provides the possibility to draw individual parts of map content. Available layers are background, transport, labels and any Feature Layer. It is possible to combine different layers with a single TiledPtvLayer, but the drawing order is not considered or changed.

Window based layer extension

For some peculiar use cases it may be necessary to get the whole map image at once, avoiding the tile partitioning. The following code provides a WindowBasedPtvLayer, which generates a complete image at all. Because of its more fundamental character, it extends the already existing L.Layer class.

In function getImageUrlAsync, the request is assembled and can be adapted to own requirements. In function processResponse the response object can be evaluated for additional returned values, if necessary:

Related Topics

The following topics might be relevant for this integration sample: