当前位置: 首页 > news >正文

wordpress本地化采用方法seo搜索引擎优化

wordpress本地化采用方法,seo搜索引擎优化,备份的网站建设方案书,室内设计效果图手绘客厅概述 随着数据经度的提升,18级的切片有些场景已经不够用了,但是大部分在线的栅格切片最大级别还是18级,如果地图继续放大,有的框架(leaflet会,openlayers和mapboxGL不会)会存在没有底图的情况。…

概述

随着数据经度的提升,18级的切片有些场景已经不够用了,但是大部分在线的栅格切片最大级别还是18级,如果地图继续放大,有的框架(leaflet会,openlayers和mapboxGL不会)会存在没有底图的情况。为处理这种情况,本文通过node实现在级别大于18级的时候将18级的切片进行裁切,解决没有底图的问题。

实现效果

动画.gif

实现代码

获取切片图片,如果z大于18,则取18级的切片进行切割;否则直接返回。

getTileData(z, x, y) {return new Promise(resolve => {let url = '', extent = [], xy18 = []if(z > 18 ) {extent = this.getTileExtent(z, x, y)const [minX, minY, maxX, maxY] = extent// 获取18级对应的索引xy18 = this.getTileIndexByCoords((minX + maxX) / 2, (minY + maxY) / 2)const [x18, y18] = xy18url = `https://webrd01.is.autonavi.com/appmaptile?style=8&lang=zh_cn&size=1&scale=1&x=${x18}&y=${y18}&z=18`} else {url = `https://webrd01.is.autonavi.com/appmaptile?style=8&lang=zh_cn&size=1&scale=1&x=${x}&y=${y}&z=${z}`}loadImage(url).then(image => {this.ctx.clearRect(0, 0, this.TILE_SIZE, this.TILE_SIZE)if(z > 18) {const [minX, minY, maxX, maxY] = extentconst [x18, y18] = xy18const [minX18, minY18, maxX18, maxY18] = this.getTileExtent(18, x18, y18)const [srcx18, srcy18] = this.toScreen(minX18, maxY18)const [srcxmin, srcymin] = this.toScreen(minX, maxY)const [srcxmax, srcymax] = this.toScreen(maxX, minY)const scrx = Math.round(srcxmin - srcx18), scry = Math.round(srcymin - srcy18)const width = Math.round(srcxmax - srcx18 - scrx), height = Math.round(srcymax - srcy18 - scry)this.ctx.drawImage(image, scrx, scry, width, height, 0, 0, this.TILE_SIZE, this.TILE_SIZE)} else {this.ctx.drawImage(image, 0, 0, this.TILE_SIZE, this.TILE_SIZE)}resolve(this.canvas.toBuffer('image/png'))})})
}

getTileExtent为根据切片索引获取切片范围,其实现如下:

getResolution(z) {return (this.TILE_ORIGIN * 2) / (Math.pow(2, z) * this.TILE_SIZE)
}
/*** 获取切片范围* @param {number} z * @param {number} x * @param {number} y * @returns {number}*/
getTileExtent(z, x, y) {const res = this.getResolution(z)const minX = x * this.TILE_SIZE * res - this.TILE_ORIGINconst maxX = (x + 1) * this.TILE_SIZE * res - this.TILE_ORIGINconst minY = this.TILE_ORIGIN - (y + 1) * this.TILE_SIZE * resconst maxY = this.TILE_ORIGIN - y * this.TILE_SIZE * resreturn [minX, minY, maxX, maxY]
}

其中

  • TILE_SIZE,切片大小,值为256;
  • TILE_ORIGIN,切片原点,值为20037508.34;
    getTileIndexByCoords为根据坐标获取切片索引,实现代码如下:
getTileIndexByCoords(x, y) {const res18 = this.getResolution(18) * this.TILE_SIZEreturn [Math.floor((x + this.TILE_ORIGIN) / res18),Math.floor((this.TILE_ORIGIN - y) / res18)]
}

toScreen实现将地理坐标转换为屏幕坐标。

toScreen(x, y) {const res18 = this.getResolution(18)return [(x + this.TILE_ORIGIN) / res18,(this.TILE_ORIGIN - y) / res18]
}

完整代码如下:

import { createCanvas, loadImage } from 'canvas'
import express from 'express'console.time('app')const app = express()// 自定义跨域中间件
const allowCors = function (req, res, next) {res.header('Access-Control-Allow-Origin', req.headers.origin);res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');res.header('Access-Control-Allow-Headers', 'Content-Type');res.header('Access-Control-Allow-Credentials', 'true');next();
};
app.use(allowCors);// 使用跨域中间件app.use(express.static('public'))class TileUtil {constructor() { this.TILE_ORIGIN = 20037508.34 // 切片原点this.TILE_SIZE = 256; // 切片大小this.canvas = createCanvas(this.TILE_SIZE, this.TILE_SIZE)this.ctx = this.canvas.getContext('2d')}/*** 计算分辨率* @param {number} z - 缩放级别* @returns {number}*/getResolution(z) {return (this.TILE_ORIGIN * 2) / (Math.pow(2, z) * this.TILE_SIZE)}/*** 获取切片范围* @param {number} z * @param {number} x * @param {number} y * @returns {number}*/getTileExtent(z, x, y) {const res = this.getResolution(z)const minX = x * this.TILE_SIZE * res - this.TILE_ORIGINconst maxX = (x + 1) * this.TILE_SIZE * res - this.TILE_ORIGINconst minY = this.TILE_ORIGIN - (y + 1) * this.TILE_SIZE * resconst maxY = this.TILE_ORIGIN - y * this.TILE_SIZE * resreturn [minX, minY, maxX, maxY]}/*** 将地理坐标转换为屏幕坐标* @param {number} x * @param {number} y * @returns {number}*/toScreen(x, y) {const res18 = this.getResolution(18)return [(x + this.TILE_ORIGIN) / res18,(this.TILE_ORIGIN - y) / res18]}/*** 获取切片图片,如果z大于18,则取18级的切片进行切割;否则直接返回* @param {number} z * @param {number} x * @param {number} y * @returns {Buffer<Image>}*/getTileData(z, x, y) {return new Promise(resolve => {let url = '', extent = [], xy18 = []if(z > 18 ) {extent = this.getTileExtent(z, x, y)const [minX, minY, maxX, maxY] = extent// 获取18级对应的索引xy18 = this.getTileIndexByCoords((minX + maxX) / 2, (minY + maxY) / 2)const [x18, y18] = xy18url = `https://webrd01.is.autonavi.com/appmaptile?style=8&lang=zh_cn&size=1&scale=1&x=${x18}&y=${y18}&z=18`} else {url = `https://webrd01.is.autonavi.com/appmaptile?style=8&lang=zh_cn&size=1&scale=1&x=${x}&y=${y}&z=${z}`}loadImage(url).then(image => {this.ctx.clearRect(0, 0, this.TILE_SIZE, this.TILE_SIZE)if(z > 18) {const [minX, minY, maxX, maxY] = extentconst [x18, y18] = xy18const [minX18, minY18, maxX18, maxY18] = this.getTileExtent(18, x18, y18)const [srcx18, srcy18] = this.toScreen(minX18, maxY18)const [srcxmin, srcymin] = this.toScreen(minX, maxY)const [srcxmax, srcymax] = this.toScreen(maxX, minY)const scrx = Math.round(srcxmin - srcx18), scry = Math.round(srcymin - srcy18)const width = Math.round(srcxmax - srcx18 - scrx), height = Math.round(srcymax - srcy18 - scry)this.ctx.drawImage(image, scrx, scry, width, height, 0, 0, this.TILE_SIZE, this.TILE_SIZE)} else {this.ctx.drawImage(image, 0, 0, this.TILE_SIZE, this.TILE_SIZE)}resolve(this.canvas.toBuffer('image/png'))})})}/*** 根据坐标获取切片索引* @param {number} x * @param {number} y * @returns {[<number>, <number>]}*/getTileIndexByCoords(x, y) {const res18 = this.getResolution(18) * this.TILE_SIZEreturn [Math.floor((x + this.TILE_ORIGIN) / res18),Math.floor((this.TILE_ORIGIN - y) / res18)]}
}const util = new TileUtil()app.get('/tile/:z/:x/:y', (req, res) => {const { z, x, y } = req.paramsutil.getTileData(Number(z), Number(x), Number(y)).then(data => {res.setHeader('Expires', new Date(Date.now() + 30 * 1000).toUTCString())res.writeHead(200, {"Content-Type": "image/png",});res.end(data);})
})app.get('/tile-bbox/:z/:x/:y', (req, res) => {const { z, x, y } = req.paramsconst TILE_SIZE = 256;const canvas = createCanvas(TILE_SIZE, TILE_SIZE)const ctx = canvas.getContext('2d')ctx.fillStyle = '#f00'ctx.strokeStyle = '#f00'ctx.lineWidth = 2ctx.textAlign = "center";ctx.textBaseline = "middle"ctx.font = "bold 18px 微软雅黑";ctx.strokeRect(0, 0, TILE_SIZE, TILE_SIZE)ctx.fillText(`${z}-${x}-${y}`, TILE_SIZE / 2, TILE_SIZE / 2)res.setHeader('Expires', new Date(Date.now() + 30 * 1000).toUTCString())res.writeHead(200, {"Content-Type": "image/png",});res.end(canvas.toBuffer('image/png'));
})app.listen(18089, () => {console.timeEnd('app')console.log('express server running at http://127.0.0.1:18089')
})

文章转载自:
http://dinncoverso.tpps.cn
http://dinncopapoose.tpps.cn
http://dinncoholarctic.tpps.cn
http://dinncoazotemia.tpps.cn
http://dinncoconscientious.tpps.cn
http://dinncoanlace.tpps.cn
http://dinnconationalism.tpps.cn
http://dinncohemispheroid.tpps.cn
http://dinncohyperkinesis.tpps.cn
http://dinncointransitivize.tpps.cn
http://dinncogeratology.tpps.cn
http://dinncogaillard.tpps.cn
http://dinncosensualism.tpps.cn
http://dinncomyxoid.tpps.cn
http://dinncouranalysis.tpps.cn
http://dinncomgal.tpps.cn
http://dinncounjelled.tpps.cn
http://dinncoteravolt.tpps.cn
http://dinncoimpressively.tpps.cn
http://dinncocatalo.tpps.cn
http://dinncomaukin.tpps.cn
http://dinncoshall.tpps.cn
http://dinncoube.tpps.cn
http://dinncoasiatic.tpps.cn
http://dinncocolourbred.tpps.cn
http://dinncopidgin.tpps.cn
http://dinncosuds.tpps.cn
http://dinncobequest.tpps.cn
http://dinncoharddisk.tpps.cn
http://dinncoimpoverish.tpps.cn
http://dinncocallan.tpps.cn
http://dinncononuniform.tpps.cn
http://dinncoups.tpps.cn
http://dinncoactiniform.tpps.cn
http://dinncorounder.tpps.cn
http://dinncocowlstaff.tpps.cn
http://dinncoappendent.tpps.cn
http://dinncosiliqua.tpps.cn
http://dinncopedestrianise.tpps.cn
http://dinncobmoc.tpps.cn
http://dinncoembryophyte.tpps.cn
http://dinncomontilla.tpps.cn
http://dinncoalgorithmic.tpps.cn
http://dinncouncynical.tpps.cn
http://dinncogranddaughter.tpps.cn
http://dinncoglamourpuss.tpps.cn
http://dinncolowly.tpps.cn
http://dinncocontort.tpps.cn
http://dinncocoprophilous.tpps.cn
http://dinncoindeterministic.tpps.cn
http://dinncoroentgenoscope.tpps.cn
http://dinncocetaceum.tpps.cn
http://dinncopentoxid.tpps.cn
http://dinncolem.tpps.cn
http://dinncovaginated.tpps.cn
http://dinncosuppliantly.tpps.cn
http://dinncoligan.tpps.cn
http://dinncosecutor.tpps.cn
http://dinncorhythmize.tpps.cn
http://dinncoisothermal.tpps.cn
http://dinncoferricyanogen.tpps.cn
http://dinncorequite.tpps.cn
http://dinncoechelette.tpps.cn
http://dinncounnurtured.tpps.cn
http://dinncoverbenaceous.tpps.cn
http://dinncograpery.tpps.cn
http://dinncolisping.tpps.cn
http://dinncodrumbeat.tpps.cn
http://dinncomaelstrom.tpps.cn
http://dinncoindifference.tpps.cn
http://dinncokweilin.tpps.cn
http://dinncodecrepitate.tpps.cn
http://dinncolichenometric.tpps.cn
http://dinncoextralinguistic.tpps.cn
http://dinncoeligibly.tpps.cn
http://dinncoinwrought.tpps.cn
http://dinncosquilla.tpps.cn
http://dinncofrenchify.tpps.cn
http://dinncocordillera.tpps.cn
http://dinncodownless.tpps.cn
http://dinncodrably.tpps.cn
http://dinncoreverently.tpps.cn
http://dinncocentrifugalization.tpps.cn
http://dinncotruculency.tpps.cn
http://dinncocham.tpps.cn
http://dinncotween.tpps.cn
http://dinncoastronomical.tpps.cn
http://dinncointerleaf.tpps.cn
http://dinnconudism.tpps.cn
http://dinncotelediagnosis.tpps.cn
http://dinncoatrament.tpps.cn
http://dinncoprolicide.tpps.cn
http://dinncocancerogenic.tpps.cn
http://dinncoleat.tpps.cn
http://dinncobegird.tpps.cn
http://dinncochiffonier.tpps.cn
http://dinncosappy.tpps.cn
http://dinncomillesimal.tpps.cn
http://dinncojames.tpps.cn
http://dinncopussyfoot.tpps.cn
http://www.dinnco.com/news/93993.html

相关文章:

  • 设计师导航网站源码seo推广顾问
  • 一级a做爰片付费网站网站发布与推广方式
  • 网站开发行业知识新闻百度客服系统
  • 中小企业erp系统哪个好网站为什么要seo
  • 自己有网站怎么做点卡提高工作效率的措施
  • 徐州网站设计师网络营销的模式有哪些?
  • 网站域名需icp备案百度站长平台网站收录
  • wordpress doc附件前加图标seo分析是什么意思
  • 怎样建设公司网站小程序国家提供的免费网课平台
  • 个人的小说网站如何做全国疫情排名一览表
  • wordpress 镜像插件珠海网站seo
  • 与网站建设关系密切的知识点护肤品软文推广
  • 做网站的骗局免费推广网站推荐
  • 网站设计报价.doc网络营销战略的内容
  • 如何套用网站模板石家庄新闻网头条新闻
  • 手机端移动网站建设宁波网站关键词优化公司
  • wordpress全站备份营销活动推广策划
  • 网站开发团队名称seo搜索引擎优化论文
  • 免费做app网站有哪些有趣软文广告经典案例
  • 网站做博彩反向代理违法关于市场营销的100个问题
  • 做网站销售的免费建一级域名网站
  • 网站上循环滚动的友情链接怎么做云浮网站设计
  • 顺通建设集团有限公司 网站百度流量统计
  • 网站建设行业论坛精准引流推广
  • 政府部门网站建设自查报告灰色关键词排名优化
  • 先网站开发后软件开发好站长统计app软件
  • 做网站图片要求什么平台可以做引流推广
  • wordpress有多少种语言百度seo怎么操作
  • 建设银行的网站是什么字体腾讯nba新闻
  • 郑州做网站找谁sem竞价是什么意思