正在显示
8 个修改的文件
包含
517 行增加
和
2 行删除
data/0.pbf
0 → 100644
不能预览此文件类型
data/1.pbf
0 → 100644
data/16.pbf
0 → 100644
不能预览此文件类型
data/17.pbf
0 → 100644
dist/leaflet-echarts4.js
0 → 100644
| 1 | +//LeafletEcharts Created by HuangTao. | |
| 2 | +(function(root, factory) { | |
| 3 | + if (typeof define === 'function' && define.amd) { | |
| 4 | + // AMD. Register as an anonymous module. | |
| 5 | + define(['leaflet'], factory); | |
| 6 | + } else if (typeof module === 'object' && module.exports) { | |
| 7 | + // Node. Does not work with strict CommonJS, but | |
| 8 | + // only CommonJS-like environments that support module.exports, | |
| 9 | + // like Node. | |
| 10 | + module.exports = factory(require('leaflet'), require('echarts')); | |
| 11 | + } else if (typeof root !== 'undefined' && root.L && root.echarts) { | |
| 12 | + // Browser globals (root is window) | |
| 13 | + LeafletEcharts = factory(L, echarts); | |
| 14 | + } | |
| 15 | + }(this, function(L, echarts) { | |
| 16 | + var LeafletMap; //Leaflet Map | |
| 17 | + var EchartInstance; //Echart Instance | |
| 18 | + var maps = {}; | |
| 19 | + var MAP_ATTRIBUTE_KEY = '_lmap_'; | |
| 20 | + var mapidBase = new Date() - 0; | |
| 21 | + | |
| 22 | + //define LMapModel | |
| 23 | + var LMapModel = echarts.extendComponentModel({ | |
| 24 | + type: 'lmap', | |
| 25 | + | |
| 26 | + getLMap : function() { | |
| 27 | + return this.__lmap; | |
| 28 | + }, | |
| 29 | + | |
| 30 | + | |
| 31 | + defaultOption: { | |
| 32 | + mapOptions : { | |
| 33 | + center: [37.550339,104.114129], | |
| 34 | + zoom: 5 | |
| 35 | + } | |
| 36 | + } | |
| 37 | + }); | |
| 38 | + | |
| 39 | + //define LMapView | |
| 40 | + var LMapView = echarts.extendComponentView({ | |
| 41 | + type: 'lmap', | |
| 42 | + | |
| 43 | + render: function (lMapModel, ecModel, api) { | |
| 44 | + } | |
| 45 | + }); | |
| 46 | + | |
| 47 | + //define EchartLayer | |
| 48 | + L.EchartLayer = L.Class.extend({ | |
| 49 | + includes: [L.Evented.prototype], | |
| 50 | + _echartsContainer:null, | |
| 51 | + _map:null, | |
| 52 | + _api:null, | |
| 53 | + _ecModel:null, | |
| 54 | + _resizing:false, | |
| 55 | + | |
| 56 | + initialize:function(api, root) { | |
| 57 | + this._api = api; | |
| 58 | + this._echartsContainer= root ? root: api.getDom(); | |
| 59 | + }, | |
| 60 | + | |
| 61 | + getMap: function() { | |
| 62 | + return this._map; | |
| 63 | + }, | |
| 64 | + | |
| 65 | + getOverLayer : function() { | |
| 66 | + return this.__overlayer; | |
| 67 | + }, | |
| 68 | + _layerAdd: function (t) { | |
| 69 | + var i = t.target; | |
| 70 | + if (i.hasLayer(this)) { | |
| 71 | + if (this._map = i, | |
| 72 | + this._zoomAnimated = i._zoomAnimated, | |
| 73 | + this.getEvents) { | |
| 74 | + var e = this.getEvents(); | |
| 75 | + i.on(e, this), | |
| 76 | + this.once("remove", function () { | |
| 77 | + i.off(e, this) | |
| 78 | + }, this) | |
| 79 | + } | |
| 80 | + this.onAdd(i), | |
| 81 | + this.getAttribution && i.attributionControl && i.attributionControl.addAttribution(this.getAttribution()), | |
| 82 | + this.fire("add"), | |
| 83 | + i.fire("layeradd", { | |
| 84 | + layer: this | |
| 85 | + }) | |
| 86 | + } | |
| 87 | + }, | |
| 88 | + setModel: function(ecModel) { | |
| 89 | + this._ecModel = ecModel; | |
| 90 | + }, | |
| 91 | + addTo: function (map) { | |
| 92 | + this.onAdd(map); | |
| 93 | + }, | |
| 94 | + onAdd: function (map) { | |
| 95 | + this._map = map; | |
| 96 | + var size = map.getSize(); | |
| 97 | + | |
| 98 | + map.getPanes().overlayPane.appendChild(this._echartsContainer); | |
| 99 | + | |
| 100 | + map.on('moveend', this._moveend, this); | |
| 101 | + map.on('resize', this._resize, this); | |
| 102 | + }, | |
| 103 | + | |
| 104 | + _resize:function() { | |
| 105 | + var domPosition = this._map._getMapPanePos(); | |
| 106 | + this._mapOffset = [-parseInt(domPosition.x) || 0, -parseInt(domPosition.y) || 0]; | |
| 107 | + this._echartsContainer.style.left = this._mapOffset[0] + 'px'; | |
| 108 | + this._echartsContainer.style.top = this._mapOffset[1] + 'px'; | |
| 109 | + var size = this._map.getSize(); | |
| 110 | + this._echartsContainer.style.height = size.y + 'px'; | |
| 111 | + this._echartsContainer.style.width = size.x + 'px'; | |
| 112 | + //resize over will moveend; | |
| 113 | + this._resizing=true; | |
| 114 | + }, | |
| 115 | + | |
| 116 | + | |
| 117 | + _moveend : function() { | |
| 118 | + var domPosition = this._map._getMapPanePos(); | |
| 119 | + this._mapOffset = [-parseInt(domPosition.x) || 0, -parseInt(domPosition.y) || 0]; | |
| 120 | + this._echartsContainer.style.left = this._mapOffset[0] + 'px'; | |
| 121 | + this._echartsContainer.style.top = this._mapOffset[1] + 'px'; | |
| 122 | + if (this._resizing == true) | |
| 123 | + { | |
| 124 | + this._resizing = false; | |
| 125 | + var ec = echarts.getInstanceByDom(this._api.getDom()); | |
| 126 | + ec.resize(); | |
| 127 | + } else { | |
| 128 | + this._api.dispatchAction({ | |
| 129 | + type: 'mapMoveEnd' | |
| 130 | + }); | |
| 131 | + } | |
| 132 | + }, | |
| 133 | + | |
| 134 | + onRemove: function (map) { | |
| 135 | + // remove layer's DOM elements and listeners | |
| 136 | + map.getPanes().overlayPane.removeChild(this._root); | |
| 137 | + map.off('viewreset', this._viewreset, this); | |
| 138 | + map.off('resize', this._resize, this); | |
| 139 | + } | |
| 140 | + | |
| 141 | + }); | |
| 142 | + | |
| 143 | + | |
| 144 | + function LMapCoordSys(lmap, api) { | |
| 145 | + this._lmap = lmap; | |
| 146 | + this.dimensions = ['lng', 'lat']; | |
| 147 | + this._mapOffset = [0, 0]; | |
| 148 | + | |
| 149 | + this._api = api; | |
| 150 | + } | |
| 151 | + | |
| 152 | + LMapCoordSys.prototype.dimensions = ['lng', 'lat']; | |
| 153 | + | |
| 154 | + LMapCoordSys.prototype.setMapOffset = function (mapOffset) { | |
| 155 | + this._mapOffset = mapOffset; | |
| 156 | + }; | |
| 157 | + | |
| 158 | + LMapCoordSys.prototype.getLMap = function () { | |
| 159 | + return this._lmap; | |
| 160 | + }; | |
| 161 | + | |
| 162 | + LMapCoordSys.prototype.dataToPoint = function (data) { | |
| 163 | + var point = new L.latLng(data[1], data[0]); | |
| 164 | + // TODO pointToOverlayPixel is toooooooo slow, cache the transform | |
| 165 | + var px = this._lmap.latLngToContainerPoint(point); | |
| 166 | + var mapOffset = this._mapOffset; | |
| 167 | + return [px.x - mapOffset[0], px.y - mapOffset[1]]; | |
| 168 | + }; | |
| 169 | + | |
| 170 | + LMapCoordSys.prototype.pointToData = function (pt) { | |
| 171 | + var mapOffset = this._mapOffset; | |
| 172 | + var pt = this._lmap.containerPointToLatLng({ | |
| 173 | + x: pt[0] + mapOffset[0], | |
| 174 | + y: pt[1] + mapOffset[1] | |
| 175 | + }); | |
| 176 | + return [pt.lat, pt.lng]; | |
| 177 | + }; | |
| 178 | + | |
| 179 | + LMapCoordSys.prototype.getViewRect = function () { | |
| 180 | + var api = this._api; | |
| 181 | + return new echarts.graphic.BoundingRect(0, 0, api.getWidth(), api.getHeight()); | |
| 182 | + }; | |
| 183 | + | |
| 184 | + LMapCoordSys.prototype.getRoamTransform = function () { | |
| 185 | + return echarts.matrix.create(); | |
| 186 | + }; | |
| 187 | + | |
| 188 | + // For deciding which dimensions to use when creating list data | |
| 189 | + LMapCoordSys.dimensions = LMapCoordSys.prototype.dimensions; | |
| 190 | + | |
| 191 | + LMapCoordSys.create = function (ecModel, api) { | |
| 192 | + var lmapCoordSys; | |
| 193 | + | |
| 194 | + ecModel.eachComponent('lmap', function (lmapModel) { | |
| 195 | + if (lmapCoordSys) { | |
| 196 | + throw new Error('Only one lmap component can exist'); | |
| 197 | + } | |
| 198 | + | |
| 199 | + var root = api.getDom(); | |
| 200 | + var key = root.getAttribute(MAP_ATTRIBUTE_KEY); | |
| 201 | + var viewportRoot; | |
| 202 | + | |
| 203 | + if (!key) { | |
| 204 | + | |
| 205 | + viewportRoot = api.getZr().painter.getViewportRoot(); | |
| 206 | + if (typeof L === 'undefined') { | |
| 207 | + throw new Error('LMap api is not loaded'); | |
| 208 | + } | |
| 209 | + | |
| 210 | + // Not support IE8 | |
| 211 | + var lmapRoot = root.querySelector('.ec-extension-lmap'); | |
| 212 | + if (lmapRoot) { | |
| 213 | + // Reset viewport left and top, which will be changed | |
| 214 | + // in moving handler in BMapView | |
| 215 | + viewportRoot.style.left = '0px'; | |
| 216 | + viewportRoot.style.top = '0px'; | |
| 217 | + root.removeChild(lmapRoot); | |
| 218 | + } | |
| 219 | + lmapRoot = document.createElement('div'); | |
| 220 | + lmapRoot.style.cssText = 'width:100%;height:100%'; | |
| 221 | + // Not support IE8 | |
| 222 | + lmapRoot.classList.add('ec-extension-lmap'); | |
| 223 | + root.appendChild(lmapRoot); | |
| 224 | + var opts = lmapModel.get('mapOptions'); | |
| 225 | + if (typeof opts == "function") | |
| 226 | + opts = opts(); | |
| 227 | + var lmap = lmapModel.__lmap = new L.map(lmapRoot, opts); | |
| 228 | + | |
| 229 | + var mapid = 'map_' + mapidBase++; | |
| 230 | + maps[mapid] = lmap; | |
| 231 | + root.setAttribute && root.setAttribute(MAP_ATTRIBUTE_KEY, mapid); | |
| 232 | + } else { | |
| 233 | + lmapModel.__lmap = maps[key]; | |
| 234 | + } | |
| 235 | + | |
| 236 | + | |
| 237 | + if (!lmapModel.__overlayer) | |
| 238 | + { | |
| 239 | + var overlayer = lmapModel.__overlayer = new L.EchartLayer(api, viewportRoot); | |
| 240 | + lmapModel.__lmap.addLayer(overlayer); | |
| 241 | + lmapModel.__overlayer.setModel(lmapModel); | |
| 242 | + } | |
| 243 | + | |
| 244 | + lmapCoordSys = new LMapCoordSys(lmapModel.__lmap, api); | |
| 245 | + lmapCoordSys.setMapOffset(lmapModel.__mapOffset || [0, 0]); | |
| 246 | + lmapModel.coordinateSystem = lmapCoordSys; | |
| 247 | + }); | |
| 248 | + | |
| 249 | + ecModel.eachComponent('geo', function (geoModel) { | |
| 250 | + var root = api.getDom(); | |
| 251 | + var key = root.getAttribute(MAP_ATTRIBUTE_KEY); | |
| 252 | + if (!key) | |
| 253 | + throw new Error('Must Init LeafletMap First!'); | |
| 254 | + | |
| 255 | + var leafletMap = geoModel.__lmap = maps[key]; | |
| 256 | + if (!lmapCoordSys) { | |
| 257 | + lmapCoordSys = new LMapCoordSys(leafletMap, api); | |
| 258 | + lmapCoordSys.setMapOffset(geoModel.__mapOffset || [0, 0]); | |
| 259 | + } | |
| 260 | + | |
| 261 | + if (!geoModel.__overlayer) | |
| 262 | + { | |
| 263 | + var overlayer = geoModel.__overlayer = new L.EchartLayer(api); | |
| 264 | + leafletMap.addLayer(overlayer); | |
| 265 | + overlayer.setModel(geoModel); | |
| 266 | + } | |
| 267 | + }); | |
| 268 | + | |
| 269 | + ecModel.eachSeries(function (seriesModel) { | |
| 270 | + var coordSys = seriesModel.get('coordinateSystem'); | |
| 271 | + //series Lines only support geo coordSys; | |
| 272 | + if (coordSys === 'geo' || coordSys === 'lmap') { | |
| 273 | + seriesModel.coordinateSystem = lmapCoordSys; | |
| 274 | + } | |
| 275 | + }); | |
| 276 | + | |
| 277 | + }; | |
| 278 | + | |
| 279 | + //register lmap coordinateSystem | |
| 280 | + echarts.registerCoordinateSystem( | |
| 281 | + 'lmap', LMapCoordSys | |
| 282 | + ); | |
| 283 | + | |
| 284 | + //register map moveend Action to UpdateLayout | |
| 285 | + echarts.registerAction({ | |
| 286 | + type: 'mapMoveEnd', | |
| 287 | + event: 'mapMoveEnd', | |
| 288 | + update: 'updateLayout' | |
| 289 | + }, function (payload, ecModel) { | |
| 290 | + ecModel.eachComponent('lmap', function (lmapModel) { | |
| 291 | + }); | |
| 292 | + }); | |
| 293 | + | |
| 294 | + function LEResult(ec, dom, map) | |
| 295 | + { | |
| 296 | + this._ec = ec; | |
| 297 | + this._dom = dom; | |
| 298 | + this._map = map; | |
| 299 | + } | |
| 300 | + | |
| 301 | + LEResult.prototype.getMap = function() { | |
| 302 | + if (this._map) | |
| 303 | + return this._map; | |
| 304 | + var mapid = this._dom.getAttribute(MAP_ATTRIBUTE_KEY); | |
| 305 | + return maps[mapid]; | |
| 306 | + } | |
| 307 | + | |
| 308 | + LEResult.prototype.getEcharts = function() { | |
| 309 | + return this._ec; | |
| 310 | + } | |
| 311 | + | |
| 312 | + LEResult.prototype.getEchartLayer = function() { | |
| 313 | + var ec = this.getEcharts(); | |
| 314 | + var mapModel = ec.getModel().getComponent('lmap'); | |
| 315 | + if (!mapModel) | |
| 316 | + mapModel = ec.getModel().getComponent('geo'); | |
| 317 | + return mapModel.__overlayer; | |
| 318 | + } | |
| 319 | + | |
| 320 | + LEResult.prototype.setOption = function(option, notMerge, lazyUpdate) { | |
| 321 | + this._ec.setOption(option,notMerge, lazyUpdate); | |
| 322 | + } | |
| 323 | + | |
| 324 | + /* | |
| 325 | + L.LeafletEcharts = L.Class.extend({ | |
| 326 | + //init leaflet map, return map | |
| 327 | + initMap : function(id, options) { | |
| 328 | + this.map = LeafletMap = L.map(id, options); | |
| 329 | + var mapid = 'map_' + mapidBase++; | |
| 330 | + maps[mapid] = this.map; | |
| 331 | + var div = this.echartDom = document.createElement('div'); | |
| 332 | + var size = this.map.getSize(); | |
| 333 | + div.style.position = "absolute"; | |
| 334 | + div.style.height = size.y + 'px'; | |
| 335 | + div.style.width = size.x + 'px'; | |
| 336 | + div.style.top = 0; | |
| 337 | + div.style.left = 0; | |
| 338 | + var ec = EchartInstance = echarts.init(div); | |
| 339 | + div.setAttribute && div.setAttribute(MAP_ATTRIBUTE_KEY, mapid); | |
| 340 | + return this.map; | |
| 341 | + }, | |
| 342 | + //get echart instance | |
| 343 | + getEcharts:function() { | |
| 344 | + if (this.echartDom) | |
| 345 | + return echarts.getInstanceByDom(this.echartDom); //EchartInstance; | |
| 346 | + else | |
| 347 | + return null; | |
| 348 | + }, | |
| 349 | + //get leaflet Layer for echart | |
| 350 | + getEchartLayer:function() { | |
| 351 | + var ec = this.getEcharts(); | |
| 352 | + var mapModel = ec.getModel().getComponent('lmap'); | |
| 353 | + if (!mapModel) | |
| 354 | + mapModel = ec.getModel().getComponent('geo'); | |
| 355 | + return mapModel.__overlayer; | |
| 356 | + }, | |
| 357 | + getLMap:function() { | |
| 358 | + if (this.map) | |
| 359 | + return this.map; | |
| 360 | + var mapid = this.echartDom.getAttribute(MAP_ATTRIBUTE_KEY); | |
| 361 | + return maps[mapid]; | |
| 362 | + }, | |
| 363 | + initEcharts:function(dom) { | |
| 364 | + this.echartDom = dom; | |
| 365 | + var ec = EchartInstance = echarts.init(dom); | |
| 366 | + return ec; | |
| 367 | + } | |
| 368 | + }); */ | |
| 369 | + return { | |
| 370 | + initMap : function(id, options) { | |
| 371 | + var map = L.map(id, options); | |
| 372 | + var mapid = 'map_' + mapidBase++; | |
| 373 | + maps[mapid] = map; | |
| 374 | + var div = document.createElement('div'); | |
| 375 | + var size = map.getSize(); | |
| 376 | + div.style.position = "absolute"; | |
| 377 | + div.style.height = size.y + 'px'; | |
| 378 | + div.style.width = size.x + 'px'; | |
| 379 | + div.style.top = 0; | |
| 380 | + div.style.left = 0; | |
| 381 | + var ec = echarts.init(div); | |
| 382 | + div.setAttribute && div.setAttribute(MAP_ATTRIBUTE_KEY, mapid); | |
| 383 | + return new LEResult(ec, div, map); | |
| 384 | + }, | |
| 385 | + initEcharts:function(dom) { | |
| 386 | + var ec = echarts.init(dom); | |
| 387 | + return new LEResult(ec, dom); | |
| 388 | + }, | |
| 389 | + version: "2.0.0" | |
| 390 | + }; | |
| 391 | + | |
| 392 | +})); | |
| \ No newline at end of file | ... | ... |
dist/leaflet-echarts4.min.js
0 → 100644
| 1 | +!function(t,e){"function"==typeof define&&define.amd?define(["leaflet"],e):"object"==typeof module&&module.exports?module.exports=e(require("leaflet"),require("echarts")):"undefined"!=typeof t&&t.L&&t.echarts&&(LeafletEcharts=e(L,echarts))}(this,function(t,e){function i(t,e){this._lmap=t,this.dimensions=["lng","lat"],this._mapOffset=[0,0],this._api=e}function n(t,e,i){this._ec=t,this._dom=e,this._map=i}var o={},a="_lmap_",r=new Date-0;e.extendComponentModel({type:"lmap",getLMap:function(){return this.__lmap},defaultOption:{mapOptions:{center:[37.550339,104.114129],zoom:5}}}),e.extendComponentView({type:"lmap",render:function(t,e,i){}});return t.EchartLayer=t.Class.extend({includes:[t.Evented.prototype],_echartsContainer:null,_map:null,_api:null,_ecModel:null,_resizing:!1,initialize:function(t,e){this._api=t,this._echartsContainer=e?e:t.getDom()},getMap:function(){return this._map},getOverLayer:function(){return this.__overlayer},_layerAdd:function(t){var e=t.target;if(e.hasLayer(this)){if(this._map=e,this._zoomAnimated=e._zoomAnimated,this.getEvents){var i=this.getEvents();e.on(i,this),this.once("remove",function(){e.off(i,this)},this)}this.onAdd(e),this.getAttribution&&e.attributionControl&&e.attributionControl.addAttribution(this.getAttribution()),this.fire("add"),e.fire("layeradd",{layer:this})}},setModel:function(t){this._ecModel=t},addTo:function(t){this.onAdd(t)},onAdd:function(t){this._map=t;t.getSize();t.getPanes().overlayPane.appendChild(this._echartsContainer),t.on("moveend",this._moveend,this),t.on("resize",this._resize,this)},_resize:function(){var t=this._map._getMapPanePos();this._mapOffset=[-parseInt(t.x)||0,-parseInt(t.y)||0],this._echartsContainer.style.left=this._mapOffset[0]+"px",this._echartsContainer.style.top=this._mapOffset[1]+"px";var e=this._map.getSize();this._echartsContainer.style.height=e.y+"px",this._echartsContainer.style.width=e.x+"px",this._resizing=!0},_moveend:function(){var t=this._map._getMapPanePos();if(this._mapOffset=[-parseInt(t.x)||0,-parseInt(t.y)||0],this._echartsContainer.style.left=this._mapOffset[0]+"px",this._echartsContainer.style.top=this._mapOffset[1]+"px",1==this._resizing){this._resizing=!1;var i=e.getInstanceByDom(this._api.getDom());i.resize()}else this._api.dispatchAction({type:"mapMoveEnd"})},onRemove:function(t){t.getPanes().overlayPane.removeChild(this._root),t.off("viewreset",this._viewreset,this),t.off("resize",this._resize,this)}}),i.prototype.dimensions=["lng","lat"],i.prototype.setMapOffset=function(t){this._mapOffset=t},i.prototype.getLMap=function(){return this._lmap},i.prototype.dataToPoint=function(e){var i=new t.latLng(e[1],e[0]),n=this._lmap.latLngToContainerPoint(i),o=this._mapOffset;return[n.x-o[0],n.y-o[1]]},i.prototype.pointToData=function(t){var e=this._mapOffset,t=this._lmap.containerPointToLatLng({x:t[0]+e[0],y:t[1]+e[1]});return[t.lat,t.lng]},i.prototype.getViewRect=function(){var t=this._api;return new e.graphic.BoundingRect(0,0,t.getWidth(),t.getHeight())},i.prototype.getRoamTransform=function(){return e.matrix.create()},i.dimensions=i.prototype.dimensions,i.create=function(e,n){var s;e.eachComponent("lmap",function(e){if(s)throw new Error("Only one lmap component can exist");var p,h=n.getDom(),f=h.getAttribute(a);if(f)e.__lmap=o[f];else{if(p=n.getZr().painter.getViewportRoot(),"undefined"==typeof t)throw new Error("LMap api is not loaded");var l=h.querySelector(".ec-extension-lmap");l&&(p.style.left="0px",p.style.top="0px",h.removeChild(l)),l=document.createElement("div"),l.style.cssText="width:100%;height:100%",l.classList.add("ec-extension-lmap"),h.appendChild(l);var m=e.get("mapOptions");"function"==typeof m&&(m=m());var _=e.__lmap=new t.map(l,m),c="map_"+r++;o[c]=_,h.setAttribute&&h.setAttribute(a,c)}if(!e.__overlayer){var d=e.__overlayer=new t.EchartLayer(n,p);e.__lmap.addLayer(d),e.__overlayer.setModel(e)}s=new i(e.__lmap,n),s.setMapOffset(e.__mapOffset||[0,0]),e.coordinateSystem=s}),e.eachComponent("geo",function(e){var r=n.getDom(),p=r.getAttribute(a);if(!p)throw new Error("Must Init LeafletMap First!");var h=e.__lmap=o[p];if(s||(s=new i(h,n),s.setMapOffset(e.__mapOffset||[0,0])),!e.__overlayer){var f=e.__overlayer=new t.EchartLayer(n);h.addLayer(f),f.setModel(e)}}),e.eachSeries(function(t){var e=t.get("coordinateSystem");"geo"!==e&&"lmap"!==e||(t.coordinateSystem=s)})},e.registerCoordinateSystem("lmap",i),e.registerAction({type:"mapMoveEnd",event:"mapMoveEnd",update:"updateLayout"},function(t,e){e.eachComponent("lmap",function(t){})}),n.prototype.getMap=function(){if(this._map)return this._map;var t=this._dom.getAttribute(a);return o[t]},n.prototype.getEcharts=function(){return this._ec},n.prototype.getEchartLayer=function(){var t=this.getEcharts(),e=t.getModel().getComponent("lmap");return e||(e=t.getModel().getComponent("geo")),e.__overlayer},n.prototype.setOption=function(t,e,i){this._ec.setOption(t,e,i)},{initMap:function(i,s){var p=t.map(i,s),h="map_"+r++;o[h]=p;var f=document.createElement("div"),l=p.getSize();f.style.position="absolute",f.style.height=l.y+"px",f.style.width=l.x+"px",f.style.top=0,f.style.left=0;var m=e.init(f);return f.setAttribute&&f.setAttribute(a,h),new n(m,f,p)},initEcharts:function(t){var i=e.init(t);return new n(i,t)},version:"2.0.0"}}); | |
| \ No newline at end of file | ... | ... |
examples/basic.html
0 → 100644
| 1 | +<html> | |
| 2 | +<head> | |
| 3 | + <title>Basic</title> | |
| 4 | + <meta charset="utf-8"> | |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| 6 | + <link rel="stylesheet" href="../libs/leaflet/dist/leaflet.css"/> | |
| 7 | + <style> | |
| 8 | + #map { | |
| 9 | + position: absolute; | |
| 10 | + top: 0; | |
| 11 | + bottom: 0; | |
| 12 | + width: 100%; | |
| 13 | + } | |
| 14 | + </style> | |
| 15 | +</head> | |
| 16 | +<body> | |
| 17 | +<div id="map"></div> | |
| 18 | +<script src="../libs/jquery/dist/jquery.min.js"></script> | |
| 19 | +<script src="../libs/leaflet/dist/leaflet.js"></script> | |
| 20 | + | |
| 21 | +<script src="../node_modules/pbf/dist/pbf.js"></script> | |
| 22 | +<script src="../src/point-geometry.js"></script> | |
| 23 | + | |
| 24 | +<script src="../src/vectorTileFeature.js"></script> | |
| 25 | +<script src="../src/vectorTileLayer.js"></script> | |
| 26 | +<script src="../src/vector-tile.js"></script> | |
| 27 | + | |
| 28 | +<script src="../src/MVTUtil.js"></script> | |
| 29 | +<script src="../src/StaticLabel.js"></script> | |
| 30 | +<script src="../src/MVTFeature.js"></script> | |
| 31 | +<script src="../src/MVTLayer.js"></script> | |
| 32 | +<script src="../src/MVTSource.js"></script> | |
| 33 | +<script> | |
| 34 | + var debug = {}; | |
| 35 | + | |
| 36 | +var map = L.map('map').setView([0, 0], 1); // africa | |
| 37 | + | |
| 38 | +L.tileLayer('http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', { | |
| 39 | + maxZoom: 18, | |
| 40 | + id: 'examples.map-i86knfo3' | |
| 41 | +}).addTo(map); | |
| 42 | + | |
| 43 | + | |
| 44 | +var mvtSource = new L.TileLayer.MVTSource({ | |
| 45 | + //url: "http://spatialserver.spatialdev.com/services/vector-tiles/GAUL_FSP/{z}/{x}/{y}.pbf", | |
| 46 | + url: "http://172.26.60.12/osm08/{z}/{x}/{y}.pbf", | |
| 47 | + debug: false, | |
| 48 | + clickableLayers: ["GAUL0"], | |
| 49 | + getIDForLayerFeature: function(feature) { | |
| 50 | + return feature.properties.id; | |
| 51 | + }, | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * The filter function gets called when iterating though each vector tile feature (vtf). You have access | |
| 55 | + * to every property associated with a given feature (the feature, and the layer). You can also filter | |
| 56 | + * based of the context (each tile that the feature is drawn onto). | |
| 57 | + * | |
| 58 | + * Returning false skips over the feature and it is not drawn. | |
| 59 | + * | |
| 60 | + * @param feature | |
| 61 | + * @returns {boolean} | |
| 62 | + */ | |
| 63 | + filter: function(feature, context) { | |
| 64 | + if (feature.layer.name === 'water') { | |
| 65 | + return true; | |
| 66 | + } | |
| 67 | + return true; | |
| 68 | + }, | |
| 69 | + | |
| 70 | + style: function (feature) { | |
| 71 | + var style = {}; | |
| 72 | + | |
| 73 | + var type = feature.type; | |
| 74 | + switch (type) { | |
| 75 | + case 1: //'Point' | |
| 76 | + style.color = 'rgba(49,79,79,1)'; | |
| 77 | + style.radius = 5; | |
| 78 | + style.selected = { | |
| 79 | + color: 'rgba(255,255,0,0.5)', | |
| 80 | + radius: 6 | |
| 81 | + }; | |
| 82 | + break; | |
| 83 | + case 2: //'LineString' | |
| 84 | + style.color = 'rgba(161,217,155,0.8)'; | |
| 85 | + style.size = 3; | |
| 86 | + style.selected = { | |
| 87 | + color: 'rgba(255,25,0,0.5)', | |
| 88 | + size: 4 | |
| 89 | + }; | |
| 90 | + break; | |
| 91 | + case 3: //'Polygon' | |
| 92 | + style.color = fillColor; | |
| 93 | + style.outline = { | |
| 94 | + color: strokeColor, | |
| 95 | + size: 1 | |
| 96 | + }; | |
| 97 | + style.selected = { | |
| 98 | + color: 'rgba(255,140,0,0.3)', | |
| 99 | + outline: { | |
| 100 | + color: 'rgba(255,140,0,1)', | |
| 101 | + size: 2 | |
| 102 | + } | |
| 103 | + }; | |
| 104 | + break; | |
| 105 | + } | |
| 106 | + return style; | |
| 107 | + } | |
| 108 | + | |
| 109 | +}); | |
| 110 | +debug.mvtSource = mvtSource; | |
| 111 | + | |
| 112 | +//Globals that we can change later. | |
| 113 | +var fillColor = 'rgba(149,139,255,0.4)'; | |
| 114 | +var strokeColor = 'rgb(20,20,20)'; | |
| 115 | + | |
| 116 | +//Add layer | |
| 117 | +map.addLayer(mvtSource); | |
| 118 | +</script> | |
| 119 | +</body> | |
| 120 | +</html> | |
| \ No newline at end of file | ... | ... |
请
注册
或
登录
后发表评论