get coordinates of a marker symbol in mapbox-gl-js and center on it - marker

I have this symbol on a map
map.addLayer({
"id": "home",
"type": "symbol",
"source": "property",
"interactive": true,
"layout": {
"icon-image": "rocket-15",
}
});
I would like to zoom in to this marker and center on it.
So far I have tried this:
map.featuresIn({ layer: 'home' }, function(err, features) {
console.log(features);
map.flyTo({ center: features[0].geometry.coordinates,zoom: 11 });
});
I omit the coordinates argument, so I refer to it directly (as stated in API). However, the 'features' arrive empty and I can never fly

featuresIn does not return features' geometries by default. For that, you must include the includeGeometry: true parameter.
You will find this example helpful!

Related

How to restructure positions of product media or remove all images using product api in Shopware

So I have an product and want to change the position of its images and swap the cover image, while adding some more images to the medias assigned to the product.
The media should look somewhat like this:
{
"media": [
{
"id": "a060944a2938442c8d461b3a0107ecf5",
"mediaId": "722d194bfbb84dc489f9f5b74da53bb3",
"position": 1
},
{
"id": "b060944a2938442c8d461b3a0107ecf6",
"mediaId": "822d194bfbb84dc489f9f5b74da53bb4",
"position": 2
}
],
"coverId": "a060944a2938442c8d461b3a0107ecf5"
}
and change to this:
{
"media": [
{
"id": "a060944a2938442c8d461b3a0107ecf5",
"mediaId": "722d194bfbb84dc489f9f5b74da53bb3",
"position": 3
},
{
"id": "b060944a2938442c8d461b3a0107ecf6",
"mediaId": "822d194bfbb84dc489f9f5b74da53bb4",
"position": 2
},
{
"id": "c060944a2938442c8d461b3a0107ecf7",
"mediaId": "922d194bfbb84dc489f9f5b74da53bb5",
"position": 1
}
],
"coverId": "b060944a2938442c8d461b3a0107ecf6"
}
I couldn't find a way to restructure the media positions and change the cover image.
So I tried to remove the media from the product, but the cover image stills stays even though the medias aren't connected to the product any more.
Also an UPDATE on the coverId doesn't seem to do the job either.
I used this to remove the images:
DELETE https://your-page.com/api/product/5efd4f22dc134ba7bf77c85f92fed0a9/media/b060944a2938442c8d461b3a0107ecf6
cover and media are two separate associations, so removing all media associations can still leave the cover association intact.
new ManyToOneAssociationField('cover', 'product_media_id', ProductMediaDefinition::class, 'id')
new OneToManyAssociationField('media', ProductMediaDefinition::class, 'product_id')
Notice how both refer to the definition ProductMediaDefinition. That means for coverId you have to provide the id of an existing product_media entity, not of a media entity.
If you have the id of a media entity, you can also create the product_media entity on the fly:
{
"id": "{productId}",
"cover": {
"mediaId": "{mediaId}"
}
}
If you want to remove the cover image without setting a new one, you can set coverId to null.

Datatables script DOM

I'm using datatables and I have created this javascript code
table = $('#examples').DataTable({
"ajax": {
type: "POST",
url: "./../../" + "/back-end/switch-ajax-listening/switch-ajax-listening.php",
dataType: "json",
data:
{
actionId: "page1GetAll"
}
},
dom : "B<'row'<'col-sm-6'l><'col-sm-6'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'<'#colvis'>p>>",
"buttons": [
{
extend: 'colvis',
postfixButtons: [ 'colvisRestore' ],
container : '#colvis',
columns: '0,1,2,3,4,5'
}
],
responsive: true,
"columns": [
{ "data": "idSelectPacketName"},
{ "data": "idSelectCompany" },
{"data":null,"defaultContent":"<button>View</button>"}
],
});
It works very well but I cannot be able to understand this part:
"B<'row'<'col-sm-6'l><'col-sm-6'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'<'#colvis'>p>>"
I have not written this string I have copied from an example but I am not able to understand how it works. Or have you known a guide to understand very well this string?
Because my problem is that some times the button is not aligned with the table, have you some ideas in order to solve it? Thanks.
It's a bit flakey as the author admits himself, for now, you need to put the Datatables keyletters in the correct places amongst the html tags. Something like:
dom : "<'row'<'col-sm-6'lB><'col-sm-6'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'<'#colvis'>p>>",
(placing the 'B' after the 'l')
You may also have to use CSS to obtain the desired layout.

JqWidgets treegrid issues wiring up dataAdapter object

