This page describes how to use the Simple API. The Simple API provides a JavaScript API for inserting simple maps into web pages.
To use the API you should add the following HTML:
<link href="https://map.cjl.ch/api.css" rel="stylesheet">
<script src="https://map.cjl.ch/api.js?version=2"></script>
<script>
window.onload = function() {
// add the code here
};
</script>
To put a new map in the page you'll have to put a div element with a certain id where you want your map to be:
<div id='map1' style='width:700px;height:400px;'></div>
const map1 = new morges.Map({
div: 'map1', // id of the div element to put the map in
zoom: 3,
center: [2527748, 1151338]
});
const map2 = new morges.Map({
div: 'map2',
zoom: 5,
center: [2527748, 1151338]
});
map2.addMarker();
const map3 = new morges.Map({
div: 'map3',
zoom: 5,
center: [2527748, 1151338]
});
map3.addMarker({
position: [2527758, 1151348],
size: [14, 14],
icon: '../static/46084/apihelp/img/info.png'
});
map3.addMarker({
position: [2527718, 1151308],
size: [18, 18],
icon: '../static/46084/apihelp/img/essence.png'
});
map3.addMarker({
position: [2527748, 1151338],
size: [14, 14],
icon: '../static/46084/apihelp/img/parking.png'
});
const map4 = new morges.Map({
div: 'map4',
zoom: 2,
center: [2527748, 1151338],
layers: ['cjl_ldi_admin']
});
const map5 = new morges.Map({
div: 'map5',
zoom: 4,
center: [2527748, 1151338],
backgroundLayers: ['Plan ville gris - CJL'],
layers: ['mf_at_zone_affectation', 'mf_at_plan_grl'],
addLayerSwitcher: true,
addMiniMap: true,
miniMapExpanded: true,
showCoords: true
});
const map6 = new morges.Map({
div: 'map6',
zoom: 1,
center: [2528113, 1166696],
addMiniMap: true,
miniMapExpanded: false
});
const button1 = document.getElementById('button1');
button1.onclick = function() {
map6.recenter([2519623, 1149870], 4);
}
const button2 = document.getElementById('button2');
button2.onclick = function() {
map6.recenter([2528775, 1162961], 5);
}
const map7 = new morges.Map({
div: 'map7',
layers: ['mf_cdd_point_collecte_dechetterie']
});
map7.recenterOnObjects(
/* the layer name */
'mf_cdd_point_collecte_dechetterie',
/* the ids of the objects */
['155'],
/* whether to highlight the objects or not */
true
);
const map8 = new morges.Map({
div: 'map8',
center: [2524860, 1148363]
});
map8.addCustomLayer('text', 'My custom txt layer', '../static/46084/apihelp/data.txt', {
success: function() {
map8.selectObject(1);
}
});
const map9 = new morges.Map({
div: 'map9',
zoom: 2,
center: [2528630, 1153592],
searchDiv: 'map9search'
});