目录

官方解析

博主例子


官方解析

个人觉得这官方教程给得是相当的好,因为功能非常的强大,在此记录下,方便以后使用,以后肯定会经常用到!

此节将会学到从GeoJson对象中创建且调用map vectors。

GeoJson对象如下:

var geojsonFeature = {"type": "Feature","properties": {"name": "Coors Field","amenity": "Baseball Stadium","popupContent": "This is where the Rockies play!"},"geometry": {"type": "Point","coordinates": [-104.99404, 39.75621]}
};

可以通过下面这两种方式在地图上添加geojson

L.geoJSON(geojsonFeature).addTo(map);

或者

var myLayer = L.geoJSON().addTo(map);
myLayer.addData(geojsonFeature);

两种方式设置其风格

var myLines = [{"type": "LineString","coordinates": [[-100, 40], [-105, 45], [-110, 55]]
}, {"type": "LineString","coordinates": [[-105, 40], [-110, 45], [-115, 55]]
}];var myStyle = {"color": "#ff7800","weight": 5,"opacity": 0.65
};L.geoJSON(myLines, {style: myStyle
}).addTo(map);

var states = [{"type": "Feature","properties": {"party": "Republican"},"geometry": {"type": "Polygon","coordinates": [[[-104.05, 48.99],[-97.22,  48.98],[-96.58,  45.94],[-104.03, 45.94],[-104.05, 48.99]]]}
}, {"type": "Feature","properties": {"party": "Democrat"},"geometry": {"type": "Polygon","coordinates": [[[-109.05, 41.00],[-102.06, 40.99],[-102.03, 36.99],[-109.04, 36.99],[-109.05, 41.00]]]}
}];L.geoJSON(states, {style: function(feature) {switch (feature.properties.party) {case 'Republican': return {color: "#ff0000"};case 'Democrat':   return {color: "#0000ff"};}}
}).addTo(map);

在地图上画一个点

var geojsonMarkerOptions = {radius: 8,fillColor: "#ff7800",color: "#000",weight: 1,opacity: 1,fillOpacity: 0.8
};L.geoJSON(someGeojsonFeature, {pointToLayer: function (feature, latlng) {return L.circleMarker(latlng, geojsonMarkerOptions);}
}).addTo(map);

当选点击点后,弹出某窗口

function onEachFeature(feature, layer) {// does this feature have a property named popupContent?if (feature.properties && feature.properties.popupContent) {layer.bindPopup(feature.properties.popupContent);}
}var geojsonFeature = {"type": "Feature","properties": {"name": "Coors Field","amenity": "Baseball Stadium","popupContent": "This is where the Rockies play!"},"geometry": {"type": "Point","coordinates": [-104.99404, 39.75621]}
};L.geoJSON(geojsonFeature, {onEachFeature: onEachFeature
}).addTo(map);

过滤

map中不显示"Busch Field"

var someFeatures = [{"type": "Feature","properties": {"name": "Coors Field","show_on_map": true},"geometry": {"type": "Point","coordinates": [-104.99404, 39.75621]}
}, {"type": "Feature","properties": {"name": "Busch Field","show_on_map": false},"geometry": {"type": "Point","coordinates": [-104.98404, 39.74621]}
}];L.geoJSON(someFeatures, {filter: function(feature, layer) {return feature.properties.show_on_map;}
}).addTo(map);

博主例子

这里举个例子,GIS为自己本地搭建的。

把南京和合肥圈了出来,如下图所示:

当点击某个圆后

代码如下:

test5.html

<!DOCTYPE html>
<html>
<head><title>Hello Test5</title><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" /><link rel="stylesheet" href="leaflet.css" /><script src="leaflet.js"></script>        <script src="leaflet-tilelayer-wmts-src.js"></script><script src="echarts.js"></script><style>html, body {height: 100%;margin: 0;}#map {width: 100%;height: 100%;}.chart{width: 600px;height: 300px;background-color: #fff;}</style></head>
<body>
<script src="geojson.js" type="text/javascript"></script>
<div id='map'></div><script type="text/javascript">var ign = new L.TileLayer.WMTS( "http://XXX.XXX.XXX.XXX:8080/geoserver/gwc/service/wmts" ,{layer: 'GG_9:gg_9',tilematrixset: "EPSG:900913",Format : 'image/png',TileMatrix: 'EPSG:900913:8'});var map = L.map('map', {minZoom: 5,maxZoom: 7}).setView([32, 118], 7);L.control.scale({'position':'bottomleft','metric':true,'imperial':false}).addTo(map);map.addLayer(ign);map.invalidateSize(true);function onEachFeature(feature, layer) {var popupContent = "弹出窗口,此城市为:" + feature.geometry.properties.popupContent;layer.bindPopup(popupContent);}//新加的代码L.geoJSON([bicycleRental], {onEachFeature: onEachFeature,pointToLayer: function (feature, latlng) {return L.circleMarker(latlng, {radius: 8,fillColor: "#ff7800",color: "#000",weight: 1,opacity: 1,fillOpacity: 0.8});}}).addTo(map);//新加的代码</script></body>
</html>

geojson.js

