我做了一些圈子JS如下:
L.circle(
[46.765735535841024, 23.58344078063965], 5, {
color: "blue"
}).addTo(map).bindPopup("Description: This is my description");
Run Code Online (Sandbox Code Playgroud)
我想bindPopup用一个函数替换它.当我点击圆圈而不是我的描述显示时,我想运行一个函数,例如我创建了这个函数:
function circleClick() {
// my implementations;
}
Run Code Online (Sandbox Code Playgroud)
有人会告诉我怎么可能这样做?
我希望GeoJSON.addData()会返回新创建的GeoJSON对象的subLayer,但事实并非如此.为什么我需要这样的东西?
(目前使用Leaflet 1.0Beta2)
我使用Leaflet GeoJson在GeoJSON(点,线,多边形)中显示实时数据.它是一个CRUD界面(创建,更新和删除).我收到带有GeoJSON数据的WebSocket消息,每个消息带有一个GUID.
我是CREATE的情况我只是在适当的层上做GeoJSon.AddData().
但对于UPDATE和DELETE,我想要一个添加到GeoJSON的图层的句柄,以便我可以更新其位置,或更新几何.addData没有给我这个句柄.从onEachFeature()或pointToLayer()获取它真的很难
目前,我确实有一种方法可行,但很难看.我需要做的是每当发生更新或删除时使用GeoJSon.eachLayer(fn)搜索整个图层.看起来有点贵.
{即使Leaflet没有真正设计用于这种实时r/t数据显示,它正在工作,如果你不能像我们一样使用它来观察大量的传感器数据,IoT似乎很难过.
this.delete = function (layerName, feature) {
if (!(layerName in self.myLayers)) {
alert("live.display: Missing Layer: " + layerName);
return;
}
var layerInfo = Live.myLayers[layerName];
var base = layerInfo.layer;
var id = feature.properties.objectID;
this.find(layerName, id, function (layer) {
this.removeLayer(layer);
Tools.debug(16, "live.delete:", "killed object: " + id);
});
}
this.find = function (layerName, id, action) {
var base = Live.myLayers[layerName].layer;
base.eachLayer(function (feature) {
if (!("objectID" in feature.feature.properties)) { …Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码click为某些传单标记(其中我不知道先验数字)的事件添加回调函数:
newArray.forEach(p => {
let marker = L.marker(latLng).on('click', this.markerClick).addTo(newMap)
marker.bindPopup(content)
marker.addTo(newMap)
marker.openPopup()
})
Run Code Online (Sandbox Code Playgroud)
在类中有markerClick执行此操作的函数:
markerClick(e) {
console.log("Inside marker click " + e.latlng.lat + " " + e.latlng.lng)
this.displayError("You clicked on the marker")
}
Run Code Online (Sandbox Code Playgroud)
将console.log正在打印的正确的价值观lat和lng标记,但是打电话时displayError运行时引发错误说:
this.displayError 不是函数
这是一个在类中声明的函数,我用来根据我的需要显示带有自定义消息的祝酒词。这是代码:
displayError(messageErr: string) {
let toast = this.toastCtrl.create({
message: messageErr,
duration: 3000,
position: 'top'
});
toast.present();
}
Run Code Online (Sandbox Code Playgroud)
为什么说那不是函数?
编辑:它不仅仅是displayError,类的每个函数都给出了这个消息。
如何从添加的比例尺中获取值:
L.control.scale({position: 'bottomleft'}).addTo(map);
Run Code Online (Sandbox Code Playgroud)
无论它显示什么比例,如何将其分配给 JavaScript 中的变量?
使用 Leaflet 的 Mapbox 无法在模态中正确显示时遇到问题。
地图和标记位于左上角,其余图块为空白。
我已经直接在页面中尝试了代码而不是模式,它可以工作......
<style>
#mapid { height: 300px; }
</style>
<div id="mapid"></div>
<script>
var mymap = L.map('mapid').setView([<?= $return['latitude']; ?>, <?= $return['longitude']; ?>], 13);
//var mymap = L.Map('mapid', { center: new L.LatLng(<?= $return['latitude']; ?>, <?= $return['longitude']; ?>]), zoom: 15, layers: [nexrad], zoomControl: true });
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=<?= $MapBoxToken ?>', {
attribution: '© <a href="http://mapbox.com">Mapbox</a>, © <a href="http://openstreetmap.org">OpenStreetMap</a>',
maxZoom: 20,
id: 'mapbox.streets',
accessToken: '<?= $MapBoxToken ?>'
}).addTo(mymap);
var marker = L.marker([<?= $return['latitude']; ?>, <?= $return['longitude']; ?>]).addTo(mymap);
</script>
Run Code Online (Sandbox Code Playgroud)
我正在尝试在 react 组件中实现一个简单的 Leaflet 地图。由于某种原因,地图的图块没有加载或以随机顺序加载。有没有其他人经历过这种情况?
这是应用程序的 CodeSandbox:https ://codesandbox.io/s/3qmp8x4131
这是代码:
import React from "react";
import ReactDOM from "react-dom";
import * as L from "leaflet";
export default class Map extends React.Component {
map = null;
componentDidMount() {
var map = (this.map = L.map(ReactDOM.findDOMNode(this), {
minZoom: 2,
maxZoom: 20,
layers: [
L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution:
'© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
})
],
attributionControl: false
}));
map.on("click", this.onMapClick);
map.fitWorld();
}
componentWillUnmount() {
if (!this.map) return;
this.map.off("click", this.onMapClick);
this.map = null;
}
onMapClick = …Run Code Online (Sandbox Code Playgroud) 我尝试使用通过 NPM 导入的 Realm 但失败了。
我正在使用 JavaScript 的 Realm 示例:
const Realm = require('realm');
// Define your models and their properties
const CarSchema = {
name: 'Car',
properties: {
make: 'string',
model: 'string',
miles: {type: 'int', default: 0},
}
};
const PersonSchema = {
name: 'Person',
properties: {
name: 'string',
birthday: 'date',
cars: 'Car[]',
picture: 'data?' // optional property
}
};
Realm.open({schema: [CarSchema, PersonSchema]})
.then(realm => {
// Create Realm objects and write to local storage
realm.write(() => {
const …Run Code Online (Sandbox Code Playgroud) 我刚刚使用 Leaflet 为网站构建地图,并注意到要添加图块图层,至少可以使用两种方法L.TileLayer()和L.tileLayer(),它们的名称仅在单个字符的大小写上有所不同。
然而,虽然这两个方法返回的对象都可以添加到由L.map()返回的对象返回的地图对象中,但返回的对象L.TileLayer()似乎没有该addTo()方法,而返回的对象似乎没有该方法L.tileLayer()。例如两者
var map = L.map('map');
var tiles = new L.TileLayer(<tileUrl>, {attribution: <tileAttrib>});
map.addLayer(tiles);
Run Code Online (Sandbox Code Playgroud)
和
var map = L.map('map');
var tiles = new L.tileLayer(<tileUrl>, {attribution: <tileAttrib>});
map.addLayer(tiles);
Run Code Online (Sandbox Code Playgroud)
也
var map = L.map('map');
L.tileLayer(<tileUrl>, {attribution: <tileAttrib>}).addTo(map);
Run Code Online (Sandbox Code Playgroud)
同时
var map = L.map('map');
L.TileLayer(<tileUrl>, {attribution: <tileAttrib>}).addTo(map);
Run Code Online (Sandbox Code Playgroud)
失败。浏览Leaflet的文档,似乎正确的使用方法是,L.tileLayer()那么问题是有什么用L.TileLayer()?
这是到目前为止我的代码的完整示例,要尝试不同的替代方案,只需取消注释要测试的代码并确保其他替代方案得到注释
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/> …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用 WebView 来显示传单地图。
在 HTML 文件中,我有以下学分和链接:
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=xxxxx', {
maxZoom: 18,
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
id: 'mapbox.streets'
}).addTo(mymap);
Run Code Online (Sandbox Code Playgroud)
这看起来像这样:
有没有办法将属性控件放在左上角而不是右下角?
我正在使用Leaflet.markercluster。
这是我的代码,基于各种相关问题:
// Takes an L.markerClusterGroup as input parameter
Self.GetNumMarkersInClusterGroup = function(clusterGroup)
{
Self.map.eachLayer(function (layer) {
if (layer.getChildCount) {
// somehow need to check here for our desired cluter group
console.log('Cluster group has ' + layer._childClusters.length + 'layers') ;
console.log('With a total of ' + layer._childCount + ' markers');
}
});
} // GetNumMarkersInClusterGroup()
Run Code Online (Sandbox Code Playgroud)
但是,layer.getChildCount未定义:-( 我做错了什么?
相关问题:
leaflet ×9
javascript ×4
electron ×1
gis ×1
mapbox ×1
npm-install ×1
onclick ×1
reactjs ×1
realm ×1
webpack ×1