Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1998495.39lFTFxDty@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Tue, 19 Feb 2013 13:22:03 +0100 User-Agent: KNode/4.8.5 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. MIME-Version: 1.0 Lines: 118 NNTP-Posting-Date: 19 Feb 2013 13:22:11 CET NNTP-Posting-Host: 06c529cd.newsspool3.arcor-online.net X-Trace: DXC=5R?af4SQO^ePXlQ;h]GTMdMcF=Q^Z^V3h4Fo<]lROoRa8kFYBYU3JEomNDR\jCKFUgi X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:18572 Bunyip wrote: ^^^^^^ Who? > I am trying to include a file containing polygon data for a Google map > in a JS function which loads the map. I've tried a few things found on > various Googled sites including: > ============================= > > > > > >
> > =========================== > coords.js conatins: > var ZipCoordinates14 = [ > new google.maps.LatLng(39.721448436441, -76.177407691101), > new google.maps.LatLng(39.721498081776, -76.158070551061), > new google.maps.LatLng(39.721639384602, -76.10303229774), > etc. > new google.maps.LatLng(39.721448436441, -76.177407691101) > ]; > var ZipPolygon = new google.maps.Polyline({ > path: ZipCoordinates14, > strokeColor: '#FF0000', > strokeOpacity: 1.0, > strokeWeight: 1 > }); You might want to consider var maps = google.maps; and new maps.…(…); which would skip at least one scope chain resolution step per invocation. Or, if it works (which it should with proper namespacing), var LatLng = google.maps.LatLng; etc. and new LatLng(…) etc. > ZipPolygon.setMap(map); > =========================== > It works when the contents of coords.js are in the initialize() > function but not when I try to include it as a separate file. I get > just the map but without the polygon overlay. > > How can I do this include? Since you are using Google Maps and the map is loading, that approach of dynamically loading scripts (which is otherwise questionable) is basically OK as Google Maps uses it itself. (Although there may be the document.head shorthand property and the backwards-compatible document.body property should suffice.) The error message that you are getting in your script console when include() is called should be something like “ReferenceError: map is not defined”. Use a debugger and set breakpoints to be sure. “map” currently is the name of a variable declared *local* to initialize(). However, it needs to be the name a *globally available* property (such as a global variable) if code in the global execution context (such as in coords.js) is to access it. That is, you only need to *initialize* the property value in initialize(), and declare/define the property elsewhere. As an alternative, you can split Polyline data and instantiation and pass the value of “map” as an argument to a function, unless you want the Polyline instantiation happening in initialize() directly. Are you using Valid markup? -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.