[OpenLayers-Users] JS code in external script

Nicholas Efremov-Kendall n.e.kendall at gmail.com
Sat Jul 25 17:16:54 EDT 2009


Hi all,
the application I've been developing relies on the OL url API, Openstreet
map (for now etc). I have one version where the code is written in-line, one
version where the code is in an external script. The in-line code works
fine, but the external script has misalignment issues. I have no idea why
this is happening, does anyone have any suggestions?

These are all included in my header file

<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js
"></script>
<script src="js/OpenLayers-2.7/proj4js-combined.js"></script>
<script language="javascript" type="text/javascript"
src="js/mapsettings2.js"></script>

and here is my code, note it is exactly the same as the in-line version.

 <!--
var map, layer, selectedFeature, selectControl, selectedFeature;
var lat = 10.87;
var lon = 33.79;

//Popups
function onPopupClose(evt) {
            selectControl.unselect(selectedFeature);
        }
function onFeatureSelect(feature) {
            selectedFeature = feature;
            popup = new OpenLayers.Popup.FramedCloud("chicken",

feature.geometry.getBounds().getCenterLonLat(),
                                     null,
                                     "<div style='font-size:.8em'>Site_ID: "
+ feature.attributes.title +"<hr />Locality: " +
feature.attributes.title+"<br/>Description: " +feature.attributes+"<br/>
Feature ID: "+feature.id+"<br/>Feature Type:"+feature.attributes.NEWSITE_
+"</div>",
                                     null, true, onPopupClose);
            feature.popup = popup;
            map.addPopup(popup);
        }
  function onFeatureUnselect(feature) {
            map.removePopup(feature.popup);
            feature.popup.destroy();
            feature.popup = null;
        }
 //Map Constructor
function init() {
map = new OpenLayers.Map ("map",
{
controls:[
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Attribution()],
sphericalMercator: true,
maxExtent: new
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
maxResolution: 156543.0399,
numZoomLevels: 19,
units: 'm',
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
}
);
//Map Data
//Base Layers
var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
map.addLayer(layerMapnik);
 var ol_wms = new OpenLayers.Layer.WMS( "World Map",
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic', format: 'image/png'
} );

// Overlays
var topo = new OpenLayers.Layer.GML("Jerba Topography",
"data/topopj.gml",  {styleMap: new OpenLayers.StyleMap({strokeWidth: 1,
strokeColor: "#000000"}) });
 map.addLayer(topo);

var sites = new OpenLayers.Layer.GML(
 "Sites", "data/siteswatr.gml", {styleMap: new
OpenLayers.StyleMap({pointRadius: 2.5, fillColor: "#"},
 {projection: new OpenLayers.Projection("EPSG:32632")})});
 map.addLayer(sites);
  var outline = new OpenLayers.Layer.GML("Jerba Island",
"data/outline.gml");
 map.addLayer(outline);

 //Map Controls Should theoretically be in map constructor, but only
navigation works
 map.addControl( new OpenLayers.Control.LayerSwitcher());
 map.addControl( new OpenLayers.Control.MousePosition());
 map.addControl( new OpenLayers.Control.OverviewMap());
 map.addControl( new OpenLayers.Control.ScaleLine());
    //map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);

//highlighting stuff
  var report = function(e) {
                OpenLayers.Console.log(e.type, e.feature.id);
            };

            var highlightCtrl = new OpenLayers.Control.SelectFeature(sites,
{
onSelect: onFeatureSelect,
onUnselect: onFeatureUnselect,
hover: true,
                highlightOnly: true,
                renderIntent: "temporary",
                eventListeners: {
                    beforefeaturehighlighted: report,
                    featurehighlighted: report,
                    featureunhighlighted: report
                }
            });

            var selectCtrl = new OpenLayers.Control.SelectFeature(sites,
                {clickout: true}
            );

            map.addControl(highlightCtrl);
            map.addControl(selectCtrl);

            highlightCtrl.activate();
            selectCtrl.activate();
     // set center from geometry
    if( ! map.getCenter() )
{
topo.events.register('loadend', topo,
function(){map.zoomToExtent(topo.getDataExtent())});
map.setCenter(null, null);
}
else
{
map.setCenter(new OpenLayers.LonLat(lon, lat));
} ;

};
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090725/b96d75c6/attachment.html


More information about the Users mailing list