加载和查看OpenStreetMap图块的问题:无法加载资源:服务器以403()electRoneReactectwebpack的状态做出响应
正如我在此stackoverflow
问题中所描述的,问题:传单:突然我会收到此错误消息:无法加载资源:服务器以403()状态响应 我正在遇到加载和查看OpenStreetMap图块
:
无法加载资源的问题:服务器以403()
的状态响应,
基于信息: https://operations.osmfoundation.org/policies/fiteles/fiteles/ 代码> openstreetMap 图块用法:
Requirements
Heavy use (e.g. distributing an app that uses tiles from openstreetmap.org) is forbidden without prior permission from the [Operations Working Group](https://wiki.osmfoundation.org/wiki/Operations_Working_Group). See below for alternatives.
Clearly display [license](https://wiki.openstreetmap.org/wiki/License) attribution.
Do not actively or passively encourage copyright infringement.
Calls to /cgi-bin/export may only be triggered by direct end-user action. (For example: “click here to export”.) The export call is an expensive (CPU+RAM) function to run and will frequently reject when server is under high load.
Recommended: Do not hardcode any URL at tile.openstreetmap.org as doing so will limit your ability to react quickly if the service is disrupted or blocked.
Recommended: add a link to https://www.openstreetmap.org/fixthemap to allow your users to report and fix problems in our data.
Technical Usage Requirements
Valid [HTTP User-Agent](http://en.wikipedia.org/wiki/en:User_agent) identifying application. Faking another app’s User-Agent WILL get you blocked.
If known, a valid [HTTP Referer](http://en.wikipedia.org/wiki/en:HTTP_Referer).
DO NOT send no-cache headers. (“Cache-Control: no-cache”, “Pragma: no-cache” etc.)
Cache Tile downloads locally according to HTTP Expiry Header, alternatively a minimum of 7 days.
Maximum of 2 download threads. (Unmodified web browsers’ download thread limits are acceptable.)
Note: modern web browsers in standard configuration generally pass all the above technical requirements.
据我了解,我确实尊重所有这些
html
file:
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="original-trial" content=AhRSNW+2zbXlDahhAcj194oqlgDxj3TqG4sYwhsUdqldtNbZagboEjqIJZuUvBsIjtij4VSW0YvP5tGSpVgu6wgAAABzeyJvcmlnaW4iOiJodHRwczovL2dnYy53b3JsZDo0NDMiLCJmZWF0dXJlIjoiVW5yZXN0cmljdGVkU2hhcmVkQXJyYXlCdWZmZXIiLCJleHBpcnkiOjE2MzM0NzgzO>
<title>First Window</title>
</head>
<body>
<div id="app"></div>
<script type="javascript" defer src="./app/index.js"></script>
<script>
</script>
<style>
.leaflet-container {
height: 800px;
width: 100%;
}
</style>
</body>
</html>
app.tsxx
:
import * as React from 'react';
const Mapping = React.lazy(() => import('./mapVisualize/maps'))
function App() {
return (
<div className='container'>
<React.Suspense fallback={<div>Loading...</div>}>
<Mapping />
</React.Suspense>
</div>
);
}
export default App;
./ mapvisalize/mapvisalize / MAPS.JS
:
从“小叶”导入传单; 导入“传单/dist/feflet.css”;
import React from "react";
import {
TileLayer,
LayersControl,
Marker,
Popup,
MapContainer
} from "react-leaflet";
import iconUrl from "../../../assets/css/svg/push_pin_black_36dp.svg";
export const newicon = new Leaflet.Icon({
iconUrl,
iconAnchor: [5, 55],
popupAnchor: [10, -44],
iconSize: [25, 55]
});
const center = {
lat: 51.505,
lng: -0.09
};
export default function App() {
return (
<div className="App">
<MapContainer center={center} zoom={13} style={{ height: "200px" }}>
<LayersControl position="topleft">
<LayersControl.BaseLayer checked name="Basic Map">
<TileLayer
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
</LayersControl.BaseLayer>
<Marker position={[51.505, -0.09]}>
<Popup>
A pretty CSS3 popup. <br /> Easily customizable.
</Popup>
</Marker>
<LayersControl.BaseLayer name="Topo Map">
<TileLayer
attribution='Map data: © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, <a href="http://viewfinderpanoramas.org">SRTM</a> | Map style: © <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)'
url="https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png"
/>
</LayersControl.BaseLayer>
</LayersControl>
<Marker position={[51.505, -0.09]}>
<Popup>
A pretty CSS3 popup. <br /> Easily customizable.
</Popup>
</Marker>
</MapContainer>
</div>
);
}
webpack.config.js
:
const path = require('path');
const cwd = process.cwd();
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
function srcPaths(src) {
return path.join(__dirname, src);
}
const isEnvProduction = process.env.NODE_ENV === 'production';
const isEnvDevelopment = process.env.NODE_ENV === 'development';
// main process
var main_config = {
mode: isEnvProduction ? 'production' : 'development',
entry: './src/main/main.ts',
target: 'electron-main',
resolve: {
extensions: ['.jsx', '.js', 'ts'],
},
externals: [
{
'utf-8-validate': 'commonjs utf-8-validate',
bufferutil: 'commonjs bufferutil',
},
],
module: {
rules: [
{
test: /\.ts$/,
include: /src/,
use: [{ loader: 'ts-loader' }]
},
{
test: /\.(sass|less|css)$/i,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader'
},
{
loader: 'less-loader',
},
],
},
{
test: /\.s?css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
sourceMap: true
}
},
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
},
{
test: /\.(png|jpe?g|svg|gif)$/i,
use: [
{
loader: "file-loader",
options: {
name: "[path]/[name].[ext]",
},
},
],
},
{
test: /\.geojson$/,
use: [
{
loader: "json-loader",
}
],
}
]
},
output: {
path: __dirname + '/dist',
filename: 'main.js'
},
node: {
__dirname: false,
__filename: false
},
};
// renderer process
var renderer_config = {
mode: isEnvProduction ? 'production' : 'development',
entry: {
app: ['./src/app/index.tsx', 'react-app-polyfill/stable'],
style: [
'./src/app/styles/index.css',
path.resolve(__dirname, 'node_modules/leaflet/dist/leaflet.css')
]
},
//target: 'electron-renderer',
//target: 'web',
target: ['web', 'es5'],
resolve: {
extensions: ['.jsx', '.js', '.tsx', '.ts'],
},
output: {
path: __dirname + '/dist/',
//filename: 'renderer.js'
filename: '[name].js',
},
externals: [
{
'utf-8-validate': 'commonjs utf-8-validate',
bufferutil: 'commonjs bufferutil',
},
],
module: {
rules: [
{
test: /\.(js|ts)x?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
// css files
test: /\.css$/i,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader'
},
],
},
{
test: /\.(png|jpe?g|svg|gif)$/i,
use: [
{
loader: "file-loader",
options: {
name: "[path]/[name].[ext]",
},
},
],
},
{
// Font files
test: /\.(woff|woff2|ttf|otf)$/,
loader: 'file-loader',
options: {
name: '[hash].[ext]',
outputPath: 'dist/assets/css/'
}
},
],
},
node: {
__dirname: false,
__filename: false
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/app/index.html',
inject:'body',
chunks: ['app'],
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
linkType: 'text/css',
}),
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, "./src/assets/css"),
to: path.resolve(__dirname, "./dist/assets/css")
},
],
options: {
concurrency: 100,
},
}),
]
}
module.exports = [
main_config,
renderer_config,
];
我的困惑是,这仅对基本地图层
:
<LayersControl position="topleft">
<LayersControl.BaseLayer checked name="Basic Map">
<TileLayer
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
</LayersControl.BaseLayer>
/I.SSTATIC.NET/ANZAY.PNG“ rel =” nofollow noreferrer“>
例如,它无法加载此瓷砖:
https:https://b.tile。 openstreetmap.org/13/4094/2723.png
i.sstatic.net/nzrev.png“ alt =”在此处输入图像说明“>
错误消息:访问拒绝请参见:https://operations.osmfoundation.org/policies/policies/fiteles/
使用topo映射层
可视化似乎很好:
<LayersControl.BaseLayer name="Topo Map">
<TileLayer
attribution='Map data: © <a href="http://viewfinderpanoramas.org">SRTM</a> | Map style: © <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)'
url="https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png"
/>
</LayersControl.BaseLayer>
如何解决问题? 期待您的帮助
As I described in this StackOverflow
question : Leaflet : Suddenly I'm getting this error message: Failed to load resource: the server responded with a status of 403 ()
I'm experiencing issues with loading and viewing openstreetmap tiles
:
Failed to load resource: the server responded with a status of 403 ()
Based on the info here : https://operations.osmfoundation.org/policies/tiles/ the following are the requirements for the openstreetmap
tiles usage:
Requirements
Heavy use (e.g. distributing an app that uses tiles from openstreetmap.org) is forbidden without prior permission from the [Operations Working Group](https://wiki.osmfoundation.org/wiki/Operations_Working_Group). See below for alternatives.
Clearly display [license](https://wiki.openstreetmap.org/wiki/License) attribution.
Do not actively or passively encourage copyright infringement.
Calls to /cgi-bin/export may only be triggered by direct end-user action. (For example: “click here to export”.) The export call is an expensive (CPU+RAM) function to run and will frequently reject when server is under high load.
Recommended: Do not hardcode any URL at tile.openstreetmap.org as doing so will limit your ability to react quickly if the service is disrupted or blocked.
Recommended: add a link to https://www.openstreetmap.org/fixthemap to allow your users to report and fix problems in our data.
Technical Usage Requirements
Valid [HTTP User-Agent](http://en.wikipedia.org/wiki/en:User_agent) identifying application. Faking another app’s User-Agent WILL get you blocked.
If known, a valid [HTTP Referer](http://en.wikipedia.org/wiki/en:HTTP_Referer).
DO NOT send no-cache headers. (“Cache-Control: no-cache”, “Pragma: no-cache” etc.)
Cache Tile downloads locally according to HTTP Expiry Header, alternatively a minimum of 7 days.
Maximum of 2 download threads. (Unmodified web browsers’ download thread limits are acceptable.)
Note: modern web browsers in standard configuration generally pass all the above technical requirements.
As far as I understand, I do respect all of them
html
file:
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="original-trial" content=AhRSNW+2zbXlDahhAcj194oqlgDxj3TqG4sYwhsUdqldtNbZagboEjqIJZuUvBsIjtij4VSW0YvP5tGSpVgu6wgAAABzeyJvcmlnaW4iOiJodHRwczovL2dnYy53b3JsZDo0NDMiLCJmZWF0dXJlIjoiVW5yZXN0cmljdGVkU2hhcmVkQXJyYXlCdWZmZXIiLCJleHBpcnkiOjE2MzM0NzgzO>
<title>First Window</title>
</head>
<body>
<div id="app"></div>
<script type="javascript" defer src="./app/index.js"></script>
<script>
</script>
<style>
.leaflet-container {
height: 800px;
width: 100%;
}
</style>
</body>
</html>
App.tsx
:
import * as React from 'react';
const Mapping = React.lazy(() => import('./mapVisualize/maps'))
function App() {
return (
<div className='container'>
<React.Suspense fallback={<div>Loading...</div>}>
<Mapping />
</React.Suspense>
</div>
);
}
export default App;
./mapVisualize/maps.js
:
import Leaflet from "leaflet";
import "leaflet/dist/leaflet.css";
import React from "react";
import {
TileLayer,
LayersControl,
Marker,
Popup,
MapContainer
} from "react-leaflet";
import iconUrl from "../../../assets/css/svg/push_pin_black_36dp.svg";
export const newicon = new Leaflet.Icon({
iconUrl,
iconAnchor: [5, 55],
popupAnchor: [10, -44],
iconSize: [25, 55]
});
const center = {
lat: 51.505,
lng: -0.09
};
export default function App() {
return (
<div className="App">
<MapContainer center={center} zoom={13} style={{ height: "200px" }}>
<LayersControl position="topleft">
<LayersControl.BaseLayer checked name="Basic Map">
<TileLayer
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
</LayersControl.BaseLayer>
<Marker position={[51.505, -0.09]}>
<Popup>
A pretty CSS3 popup. <br /> Easily customizable.
</Popup>
</Marker>
<LayersControl.BaseLayer name="Topo Map">
<TileLayer
attribution='Map data: © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, <a href="http://viewfinderpanoramas.org">SRTM</a> | Map style: © <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)'
url="https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png"
/>
</LayersControl.BaseLayer>
</LayersControl>
<Marker position={[51.505, -0.09]}>
<Popup>
A pretty CSS3 popup. <br /> Easily customizable.
</Popup>
</Marker>
</MapContainer>
</div>
);
}
webpack.config.js
:
const path = require('path');
const cwd = process.cwd();
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
function srcPaths(src) {
return path.join(__dirname, src);
}
const isEnvProduction = process.env.NODE_ENV === 'production';
const isEnvDevelopment = process.env.NODE_ENV === 'development';
// main process
var main_config = {
mode: isEnvProduction ? 'production' : 'development',
entry: './src/main/main.ts',
target: 'electron-main',
resolve: {
extensions: ['.jsx', '.js', 'ts'],
},
externals: [
{
'utf-8-validate': 'commonjs utf-8-validate',
bufferutil: 'commonjs bufferutil',
},
],
module: {
rules: [
{
test: /\.ts$/,
include: /src/,
use: [{ loader: 'ts-loader' }]
},
{
test: /\.(sass|less|css)$/i,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader'
},
{
loader: 'less-loader',
},
],
},
{
test: /\.s?css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
sourceMap: true
}
},
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
},
{
test: /\.(png|jpe?g|svg|gif)$/i,
use: [
{
loader: "file-loader",
options: {
name: "[path]/[name].[ext]",
},
},
],
},
{
test: /\.geojson$/,
use: [
{
loader: "json-loader",
}
],
}
]
},
output: {
path: __dirname + '/dist',
filename: 'main.js'
},
node: {
__dirname: false,
__filename: false
},
};
// renderer process
var renderer_config = {
mode: isEnvProduction ? 'production' : 'development',
entry: {
app: ['./src/app/index.tsx', 'react-app-polyfill/stable'],
style: [
'./src/app/styles/index.css',
path.resolve(__dirname, 'node_modules/leaflet/dist/leaflet.css')
]
},
//target: 'electron-renderer',
//target: 'web',
target: ['web', 'es5'],
resolve: {
extensions: ['.jsx', '.js', '.tsx', '.ts'],
},
output: {
path: __dirname + '/dist/',
//filename: 'renderer.js'
filename: '[name].js',
},
externals: [
{
'utf-8-validate': 'commonjs utf-8-validate',
bufferutil: 'commonjs bufferutil',
},
],
module: {
rules: [
{
test: /\.(js|ts)x?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
// css files
test: /\.css$/i,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader'
},
],
},
{
test: /\.(png|jpe?g|svg|gif)$/i,
use: [
{
loader: "file-loader",
options: {
name: "[path]/[name].[ext]",
},
},
],
},
{
// Font files
test: /\.(woff|woff2|ttf|otf)$/,
loader: 'file-loader',
options: {
name: '[hash].[ext]',
outputPath: 'dist/assets/css/'
}
},
],
},
node: {
__dirname: false,
__filename: false
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/app/index.html',
inject:'body',
chunks: ['app'],
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
linkType: 'text/css',
}),
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, "./src/assets/css"),
to: path.resolve(__dirname, "./dist/assets/css")
},
],
options: {
concurrency: 100,
},
}),
]
}
module.exports = [
main_config,
renderer_config,
];
What perplex me is that this happens only for the Basic Map Layer
:
<LayersControl position="topleft">
<LayersControl.BaseLayer checked name="Basic Map">
<TileLayer
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
</LayersControl.BaseLayer>
For example, it fails to load this tile:
https://b.tile.openstreetmap.org/13/4094/2723.png
Error message: Access Denied See: https://operations.osmfoundation.org/policies/tiles/
With the Topo Map Layer
the visualization seems fine :
<LayersControl.BaseLayer name="Topo Map">
<TileLayer
attribution='Map data: © <a href="http://viewfinderpanoramas.org">SRTM</a> | Map style: © <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)'
url="https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png"
/>
</LayersControl.BaseLayer>
How to solve the issue?
Looking forward to your kind help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论