I'm in the AngularJS environment, and trying to get a jqWidgets TreeGrid working.
I have the dataAdapter all wired up with the Json formatted data, however the grid renders only one row.
I also have a test treeGrid on the same page, and with sample data, which is working fine.
I'm putting the final Json data setting side-by-side to try and determine where I'm going wrong.
I've used this page as a guide to wire up the treegrid settings, etc. http://www.jqwidgets.com/jquery-widgets-documentation/documentation/angularjs/angularjs.htm
Here is the html showing the jqx treegrid directive for the "bad" grid:
<jqx-tree-grid jqx-instance="jqGridHierObj" jqx-settings="vm.jqGridHierSettings"></jqx-tree-grid>
And the "bad" Json data tree settings binded vm.jqGridHierSettings (too large to post inline):
http://www.bobmazzo.com/grid/TreeGrid_Data_Bad.txt
and here is the "good" grid with Employee test data :
HTML:
<jqx-tree-grid jqx-instance="jqGridEmpObj" jqx-settings="vm.jqGridEmpSettings"></jqx-grid>
vm.jqGridEmpSettings Json data :
http://www.bobmazzo.com/grid/TreeGrid_Data_Good.txt
and from my Angular controller code, a snippet of the javascript with Json data bindings :
I need help to figure out why the "bad" grid is not working ! And why it only renders one row, where is should be showing a hierarchy of data.
thanks.
Bob
I found the solution. You must define the “children” as an array type in the 'source' object; that is, prior to passing that object into the dataAdapter. See the dataFields property below :
var source = {
dataType: "json",
dataFields: [
{
"name": "id",
"type": "number"
},
{
"name": "field0",
"type": "string"
},
{
"name": "field1",
"type": "number"
},
{
"name": "field2",
"type": "number"
},
{
name: 'children', // MUST DEFINE CHILDREN AS ARRAY TYPE
type: 'array'
},
],
hierarchy: {
root: 'children'
},
id: 'id',
localData: myData
};
var dataAdapter = new $.jqx.dataAdapter(source);

Datatables 1.10 bSelectedOnly equivalent

I'm trying to find the equivalent of bSelectedOnly in the new version of Datatables 1.10.
I only want to print rows that the user has selected, or print all rows if they havn't selected any.
"tableTools": {
"sSwfPath": "/Datatables-1.10.0/extensions/TableTools/swf/copy_csv_xls.swf", //Add buttons for saving table data in these formats
"sRowSelect": "os", //allow user to select multiple rows in the table
"aButtons": [
{
"sExtends": "print",
"bSelectedOnly": "true",
},
{
"sExtends": "select_none",
},
]
},
It hasn't changed (see docs). But you have an error in your code. Instead of
"bSelectedOnly": "true",
it should be
"bSelectedOnly": true,
Also, bSelectedOnly is not available as a print option. It is only available as a flash button option. See here. That is the actual reason why what you're trying to do will not work :)

Google Places API's search results with huge viewports

I have been trying out Google's new Places API. It's "Places Search" returns a list of places close to the latitude/longitude you provide. Each of the results has its actual lat/lang, and some also have "viewports", which are supposed to be the bounding boxes of larger places like stadiums and malls. However, inspecting the viewports on the map, they are way too big. For example, here is a query (it won't work because it doesn't have a real key):
https://maps.googleapis.com/maps/api/place/search/json?location=47.5932,-122.3318&radius=300&sensor=false&key=FOO
Here is part of the result JSON:
{
"status": "OK",
"results": [ {
"name": "Qwest Field",
"vicinity": "Occidental Ave S, Seattle",
"types": [ "stadium", "establishment" ],
"geometry": {
"location": {
"lat": 47.5959329,
"lng": -122.3317095
},
"viewport": {
"southwest": {
"lat": 47.5884079,
"lng": -122.3477169
},
"northeast": {
"lat": 47.6034568,
"lng": -122.3157021
}
}
},
"icon": "http://maps.gstatic.com/mapfiles/place_api/icons/stadium-71.png",
"reference": "CnRrAAAAwM6Pr_ER4VDFNlwg4_JrMxG9FGaqAXokpQXGot9OqzylWRX_NIPsptuMoIeHej9GUDp5otUTQifL-kyP5l0AM5u93PTV22U7-Xz-y_dHuWAjetviEBlo24JIGgWcnuExlE1FBh2FKkNzCdpyUdv7PRIQodCSeacFJtrl8ZkZ1wvfvxoUFCIvCrbknO6tEl3EewS1wrjl06M",
"id": "d4fd94323d3f462730123ac2c5eb91d0180bb819"
},
...
If you look at the lat/langs for the two corners, they are way apart.
I tried a few other places and they all had this problem. Has anybody noticed the same issue?
The 'viewport' property does not represent the bounding box of the place. It represents the recommended map view to use when displaying this place on a Google map. For large features, such as a state or a city it may approximate to the bounds of the feature, but for small features there is a minimum size (~500m across) that is returned, so that the map shows a wide enough area around the feature for a user to understand the location of the place in context.
Hope that helps,
Thor.