22
33You can embed an interactive version of the [ map viewer] ( https://map.geo.admin.ch/ ) into your webpage using an HTML iframe, as shown below:
44
5- <iframe src =" https://map.geo.admin.ch/#/embed?lang=en¢ er=2600988.46,1197433.4&z=8&topic=ech&layers=&bgLayer=ch.swisstopo.pixelkarte-farbe&featureInfo=default " style =" border : 0 ;width : 400 px ;height : 300px ;max-width : 100% ;max-height : 100% ;" allow =" geolocation " ></iframe >
5+ <iframe src =" https://map.geo.admin.ch/#/embed?lang=en¢ er=2600988.46,1197433.4&z=8&topic=ech&layers=&bgLayer=ch.swisstopo.pixelkarte-farbe&featureInfo=default " style =" border : 0 ;width : 100 % ;height : 300px ;max-width : 100% ;max-height : 100% ;" allow =" geolocation " ></iframe >
66
77The following expands on the introduction given in the [ Web Integration: iFrame] ( https://www.geo.admin.ch/de/web-integration-iframe/ ) page.
88
@@ -21,7 +21,11 @@ To add a legend of a specific layer to your embedded map viewer:
2121Here is an example:
2222
2323``` html
24- <iframe src =" https://map.geo.admin.ch/#/embed?lang=en¢er=2675475,1229326.76&z=6&topic=ech&layers=ch.bfe.grundwasserwaermenutzungspotential&bgLayer=ch.swisstopo.pixelkarte-grau" style =" border : 0 ;width : 400px ;height : 300px ;max-width : 100% ;max-height : 100% ;" allow =" geolocation" ></iframe >
24+ <iframe
25+ src =" https://map.geo.admin.ch/#/embed?lang=en¢er=2675475,1229326.76&z=6&topic=ech&layers=ch.bfe.grundwasserwaermenutzungspotential&bgLayer=ch.swisstopo.pixelkarte-grau"
26+ style =" border : 0 ;width : 100% ;height : 300px ;max-width : 100% ;max-height : 100% ;"
27+ allow =" geolocation"
28+ ></iframe >
2529<b >Legend</b >
2630<p >
2731 <img
@@ -33,9 +37,10 @@ Here is an example:
3337
3438which looks like this in the final webpage:
3539
36- <iframe src =" https://map.geo.admin.ch/#/embed?lang=en¢ er=2675475,1229326.76&z=6&topic=ech&layers=ch.bfe.grundwasserwaermenutzungspotential&bgLayer=ch.swisstopo.pixelkarte-grau " style =" border : 0 ;width : 400 px ;height : 300px ;max-width : 100% ;max-height : 100% ;" allow =" geolocation " ></iframe >
40+ <iframe src =" https://map.geo.admin.ch/#/embed?lang=en¢ er=2675475,1229326.76&z=6&topic=ech&layers=ch.bfe.grundwasserwaermenutzungspotential&bgLayer=ch.swisstopo.pixelkarte-grau " style =" border : 0 ;width : 100 % ;height : 300px ;max-width : 100% ;max-height : 100% ;" allow =" geolocation " ></iframe >
3741
3842<b >Legend</b >
43+
3944<p >
4045 <img
4146 src="https://api3.geo.admin.ch/static/images/legends/ch.bfe.grundwasserwaermenutzungspotential_en.png "
@@ -55,7 +60,7 @@ To add custom elements like POIs, paths, and text on top of the map viewer:
5560
5661For example, to get to a result that looks like this:
5762
58- <iframe src =" https://map.geo.admin.ch/#/embed?lang=en¢ er=2685959.53,1248777.78&z=9.63&topic=ech&layers=KML%7Chttps://cms.geo.admin.ch/www.geo.admin.ch/kml/zoo.kml&bgLayer=ch.swisstopo.pixelkarte-grau&featureInfo=default " style =" border : 0 ;width : 400 px ;height : 300px ;max-width : 100% ;max-height : 100% ;" allow =" geolocation " ></iframe >
63+ <iframe src =" https://map.geo.admin.ch/#/embed?lang=en¢ er=2685959.53,1248777.78&z=9.63&topic=ech&layers=KML%7Chttps://cms.geo.admin.ch/www.geo.admin.ch/kml/zoo.kml&bgLayer=ch.swisstopo.pixelkarte-grau&featureInfo=default " style =" border : 0 ;width : 100 % ;height : 300px ;max-width : 100% ;max-height : 100% ;" allow =" geolocation " ></iframe >
5964
6065follow these steps:
6166
@@ -65,20 +70,21 @@ follow these steps:
6570
6671 ``` html
6772 <iframe
68- src =" https://map.geo.admin.ch/#/embed?
73+ src =" https://map.geo.admin.ch/#/embed?
6974 lang=en&
7075 center=2685959.53,1248777.78&
7176 z=9.63&
7277 topic=ech&
7378 layers=KML%7Chttps://cms.geo.admin.ch/www.geo.admin.ch/kml/zoo.kml
7479 &bgLayer=ch.swisstopo.pixelkarte-grau
7580 &featureInfo=default"
76- style =" border : 0 ;
77- width : 400 px ;
81+ style =" border : 0 ;
82+ width : 100 % ;
7883 height : 300px ;
7984 max-width : 100% ;
8085 max-height : 100% ; "
81- allow =" geolocation" >
86+ allow =" geolocation"
87+ >
8288 </iframe >
8389 ```
8490
@@ -95,7 +101,7 @@ For example, to center the map on the address "Holzikofenweg 36, 3007 Bern":
95101 src="https://map.geo.admin.ch/#/embed ?
96102 &swisssearch=Holzikofenweg 36, 3007 Bern"
97103 style="border: 0;
98- width: 400px ;
104+ width: 100% ;
99105 height: 300px;
100106 max-width: 100%;
101107 max-height: 100%;"
@@ -106,14 +112,15 @@ You would pass the address to the `swisssearch` parameter in an iframe like this
106112
107113``` html
108114<iframe
109- src =" https://map.geo.admin.ch/#/embed?
115+ src =" https://map.geo.admin.ch/#/embed?
110116 &swisssearch=Holzikofenweg 36, 3007 Bern"
111- style =" border : 0 ;
112- width : 400 px ;
117+ style =" border : 0 ;
118+ width : 100 % ;
113119 height : 300px ;
114120 max-width : 100% ;
115121 max-height : 100% ; "
116- allow =" geolocation" >
122+ allow =" geolocation"
123+ >
117124</iframe >
118125```
119126
@@ -124,7 +131,7 @@ For example, if you search for the ambiguous "Holzikofenweg, 3007 Bern" without
124131 src="https://map.geo.admin.ch/#/embed ?
125132 &swisssearch=Holzikofenweg, 3007 Bern"
126133 style="border: 0;
127- width: 400px ;
134+ width: 100% ;
128135 height: 300px;
129136 max-width: 100%;
130137 max-height: 100%;"
@@ -135,15 +142,16 @@ Appending `swisssearch_autoselect=true` centers the map on the first search resu
135142
136143``` html
137144<iframe
138- src =" https://map.geo.admin.ch/#/embed?
145+ src =" https://map.geo.admin.ch/#/embed?
139146 &swisssearch=Holzikofenweg, 3007 Bern
140147 &swisssearch_autoselect=true"
141- style =" border : 0 ;
142- width : 400 px ;
148+ style =" border : 0 ;
149+ width : 100 % ;
143150 height : 300px ;
144151 max-width : 100% ;
145152 max-height : 100% ; "
146- allow =" geolocation" >
153+ allow =" geolocation"
154+ >
147155</iframe >
148156```
149157
@@ -154,7 +162,7 @@ The corresponding iframe:
154162 &swisssearch=Holzikofenweg, 3007 Bern
155163 &swisssearch_autoselect=true"
156164 style="border: 0;
157- width: 400px ;
165+ width: 100% ;
158166 height: 300px;
159167 max-width: 100%;
160168 max-height: 100%;"
@@ -167,25 +175,35 @@ To embed the map viewer with the search bar and other menus, replace the `#/embe
167175
168176In an example:
169177
170- <iframe src =" https://map.geo.admin.ch/#/map?lang=en¢ er=2675475,1229326.76&z=6&bgLayer=ch.swisstopo.pixelkarte-farbe " style =" border : 0 ;width : 400 px ;height : 300px ;max-width : 100% ;max-height : 100% ;" allow =" geolocation " ></iframe >
178+ <iframe src =" https://map.geo.admin.ch/#/map?lang=en¢ er=2675475,1229326.76&z=6&bgLayer=ch.swisstopo.pixelkarte-farbe " style =" border : 0 ;width : 100 % ;height : 300px ;max-width : 100% ;max-height : 100% ;" allow =" geolocation " ></iframe >
171179
172180This is represented by an iframe like:
173181
174182``` html
175183<iframe
176- src =" https://map.geo.admin.ch/#/map?
184+ src =" https://map.geo.admin.ch/#/map?
177185 lang=en&
178186 center=2675475,1229326.76&
179187 z=6&
180188 bgLayer=ch.swisstopo.pixelkarte-farbe"
181- style =" border : 0 ;
182- width : 400 px ;
189+ style =" border : 0 ;
190+ width : 100 % ;
183191 height : 300px ;
184192 max-width : 100% ;
185193 max-height : 100% ; "
186- allow =" geolocation" ></iframe >
194+ allow =" geolocation"
195+ ></iframe >
187196```
188197
189198::: tip
190199To ensure proper geolocation functionality, explicitly enable geolocation with ` allow="geolocation" ` to avoid issues in certain web browsers.
191200:::
201+
202+ ## Example: Accessing Feature Info from an Embedded Map
203+
204+ This example demonstrates how to enable interaction between an embedded map and other elements on your webpage.
205+ When a user clicks on a supported feature (currently from KML or GeoJSON layers), the map sends a ` message ` event to the parent page using the postMessage API.
206+ The event is then captured by the parent page and used to display feature information outside the iframe.
207+
208+ <iframe height =" 600 " style =" width : 100% ;" scrolling =" no " title =" Basic iframe " src =" https://codepen.io/geoadmin/embed/zxvyMBp?default-tab=none%2Cresult " frameborder =" no " loading =" lazy " allowtransparency =" true " allowfullscreen =" true " >
209+ </iframe >
0 commit comments