[OpenLayers-Users] JS code in external script

Nicholas Efremov-Kendall n.e.kendall at gmail.com
Sun Jul 26 10:52:20 EDT 2009


Hi Shawn,
I don't know that that's the problem. I don't get any errors, it just
centers incorrectly as far as I can tell. For now, I'm just doing in-line
code.

On Sun, Jul 26, 2009 at 9:31 AM, Shawn Oatley <shawn at niagarafalls.ca> wrote:

>  It's a lttle bit hard to tell here, but it looks like you have an extra
> closing bracket at the bottom.   You should try Firebug and see if it
> reports any errors in the console.  Plus, in firebug, you can check out the
> scripts tab and see if all the scripts are actually loaded (proper file
> paths, etc..).
>
> Shawn
>
> >>> On 7/25/2009 at 5:16 PM, Nicholas Efremov-Kendall <
> n.e.kendall at gmail.com> wrote:
> 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/20090726/86b84577/attachment.html


More information about the Users mailing list