Cluster Layer in Arcgis - arcgis

Can someone please help me out of this problem. What's wrong in the above code it will not shows any error but cluster layer not displaying.Remaining features are working.I am using this example https://github.com/nickcam/FlareClusterLayer
var dojoConfig = {
async: true,
packages: [{
name: 'extras',
location: location.pathname.replace(/[^\/]+$/, '') + 'JS/extras'
}]
};
var findTask, findParams;
ready(function () {
parser.parse();
var clusterLayer;
// registry.byId("ddlDistrict").on("onchange", doFind);
var intialextent = new Extent(8245227.8765913, 1297819.43274543, 8758703.79511306, 2095175.01113784, new SpatialReference({ wkid: 102100 }));
var AgricultureBoundary = new ArcGISDynamicMapServiceLayer("http://[myserver]/arcgisserver/rest/services/CRD/CRD1/MapServer", {
opacity: 0.75
});
var pointFeatureLayer = new FeatureLayer("http://[myserver]/arcgisserver/rest/services/CRD/CRD2/FeatureServer/0", {
id: "Points"
});
map = new Map("mapDiv", {
center: [77.2, 14],
zoom: 7,
extent: intialextent,
basemap: "streets",
});
map.addLayers([AgricultureBoundary, pointFeatureLayer]);
var queryTask = new esri.tasks.QueryTask("http://[myserver]/arcgisserver/rest/services/CRD/CRD2/FeatureServer/0");
var query = new esri.tasks.Query();
query.returnGeometry = true;
query.where = "pointcollected = 'No'";
query.outFields = ["*"];
dojo.connect(queryTask, "onComplete", function (featureSet) {
var inputInfo = {};
inputInfo.data = dojo.map(featureSet.features, function (feature) {
var pointX = feature.geometry.x;
var pointY = feature.geometry.y;
var att = feature.attributes;
return { "x": pointX, "y": pointY, "attributes": att };
});
clusterLayer = new ClusterFeatureLayer({
"data": inputInfo.data,
"distance": 1,
"id": "clusters",
"labelColor": "#fff",
"labelOffset": 10,
"resolution": map.extent.getWidth() / map.width,
"singleColor": "#888",
"singleTemplate": infoTemplate
});
var defaultSym = new esri.symbol.SimpleMarkerSymbol().setSize(4);
var renderer = new esri.renderer.ClassBreaksRenderer(defaultSym, "clusterCount");
var blue = new esri.symbol.PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Shapes/BluePin1LargeB.png", 32, 32).setOffset(0, 15);
var green = new esri.symbol.PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Shapes/GreenPin1LargeB.png", 64, 64).setOffset(0, 15);
var red = new esri.symbol.PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Shapes/RedPin1LargeB.png", 72, 72).setOffset(0, 15);
renderer.addBreak(0, 2, blue);
renderer.addBreak(2, 200, green);
renderer.addBreak(200, 1001, red);
clusterLayer.setRenderer(renderer);
map.addLayer(clusterLayer);
});
});

Passing data in the constructor like that won't do anything (although it probably should handle it).
Try the below instead:
dojo.connect(queryTask, "onComplete", function (featureSet) {
var inputInfo = {};
inputInfo.data = dojo.map(featureSet.features, function (feature) {
var pointX = feature.geometry.x;
var pointY = feature.geometry.y;
var att = feature.attributes;
return { "x": pointX, "y": pointY, "attributes": att };
});
clusterLayer = new ClusterFeatureLayer({
"distance": 1,
"id": "clusters",
"labelColor": "#fff",
"labelOffset": 10,
"resolution": map.extent.getWidth() / map.width,
"singleColor": "#888",
"singleTemplate": infoTemplate
});
var defaultSym = new esri.symbol.SimpleMarkerSymbol().setSize(4);
var renderer = new esri.renderer.ClassBreaksRenderer(defaultSym, "clusterCount");
var blue = new esri.symbol.PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Shapes/BluePin1LargeB.png", 32, 32).setOffset(0, 15);
var green = new esri.symbol.PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Shapes/GreenPin1LargeB.png", 64, 64).setOffset(0, 15);
var red = new esri.symbol.PictureMarkerSymbol("http://static.arcgis.com/images/Symbols/Shapes/RedPin1LargeB.png", 72, 72).setOffset(0, 15);
renderer.addBreak(0, 2, blue);
renderer.addBreak(2, 200, green);
renderer.addBreak(200, 1001, red);
clusterLayer.setRenderer(renderer);
map.addLayer(clusterLayer);
clusterLayer.addData(inputInfo.data);
});

Related

