在 React-Leaflet 2.8.0 中,旧的处理方式是使用MapLayer和withLeaflet。
但现在在反应传单中:
MapLayerwithLeaflet从版本 3 开始已弃用。
我试图掌握核心文档:https ://react-leaflet.js.org/docs/core-introduction
但以下不起作用,我明白了
提供的对象不是图层。
import React, { Component, useEffect } from "react";
import { useLeafletContext, leafletElement, createLayerComponent } from '@react-leaflet/core'
import { MapContainer, TileLayer, useMap } from "react-leaflet";
import Leaflet from "leaflet";
import "leaflet-routing-machine";
function Routing(props) {
const context = useLeafletContext();
useEffect(() =>
{
let routing = createLayerComponent(Leaflet.Routing.control(
{
waypoints: [
Leaflet.latLng(33.52001088075479, 36.26829385757446),
Leaflet.latLng(33.50546582848033, 36.29547681726967)
],
lineOptions: {
styles: [{ color: "#6FA1EC", weight: 4 }] …Run Code Online (Sandbox Code Playgroud) javascript leaflet reactjs leaflet-routing-machine react-leaflet
我正在尝试扩展“react-leaflet”v3 中的 TileLayer 组件。有必要重写此函数以提供自定义磁贴 URL 命名方案。我需要的一个例子,写在基本传单中:
function initMap() {
L.TileLayer.WebGis = L.TileLayer.extend({
initialize: function (url, options) {
options = L.setOptions(this, options);
if (options.detectRetina && L.Browser.retina && options.maxZoom > 0) {
options.tileSize = Math.floor(options.tileSize / 2);
options.zoomOffset++;
if (options.minZoom > 0) {
options.minZoom--;
}
this.options.maxZoom--;
}
if (options.bounds) {
options.bounds = L.latLngBounds(options.bounds);
}
this._url = url + "/gis_render/{x}_{y}_{z}/" + options.userId + "/tile.png";
var subdomains = this.options.subdomains;
if (typeof subdomains === 'string') {
this.options.subdomains = subdomains.split('');
}
},
getTileUrl: function (tilePoint) { …Run Code Online (Sandbox Code Playgroud)