Adding object in array of object in javascript - javascript

I have an Array object in my code:
cities =[{city_name:'NY',X:'1',Y:'2'}]
I'm trying to get new city info using ajax and add to cities array.
I get the response from ajax and make exact object like above, but when I try to push new object into array nothing happen.
My full code:
<script>
cities = [{
svgPath: targetSVG,
title: "Romania",
latitude: 44.4333000183,
longitude: 26.1000003815,
}
, {
svgPath: targetSVG,
title: "China",
latitude: 39.8897018433,
longitude: 115.275001526,
}
, {
svgPath: targetSVG,
title: "Taiwan",
latitude: 24.8047008514,
longitude: 120.9713974,
}
];
function push_test() {
temp = {
arc: -0.85,
alpha: 0.9,
latitudes: 1,
longitudes: 2
};
cities.push(temp);
}
</script>
<button onclick='push_test()'>test</button>

Related

OpenLayers - Heatmap | Override default overlap weight calculation

I am trying to implement an OpenLayers Heatmap to visualize some data on a map. My goal is to display heatmap points with given weights. Currently my poc code looks like this:
const features = [
{ lat: 46.934942, lon: 17.891804, id: 10, value: 6.5 },
{ lat: 46.93489, lon: 17.892713, id: 11, value: 5.2 },
{ lat: 46.934662, lon: 17.892331, id: 12, value: 5.9 },
].map((item) => {
const feature = createFeature({
lon: item.lon,
lat: item.lat,
id: `${item.id}`,
customStyle: new olStyle.Style({
image: new olStyle.Circle({
radius: 5,
fill: new olStyle.Fill({
color: "#AB1F58",
}),
}),
}),
});
feature.setProperties({ value: item.value });
return feature;
});
const newLayer = new olLayer.Heatmap({
source: new olSource.Vector({
features,
}),
blur: 0,
radius: 50,
weight(feature) {
return feature.getProperties().value / 10;
},
});
map.addLayer(newLayer)
Example image
My problem is that OpenLayers sums the values when the features overlap but I would like the overlap area to have the average value.
Is this possible or should I look for another solution?
One way that I can think of is by using a Cluster source. Write your own createCluster function to return a new feature with an average value and display this.

Drawing a circle around a point in vue2-google-maps

I am using Vue to build a site that takes in some data and displays a google map with markers and circles around the points with the markers.
So far I can create the map with markers perfectly fine, however I have no idea what the proper way to create a circle is with the Vue2-google-maps package, despite having combed through the Documentation for a long time.
Here is the code so far
<GmapMap
:center="center"
:zoom="10"
class="google-map">
<GmapMarker
:key="index"
v-for="(pin, index) in markers"
:position="pin.position"
:icon="pin.icon"
:clickable="true"
:draggable="true"
#click="center=pin.position">
</GmapMarker>
<GmapCircle
:key="index"
v-for="(pin, index) in markers"
:center="pin.position"
:radius="1000"
:visible="true"
:fillColor="red"
:fillOpacity:="1.0">
</GmapCircle>
</GmapMap>
Note that markers is a list of markers that is created somewhere else in the code.
If you take out the tags, the code works perfectly fine placing all the markers. I just need to know what the proper tag/object set is for creating a circle.
You are on the right track, GmapCircle component in vue2-google-maps library is intended for creating circles on the map. There are might be several reasons why circles are not getting displayed:
center property value is invalid, the supported format is {lat: <lat>, lng: <lng>} or google.maps.LatLng value
maybe you could not spot them due to relatively small size (given the provided 2 kilometer diameter, they could be easily missed)?
Regarding fillColor and fillOpacity properties, they need to be passed via options property, e.g. :options="{fillColor:'red',fillOpacity:1.0}"
Anyway the following example demonstrates how to create circles on map via vue2-google-maps
<GmapMap :center="center" :zoom="zoom" ref="map">
<GmapCircle
v-for="(pin, index) in markers"
:key="index"
:center="pin.position"
:radius="100000"
:visible="true"
:options="{fillColor:'red',fillOpacity:1.0}"
></GmapCircle>
</GmapMap>
export default {
data() {
return {
zoom: 5,
center: { lat: 59.339025, lng: 18.065818 },
markers: [
{ Id: 1, name: "Oslo", position: { lat: 59.923043, lng: 10.752839 } },
{ Id: 2, name: "Stockholm", position: { lat: 59.339025, lng: 18.065818 } },
{ Id: 3, name: "Copenhagen", position: { lat: 55.675507, lng: 12.574227 }},
{ Id: 4, name: "Berlin", position: { lat: 52.521248, lng: 13.399038 } },
{ Id: 5, name: "Paris", position: { lat: 48.856127, lng: 2.346525 } }
]
};
},
methods: {}
};
in my case, i had error that saw:" GmapCircle not define component", so i have used this code:
<gmap-circle
v-for="(infoWindow, index) in arrayMarkers"
:key="'circle_'+index"
radius="100"
:center="infoWindow.position"
/>

Filter data by using nodejs