OpenLayers Vector tiles Styling Optimization

I am new to openlayers and vector layer and i am facing performance problem. I have 3 layers and each layer containing thousands of features. Is it the correct way of styling the layer or is there anything else we can do to further make it even faster even on low end computer. What else can be done in case of geoserver layergroup. How can we efficiently style it since it has many layers and how to get the layers from the layer group.
var gridsetName = "EPSG:900913";
var baseUrl = "http://localhost:8080/geoserver/gwc/service/wmts";
var style = "";
var format = "application/vnd.mapbox-vector-tile";
var layerCache = {};
var gardening_area_uncertainity = new Style({
stroke: new Stroke({
color: "rgba(200,20,20,0.8)",
width: 2,
}),
});
var gardening_point = new Style({
image: new Circle({
stroke: new Stroke({
width: 1,
color: "red",
}),
radius: 2,
}),
});
var layers = [
{
layer: "city:gardenings_point_uncertainity",
style: gardening_area_uncertainity,
},
{ layer: "city:gardening_aiming_area", style: gardening_area_uncertainity },
{ layer: "city:gardening_aiming_point", style: gardening_point },
];
var key = 0;
var styleForLayer = null;
var layerFeature = function (feature) {
//console.log("Type is:",feature.type_)
if (feature.get("layer") === "gardening_aiming_point") key = 1;
else if (feature.get("layer") === "gardenings_point_uncertainity") key = 2;
else if (feature.get("layer") === "gardening_aiming_area") key = 3;
styleForLayer = layerCache[key];
if (!styleForLayer) {
switch (feature.get("layer")) {
case "gardening_aiming_area":
styleForLayer = gardening_area_uncertainity;
break;
case "gardenings_point_uncertainity":
styleForLayer = gardening_area_uncertainity;
break;
case "gardening_aiming_point":
styleForLayer = gardening_point;
break;
}
layerCache[key] = styleForLayer;
}
return styleForLayer;
};
var i;
var view = new View({
center: [0, 0],
zoom: 2,
// constrainResolution:true,
extent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
});
var map = new Map({
layers: [
new TileLayer({
preload: Infinity,
source: new OSM({ cacheSize: 20000 }),
}),
],
target: "map",
view: view,
});
map
.getView()
.fit([-20037508.34, -20037508.34, 20037508.34, 20037508.34], map.getSize());
map.on("moveend", (evt) => {
console.log(map.getView().getZoom());
});
function constructSource() {
var url = baseUrl + "?";
for (var param in params) {
url = url + param + "=" + params[param] + "&";
}
url = url.slice(0, -1);
var source = new VectorTileSource({
url: url,
format: new MVT({}),
tileGrid: new WMTS({
tileSize: [256, 256],
origin: [-2.003750834e7, 2.003750834e7],
resolutions: resolutions,
}),
});
return source;
}
for (i = 0; i < layers.length; i++) {
//console.log('Layer',layers[i])
var params = {
REQUEST: "GetTile",
SERVICE: "WMTS",
VERSION: "1.0.0",
LAYER: layers[i].layer,
STYLE: style,
TILEMATRIX: gridsetName + ":{z}",
TILEMATRIXSET: gridsetName,
FORMAT: format,
TILECOL: "{x}",
TILEROW: "{y}",
};
var layer = new VectorTileLayer({
source: constructSource(),
preload: Infinity,
renderMode: "image",
style: layers[i].style,
});
map.addLayer(layer);
}

Multiple renderer in esri map

