From f0c02453e8ef70bf48cd8df5d3193dc89eabf08e Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Tue, 21 Oct 2014 16:32:26 -0700 Subject: [PATCH 01/29] updated for leaflet 1.0 --- spec/Layers/DymanicMapLayerSpec.js | 3 ++ spec/Layers/FeatureLayer/FeatureLayerSpec.js | 8 ++-- .../Layers/FeatureLayer/FeatureManagerSpec.js | 2 +- spec/Tasks/IdentifyFeaturesSpec.js | 11 +---- spec/Tasks/QuerySpec.js | 2 +- src/EsriLeaflet.js | 2 +- src/Layers/BasemapLayer.js | 20 +--------- src/Layers/DynamicMapLayer.js | 2 +- src/Layers/FeatureLayer/FeatureGrid.js | 40 ++++++++----------- src/Layers/FeatureLayer/FeatureLayer.js | 37 +++-------------- src/Layers/FeatureLayer/FeatureManager.js | 15 ++----- src/Layers/ImageMapLayer.js | 2 +- src/Layers/RasterLayer.js | 28 +------------ src/Layers/TiledMapLayer.js | 12 +----- src/Services/Service.js | 14 +++---- src/Tasks/IdentifyImage.js | 2 + 16 files changed, 52 insertions(+), 148 deletions(-) diff --git a/spec/Layers/DymanicMapLayerSpec.js b/spec/Layers/DymanicMapLayerSpec.js index 9c0f2d74f..efe88c4b7 100644 --- a/spec/Layers/DymanicMapLayerSpec.js +++ b/spec/Layers/DymanicMapLayerSpec.js @@ -153,6 +153,9 @@ describe('L.esri.Layers.DynamicMapLayer', function () { layer.on('requeststart', requeststartSpy); layer.on('requestend', requestendSpy); + layer.on('requeststart', requeststartSpy); + layer.on('requestend', requestendSpy); + layer.metadata(function(){}); server.respond(); diff --git a/spec/Layers/FeatureLayer/FeatureLayerSpec.js b/spec/Layers/FeatureLayer/FeatureLayerSpec.js index f18017a3b..c3d10c203 100644 --- a/spec/Layers/FeatureLayer/FeatureLayerSpec.js +++ b/spec/Layers/FeatureLayer/FeatureLayerSpec.js @@ -230,12 +230,14 @@ describe('L.esri.Layers.FeatureLayer', function () { layer = L.esri.featureLayer('http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0', { timeField: 'time' }).addTo(map); layer.createLayers(multiPolygon); + layer.bindPopup(function(feature){ return 'ID: ' + feature.id; }); + layer.unbindPopup(); - expect(layer.getFeature(1).getLayers()[0]._popup).to.equal(null); - expect(layer.getFeature(1).getLayers()[1]._popup).to.equal(null); + + expect(layer.getFeature(1)._popup).to.equal(null); }); it('should iterate over each feature', function(){ @@ -307,7 +309,7 @@ describe('L.esri.Layers.FeatureLayer', function () { layer.getFeature(1).fire('click', { foo: 'bar' - }); + }, true); expect(spy.getCall(0).args[0].foo).to.equal('bar'); expect(spy.getCall(0).args[0].type).to.equal('click'); diff --git a/spec/Layers/FeatureLayer/FeatureManagerSpec.js b/spec/Layers/FeatureLayer/FeatureManagerSpec.js index f498572a1..640d16826 100644 --- a/spec/Layers/FeatureLayer/FeatureManagerSpec.js +++ b/spec/Layers/FeatureLayer/FeatureManagerSpec.js @@ -708,7 +708,7 @@ describe('L.esri.Layers.FeatureManager', function () { }); it('should support generalizing geometries', function(){ - server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?returnGeometry=true&where=1%3D1&outSr=4326&outFields=*&inSr=4326&geometry=%7B%22xmin%22%3A-122.6953125%2C%22ymin%22%3A45.521743896993634%2C%22xmax%22%3A-122.6513671875%2C%22ymax%22%3A45.55252525134013%2C%22spatialReference%22%3A%7B%22wkid%22%3A4326%7D%7D&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&geometryPrecision=6&maxAllowableOffset=0.00004291534423829546&f=json', JSON.stringify({ + server.respondWith('GET', 'http://services.arcgis.com/mock/arcgis/rest/services/MockService/MockFeatureServer/0/query?returnGeometry=true&where=1%3D1&outSr=4326&outFields=*&inSr=4326&geometry=%7B%22xmin%22%3A-122.6953125%2C%22ymin%22%3A45.521743896993634%2C%22xmax%22%3A-122.6513671875%2C%22ymax%22%3A45.55252525134013%2C%22spatialReference%22%3A%7B%22wkid%22%3A4326%7D%7D&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&geometryPrecision=6&maxAllowableOffset=0.00004291534423826704&f=json', JSON.stringify({ fields: fields, features: [feature6], objectIdFieldName: 'OBJECTID', diff --git a/spec/Tasks/IdentifyFeaturesSpec.js b/spec/Tasks/IdentifyFeaturesSpec.js index 7c35bcf35..dcadbc314 100644 --- a/spec/Tasks/IdentifyFeaturesSpec.js +++ b/spec/Tasks/IdentifyFeaturesSpec.js @@ -105,7 +105,6 @@ describe('L.esri.Tasks.IdentifyFeatures', function () { it('should identify features with a 2 layer definitions', function(done){ - // server.respondWith('GET', url + 'identify?sr=4326&layers=all&tolerance=3&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-122.66535758972167%2C45.50624163368495%2C-122.65462875366211%2C45.51376023843158&geometry=-122.66%2C45.51&geometryType=esriGeometryPoint&layerDefs=0%3ANAME%3DOregon%3B1%3ANAME%3DMultnomah&f=json', JSON.stringify(sampleResponse)); var request = task.layerDef(0, 'NAME=Oregon').layerDef(1, 'NAME=Multnomah').run(function(error, featureCollection, raw){ expect(featureCollection).to.deep.equal(sampleFeatureCollection); @@ -119,7 +118,6 @@ describe('L.esri.Tasks.IdentifyFeatures', function () { }); it('should identify features in a given time range', function(done){ - // server.respondWith('GET', url + 'identify?sr=4326&layers=all&tolerance=3&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-122.66535758972167%2C45.50624163368495%2C-122.65462875366211%2C45.51376023843158&geometry=-122.66%2C45.51&geometryType=esriGeometryPoint&time=1357027200000%2C1388563200000&f=json', JSON.stringify(sampleResponse)); var start = new Date('January 1 2013 GMT-0800'); var end = new Date('January 1 2014 GMT-0800'); @@ -136,7 +134,6 @@ describe('L.esri.Tasks.IdentifyFeatures', function () { }); it('should restrict identification to specific layers', function(done){ - // server.respondWith('GET', url + 'identify?sr=4326&layers=top&tolerance=3&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-122.66535758972167%2C45.50624163368495%2C-122.65462875366211%2C45.51376023843158&geometry=-122.66%2C45.51&geometryType=esriGeometryPoint&f=json', JSON.stringify(sampleResponse)); var request = task.layers('top').run(function(error, featureCollection, raw){ expect(featureCollection).to.deep.equal(sampleFeatureCollection); @@ -148,7 +145,6 @@ describe('L.esri.Tasks.IdentifyFeatures', function () { }); it('should identify features and limit geometries to a given precision', function(done){ - // server.respondWith('GET', url + 'identify?sr=4326&layers=all&tolerance=3&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-122.66535758972167%2C45.50624163368495%2C-122.65462875366211%2C45.51376023843158&geometry=-122.66%2C45.51&geometryType=esriGeometryPoint&geometryPrecision=4&f=json', JSON.stringify(sampleResponse)); var request = task.precision(4).run(function(error, featureCollection, raw){ expect(featureCollection).to.deep.equal(sampleFeatureCollection); @@ -162,7 +158,6 @@ describe('L.esri.Tasks.IdentifyFeatures', function () { }); it('should identify features and simplify geometries', function(done){ - // server.respondWith('GET', url + 'identify?sr=4326&layers=all&tolerance=3&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-122.66535758972167%2C45.50624163368495%2C-122.65462875366211%2C45.51376023843158&geometry=-122.66%2C45.51&geometryType=esriGeometryPoint&maxAllowableOffset=0.000010728836059556101&f=json', JSON.stringify(sampleResponse)); var request = task.simplify(map, 0.5).run(function(error, featureCollection, raw){ expect(featureCollection).to.deep.equal(sampleFeatureCollection); @@ -170,13 +165,12 @@ describe('L.esri.Tasks.IdentifyFeatures', function () { done(); }); - expect(request.url).to.contain('maxAllowableOffset=0.000010728836059556101'); + expect(request.url).to.contain('maxAllowableOffset=0.000010728836059570313'); request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, JSON.stringify(sampleResponse)); }); it('should identify features with a token', function(done){ - // server.respondWith('GET', url + 'identify?sr=4326&layers=all&tolerance=3&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-122.66535758972167%2C45.50624163368495%2C-122.65462875366211%2C45.51376023843158&geometry=-122.66%2C45.51&geometryType=esriGeometryPoint&token=foo&f=json', JSON.stringify(sampleResponse)); var request = task.token('foo').run(function(error, featureCollection, raw){ expect(featureCollection).to.deep.equal(sampleFeatureCollection); @@ -190,7 +184,6 @@ describe('L.esri.Tasks.IdentifyFeatures', function () { }); it('should identify features within a certain pixel tolerance', function(done){ - // server.respondWith('GET', url + 'identify?sr=4326&layers=all&tolerance=4&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-122.66535758972167%2C45.50624163368495%2C-122.65462875366211%2C45.51376023843158&geometry=-122.66%2C45.51&geometryType=esriGeometryPoint&f=json', JSON.stringify(sampleResponse)); var request = task.tolerance(4).run(function(error, featureCollection, raw){ expect(featureCollection).to.deep.equal(sampleFeatureCollection); @@ -206,7 +199,6 @@ describe('L.esri.Tasks.IdentifyFeatures', function () { it('should use a service to execute the request', function(done){ var service = L.esri.Services.mapService(url); - // server.respondWith('GET', url + 'identify?sr=4326&layers=all&tolerance=3&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-122.66535758972167%2C45.50624163368495%2C-122.65462875366211%2C45.51376023843158&geometry=-122.66%2C45.51&geometryType=esriGeometryPoint&f=json', JSON.stringify(sampleResponse)); var request = service.identify().on(map).at(latlng).run(function(error, featureCollection, raw){ expect(featureCollection).to.deep.equal(sampleFeatureCollection); @@ -230,7 +222,6 @@ describe('L.esri.Tasks.IdentifyFeatures', function () { it('should use a service to execute the request with simple LatLng', function(done){ var service = L.esri.Services.mapService(url); - // server.respondWith('GET', url + 'identify?sr=4326&layers=all&tolerance=3&returnGeometry=true&imageDisplay=500%2C500%2C96&mapExtent=-122.66535758972167%2C45.50624163368495%2C-122.65462875366211%2C45.51376023843158&geometry=-122.66%2C45.51&geometryType=esriGeometryPoint&f=json', JSON.stringify(sampleResponse)); var request = service.identify().on(map).at(rawLatlng).run(function(error, featureCollection, raw){ expect(featureCollection).to.deep.equal(sampleFeatureCollection); diff --git a/spec/Tasks/QuerySpec.js b/spec/Tasks/QuerySpec.js index aed46e926..adf24e045 100644 --- a/spec/Tasks/QuerySpec.js +++ b/spec/Tasks/QuerySpec.js @@ -517,7 +517,7 @@ describe('L.esri.Tasks.Query', function () { }); it('should identify features and simplify geometries', function(done){ - server.respondWith('GET', featureLayerUrl + 'query?returnGeometry=true&where=1%3D1&outSr=4326&outFields=*&maxAllowableOffset=0.000010728836059556101&f=json', JSON.stringify(sampleQueryResponse)); + server.respondWith('GET', featureLayerUrl + 'query?returnGeometry=true&where=1%3D1&outSr=4326&outFields=*&maxAllowableOffset=0.000010728836059570313&f=json', JSON.stringify(sampleQueryResponse)); task.simplify(map, 0.5).run(function(error, featureCollection, raw){ expect(featureCollection).to.deep.equal(sampleFeatureCollection); diff --git a/src/EsriLeaflet.js b/src/EsriLeaflet.js index 8553b88d3..22158d9af 100644 --- a/src/EsriLeaflet.js +++ b/src/EsriLeaflet.js @@ -1,5 +1,5 @@ var EsriLeaflet = { //jshint ignore:line - VERSION: '1.0.0-rc.2', + VERSION: '1.0.0', Layers: {}, Services: {}, Controls: {}, diff --git a/src/Layers/BasemapLayer.js b/src/Layers/BasemapLayer.js index a653c6072..49efbf505 100644 --- a/src/Layers/BasemapLayer.js +++ b/src/Layers/BasemapLayer.js @@ -46,7 +46,6 @@ options: { hideLogo: true, logoPosition: 'bottomright', - //pane: 'esri-label', minZoom: 1, maxZoom: 16, subdomains: ['server', 'services'] @@ -79,7 +78,6 @@ options: { hideLogo: true, logoPosition: 'bottomright', - //pane: 'esri-label', minZoom: 1, maxZoom: 10, subdomains: ['1', '2'] @@ -101,7 +99,6 @@ options: { hideLogo: true, logoPosition: 'bottomright', - //pane: 'esri-label', minZoom: 1, maxZoom: 16, subdomains: ['server', 'services'] @@ -123,7 +120,6 @@ options: { hideLogo: true, logoPosition: 'bottomright', - //pane: 'esri-label', minZoom: 1, maxZoom: 19, subdomains: ['server', 'services'] @@ -131,7 +127,6 @@ }, ImageryTransportation: { urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Transportation/MapServer/tile/{z}/{y}/{x}', - //pane: 'esri-label', options: { hideLogo: true, logoPosition: 'bottomright', @@ -156,7 +151,6 @@ options: { hideLogo: true, logoPosition: 'bottomright', - //pane: 'esri-label', minZoom: 1, maxZoom: 12, subdomains: ['server', 'services'] @@ -178,7 +172,6 @@ options: { hideLogo: true, logoPosition: 'bottomright', - //pane: 'esri-label', minZoom: 1, maxZoom: 13, subdomains: ['server', 'services'] @@ -216,10 +209,6 @@ }).addTo(map); } - // if(this.options.pane && EsriLeaflet.Support.pointerEvents){ - // this._initPane(); - // } - L.TileLayer.prototype.onAdd.call(this, map); map.on('moveend', this._updateMapAttribution, this); @@ -237,13 +226,6 @@ var attribution = '' + this.options.attribution + ''/* + logo*/; return attribution; }, - // _initPane: function(){ - // if(!this._map.getPane(this.options.pane)){ - // var pane = this._map.createPane(this.options.pane); - // pane.style.pointerEvents = 'none'; - // pane.style.zIndex = 5; - // } - // }, _getAttributionData: function(url){ EsriLeaflet.get(url, {}, function(error, attributions){ this._attributions = []; @@ -285,8 +267,10 @@ } newAttributions = newAttributions.substr(2); var attributionElement = this._map.attributionControl._container.querySelector('.esri-attributions'); + attributionElement.innerHTML = newAttributions; attributionElement.style.maxWidth = (this._map.getSize().x * 0.65) + 'px'; + this.fire('attributionupdated', { attribution: newAttributions }); diff --git a/src/Layers/DynamicMapLayer.js b/src/Layers/DynamicMapLayer.js index 3a829ab8d..fbab7ec59 100644 --- a/src/Layers/DynamicMapLayer.js +++ b/src/Layers/DynamicMapLayer.js @@ -12,7 +12,7 @@ EsriLeaflet.Layers.DynamicMapLayer = EsriLeaflet.Layers.RasterLayer.extend({ initialize: function (url, options) { this.url = EsriLeaflet.Util.cleanUrl(url); this._service = new EsriLeaflet.Services.MapService(this.url, options); - this._service.on('authenticationrequired requeststart requestend requesterror requestsuccess', this._propagateEvent, this); + this._service.addEventParent(this); L.Util.setOptions(this, options); }, diff --git a/src/Layers/FeatureLayer/FeatureGrid.js b/src/Layers/FeatureLayer/FeatureGrid.js index 597005b75..7311b7fde 100644 --- a/src/Layers/FeatureLayer/FeatureGrid.js +++ b/src/Layers/FeatureLayer/FeatureGrid.js @@ -1,6 +1,4 @@ -EsriLeaflet.Layers.FeatureGrid = L.Class.extend({ - - includes: L.Mixin.Events, +EsriLeaflet.Layers.FeatureGrid = L.Layer.extend({ options: { cellSize: 512, @@ -13,10 +11,7 @@ EsriLeaflet.Layers.FeatureGrid = L.Class.extend({ onAdd: function (map) { this._map = map; - this._update = L.Util.limitExecByInterval(this._update, this.options.updateInterval, this); - - // @TODO remove for leaflet 0.8 - this._map.addEventListener(this.getEvents(), this); + this._update = L.Util.throttle(this._update, this.options.updateInterval, this); this._reset(); this._update(); @@ -54,8 +49,7 @@ EsriLeaflet.Layers.FeatureGrid = L.Class.extend({ this._cellsToLoad = 0; this._cellsTotal = 0; - // @TODO enable at Leaflet 0.8 - // this._cellNumBounds = this._getCellNumBounds(); + this._cellNumBounds = this._getCellNumBounds(); this._resetWrap(); }, @@ -220,7 +214,7 @@ EsriLeaflet.Layers.FeatureGrid = L.Class.extend({ this.fire('cellleave', { bounds: cell.bounds, coords: cell.coords - }); + }, true); } }, @@ -236,7 +230,7 @@ EsriLeaflet.Layers.FeatureGrid = L.Class.extend({ this.fire('cellleave', { bounds: bounds, coords: coords - }); + }, true); } }, @@ -260,7 +254,7 @@ EsriLeaflet.Layers.FeatureGrid = L.Class.extend({ this.fire('cellenter', { bounds: cell.bounds, coords: coords - }); + }, true); this._activeCells[key] = cell; } @@ -282,25 +276,23 @@ EsriLeaflet.Layers.FeatureGrid = L.Class.extend({ this.fire('cellcreate', { bounds: cell.bounds, coords: coords - }); + }, true); } }, _wrapCoords: function (coords) { coords.x = this._wrapLng ? L.Util.wrapNum(coords.x, this._wrapLng) : coords.x; coords.y = this._wrapLat ? L.Util.wrapNum(coords.y, this._wrapLat) : coords.y; - } + }, // get the global cell coordinates range for the current zoom - // @TODO enable at Leaflet 0.8 - // _getCellNumBounds: function () { - // // @TODO for Leaflet 0.8 - // // var bounds = this._map.getPixelWorldBounds(), - // // size = this._getCellSize(); - // // - // // return bounds ? L.bounds( - // // bounds.min.divideBy(size).floor(), - // // bounds.max.divideBy(size).ceil().subtract([1, 1])) : null; - // } + _getCellNumBounds: function () { + var bounds = this._map.getPixelWorldBounds(); + var size = this._getCellSize(); + + return bounds ? L.bounds( + bounds.min.divideBy(size).floor(), + bounds.max.divideBy(size).ceil().subtract([1, 1])) : null; + } }); \ No newline at end of file diff --git a/src/Layers/FeatureLayer/FeatureLayer.js b/src/Layers/FeatureLayer/FeatureLayer.js index d6508ee51..dbe00fa61 100644 --- a/src/Layers/FeatureLayer/FeatureLayer.js +++ b/src/Layers/FeatureLayer/FeatureLayer.js @@ -1,9 +1,5 @@ EsriLeaflet.Layers.FeatureLayer = EsriLeaflet.Layers.FeatureManager.extend({ - statics: { - EVENTS: 'click dblclick mouseover mouseout mousemove contextmenu popupopen popupclose' - }, - /** * Constructor */ @@ -14,8 +10,6 @@ EsriLeaflet.Layers.FeatureLayer = EsriLeaflet.Layers.FeatureManager.extend({ options = L.setOptions(this, options); this._layers = {}; - this._leafletIds = {}; - this._key = 'c'+(Math.random() * 1e9).toString(36).replace('.', '_'); }, /** @@ -36,9 +30,7 @@ EsriLeaflet.Layers.FeatureLayer = EsriLeaflet.Layers.FeatureManager.extend({ }, createNewLayer: function(geojson){ - // @TODO Leaflet 0.8 - //newLayer = L.GeoJSON.geometryToLayer(geojson, this.options); - return L.GeoJSON.geometryToLayer(geojson, this.options.pointToLayer, L.GeoJSON.coordsToLatLng, this.options); + return L.GeoJSON.geometryToLayer(geojson, this.options); }, /** @@ -58,29 +50,18 @@ EsriLeaflet.Layers.FeatureLayer = EsriLeaflet.Layers.FeatureManager.extend({ } if (layer && layer.setLatLngs) { - // @TODO Leaflet 0.8 - //newLayer = L.GeoJSON.geometryToLayer(geojson, this.options); - var updateGeo = this.createNewLayer(geojson); layer.setLatLngs(updateGeo.getLatLngs()); } if(!layer){ - // @TODO Leaflet 0.8 - //newLayer = L.GeoJSON.geometryToLayer(geojson, this.options); newLayer = this.createNewLayer(geojson); newLayer.feature = geojson; newLayer.defaultOptions = newLayer.options; - newLayer._leaflet_id = this._key + '_' + geojson.id; - - this._leafletIds[newLayer._leaflet_id] = geojson.id; // bubble events from layers to this - // @TODO Leaflet 0.8 - // newLayer.addEventParent(this); - - newLayer.on(EsriLeaflet.Layers.FeatureLayer.EVENTS, this._propagateEvent, this); + newLayer.addEventParent(this); // bind a popup if we have one if(this._popup && newLayer.bindPopup){ @@ -99,7 +80,7 @@ EsriLeaflet.Layers.FeatureLayer = EsriLeaflet.Layers.FeatureManager.extend({ this.fire('createfeature', { feature: newLayer.feature - }); + }, true); // add the layer if it is within the time bounds or our layer is not time enabled if(!this.options.timeField || (this.options.timeField && this._featureWithinTimeRange(geojson)) ){ @@ -115,7 +96,7 @@ EsriLeaflet.Layers.FeatureLayer = EsriLeaflet.Layers.FeatureManager.extend({ if(layer){ this.fire('addfeature', { feature: layer.feature - }); + }, true); this._map.addLayer(layer); } } @@ -129,7 +110,7 @@ EsriLeaflet.Layers.FeatureLayer = EsriLeaflet.Layers.FeatureManager.extend({ this.fire('removefeature', { feature: layer.feature, permanent: permanent - }); + }, true); this._map.removeLayer(layer); } if(layer && permanent){ @@ -217,14 +198,6 @@ EsriLeaflet.Layers.FeatureLayer = EsriLeaflet.Layers.FeatureManager.extend({ getFeature: function (id) { return this._layers[id]; - }, - - // from https://github.com/Leaflet/Leaflet/blob/v0.7.2/src/layer/FeatureGroup.js - // @TODO remove at Leaflet 0.8 - _propagateEvent: function (e) { - e.layer = this._layers[this._leafletIds[e.target._leaflet_id]]; - e.target = this; - this.fire(e.type, e); } }); diff --git a/src/Layers/FeatureLayer/FeatureManager.js b/src/Layers/FeatureLayer/FeatureManager.js index 5aeab96ee..0b7f094b7 100644 --- a/src/Layers/FeatureLayer/FeatureManager.js +++ b/src/Layers/FeatureLayer/FeatureManager.js @@ -29,6 +29,7 @@ this.url = EsriLeaflet.Util.cleanUrl(url); this._service = new EsriLeaflet.Services.FeatureLayer(this.url, options); + this._service.addEventParent(this); //use case insensitive regex to look for common fieldnames used for indexing /*global console */ @@ -44,14 +45,6 @@ } } - // Leaflet 0.8 change to new propagation - this._service.on('authenticationrequired requeststart requestend requesterror requestsuccess', function (e) { - e = L.extend({ - target: this - }, e); - this.fire(e.type, e); - }, this); - if(this.options.timeField.start && this.options.timeField.end){ this._startTimeIndex = new BinarySearchIndex(); this._endTimeIndex = new BinarySearchIndex(); @@ -95,12 +88,12 @@ if(this._activeRequests === 1){ this.fire('loading', { bounds: bounds - }); + }, true); } return this._buildQuery(bounds).run(function(error, featureCollection, response){ if(response && response.exceededTransferLimit){ - this.fire('drawlimitexceeded'); + this.fire('drawlimitexceeded', {}, true); } //deincriment the request counter @@ -118,7 +111,7 @@ if(this._activeRequests <= 0){ this.fire('load', { bounds: bounds - }); + }, true); } }, this); }, diff --git a/src/Layers/ImageMapLayer.js b/src/Layers/ImageMapLayer.js index 8b5762f6b..d89cf1486 100644 --- a/src/Layers/ImageMapLayer.js +++ b/src/Layers/ImageMapLayer.js @@ -16,7 +16,7 @@ EsriLeaflet.Layers.ImageMapLayer = EsriLeaflet.Layers.RasterLayer.extend({ initialize: function (url, options) { this.url = EsriLeaflet.Util.cleanUrl(url); this._service = new EsriLeaflet.Services.ImageService(this.url, options); - this._service.on('authenticationrequired requeststart requestend requesterror requestsuccess', this._propagateEvent, this); + this._service.addEventParent(this); L.Util.setOptions(this, options); }, diff --git a/src/Layers/RasterLayer.js b/src/Layers/RasterLayer.js index 4bf7a023d..0aebe0e8c 100644 --- a/src/Layers/RasterLayer.js +++ b/src/Layers/RasterLayer.js @@ -1,5 +1,4 @@ -EsriLeaflet.Layers.RasterLayer = L.Class.extend({ - includes: L.Mixin.Events, +EsriLeaflet.Layers.RasterLayer = L.Layer.extend({ options: { opacity: 1, @@ -10,7 +9,7 @@ EsriLeaflet.Layers.RasterLayer = L.Class.extend({ onAdd: function (map) { this._map = map; - this._update = L.Util.limitExecByInterval(this._update, this.options.updateInterval, this); + this._update = L.Util.throttle(this._update, this.options.updateInterval, this); if (map.options.crs && map.options.crs.code) { var sr = map.options.crs.code.split(':')[1]; @@ -18,9 +17,6 @@ EsriLeaflet.Layers.RasterLayer = L.Class.extend({ this.options.imageSR = sr; } - // @TODO remove at Leaflet 0.8 - this._map.addEventListener(this.getEvents(), this); - this._update(); if(this._popup){ @@ -65,16 +61,6 @@ EsriLeaflet.Layers.RasterLayer = L.Class.extend({ this._map.removeEventListener(this.getEvents(), this); }, - addTo: function(map){ - map.addLayer(this); - return this; - }, - - removeFrom: function(map){ - map.removeLayer(this); - return this; - }, - getEvents: function(){ return { moveend: this._update @@ -208,15 +194,5 @@ EsriLeaflet.Layers.RasterLayer = L.Class.extend({ _resetPopupState: function(e){ this._shouldRenderPopup = false; this._lastClick = e.latlng; - }, - - // from https://github.com/Leaflet/Leaflet/blob/v0.7.2/src/layer/FeatureGroup.js - // @TODO remove at Leaflet 0.8 - _propagateEvent: function (e) { - e = L.extend({ - layer: e.target, - target: this - }, e); - this.fire(e.type, e); } }); \ No newline at end of file diff --git a/src/Layers/TiledMapLayer.js b/src/Layers/TiledMapLayer.js index 230f5dddb..bba06f061 100644 --- a/src/Layers/TiledMapLayer.js +++ b/src/Layers/TiledMapLayer.js @@ -6,7 +6,7 @@ EsriLeaflet.Layers.TiledMapLayer = L.TileLayer.extend({ this.url = L.esri.Util.cleanUrl(url); this.tileUrl = L.esri.Util.cleanUrl(url) + 'tile/{z}/{y}/{x}'; this._service = new L.esri.Services.MapService(this.url, options); - this._service.on('authenticationrequired requeststart requestend requesterror requestsuccess', this._propagateEvent, this); + this._service.addEventParent(this); //if this is looking at the AGO tiles subdomain insert the subdomain placeholder if(this.tileUrl.match('://tiles.arcgisonline.com')){ @@ -30,16 +30,6 @@ EsriLeaflet.Layers.TiledMapLayer = L.TileLayer.extend({ authenticate: function(token){ this._service.authenticate(token); return this; - }, - - // from https://github.com/Leaflet/Leaflet/blob/v0.7.2/src/layer/FeatureGroup.js - // @TODO remove at Leaflet 0.8 - _propagateEvent: function (e) { - e = L.extend({ - layer: e.target, - target: this - }, e); - this.fire(e.type, e); } }); diff --git a/src/Services/Service.js b/src/Services/Service.js index 98c7d3f64..897c08416 100644 --- a/src/Services/Service.js +++ b/src/Services/Service.js @@ -1,6 +1,4 @@ -EsriLeaflet.Services.Service = L.Class.extend({ - - includes: L.Mixin.Events, +EsriLeaflet.Services.Service = L.Evented.extend({ options: { proxy: false, @@ -42,7 +40,7 @@ EsriLeaflet.Services.Service = L.Class.extend({ url: this.url + path, params: params, method: method - }); + }, true); var wrappedCallback = this._createServiceCallback(method, path, params, callback, context); @@ -76,7 +74,7 @@ EsriLeaflet.Services.Service = L.Class.extend({ this.fire('authenticationrequired', { authenticate: L.Util.bind(this.authenticate, this) - }); + }, true); } else { callback.call(context, error, response); @@ -87,21 +85,21 @@ EsriLeaflet.Services.Service = L.Class.extend({ message: error.message, code: error.code, method: method - }); + }, true); } else { this.fire('requestsuccess', { url: this.url + path, params: params, response: response, method: method - }); + }, true); } this.fire('requestend', { url: this.url + path, params: params, method: method - }); + }, true); } }, this); }, diff --git a/src/Tasks/IdentifyImage.js b/src/Tasks/IdentifyImage.js index 6e351c87a..e131022a7 100644 --- a/src/Tasks/IdentifyImage.js +++ b/src/Tasks/IdentifyImage.js @@ -73,9 +73,11 @@ EsriLeaflet.Tasks.IdentifyImage = EsriLeaflet.Tasks.Identify.extend({ 'id': response.objectId } }; + if (response.properties && response.properties.Values) { geoJSON.pixel.properties.values = response.properties.Values; } + if (catalogItems && catalogItems.features) { geoJSON.catalogItems = EsriLeaflet.Util.responseToFeatureCollection(catalogItems); if (catalogItemVisibilities && catalogItemVisibilities.length === geoJSON.catalogItems.features.length) { From b114354a3531a7393cf44112bfd6d5f73bb8ee23 Mon Sep 17 00:00:00 2001 From: Rachel Nehmer Date: Mon, 8 Dec 2014 16:46:29 -0800 Subject: [PATCH 02/29] build leaflet distribution in submodule --- package.json | 5 +++-- scripts/install.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 scripts/install.js diff --git a/package.json b/package.json index 29d0877f1..9cdbbe9d4 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "scripts": { "prepublish": "node -e \"require('grunt').tasks(['prepublish']);\"", "start": "node -e \"require('grunt').tasks(['default']);\"", - "test": "node -e \"require('grunt').tasks(['test']);\"" + "test": "node -e \"require('grunt').tasks(['test']);\"", + "postinstall": "node scripts/install.js" }, "author": "Patrick Arlt (http://patrickarlt.com)", "contributors": [ @@ -45,6 +46,6 @@ "license": "Apache", "readmeFilename": "README.md", "dependencies": { - "leaflet": "^0.7.0" + "leaflet": "git://github.com/Leaflet/Leaflet.git#master" } } diff --git a/scripts/install.js b/scripts/install.js new file mode 100644 index 000000000..55693f3ae --- /dev/null +++ b/scripts/install.js @@ -0,0 +1,15 @@ +var sys = require('sys'); +var exec = require('child_process').exec; + + +process.chdir('./node_modules/leaflet'); +exec('npm install', function (error, stdout, stderr) { + if (error) { sys.puts(error);return; } + if (stderr) { sys.puts(stderr);return; } + if (stdout) { sys.puts(stdout); } + exec('jake', function (error, stdout, stderr) { + if (error) { sys.puts(error); } + if (stderr) { sys.puts(stderr); } + if (stdout) { sys.puts(stdout); } + }); +}); From c2aec4e5c7d7d1398ada745b49480ef6fef639b2 Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Fri, 3 Jul 2015 08:54:20 -0700 Subject: [PATCH 03/29] fixup samples --- .../image-map-layer-rendering-rule.hbs | 5 ++- .../pages/examples/switching-basemaps.hbs | 3 +- src/Layers/FeatureLayer/FeatureLayer.js | 37 ------------------- src/Layers/FeatureLayer/FeatureManager.js | 2 +- 4 files changed, 6 insertions(+), 41 deletions(-) diff --git a/site/source/pages/examples/image-map-layer-rendering-rule.hbs b/site/source/pages/examples/image-map-layer-rendering-rule.hbs index bde66bfd6..28b20910d 100644 --- a/site/source/pages/examples/image-map-layer-rendering-rule.hbs +++ b/site/source/pages/examples/image-map-layer-rendering-rule.hbs @@ -21,7 +21,8 @@ layout: example.hbs L.esri.basemapLayer('Imagery').addTo(map); L.esri.imageMapLayer('http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/SanAndreasLidar/ImageServer', { - renderingRule: renderingRule + renderingRule: renderingRule, + useCors: false }).addTo(map); - \ No newline at end of file + diff --git a/site/source/pages/examples/switching-basemaps.hbs b/site/source/pages/examples/switching-basemaps.hbs index 98c641e61..c5df2fb57 100644 --- a/site/source/pages/examples/switching-basemaps.hbs +++ b/site/source/pages/examples/switching-basemaps.hbs @@ -3,6 +3,7 @@ title: Switching basemaps description: Switching between all available basemaps packaged with Esri Leaflet. layout: example.hbs --- +