Javascript 使用其他内容更新特定div的内容
我在一个网站上工作,它显示了一个自然公园的路线信息。当用户单击曲目时,它应该使用曲目详细信息(geojson上的外部html)更新div“#info”。我无法让细节发挥作用 下面是javascript代码:Javascript 使用其他内容更新特定div的内容,javascript,jquery,mapbox,Javascript,Jquery,Mapbox,我在一个网站上工作,它显示了一个自然公园的路线信息。当用户单击曲目时,它应该使用曲目详细信息(geojson上的外部html)更新div“#info”。我无法让细节发挥作用 下面是javascript代码: var map = L.mapbox.map('map', 'pokomoko.l6e2j9h1'); var geojson = [{ "type": "FeatureCollection", "crs": { "type": "name",
var map = L.mapbox.map('map', 'pokomoko.l6e2j9h1');
var geojson = [{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [{
"type": "Feature",
"properties": {
"Name": "Camí circular",
"Descriptio": null,
'id': 2,
"stroke": "blue",
"stroke-opacity": 1,
"stroke-width": 6,
"URL": 'Circular/circular_cat.html'
},
"geometry": {
"type": "LineString",
"coordinates": [
[1.768113361018627, 41.609716521663515],
[1.768283835249583, 41.609747082164205],
[1.768422882004483, 41.609779001160376],
[1.7685547698433, 41.609805665922217],
[1.768687708285772, 41.609832049115262],
[1.768817761141674, 41.609857849364609],
[1.768905770134774, 41.609893436891795],
// ....
]
}];
// Create a feature layer that will hold the GeoJSON above.
var features = L.mapbox.featureLayer().addTo(map);
features.setGeoJSON(geojson);
features.on('mouseover', function (e) {
focusline(e.layer.feature.properties.id);
});
features.on('click', function() {
$("#info").load(getURL(features)).hide().fadeIn('slow');
});
function focusline(focus) {
// Iterate through each feature in the
// features object and alter the properties.
features.eachLayer(function (l) {
var props = l.feature.properties;
props['stroke-opacity'] = (props.id !== focus) ? 0.25 : 1;
});
// Rerun the geojson
features.setGeoJSON(geojson);
}
这里有一种方法
var features = L.mapbox.featureLayer().addTo(map);
features.setGeoJSON(geojson);
features.on('click', function(e) {
loadIframe(e.layer.feature.properties.data);
});
features.on('mouseover', function(e) {
focusline(e.layer.feature.properties.id);
});
function loadIframe (url) {
$("#info").load(url).hide().fadeIn('slow');
// Rerun the geojson
features.setGeoJSON(geojson);
};
function focusline(focus) {
// Iterate through each feature in the
// features object and alter the properties.
features.eachLayer(function(l) {
var props = l.feature.properties;
props['stroke-opacity'] = (props.id !== focus) ? 0.5 : 1;});
}
什么是
getPage()
?此功能不在您的代码中。是否触发了单击事件?getPage(features)
是否返回包含有效URL的字符串?正如Jeremy已经提到的:getPage()
定义在哪里?是的,我对javascript不是很在行,我在互联网上的另一个示例中查看的代码也不是我的代码,如果有人能帮我触发点击,我将非常感激!谢谢,我已经更改了一个有效的URL页面,但它没有工作太多。