Initializing an openlayers map from an external Javascript file

My goal is to load an OpenLayers map using an external JS file. In my head I have a jQuery library, and in my body I have an OpenLayers library, my Openlayers code and a div tag.

<script type="text/javascript" src="http://example.com/OpenLayers.js"></script>
<script type="text/javascript" src="http://example.com/MyMapScript.js"></script>
<div id="map"></div>

However, I do not have access to the body tag, so I cannot run onload="init()"how this works in most examples.

Instead, at the bottom, MyMapScript.jsI added the line below.

jQuery(window).load(init());

Here he gets a little weird. Using Firebug, I see that this code is called and it initializes the map object with all its properties. I also see that it calls the WMS server and successfully receives all the cards. However, in fact, it does not draw anything on the page, and additional divs are not added to the HTML.

, , , init() . http://bytes.com/topic/javascript/answers/855670-unusual-behavior-function-calls-java-script

, , , - .

<script type="text/javascript" src="http://example.com/OpenLayers.js"></script>
<script type="text/javascript" src="http://example.com/MyMapScript.js"></script>
<script type="text/javascript"> window.onload=init; </script>
<div id="map"></div>

, .

OpenLayers javascript? - window.onload=init;? HTML, ?

+3
1

. , . div, , div javascript, .

.

<div id="map" style="width:400px; height:400px;"></div>    
<script type="text/javascript" src="http://example.com/OpenLayers.js"></script>
<script type="text/javascript" src="http://example.com/MyMapScript.js"></script>
+5

Source: https://habr.com/ru/post/1783864/


All Articles