- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在构建 GeoJSON 并将其放在 map 上的传单代码方面遇到了一些麻烦。
GeoJSON 是根据服务的 XML 响应构建的。
错误是
无效的 GeoJSON 对象。 throw new Error('Invalid GeoJSON object.');
我的代码是...
<html>
<head>
<title>Prova caricamento WMS Indirizzi del PCN</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css"/>
</head>
<body>
<div id="map" style="width: 600px; height: 400px"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet-src.js"></script>
<script>
var browser = navigator.userAgent.toLowerCase();
var isIE = (browser.indexOf("msie")>-1 || browser.indexOf("trident")>-1);
if (isIE && window.XDomainRequest) {
if (window.XDomainRequest) {
var query = 'http://wms.pcn.minambiente.it/ogc?map=/ms_ogc/wfs/Numeri_Civici_2012.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=IN.NUMERICIVICI.2012&SRSNAME=EPSG:4326&bbox=7.719,44.849,7.72,44.85&outputFormat=GML2';
var xdr = new XDomainRequest();
if (xdr) {
xdr.onload = function () {
addressPCN(data);
}
xdr.onerror = function () {
alert("KO");
}
xdr.open('GET', query);
xdr.send();
}
}
}
else {
var query = 'http://wms.pcn.minambiente.it/ogc?map=/ms_ogc/wfs/Numeri_Civici_2012.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=IN.NUMERICIVICI.2012&SRSNAME=EPSG:4326&bbox=7.719,44.849,7.72,44.85&outputFormat=GML2';
$.ajax({
type: "GET",
url: query,
dataType: "text",
crossDomain: true,
success: function (data) {
addressPCN(data);
},
error: function (response, textStatus, errorThrown) {
alert("KO");
alert(errorThrown);
}
});
}
var map = L.map('map').setView([42, 12], 5);
L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'examples.map-20v6611k'
}).addTo(map);
function addressPCN (addressList) {
//alert("In function addressList");
//alert(addressList);
var addressPCN = '{"type": "FeatureCollection","features":[';
$xmlData = $.parseXML(addressList);
$features = $('gml\\:featureMember, featureMember', $xmlData);
//alert($features.length);
$features.each(function () {
var $this = $(this);
//alert($this.find('ms\\:nome, nome').text() + ' - ' + $this.find('ms\\:civico, civico').text());
addressPCN = addressPCN + '{"type": "Feature", "properties": { "popupContent": "' + $this.find('ms\\:nome, nome').text() + ' ' + $this.find('ms\\:civico, civico').text() + '", ' + '"show_on_map": true }, "geometry": { "type": "Point", "coordinates": [' + $this.find('gml\\:Point, Point').find('gml\\:coordinates, coordinates').text() + ']}},'
});
var addressPCN = addressPCN + ']}';
alert(addressPCN);
function onEachFeature(feature, layer) {
if (feature.properties && feature.properties.popupContent) {
layer.bindPopup(feature.properties.popupContent);
}
}
//var addressPCN = {"type": "FeatureCollection","features":[{"type": "Feature", "properties": { "popupContent": "Via Pegolo 9", "show_on_map": true }, "geometry": { "type": "Point", "coordinates": [7.719490,44.849197]}},{"type": "Feature", "properties": { "popupContent": "Via Pegolo 8", "show_on_map": true }, "geometry": { "type": "Point", "coordinates": [7.719490,44.849197]}},]};
L.geoJson(addressPCN, {
onEachFeature: onEachFeature
}).addTo(map);
}
</script>
//var addressPCN = {"type": "FeatureCollection","features":[{"type": "Feature", "properties": { "popupContent": "Via Pegolo 9", "show_on_map": true }, "geometry": { "type": "Point", "coordinates": [7.719490,44.849197]}},{"type": "Feature", "properties": { "popupContent": "Via Pegolo 8", "show_on_map": true }, "geometry": { "type": "Point", "coordinates": [7.719490,44.849197]}},]};
最佳答案
问题是我试图将字符串用作 JSON 对象。
解决方法是使用 jQuery.parseJSON 使用我的 JSON 代码 (addressPCN1) 将我的字符串转换为 Javascript JSON 对象的函数。
这是有效的代码......
<!DOCTYPE html>
<html>
<head>
<title>Prova caricamento WMS Indirizzi del PCN</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css"/>
</head>
<body>
<div id="map" style="width: 600px; height: 400px"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet-src.js"></script>
<script>
var browser = navigator.userAgent.toLowerCase();
var isIE = (browser.indexOf("msie")>-1 || browser.indexOf("trident")>-1);
if (isIE && window.XDomainRequest) {
if (window.XDomainRequest) {
var query = 'service_url';
var xdr = new XDomainRequest();
if (xdr) {
xdr.onload = function () {
addressPCN(xdr.responseText);
}
xdr.onerror = function () {
alert("KO");
}
xdr.open('GET', query);
xdr.send();
}
}
}
else {
var query = 'service_url';
$.ajax({
type: "GET",
url: query,
dataType: "text",
crossDomain: true,
success: function (data) {
//alert("OK");
//alert(data);
addressPCN(data);
alert($this.find('ms\\:nome, nome').text() + ' - ' + $this.find('ms\\:civico, civico').text());
},
error: function (response, textStatus, errorThrown) {
alert("KO");
alert(errorThrown);
}
});
}
var map = L.map('map').setView([42, 12], 5);
L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'examples.map-20v6611k'
}).addTo(map);
function addressPCN (addressList) {
var addressPCN = '{"type": "FeatureCollection","features":[';
$xmlData = $.parseXML(addressList);
$features = $('gml\\:featureMember, featureMember', $xmlData);
$features.each(function () {
var $this = $(this);
//alert($this.find('ms\\:nome, nome').text() + ' - ' + $this.find('ms\\:civico, civico').text());
addressPCN = addressPCN + '{"type": "Feature", "properties": { "popupContent": "' + $this.find('ms\\:nome, nome').text() + ' ' + $this.find('ms\\:civico, civico').text() + '", ' + '"show_on_map": true }, "geometry": { "type": "Point", "coordinates": [' + $this.find('gml\\:Point, Point').find('gml\\:coordinates, coordinates').text() + ']}},'
});
var addressPCN = addressPCN + ']}';
alert(addressPCN);
var addressPCN1 = addressPCN.replace(',]}',']}');
alert(addressPCN1);
var addressPCN2 = jQuery.parseJSON(addressPCN1);
alert(addressPCN2);
function onEachFeature(feature, layer) {
if (feature.properties && feature.properties.popupContent) {
layer.bindPopup(feature.properties.popupContent);
}
}
L.geoJson(addressPCN2, {
onEachFeature: onEachFeature
}).addTo(map);
}
</script>
</body>
</html>
关于leaflet - 将 GeoJSON 放在传单 map 上 : Invalid GeoJSON object. 抛出新错误 ('Invalid GeoJSON object.' );,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25216165/
我正在尝试按照此链接 http://bost.ocks.org/mike/map/ 上的教程进行操作到目前为止,我已经完全按照列出的每条说明进行操作,但是当我尝试运行“#Converting Data
何我可以反转一个国家的 GeoJson,以便它将国家定义为世界地图多边形中的一个洞?我需要这个来在 OpenLayers 5.3 中创建 GeoJson VectorLayer 的蒙版。 最佳答案 在
我在构建 GeoJSON 并将其放在 map 上的传单代码方面遇到了一些麻烦。 GeoJSON 是根据服务的 XML 响应构建的。 错误是 无效的 GeoJSON 对象。 throw new Erro
我有一个 geojson 表示插值天气数据的等高线层。某些轮廓在更高的缩放级别消失,如以下屏幕抓图所示。 将多边形作为图层添加到 Mapbox 时,使用以下代码: map.addSource('min
我有一些地理边界 have a GeoJSON endpoint for . 我还有一些变量存储在单独的 GeoJSON endpoint 中它没有坐标,但确实有我想稍后使用 D3 对 map 进行主
我是 MapBox GL Js 的新手,我想通过 https 调用一个大的 GeoJSON 文件并将其显示到 map 上。 我认为调用 vector Tile 是最好的方法,我找到了一些教程,展示了如
我已经使用 SQL 到 geoJSON 生成了我的数据库的一些兴趣点。 地理数据: { "FeatureCollection" : [ { "g
创建一张与此处找到的 map 类似的 map : https://www.plantmaps.com/interactive-california-2012-usda-plant-zone-hardi
我对 ammCharts 比较陌生,这也是我第一次尝试创建 geoJSON 文件。 以下是我的geoJson文件: GeoJSON file 这就是我要实现的目标: example 当我加载我的 ge
我有几个 geojson 层,并且我使用组将其分层。我使用此处找到的 Mike 答案将 map 集中在给定的 geojson 文件上 -> Center a map in d3 given a geo
环回新手,但设置我的第一个基于节点的 RestAPI 很有趣。我能够创建模型并在数据存储中创建关联的表。我的模型需要具有数据类型 geojson 的属性,即以下形式的字符串: { “类型”:“特征”,
我使用传单构建了一个 map ,其中包含大的 GeoJSON 区域,这些区域由多个“较小”的 GeoJSON 区域组成。 我正在使用 Leaftet-Ajax 来这样调用它们: var Rennes
我已经能够让其中的一部分工作,但是当 properties.affectedZones 有多个条目时,我的 jQuery 失败了。我已经使用 .each 努力显示受到红旗警告的受影响区域,但是当有两个
我需要对从 geojson 文件中提取的每个功能进行不同的样式设置。然而,这个匿名样式函数仅更改它遇到的第一个功能的样式并停止。我是传单新手。看过几个演示,但找不到这个匿名样式函数仅更改第一个功能的样
我有多个 geojson 类型:存储在 Mysql 中的 FeatureCollection。我想将两个或多个 geojson 合并到一个 FeatureCollection geojson 中并显示
我有这个 geojson { "type":"FeatureCollection", "features":[ { "type":"Feature",
我正在尝试在基于标准 HelloWorld 示例应用程序的测试应用程序中加载以下 geoJson 文件。 { "type": "FeatureCollection", "generator":
我正在使用 GeoJSON 数据构建传单 map 。尝试根据 GeoJSON 属性设置我使用的图标时遇到问题。我认为我的错误与使用字符串调用对象有关,但我无法弄清楚它到底是什么。 这是我的代码: Ge
我有包含如下地理字段的文档。 "geo" : { "type" : "Point", "coordinates" : [ 37.44609999, -1
是否可以仅使用 JavaScript(通过 d3、topojson 或任何其他方式)确定给定纬度、经度的 GeoJSON 点是否位于给定 GeoJSON 多边形内? 例如,我可以根据教程 here 绘
我是一名优秀的程序员,十分优秀!