I have requirement which is using classbreakrenderer for showing clusters size as it breaks down, now i want to use one renderer which shows different different symbol for single cluster based on some attribute value.
I have tried to use UniqueValueRenderer but it not working.
Any suggestion
I have requirement which is using classbreakrenderer for showing clusters size as it breaks down, now i want to use one renderer which shows different different symbol for single cluster based on some attribute value.
I have tried to use UniqueValueRenderer but it not working.
I have requirement which is using classbreakrenderer for showing clusters size as it breaks down, now i want to use one renderer which shows different different symbol for single cluster based on some attribute value.
I have tried to use UniqueValueRenderer but it not working.
<script type="text/javascript">
window.dojoConfig = {
async: true,
packages: [
{
name: 'app',
location: window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + '/src'
}
]};
</script>
<!-- ArcGIS API for JavaScript library references -->
<script src="https://js.arcgis.com/3.15compact"></script>
<script>
require(["esri/map",
"esri/dijit/Geocoder",
"esri/dijit/HomeButton",
"esri/renderers/SimpleRenderer",
"esri/symbols/PictureMarkerSymbol",
"esri/layers/FeatureLayer",
"esri/InfoTemplate",
"esri/graphic",
"esri/graphicsUtils",
"app/clusterfeaturelayer",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol",
"esri/symbols/PictureMarkerSymbol",
"esri/renderers/ClassBreaksRenderer",
"esri/renderers/HeatmapRenderer",
"esri/renderers/UniqueValueRenderer",
"dojo/_base/Color",
"dojo/on",
"dojo/dom-style",
"dojo/_base/fx",
"dojo/fx/easing",
"dojo/dom",
"dojo/domReady!"],
function (Map, Geocoder, HomeButton, SimpleRenderer, PictureMarkerSymbol, FeatureLayer, UniqueValueRenderer, InfoTemplate, Graphic, graphicsUtils, ClusterFeatureLayer, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, PictureMarkerSymbol, ClassBreaksRenderer, HeatmapRenderer, Color, on, domStyle, fx, easing, dom) {
// Locals
var map,
popup,
clusterLayer,
geocoder,
infoTemplate,
defaultSym,
selectedSym,
activeClusterElement;
// Create map
map = new Map("mapDiv", {
basemap: "dark-gray",
center: [-120, 50],
zoom: 3
});
// Create widget
geocoder = new Geocoder({
value: "California, United States",
autoNavigate: true,
maxLocations: 25,
autoComplete: true,
arcgisGeocoder: {
outFields: "Place_addr, PlaceName, Score"
},
map: map
}, "search");
geocoder.startup();
var home = new HomeButton({
map: map
}, "homeButton");
home.startup();
// Add raw points
// var featureLayer = new FeatureLayer("http://services.arcgis.com/oKgs2tbjK6zwTdvi/arcgis/rest/services/Major_World_Cities/FeatureServer/0", {
// infoTemplate: infoTemplate,
// outFields: ["*"]
// });
// map.addLayer(featureLayer);
// Add heatmap
// var featureLayer2 = new FeatureLayer("http://services.arcgis.com/oKgs2tbjK6zwTdvi/arcgis/rest/services/Major_World_Cities/FeatureServer/0");
// var heatmapRenderer = new HeatmapRenderer();
// featureLayer2.setRenderer(heatmapRenderer);
// map.addLayer(featureLayer2);
// Add clusters
map.on("load", function () {
// Add layer
addClusterLayer();
addClusterLayerEvents();
});
// Set popup
popup = map.infoWindow;
popup.highlight = false;
popup.titleInBody = false;
popup.domNode.className += " light";
//popup.domNode.style.marginTop = "-17px"; // for pins only
// Popup content
//infoTemplate = new InfoTemplate("Seismic Activity > 4.0", "<p>Location: ${NAME}</p><p>Magnitude: ${OTHER_MAG1}</p><p>Date: ${YEAR}/${MONTH}/${DAY}</p>");
infoTemplate = new InfoTemplate("<b>${CITY_NAME}</b>", "<p>COUNTRY: ${CNTRY_NAME}</p><p>STATE/PROVINCE: ${ADMIN_NAME}</p><p>POPULATION: ${POP}</p>");
// Option 1: Esri marker for single locations and selections
// defaultSym = new createPictureSymbol("./images/blue-cluster-pin.png", 0, 8, 9, 16);
// selectedSym = new createPictureSymbol("./images/blue-cluster-pin.png", 0, 9, 11, 20);
// Option 2: Use circle markers for symbols - Red
defaultSym = new SimpleMarkerSymbol("circle", 16,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([102,0,0, 0.55]), 3),
new Color([255, 255, 255, 1]));
selectedSym = new SimpleMarkerSymbol("circle", 16,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([102,0,0, 0.85]), 3),
new Color([255, 255, 255, 1]));
// Create a feature layer to get feature service
function addClusterLayer() {
var renderer,
renderer1,
small,
medium,
large,
xlarge;
// Add cluster renderer
clusterLayer = new ClusterFeatureLayer({
"url": "http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/World_Cities/FeatureServer/0",
//"url": "http://services.arcgis.com/BG6nSlhZSAWtExvp/arcgis/rest/services/GlobalSeismographyNetwork/FeatureServer/0",
// "url": "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/Since_1970/MapServer/0",
"distance": 95,
"id": "clusters",
"labelColor": "#fff",
"resolution": map.extent.getWidth() / map.width,
//"singleColor": "#888",
"singleSymbol": defaultSym,
"singleTemplate": infoTemplate,
"useDefaultSymbol": false,
"zoomOnClick": false,
"showSingles": true,
"objectIdField": "FID",
outFields: ["*"]
});
renderer = new ClassBreaksRenderer(defaultSym, "clusterCount");
// Red Clusters
small = new SimpleMarkerSymbol("circle", 25,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([212,116,60,0.5]), 15),
new Color([212,116,60,0.75]));
medium = new SimpleMarkerSymbol("circle", 50,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([178,70,37,0.5]), 15),
new Color([178,70,37,0.75]));
large = new SimpleMarkerSymbol("circle", 80,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([144,24,13,0.5]), 15),
new Color([144,24,13,0.75]));
xlarge = new SimpleMarkerSymbol("circle", 110,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([102,0,0,0.5]), 15),
new Color([102,0,0,0.75]));
// Break values - can adjust easily
renderer.addBreak(2, 50, small);
renderer.addBreak(50, 250, medium);
renderer.addBreak(250, 1000, large);
renderer.addBreak(1000, 50000, xlarge);
// Providing a ClassBreakRenderer is also optional
clusterLayer.setRenderer(renderer);
//added second renderer
var renderer1 = new UniqueValueRenderer(defaultSymbol, "CNTRY_NAME");
//add symbol for each possible value
renderer1.addValue("United States", new PictureMarkerSymbol({
"angle": 0,
"xoffset": 0,
"yoffset": 8,
"type": "esriPMS",
"url": "./images/blue-pin.png",
"contentType": "image/png",
"width": 24,
"height": 24
}));
renderer1.addValue("Argentina", new PictureMarkerSymbol({
"angle": 0,
"xoffset": 0,
"yoffset": 12,
"type": "esriPMS",
"url": "./images/blue-cluster-pin.png",
"contentType": "image/png",
"width": 24,
"height": 24
}));
//added to cluster
clusterLayer.setRenderer(renderer1);
map.addLayer(clusterLayer);
}
// Create png marker
// function createPictureSymbol(url, xOffset, yOffset, xWidth, yHeight) {
// return new PictureMarkerSymbol(
// {
// "angle": 0,
// "xoffset": xOffset,
// "yoffset": yOffset,
// "type": "esriPMS",
// "url": url,
// "contentType": "image/png",
// "width": xWidth,
// "height": yHeight
// }
// );
// }
// Create new graphic and add to map.graphics
function addSelectedFeature() {
var selIndex = map.infoWindow.selectedIndex,
selFeature;
if (selIndex !== -1) {
selFeature = map.infoWindow.features[selIndex];
// Remove old feature first
removeSelectedFeature();
// Add new graphic
map.infoWindow._lastSelected = new Graphic(selFeature.toJson());
map.infoWindow._lastSelected.setSymbol(selectedSym);
map.graphics.add(map.infoWindow._lastSelected);
}
}
// Remove graphic from map.graphics
function removeSelectedFeature() {
if (map.infoWindow._lastSelected) {
map.graphics.remove(map.infoWindow._lastSelected);
map.infoWindow._lastSelected = null;
}
}
// Highlight clusters
function setActiveClusterOpacity(elem, fillOpacity, strokeOpacity) {
var textElm;
if (elem) {
elem.setAttribute("fill-opacity", fillOpacity);
elem.setAttribute("stroke-opacity", strokeOpacity);
// Overide inherited properties for the text in the circle
textElm = elem.nextElementSibling;
if (textElm && textElm.nodeName === "text") {
textElm.setAttribute("fill-opacity", 1);
}
}
}
// Hide popup if selected feature is clustered
function onClustersShown(clusters) {
var i = 0,
extent;
if (map.infoWindow.isShowing && map.infoWindow._lastSelected) {
for (i; i < clusters.length; i++) {
if (clusters[i].attributes.clusterCount > 1) {
extent = clusterLayer._getClusterExtent(clusters[i]);
if (extent.contains(map.infoWindow._lastSelected.geometry)) {
map.infoWindow.hide();
break;
}
}
}
}
}
// Wire cluster layer events
function addClusterLayerEvents() {
// Mouse over events
clusterLayer.on("mouse-over", onMouseOverCluster);
clusterLayer.on("mouse-out", onMouseOutCluster);
// Clusters drawn
clusterLayer.on("clusters-shown", onClustersShown);
}
// Save the last selected graphic so we can highlight it
map.infoWindow.on("selection-change", function () {
addSelectedFeature();
animateInfoWindow();
});
// Clear selected graphic when infoWindow is hidden
map.infoWindow.on("hide", function () {
// re-activate cluster
setActiveClusterOpacity(activeClusterElement, 0.75, 0.5);
removeSelectedFeature();
});
// Popup enhancements
function onMouseOverCluster(e) {
if (e.graphic.attributes.clusterCount === 1) {
e.graphic._graphicsLayer.onClick(e);
} else {
if (e.target.nodeName === "circle") {
activeClusterElement = e.target;
setActiveClusterOpacity(activeClusterElement, 1, 1);
} else {
setActiveClusterOpacity(activeClusterElement, 1, 1);
}
}
}
function onMouseOutCluster(e) {
if (e.graphic.attributes.clusterCount > 1) {
if (e.target.nodeName === "circle" || e.target.nodeName === "text") {
setActiveClusterOpacity(activeClusterElement, 0.75, 0.5);
setActiveClusterOpacity(e.target, 0.75, 0.5);
}
}
}
function animateInfoWindow() {
domStyle.set(map.infoWindow.domNode, "opacity", 0);
fx.fadeIn({node: map.infoWindow.domNode,
duration: 150,
easing: easing.quadIn}).play();
}
// Click to close
map.on('click', function () {
if (map.infoWindow.isShowing) {
map.infoWindow.hide();
}
});
// ESC is pressed
map.on('key-down', function (e) {
if (e.keyCode === 27) {
map.infoWindow.hide();
}
});
// Dynamically reposition popups when map moves
map.on('extent-change', function () {
if (map.infoWindow.isShowing) {
map.infoWindow.reposition();
}
});
// Auto recenter map - optional
autoRecenter(map);
function autoRecenter(map) {
on(map, 'load', function (map) {
on(window, 'resize', map, map.resize);
});
on(map, 'resize', function(extent, width, height) {
map.__resizeCenter = map.extent.getCenter();
setTimeout(function() {
map.centerAt(map.__resizeCenter);
}, 100);
});
}
});
</script>
</head>
<body>
<div id="mapDiv"></div>
<div id="search"></div>
<div id="homeButton"></div>
</body>
</html>

