-
Notifications
You must be signed in to change notification settings - Fork 35
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
refreshing map data #140
Comments
I've refactored my code based on some of the other threads as such: import Ember from 'ember';
import ENV from '../config/environment';
import EmberLeafletComponent from 'ember-leaflet/components/leaflet-map';
import MarkerLayer from 'ember-leaflet/layers/marker';
import TileLayer from 'ember-leaflet/layers/tile';
L.Icon.Default.imagePath = '/images/leaflet';
export default EmberLeafletComponent.extend({
center: Ember.computed(function() {
return this.get('coordinates');
}),
/////////////////////////////////////
// PROPERTIES
/////////////////////////////////////
geoJSON: null,
/////////////////////////////////////
// COMPUTED PROPERTIES
/////////////////////////////////////
childLayers: Ember.computed(function() {
return [
TileLayer.extend({
tileUrl: 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}',
options: {
id: 'scoutforpets.o2ml3nm1',
accessToken: ENV.APP.MAPBOX_KEY
}
}),
MarkerLayer.extend({
component: this,
contentBinding: Ember.computed.reads('component.coordinates')
})
];
}),
coordinates: Ember.computed('geoJSON', function() {
if (this.get('geoJSON')) {
const coordinates = JSON.parse(this.get('geoJSON')).coordinates;
if (coordinates) {
return { location: L.latLng(coordinates[1], coordinates[0]) };
}
}
return null;
})
}); Unfortunately, I'm still not having any luck. All I mentioned above, I'm simply trying to change the marker on the map when new data is passed in, but it's been seemingly difficult to get working. I'm sure it's something trivial, but am really pulling my hair out at this point! @gabesmed @miguelcobain would you be able to lend 5 minutes to offer some advice? Thank you! |
@jamesdixon As a hint, remember that each child layer has Try to:
{{ember-leaflet appointmentLatlng=appointmentLatlng center=center ...}} //TODO move to separate file
let AppointmentMarkerLayer = MarkerLayer.extend({
location: Ember.computed.alias('controller.appointmentLatlng')
});
//TODO move to separate file
let MapBoxTileLayer = TileLayer.extend({
//...
});
export default EmberLeafletComponent.extend({
childLayers: [MapBoxTileLayer, AppointmentMarkerLayer]
}); This way, whenever |
@miguelcobain I appreciate the advice. Going to take a break from this for a bit and will give it a shot. Thank you for your response! |
awesome thank you for the response and thanks to @jamesdixon for the question! I externalized all |
@localyost consider using ember-leaflet 2.0 - www.ember-leaflet.com |
Just stumbled across it after that last post! Great work man, thanks! |
Hi, I'm using ember-leaflet to display a map for an appointment's location. The user selects an appointment from a list and the corresponding appointment details (including the map) are then displayed.
When an appointment is selected, the details are passed to the component, which contains the map. Unfortunately, after the user selects an appointment and then another is selected, the coordinates on the map do not change. However, outputting the coordinates using Handlebars, I can in fact see that the different coordinates are being passed to the component. That leads me to believe that the map needs to be "refreshed" somehow in order for the new coordinates to be displayed on the map.
I use the component like so:
{{ember-leaflet geoJSON=geoJSON}}
where geoJSON is a string containing the location data.My component is as follows:
When setting a breakpoint, it appears that
childLayers
andcoordinates
are only being called once regardless of which appointment is selected by the user. I've considered setting up an observer to observe thegeoJSON
property, but it seems overkill.Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: