User Tools

Site Tools


No renderer 'pdf' found for mode 'pdf'
en:api:shortexamples

Working with Layers

In the .createMap() method, you can control the layers displayed initially more in detail. The following properties control the layers included and displayed:

  • layers - Comma Separated list of layer names to be included in the map.
  • layers_indices - need to better understand what this means
  • layers_opacity - Comma Separated list of floating point opacity values for the layers list (in order)

Layer Exclusions

The GeoAPI has defined layer exclusion rules, which limit some layers abilities to be displayed alongside other layers. One notable example is the “Plan Cadastral” layer, which cannot be displayed along with the any aerial imagery, for legal reasons. These restrictions are enforced at the GeoAPI level.

To better understand exclusions, in the following example the background layers (bgLayers) “aerial” and “topo” are automatically replaced by “voidLayer”. In addition “ortho_irc” is excluded by “parcels”. Layer “communes” is still visible because not excluded. “fakelayer” is removed since it does not actually exist. Indices and opacity settings are preserved. Exclusion affects layers defined first in the list and does not take into account layers_indices order.

...
<script type="text/javascript">
Ext.onReady(function() {
        geo = new geoadmin.API({lang: 'fr'});
        geo.createMap({
            div: 'map',
            easting: 59130,
            northing: 107670,
            zoom: 8,
            layers: 'fakelayer,ortho_irc,communes,parcels',
            layers_indices: '6,3,5,4',
            layers_opacity: '1,0.6,1,0.4',
            bgLayer: 'pixelmaps-color',
            bgOpacity: 50
        });
    });
</script>
...

Using the geosearch programmatically

The Geosearch is a web service which can be used not only through the map search box, but also programmatically. The service returns a JSONP object with the coordinate(s) matched against an address string, which in this example are used in the callback to create a marker and popup.

...
geo.searchUrl="//api.geoportail.lu/locationsearch"; 
 
callback = function(json) {
	if (json.success) {
		var location = json.results[0].bbox;
		geo.map.zoomToExtent(location);
	};
	marker = geo.showMarker({
		iconPath: '//apps.geoportail.lu/exemple_api/exemplesWikiGeoAPI/lion.png', //absolute url to image file
		graphicHeight: 35, 
		graphicWidth: 35,
		easting: geo.map.getCenter.lon,
		northing: geo.map.getCenter.lat,
		html: "This is the content of the popup, it also takes html tags",
		title: "This is the title of the popup",
		hover: true //display marker popup on mouseover
	});	
};
var params = {
		query: "54, Avenue Gaston Diderich, L-1420 Luxembourg",
		cb: 'callback'
};
var script = document.createElement('script');
script.src = geo.searchUrl + "?" +  Ext.urlEncode(params);
document.body.appendChild(script);
...

en/api/shortexamples.txt · Last modified: 2017/03/02 12:27 (external edit)