-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement changes to fractracker mobile layer #330
Merged
jywarren
merged 4 commits into
publiclab:master
from
crisner:update-fractracker-mobile-layer
Jan 8, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
describe('FracTrackerMobile Layer', function() { | ||
|
||
var mapContainer = document.createElement('div'); | ||
var map = L.map(mapContainer); | ||
var FracTracker_mobile = L.geoJSON.fracTrackerMobile(); | ||
|
||
it('adds layer to map', function() { | ||
map.addLayer(FracTracker_mobile); | ||
expect(Object.keys(map._layers)).toHaveLength(1); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,102 @@ | ||
fracTrackerMobileLayer = function(map) { | ||
var FracTracker_mobile = L.esri.featureLayer({ | ||
url: 'https://services.arcgis.com/jDGuO8tYggdCCnUJ/arcgis/rest/services/FracTrackerMobileAppNPCAMesaVerdeNationalPark_051416/FeatureServer/0/', | ||
simplifyFactor: 1, | ||
}); | ||
|
||
FracTracker_mobile.bindPopup(function(layer) { | ||
return L.Util.template('<p><strong>Id : </strong>{OBJECTID}<br><strong>FT_MV_ID : </strong>{FT_MV_ID}<br><strong>Long : </strong>{Long}<br><strong>Lat :</strong> {Lat} <br> <strong>Caption : </strong>{caption} <br> <strong>issue :</strong> {issue} <br> <strong>facility :</strong> {facility} <br><strong> Location :</strong> {location} <br> <strong>URL :</strong> <a href={URL2}>{URL2}</a> <br> <img src={URL2} height="280" width="290"></p>', layer.feature.properties); | ||
}); | ||
|
||
FracTracker_mobile.on('loading', function(e) { | ||
if (typeof map.spin === 'function') { | ||
map.spin(true); | ||
} | ||
}); | ||
FracTracker_mobile.on('load', function(e) { | ||
if (typeof map.spin === 'function') { | ||
map.spin(false); | ||
} | ||
}); | ||
|
||
return FracTracker_mobile; | ||
L.GeoJSON.FracTrackerMobile = L.GeoJSON.extend( | ||
{ | ||
options: { }, | ||
|
||
initialize: function(options) { | ||
options = options || {}; | ||
L.Util.setOptions(this, options); | ||
this._layers = {}; | ||
}, | ||
|
||
onAdd: function(map) { | ||
map.on('moveend', this.requestData, this); | ||
this._map = map; | ||
this.requestData(); | ||
}, | ||
|
||
onRemove: function(map) { | ||
map.off('moveend', this.requestData, this); | ||
if (typeof map.spin === 'function') { | ||
map.spin(false); | ||
} | ||
this.clearLayers(); | ||
this._layers = {}; | ||
}, | ||
|
||
requestData: function() { | ||
var self = this; | ||
|
||
(function() { | ||
var bounds = self._map.getBounds(); | ||
var northEast = bounds.getNorthEast(); | ||
var southWest = bounds.getSouthWest(); | ||
var left = southWest.lng; | ||
var right = northEast.lng; | ||
var top = northEast.lat; | ||
var bottom = southWest.lat; | ||
var polygon = left + ' ' + top + ',' + right + ' ' + top + ',' + right + ' ' + bottom + ',' + left + ' ' + bottom + ',' + left + ' ' + top; | ||
|
||
var $ = window.jQuery; | ||
var fractrackerMobile_url = 'https://cors-anywhere.herokuapp.com/https://api.fractracker.org/v1/data/report?page=1&results_per_page=250&q={"filters":[{"name":"geometry","op":"intersects","val":"SRID=4326;POLYGON((' + polygon +'))"}],"order_by":[{"field":"report_date","direction":"desc"},{"field":"id","direction":"desc"}]}'; | ||
|
||
if (typeof self._map.spin === 'function') { | ||
self._map.spin(true); | ||
} | ||
|
||
return $.getJSON(fractrackerMobile_url); | ||
|
||
})().done(function(data) { | ||
self.parseData(data); | ||
if (typeof self._map.spin === 'function') { | ||
self._map.spin(false); | ||
} | ||
}); | ||
}, | ||
|
||
parseData: function(data) { | ||
if (!!data) { | ||
for ( var i = 0; i < data.features.length; i++) { | ||
this.addMarker(data.features[i]); | ||
} | ||
} | ||
}, | ||
|
||
getMarker: function(data) { | ||
var coords = this.coordsToLatLng(data.geometry.coordinates || data.geometry.geometries[0].coordinates); | ||
var lat = coords.lat; | ||
var lng = coords.lng; | ||
var description = data.properties.description ? data.properties.description : ''; | ||
var date = new Date(data.properties.report_date).toUTCString(); | ||
var dateModified = new Date(data.properties.modified_on).toUTCString(); | ||
var organizationName = data.properties.created_by.organization_name ? data.properties.created_by.organization_name : ''; | ||
var imageUrl = data.properties.images[0] && data.properties.images[0].properties.square; | ||
var imageElement = imageUrl ? '<img src="' + imageUrl + '" alt="User image" width="100%" />' : ''; | ||
var marker; | ||
if (!isNaN((lat)) && !isNaN((lng)) ) { | ||
marker = new L.circleMarker([lat, lng], { radius: 5, color: '#e4458b'}) | ||
.bindPopup(imageElement + '<br><strong>'+ description + '</strong><br>Lat : ' + lat + '<br>Lon : '+ lng + '<br>Reported on : ' + date + '<br>Modified on : ' + dateModified + '<br>' + organizationName); | ||
} | ||
return marker; | ||
}, | ||
|
||
addMarker: function(data) { | ||
var marker; | ||
var key = data.id; | ||
if (!this._layers[key]) { | ||
marker = this.getMarker(data); | ||
this._layers[key] = marker; | ||
this.addLayer(marker); | ||
} | ||
}, | ||
|
||
coordsToLatLng: function(coords) { | ||
return new L.LatLng(coords[1], coords[0]); | ||
}, | ||
|
||
}, | ||
); | ||
|
||
|
||
L.geoJSON.fracTrackerMobile = function(options) { | ||
return new L.GeoJSON.FracTrackerMobile(options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey,
What is this url cors-anywhere.herokuapp.com ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to remove the cors policy issue. Jeff had suggested using it in the issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it doesn't fetch the results if this is not prepended. But I am planning to look into it more tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows us to fetch it despite CORS restrictions. We've confirmed this is OK with the FracTracker team. Thanks!