Package com.gi.server.core.service.mapservice

Examples of com.gi.server.core.service.mapservice.MapService


  private String result(String serviceName, String layerId, String token,
      String f, String adds, String updates, String deletes) {
    String result = null;

    try {
      MapService mapService = ServiceManager.getMapService(serviceName);

      if (mapService != null) {
        MapServiceDesc mapServiceDesc = mapService.getMapServiceDesc();
        if (mapServiceDesc.isNeedToken()) {
          boolean htmlNoParams = "html".equals(f) && adds == null
              && updates == null && deletes == null;
          if (!TokenService.verifyToken(token) && !htmlNoParams) {
            return TokenService.TOKEN_INVALID_TIP;
          }
        }

        // Handle layerId
        int nLayerId = Integer.parseInt(layerId);

        MapDesc mapDesc = mapService.getMapDesc();
        boolean editable = mapDesc.getLayerInfo(nLayerId).isEditable();
        if (!editable) {
          return null;
        }

        FeatureType featureType = null;
        MapServiceInstance instance = (MapServiceInstance) mapService
            .getMapServicePool().checkoutIdleInstance();
        try {
          Layer layer = instance.getMap().getLayer(nLayerId);
          featureType = layer.getMapLayer().getFeatureSource()
              .getSchema();
        } finally {
          if (instance != null) {
            mapService.getMapServicePool().checkinIdelInstance(
                instance);
          }
        }

        // Handle features
        FeatureCollection<SimpleFeatureType, SimpleFeature> addsFeatureCollection = null;
        if (adds != null) {
          addsFeatureCollection = EsriJsonUtil
              .json2FeatureCollection(adds,
                  (SimpleFeatureType) featureType);
        }
        FeatureCollection<SimpleFeatureType, SimpleFeature> updatesFeatureCollection = null;
        if (updates != null) {
          updatesFeatureCollection = EsriJsonUtil
              .json2FeatureCollection(updates,
                  (SimpleFeatureType) featureType);
        }
        String[] deleteFeatureIds = null;
        if (deletes != null) {
          deleteFeatureIds = deletes.split(",");
        }

        instance = (MapServiceInstance) mapService.getMapServicePool()
            .checkoutIdleInstance();

        List<FeatureId> addFeatureIds = null;
        HashMap<FeatureId, Boolean> updateFeatureIds = null;
        boolean deleteSuccess = false;
        try {
          Layer layer = instance.getMap().getLayer(nLayerId);

          try {
            addFeatureIds = layer.add(addsFeatureCollection);
          } catch (Exception ex) {
            ex.printStackTrace();
          }
          try {
            updateFeatureIds = layer
                .update(updatesFeatureCollection);
          } catch (Exception ex) {
            ex.printStackTrace();
          }
          try {
            deleteSuccess = layer.delete(deleteFeatureIds);
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        } finally {
          if (instance != null) {
            mapService.getMapServicePool().checkinIdelInstance(
                instance);
          }
        }

        // Various out format
View Full Code Here


  private String result(String serviceName, String layerId, String token,
      String f, String features) {
    String result = null;

    try {
      MapService mapService = ServiceManager.getMapService(serviceName);

      if (mapService != null) {
        MapServiceDesc mapServiceDesc = mapService.getMapServiceDesc();
        if (mapServiceDesc.isNeedToken()) {
          if (!TokenService.verifyToken(token)
              && !("html".equals(f) && features == null)) {
            return TokenService.TOKEN_INVALID_TIP;
          }
        }

        // Handle layerId
        int nLayerId = Integer.parseInt(layerId);

        MapDesc mapDesc = mapService.getMapDesc();
        boolean editable = mapDesc.getLayerInfo(nLayerId).isEditable();
        if(!editable){
          return null;
        }
         
        FeatureType featureType = null;
        MapServiceInstance instance = (MapServiceInstance) mapService
            .getMapServicePool().checkoutIdleInstance();
        try {
          Layer layer = instance.getMap().getLayer(nLayerId);
          featureType = layer.getMapLayer().getFeatureSource()
              .getSchema();
        } finally {
          if (instance != null) {
            mapService.getMapServicePool().checkinIdelInstance(
                instance);
          }
        }

        // Handle features
        FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = EsriJsonUtil
            .json2FeatureCollection(features,
                (SimpleFeatureType) featureType);

        instance = (MapServiceInstance) mapService.getMapServicePool()
            .checkoutIdleInstance();
        List<FeatureId> featureIds = null;
        try {
          Layer layer = instance.getMap().getLayer(nLayerId);
          featureIds = layer.add(featureCollection);
        } finally {
          if (instance != null) {
            mapService.getMapServicePool().checkinIdelInstance(
                instance);
          }
        }

        // Various out format
View Full Code Here

   * @param serviceRelativePath
   *            like "dir1/dir2/name"
   * @return
   */
  public static MapService loadMapService(String serviceRelativePath) {
    MapService result = null;

    try {
      result = getMapService(serviceRelativePath);

      if (result == null) {
        result = new MapService(serviceRelativePath);
        String serviceName = PathUtil
            .realPathToName(serviceRelativePath);
        mapServices.put(serviceName, result);
      }
    } catch (Exception ex) {
View Full Code Here

    return result;
  }

  public static MapService getMapService(String serviceName) {
    MapService result = null;

    try {
      if (mapServices.containsKey(serviceName)) {
        result = mapServices.get(serviceName);
      }
View Full Code Here

  public static void removeMapServices() {
    for (Iterator<Entry<String, MapService>> itr = mapServices.entrySet()
        .iterator(); itr.hasNext();) {
      Entry<String, MapService> entry = itr.next();
      MapService mapService = entry.getValue();
      MapServicePool mapServicePool = mapService.getMapServicePool();
      mapServicePool.dispose();
    }

    mapServices.clear();
  }
View Full Code Here

  public static boolean reloadMapService(String serviceName) {
    boolean result = false;

    try {
      if (mapServices.containsKey(serviceName)) {
        MapService mapService = mapServices.get(serviceName);
        mapService.getMapServicePool().dispose();
        mapServices.remove(serviceName);
      }

      MapService mapService = loadMapService(PathUtil
          .nameToRealPath(serviceName));
      if (mapService != null) {
        result = true;
      }
    } catch (Exception ex) {
View Full Code Here

      String inSR, String spatialRel, String where, String outFields,
      boolean returnGeometry, String outSR, boolean returnIdsOnly) {
    String result = null;

    try {
      MapService mapService = ServiceManager.getMapService(serviceName);

      if (mapService != null) {
        MapDesc mapDesc = mapService.getMapDesc();
        MapServiceDesc mapServiceDesc = mapService.getMapServiceDesc();
        if (mapServiceDesc.isNeedToken()) {
          boolean htmlNoParams = "html".equals(f)
              && objectIds == null && geometry == null
              && geometryType == null && inSR == null
              && spatialRel == null && where == null
              && outFields == null && outSR == null;
          if (!TokenService.verifyToken(token) && !htmlNoParams) {
            return TokenService.TOKEN_INVALID_TIP;
          }
        }

        // Handle layerId
        int nLayerId = Integer.parseInt(layerId);

        // Handle SRs
        String sr = mapDesc.getWkid();
        if (inSR == null || "".equals(inSR)) {
          inSR = sr;
        }
        if (outSR == null || "".equals(outSR)) {
          outSR = sr;
        }

        String[] featureIds = null;
        com.gi.engine.carto.QueryParam queryParam = null;

        // Handle objectids
        if (objectIds != null && !"".equals(objectIds)) {
          featureIds = objectIds.split(",");
        } else {
          // Handle geometry
          Geometry geo = null;
          if (geometry != null && !"".equals(geometry)) {
            geo = EsriJsonUtil.json2Geometry(geometry);

            if (!sr.equals(inSR)) {
              geo = GeometryToolkit.project(geo, inSR, sr);
            }
          }

          // Handle spatialRel
          SpatialFilterType relation;
          if ("esriSpatialRelContains".equals(spatialRel)) {
            relation = SpatialFilterType.CONTAINS;
          } else if ("esriSpatialRelCrosses".equals(spatialRel)) {
            relation = SpatialFilterType.CROSSES;
          } else if ("esriSpatialRelEnvelopeIntersects"
              .equals(spatialRel)) {
            relation = SpatialFilterType.ENVELOPE_INTERSECTS;
          } else if ("esriSpatialRelIndexIntersects"
              .equals(spatialRel)) {
            relation = SpatialFilterType.INDEX_INTERSECTS;
          } else if ("esriSpatialRelOverlaps".equals(spatialRel)) {
            relation = SpatialFilterType.OVERLAPS;
          } else if ("esriSpatialRelTouches".equals(spatialRel)) {
            relation = SpatialFilterType.TOUCHES;
          } else if ("esriSpatialRelWithin".equals(spatialRel)) {
            relation = SpatialFilterType.WITHIN;
          } else {
            relation = SpatialFilterType.INTERSECTS;
          }

          queryParam = new com.gi.engine.carto.QueryParam();
          queryParam.setGeometry(geo);
          queryParam.setSpatialFilterType(relation);
          queryParam.setWhere(where);
        }

        FeatureCollection<? extends FeatureType, ? extends Feature> featureCollection = null;
        MapServiceInstance instance = (MapServiceInstance) mapService
            .getMapServicePool().checkoutIdleInstance();
        try {
          Layer layer = instance.getMap().getLayer(nLayerId);
          if (featureIds != null) {
            featureCollection = layer.query(featureIds);
          } else {
            featureCollection = layer.query(queryParam);
          }
        } finally {
          if (instance != null) {
            mapService.getMapServicePool().checkinIdelInstance(
                instance);
          }
        }

        // Various out format
View Full Code Here

      String searchText, String contains, String searchFields, String sr,
      String layers, String returnGeometry) {
    String result = null;

    try {
      MapService mapService = ServiceManager.getMapService(serviceName);

      if (mapService != null) {
        MapDesc mapDesc = mapService.getMapDesc();
        MapServiceDesc mapServiceDesc = mapService.getMapServiceDesc();
        if (mapServiceDesc.isNeedToken()) {
          if (!TokenService.verifyToken(token)
              && !("html".equals(f) && searchText == null)) {
            return TokenService.TOKEN_INVALID_TIP;
          }
        }

        String mapSR = mapDesc.getWkid();

        // Handle contains
        boolean isContains = Boolean.parseBoolean(contains);

        // Handle searchFields
        String[] strSearchFields = null;
        if (searchFields != null && !"".equals(searchFields)) {
          strSearchFields = searchFields.split(",");
        }

        // Handle SRs
        if (sr == null || "".equals(sr)) {
          sr = mapSR;
        }

        // Handle layers
        String[] layerIds = null;
        if (layers != null && !"".equals(layers)) {
          layerIds = layers.split(",");
        }
        ArrayList<String> layerIdArray = null;
        if (layerIds != null) {
          layerIdArray = new ArrayList<String>();
          int count = layerIds.length;
          for (int i = 0; i < count; i++) {
            layerIdArray.add(layerIds[i]);
          }
        }

        // Handle returnGeometry
        boolean isReturnGeometry = Boolean.parseBoolean(returnGeometry);

        FindParam findParam = new FindParam();
        findParam.setSearchText(searchText);
        findParam.setContains(isContains);
        findParam.setSearchFields(strSearchFields);

        ArrayList<FeatureResult> featureResults = null;
        MapServiceInstance instance = (MapServiceInstance) mapService
            .getMapServicePool().checkoutIdleInstance();
        try {
          featureResults = instance.find(layerIdArray, findParam);
        } finally {
          if (instance != null) {
            mapService.getMapServicePool().checkinIdelInstance(
                instance);
          }
        }

        // Various out format
View Full Code Here

  private byte[] result(String serviceName, String level, String row,
      String col, String token) {
    byte[] result = null;

    try {
      MapService mapService = ServiceManager.getMapService(serviceName);

      if (mapService != null) {
        MapServiceDesc mapServiceDesc = mapService.getMapServiceDesc();
        if (mapServiceDesc.isNeedToken()) {
          if (!TokenService.verifyToken(token)) {
            return TokenService.TOKEN_INVALID_TIP.getBytes();
          }
        }

        // Handle level, row, col
        // col may contains suffix
        if (col.contains(".")) {
          col = col.substring(0, col.indexOf("."));
        }
        int nLevel = Integer.parseInt(level);
        int nRow = Integer.parseInt(row);
        int nCol = Integer.parseInt(col);

        // Handle export
        MapServiceInstance instance = (MapServiceInstance) mapService
            .getMapServicePool().checkoutIdleInstance();
        try {
          if (mapServiceDesc.getTileInfo().isCreateOnDemand()) {
            result = instance.getOrCreateTile(nLevel, nRow, nCol);
          } else {
            result = instance.getTile(nLevel, nRow, nCol);
          }
        } finally {
          if (instance != null) {
            mapService.getMapServicePool().checkinIdelInstance(
                instance);
          }
        }
      }
    } catch (Exception ex) {
View Full Code Here

      String bboxSR, String format, String layerDefs, String layers,
      String transparent) {
    byte[] result = null;

    try {
      MapService mapService = ServiceManager.getMapService(serviceName);

      if (mapService != null) {
        MapDesc mapDesc = mapService.getMapDesc();
        MapServiceDesc mapServiceDesc = mapService.getMapServiceDesc();
        if (mapServiceDesc.isNeedToken()) {
          if (!TokenService.verifyToken(token)
              && !("html".equals(f) && bbox == null)) {
            return TokenService.TOKEN_INVALID_TIP.getBytes();
          }
        }

        // Handle SRs
        String sr = mapDesc.getWkid();
        if (bboxSR == null || "".equals(bboxSR)) {
          bboxSR = sr;
        }
        if (imageSR == null || "".equals(imageSR)) {
          imageSR = sr;
        }

        // Handle size
        String[] sizes = size.split(",");
        int width = Integer.parseInt(sizes[0]);
        int height = Integer.parseInt(sizes[1]);

        // Handle bbox
        double xmin = 0, ymin = 0, xmax = 0, ymax = 0;
        if (bbox != null && bbox.indexOf(",") > 0) {
          String[] bboxs = bbox.split(",");
          if (bbox.length() > 3) {
            xmin = Double.parseDouble(bboxs[0]);
            ymin = Double.parseDouble(bboxs[1]);
            xmax = Double.parseDouble(bboxs[2]);
            ymax = Double.parseDouble(bboxs[3]);
          }
        }
        if ((xmax - xmin) * (ymax - ymin) == 0) {
          Envelope extent = mapDesc.getInitialExtent();
          xmin = extent.getMinX();
          xmax = extent.getMaxX();
          ymin = extent.getMinY();
          ymax = extent.getMaxY();
        }
        CoordinateReferenceSystem bboxCRS = SpatialReferenceManager
            .wkidToCRS(bboxSR, true);
        ReferencedEnvelope env = new ReferencedEnvelope(xmin, xmax,
            ymin, ymax, bboxCRS);
        env = GeometryToolkit.project(env, imageSR);
        env = MapUtil.adjustEnvelopeToSize(env,
            width, height);

        // Handle dpi
        int nDPI = Integer.parseInt(dpi);

        // Handle layerDefs
        HashMap<String, String> mapLayerDefs = null;
        if (layerDefs != null && !"".equals(layerDefs)) {
          try {
            mapLayerDefs = new HashMap<String, String>();
            String[] defs = layerDefs.split(",");
            for (int i = 0; i < defs.length; i++) {
              String def = defs[i];
              if (def.contains(":")) {
                String[] deff = def.split(":");
                if (deff.length > 1) {
                  mapLayerDefs.put(deff[0], deff[1]);
                }
              } else {
                mapLayerDefs.put(String.valueOf(i), def);
              }
            }
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        }

        // Handle layers
        ArrayList<String> layerIds = new ArrayList<String>();
        if (layers != null && !"".equals(layers) && !"*".equals(layers)) {
          String[] strLayers = layers.split(",");
          int layerCount = strLayers.length;
          for (int i = 0; i < layerCount; i++) {
            layerIds.add(strLayers[i]);
          }
        } else {
          for (int i = 0, count = mapDesc.getLayerInfos().size(); i < count; i++) {
            LayerInfo layerInfo = mapDesc.getLayerInfo(i);
            if (layerInfo.isVisible()) {
              layerIds.add(String.valueOf(i));
            }
          }
        }

        // Handle export
        RenderParam renderParam = new RenderParam();
        renderParam.setAntiAlias(mapDesc.isAntiAlias());
        renderParam.setExtent(env);
        renderParam.setImageHeight(height);
        renderParam.setImageWidth(width);
        renderParam.setLayerDefs(mapLayerDefs);
        renderParam.setTransparent(Boolean.parseBoolean(transparent));
        renderParam.setVisibleLayerIds(layerIds);

        byte[] image = null;
        double scale = 0;
        MapServiceInstance instance = (MapServiceInstance) mapService
            .getMapServicePool().checkoutIdleInstance();
        try {
          image = instance.export(renderParam, format, nDPI);
          scale = instance.getMap().computeScale(env, width, height,
              nDPI);
        } finally {
          if (instance != null) {
            mapService.getMapServicePool().checkinIdelInstance(
                instance);
          }
        }

        // Various out format
View Full Code Here

TOP

Related Classes of com.gi.server.core.service.mapservice.MapService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.