Creating n number of circles on google map with ng-maps - angularjs

I've read a few other posts that are similar in nature on SO, but I still don't understand what I have done wrong.
I want to create multiple circles on a google map from a json string configured like:
[
{"name":"0","lat":30.45,"long":91.15},
{"name":"1","lat":0.0,"long":0.0},
{"name":"5","lat":0.0,"long":0.0}
]
I am hoping I can just iterate through the string and set the respective values.
The variable geofences is bound to the containing div with the ng-app declaration.
This is my current try:
<ng-map class=map zoom="15" center="[30.45, -91.15]">
<marker position="[30.45, -91.15]" />
<shape
ng-repeat="fence in geofences"
name="{{fence.name}}"
radius="40"
center="[{{fence.lat}}, {{fence.long}}]"
radius="40" />
<control name="overviewMap" opened="true" />
</ng-map>
I expect it has something to do with getting the values from a variable as if I hard code a value it works
This is what the Chrome developer console output:
angular.js:12332 TypeError: Cannot read property 'id' of undefined
and at the very bottom of the stack trace:
<shape ng-repeat="fence in geofences" name="{{fence.name}}" center="[{{fence.lat}}, {{fence.long}}]" radius="40" class="ng-scope >
What have I done incorrectly or worst case scenario how could I do something like this?

Most likely you are getting this error since google.maps.Circle object could not be created. shape directive expects name attribute that corresponds to map object (see below list), the provided values (e.g. "0" or "1") are invalid
The list of supported shape names:
circle
polygon
polyline
rectangle
groundOverlay
image
So, since your goal is to display circles, specify for name attribute cicrle value:
<shape ng-repeat="fence in geofences"
name="circle"
radius="40"
center="[{{fence.lat}}, {{fence.long}}]"
/>
Example
var app = angular.module('mapApp', ['ngMap']);
app.controller('mapCntrl', function ($scope) {
$scope.geofences = [
{ "name": "circle", "lat": 30.45, "long": -91.15 }
];
});
<script src="https://maps.google.com/maps/api/js?libraries=placeses,visualization,drawing,geometry,places"></script>
<script src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<div ng-app="mapApp" ng-controller="mapCntrl">
<ng-map class=map zoom="15" center="[30.45, -91.15]">
<marker position="[30.45, -91.15]" />
<shape ng-repeat="fence in geofences"
name="circle"
radius="40"
center="[{{fence.lat}}, {{fence.long}}]"
/>
<control name="overviewMap" opened="true" />
</ng-map>
</div>
Plunker

Related

Make multiple small rectangles inside big rectangle using svg and ng-repeat