Append Existing Pdf to Jspdf

I am using the jspdf library to create a pdf and its working out great. I am now trying to append to that pdf another existing pdf. At the moment when my user clicks the download button it fires off two separate downloads. I was thinking that a work around might be creating two images and adding them to my pdf created with Jspdf. Has anyone appended an existing pdf to a pdf generated using jspdf?
$(document).ready(function () {
var doc = new jsPDF('p', 'pt', 'letter');
var imgData = 'cats.jpg'
var specialElementHandlers = {
'#content': function (element, renderer) {
return true;
}
};
$('#cmd').click(function () {
doc.addImage(imgData, 'JPEG', 0, 250, 615, 200);
doc.fromHTML($('#content').get(0), 0, 0, {
'elementHandlers': specialElementHandlers
});
doc.save('TemporaryIdCard.pdf');
});
});
I ended up hacking an answer from here.
Not thrilled about it but it works. I created images from the content in the PDF I was trying to append and then added each as a page to my doc
var doc = new jsPDF('p', 'pt', 'letter');
var imgData = 'cats.jpeg';
var imgData2 = 'dogs.jpeg';
var imgData3 = 'kittens.jpeg';
var specialElementHandlers = {
'#content': function (element, renderer) {
return true;
}
};
var pageHeight = doc.internal.pageSize.height;
var y = 800;
var x = 800;
$('#cmd').click(function () {
doc.addImage(imgData, 'JPEG', 0, 250, 615, 200);
doc.fromHTML($('#content').get(0), 0, 0, {
'elementHandlers': specialElementHandlers
});
if (y >= pageHeight) {
doc.addPage();
doc.addImage(imgData3, 'JPEG', 45, 45, 500, 550);
y = 0;
}
if (x >= pageHeight) {
doc.addPage();
doc.addImage(imgData2, 'JPEG', 50, 70, 500, 500);
x = 0;
}
doc.save('TemporaryIdCard.pdf');
});