var bicycleRental = {"type" : "FeatureConllection","features" : [{"geometry" : {"type" : "Point","coordinates" : [118.8, 32.05],"properties": {"popupContent" : "南京"}},"type" : "Feature","id" : 100},{"geometry" : {"type" : "Point","coordinates" : [117.242, 31.8],"properties": {"popupContent" : "合肥"}},"type" : "Feature","id" : 101}]
};

这里要注意一点!

此处的经纬度是反过来的!!!!!

Leaflet文档阅读笔记-Using GeoJSON with Leaflet笔记相关推荐

  1. Leaflet文档阅读笔记-Quick Start Guide笔记

    目录 网络加载JS和CSS 初始化地图 在地图上做标记 在地图上点击事件获得坐标 个人对这篇文档的体会 网络加载JS和CSS 先要加载css,然后在加载js <link rel="st ...

  2. Leaflet文档阅读笔记- Showing video files解析

    目录 官方解析 博主例子 官方解析 这里,官方首先告诉我们,当<video>这个标签还没出现的时候,在web上展示视频是很艰巨的.现在有了这个标签,只需要如下代码就能在web页面上展示视频 ...

  3. Leaflet文档阅读笔记-Extending Leaflet: Handlers and Controls笔记

    目录 官方解析 博主栗子 官方解析 Leaflet 1.0中出现了处理者这个新概念,处理浏览器里的dom事件单击,双击,地图滑动及map状态的改变. 当处理者启动时调用addHooks()函数,未启动 ...

  4. Leaflet文档阅读笔记-Zoom levels笔记

    目录 官方解析 博主例子 官方解析 把地图放缩锁定到0级 var map = L.map('map', {minZoom: 0,maxZoom: 0 });var cartodbAttribution ...

  5. Leaflet文档阅读笔记-Markers With Custom Icons笔记

    目录 官方解析 博主例子 官方解析 这个内容主要是把自定义图片,放到地图上,并且还可以增加阴影图片,以及点击图片后的弹出事件. 官方是准备了下面这4张图片: 使用下面这种方式可以单独设置,自定义图标 ...

  6. Leaflet文档阅读笔记-Leaflet on Mobile笔记

    目录 CSS和HTML改如何设置 定位功能 CSS和HTML改如何设置 如下的设置: body {padding: 0;margin: 0; } html, body, #map {height: 1 ...

  7. Qt文档阅读笔记-共享库的创建与调用

    使用共享库的符号 这个符号可以作用在变量.类.函数中,并且这些都可以被调用端使用. 在编译共享库中,需要使用export符号.在使用端调用的时候使用import符号. 这里是本人从文档中记录的笔记,大 ...

  8. Qt文档阅读笔记-加载HeightMap(高度图)构造3D地形图

    Qt文档阅读笔记-加载HeightMap(高度图)构造3D地形图 QHeightMapSurfaceDataProxy:是Q3DSurface的一个基本代理类. 他是专门加载高度图. 高度图是没有X, ...

  9. Qt文档阅读笔记-Rotations Example相关

    Rotations Example文档阅读笔记 使用这种方式,对y轴和z轴进行旋转. QQuaternion yRotation = QQuaternion::fromAxisAndAngle(0.0 ...

最新文章

  1. window.open打开新窗口不改变原窗口_我P的图不高级,就很可耻吗?
  2. 优秀的开源项目C_适合提高C/C++、网络编程能力的开源项目!不要错过,赶紧收藏...
  3. 周志华任大会首个华人程序主席!
  4. VB讲课笔记14:二级VB知识点总结
  5. windows程序窗体创建流程模型A--发送自定义消息逻辑上出现Bug
  6. 核心动画——CAAnimation
  7. JavaScript编码风格指南(中文版)
  8. 15 个提高 Google 搜索效率的小技巧
  9. 简单循迹小车实验心得_智能小车实验报告
  10. 教学演示软件 模型八 医学的人体模型
  11. intel DQ77KB 主板使用说明书
  12. 从零开始学习网络数据包分析:科来抓包的入门教程
  13. Java石头剪刀布(简单小游戏)
  14. 八成互联网电视系统非法采集用户数据;前亚马逊工程师被定罪;雅虎将在香港测试元宇宙技术 | 每日大事件...
  15. 用原生 Audio API 实现一个千千静听
  16. 沪江快速手机打字破解版
  17. for循环倒序java_for循环
  18. 【云计算】Vmware SDDC 架构
  19. 5个设计师都在用的在线网页设计编辑器!
  20. 计算机资格怎么报名,专家带您了解计算机技术资格报名步骤

热门文章

  1. UNIX网络编程——进程间通信概述
  2. 连数据都读不懂,你凭什么说会数据分析?
  3. 这10种创意图表,能让可视化报告瞬间变得惊艳炫酷,5分钟学会
  4. 一招彻底破除数据孤岛!这家企业用数据集市整合了30套系统
  5. 实用、酷炫的可视化,你用10小时,同事用10分钟,差距在哪?
  6. 职场老油条靠它升职后:还用Excel手动做报表?想想就可笑
  7. NX(UGS)技术关于我和你顶着忽移不定的云彩
  8. 程序员应学习蜡笔小新的心态
  9. 【再来一套网站程序】kfguan网整站程序下载
  10. 第一句就是定义了一种ptrfun的C++类型