I have this code where I need to display multiple small rectangles inside a big rectangle and I need to do this entire process multiple times.
here is my data:
"data": {
"rect1": {
"a":[10,20],
"b":[35,10]
},
"rect2": {
"y":[25,10],
"z":[55,20]
}
}
This data should make two rectangles rect1 and rect2 and two rectangles inside each of them a,b and y,z respectively. each small rectangle has start position x and width of that small rectangle for example a starts at x 10 and width=20.
<ul>
<li ng-repeat="(rect,coords) in data">
<svg>
<rect x=1 y=1 width=1000 height=50 style="fill:grey;" />
<span ng-repeat="coord in coords">
<rect x={{coord[0]}} y=1 width={{coord[1]}} height=50 style="fill:blue;" />
enter code here
But this code is not working as I have added ng-repeat line between the two tags.
image of what the final result should look like
I made this image in powerpoint so ignore the background.
You were pretty close. You can't use <span> inside an SVG. But most of the rest was correct.
Also it is better to use ng-attr-x="{{value}} instead of x="{{value}}. Otherwise the SVG parser will throw errors because it doesn't understand the string "{{value}}".
Here is a working example.
var app = angular.module('myApp', [])
app.controller("AppCtrl", ["$scope", function($scope) {
$scope.data = {
"rect1": {
"a":[10,20],
"b":[35,10]
},
"rect2": {
"y":[25,10],
"z":[55,20]
}
};
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<ul ng-controller="AppCtrl">
<li ng-repeat="(rectName, coords) in data">
<svg id="{{rectName}}" width="100%" height="50">
<rect x="1" y="1" width="1000" height="50"
style="fill: lightgrey;" />
<rect ng-repeat="(label, coord) in coords"
ng-attr-x="{{coord[0]}}" y="1"
ng-attr-width="{{coord[1]}}" height="50"
style="fill: blue;" />
<text ng-repeat="(label, coord) in coords"
ng-attr-x="{{coord[0]}}" y="25"
style="fill: white;">{{label}}</text>
</svg>
</li>
</ul>
</div>

Angular material as foreignObject inside SVG

My general purpose is to make a dynamic and very simple flowchart view. I use svg and angular material. I am trying to show angular material objects like (md-select, md-menu, md-button) inside SVG. After a quick research I saw it is possible with "foreignObject" tags.
Secondly; I want to move all these elements at once inside SVG regarding mouse panning. So I use "viewBox" property.
In my sample;
I use "foreignObject" tag to show angular material "md-select" inside a svg element.
I expect "md-select" to move when I change x and y values of viewBox property of svg element but it keeps its position while clickable area changes.
When I try same scenario with html "select" it moves as I expect. But I can't do the same with angular material objects. (they visually stay in their original position but their click area goes another where regarding viexBox x-y values.)
<div ng-controller="MyCtrl">
x: <input ng-model="vbx">
y: <input ng-model="vby">
<svg id="processDesignPanel" viewBox="{{vbx}} {{vby}} 500 500" name="processDesignPanel" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="800px" height="800px">
<foreignObject width="100" height="50" x="100" y="100">
<md-select placeholder="Assign to user" ng-model="userkey" style="width: 200px;">
<md-option ng-repeat="user in formusers">{{user}}</md-option>
</md-select>
</foreignObject>
<foreignObject width="100" height="50" x="100" y="200">
<select placeholder="Assign to user" ng-model="userkey" style="width: 150px;">
<option ng-repeat="user in formusers">{{user}}</option>
</select>
</foreignObject>
</svg>
</div>
sample js
angular.module('MyApp', ['ngMaterial'])
.controller('MyCtrl', function ($scope) {
$scope.formusers=["ally","mike"];
$scope.vbx=null;
$scope.vby=null;
})
here is my fiddle.
This isn't a complete solution, but I think it's a couple steps in that direction. I cut down your fiddle to show the incorrectly-placed MD select along with the correctly-placed regular select, with a button that modifies the style of the md-select-value tag to have position:inherit and z-index:auto, which makes the MD select appear in the correct place. I don't know why it does this, yet, as I haven't delved into the lib's CSS.
document.getElementsByTagName('md-select-value')[0].setAttribute('style','z-index:auto; position:inherit')
https://jsfiddle.net/emamid/n8tr0gfk/6/

Using ngmaps with json data

I am trying to use the ngmaps directive for ionic but it doesnt seem to display anything when i use it. I am trying to create the url with json data, it should be putting latitude and longitude into the map center but nothing shows up, not even the map.
<div id="gmap" ng-controller="mapCtrl">
<div map-data="https://maps.google.com/maps/api/js"
map-data-params="{{googleMapsUrl}}">
<ng-map center="{{office.LatLong}}" zoom="3"></ng-map>
</div>
.controller('mapCtrl', function(NgMap, $scope) {
NgMap.getMap().then(function(map) {
console.log(map.getCenter());
//console.log('markers', map.markers);
//console.log('shapes', map.shapes);
$scope.googleMapsUrl="https://maps.googleapis.com/maps/api/js?key=AIzaSyBGAHnplGPjFoVvShk6Tsna3-DN8rHQBI8";
});
})
Here is a working Plunker based on ngmap:
There was a problem with your divs (not closing), here is the right sintax:
<div id="gmap" >
<div map-data="https://maps.google.com/maps/api/js" map-data-params="{{googleMapsUrl}}">
<ng-map center="{{office.LatLong}}" zoom="4"></ng-map>
</div>
</div>

How do I implement clickable windows on markers using Angular Google Maps?

I have tried this every-which-way and still no luck. Please bear with me, I am a designer by trade.
I have created a Plunker of where I am so far.
I am using Angular Google Maps to create a map upon which I would like to output my markers, clicking one of which will open its info-window. Within each info window I would like to have some interactive content e.g. buttons, links, marching bands etc
My problem is multi-faceted:
When I place the info window html inside the tag none of the variables are displayed unless a ng-non-bindable is placed on a parent. However, I want the content to be interactive. As you will see in my code, the button does nothing.
<ui-gmap-windows show="show">
<div class="markerwindow" ng-non-bindable>
<h1>{{ title }}</h1>
<p>{{ message }}</p>
<footer>
Google
<button click="buttonClick(id)">Button</button>
</footer>
</div>
</ui-gmap-windows>
I cannot separate the template out into a separate file [I expect the info window to end up being pretty significant] using templateUrl on the without this error:
"Possibly unhandled Error: error within chunking iterator: Error:
[jqLite:nosel] Looking up elements via selectors is not supported by
jqLite!"
<ui-gmap-windows show="show" templateUrl="templates/window.html">
</ui-gmap-windows>
Finally, I weep to myself sometimes when I read documentation...
Could someone help me identify the issues with my approach? I would really appreciate even a flake of help because I'm really struggling to see a way over this obstacle at the moment.
Thanks in advance.
The templateURL attribute is a property on your marker object. Here is some code I'm currently working on:
function createMarkers(data) {
$scope.markers = data.map(function(marker){
var tags = marker.tags.map(function(tag){
return {
tag: tag.tag,
url: tag.url
}
})
return ({
id: marker.id,
latitude: marker.position.lat,
longitude: marker.position.lng,
info: {
title: marker.item,
description: marker.note,
place: marker.position.place,
tags: tags
},
template: "views/partials/main/gmapWindow.html"
})
})
}
As you can see I have a property named template that contains an url to a template (partials might not be the best naming...). Also note that I have a property called info that contains stuff like title and description.
My ui-gmap-google-map-directive looks like this:
<ui-gmap-google-map center='map.center' zoom='map.zoom'>
<ui-gmap-markers models="markers" coords="'self'" icon="'icon'">
<ui-gmap-windows
templateUrl="'template'"
templateParameter="'info'"
show="'showWindow'"
closeClick="'closeClick'"
></ui-gmap-windows>
</ui-gmap-markers>
</ui-gmap-google-map>
Note that I use both " as well as ' in templateUrl and templateParameter. templateUrl is the property that contains a string to a template (this way we can use different template for different markers) and templateParameter is also a property in the markers-model. That property contains an object that we pass into the template.
Finally we can create our template and access the object that we passed into it, in my case the info-object that where a property on the model.
<div>
<h3>{{ :: parameter.title }}</h3>
<p><em>{{ :: parameter.description }}</em></p>
<p><strong>{{ :: parameter.place }}</strong></p>
<p class="muted">Tags: <tags marker="{{ :: parameter.tags }}" /></p>
</div>
Oh, and I weep as well when reading the documentation...

AngularJs - Error while using index of ng-repeat in map element

I'm trying to launch an ng-click function inside an ng-repeat but I get a problem, while clicking the element, the function always pick the last occurrence of my loop.
To be more precise here's an example:
<div ng-controller="qualityController">
<div ng-repeat="quality in qualities">
<img src ={{ asset('bundles/mybundle/img/jauge_normal.png') }} width="160" height="160" alt="Circle" usemap="#circle">
<div class="g-performance-rate-knob">
<input type="text" data-angleOffset=180 data-angleArc=360 data-fgColor="#ff7200" data-width="116" data-height="116" data-step="0.1" data-min="0" data-max="100" data-readOnly=true knob class="dial" ng-model="quality.note">
</div>
<map name="circle" id="circle" ng-click="loadQualityDetail(quality.id)">
<area shape="circle" coords="80,80,80" data-toggle="modal" data-target="#modal-stars-{[{ quality.id }]}" class="more" alt=""/>
</map>
</div>
</div>
Js:
app.controller('qualityController', function ($scope,$http)
{
qualities = [];
qualities.push({id : 1});
qualities.push({id : 2});
qualities.push({id : 3});
qualities.push({id : 4});
$scope.loadQualityDetail = function(qualityId)
{
console.log(qualityId);
}
});
Wherever I click, I get "4" in my console.
Note: I use jQuery Knob library. But it seems like the problem appear on map or area elements.
If you need more information please tell me I could make a fiddle.
Thanks by advance,

Resources