Adding graphic layer to map in arcgis java script api

I am using arcgis js api.I have called all necessary esri class modules and all class name in order. I am using query task to add points to map as a graphic layer.I am getting error for graphic.I am not able to trace the error.
var map;
var toc;
var mapserviceurl = "http://......./arcgisserver/rest/services/CRD/CRD1/MapServer";
require(["dojo/parser",
"dojo/on", "esri/map","esri/dijit/HomeButton",
"esri/dijit/Measurement", "dojo/_base/lang","esri/layers/ArcGISDynamicMapServiceLayer",
"esri/layers/FeatureLayer","esri/graphic","esri/layers/GraphicsLayer",
"esri/dijit/Scalebar","esri/dijit/BasemapGallery","esri/toolbars/navigation",
"esri/dijit/OverviewMap","esri/geometry/Extent","esri/SpatialReference",
"esri/geometry/webMercatorUtils","esri/tasks/query","esri/tasks/QueryTask",
"esri/toolbars/draw","esri/symbols/SimpleLineSymbol","esri/symbols/SimpleFillSymbol",
"esri/symbols/PictureMarkerSymbol","esri/symbols/SimpleMarkerSymbol",
"esri/renderers/SimpleRenderer","esri/geometry/Point","esri/Color",
"agsjs/dijit/TOC","esri/InfoTemplate", "esri/tasks/IdentifyTask",
"esri/tasks/IdentifyParameters", "esri/dijit/Popup", "dojo/dom-construct",
"esri/tasks/locator","dojo/_base/array", "dojo/domReady!"],
function (parser, on, Map, HomeButton, Measurement,lang, ArcGISDynamicMapServiceLayer, FeatureLayer, graphic, GraphicsLayer, Scalebar, BasemapGallery, Navigation, OverviewMap, Extent, SpatialReference,
webMercatorUtils, Query, QueryTask, DrawToolbar, SimpleLineSymbol, SimpleFillSymbol,
PictureMarkerSymbol, SimpleMarkerSymbol, SimpleRenderer,Point,Color,TOC,InfoTemplate,IdentifyTask,IdentifyParameters,
Popup,domConstruct,Locator,arrayUtils) {
parser.parse();
createDialogs();
var identifyTask, identifyParams;
var intialextent = new Extent(7778597.959975056, 1564947.1810059766, 9217107.340624947, 2133123.2518000016, new SpatialReference({ wkid: 102100 }));
map = new Map("divMap", {
basemap: "streets",
center: [75, 14],
zoom: 7,
extent: intialextent,
logo: false,
fitExtent: true,
slider: true
});
var operationalLayer = new ArcGISDynamicMapServiceLayer(mapserviceurl);
var samplelocations = new GraphicsLayer({ id: "Samplelocations" });
var samplelocationsSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10, SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([239, 107, 0]), 1), new Color([239, 107, 0]));
var samplelocationrenderer = new SimpleRenderer(samplelocations);
samplelocations.setRenderer(samplelocationrenderer);
var home = new HomeButton({
map: map
}, "HomeButton");
home.startup();
map.on('layers-add-result', function (evt) {
try {
var toc = new TOC({
map: map,
layerInfos: [{
layer: pointFeatureLayer,
title: "My Feature"
}, {
layer: operationalLayer,
title: "Dynamic Map"
}]
}, "tocDiv");
toc.startup();
toc.on("load", function () {
console.log("TOC loaded");
});
}
catch (e) {
console.error(e.message);
}
});
map.addLayers([operationalLayer, pointFeatureLayer, samplelocations]);
var basemapGallery = new BasemapGallery({
showArcGISBasemaps: true,
map: map
}, "basemapGallery");
basemapGallery.on("load", function () {
basemapGallery.remove('basemap_1');
basemapGallery.remove('basemap_2');
basemapGallery.remove('basemap_3');
basemapGallery.remove('basemap_4');
basemapGallery.remove('basemap_5');
basemapGallery.remove('basemap_8');
});
basemapGallery.startup();
var Scalebar = new Scalebar({
map: map,
scalebarUnit: 'metric',
scalebarStyle: 'line'
});
var measurement = new Measurement({
map: map
}, measurementDiv);
measurement.startup();
map.on("mouse-move", showcoordiantes);
map.on("mouse-drag", showcoordiantes);
//overview tools
var OverviewMap = new OverviewMap({
map: map,
attachTo: "bottom-right",
color: " #D84E13",
opacity: .40
});
OverviewMap.startup();
function showcoordiantes(evt) {
var p = webMercatorUtils.webMercatorToGeographic(evt.mapPoint);
$("#latlong").html("Lat,Long : " + p.y.toFixed(4) + "," + p.x.toFixed(4));
}
$("#ClearGraphics").click(function (e) {
e.preventDefault();
// drawtools.deactivate();
map.infoWindow.hide();
map.setMapCursor("default");
map.graphics.clear();
});
var navToolbar = new Navigation(map);
//zoom In
$("#ZoomInTool").click(function (e) {
e.preventDefault();
map.setMapCursor("url('images/cursors/zoomin.cur'), auto");
navToolbar.activate(Navigation.ZOOM_IN);
});
//ZoomOut
$("#ZoomOutTool").click(function (e) {
e.preventDefault();
map.setMapCursor("url('images/cursors/zoomout.cur'), auto");
navToolbar.activate(Navigation.ZOOM_OUT);
});
//Pan
$("#panTool").click(function (e) {
e.preventDefault();
map.setMapCursor("url('images/cursors/pan.cur'), auto");
navToolbar.activate(Navigation.PAN);
});
//FullExtent
$("#zoomfullext").click(function (e) {
e.preventDefault();
map.setMapCursor("default");
navToolbar.deactivate();
// navToolbar.zoomToFullExtent();
map.setExtent(intialextent, true);
});
//Zoom to previous
$("#zoomtoPrevExtent").click(function (e) {
e.preventDefault();
map.setMapCursor("default");
navToolbar.deactivate();
navToolbar.zoomToPrevExtent();
});
//Zoom to Next
$("#zoomtoNextExtent").click(function (e) {
e.preventDefault();
map.setMapCursor("default");
navToolbar.deactivate();
navToolbar.zoomToNextExtent();
});
map.on("load", showresults)
function showresults() {
var queryTask = new esri.tasks.QueryTask('http://......./arcgisserver/rest/services/CRD/CRD2/MapServer/0');
var query = new esri.tasks.Query();
symbol = new esri.symbol.SimpleMarkerSymbol();
symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE);
symbol.setSize(10);
symbol.setColor(new dojo.Color([255, 255, 0, 0.5]));
query.returnGeometry = true;
query.outFields = ["*"];
query.outSpatialReference = map.spatialReference;
query.where = "objectid = '" + 5281902 + "'";
map.graphics.clear();
queryTask.execute(query, addPointsToMap);
function addPointsToMap(featureSet) {
var graphic = featureSet.features;
graphic.setSymbol(symbol);
map.graphics.add(graphic);
var extent = esri.graphicsExtent(features);
if (extent) {
map.setExtent(extent)
}
}
}
});
I am getting error as
You are assigning an array to the graphic variable:
var graphic = featureSet.features;
Select a single feature of the array and set the symbol then e.g.
var graphic = featureSet.features[0];