from one API I am getting these type of response. I need to get latitude, longitude of single entity. How can I filter this data by using javascript (node js).
header {
gtfs_realtime_version: "1.0"
incrementality: FULL_DATASET
timestamp: 1501132018
}
entity {
id: "1"
vehicle {
trip {
trip_id: "141.180717.42.1145"
schedule_relationship: SCHEDULED
route_id: "4T.C.141"
}
position {
latitude: -29.77179
longitude: 151.11717
bearing: 90.00001
}
timestamp: 1501131987
congestion_level: UNKNOWN_CONGESTION_LEVEL
stop_id: "23604"
vehicle {
id: "141"
label: "11:45am (141) Grafton City - Moree Town"
}
}
}
entity {
id: "2"
vehicle {
trip {
trip_id: "511.160717.90.1416"
schedule_relationship: SCHEDULED
route_id: "4T.C.511"
}
position {
latitude: -32.09544
longitude: 148.06787
bearing: 313.0
}
timestamp: 1501131974
congestion_level: UNKNOWN_CONGESTION_LEVEL
stop_id: "28211"
vehicle {
id: "511"
label: "02:16pm (511) Dubbo - Bourke"
}
}
}
All these data are of transportation API. If it would have been in JSON then we can get it by using foreach and by using its index.
Use javascript map function and extract only those fields which you want.

Amcharts - Maps: bad coordinates (lat/long) on a custom map (county level Romania)

I'm trying to add cities on a county map. The lat and long are drawn corectcly on the full size map(Romania level) but on the county map these are drawn wrong. I think I should rescale the map or lat/long of the city, I don't know...
How should I generate the county map in accordance with cities lat/long?
The code is listed below:
http://jsfiddle.net/xzAx7/33/
var map;
AmCharts.ready(function() {
map = new AmCharts.AmMap();
map.pathToImages = "http://www.ammap.com/lib/images/";
//map.panEventsEnabled = true; // this line enables pinch-zooming and dragging on touch devices
map.balloon.color = "#000000";
var wordlDataProvider = {
mapVar: AmCharts.maps.Cluj,
getAreasFromMap: true,
areas: [
{ id: "FR", color: "#4444ff" },
{ id: "RU", color: "#4444ff" },
{ id: "US", color: "#4444ff" }
],
images: [{
title: "ClujNapoca",
latitude: 46.85307355,
longitude: 23.63327696,
type: "circle",
color: "red",
scale: 0.5
}, {
title: "Turda",
latitude: 46.5745618,
longitude: 23.78573862,
type: "circle",
color: "red",
scale: 0.5
}]
};
map.dataProvider = wordlDataProvider;
map.areasSettings = {
autoZoom: true,
selectedColor: "#CC0000"
};
map.write("mapdiv");
});
I've found the solution. You need to define "defs" properties (leftLongiitude, ...) when you create a custom map. This is specified in this article - https://www.amcharts.com/tutorials/creating-custom-maps-for-javascript-ammap/
In the amCharts article is explained how you can get these "defs" properties.
I've changes the code below to understand how it works
"defs": {
"amcharts:ammap": {
"projection":"mercator",
"leftLongitude":"22.607117",
"topLatitude":"47.363798",
"rightLongitude":"24.261932",
"bottomLatitude":"46.384241"
}
}
demo: http://jsfiddle.net/xzAx7/35/

different markers groups in leaftlet

I am using Angular and leaflet and want to build a map with different markers, eg.: ships and bridges. I want to update them individually without removing and setting all markers again. So when I have new ships, I just want to call the ship markers, update them and the bridge markers stay the same.
Right now, I tried something like this:
angular.module('angularMapApp')
.controller('MainCtrl', ['$scope', 'RequestService', 'setShipMarkers', '$q', function($scope, RequestService, setShipMarkers, $q) {
angular.extend($scope, {
hamburg: {
lat: 53.551086,
lng: 9.993682,
zoom: 13
},
markers: {
ships: {
m1: {
lat: 42.20133,
lng: 2.19110
},
m2: {
lat: 42.21133,
lng: 2.18110
}
},
bridges: {
m3: {
lat: 42.19133,
lng: 2.18110
},
m4: {
lat: 42.3,
lng: 2.16110
}
}
},
defaults: {
tileLayer: 'http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png',
zoomControlPosition: 'topright',
tileLayerOptions: {
opacity: 0.9,
detectRetina: true,
reuseTiles: true,
},
scrollWheelZoom: false
}
});
But this does not works, as I get the following error (after setting markers-nested: true in my view):
You must add layers to the directive if the markers are going to use
this functionality.
However why do I need layers, if I just want to call different markers group on the same layer. I just do not want to update all of them at once.
So maybe someone can tell me, how to get separate marker groups and how to call them to update them.
For each kind of nested marker you have to create its own group layer like this, they can be empty:
layers: {
overlays: {
ships: { // use the same name as in the marker object
name: "Ships",
type: "group",
visible: true
},
bridges: { // use the same name as in the marker object
name: "bridges",
type: "group",
visible: true
}
}
}
By doing that you will also have to move the OSM base layer into the layers.baselayers object, but markers-nested="true" works this way.
Demo: http://plnkr.co/edit/HQx8bQmmsFUGcLxYt95N?p=preview

Categories