- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Object.useData [as afterParse] 中收到“未捕获的类型错误:无法读取未定义的属性‘地标’”
这是一个简化的代码片段:
<script>
var map;
var myParser;
function initMap() {
map = new google.maps.Map(document.getElementById('map'));
myParser = new geoXML3.parser({
map: map,
afterParse: useData
});
myParser.parse('./my.kml');
function useData() {
var someVar = myParser.docs[0].placemarks.length;
//yada yada
}
google.maps.event.addDomListener(window, 'load', initMap);
</script>
我做错了什么?
最佳答案
after parse 函数将 docs
数组作为其参数传递。当它被调用时,你可以这样做:
function useData(doc) {
console.log("parsed " + doc[0].placemarks.length + " placemarks");
document.getElementById('info').innerHTML = "parsed " + doc[0].placemarks.length + " placemarks";
}
代码片段:
var map;
var myParser;
function initMap() {
map = new google.maps.Map(document.getElementById('map'));
myParser = new geoXML3.parser({
map: map,
afterParse: useData
});
myParser.parseKmlString(kmlStr);
function useData(doc) {
console.log("parsed " + doc[0].placemarks.length + " placemarks");
document.getElementById('info').innerHTML = "parsed " + doc[0].placemarks.length + " placemarks";
}
}
google.maps.event.addDomListener(window, 'load', initMap);
var kmlStr = '<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"><Document><name>Massachusetts Cities</name><Folder><Placemark><name>Boston</name><description>Boston is the capital of and largest city in Massachusetts. The Boston Massacre and the Boston Tea Party occurred in Boston and led to the American Revolution.</description><LookAt><longitude>-71.05977300312775</longitude><latitude>42.35843100531216</latitude><altitude>0</altitude><heading>-2.107386233340164e-009</heading><tilt>0</tilt><range>34426.00143998101</range><altitudeMode>relativeToGround</altitudeMode><gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode></LookAt><styleUrl>#msn_ylw-pushpin9</styleUrl><Point><altitudeMode>absolute</altitudeMode><coordinates>-71.05977300312775,42.35843100531217,3.1482280535562</coordinates></Point></Placemark><Placemark><name>Worcester</name><description>Worcester is known as the "Heart of the Commonwealth" due to its location in central Massachusetts, thus, a heart is the official symbol of the city.</description><LookAt><longitude>-71.80229299737233</longitude><latitude>42.2625930065606</latitude><altitude>0</altitude><heading>1.76716070878667e-009</heading><tilt>0</tilt><range>17233.50055269895</range><altitudeMode>relativeToGround</altitudeMode><gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode></LookAt><styleUrl>#msn_ylw-pushpin0</styleUrl><Point><altitudeMode>absolute</altitudeMode><coordinates>-71.80229299737233,42.26259300656061,145.2545892926215</coordinates></Point></Placemark><Placemark><name>Springfield</name><description>Historically the first Springfield in America.</description><LookAt><longitude>-72.58981099924824</longitude><latitude>42.10148299778795</latitude><altitude>0</altitude><heading>5.040065975981161e-010</heading><tilt>0</tilt><range>17277.36855774167</range><altitudeMode>relativeToGround</altitudeMode><gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode></LookAt><styleUrl>#msn_ylw-pushpin6</styleUrl><Point><altitudeMode>absolute</altitudeMode><coordinates>-72.58981099984295,42.10148300097482,39.44687703020819</coordinates></Point></Placemark><Placemark><name>Lowell</name><description>Lowell is known as the birthplace of the industrial revolution in the United States.</description><LookAt><longitude>-71.31617200184621</longitude><latitude>42.63342499640326</latitude><altitude>0</altitude><heading>-1.250482781337603e-009</heading><tilt>0</tilt><range>8564.451680780059</range><altitudeMode>relativeToGround</altitudeMode><gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode></LookAt><styleUrl>#msn_ylw-pushpin3</styleUrl><Point><altitudeMode>absolute</altitudeMode><coordinates>-71.31617200184621,42.63342499640325,32.71923637446179</coordinates></Point></Placemark><Placemark><name>Cambridge</name><description>Cambridge is home to two internationally prominent universities, Harvard University and the Massachusetts Institute of Technology.</description><LookAt><longitude>-71.10965300713373</longitude><latitude>42.37264000434871</latitude><altitude>0</altitude><heading>-4.807793248148562e-009</heading><tilt>0</tilt><range>8600.20020650975</range><altitudeMode>relativeToGround</altitudeMode><gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode></LookAt><styleUrl>#msn_ylw-pushpin2</styleUrl><Point><altitudeMode>absolute</altitudeMode><coordinates>-71.10965300713372,42.37264000434871,7.159466020276252</coordinates></Point></Placemark><Placemark><name>Brockton</name><description>Brockton is sometimes referred to as the "City of Champions" due to the success of native boxers Rocky Marciano and Marvin Hagler.</description><LookAt><longitude>-71.01837899995951</longitude><latitude>42.08343399824823</latitude><altitude>0</altitude><heading>2.712218004618013e-011</heading><tilt>0</tilt><range>8639.699317635228</range><altitudeMode>relativeToGround</altitudeMode><gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode></LookAt><styleUrl>#msn_ylw-pushpin</styleUrl><Point><altitudeMode>absolute</altitudeMode><coordinates>-71.0183789999595,42.08343399824823,30.29967761376449</coordinates></Point></Placemark><Placemark><name>New Bedford</name><description>New Bedford is nicknamed "The Whaling City" because during the 19th century it was one of the most important whaling ports in the world.</description><LookAt><longitude>-70.93420500203244</longitude><latitude>41.63621500187266</latitude><altitude>0</altitude><heading>-1.350326753898106e-009</heading><tilt>0</tilt><range>17403.47639378627</range><altitudeMode>relativeToGround</altitudeMode><gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode></LookAt><styleUrl>#msn_ylw-pushpin4</styleUrl><Point><altitudeMode>absolute</altitudeMode><coordinates>-70.93420500203244,41.63621500187266,24.75716633283448</coordinates></Point></Placemark><Placemark><name>Fall River</name><description>Fall River is known for Battleship Cove which has the world's largest collection of World War II naval vessels.</description><LookAt><longitude>-71.15504499654021</longitude><latitude>41.70149101206891</latitude><altitude>0</altitude><heading>2.301640200787889e-009</heading><tilt>0</tilt><range>17385.8377123415</range><altitudeMode>relativeToGround</altitudeMode><gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode></LookAt><styleUrl>#msn_ylw-pushpin7</styleUrl><Point><altitudeMode>absolute</altitudeMode><coordinates>-71.15504499654021,41.70149101206891,23.26129426529637</coordinates></Point></Placemark><Placemark><name>Lynn</name><description>Lynn is about 7 miles north of downtown Boston.</description><LookAt><longitude>-70.94949399981969</longitude><latitude>42.46676300410375</latitude><altitude>0</altitude><heading>1.217166471049273e-010</heading><tilt>0</tilt><range>8587.326697933368</range><altitudeMode>relativeToGround</altitudeMode><gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode></LookAt><styleUrl>#msn_ylw-pushpin5</styleUrl><Point><altitudeMode>absolute</altitudeMode><coordinates>-70.94949399981969,42.46676300410375,14.89168526609486</coordinates></Point></Placemark><Placemark><name>Quincy</name><description>Quincy is the birthplace of U.S. Presidents John Adams and John Quincy Adams.</description><LookAt><longitude>-71.00227000742845</longitude><latitude>42.25287699598879</latitude><altitude>0</altitude><heading>-4.994952988379282e-009</heading><tilt>0</tilt><range>17236.11617372477</range><altitudeMode>relativeToGround</altitudeMode><gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode></LookAt><styleUrl>#msn_ylw-pushpin8</styleUrl><Point><altitudeMode>absolute</altitudeMode><coordinates>-71.00227000742845,42.25287699598879,14.5549973299613</coordinates></Point></Placemark></Folder></Document></kml>';
html,
body {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
#map {
height: 90%;
width: 100%;
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script src="https://cdn.rawgit.com/geocodezip/geoxml3/master/polys/geoxml3.js"></script>
<div id="info"></div>
<div id="map"></div>
关于geoxml3 afterParse回调的javascript范围错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50788910/
我正在研究 learnyounode 的 HTTP 客户端作业。 我想知道为什么控制台记录来自response.on(“end”,callback)的数据仅输出预期输出的最后一部分,而控制台记录来自r
我正在尝试创建一个对象列表(在我的示例中为 List),我在其中使用 json 将对象添加到此列表,但该列表仍为空。这是我的代码: public List readCardsFromJson() {
我有一个 JavaScript 函数“print_something”,它在大约 300 个 jsp 帮助页面中实现。我发现这个“print_something”函数必须被纠正。所以我正在寻找一个不更
有 2 个 HTML 下拉列表,一个用于 12 小时时间,一个用于每小时 5 分钟的时间间隔。 .. 1 .. 12 .. 0 .. 55 .. 一直在尝试使用 if/
我有一个 A 类,我打算在它与设备驱动程序交互时将其放入共享库中。 我有一个 B 类,将来可能是 C、D、E...,它将使用共享库中的 A 类。 我想要在类 A 中设置回调函数的功能,以便当特定事件发
我需要能够在处理完 Observable.next() 之后执行回调。 我有一个组件“A”,它有一个主题使用 Subject.next() 发送通知。我有一个组件“B”,它订阅了 Subject.as
我有一张在顶部和底部单元格下方带有阴影的表格(此处使用 Matt Gallagher 的解决方案:http://cocoawithlove.com/2009/08/adding-shadow-effe
有人可以向我解释一下为什么这段代码有效 renderSquare(i) { return ( this.handleClick(i)} /> ); } 但
我可以让两个不同的客户端监听相同的 WCF 回调并让它们都接收相同的数据而不必进行两次处理吗? 最佳答案 不是真的 - 至少不是直接的。你所描述的听起来很像发布/订阅模式。 WCF 服务基本上在任何给
我是 SignalR 的新手,如果这个问题太明显,我深表歉意,但我在文档中找不到任何答案。 这是我的代码。 /*1*/ actions.client.doActionA = function (r
我有这个应用程序,您可以在其中输入一些文本并按下一个按钮,将此文本添加到自定义小部件中。这是代码: import 'dart:core'; import 'package:flutter/materi
我读到当您还想使用模型回调时不能使用 Keras 进行交叉验证,但是 this post表明这毕竟是可能的。但是,我很难将其纳入我的上下文。 为了更详细地探讨这个问题,我正在关注 machinelea
我尝试在重力表单中提交表单失败后运行一些 jQuery 代码,也就是验证发现错误时。 我尝试使用 Ajax:complete 回调,但它根本不触发。 我尝试运行的代码基本上将监听器添加到选择下拉列表中
我有一个 $image,我 .fadeIn 和 .fadeOut,然后 .remove .fadeOut 完成。这是我的代码: $image .fadeIn() .fadeOut(func
我正在处理一个自定义文件路径类,它应该始终执行一个函数 写入相应的系统文件及其文件对象后 关闭。该函数将文件路径的内容上传到远程位置。 我希望上传功能完全在用户的幕后发生 透视,即用户可以像使用其他任
这里是 javascript 新手,所以回调在我的大脑中仍然有点不确定。 我想做的是:给定一个“菜单”,它是一个 objectId 数组,查询与该 objectId 相对应的每个 foodItem,获
我正在学习回调,我编写了以下代码: var http = require('http'); var str = ""; var count = 2; function jugglingAsync(ca
这是我的困境,我有一系列被调用的函数,我正在使用回调函数在它们完成时执行函数。回调返回一个值并且效果也很好,我的问题是当我向回调添加参数时我无法再访问返回值。这是一个有效的例子: function m
This question already has answers here: Explanation of function pointers (4个答案) 上个月关闭。 如何将函数指针作为参数传递
我无法让以下代码工作。假设 ajax 调用有效,并且 msg['username'] 预设为 'john'。我想我对如何将变量传递给回调感到困惑。编辑:我认为我的主要困惑是如何从 Ajax 中获取“m
我是一名优秀的程序员,十分优秀!