Google Maps API V3 and Airline Route Map

I'm trying to create an interactive route map like the ones airlines have and I'm using Google Maps API v3. I was able to put markers on the map for outstations and different markers for hubs. I've searched extensively to understand how I should create the lines, where the user clicks a hub and lines are drawn to the destinations. It would also have to draw a line back to the hub(s) if the user clicks an outstation. Any help and/or direction would be greatly appreciated! Here's my code with only some of the outstations and hubs.
<script>
var outstations = [
[37.618972, -122.374889, "SFO" ],
[37.3626, -121.929022, "SJC" ],
[23.15185, -109.721044, "SJD" ],
[9.993861, -84.208806, "SJO" ],
[17.311194, -62.718667, "SKB" ],
[17.701889, -64.798556, "STX" ],
[38.695417, -121.590778, "SMF" ],
];
var hubs = [
[39.0488367, -84.6678222, "Cincinnati/N. KY Int'l Airport" ],
[35.8776389, -78.7874722, "Raleigh-Durham Int'l Airport" ],
[36.0800556, -115.1522500, "Las Vegas/McCarran Int'l Airport" ],
[18.4393987, -66.0021348, "San Juan Luis Munoz Marin Int'l Airport" ],
];
function initialize()
{
var map = new google.maps.Map(document.getElementById("map_canvas"),{
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
mapTypeId: google.maps.MapTypeId.HYBRID
});
var bounds = new google.maps.LatLngBounds();
var infowindow = new google.maps.InfoWindow();
for (var a in outstations) {
var b = outstations[a];
var latlng = new google.maps.LatLng(b[0], b[1]);
bounds.extend(new google.maps.LatLng(37.579407, -95.624995));
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon: 'http://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_purple.png',
title: b[2]
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(this.title);
infowindow.open(map, this);
});
}
for (var c in hubs) {
var d = hubs[c];
var latlng = new google.maps.LatLng(d[0], d[1]);
var marker = new google.maps.Marker({
position: latlng,
animation: google.maps.Animation.DROP,
map: map,
icon: 'http://maps.google.com/mapfiles/kml/pal2/icon56.png',
title: d[2]
});
}
map.fitBounds(bounds);
var listener = google.maps.event.addListener(map, "idle", function() {
if (map.getZoom() > 16) map.setZoom(4);
google.maps.event.removeListener(listener);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
It should be something like this.
(Please answer my questions in the comment under your post, if the script does not behave exactly as you need it to)
EDIT: Now it also connects a few outstations to other outstations
var hubMarkers = [];
var outstationMarkers = [];
var flightLines = [];
var outstations = [
[37.618972, -122.374889, "SFO" ],
[37.3626, -121.929022, "SJC" ],
[23.15185, -109.721044, "SJD" ],
[9.993861, -84.208806, "SJO" ],
[17.311194, -62.718667, "SKB" ],
[17.701889, -64.798556, "STX" ],
[38.695417, -121.590778, "SMF" ],
];
var hubs = [
[39.0488367, -84.6678222, "Cincinnati/N. KY Int'l Airport" ],
[35.8776389, -78.7874722, "Raleigh-Durham Int'l Airport" ],
[36.0800556, -115.1522500, "Las Vegas/McCarran Int'l Airport" ],
[18.4393987, -66.0021348, "San Juan Luis Munoz Marin Int'l Airport" ],
];
var hubConnections = [
[], // Cincinnati, no connections to outstations
[],
[0, 1, 2, 6], // Vegas, connected with SFO, SJC, ...
[3, 4, 5]
];
var outstationConnections = [
[1, 6], // SFO, connections to outstations SJC & SMF
[0], // SJC, connection to outstation SFO
[], // SJD
[], // SJO
[5], // SKB, connection to outstation STX
[4], // STX, connection to outstation SKB
[0], // SMF, connection to outstation SFO
];
function initialize() {
var map = new google.maps.Map(document.getElementById("map_canvas"), {
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
mapTypeId: google.maps.MapTypeId.HYBRID
});
var bounds = new google.maps.LatLngBounds();
var infowindow = new google.maps.InfoWindow();
for (var a in outstations) {
var b = outstations[a];
var latlng = new google.maps.LatLng(b[0], b[1]);
bounds.extend(new google.maps.LatLng(37.579407, -95.624995));
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon: 'http://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_purple.png',
title: b[2]
});
google.maps.event.addListener(marker, 'click', function() {
// clear all previous lines
for (var i=0; i<flightLines.length; i++) {
flightLines[i].setMap(null);
}
var index = outstationMarkers.indexOf(this);
for (i=0; i<hubConnections.length; i++) {
if ( hubConnections[i].indexOf(index) > -1 ) { // if the index of the outstation Marker is found in the connections of that hub
var flightPath = new google.maps.Polyline({
path: [new google.maps.LatLng(hubs[i][0], hubs[i][1]), new google.maps.LatLng(outstations[index][0], outstations[index][1])],
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
flightLines.push(flightPath);
}
}
// now we add the connections of this outstation to other outstations
for (i=0; i<outstationConnections.length; i++) {
if ( outstationConnections[i].indexOf(index) > -1 ) { // if the index of the outstation Marker is found in the connections of that hub
var flightPath = new google.maps.Polyline({
path: [new google.maps.LatLng(outstations[i][0], outstations[i][1]), new google.maps.LatLng(outstations[index][0], outstations[index][1])],
geodesic: true,
strokeColor: '#0000FF',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
flightLines.push(flightPath);
}
}
});
outstationMarkers.push(marker);
}
for (var c in hubs) {
var d = hubs[c];
var latlng = new google.maps.LatLng(d[0], d[1]);
var marker = new google.maps.Marker({
position: latlng,
animation: google.maps.Animation.DROP,
map: map,
icon: 'http://maps.google.com/mapfiles/kml/pal2/icon56.png',
title: d[2]
});
google.maps.event.addListener(marker, 'click', function() {
// clear all previous lines
for (var i=0; i<flightLines.length; i++) {
flightLines[i].setMap(null);
}
var index = hubMarkers.indexOf(this);
// line to all the connected outstations
for (i=0; i<hubConnections[index].length; i++) {
var flightPath = new google.maps.Polyline({
path: [
new google.maps.LatLng(hubs[index][0], hubs[index][1]),
new google.maps.LatLng(outstations[ hubConnections[index][i] ][0], outstations[ hubConnections[index][i] ][1])
],
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
flightLines.push(flightPath);
}
// line to all hubs
for (i=0; i<hubs.length; i++) {
if (i != index) {
var flightPath = new google.maps.Polyline({
path: [
new google.maps.LatLng(hubs[index][0], hubs[index][1]),
new google.maps.LatLng(hubs[i][0], hubs[i][1])
],
geodesic: true,
strokeColor: '#00FF00',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
flightLines.push(flightPath);
}
}
});
hubMarkers.push(marker);
}
map.fitBounds(bounds);
var listener = google.maps.event.addListener(map, "idle", function() {
if (map.getZoom() > 16) {
map.setZoom(4);
}
google.maps.event.removeListener(listener);
});
}
google.maps.event.addDomListener(window, 'load', initialize);